Java 类org.eclipse.core.commands.CommandManager 实例源码

项目:translationstudio8    文件:KeyController2.java   
private static BindingManager loadModelBackend(IServiceLocator locator) {
    IBindingService bindingService = (IBindingService) locator.getService(IBindingService.class);
    BindingManager bindingManager = new BindingManager(new ContextManager(), new CommandManager());
    final Scheme[] definedSchemes = bindingService.getDefinedSchemes();
    try {
        Scheme modelActiveScheme = null;
        for (int i = 0; i < definedSchemes.length; i++) {
            final Scheme scheme = definedSchemes[i];
            final Scheme copy = bindingManager.getScheme(scheme.getId());
            copy.define(scheme.getName(), scheme.getDescription(), scheme.getParentId());
            if (definedSchemes[i] == bindingService.getActiveScheme()) {
                modelActiveScheme = copy;
            }
        }
        bindingManager.setActiveScheme(modelActiveScheme);
    } catch (final NotDefinedException e) {
        StatusManager.getManager()
                .handle(new Status(IStatus.WARNING, WorkbenchPlugin.PI_WORKBENCH,
                        "Keys page found an undefined scheme", e)); //$NON-NLS-1$
    }
    bindingManager.setLocale(bindingService.getLocale());
    bindingManager.setPlatform(bindingService.getPlatform());
    bindingManager.setBindings(bindingService.getBindings());
    return bindingManager;
}
项目:gef-gwt    文件:BindingManager.java   
/**
 * <p>
 * Constructs a new instance of <code>BindingManager</code>.
 * </p>
 * <p>
 * This method completes in amortized constant time (O(1)).
 * </p>
 * 
 * @param contextManager
 *            The context manager that will support this binding manager.
 *            This value must not be <code>null</code>.
 * @param commandManager
 *            The command manager that will support this binding manager.
 *            This value must not be <code>null</code>.
 */
public BindingManager(final ContextManager contextManager,
        final CommandManager commandManager) {
    if (contextManager == null) {
        throw new NullPointerException(
                "A binding manager requires a context manager"); //$NON-NLS-1$
    }

    if (commandManager == null) {
        throw new NullPointerException(
                "A binding manager requires a command manager"); //$NON-NLS-1$
    }

    this.contextManager = contextManager;
    contextManager.addContextManagerListener(this);
    this.commandManager = commandManager;
}
项目:tmxeditor8    文件:KeyController2.java   
private static BindingManager loadModelBackend(IServiceLocator locator) {
    IBindingService bindingService = (IBindingService) locator.getService(IBindingService.class);
    BindingManager bindingManager = new BindingManager(new ContextManager(), new CommandManager());
    final Scheme[] definedSchemes = bindingService.getDefinedSchemes();
    try {
        Scheme modelActiveScheme = null;
        for (int i = 0; i < definedSchemes.length; i++) {
            final Scheme scheme = definedSchemes[i];
            final Scheme copy = bindingManager.getScheme(scheme.getId());
            copy.define(scheme.getName(), scheme.getDescription(), scheme.getParentId());
            if (definedSchemes[i] == bindingService.getActiveScheme()) {
                modelActiveScheme = copy;
            }
        }
        bindingManager.setActiveScheme(modelActiveScheme);
    } catch (final NotDefinedException e) {
        StatusManager.getManager()
                .handle(new Status(IStatus.WARNING, WorkbenchPlugin.PI_WORKBENCH,
                        "Keys page found an undefined scheme", e)); //$NON-NLS-1$
    }
    bindingManager.setLocale(bindingService.getLocale());
    bindingManager.setPlatform(bindingService.getPlatform());
    bindingManager.setBindings(bindingService.getBindings());
    return bindingManager;
}
项目:tmxeditor8    文件:KeyController2.java   
private static BindingManager loadModelBackend(IServiceLocator locator) {
    IBindingService bindingService = (IBindingService) locator.getService(IBindingService.class);
    BindingManager bindingManager = new BindingManager(new ContextManager(), new CommandManager());
    final Scheme[] definedSchemes = bindingService.getDefinedSchemes();
    try {
        Scheme modelActiveScheme = null;
        for (int i = 0; i < definedSchemes.length; i++) {
            final Scheme scheme = definedSchemes[i];
            final Scheme copy = bindingManager.getScheme(scheme.getId());
            copy.define(scheme.getName(), scheme.getDescription(), scheme.getParentId());
            if (definedSchemes[i] == bindingService.getActiveScheme()) {
                modelActiveScheme = copy;
            }
        }
        bindingManager.setActiveScheme(modelActiveScheme);
    } catch (final NotDefinedException e) {
        StatusManager.getManager()
                .handle(new Status(IStatus.WARNING, WorkbenchPlugin.PI_WORKBENCH,
                        "Keys page found an undefined scheme", e)); //$NON-NLS-1$
    }
    bindingManager.setLocale(bindingService.getLocale());
    bindingManager.setPlatform(bindingService.getPlatform());
    bindingManager.setBindings(bindingService.getBindings());
    return bindingManager;
}
项目:relations    文件:BindingModelTest.java   
/**
 * @throws java.lang.Exception
 */
