|
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-2000 Sun
* Microsystems, Inc. All Rights Reserved.
*/
package org.netbeans.modules.vcscore;
import java.awt.event.ActionListener;
import java.lang.ref.WeakReference;
import java.util.*;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import org.openide.awt.Actions;
import org.openide.awt.JInlineMenu;
import org.openide.awt.JMenuPlus;
import org.openide.filesystems.*;
import org.openide.nodes.*;
import org.openide.util.HelpCtx;
import org.openide.util.NbBundle;
import org.openide.util.actions.*;
import org.netbeans.spi.vcs.commands.CommandSupport;
import org.netbeans.modules.vcscore.VcsFileSystem;
import org.netbeans.modules.vcscore.Variables;
import org.netbeans.modules.vcscore.cmdline.UserCommandSupport;
import org.netbeans.modules.vcscore.commands.*;
import org.netbeans.modules.vcscore.util.Table;
import org.netbeans.modules.vcscore.util.VcsUtilities;
import org.netbeans.modules.vcscore.util.WeakList;
import org.netbeans.modules.vcscore.versioning.RevisionItem;
/**
*
* @author Martin Entlicher
*/
public class VcsRevisionAction extends NodeAction implements ActionListener, Runnable {
protected WeakReference fileSystem = new WeakReference(null);
protected WeakReference fileObject = new WeakReference(null);
protected Collection selectedRevisionItems = null;
private String commandName;
private static final long serialVersionUID = 8803248742536265293L;
//private VcsFileSystem fileSystem = null;
//private FileObject fo = null;
//private Hashtable additionalVars = new Hashtable();
//private VcsCommand openRevisionCommand = null;
/** Creates new RevisionAction
* Gets revision actions from filesystem and acts on a file object.
* Both the filesystem and file object are obtained from the revision node.
*/
public VcsRevisionAction() {
}
/* Creates new RevisionAction
* Gets revision actions from filesystem and acts on the givn file object.
* @param fileSystem the file system to get the actions from
* @param fo the file object to act on
*
public RevisionAction(VcsFileSystem fileSystem, FileObject fo) {
this.fileSystem = fileSystem;
this.fo = fo;
}
*/
public void setFileSystem(VcsFileSystem fileSystem) {
this.fileSystem = new WeakReference(fileSystem);
}
public void setFileObject(FileObject fileObject) {
this.fileObject = new WeakReference(fileObject);
}
public void setSelectedRevisionItems(Collection items) {
if (items == null) {
this.selectedRevisionItems = null;
return ;
}
this.selectedRevisionItems = new WeakList(items);
}
public String getName(){
return NbBundle.getMessage(VcsRevisionAction.class, "CTL_Revision_Action"); // NOI18N
}
/**
* @return false to run in AWT thread.
*/
protected boolean asynchronous() {
return false;
}
//-------------------------------------------
public void performAction(Node[] nodes){
//D.deb("performAction()"); // NOI18N
}
//-------------------------------------------
public boolean enable(Node[] nodes){
//D.deb("enable()"); // NOI18N
return nodes.length > 0;
}
//-------------------------------------------
public HelpCtx getHelpCtx(){
return new HelpCtx(VcsRevisionAction.class);
}
protected JMenuItem createItem(VcsCommand cmd) {
JMenuItem item = null;
/*
if (cmd == null) {
//E.err("Command "+name+" not configured."); // NOI18N
item = new JMenuItem("'"+name+"' not configured.");
item.setEnabled(false);
return item;
}
*/
//Hashtable vars = fileSystem.getVariablesAsHashtable();
//String label = cmd.getDisplayName();
/*
if (label.indexOf('$') >= 0) {
label = Variables.expandFast(vars, label, true);
}
*/
item = new JMenuItem();
Actions.setMenuText(item, cmd.getDisplayName(), false);
String[] props = cmd.getPropertyNames();
if (props != null && props.length > 0) {
item.setActionCommand(cmd.getName());
item.addActionListener(this);
}
return item;
}
/**
* Add a popup submenu.
*/
private void addMenu(CommandsTree commands, JMenu parent, int numSelected) {
//Children children = commands.getChildren();
CommandsTree[] subCommands = commands.children();
for (int i = 0; i < subCommands.length; i++) {
//Node child = (Node) subnodes.nextElement();
//VcsCommand cmd = (VcsCommand) child.getCookie(VcsCommand.class);
CommandSupport cmdSupp = subCommands[i].getCommandSupport();
if (!(cmdSupp instanceof UserCommandSupport)) continue;
VcsCommand cmd = ((UserCommandSupport) cmdSupp).getVcsCommand();
if (cmd == null) {
parent.addSeparator();
continue;
}
int numRev = VcsCommandIO.getIntegerPropertyAssumeZero(cmd, VcsCommand.PROPERTY_NUM_REVISIONS);
if (numRev != numSelected
|| VcsCommandIO.getBooleanPropertyAssumeDefault(cmd, VcsCommand.PROPERTY_HIDDEN)
|| cmd.getDisplayName() == null) continue;
if (subCommands[i].hasChildren()) {
JMenu submenu;
String[] props = cmd.getPropertyNames();
//if (props == null || props.length == 0) {
// submenu = new JMenuPlus(cmd.getDisplayName());
//} else {
submenu = new JMenuPlus();
//}
Actions.setMenuText(submenu, cmd.getDisplayName(), false);
addMenu(subCommands[i], submenu, numSelected);
parent.add(submenu);
} else {
JMenuItem item = createItem(cmd);
parent.add(item);
}
}
}
/**
* Get a menu item that can present this action in a
|
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 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.