Search in sources :

Example 6 with ParameterizedCommand

use of org.eclipse.core.commands.ParameterizedCommand in project translationstudio8 by heartsome.

the class KeyController2 method setDefaultBindings.

/**
	 * Sets the bindings to default.
	 * @param bindingService
	 * @throws NotDefinedException
	 */
public void setDefaultBindings(IBindingService bindingService, List<String> lstRemove) throws NotDefinedException {
    // Fix the scheme in the local changes.
    final String defaultSchemeId = bindingService.getDefaultSchemeId();
    final Scheme defaultScheme = fBindingManager.getScheme(defaultSchemeId);
    try {
        fBindingManager.setActiveScheme(defaultScheme);
    } catch (final NotDefinedException e) {
    // At least we tried....
    }
    // Restore any User defined bindings
    Binding[] bindings = fBindingManager.getBindings();
    for (int i = 0; i < bindings.length; i++) {
        ParameterizedCommand pCommand = bindings[i].getParameterizedCommand();
        String commandId = null;
        if (pCommand != null) {
            commandId = pCommand.getCommand().getId();
        }
        if (bindings[i].getType() == Binding.USER || (commandId != null && lstRemove.contains(commandId))) {
            fBindingManager.removeBinding(bindings[i]);
        }
    }
    bindingModel.refresh(contextModel, lstRemove);
    saveBindings(bindingService);
}
Also used : KeyBinding(org.eclipse.jface.bindings.keys.KeyBinding) Binding(org.eclipse.jface.bindings.Binding) Scheme(org.eclipse.jface.bindings.Scheme) NotDefinedException(org.eclipse.core.commands.common.NotDefinedException) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand)

Example 7 with ParameterizedCommand

use of org.eclipse.core.commands.ParameterizedCommand in project translationstudio8 by heartsome.

the class BindingModel2 method copy.

/**
	 * Makes a copy of the
	 * @param element
	 */
public void copy(BindingElement element) {
    if (element == null || !(element.getModelObject() instanceof Binding)) {
        return;
    }
    BindingElement be = new BindingElement(controller);
    ParameterizedCommand parameterizedCommand = ((Binding) element.getModelObject()).getParameterizedCommand();
    be.init(parameterizedCommand);
    be.setParent(this);
    bindingElements.add(be);
    commandToElement.put(parameterizedCommand, be);
    controller.firePropertyChange(this, PROP_BINDING_ADD, null, be);
    setSelectedElement(be);
}
Also used : KeyBinding(org.eclipse.jface.bindings.keys.KeyBinding) Binding(org.eclipse.jface.bindings.Binding) BindingElement(org.eclipse.ui.internal.keys.model.BindingElement) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand)

Example 8 with ParameterizedCommand

use of org.eclipse.core.commands.ParameterizedCommand in project translationstudio8 by heartsome.

the class BindingModel2 method restoreBinding.

/**
	 * Restores the specified BindingElement. A refresh should be performed afterwards. The refresh may be done after
	 * several elements have been restored.
	 * @param element
	 */
public void restoreBinding(BindingElement element) {
    if (element == null) {
        return;
    }
    Object modelObject = element.getModelObject();
    ParameterizedCommand cmd = null;
    if (modelObject instanceof ParameterizedCommand) {
        cmd = (ParameterizedCommand) modelObject;
        TriggerSequence trigger = bindingManager.getBestActiveBindingFor(cmd.getId());
        Binding binding = bindingManager.getPerfectMatch(trigger);
        if (binding != null && binding.getType() == Binding.SYSTEM) {
            return;
        }
    } else if (modelObject instanceof KeyBinding) {
        cmd = ((KeyBinding) modelObject).getParameterizedCommand();
    }
    // Remove any USER bindings
    Binding[] managerBindings = bindingManager.getBindings();
    ArrayList systemBindings = new ArrayList();
    ArrayList removalBindings = new ArrayList();
    for (int i = 0; i < managerBindings.length; i++) {
        if (managerBindings[i].getParameterizedCommand() == null) {
            removalBindings.add(managerBindings[i]);
        } else if (managerBindings[i].getParameterizedCommand().equals(cmd)) {
            if (managerBindings[i].getType() == Binding.USER) {
                bindingManager.removeBinding(managerBindings[i]);
            } else if (managerBindings[i].getType() == Binding.SYSTEM) {
                systemBindings.add(managerBindings[i]);
            }
        }
    }
    // Clear the USER bindings for parameterized commands
    Iterator i = systemBindings.iterator();
    while (i.hasNext()) {
        Binding sys = (Binding) i.next();
        Iterator j = removalBindings.iterator();
        while (j.hasNext()) {
            Binding del = (Binding) j.next();
            if (deletes(del, sys) && del.getType() == Binding.USER) {
                bindingManager.removeBinding(del);
            }
        }
    }
    setSelectedElement(null);
    bindingElements.remove(element);
    bindingToElement.remove(modelObject);
    commandToElement.remove(modelObject);
    controller.firePropertyChange(this, PROP_BINDING_REMOVE, null, element);
}
Also used : KeyBinding(org.eclipse.jface.bindings.keys.KeyBinding) Binding(org.eclipse.jface.bindings.Binding) KeyBinding(org.eclipse.jface.bindings.keys.KeyBinding) TriggerSequence(org.eclipse.jface.bindings.TriggerSequence) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand)

Example 9 with ParameterizedCommand

use of org.eclipse.core.commands.ParameterizedCommand in project translationstudio8 by heartsome.

the class BindingModel2 method init.

/**
	 * The initialization only.
	 * @param locator
	 * @param manager
	 * @param model
	 */