@Before
public void setUp() throws Exception {
    contextManager = new ContextManager();
    commandManager = new CommandManager();
    bindings = new ArrayList<Binding>();

    command1 = commandManager.getCommand(COMMAND_IDS[0]);
    command2 = commandManager.getCommand(COMMAND_IDS[1]);
    command3 = commandManager.getCommand(COMMAND_IDS[2]);
    bindings.add(createBinding(command1, "a", KeySequence.getInstance("M1+A")));
    bindings.add(createBinding(command2, "b", KeySequence.getInstance("M1+B")));
    bindings.add(createBinding(command3, "c", KeySequence.getInstance("M1+C")));

    bindingManager = new BindingManager(contextManager, commandManager);
    bindingManager.addBinding(bindings.get(0));
    bindingManager.addBinding(bindings.get(1));
    bindingManager.addBinding(bindings.get(2));
    final Scheme scheme = bindingManager.getScheme("default");
    scheme.define("myScheme1", "My scheme for testing", null);
    bindingManager.setActiveScheme(scheme);
}
项目:relations    文件:AbstractEditForm.java   
ContributionItemsFactory(final MApplication inApplication,
        final EModelService inModelService,
        final EBindingService inBindingService) {
    items = new ArrayList<StyleContributionItem>();

    final IEclipseContext lContext = inApplication.getContext();
    final CommandManager lCommandManager = lContext
            .get(CommandManager.class);
    final ISWTResourceUtilities lResourceUtility = (ISWTResourceUtilities) lContext
            .get(IResourceUtilities.class.getName());
    final EHandlerService lHandlerService = lContext
            .get(EHandlerService.class);

    final MToolBar lToolbar = (MToolBar) inModelService
            .find(MUI_ID_STYLING_TOOLBAR, inApplication);
    for (final MToolBarElement lElement : lToolbar.getChildren()) {
        if (lElement instanceof MHandledToolItem) {
            final StyleContributionItem lItem = new StyleContributionItem(
                    (MHandledToolItem) lElement, lResourceUtility,
                    inBindingService, lCommandManager, lHandlerService);
            ContextInjectionFactory.inject(lItem, lContext);
            items.add(lItem);
        }
    }
}
项目:gef-gwt    文件:ExternalActionManager.java   
/**
 * Constructs a new instance of <code>CommandCallback</code> with the
 * workbench it should be using. All commands will be considered active.
 * 
 * @param bindingManager
 *            The binding manager which will provide the callback; must
 *            not be <code>null</code>.
 * @param commandManager
 *            The command manager which will provide the callback; must
 *            not be <code>null</code>.
 * 
 * @since 3.1
 */
