package com.nitesh.p4demo; /* * Author : Nitesh Suthar * Application : P4Java Utility Tool. * Profile : https://swarm.workshop.perforce.com/users/sutharNitesh/ */ import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.EventQueue; import java.awt.Rectangle; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowEvent; import java.io.IOException; import java.io.OutputStream; import java.io.PrintStream; 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.JScrollPane; import javax.swing.JTextArea; import javax.swing.JTextField; import javax.swing.LayoutStyle.ComponentPlacement; 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 MainUI() { uiContext = this; setTitle("P4Java Demo Tool"); setSize(600, 480); setMaximizedBounds(new Rectangle(600,480)); setMinimumSize(new Dimension(600,480)); addWindowListener(new UIListener()); btnListener = new BtnAction(); txtName = new JTextField("sutharNitesh"); txtPassword = new JPasswordField("1q2w3e4r5t"); txtServerUrl = new JTextField("public.perforce.com:1666"); lblName = new JLabel("User Name :"); lblPassword = new JLabel("Password :"); lblServerUrl = new JLabel("Server :"); btnLogin = new JButton(CommonConstants.STR_LOG_IN); btnLogin.addActionListener(btnListener); btnClCount = new JButton(CommonConstants.STR_CL_COUNT); btnClCount.addActionListener(btnListener); btnClCount.setEnabled(false); logArea = new JTextArea(); logArea.setText("P4JAVA utility tool\n\n"); scrollPane = new JScrollPane(); scrollPane.setViewportView(logArea); scrollPane.setRequestFocusEnabled(true); JPanel panel = new JPanel(); GroupLayout layout = new GroupLayout(panel); panel.setLayout(layout); layout.setHorizontalGroup(layout .createParallelGroup() .addGroup( 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) .addComponent(btnClCount))) .addGap(5) .addComponent(scrollPane, GroupLayout.DEFAULT_SIZE, 300, GroupLayout.DEFAULT_SIZE)); 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) .addComponent(btnLogin) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(btnClCount) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(scrollPane, GroupLayout.DEFAULT_SIZE, 300, GroupLayout.DEFAULT_SIZE)); add(panel, BorderLayout.NORTH); PrintStream consoleStream = new PrintStream(new OutputStream() { @Override public void write(byte[] b, int off, int len) throws IOException { logArea.setForeground(Color.BLUE); logArea.append(new String(b, off, len)); } @Override public void write(int arg0) throws IOException { } }); System.setOut(consoleStream); System.setErr(consoleStream); } JTextField txtServerUrl; JTextField txtName; JPasswordField txtPassword; JLabel lblName; JLabel lblPassword; JLabel lblServerUrl; JButton btnLogin; JButton btnClCount; JScrollPane scrollPane; JTextArea logArea; MainUI uiContext; PerforceConnection connection; BtnAction btnListener; class BtnAction implements ActionListener { @Override public void actionPerformed(ActionEvent e) { JButton btn = (JButton) e.getSource(); System.out.println("Pressed \""+btn.getText()+"\" Button"); switch (CommonConstants.getValue(btn.getText())) { case 0: // Login connection = new PerforceConnection(txtServerUrl.getText()); if (connection.open(txtName.getText(), new String(txtPassword.getPassword()))) { txtServerUrl.setEditable(false); txtName.setEditable(false); txtPassword.setEditable(false); btnLogin.setText(CommonConstants.STR_LOG_OUT); btnClCount.setEnabled(true); System.out.println("Login Successful \n"+connection); } break; case 1: // Logout connection.close(); txtServerUrl.setEditable(true); txtName.setEditable(true); txtPassword.setEditable(true); btnClCount.setEnabled(false); btnLogin.setText(CommonConstants.STR_LOG_IN); System.out.println("User "+txtName.getText()+" Logged out successfully"); break; case 2: // total CL Submitted. System.out.println("Total CLs Submitted by user "+txtName.getText()+" are " + connection.getUserSubmittedChangeListCount(txtName .getText())); System.out.println("Total CLs Submitted by user michael_allard are "+connection.getUserSubmittedChangeListCount("michael_allard")); System.out.println("Total CLs Submitted by user sivananda_poreddy are "+connection.getUserSubmittedChangeListCount("sivananda_poreddy")); break; default: System.out.println("No such action exits!"); } } } class UIListener extends UIWindowListener { @Override public void windowClosing(WindowEvent e) { System.out.println("windowClosing " + e.toString()); if (connection != null && connection.isOpen()) { connection.close(); } } } }
# | 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 |