use of org.freeplane.core.ui.menubuilders.generic.EntryAccessor in project freeplane by freeplane.
the class AddOnDetailsPanel method formatMenuLocation.
private String formatMenuLocation(ScriptAddOnProperties.Script script) {
final MModeController modeController = (MModeController) Controller.getCurrentModeController();
Entry top = modeController.getUserInputListenerFactory().getGenericMenuStructure();
final String canonicalPath = entryNavigator.replaceAliases(script.menuLocation);
final String[] pathElements = canonicalPath.split("/");
Entry entry = top;
final ListIterator<String> pathIterator = Arrays.asList(pathElements).listIterator();
while (pathIterator.hasNext()) {
String name = pathIterator.next();
if (!name.isEmpty()) {
final Entry child = entry.getChild(name);
if (child == null) {
pathIterator.previous();
break;
}
entry = child;
}
}
if (entry == null)
return script.menuLocation;
final FreeplaneResourceAccessor resourceAccessor = new FreeplaneResourceAccessor();
final EntryAccessor entryAccessor = new EntryAccessor(resourceAccessor);
final String entryLocationDescription = entryAccessor.getLocationDescription(entry);
if (!pathIterator.hasNext())
return entryLocationDescription;
StringBuilder menuLocationDescription = new StringBuilder(entryLocationDescription);
while (pathIterator.hasNext()) {
menuLocationDescription.append(EntryAccessor.MENU_ELEMENT_SEPARATOR);
menuLocationDescription.append(ScriptingMenuUtils.scriptNameToMenuItemTitle(pathIterator.next()));
}
return menuLocationDescription.toString();
}
use of org.freeplane.core.ui.menubuilders.generic.EntryAccessor in project freeplane by freeplane.
the class ScriptingMenuEntryVisitor method createNoScriptsAvailableAction.
private Entry createNoScriptsAvailableAction() {
final Entry entry = new Entry();
entry.setName("NoScriptsAvailableAction");
@SuppressWarnings("serial") final AFreeplaneAction noScriptsAvailableAction = new AFreeplaneAction("NoScriptsAvailableAction", noScriptsAvailableMessage(), null) {
@Override
public void actionPerformed(ActionEvent e) {
}
};
new EntryAccessor().setAction(entry, noScriptsAvailableAction);
return entry;
}
use of org.freeplane.core.ui.menubuilders.generic.EntryAccessor in project freeplane by freeplane.
the class ScriptingMenuEntryVisitor method createEntry.
private Entry createEntry(AFreeplaneAction action) {
final EntryAccessor entryAccessor = new EntryAccessor();
final Entry scriptEntry = new Entry();
scriptEntry.setName(action.getKey());
// System.err.println("registering " + scriptEntry.getName());
entryAccessor.setAction(scriptEntry, action);
return scriptEntry;
}
use of org.freeplane.core.ui.menubuilders.generic.EntryAccessor in project freeplane by freeplane.
the class MenuUtils method executeMenuItems.
/**
* to be used from scripts to execute menu items. Find out the menuItemKey
* of a menu item with the devtools add-on. It contains a tool for that.
*/
public static void executeMenuItems(final List<String> menuItemKeys) {
LogUtils.info("menu items to execute: " + menuItemKeys);
final Entry genericMenuStructure = genericMenuStructure();
final EntryAccessor entryAccessor = new EntryAccessor(new FreeplaneResourceAccessor());
for (String menuItemKey : menuItemKeys) {
Entry menuItem = genericMenuStructure.findEntry(menuItemKey);
final AFreeplaneAction action = menuItem != null ? entryAccessor.getAction(menuItem) : null;
if (action == null) {
UITools.errorMessage(TextUtils.format("MenuUtils.invalid_menuitem", menuItemKey));
return;
}
LogUtils.info("executing " + ActionUtils.getActionTitle(action) + "(" + menuItemKey + ")");
ActionEvent e = new ActionEvent(menuItem, 0, null);
action.actionPerformed(e);
}
}
use of org.freeplane.core.ui.menubuilders.generic.EntryAccessor in project freeplane by freeplane.
the class ConditionalActionBuilder method visit.
@Override
public void visit(Entry target) {
final String property = (String) target.getAttribute("property");
if (ResourceController.getResourceController().getBooleanProperty(property, false)) {
try {
final String keyName = (String) target.getAttribute("actionKey");
final AFreeplaneAction existingAction = freeplaneActions.getAction(keyName);
final AFreeplaneAction action;
if (existingAction != null)
action = existingAction;
else {
final String className = (String) target.getAttribute("actionClass");
final Class<?> classDefinition = getClass().getClassLoader().loadClass(className);
action = (AFreeplaneAction) classDefinition.newInstance();
freeplaneActions.addAction(action);
}
new EntryAccessor().setAction(target, action);
return;
} catch (Exception e) {
LogUtils.severe(e);
}
}
}
Aggregations