Search in sources :

Example 11 with BindingElement

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

the class BindingModel2 method restoreBinding.

/**
	 * Restores the currently selected binding.
	 * @param contextModel
	 */
public void restoreBinding(ContextModel contextModel) {
    BindingElement element = (BindingElement) getSelectedElement();
    if (element == null) {
        return;
    }
    restoreBinding(element);
    refresh(contextModel);
    Object obj = element.getModelObject();
    ParameterizedCommand cmd = null;
    if (obj instanceof ParameterizedCommand) {
        cmd = (ParameterizedCommand) obj;
    } else if (obj instanceof KeyBinding) {
        cmd = ((KeyBinding) obj).getParameterizedCommand();
    }
    boolean done = false;
    Iterator i = bindingElements.iterator();
    // Reselects the command
    while (i.hasNext() && !done) {
        BindingElement be = (BindingElement) i.next();
        obj = be.getModelObject();
        ParameterizedCommand pcmd = null;
        if (obj instanceof ParameterizedCommand) {
            pcmd = (ParameterizedCommand) obj;
        } else if (obj instanceof KeyBinding) {
            pcmd = ((KeyBinding) obj).getParameterizedCommand();
        }
        if (cmd.equals(pcmd)) {
            done = true;
            setSelectedElement(be);
        }
    }
}
Also used : KeyBinding(org.eclipse.jface.bindings.keys.KeyBinding) BindingElement(org.eclipse.ui.internal.keys.model.BindingElement) Iterator(java.util.Iterator) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand)

Example 12 with BindingElement

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

the class ConflictModel2 method updateConflictsFor.

public void updateConflictsFor(BindingElement newValue, TriggerSequence oldTrigger, TriggerSequence newTrigger, boolean removal) {
    Collection matches = (Collection) conflictsMap.get(newValue);
    if (matches != null) {
        if (newTrigger == null || removal) {
            // we need to clear this match
            matches.remove(newValue);
            conflictsMap.remove(newValue);
            if (matches == conflicts) {
                controller.firePropertyChange(this, PROP_CONFLICTS_REMOVE, null, newValue);
            }
            if (matches.size() == 1) {
                BindingElement tbe = (BindingElement) matches.iterator().next();
                conflictsMap.remove(tbe);
                tbe.setConflict(Boolean.FALSE);
                if (matches == conflicts) {
                    setConflicts(null);
                }
            }
            return;
        } else if (oldTrigger != null && !newTrigger.equals(oldTrigger)) {
            // we need to clear this match
            matches.remove(newValue);
            conflictsMap.remove(newValue);
            if (matches == conflicts) {
                controller.firePropertyChange(this, PROP_CONFLICTS_REMOVE, null, newValue);
            }
            if (matches.size() == 1) {
                BindingElement tbe = (BindingElement) matches.iterator().next();
                conflictsMap.remove(tbe);
                tbe.setConflict(Boolean.FALSE);
                if (matches == conflicts) {
                    setConflicts(null);
                }
            }
        } else {
            return;
        }
    }
    if (newValue.getTrigger() == null || !(newValue.getModelObject() instanceof Binding)) {
        return;
    }
    Binding binding = (Binding) newValue.getModelObject();
    TriggerSequence trigger = binding.getTriggerSequence();
    matches = (Collection) bindingManager.getActiveBindingsDisregardingContext().get(trigger);
    ArrayList localConflicts = new ArrayList();
    if (matches != null) {
        localConflicts.add(newValue);
        Iterator i = matches.iterator();
        while (i.hasNext()) {
            Binding b = (Binding) i.next();
            //				Bug #2740 快捷键--快捷键设置问题:修改验证冲突快捷键的方法,使用以下的方式,原来使用的是上面注释的方式
            if (binding != b && !b.getParameterizedCommand().getCommand().toString().equals(binding.getParameterizedCommand().getCommand().toString())) {
                Object element = bindingModel.getBindingToElement().get(b);
                if (element != null) {
                    localConflicts.add(element);
                }
            }
        }
    }
    if (localConflicts.size() > 1) {
        // first find if it is already a conflict collection
        Collection knownConflicts = null;
        Iterator i = localConflicts.iterator();
        while (i.hasNext() && knownConflicts == null) {
            BindingElement tbe = (BindingElement) i.next();
            knownConflicts = (Collection) conflictsMap.get(tbe);
        }
        if (knownConflicts != null) {
            knownConflicts.add(newValue);
            conflictsMap.put(newValue, knownConflicts);
            newValue.setConflict(Boolean.TRUE);
            if (knownConflicts == conflicts) {
                controller.firePropertyChange(this, PROP_CONFLICTS_ADD, null, newValue);
            } else if (newValue == getSelectedElement()) {
                setConflicts(knownConflicts);
            }
            return;
        }
        boolean isSelected = false;
        i = localConflicts.iterator();
        while (i.hasNext()) {
            BindingElement tbe = (BindingElement) i.next();
            if (tbe != null) {
                conflictsMap.put(tbe, localConflicts);
                tbe.setConflict(Boolean.TRUE);
            }
            if (tbe == getSelectedElement()) {
                isSelected = true;
            }
        }
        if (isSelected) {
            setConflicts(localConflicts);
        }
    }
}
Also used : Binding(org.eclipse.jface.bindings.Binding) TriggerSequence(org.eclipse.jface.bindings.TriggerSequence) BindingElement(org.eclipse.ui.internal.keys.model.BindingElement) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) Collection(java.util.Collection)

