|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.modules.cvsclient.commands.commit; import javax.swing.JButton; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import org.netbeans.modules.vcscore.util.Debug; import javax.swing.table.TableColumn; import javax.swing.table.JTableHeader; import org.openide.util.NbBundle; import org.netbeans.modules.javacvs.commands.CvsCommit; import org.netbeans.lib.cvsclient.command.FileInfoContainer; import org.netbeans.lib.cvsclient.event.*; import java.util.ResourceBundle; import org.netbeans.modules.cvsclient.commands.*; import org.netbeans.modules.javacvs.commands.ClientProvider; import java.awt.Dialog; import org.netbeans.lib.cvsclient.command.commit.CommitInformation; import org.netbeans.modules.vcscore.util.table.*; import javax.accessibility.*; import org.openide.DialogDescriptor; import java.lang.reflect.Method; public class CommitInfoPanel extends DefaultInfoPanel { TableInfoModel model; CvsCommit command; long currentTimeStamp; long firedTimeStamp = 0; int addedCount = 0; int totalCount = 0; private String labelString; private boolean wasSending; private java.io.File sendingDir = null; private org.netbeans.lib.cvsclient.command.Command currentCom; private ActionListener stopActionListener; /** Creates new form CommitInfoPanel */ public CommitInfoPanel(CvsCommit comm) { initComponents(); initAccessibility(); btnViewLog.setMnemonic(NbBundle.getBundle(CommitInfoPanel.class).getString("CommitInfoPanel.logButton.mnemonic").charAt(0)); //NOI18N btnStop.setMnemonic(NbBundle.getBundle(CommitInfoPanel.class).getString("CommitInfoPanel.stopButton.mnemonic").charAt(0)); //NOI18N command = comm; setPreferredSize(new java.awt.Dimension(450, 200)); setMinimumSize(new java.awt.Dimension(450, 200)); labelString = NbBundle.getBundle(CommitInfoPanel.class). getString("CommitInfoPanel.lblSending.text"); //NOI18N model = new GrowingTableInfoModel(); Class classa = CommitInformation.class; String column1 = NbBundle.getBundle(CommitInfoPanel.class).getString("CommitTableInfoModel.type"); //NOI18N String column2 = NbBundle.getBundle(CommitInfoPanel.class).getString("CommitTableInfoModel.fileName"); //NOI18N String column3 = NbBundle.getBundle(CommitInfoPanel.class).getString("CommitTableInfoModel.revision"); //NOI18N String column4 = NbBundle.getBundle(CommitInfoPanel.class).getString("CommitTableInfoModel.path"); //NOI18N try { Method method1 = classa.getMethod("getType", null); //NOI18N Method method2 = classa.getMethod("getFile", null); //NOI18N Method method3 = classa.getMethod("getRevision", null); //NOI18N model.setColumnDefinition(0, column1, method1, true, null); ClientProvider prov = command.getClientProvider(); model.setColumnDefinition(1, column2, method2, true, new FileComparator()); model.setColumnDefinition(2, column3, method3, true, new RevisionComparator()); model.setColumnDefinition(3, column4, method2, true, new PathComparator(prov.getLocalPath())); } catch (NoSuchMethodException exc) { Thread.dumpStack(); } catch (SecurityException exc2) { Thread.dumpStack(); } tblUpdates.setModel(model); TableColumn col = tblUpdates.getColumnModel().getColumn(2); col.setMaxWidth(60); // HACK to set the width of column at desired size col = tblUpdates.getColumnModel().getColumn(0); col.setMaxWidth(60); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the FormEditor. */ private void initComponents() {//GEN-BEGIN:initComponents java.awt.GridBagConstraints gridBagConstraints; pnlButtons = new javax.swing.JPanel(); btnViewLog = new javax.swing.JButton(); btnStop = new javax.swing.JButton(); spCentral = new javax.swing.JScrollPane(); tblUpdates = new javax.swing.JTable(); lblSending = new javax.swing.JLabel(); setLayout(new java.awt.GridBagLayout()); setPreferredSize(new java.awt.Dimension(273, 170)); setMinimumSize(new java.awt.Dimension(170, 100)); pnlButtons.setLayout(new java.awt.GridBagLayout()); btnViewLog.setText(org.openide.util.NbBundle.getBundle(CommitInfoPanel.class).getString("CommitInfoPanel.logButton")); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; gridBagConstraints.weightx = 1.0; pnlButtons.add(btnViewLog, gridBagConstraints); btnStop.setText(org.openide.util.NbBundle.getBundle(CommitInfoPanel.class).getString("CommitInfoPanel.stopButton")); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 0); pnlButtons.add(btnStop, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 2; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.insets = new java.awt.Insets(17, 12, 11, 11); add(pnlButtons, gridBagConstraints); spCentral.setPreferredSize(new java.awt.Dimension(250, 60)); tblUpdates.setModel(new javax.swing.table.DefaultTableModel( new Object [][] { {null, null, null, null}, {null, null, null, null}, {null, null, null, null}, {null, null, null, null} }, new String [] { "Title 1", "Title 2", "Title 3", "Title 4" } )); spCentral.setViewportView(tblUpdates); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; gridBagConstraints.insets = new java.awt.Insets(0, 12, 0, 11); add(spCentral, gridBagConstraints); lblSending.setLabelFor(tblUpdates); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.insets = new java.awt.Insets(12, 12, 2, 11); gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; add(lblSending, gridBagConstraints); }//GEN-END:initComponents private void btnEditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditActionPerformed }//GEN-LAST:event_btnEditActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton btnViewLog; private javax.swing.JTable tblUpdates; private javax.swing.JScrollPane spCentral; private javax.swing.JButton btnStop; private javax.swing.JLabel lblSending; private javax.swing.JPanel pnlButtons; // End of variables declaration//GEN-END:variables private static final ResourceBundle bundle = NbBundle.getBundle(CommitInfoPanel.class); //NOI18N private void initAccessibility() { AccessibleContext context = tblUpdates.getAccessibleContext(); context.setAccessibleDescription(bundle.getString("ACSD_CommitInfoPanel.tblUpdates")); context = btnViewLog.getAccessibleContext(); context.setAccessibleDescription(bundle.getString("ACSD_CommitInfoPanel.btnViewLog")); context = btnStop.getAccessibleContext(); context.setAccessibleDescription(bundle.getString("ACSD_CommitInfoPanel.btnStop")); } /** this method should be used with Choosers to display the dialog.. * then later the displayOutputData will just present the datat gotten from server * Reason: to have something displayer right away.. * This method is to be called when creating the command and Chooser. */ public void displayFrameWork() { TableColumn col = tblUpdates.getColumnModel().getColumn(0); col.setPreferredWidth(60); // HACK to set the width of column at desired size // String title = NbBundle.getBundle(CommitInfoPanel.class).getString("CommitInfoPanel.dialogTitle") + " " + command.getName(); // setName(title); setName(command.getName()); stopActionListener = new StopActionListener(); btnStop.addActionListener(stopActionListener); btnViewLog.setEnabled(false); javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { open(); } }); /* dd = new DialogDescriptor(this, title); Object[] options = new Object[1]; btnStop = new JButton(); btnStop.setText(NbBundle.getBundle(CommitInfoPanel.class).getString("CommitInfoPanel.stopButton")); options[0] = btnStop; dd.setOptions(options); Object[] empty = new Object[1]; dd.setClosingOptions(empty); // none are closing dd.setButtonListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { shutDownCommand(); } }); javax.swing.SwingUtilities.invokeLater(new Runnable () { public void run () { Dialog dial = TopManager.getDefault().createDialog(dd); dial.setModal(false); dial.show(); } }); */ } protected void shutDownCommand() { // we can do that because it's running from other thread then command and won't kill itself if (btnStop != null) { btnStop.setText(NbBundle.getBundle(CommitInfoPanel.class).getString("CommitInfoPanel.stopping")); //NOI18N btnStop.setEnabled(false); } command.hardCommandStop(); // displayOutputData(); } /** Does the actual display - docking into the javacvs Mode, * displaying as single Dialog.. whatever. */ public void displayOutputData() { /* if (!isOpened()) { return; } */ btnStop.setText(NbBundle.getBundle(CommitInfoPanel.class).getString("CommitInfoPanel.closeButton")); //NOI18N btnStop.setMnemonic(NbBundle.getBundle(CommitInfoPanel.class).getString("CommitInfoPanel.closeButton.mnemonic").charAt(0)); //NOI18N btnStop.setEnabled(true); btnStop.removeActionListener(stopActionListener); btnStop.addActionListener(new CloseActionListener()); btnViewLog.addActionListener(new ViewLogActionListener(btnViewLog)); btnViewLog.setEnabled(true); // forces the NbPresenter to keep the user's resizing. /* if (isShowing()) { this.setPreferredSize(getSize()); } Object[] options = new Object[2]; JButton btnClose = new JButton(); btnClose.setText(NbBundle.getBundle(CommitInfoPanel.class).getString("CommitInfoPanel.closeButton")); btnClose.setDefaultCapable(true); options[1] = btnClose; dd.setValue(btnClose); final String log = NbBundle.getBundle(CommitInfoPanel.class).getString("CommitInfoPanel.logButton"); options[0] = log; Object[] closing = new Object[1]; closing[0] = options[1]; dd.setOptions(options); dd.setClosingOptions(closing); // all are closing dd.setButtonListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (evt.getActionCommand().equals(log)) { doShowCommandLog(); } } }); */ JTableHeader head = tblUpdates.getTableHeader(); head.setUpdateTableInRealTime(true); ColumnSortListener listen = new ColumnSortListener(tblUpdates); head.addMouseListener(listen); } /* private String getMIMEType(File infoFile) { if (infoFile == null) return "text/plain"; String tempStr = infoFile.getName(); String extension = null; D.deb("tempStr=" + tempStr); int ind = tempStr.indexOf('.'); if (ind > 0) { extension = tempStr.substring(ind + 1); } D.deb("extension=" + extension); if (extension == null) { extension = "text/plain"; } String type = FileUtil.getMIMEType(extension); if (type == null) { type = "text/plain"; } return type; } */ /** * This is the last method to be called in the displayer. * Is called when the execution finishes. Any filan touchups can be made here. */ public void showFinishedCommand() { if (wasSending) { lblSending.setText(" "); //NOI18N wasSending = false; } displayOutputData(); } /** * This method is the first one that is called during execution. * Here any initial setup of the displayer can be made. */ public void showStartCommand() { displayFrameWork(); } /** * this one is called when the command's execution fails for any reason. */ public void showExecutionFailed(Exception exception) { if (wasSending) { lblSending.setText(" "); //NOI18N wasSending = false; } // if (isOpened()) { displayOutputData(); // } } /** * When the library command's builder generates a FileInfoContainer object, the * Displayer is notified. * @param info - the generated information object */ public void showFileInfoGenerated(FileInfoContainer info) { if (wasSending) { lblSending.setText(" "); //NOI18N wasSending = false; } if (info instanceof CommitInformation) { model.addElement(info); currentTimeStamp = System.currentTimeMillis(); addedCount = addedCount + 1; totalCount = totalCount + 1; long tpDiff = currentTimeStamp - firedTimeStamp; if (totalCount < 200 || addedCount > 5 || tpDiff > 1000) { javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { tblUpdates.changeSelection(model.getRowCount(), 0, false, false); } }); firedTimeStamp = System.currentTimeMillis(); addedCount = 0; } } } /** * When the server generates a line of output/error, the displayer is notified. * @param message - the string to be displayed, be it error/message (E/M response) */ public void messageGenerated(MessageEvent message) { super.messageGenerated(message); if (message instanceof EnhancedMessageEvent) { EnhancedMessageEvent ev = (EnhancedMessageEvent)message; if (ev.getKey().equals(ev.FILE_SENDING)) { java.io.File file = (java.io.File)ev.getValue(); if (sendingDir == null || (!sendingDir.equals(file.getParentFile()))) { sendingDir = file.getParentFile(); String lbl = sendingDir.getAbsolutePath().substring(currentCom.getLocalDirectory().length()); lblSending.setText(java.text.MessageFormat.format(labelString, new Object[] {lbl})); lblSending.setDisplayedMnemonic(NbBundle.getBundle(CommitInfoPanel.class).getString("CommitInfoPanel.lblSending.mnemonic").charAt(0)); // NOI18N lblSending.setLabelFor(tblUpdates); } wasSending = true; } if (ev.getKey().equals(ev.REQUESTS_SENT)) { lblSending.setText(NbBundle.getBundle(CommitInfoPanel.class).getString("CommitInfoPanel.All_Requests_Sent")); //NOI18N wasSending = true; } } } /** * this method is called before any of the library's commands * that is stored in the queue in FileSystemCommand, is run. * @param currentCommand shows the command that will be executed. */ public void showBeforeEachExecute(org.netbeans.lib.cvsclient.command.Command currentCommand) { super.showBeforeEachExecute(currentCommand); currentCom = currentCommand; } } |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.