Search in sources :

Example 26 with EntryAccessor

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();
}
Also used : Entry(org.freeplane.core.ui.menubuilders.generic.Entry) FreeplaneResourceAccessor(org.freeplane.core.ui.menubuilders.FreeplaneResourceAccessor) EntryAccessor(org.freeplane.core.ui.menubuilders.generic.EntryAccessor) MModeController(org.freeplane.features.mode.mindmapmode.MModeController)

Example 27 with EntryAccessor

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;
}
Also used : Entry(org.freeplane.core.ui.menubuilders.generic.Entry) AFreeplaneAction(org.freeplane.core.ui.AFreeplaneAction) ActionEvent(java.awt.event.ActionEvent) EntryAccessor(org.freeplane.core.ui.menubuilders.generic.EntryAccessor)

Example 28 with EntryAccessor

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;
}
Also used : Entry(org.freeplane.core.ui.menubuilders.generic.Entry) EntryAccessor(org.freeplane.core.ui.menubuilders.generic.EntryAccessor)

Example 29 with EntryAccessor

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);
    }
}
Also used : Entry(org.freeplane.core.ui.menubuilders.generic.Entry) AFreeplaneAction(org.freeplane.core.ui.AFreeplaneAction) FreeplaneResourceAccessor(org.freeplane.core.ui.menubuilders.FreeplaneResourceAccessor) ActionEvent(java.awt.event.ActionEvent) EntryAccessor(org.freeplane.core.ui.menubuilders.generic.EntryAccessor)

Example 30 with EntryAccessor

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);
        }
    }
}
Also used : AFreeplaneAction(org.freeplane.core.ui.AFreeplaneAction) EntryAccessor(org.freeplane.core.ui.menubuilders.generic.EntryAccessor)

Aggregations

EntryAccessor (org.freeplane.core.ui.menubuilders.generic.EntryAccessor)58 Entry (org.freeplane.core.ui.menubuilders.generic.Entry)40 Test (org.junit.Test)35 AFreeplaneAction (org.freeplane.core.ui.AFreeplaneAction)27 JMenu (javax.swing.JMenu)13 Component (java.awt.Component)6 Container (java.awt.Container)6 JMenuItem (javax.swing.JMenuItem)6 JToolBar (javax.swing.JToolBar)4 JButton (javax.swing.JButton)3 JComponent (javax.swing.JComponent)3 JPanel (javax.swing.JPanel)3 FreeplaneMenuBar (org.freeplane.core.ui.components.FreeplaneMenuBar)3 FreeplaneToolBar (org.freeplane.core.ui.components.FreeplaneToolBar)3 FreeplaneResourceAccessor (org.freeplane.core.ui.menubuilders.FreeplaneResourceAccessor)3 JToolbarComponentBuilder (org.freeplane.core.ui.menubuilders.menu.JToolbarComponentBuilder)3 ActionEvent (java.awt.event.ActionEvent)2 KeyStroke (javax.swing.KeyStroke)2 ResourceController (org.freeplane.core.resources.ResourceController)2 ActionEnabler (org.freeplane.core.ui.ActionEnabler)2