package com.nitesh.p4demo; import java.awt.BorderLayout; import java.awt.EventQueue; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.net.URISyntaxException; import java.util.List; import javax.swing.GroupLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JPasswordField; import javax.swing.JTextField; import javax.swing.LayoutStyle.ComponentPlacement; import com.perforce.p4java.core.IDepot; import com.perforce.p4java.exception.AccessException; import com.perforce.p4java.exception.ConfigException; import com.perforce.p4java.exception.ConnectionException; import com.perforce.p4java.exception.NoSuchObjectException; import com.perforce.p4java.exception.RequestException; import com.perforce.p4java.exception.ResourceException; import com.perforce.p4java.server.IServer; import com.perforce.p4java.server.IServerInfo; import com.perforce.p4java.server.ServerFactory; public class MainUI extends JFrame{ /** * */ private static final long serialVersionUID = 2267642545084856629L; public static void main(String args[]) { EventQueue.invokeLater(new Runnable(){ @Override public void run() { MainUI ui = new MainUI(); ui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); ui.setVisible(true); }}); } public void loginUser() throws ConnectionException, NoSuchObjectException, ConfigException, ResourceException, URISyntaxException, AccessException, RequestException { System.out.println("Login clicked for "+txtName.getText()+" Password: "+ new String(txtPassword.getPassword())); IServer server = ServerFactory.getServer("p4java://"+txtServerUrl.getText(), null); server.connect(); server.setUserName(txtName.getText()); server.login(new String(txtPassword.getPassword())); IServerInfo info = server.getServerInfo(); System.out.println(formatInfo(info)); List<IDepot> depot =server.getDepots(); for(IDepot dp : depot) { System.out.println("Depot Name: "+dp.getName()+"Address : "+dp.getAddress()+" Owner: "+dp.getOwnerName()); } server.logout(); server.disconnect(); } public String formatInfo(IServerInfo info) { return "Info :\n{\nClient Address : "+info.getClientAddress()+"\nClient Name: "+info.getClientName()+"\nUser Name: "+info.getUserName() +"\nServer Root: "+info.getServerRoot()+"\n}"; } public MainUI() { uiContext =this; setTitle("P4V Test Demo"); setSize(600,480); txtName = new JTextField("sutharNitesh"); txtPassword = new JPasswordField("xxxxxxx"); txtServerUrl = new JTextField("public.perforce.com:1666"); lblName = new JLabel("User Name :"); lblPassword = new JLabel("Password :"); lblServerUrl = new JLabel("Server :"); btnLogin = new JButton("Login"); btnLogin.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent e) { try { uiContext.loginUser(); } catch (ConnectionException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (NoSuchObjectException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (ConfigException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (ResourceException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (AccessException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (RequestException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (URISyntaxException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } }}); JPanel panel = new JPanel(); //GroupLayout layout = new GroupLayout(getContentPane()); //getContentPane().setLayout(layout); GroupLayout layout = new GroupLayout(panel); panel.setLayout(layout); layout.setHorizontalGroup( layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup() .addComponent(lblServerUrl,GroupLayout.Alignment.TRAILING) .addComponent(lblName,GroupLayout.Alignment.TRAILING) .addComponent(lblPassword,GroupLayout.Alignment.TRAILING)) .addPreferredGap(ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup() .addComponent(txtServerUrl,200,200,200) .addComponent(txtName,200,200,200) .addComponent(txtPassword,200,200,200) .addComponent(btnLogin))); layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] { txtName, txtPassword }); layout.setVerticalGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup() .addComponent(lblServerUrl) .addComponent(txtServerUrl,GroupLayout.PREFERRED_SIZE,GroupLayout.DEFAULT_SIZE,GroupLayout.PREFERRED_SIZE)) .addPreferredGap(ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup() .addComponent(lblName) .addComponent(txtName,GroupLayout.PREFERRED_SIZE,GroupLayout.DEFAULT_SIZE,GroupLayout.PREFERRED_SIZE)) .addPreferredGap(ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup() .addComponent(lblPassword) .addComponent(txtPassword,GroupLayout.PREFERRED_SIZE,GroupLayout.DEFAULT_SIZE,GroupLayout.PREFERRED_SIZE)) .addPreferredGap(ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup() .addGap(100) .addComponent(btnLogin))); add(panel,BorderLayout.NORTH); } JTextField txtServerUrl; JTextField txtName; JPasswordField txtPassword; JLabel lblName; JLabel lblPassword; JLabel lblServerUrl; JButton btnLogin; MainUI uiContext; }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#3 | 21309 | sutharNitesh | Setup project in eclipse Neon Java IDE | ||
#2 | 13640 | sutharNitesh |
Updated GUI 1> Added Login Screen 2> Added OnScreen logging 3> Added Button to get Total no. of Submitted CLs 4> Added Exported Jar in ~/P4DemoTool/bin/P4DemoTool.jar Execution Command >java -jar <local path to locate jar>/P4DemoTool.jar |
||
#1 | 13638 | sutharNitesh | P4DemoTool -> Writing demo tool to utilize p4java api, to do generic db queries |