Example 13 with BindingElement

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

the class ConflictModel2 method init.

public void init(BindingManager manager, BindingModel model) {
    bindingManager = manager;
    bindingModel = model;
    conflictsMap = new HashMap();
    Iterator i = bindingModel.getBindings().iterator();
    while (i.hasNext()) {
        BindingElement be = (BindingElement) i.next();
        if (be.getModelObject() instanceof Binding) {
            updateConflictsFor(be);
        }
    }
    controller.addPropertyChangeListener(new IPropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent event) {
            if (event.getSource() == ConflictModel2.this && CommonModel.PROP_SELECTED_ELEMENT.equals(event.getProperty())) {
                if (event.getNewValue() != null) {
                    updateConflictsFor((BindingElement) event.getOldValue(), (BindingElement) event.getNewValue());
                    setConflicts((Collection) conflictsMap.get(event.getNewValue()));
                } else {
                    setConflicts(null);
                }
            } else if (BindingModel.PROP_BINDING_REMOVE.equals(event.getProperty())) {
                updateConflictsFor((BindingElement) event.getOldValue(), (BindingElement) event.getNewValue(), true);
            }
        }
    });
}
Also used : Binding(org.eclipse.jface.bindings.Binding) IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) HashMap(java.util.HashMap) BindingElement(org.eclipse.ui.internal.keys.model.BindingElement) Iterator(java.util.Iterator) Collection(java.util.Collection)

Example 14 with BindingElement

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

the class KeyController2 method init.

public void init(IServiceLocator locator, List<String> lstRemove) {
    getEventManager().clear();
    this.serviceLocator = locator;
    //	filterDupliteBind();
    fBindingManager = loadModelBackend(serviceLocator);
    contextModel = new ContextModel(this);
    contextModel.init(serviceLocator);
    fSchemeModel = new SchemeModel(this);
    fSchemeModel.init(fBindingManager);
    bindingModel = new BindingModel2(this);
    bindingModel.init(serviceLocator, fBindingManager, contextModel);
    HashSet<BindingElement> set = bindingModel.getBindings();
    Iterator<BindingElement> iterator = set.iterator();
    while (iterator.hasNext()) {
        BindingElement bindingElement = iterator.next();
        if (lstRemove.contains(bindingElement.getId())) {
            iterator.remove();
        }
    }
    bindingModel.setBindings(set);
    Map<Binding, BindingElement> mapBBe = bindingModel.getBindingToElement();
    Iterator<Entry<Binding, BindingElement>> it = mapBBe.entrySet().iterator();
    while (it.hasNext()) {
        Entry<Binding, BindingElement> entry = (Entry<Binding, BindingElement>) it.next();
        if (lstRemove.contains(entry.getValue().getId())) {
            it.remove();
        }
    }
    bindingModel.setBindingToElement(mapBBe);
    conflictModel = new ConflictModel2(this);
    conflictModel.init(fBindingManager, bindingModel);
    addSetContextListener();
    addSetBindingListener();
    addSetConflictListener();
    addSetKeySequenceListener();
    addSetSchemeListener();
    addSetModelObjectListener();
}
Also used : KeyBinding(org.eclipse.jface.bindings.keys.KeyBinding) Binding(org.eclipse.jface.bindings.Binding) Entry(java.util.Map.Entry) ContextModel(org.eclipse.ui.internal.keys.model.ContextModel) BindingElement(org.eclipse.ui.internal.keys.model.BindingElement) SchemeModel(org.eclipse.ui.internal.keys.model.SchemeModel)

Example 15 with BindingElement

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

the class KeysPreferencePage method createTree.

