Search in sources :

Example 1 with BindingElement

use of org.eclipse.ui.internal.keys.model.BindingElement in project translationstudio8 by heartsome.

the class KeysPreferencePage method applyData.

public void applyData(Object data) {
    // }
    if (data instanceof ModelElement) {
        model.setSelectedElement((ModelElement) data);
    }
    if (data instanceof Binding && fFilteredTree != null) {
        BindingElement be = (BindingElement) model.getBindingToElement().get(data);
        fFilteredTree.getViewer().setSelection(new StructuredSelection(be), true);
    }
    if (data instanceof ParameterizedCommand) {
        Map commandToElement = model.getCommandToElement();
        BindingElement be = (BindingElement) commandToElement.get(data);
        if (be != null) {
            fFilteredTree.getViewer().setSelection(new StructuredSelection(be), true);
        }
    }
}
Also used : Binding(org.eclipse.jface.bindings.Binding) ModelElement(org.eclipse.ui.internal.keys.model.ModelElement) BindingElement(org.eclipse.ui.internal.keys.model.BindingElement) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand) Map(java.util.Map)

Example 2 with BindingElement

use of org.eclipse.ui.internal.keys.model.BindingElement in project translationstudio8 by heartsome.

the class BindingModel2 method refresh.

/**
	 * Refreshes the binding model to be in sync with the {@link BindingManager}.
	 * @param contextModel
	 */
public void refresh(ContextModel contextModel, List<String> lstRemove) {
    Set cmdsForBindings = new HashSet();
    Iterator<BindingElement> iterator = bindingElements.iterator();
    while (iterator.hasNext()) {
        BindingElement bindingElement = iterator.next();
        if (lstRemove.contains(bindingElement.getId())) {
            iterator.remove();
        }
    }
    Iterator<Entry<Binding, BindingElement>> it = bindingToElement.entrySet().iterator();
    while (it.hasNext()) {
        Entry<Binding, BindingElement> entry = (Entry<Binding, BindingElement>) it.next();
        if (lstRemove.contains(entry.getValue().getId())) {
            it.remove();
        }
    }
    Collection activeManagerBindings = bindingManager.getActiveBindingsDisregardingContextFlat();
    // add any bindings that we don't already have.
    Iterator i = activeManagerBindings.iterator();
    Map<String, BindingElement> temp = new HashMap<String, BindingElement>();
    while (i.hasNext()) {
        KeyBinding b = (KeyBinding) i.next();
        ParameterizedCommand parameterizedCommand = b.getParameterizedCommand();
        cmdsForBindings.add(parameterizedCommand);
        if (!bindingToElement.containsKey(b)) {
            BindingElement be = new BindingElement(controller);
            be.init(b, contextModel);
            be.setParent(this);
            bindingElements.add(be);
            bindingToElement.put(b, be);
            controller.firePropertyChange(this, PROP_BINDING_ADD, null, be);
            // 去掉添加重复的情况
            temp.put(parameterizedCommand.getId(), be);
            if (commandToElement.containsKey(parameterizedCommand) && be.getUserDelta().intValue() == Binding.SYSTEM) {
                Object remove = commandToElement.remove(parameterizedCommand);
                bindingElements.remove(remove);
                controller.firePropertyChange(this, PROP_BINDING_REMOVE, null, remove);
            }
        }
    }
    // 修改在恢复默认设置,出现两个相同的选项	
    i = bindingElements.iterator();
    while (i.hasNext()) {
        BindingElement be = (BindingElement) i.next();
        Object obj = be.getModelObject();
        if (temp.containsKey(be.getId())) {
            if (!(obj instanceof Binding)) {
                System.out.println("remove");
                i.remove();
                controller.firePropertyChange(this, PROP_BINDING_REMOVE, null, be);
            }
        }
    }
    // remove bindings that shouldn't be there
    i = bindingElements.iterator();
    while (i.hasNext()) {
        BindingElement be = (BindingElement) i.next();
        Object obj = be.getModelObject();
        if (obj instanceof Binding) {
            Binding b = (Binding) obj;
            if (!activeManagerBindings.contains(b) || lstRemove.contains(be.getId())) {
                be.fill(b.getParameterizedCommand());
                bindingToElement.remove(b);
                i.remove();
                controller.firePropertyChange(this, PROP_BINDING_REMOVE, null, be);
            }
        } else {
            cmdsForBindings.add(obj);
        }
    }
    // If we removed the last binding for a parameterized command,
    // put back the CMD
    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);
            if (lstRemove.contains(be.getId())) {
                continue;
            }
            bindingElements.add(be);
            commandToElement.put(cmd, be);
            controller.firePropertyChange(this, PROP_BINDING_ADD, null, be);
        }
    }
}
Also used : KeyBinding(org.eclipse.jface.bindings.keys.KeyBinding) Binding(org.eclipse.jface.bindings.Binding) HashSet(java.util.HashSet) Set(java.util.Set) BindingElement(org.eclipse.ui.internal.keys.model.BindingElement) HashMap(java.util.HashMap) KeyBinding(org.eclipse.jface.bindings.keys.KeyBinding) Entry(java.util.Map.Entry) Iterator(java.util.Iterator) Collection(java.util.Collection) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand) HashSet(java.util.HashSet)