public CommandCallback(final BindingManager bindingManager,
        final CommandManager commandManager) {
    this(bindingManager, commandManager, new IActiveChecker() {
        public boolean isActive(String commandId) {
            return true;
        }

    }, new IExecuteApplicable() {
        public boolean isApplicable(IAction action) {
            return true;
        }
    });
}
项目:gef-gwt    文件:ExternalActionManager.java   
/**
 * Constructs a new instance of <code>CommandCallback</code> with the
 * workbench it should be using.
 * 
 * @param bindingManager
 *            The binding manager which will provide the callback; must
 *            not be <code>null</code>.
 * @param commandManager
 *            The command manager which will provide the callback; must
 *            not be <code>null</code>.
 * @param activeChecker
 *            The callback mechanism for checking whether a command is
 *            active; must not be <code>null</code>.
 * @param checker
 *            The callback to check if an IAction should fire execution
 *            events.
 * 
 * @since 3.4
 */
public CommandCallback(final BindingManager bindingManager,
        final CommandManager commandManager,
        final IActiveChecker activeChecker,
        final IExecuteApplicable checker) {
    if (bindingManager == null) {
        throw new NullPointerException(
                "The callback needs a binding manager"); //$NON-NLS-1$
    }

    if (commandManager == null) {
        throw new NullPointerException(
                "The callback needs a command manager"); //$NON-NLS-1$
    }

    if (activeChecker == null) {
        throw new NullPointerException(
                "The callback needs an active callback"); //$NON-NLS-1$
    }
    if (checker == null) {
        throw new NullPointerException(
                "The callback needs an applicable callback"); //$NON-NLS-1$
    }

    this.activeChecker = activeChecker;
    this.bindingManager = bindingManager;
    this.commandManager = commandManager;
    this.applicabilityChecker = checker;
}
项目:relations    文件:KeyControllerTest.java   
@Before
public void setUp() throws Exception {
    contextManager = new ContextManager();
    commandManager = new CommandManager();
    bindingManager = new BindingManager(contextManager, commandManager);
    MockitoAnnotations.initMocks(this);

    final Scheme scheme = bindingManager.getScheme(SCHEME_ID);
    scheme.define("scheme:name", "scheme:description", null);
    bindingManager.setActiveScheme(scheme);
    bindingManager.schemeChanged(new SchemeEvent(scheme, true, false, false, false));
    inject(keyController, "commandManager", commandManager);
    inject(keyController, "bindingManagerApp", bindingManager);
}
项目:relations    文件:SaveHelperTest.java   
@Before
public void setUp() throws Exception {
    commandManager = new CommandManager();
    MockitoAnnotations.initMocks(this);

    bindingTable = new TestBindingTable();
}
项目:relations    文件:AbstractEditForm.java   
protected StyleContributionItem(final MHandledToolItem inElement,
        final ISWTResourceUtilities inUtility,
        final EBindingService inBindingService,
        final CommandManager inCommandManager,
        final EHandlerService inHandlerService) {
    super(inElement.getElementId());
    handlerService = inHandlerService;
    icon = inUtility.imageDescriptorFromURI(
            URI.createURI(inElement.getIconURI()));
    tooltip = inElement.getLocalizedTooltip();
    command = createCommand(inElement.getCommand(), inCommandManager);
    sequence = inBindingService.getBestSequenceFor(command);
    style = Styles.getStyle(inElement.getCommand().getElementId());
}
项目:relations    文件:KeyController.java   
private BindingManager loadModelBackend() {
    final BindingManager outManager = new BindingManager(
            new ContextManager(), new CommandManager());
    final Scheme[] definedSchemes = bindingManagerApp.getDefinedSchemes();
    try {
        Scheme modelActiveScheme = null;
        for (int i = 0; i < definedSchemes.length; i++) {
            final Scheme scheme = definedSchemes[i];
            final Scheme copy = outManager.getScheme(scheme.getId());
            copy.define(scheme.getName(), scheme.getDescription(),
                    scheme.getParentId());
            if (definedSchemes[i].getId()
                    .equals(bindingManagerApp.getActiveScheme().getId())) {
                modelActiveScheme = copy;
            }
        }
        outManager.setActiveScheme(modelActiveScheme);
    }
    catch (final NotDefinedException exc) {
        log.error(exc, exc.getMessage());
    }
    outManager.setLocale(bindingManagerApp.getLocale());
    outManager.setPlatform(bindingManagerApp.getPlatform());
    // fill bindings from bindingService to bindingManager instance
    outManager.setBindings(getBindingsFromSrc());
    return outManager;
}
项目:n4js    文件:SelectAllProjectExplorer_PluginUITest.java   
/**
 * Executes the select all command in the currently open workbench.
 */
