use of alma.acs.commandcenter.util.VariableString.UnresolvableException in project ACS by ACS-Community.
the class CommandCenterGui method addExtraTool.
/**
* Adds an entry to the tools menu, on activation an input dialog is shown and
* evaluated. Finally the specified listener is triggered.
*/
public void addExtraTool(Tool tool, final HashMap<String, Object> result, final ExecuteTools.ToolStarter ts) {
// --- create an input dialog
final ToolInputPanel tp = new ToolInputPanel(this, tool);
// --- create an action that shows the input panel (if needed) and runs the tool
// make up the pretty names to show in the gui
final String cap = tool.getCaption();
// menu text: append three dots if user has to give input
String menuCaption = (tp.counter == 0) ? cap : cap + "...";
// tab text: shorten if too long
final String tabCaption = (cap.length() < 15) ? cap : cap.substring(0, 8) + "..." + cap.substring(cap.length() - 4);
Action a = new AbstractAction(menuCaption) {
public void actionPerformed(ActionEvent evt) {
// only show if panel contains more than zero lines
if (tp.counter > 0) {
boolean ok = tp.showPanel();
if (!ok) {
// user cancelled the dialog
return;
}
// read results from dialog
Map<String, String> map = tp.evaluate();
result.putAll(map);
}
NativeCommand.Listener listener = giveOutputListener(tabCaption);
try {
ts.start(listener);
} catch (UnresolvableException exc) {
String var = exc.getVariableName();
controller.handleUnresolvableVariable(var);
log.log(Level.INFO, "Couldn't start tool '" + cap + "': Variable '" + var + "' is undefined");
} catch (Throwable t) {
log.info("Couldn't start tool '" + cap + "', check definition file; reason was: " + t);
}
}
};
// append the action to the tools menu
JMenuItem mi = toolsMenu.add(a);
addedToolMenuItems.add(mi);
}
Aggregations