Example 3 with BindingElement

use of org.eclipse.ui.internal.keys.model.BindingElement in project translationstudio8 by heartsome.

the class BindingModel2 method copy.

/**
	 * Makes a copy of the selected element.
	 */
public void copy() {
    BindingElement element = (BindingElement) getSelectedElement();
    copy(element);
}
Also used : BindingElement(org.eclipse.ui.internal.keys.model.BindingElement)

Example 4 with BindingElement

use of org.eclipse.ui.internal.keys.model.BindingElement in project translationstudio8 by heartsome.

the class KeyController2 method updateTrigger.

/**
	 * @param activeBinding
	 * @param oldSequence
	 * @param keySequence
	 */
public void updateTrigger(BindingElement activeBinding, KeySequence oldSequence, KeySequence keySequence) {
    if (activeBinding == null) {
        return;
    }
    Object obj = activeBinding.getModelObject();
    if (obj instanceof KeyBinding) {
        KeyBinding keyBinding = (KeyBinding) obj;
        if (!keyBinding.getKeySequence().equals(keySequence)) {
            if (keySequence != null && !keySequence.isEmpty()) {
                String activeSchemeId = fSchemeModel.getSelectedElement().getId();
                ModelElement selectedElement = contextModel.getSelectedElement();
                String activeContextId = selectedElement == null ? IContextService.CONTEXT_ID_WINDOW : selectedElement.getId();
                final KeyBinding binding = new KeyBinding(keySequence, keyBinding.getParameterizedCommand(), activeSchemeId, activeContextId, null, null, null, Binding.USER);
                Map bindingToElement = bindingModel.getBindingToElement();
                bindingToElement.remove(keyBinding);
                if (keyBinding.getType() == Binding.USER) {
                    fBindingManager.removeBinding(keyBinding);
                } else {
                    fBindingManager.addBinding(new KeyBinding(keyBinding.getKeySequence(), null, keyBinding.getSchemeId(), keyBinding.getContextId(), null, null, null, Binding.USER));
                }
                fBindingManager.addBinding(binding);
                activeBinding.fill(binding, contextModel);
                bindingModel.getBindingToElement().put(binding, activeBinding);
                // Remove binding for any system conflicts
                Object[] keys = bindingToElement.keySet().toArray();
                for (int i = 0; i < keys.length; i++) {
                    Binding bindingKey = (Binding) keys[i];
                    if (oldSequence.equals(bindingKey.getTriggerSequence()) && bindingKey.getType() == Binding.SYSTEM) {
                        BindingElement be = (BindingElement) bindingToElement.get(bindingKey);
                        bindingModel.remove(be);
                    }
                }
                bindingModel.setSelectedElement(activeBinding);
            } else {
                bindingModel.getBindingToElement().remove(keyBinding);
                if (keyBinding.getType() == Binding.USER) {
                    fBindingManager.removeBinding(keyBinding);
                } else {
                    fBindingManager.addBinding(new KeyBinding(keyBinding.getKeySequence(), null, keyBinding.getSchemeId(), keyBinding.getContextId(), null, null, null, Binding.USER));
                }
                activeBinding.fill(keyBinding.getParameterizedCommand());
            }
        }
    } else if (obj instanceof ParameterizedCommand) {
        ParameterizedCommand cmd = (ParameterizedCommand) obj;
        if (keySequence != null && !keySequence.isEmpty()) {
            String activeSchemeId = fSchemeModel.getSelectedElement().getId();
            ModelElement selectedElement = contextModel.getSelectedElement();
            String activeContextId = selectedElement == null ? IContextService.CONTEXT_ID_WINDOW : selectedElement.getId();
            final KeyBinding binding = new KeyBinding(keySequence, cmd, activeSchemeId, activeContextId, null, null, null, Binding.USER);
            fBindingManager.addBinding(binding);
            activeBinding.fill(binding, contextModel);
            bindingModel.getBindingToElement().put(binding, activeBinding);
        }
    }
}
Also used : KeyBinding(org.eclipse.jface.bindings.keys.KeyBinding) Binding(org.eclipse.jface.bindings.Binding) KeyBinding(org.eclipse.jface.bindings.keys.KeyBinding) ModelElement(org.eclipse.ui.internal.keys.model.ModelElement) BindingElement(org.eclipse.ui.internal.keys.model.BindingElement) Map(java.util.Map) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand)

