|
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.remove;
import java.util.*;
import javax.accessibility.*;
import java.io.IOException;
import java.io.File;
import javax.swing.*;
import javax.swing.table.*;
import java.awt.*;
import java.awt.event.*;
import org.netbeans.modules.vcscore.util.Debug;
import org.netbeans.modules.cvsclient.commands.*;
import org.netbeans.modules.cvsclient.IndependantClient;
import org.netbeans.modules.javacvs.commands.CvsCommit;
import org.netbeans.modules.javacvs.commands.CvsRemove;
import org.netbeans.modules.javacvs.commands.FileSystemCommand;
import org.netbeans.lib.cvsclient.command.remove.RemoveInformation;
import org.netbeans.modules.cvsclient.NbJavaCvsFileSystem;
import org.netbeans.modules.cvsclient.FsCommandFactory;
import org.openide.util.NbBundle;
import org.openide.filesystems.*;
import org.openide.loaders.*;
import org.openide.cookies.*;
import org.openide.*;
import java.lang.reflect.Method;
import org.netbeans.modules.javacvs.commands.ClientProvider;
import org.netbeans.modules.vcscore.util.table.*;
import org.openide.DialogDisplayer;
public class RemoveInfoPanel extends DefaultInfoPanel {
private Debug E=new Debug("RemoveInfoPanel", true); // NOI18N
private Debug D=E;
ArrayList listeners;
TableInfoModel model;
CvsRemove command;
private boolean stopped;
private ActionListener stopActionListener;
/** Creates new form UpdateInfoPanel */
public RemoveInfoPanel(CvsRemove comm) {
initComponents();
initAccessibility();
btnCommit.setMnemonic(NbBundle.getBundle(RemoveInfoPanel.class).getString("RemoveInfoPanel.commitButton.mnemonic").charAt(0)); //NOI18N
btnViewLog.setMnemonic(NbBundle.getBundle(RemoveInfoPanel.class).getString("RemoveInfoPanel.logButton.mnemonic").charAt(0)); //NOI18N
btnStop.setMnemonic(NbBundle.getBundle(RemoveInfoPanel.class).getString("RemoveInfoPanel.stopButton.mnemonic").charAt(0)); //NOI18N
setPreferredSize(new java.awt.Dimension(450, 200));
setMinimumSize(new java.awt.Dimension(450, 200));
stopped = false;
command = comm;
model = new GrowingTableInfoModel();
Class classa = RemoveInformation.class;
String column1 = NbBundle.getBundle(RemoveInfoPanel.class).getString("RemoveTableInfoModel.type"); // NOI18N
String column2 = NbBundle.getBundle(RemoveInfoPanel.class).getString("RemoveTableInfoModel.fileName"); // NOI18N
String column3 = NbBundle.getBundle(RemoveInfoPanel.class).getString("RemoveTableInfoModel.path"); // NOI18N
try {
Method method1 = classa.getMethod("isRemoved", null); // NOI18N
Method method2 = classa.getMethod("getFile", null); // NOI18N
model.setColumnDefinition(0, column1, method1, true, new RemoveTypeComparator());
ClientProvider prov = command.getClientProvider();
model.setColumnDefinition(1, column2, method2, true, new FileComparator());
model.setColumnDefinition(2, column3, method2, true, new PathComparator(prov.getLocalPath()));
} catch (NoSuchMethodException exc) {
Thread.dumpStack();
} catch (SecurityException exc2) {
Thread.dumpStack();
}
tblRemoved.setModel(model);
}
/** 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;
spCentral = new javax.swing.JScrollPane();
tblRemoved = new javax.swing.JTable();
pnlButtons = new javax.swing.JPanel();
btnCommit = new javax.swing.JButton();
btnViewLog = new javax.swing.JButton();
btnStop = new javax.swing.JButton();
setLayout(new java.awt.GridBagLayout());
spCentral.setPreferredSize(new java.awt.Dimension(250, 60));
tblRemoved.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(tblRemoved);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.weighty = 1.0;
gridBagConstraints.insets = new java.awt.Insets(12, 12, 0, 11);
add(spCentral, gridBagConstraints);
pnlButtons.setLayout(new java.awt.GridBagLayout());
btnCommit.setText(org.openide.util.NbBundle.getBundle(RemoveInfoPanel.class).getString("RemoveInfoPanel.commitButton"));
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
gridBagConstraints.weightx = 1.0;
pnlButtons.add(btnCommit, gridBagConstraints);
btnViewLog.setText(org.openide.util.NbBundle.getBundle(RemoveInfoPanel.class).getString("RemoveInfoPanel.logButton"));
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 0);
pnlButtons.add(btnViewLog, gridBagConstraints);
btnStop.setText(org.openide.util.NbBundle.getBundle(RemoveInfoPanel.class).getString("RemoveInfoPanel.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 = 1;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.insets = new java.awt.Insets(17, 12, 11, 11);
add(pnlButtons, gridBagConstraints);
}//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnCommit;
private javax.swing.JTable tblRemoved;
private javax.swing.JButton btnViewLog;
private javax.swing.JScrollPane spCentral;
private javax.swing.JButton btnStop;
private javax.swing.JPanel pnlButtons;
// End of variables declaration//GEN-END:variables
private static final java.util.ResourceBundle bundle = NbBundle.getBundle(RemoveInfoPanel.class); // NOI18N
private void initAccessibility() {
AccessibleContext context = this.getAccessibleContext();
context.setAccessibleDescription(bundle.getString("ACSD_RemoveInfoPanel"));
context = btnCommit.getAccessibleContext();
context.setAccessibleDescription(bundle.getString("ACSD_RemoveInfoPanel.btnCommit"));
context = btnViewLog.getAccessibleContext();
context.setAccessibleDescription(bundle.getString("ACSD_RemoveInfoPanel.btnViewLog"));
context = btnStop.getAccessibleContext();
context.setAccessibleDescription(bundle.getString("ACSD_RemoveInfoPanel.btnStop"));
context = tblRemoved.getAccessibleContext();
context.setAccessibleDescription(bundle.getString("ACSD_RemoveInfoPanel.tblRemoved"));
context.setAccessibleName(bundle.getString("ACSN_RemoveInfoPanel.tblRemoved"));
}
/** 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 = tblRemoved.getColumnModel().getColumn(0);
col.setPreferredWidth(100);
// HACK to set the width of column at desired size
// String title = NbBundle.getBundle(RemoveInfoPanel.class).getString("RemoveInfoPanel.dialogTitle");
// setName(title);
setName(command.getName());
stopActionListener = new StopActionListener();
btnStop.addActionListener(stopActionListener);
btnViewLog.setEnabled(false);
btnCommit.setEnabled(false);
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
open();
}
});
/*
dd = new DialogDescriptor(this, title);
String[] options = new String[1];
options[0] = NbBundle.getBundle(RemoveInfoPanel.class).getString("RemoveInfoPanel.stopButton");
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(RemoveInfoPanel.class).getString("RemoveInfoPanel.stopping")); // NOI18N
btnStop.setEnabled(false);
}
command.hardCommandStop();
stopped = true;
// displayOutputData();
}
/** Does the actual display - docking into the javacvs Mode,
* displaying as single Dialog.. whatever.
*/
public void displayOutputData() {
/* if (!isOpened()) {
return;
}
*/
int size;
if (stopped || isRunningFromRuntime()) {
} else {
btnCommit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
performCommit();
}
});
btnCommit.setEnabled(true);
}
btnStop.setText(NbBundle.getBundle(RemoveInfoPanel.class).getString("RemoveInfoPanel.closeButton")); // NOI18N
btnStop.setMnemonic(NbBundle.getBundle(RemoveInfoPanel.class).getString("RemoveInfoPanel.closeButton.mnemonic").charAt(0)); //NOI18N
btnStop.setEnabled(true);
btnStop.removeActionListener(stopActionListener);
btnStop.addActionListener(new CloseActionListener());
btnViewLog.addActionListener(new ViewLogActionListener(btnViewLog));
btnViewLog.setEnabled(true);
/* Object[] options = new Object[size];
final String log = NbBundle.getBundle(RemoveInfoPanel.class).getString("RemoveInfoPanel.logButton");
JButton btnClose = new JButton(NbBundle.getBundle(RemoveInfoPanel.class)
.getString("RemoveInfoPanel.closeButton"));
btnClose.setDefaultCapable(true);
final String commit = NbBundle.getBundle(RemoveInfoPanel.class).getString("RemoveInfoPanel.commitButton");
options[size - 1] = btnClose;
options[size - 2] = log;
if (!stopped && !isRunningFromRuntime()) {
options[0] = commit;
}
Object[] closing = new Object[size - 1];
if (!stopped) closing[0] = options[0];
closing[size - 2] = options[size - 1];
dd.setValue(btnClose); //HACK
dd.setOptions(options);
dd.setClosingOptions(closing); // all are closing
dd.setButtonListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if (evt.getActionCommand().equals(commit)) {
performCommit();
}
if (evt.getActionCommand().equals(log)) {
doShowCommandLog();
}
}
});
*/
JTableHeader head = tblRemoved.getTableHeader();
head.setUpdateTableInRealTime(true);
ColumnSortListener listen = new ColumnSortListener(tblRemoved);
head.addMouseListener(listen);
}
private void performCommit() {
// if (!currentFSCommand.getClientProvider() instanceof IndependantClient) return;
IndependantClient provider = (IndependantClient)command.getClientProvider();
if (provider.isOffLine()) return;
int rowCount = model.getRowCount();
LinkedList fileList = new LinkedList();
for (int index = 0; index < rowCount; index++) {
RemoveInformation removeInfo = (RemoveInformation)model.getElementAt(index);
if (removeInfo.isRemoved()) {
fileList.add(removeInfo.getFile());
}
}
if (fileList.size() > 0) {
File[] fileArray = new File[fileList.size()];
fileArray = (File[])fileList.toArray(fileArray);
FsCommandFactory fact = (FsCommandFactory)FsCommandFactory.getInstance();
CvsCommit myStat = (CvsCommit)fact.createCommand(
CvsCommit.class, true, fileArray, provider);
fact.addIndependantRuntime(myStat);
fact.showCustomizerAndRun(myStat, false, false);
} else {
//TODO.. message??
String noScheduled = NbBundle.getBundle(RemoveInfoPanel.class)
.getString("RemoveInfoPanel.noScheduledAvailable"); // NOI18N
DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(noScheduled));
}
}
/**
* this one is called when the command's execution fails for any reason.
*/
public void showExecutionFailed(Exception exception) {
// if (isOpened()) {
displayOutputData();
// }
}
/**
* 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() {
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();
}
/**
* When the library command's builder generates a FileInfoContainer object, the
* Displayer is notified.
* @param info - the generated information object
*/
public void showFileInfoGenerated(org.netbeans.lib.cvsclient.command.FileInfoContainer info) {
if (info instanceof RemoveInformation) {
model.addElement(info);
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
tblRemoved.changeSelection(model.getRowCount(), 0, false, false);
}
});
}
}
}
|
| ... 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.