private void executeSelectAllCommand() throws ExecutionException {
    Command selectAllCommand = PlatformUI.getWorkbench()
            .getService(CommandManager.class).getCommand(IWorkbenchCommandConstants.EDIT_SELECT_ALL);
    selectAllCommand.getHandler().execute(new ExecutionEvent());
}
项目:relations    文件:BindingElementTest.java   
@Before
public void setUp() throws Exception {
    commandManager = new CommandManager();
}
项目:relations    文件:AbstractEditForm.java   
private ParameterizedCommand createCommand(final MCommand inCommand,
        final CommandManager inCommandManager) {
    return new ParameterizedCommand(
            inCommandManager.getCommand(inCommand.getElementId()),
            null);
}
项目:relations    文件:BindingModel.java   
/**
 * Initializes the model.
 *
 * @param bindingManager
 *            {@link BindingManager}
 * @param commandManager
 *            {@link CommandManager}
 * @param bindingTables
 *            List&lt;MBindingTable>
 * @param contextModel
 *            {@link ContextModel}
 * @return {@link BindingModel} the instance
 */
@SuppressWarnings("unchecked")
public BindingModel init(BindingManager bindingManager,
        CommandManager commandManager, List<MBindingTable> bindingTables,
        ContextModel contextModel) {
    this.bindingManager = bindingManager;
    bindingToElement = new HashMap<Binding, BindingElement>();
    commandToElement = new HashMap<ParameterizedCommand, BindingElement>();
    bindingElements = new HashSet<BindingElement>();

    final Set<ParameterizedCommand> cmdsForBindings = new HashSet<ParameterizedCommand>();
    final Iterator<Binding> bindings = bindingManager
            .getActiveBindingsDisregardingContextFlat().iterator();
    while (bindings.hasNext()) {
        final Binding binding = bindings.next();
        final BindingElement element = new BindingElement(getController());
        element.init(binding, contextModel);
        element.setParent(this);
        bindingElements.add(element);
        bindingToElement.put(binding, element);
        cmdsForBindings.add(binding.getParameterizedCommand());
    }

    final Set<String> commandIds = commandManager.getDefinedCommandIds();
    allParameterizedCommands = new HashSet<ParameterizedCommand>();
    final Iterator<String> commandIdItr = commandIds.iterator();
    while (commandIdItr.hasNext()) {
        final String currentCommandId = commandIdItr.next();
        final Command currentCommand = commandManager
                .getCommand(currentCommandId);
        try {
            allParameterizedCommands.addAll(
                    CommandHelper.generateCombinations(currentCommand));
        }
        catch (final NotDefinedException exc) {
            // It is safe to just ignore undefined commands.
        }
    }

    final Iterator<ParameterizedCommand> commands = allParameterizedCommands
            .iterator();
    while (commands.hasNext()) {
        final ParameterizedCommand command = commands.next();
        if (!cmdsForBindings.contains(command)) {
            final BindingElement bindingElement = new BindingElement(
                    getController());
            bindingElement.init(command);
            bindingElement.setParent(this);
            bindingElements.add(bindingElement);
            commandToElement.put(command, bindingElement);
        }
    }

    return this;
}
项目:gef-gwt    文件:ExternalActionManager.java   
/**
 * Constructs a new instance of <code>CommandCallback</code> with the
 * workbench it should be using.
 * 
 * @param bindingManager
 *            The binding manager which will provide the callback; must
 *            not be <code>null</code>.
 * @param commandManager
 *            The command manager which will provide the callback; must
 *            not be <code>null</code>.
 * @param activeChecker
 *            The callback mechanism for checking whether a command is
 *            active; must not be <code>null</code>.
 * 
 * @since 3.1
 */
public CommandCallback(final BindingManager bindingManager,
        final CommandManager commandManager,
        final IActiveChecker activeChecker) {
    this(bindingManager, commandManager, activeChecker,
            new IExecuteApplicable() {
                public boolean isApplicable(IAction action) {
                    return true;
                }
            });
}