Example 5 with BindingElement

use of org.eclipse.ui.internal.keys.model.BindingElement in project translationstudio8 by heartsome.

the class KeyController2 method updateBindingContext.

private void updateBindingContext(ContextElement context) {
    if (context == null) {
        return;
    }
    BindingElement activeBinding = (BindingElement) bindingModel.getSelectedElement();
    if (activeBinding == null) {
        return;
    }
    String activeSchemeId = fSchemeModel.getSelectedElement().getId();
    Object obj = activeBinding.getModelObject();
    if (obj instanceof KeyBinding) {
        KeyBinding keyBinding = (KeyBinding) obj;
        if (!keyBinding.getContextId().equals(context.getId())) {
            final KeyBinding binding = new KeyBinding(keyBinding.getKeySequence(), keyBinding.getParameterizedCommand(), activeSchemeId, context.getId(), null, null, null, Binding.USER);
            if (keyBinding.getType() == Binding.USER) {
                fBindingManager.removeBinding(keyBinding);
            } else {
                fBindingManager.addBinding(new KeyBinding(keyBinding.getKeySequence(), null, keyBinding.getSchemeId(), keyBinding.getContextId(), null, null, null, Binding.USER));
            }
            bindingModel.getBindingToElement().remove(activeBinding.getModelObject());
            fBindingManager.addBinding(binding);
            activeBinding.fill(binding, contextModel);
            bindingModel.getBindingToElement().put(binding, activeBinding);
        }
    }
}
Also used : KeyBinding(org.eclipse.jface.bindings.keys.KeyBinding) BindingElement(org.eclipse.ui.internal.keys.model.BindingElement)

Aggregations

BindingElement (org.eclipse.ui.internal.keys.model.BindingElement)15 Binding (org.eclipse.jface.bindings.Binding)9 KeyBinding (org.eclipse.jface.bindings.keys.KeyBinding)8 ParameterizedCommand (org.eclipse.core.commands.ParameterizedCommand)7 Collection (java.util.Collection)5 Iterator (java.util.Iterator)5 HashMap (java.util.HashMap)3 ModelElement (org.eclipse.ui.internal.keys.model.ModelElement)3 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Entry (java.util.Map.Entry)2 Set (java.util.Set)2 KeySequence (org.eclipse.jface.bindings.keys.KeySequence)2 IPropertyChangeListener (org.eclipse.jface.util.IPropertyChangeListener)2 PropertyChangeEvent (org.eclipse.jface.util.PropertyChangeEvent)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 BufferedWriter (java.io.BufferedWriter)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1