public void init(IServiceLocator locator, BindingManager manager, ContextModel model) {
    Set cmdsForBindings = new HashSet();
    bindingToElement = new HashMap();
    commandToElement = new HashMap();
    bindingElements = new HashSet();
    bindingManager = manager;
    Iterator i = manager.getActiveBindingsDisregardingContextFlat().iterator();
    while (i.hasNext()) {
        Binding b = (Binding) i.next();
        BindingElement be = new BindingElement(controller);
        be.init(b, model);
        be.setParent(this);
        bindingElements.add(be);
        bindingToElement.put(b, be);
        cmdsForBindings.add(b.getParameterizedCommand());
    }
    ICommandService commandService = (ICommandService) locator.getService(ICommandService.class);
    final Collection commandIds = commandService.getDefinedCommandIds();
    allParameterizedCommands = new HashSet();
    final Iterator commandIdItr = commandIds.iterator();
    while (commandIdItr.hasNext()) {
        final String currentCommandId = (String) commandIdItr.next();
        final Command currentCommand = commandService.getCommand(currentCommandId);
        try {
            allParameterizedCommands.addAll(ParameterizedCommand.generateCombinations(currentCommand));
        } catch (final NotDefinedException e) {
        // It is safe to just ignore undefined commands.
        }
    }
    i = allParameterizedCommands.iterator();
    while (i.hasNext()) {
        ParameterizedCommand cmd = (ParameterizedCommand) i.next();
        if (!cmdsForBindings.contains(cmd)) {
            BindingElement be = new BindingElement(controller);
            be.init(cmd);
            be.setParent(this);
            bindingElements.add(be);
            commandToElement.put(cmd, be);
        }
    }
}
Also used : KeyBinding(org.eclipse.jface.bindings.keys.KeyBinding) Binding(org.eclipse.jface.bindings.Binding) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) BindingElement(org.eclipse.ui.internal.keys.model.BindingElement) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand) Command(org.eclipse.core.commands.Command) Iterator(java.util.Iterator) Collection(java.util.Collection) NotDefinedException(org.eclipse.core.commands.common.NotDefinedException) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand) ICommandService(org.eclipse.ui.commands.ICommandService) HashSet(java.util.HashSet)

Example 10 with ParameterizedCommand

use of org.eclipse.core.commands.ParameterizedCommand in project translationstudio8 by heartsome.

the class BindingModel2 method remove.

/**
	 * Removes the <code>bindingElement</code> binding.
	 * @param bindingElement
	 */
public void remove(BindingElement bindingElement) {
    if (bindingElement == null || !(bindingElement.getModelObject() instanceof Binding)) {
        return;
    }
    KeyBinding keyBinding = (KeyBinding) bindingElement.getModelObject();
    if (keyBinding.getType() == Binding.USER) {
        bindingManager.removeBinding(keyBinding);
    } else {
        KeySequence keySequence = keyBinding.getKeySequence();
        // Add the delete binding
        bindingManager.addBinding(new KeyBinding(keySequence, null, keyBinding.getSchemeId(), keyBinding.getContextId(), null, null, null, Binding.USER));
        // Unbind any conflicts affected by the delete binding
        ConflictModel conflictModel = controller.getConflictModel();
        conflictModel.updateConflictsFor(bindingElement);
        Collection conflictsList = conflictModel.getConflicts();
        if (conflictsList != null) {
            Object[] conflicts = conflictsList.toArray();
            for (int i = 0; i < conflicts.length; i++) {
                BindingElement be = (BindingElement) conflicts[i];
                if (be == bindingElement) {
                    continue;
                }
                Object modelObject = be.getModelObject();
                if (modelObject instanceof Binding) {
                    Binding binding = (Binding) modelObject;
                    if (binding.getType() != Binding.SYSTEM) {
                        continue;
                    }
                    ParameterizedCommand pCommand = binding.getParameterizedCommand();
                    be.fill(pCommand);
                    commandToElement.put(pCommand, be);
                }
            }
        }
    }
    ParameterizedCommand parameterizedCommand = keyBinding.getParameterizedCommand();
    bindingElement.fill(parameterizedCommand);
    commandToElement.put(parameterizedCommand, bindingElement);
    controller.firePropertyChange(this, PROP_CONFLICT_ELEMENT_MAP, null, bindingElement);
}
Also used : KeyBinding(org.eclipse.jface.bindings.keys.KeyBinding) Binding(org.eclipse.jface.bindings.Binding) KeyBinding(org.eclipse.jface.bindings.keys.KeyBinding) BindingElement(org.eclipse.ui.internal.keys.model.BindingElement) ConflictModel(org.eclipse.ui.internal.keys.model.ConflictModel) Collection(java.util.Collection) KeySequence(org.eclipse.jface.bindings.keys.KeySequence) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand)

Aggregations

ParameterizedCommand (org.eclipse.core.commands.ParameterizedCommand)13 Binding (org.eclipse.jface.bindings.Binding)11 KeyBinding (org.eclipse.jface.bindings.keys.KeyBinding)9 BindingElement (org.eclipse.ui.internal.keys.model.BindingElement)7 Iterator (java.util.Iterator)4 NotDefinedException (org.eclipse.core.commands.common.NotDefinedException)4 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 Command (org.eclipse.core.commands.Command)3 ICommandService (org.eclipse.ui.commands.ICommandService)3 IBindingService (org.eclipse.ui.keys.IBindingService)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Set (java.util.Set)2 TriggerSequence (org.eclipse.jface.bindings.TriggerSequence)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 IWorkbench (org.eclipse.ui.IWorkbench)2 BindingService (org.eclipse.ui.internal.keys.BindingService)2 ModelElement (org.eclipse.ui.internal.keys.model.ModelElement)2