private void createTree(Composite parent) {
    fPatternFilter = new CategoryPatternFilter(true, fDefaultCategory);
    fPatternFilter.filterCategories(true);
    GridData gridData;
    fFilteredTree = new CategoryFilterTree(parent, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION, fPatternFilter);
    final GridLayout layout = new GridLayout(1, false);
    layout.marginWidth = 0;
    fFilteredTree.setLayout(layout);
    gridData = new GridData();
    gridData.grabExcessHorizontalSpace = true;
    gridData.grabExcessVerticalSpace = true;
    gridData.horizontalAlignment = SWT.FILL;
    gridData.verticalAlignment = SWT.FILL;
    fFilteredTree.setLayoutData(gridData);
    viewer = fFilteredTree.getViewer();
    // Make sure the filtered tree has a height of ITEMS_TO_SHOW
    final Tree tree = viewer.getTree();
    tree.setHeaderVisible(true);
    final Object layoutData = tree.getLayoutData();
    if (layoutData instanceof GridData) {
        gridData = (GridData) layoutData;
        final int itemHeight = tree.getItemHeight();
        if (itemHeight > 1) {
            gridData.heightHint = ITEMS_TO_SHOW * itemHeight;
        }
    }
    BindingModelComparator comparator = new BindingModelComparator();
    comparator.setSortColumn(2);
    viewer.setComparator(comparator);
    final TreeColumn commandNameColumn = new TreeColumn(tree, SWT.LEFT, COMMAND_NAME_COLUMN);
    commandNameColumn.setText(Messages.getString("preferencepage.KeysPreferencePage.commandNameColumn"));
    tree.setSortColumn(commandNameColumn);
    tree.setSortDirection(comparator.isAscending() ? SWT.UP : SWT.DOWN);
    commandNameColumn.addSelectionListener(new ResortColumn(comparator, commandNameColumn, viewer, COMMAND_NAME_COLUMN));
    final TreeViewerColumn triggerSequenceColumn = new TreeViewerColumn(viewer, SWT.LEFT, KEY_SEQUENCE_COLUMN);
    triggerSequenceColumn.getColumn().setText(Messages.getString("preferencepage.KeysPreferencePage.triggerSequenceColumn"));
    triggerSequenceColumn.getColumn().addSelectionListener(new ResortColumn(comparator, triggerSequenceColumn.getColumn(), viewer, KEY_SEQUENCE_COLUMN));
    triggerSequenceColumn.setEditingSupport(new TableViewerEditingSupport(viewer, 1));
    final TreeColumn categoryColumn = new TreeColumn(tree, SWT.LEFT, CATEGORY_COLUMN);
    categoryColumn.setText(Messages.getString("preferencepage.KeysPreferencePage.categoryColumn"));
    categoryColumn.addSelectionListener(new ResortColumn(comparator, categoryColumn, viewer, CATEGORY_COLUMN));
    viewer.setContentProvider(new ModelContentProvider());
    viewer.setLabelProvider(new BindingElementLabelProvider());
    fFilteredTree.getPatternFilter().setIncludeLeadingWildcard(true);
    final TreeColumn[] columns = viewer.getTree().getColumns();
    columns[COMMAND_NAME_COLUMN].setWidth(240);
    columns[KEY_SEQUENCE_COLUMN].setWidth(130);
    columns[CATEGORY_COLUMN].setWidth(130);
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        // When the viewer changes selection, update the model's current
        // selection
        public void selectionChanged(SelectionChangedEvent event) {
            changeBackground();
            ModelElement binding = (ModelElement) ((IStructuredSelection) event.getSelection()).getFirstElement();
            model.setSelectedElement(binding);
        }
    });
    IPropertyChangeListener treeUpdateListener = new IPropertyChangeListener() {

        // When the model changes a property, update the viewer
        public void propertyChange(PropertyChangeEvent event) {
            if (event.getSource() == model && CommonModel.PROP_SELECTED_ELEMENT.equals(event.getProperty())) {
                Object newVal = event.getNewValue();
                StructuredSelection structuredSelection = newVal == null ? null : new StructuredSelection(newVal);
                viewer.setSelection(structuredSelection, true);
            } else if (event.getSource() instanceof BindingElement && ModelElement.PROP_MODEL_OBJECT.equals(event.getProperty())) {
                viewer.update(event.getSource(), null);
            } else if (BindingElement.PROP_CONFLICT.equals(event.getProperty())) {
                viewer.update(event.getSource(), null);
            } else if (BindingModel.PROP_BINDINGS.equals(event.getProperty())) {
            // viewer.refresh();
            } else if (BindingModel.PROP_BINDING_ADD.equals(event.getProperty())) {
                viewer.add(model, event.getNewValue());
            } else if (BindingModel.PROP_BINDING_REMOVE.equals(event.getProperty())) {
                viewer.remove(event.getNewValue());
            } else if (BindingModel.PROP_BINDING_FILTER.equals(event.getProperty())) {
            // viewer.refresh();
            }
            changeBackground();
        // isValid();
        }
    };
    keyController.addPropertyChangeListener(treeUpdateListener);
    // IPropertyChangeListener conflictsListener = new IPropertyChangeListener() {
    // public void propertyChange(PropertyChangeEvent event) {
    // // System.out.println(event.getNewValue().getClass());
    // if (keyController.getConflictModel().getConflicts() != null) {
    // if (ConflictModel.PROP_CONFLICTS.equals(event.getProperty())) {
    // // lstConflict.clear();
    // if (event.getNewValue() != null) {
    // lstConflict.addAll((Collection<? extends Object>) event.getNewValue());
    // }
    // // conflictViewer.setInput(event.getNewValue());
    // } else if (ConflictModel.PROP_CONFLICTS_ADD.equals(event.getProperty())) {
    // if (event.getNewValue() != null) {
    // lstConflict.add(event.getNewValue());
    // }
    // // conflictViewer.add(event.getNewValue());
    // } else if (ConflictModel.PROP_CONFLICTS_REMOVE.equals(event.getProperty())) {
    // // conflictViewer.remove(event.getNewValue());
    // if (event.getNewValue() != null) {
    // lstConflict.remove(event.getNewValue());
    // }
    // }
    // } else {
    // lstConflict.clear();
    // }
    // // if (event.getSource() == keyController.getConflictModel()
    // // && CommonModel.PROP_SELECTED_ELEMENT.equals(event.getProperty())) {
    // // if (keyController.getConflictModel().getConflicts() != null) {
    // // Object newVal = event.getNewValue();
    // // StructuredSelection structuredSelection = newVal == null ? null : new StructuredSelection(
    // // newVal);
    // // // conflictViewer.setSelection(structuredSelection, true);
    // // }
    // // } else if (ConflictModel.PROP_CONFLICTS.equals(event.getProperty())) {
    // // // lstConflict.clear();
    // // if (event.getNewValue() != null) {
    // // lstConflict.addAll((Collection<? extends Object>) event.getNewValue());
    // // }
    // // // conflictViewer.setInput(event.getNewValue());
    // // } else if (ConflictModel.PROP_CONFLICTS_ADD.equals(event.getProperty())) {
    // // if (event.getNewValue() != null) {
    // // lstConflict.clear();
    // // lstConflict.add(event.getNewValue());
    // // }
    // // // conflictViewer.add(event.getNewValue());
    // // } else if (ConflictModel.PROP_CONFLICTS_REMOVE.equals(event.getProperty())) {
    // // // conflictViewer.remove(event.getNewValue());
    // // if (event.getNewValue() != null) {
    // // lstConflict.clear();
    // // lstConflict.remove(event.getNewValue());
    // // }
    // // }
    // }
    // };
    // keyController.addPropertyChangeListener(conflictsListener);
    IPropertyChangeListener dataUpdateListener = new IPropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent event) {
            BindingElement bindingElement = null;
            boolean weCare = false;
            if (event.getSource() == model && CommonModel.PROP_SELECTED_ELEMENT.equals(event.getProperty())) {
                bindingElement = (BindingElement) event.getNewValue();
                weCare = true;
            } else if (event.getSource() == model.getSelectedElement() && ModelElement.PROP_MODEL_OBJECT.equals(event.getProperty())) {
                bindingElement = (BindingElement) event.getSource();
                weCare = true;
            }
            if (bindingElement == null && weCare) {
                //$NON-NLS-1$
                fBindingText.setText("");
            } else if (bindingElement != null) {
                KeySequence trigger = (KeySequence) bindingElement.getTrigger();
                fKeySequenceText.setKeySequence(trigger);
            }
        }
    };
    keyController.addPropertyChangeListener(dataUpdateListener);
}
Also used : BindingElement(org.eclipse.ui.internal.keys.model.BindingElement) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ModelElement(org.eclipse.ui.internal.keys.model.ModelElement) GridLayout(org.eclipse.swt.layout.GridLayout) TreeColumn(org.eclipse.swt.widgets.TreeColumn) Tree(org.eclipse.swt.widgets.Tree) FilteredTree(org.eclipse.ui.dialogs.FilteredTree) IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) GridData(org.eclipse.swt.layout.GridData) KeySequence(org.eclipse.jface.bindings.keys.KeySequence)

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