}
});
popup.add(addValueItem);
}
} else if (path.getLastPathComponent() instanceof NamedValueProperty) {
final NamedValueProperty p = (NamedValueProperty) path.getLastPathComponent();
if (!p.isFixedCardinality()) {
JMenuItem addValueItem = new JMenuItem("Add");
addValueItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent E) {
String name = JOptionPane.showInputDialog(myTree, "Value Name");
myModel.addValue(path, getValue(p.getType()), name);
}
});
popup.add(addValueItem);
}
} else if (path.getParentPath() != null && path.getParentPath().getLastPathComponent() instanceof Property) {
final Property p = (Property) path.getParentPath().getLastPathComponent();
if (p.isMutable() && !MainHandler.getInstance().canHandle(p.getType())) {
final JMenuItem replaceValueItem = new JMenuItem("Replace");
replaceValueItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Class<?> currentType = ((Value) path.getLastPathComponent()).getObject().getClass();
Object o = NewConfigurableDialog.showDialog(replaceValueItem, p.getType(), currentType);
if (o != null) {
try {
myModel.setValue(path, o);
} catch (StructuralException ex) {
ConfigExceptionHandler.handle(ex, ex.getMessage(), event.getComponent());
}
}
}
});
popup.add(replaceValueItem);
}
if (!p.isFixedCardinality()) {
if (p instanceof ListProperty) {
JMenuItem insertValueItem = new JMenuItem("Insert");
insertValueItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
myModel.insertValue(path, getValue(p.getType()));
}
});
popup.add(insertValueItem);
}
JMenuItem removeValueItem = new JMenuItem("Remove");
removeValueItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
myModel.removeValue(path);
}
});
popup.add(removeValueItem);
}
}
JMenuItem refreshItem = new JMenuItem("Refresh");
refreshItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
myModel.refresh(path);
}
});
popup.add(refreshItem);
//property help on either property or property value ...
Property property = null;
if (path.getParentPath() != null && path.getParentPath().getLastPathComponent() instanceof Property) {
property = (Property) path.getParentPath().getLastPathComponent();
} else if (path.getLastPathComponent() instanceof Property) {
property = (Property) path.getLastPathComponent();
}
if (property != null) {
JMenuItem helpItem = new JMenuItem("Help");
final Property p = property;
helpItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String documentation = p.getDocumentation();
if (documentation != null)
ConfigUtil.showHelp(documentation);
}
});
popup.add(helpItem);