|
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-2004 Sun
* Microsystems, Inc. All Rights Reserved.
*/
package org.netbeans.modules.vcs.advanced.commands;
import java.awt.Image;
import java.awt.datatransfer.*;
import java.beans.PropertyEditor;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.ResourceBundle;
import java.util.MissingResourceException;
import org.openide.*;
import org.openide.nodes.*;
import org.openide.actions.*;
import org.openide.util.NbBundle;
import org.openide.util.Utilities;
import org.openide.util.actions.SystemAction;
import org.openide.util.actions.ActionPerformer;
import org.openide.util.datatransfer.NewType;
import org.netbeans.modules.vcscore.cmdline.exec.StructuredExec;
import org.netbeans.modules.vcscore.commands.VcsCommand;
import org.netbeans.modules.vcscore.commands.VcsCommandIO;
import org.netbeans.modules.vcscore.commands.CommandCustomizationSupport;
import org.netbeans.modules.vcscore.cmdline.UserCommand;
import org.netbeans.modules.vcscore.util.Table;
import org.netbeans.modules.vcs.advanced.commands.ConditionedCommandsBuilder.ConditionedPropertiesCommand;
import org.netbeans.modules.vcs.advanced.commands.ConditionedCommandsBuilder.ConditionedProperty;
import org.netbeans.modules.vcs.advanced.commands.ConditionedCommandsBuilder.ConditionedCommand;
import org.netbeans.modules.vcs.advanced.conditioned.ConditionedObject;
import org.netbeans.modules.vcs.advanced.conditioned.ConditionedString;
import org.netbeans.modules.vcs.advanced.conditioned.ConditionedStructuredExecEditor;
import org.netbeans.modules.vcs.advanced.conditioned.IfUnlessCondition;
import org.netbeans.modules.vcs.advanced.variables.Condition;
/**
* The Node representation of a VCS command.
*
* @author Martin Entlicher
*/
public class CommandNode extends AbstractNode {
private static final String DEFAULT_FOLDER = "org/openide/loaders/defaultFolder.gif"; // NOI18N
private static final String DEFAULT_OPEN_FOLDER = "org/openide/loaders/defaultFolderOpen.gif"; // NOI18N
//private static final String DEFAULT_COMMAND = "org/netbeans/modules/vcscore/runtime/commandIcon.gif"; // NOI18N
private static final String DEFAULT_COMMAND = "org/netbeans/modules/vcs/advanced/commands/commandsJmenuItem.gif"; // NOI18N
private static final String DEFAULT_HIDDEN_COMMAND_BADGE = "org/netbeans/modules/vcs/advanced/commands/commandsHiddenBadgeIcon.gif"; // NOI18N
private VcsCommand cmd = null;
private IfUnlessCondition mainCondition = null;
private ConditionedPropertiesCommand cpcommand = null;
private Map cproperties = null;
private ResourceBundle resourceBundle = null;
private CommandsIndex index = null;
private boolean readOnly = false;
private static Table stdandard_propertyClassTypes = new Table();
private static Table expert_propertyClassTypes = new Table();
private static Table list_propertyClassTypes = new Table();
private static Table stdlist_propertyClassTypes = new Table();
private static Table folder_std_propertyClassTypes = new Table();
private static Collection FOLDER_COMMAND_PROPERTIES;
private static Collection stdlistCmdNames;
private static Image[] SEPARATOR_ICONS = new Image[4];
static {
stdandard_propertyClassTypes.put(VcsCommand.PROPERTY_LABEL_MNEMONIC, String.class);
//stdandard_propertyClassTypes.put(VcsCommand.PROPERTY_EXEC, String.class);
stdandard_propertyClassTypes.put(VcsCommand.PROPERTY_EXEC_STRUCTURED, StructuredExec.class);
stdandard_propertyClassTypes.put(VcsCommand.PROPERTY_CONFIRMATION_MSG, String.class);
stdandard_propertyClassTypes.put(VcsCommand.PROPERTY_NOTIFICATION_SUCCESS_MSG, String.class);
stdandard_propertyClassTypes.put(VcsCommand.PROPERTY_NOTIFICATION_FAIL_MSG, String.class);
stdandard_propertyClassTypes.put(VcsCommand.PROPERTY_INPUT_DESCRIPTOR, String.class);
//propertyClassTypes.put(VcsCommand.PROPERTY_NOT_ON_ROOT, Boolean.TYPE);
stdandard_propertyClassTypes.put(VcsCommand.PROPERTY_ON_DIR, Boolean.TYPE);
stdandard_propertyClassTypes.put(VcsCommand.PROPERTY_ON_FILE, Boolean.TYPE);
stdandard_propertyClassTypes.put(VcsCommand.PROPERTY_ON_ROOT, Boolean.TYPE);
stdandard_propertyClassTypes.put(VcsCommand.PROPERTY_RUN_ON_MULTIPLE_FILES, Boolean.TYPE);
stdandard_propertyClassTypes.put(VcsCommand.PROPERTY_RUN_ON_MULTIPLE_FILES_IN_FOLDER, Boolean.TYPE);
stdandard_propertyClassTypes.put(UserCommand.PROPERTY_REFRESH_PROCESSED_FILES, Boolean.TYPE);
stdandard_propertyClassTypes.put(VcsCommand.PROPERTY_REFRESH_CURRENT_FOLDER, Boolean.TYPE);
stdandard_propertyClassTypes.put(VcsCommand.PROPERTY_REFRESH_PARENT_FOLDER, Boolean.TYPE);
stdandard_propertyClassTypes.put(VcsCommand.PROPERTY_REFRESH_ON_FAIL, Integer.TYPE);
stdandard_propertyClassTypes.put(VcsCommand.PROPERTY_DISPLAY_PLAIN_OUTPUT, Boolean.TYPE);
stdandard_propertyClassTypes.put(VcsCommand.PROPERTY_DISPLAY_INTERACTIVE_OUTPUT, Boolean.TYPE);
stdandard_propertyClassTypes.put(VcsCommand.PROPERTY_DISTINGUISH_BINARY_FILES, Boolean.TYPE);
expert_propertyClassTypes.put(VcsCommand.PROPERTY_ADVANCED_NAME, String.class);
expert_propertyClassTypes.put(VcsCommand.PROPERTY_SUPPORTS_ADVANCED_MODE, Boolean.TYPE);
expert_propertyClassTypes.put(VcsCommand.PROPERTY_HIDDEN, Boolean.TYPE);
expert_propertyClassTypes.put(VcsCommand.PROPERTY_HIDDEN_TEST_EXPRESSION, String.class);
expert_propertyClassTypes.put(VcsCommand.PROPERTY_DISABLED_ON_STATUS, String.class);
expert_propertyClassTypes.put(VcsCommand.PROPERTY_DISABLED_WHEN_NOT_LOCKED, Boolean.TYPE);
expert_propertyClassTypes.put(VcsCommand.PROPERTY_CONCURRENT_EXECUTION, Integer.TYPE);
expert_propertyClassTypes.put(VcsCommand.PROPERTY_EXEC_PRIORITY, Integer.TYPE);
expert_propertyClassTypes.put(VcsCommand.PROPERTY_PROCESS_ALL_FILES, Boolean.TYPE);
expert_propertyClassTypes.put(VcsCommand.PROPERTY_CLEAN_UNIMPORTANT_FILES_ON_SUCCESS, Boolean.TYPE);
expert_propertyClassTypes.put(VcsCommand.PROPERTY_NEEDS_HIERARCHICAL_ORDER, Boolean.TYPE);
expert_propertyClassTypes.put(VcsCommand.PROPERTY_IGNORE_FAIL, Boolean.TYPE);
expert_propertyClassTypes.put(VcsCommand.PROPERTY_REFRESH_RECURSIVELY_PATTERN_MATCHED, String.class);
expert_propertyClassTypes.put(VcsCommand.PROPERTY_REFRESH_RECURSIVELY_PATTERN_UNMATCHED, String.class);
expert_propertyClassTypes.put(VcsCommand.PROPERTY_CHECK_FOR_MODIFICATIONS, Boolean.TYPE);
expert_propertyClassTypes.put(UserCommand.PROPERTY_DATA_REGEX, String.class);
expert_propertyClassTypes.put(UserCommand.PROPERTY_ERROR_REGEX, String.class);
expert_propertyClassTypes.put(UserCommand.PROPERTY_DATA_REGEX_GLOBAL, String.class);
expert_propertyClassTypes.put(UserCommand.PROPERTY_ERROR_REGEX_GLOBAL, String.class);
expert_propertyClassTypes.put(UserCommand.PROPERTY_INPUT, String.class);
expert_propertyClassTypes.put(UserCommand.PROPERTY_INPUT_REPEAT, Boolean.TYPE);
expert_propertyClassTypes.put(VcsCommand.PROPERTY_NUM_REVISIONS, Integer.TYPE);
expert_propertyClassTypes.put(VcsCommand.PROPERTY_CHANGED_REVISION_VAR_NAME, String.class);
expert_propertyClassTypes.put(VcsCommand.PROPERTY_CHANGING_NUM_REVISIONS, Boolean.TYPE);
expert_propertyClassTypes.put(VcsCommand.PROPERTY_CHANGING_REVISION, Boolean.TYPE);
expert_propertyClassTypes.put(VcsCommand.PROPERTY_USER_PARAMS, String[].class);
expert_propertyClassTypes.put(VcsCommand.PROPERTY_LOAD_ATTRS_TO_VARS, String[].class);
expert_propertyClassTypes.put(VcsCommand.PROPERTY_GENERAL_COMMAND_ACTION_CLASS_NAME, String.class);
expert_propertyClassTypes.put(VcsCommand.PROPERTY_GENERAL_COMMAND_ACTION_DISPLAY_NAME, String.class);
expert_propertyClassTypes.put(VcsCommand.PROPERTY_DISPLAY_VISUALIZER, String.class);
expert_propertyClassTypes.put(VcsCommand.PROPERTY_PRE_COMMANDS, String.class);
expert_propertyClassTypes.put(VcsCommand.PROPERTY_COMMANDS_AFTER_SUCCESS, String.class);
expert_propertyClassTypes.put(VcsCommand.PROPERTY_COMMANDS_AFTER_FAIL, String.class);
list_propertyClassTypes.put(UserCommand.PROPERTY_LIST_INDEX_FILE_NAME, Integer.TYPE);
list_propertyClassTypes.put(UserCommand.PROPERTY_LIST_INDEX_REMOVED_FILE_NAME, Integer.TYPE);
list_propertyClassTypes.put(UserCommand.PROPERTY_REFRESH_FILE_RELATIVE_PATH, String.class);
list_propertyClassTypes.put(UserCommand.PROPERTY_LIST_INDEX_STATUS, Integer.TYPE);
list_propertyClassTypes.put(UserCommand.PROPERTY_REFRESH_FILE_STATUS_SUBSTITUTIONS, String.class);
list_propertyClassTypes.put(UserCommand.PROPERTY_LIST_INDEX_LOCKER, Integer.TYPE);
list_propertyClassTypes.put(UserCommand.PROPERTY_LIST_INDEX_REVISION, Integer.TYPE);
list_propertyClassTypes.put(UserCommand.PROPERTY_LIST_INDEX_STICKY, Integer.TYPE);
list_propertyClassTypes.put(UserCommand.PROPERTY_LIST_INDEX_TIME, Integer.TYPE);
list_propertyClassTypes.put(UserCommand.PROPERTY_LIST_INDEX_DATE, Integer.TYPE);
list_propertyClassTypes.put(UserCommand.PROPERTY_LIST_INDEX_SIZE, Integer.TYPE);
list_propertyClassTypes.put(UserCommand.PROPERTY_LIST_INDEX_ATTR, Integer.TYPE);
list_propertyClassTypes.put(UserCommand.PROPERTY_REFRESH_INFO_FROM_BOTH_DATA_OUTS, Boolean.TYPE);
stdlist_propertyClassTypes.put(UserCommand.PROPERTY_LIST_INDEX_FILE_NAME, Integer.TYPE);
stdlist_propertyClassTypes.put(UserCommand.PROPERTY_LIST_INDEX_STATUS, Integer.TYPE);
stdlist_propertyClassTypes.put(UserCommand.PROPERTY_LIST_INDEX_LOCKER, Integer.TYPE);
stdlist_propertyClassTypes.put(UserCommand.PROPERTY_LIST_INDEX_REVISION, Integer.TYPE);
stdlist_propertyClassTypes.put(UserCommand.PROPERTY_LIST_INDEX_STICKY, Integer.TYPE);
stdlist_propertyClassTypes.put(UserCommand.PROPERTY_LIST_INDEX_TIME, Integer.TYPE);
stdlist_propertyClassTypes.put(UserCommand.PROPERTY_LIST_INDEX_DATE, Integer.TYPE);
stdlist_propertyClassTypes.put(UserCommand.PROPERTY_LIST_INDEX_SIZE, Integer.TYPE);
stdlist_propertyClassTypes.put(UserCommand.PROPERTY_LIST_INDEX_ATTR, Integer.TYPE);
stdlistCmdNames = Collections.unmodifiableList(Arrays.asList(new String[] {
VcsCommand.NAME_REFRESH,
VcsCommand.NAME_REFRESH + VcsCommand.NAME_SUFFIX_OFFLINE,
VcsCommand.NAME_REFRESH_RECURSIVELY,
VcsCommand.NAME_REFRESH_RECURSIVELY + VcsCommand.NAME_SUFFIX_OFFLINE
}));
folder_std_propertyClassTypes.put(VcsCommand.PROPERTY_LABEL_MNEMONIC, String.class);
FOLDER_COMMAND_PROPERTIES = new HashSet();
FOLDER_COMMAND_PROPERTIES.add(VcsCommand.PROPERTY_LABEL_MNEMONIC);
}
/** Creates new CommandNode */
public CommandNode(Children children, VcsCommand cmd) {
this(children, cmd, null, null);
}
/** Creates new CommandNode */
public CommandNode(Children children, VcsCommand cmd, Condition condition, ConditionedPropertiesCommand cpcommand) {
super(children);
this.cmd = cmd;
this.cpcommand = cpcommand;
if (condition != null || cpcommand != null) {
mainCondition = new IfUnlessCondition(condition);
if (cmd != null) {
mainCondition.setConditionName(cmd.getName());
}
}
if (cpcommand != null) {
ConditionedProperty[] properties = cpcommand.getConditionedProperties();
cproperties = new HashMap();
if (properties != null) {
for (int i = 0; i < properties.length; i++) {
cproperties.put(properties[i].getName(), properties[i]);
}
}
}
init();
}
private void init() {
if (cmd != null) {
setDisplayName(cmd.getDisplayName());
setShortDescription(NbBundle.getMessage(CommandNode.class, "CommandNode.Description",
(cmd.getDisplayName() == null) ? cmd.getName() : cmd.getDisplayName()));
} else {
setName("SEPARATOR");
setDisplayName(g("CTL_Separator"));
setShortDescription(g("CTL_SeparatorName"));
}
index = new CommandsIndex();
getCookieSet().add(index);
fireIconChange();
}
public void setReadOnly(boolean readOnly) {
this.readOnly = readOnly;
}
public void setName(String name) {
if (cmd != null) {// && !name.equals(cmd.getDisplayName())) {
String displayName = cmd.getDisplayName();
if (displayName == null) {
cmd.setName(name);
setDisplayName(null);
// Necessary to refresh the "Name" property
firePropertyChange("name", null, name);
} else {
cmd.setDisplayName(name);
setDisplayName(name);
// Necessary to refresh the "Name" property
firePropertyChange("label", null, name);
}
// Necessary to refresh the name of the Node
fireNameChange(null, name);
} else {
super.setName(name);
}
}
public String getName() {
if (cmd != null) {
String displayName = cmd.getDisplayName();
if (displayName == null) {
return cmd.getName();
} else {
return displayName;
}
} else {
return super.getName();
}
}
public void setDisplayName(String s) {
if (s == null && cmd != null) {
s = NbBundle.getMessage(CommandNode.class, "LBL_HiddenCommandName", cmd.getName());
}
super.setDisplayName(s);
}
/**
* Get the Class type of the known command properties.
* @return the class type or null, when the property is not known
*/
public static Class getPropertyClass(String propertyName) {
Class clazz = (Class) stdandard_propertyClassTypes.get(propertyName);
if (clazz != null) return clazz;
clazz = (Class) expert_propertyClassTypes.get(propertyName);
if (clazz != null) return clazz;
clazz = (Class) list_propertyClassTypes.get(propertyName);
if (clazz != null) return clazz;
return null;
}
public void setCommand(VcsCommand cmd) {
this.cmd = cmd;
init();
}
public VcsCommand getCommand() {
return cmd;
}
public Collection getConditionedProperties() {
if (cproperties != null) {
return cproperties.values();
/*
ConditionedPropertiesCommand newCPCommand = new ConditionedPropertiesCommand(cpcommand.getCommand());
for (Iterator it = cproperties.values().iterator(); it.hasNext(); ) {
ConditionedProperty cproperty = (ConditionedProperty) it.next();
newCPCommand.addConditionedProperty(cproperty);
}
return newCPCommand;
*/
} else {
return null;
}
}
public Condition getMainCondition() {
if (mainCondition != null) {
return mainCondition.getCondition();
} else {
return null;
}
}
/**
* Get the collection of names of all commands.
*/
public Collection getAllCommandsNames() {
CommandNode root = this;
while (root.getParentNode() != null) root = (CommandNode) root.getParentNode();
ArrayList commandNames = new ArrayList();
fillCommandNames(root, commandNames);
return commandNames;
}
private static void fillCommandNames(CommandNode node, Collection commandNames) {
VcsCommand cmd = node.getCommand();
if (cmd != null) commandNames.add(cmd.getName());
Node[] subNodes = node.getChildren().getNodes();
for (int i = 0; i < subNodes.length; i++) {
fillCommandNames((CommandNode) subNodes[i], commandNames);
}
}
private Image getSeparatorIcon(int type) {
Image icon;
if (java.beans.BeanInfo.ICON_MONO_16x16 == type) {
if (SEPARATOR_ICONS[0] == null) {
try {
SEPARATOR_ICONS[0] = java.beans.Introspector.getBeanInfo(javax.swing.JSeparator.class).getIcon(type);
} catch (java.beans.IntrospectionException exc) {}
}
icon = SEPARATOR_ICONS[0];
} else if (java.beans.BeanInfo.ICON_MONO_32x32 == type) {
if (SEPARATOR_ICONS[1] == null) {
try {
SEPARATOR_ICONS[1] = java.beans.Introspector.getBeanInfo(javax.swing.JSeparator.class).getIcon(type);
} catch (java.beans.IntrospectionException exc) {}
}
icon = SEPARATOR_ICONS[1];
} else if (java.beans.BeanInfo.ICON_COLOR_16x16 == type) {
if (SEPARATOR_ICONS[2] == null) {
try {
SEPARATOR_ICONS[2] = java.beans.Introspector.getBeanInfo(javax.swing.JSeparator.class).getIcon(type);
} catch (java.beans.IntrospectionException exc) {}
}
icon = SEPARATOR_ICONS[2];
} else if (java.beans.BeanInfo.ICON_COLOR_32x32 == type) {
if (SEPARATOR_ICONS[3] == null) {
try {
SEPARATOR_ICONS[3] = java.beans.Introspector.getBeanInfo(javax.swing.JSeparator.class).getIcon(type);
} catch (java.beans.IntrospectionException exc) {}
}
icon = SEPARATOR_ICONS[3];
} else icon = null;
if (icon != null) {
return icon;
} else {
return super.getIcon(type);
}
}
/** Find an icon for this node.
*
* @param type constants from {@link java.beans.BeanInfo}
*
* @return icon to use to represent the bean
*/
public Image getIcon (int type) {
//System.out.println("getIcon("+type+"): cmd = "+cmd);
if (cmd == null) {
return getSeparatorIcon(type);
} else if (isFolderCommand(cmd)) {
return Utilities.loadImage(DEFAULT_FOLDER);
} else {
if (cmd.getDisplayName() == null) {
return Utilities.mergeImages(Utilities.loadImage(DEFAULT_COMMAND), Utilities.loadImage(DEFAULT_HIDDEN_COMMAND_BADGE), 16, 8);
} else {
return Utilities.loadImage(DEFAULT_COMMAND);
}
}
}
public Image getOpenedIcon(int type) {
//System.out.println("getOpenedIcon("+type+"): cmd = "+cmd);
return Utilities.loadImage(DEFAULT_OPEN_FOLDER);
}
public boolean canCopy() {
return (getParentNode() != null);
}
public boolean canCut() {
return (getParentNode() != null);
}
/** Copy this node to the clipboard.
*
* @return The transferable for VcsCommand
* @throws IOException if it could not copy
*/
public Transferable clipboardCopy() throws java.io.IOException {
return new CommandCopySupport.CommandTransferable(
CommandCopySupport.COMMAND_COPY_FLAVOR, this);
}
/** Cut this node to the clipboard.
*
* @return {@link Transferable} with one flavor, {@link COMMAND_CUT_FLAVOR }
* @throws IOException if it could not cut
*/
public Transferable clipboardCut() throws java.io.IOException {
return new CommandCopySupport.CommandTransferable(
CommandCopySupport.COMMAND_CUT_FLAVOR, this);
}
/** Accumulate the paste types that this node can handle
* for a given transferable.
*
|
| ... 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.