Example usage for org.eclipse.jface.bindings Binding USER

List of usage examples for org.eclipse.jface.bindings Binding USER

Introduction

In this page you can find the example usage for org.eclipse.jface.bindings Binding USER.

Prototype

int USER

To view the source code for org.eclipse.jface.bindings Binding USER.

Click Source Link

Document

The type of binding that is defined by the user (i.e., by the end user of the application).

Usage

From source file:com.bdaum.zoom.ui.internal.preferences.KeyPreferencePage.java

License:Open Source License

@SuppressWarnings("unused")
private void createBindingTable(Composite composite) {
    bindingViewer = new TableViewer(composite, SWT.BORDER | SWT.SINGLE | SWT.V_SCROLL | SWT.FULL_SELECTION);
    Table table = bindingViewer.getTable();
    table.setLayoutData(new GridData(550, 300));
    table.setHeaderVisible(true);//from   w  w  w  .j  a  v  a 2 s  .  c  o m
    table.setLinesVisible(true);
    commandColumn = createColumn(bindingViewer, Messages.getString("KeyPreferencePage.command"), 200); //$NON-NLS-1$
    commandLabelProvider = new ZColumnLabelProvider() {
        @Override
        public String getText(Object element) {
            if (element instanceof Command) {
                try {
                    return ((Command) element).getName();
                } catch (NotDefinedException e) {
                    return Messages.getString("KeyPreferencePage.undefined"); //$NON-NLS-1$
                }
            }
            return element.toString();
        }

        @Override
        public Font getFont(Object element) {
            if (element instanceof Command) {
                Binding binding = commandMap.get(((Command) element).getId());
                if (binding != null && binding.getType() == Binding.USER)
                    return JFaceResources.getFont(UiConstants.ITALICFONT);
            }
            return super.getFont(element);
        }

    };
    commandColumn.setLabelProvider(commandLabelProvider);
    keyColumn = createColumn(bindingViewer, Messages.getString("KeyPreferencePage.keys"), 150); //$NON-NLS-1$
    keyLabelProvider = new ZColumnLabelProvider() {
        @Override
        public String getText(Object element) {
            if (element instanceof Command) {
                Binding binding = commandMap.get(((Command) element).getId());
                if (binding != null)
                    return binding.getTriggerSequence().format();
                return null;
            }
            return element.toString();
        }
    };
    keyColumn.setLabelProvider(keyLabelProvider);
    catColumn = createColumn(bindingViewer, Messages.getString("KeyPreferencePage.category"), 150); //$NON-NLS-1$
    catLabelProvider = new ZColumnLabelProvider() {
        @Override
        public String getText(Object element) {
            if (element instanceof Command)
                try {
                    return ((Command) element).getCategory().getName();
                } catch (NotDefinedException e) {
                    return Messages.getString("KeyPreferencePage.undefined"); //$NON-NLS-1$
                }
            return element.toString();
        }
    };
    catColumn.setLabelProvider(catLabelProvider);
    bindingViewer.setContentProvider(ArrayContentProvider.getInstance());
    new SortColumnManager(bindingViewer, new int[] { SWT.UP, SWT.UP, SWT.UP }, 0);
    bindingViewer.setComparator(ZViewerComparator.INSTANCE);
    bindingViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            updateDetails();
        }
    });
}

From source file:com.bdaum.zoom.ui.internal.preferences.KeyPreferencePage.java

License:Open Source License

private final Control createButtonBar(final Composite parent) {
    final Composite buttonBar = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout(2, false);
    layout.marginWidth = 0;//from  w  w  w  . j a v  a2 s.co  m
    buttonBar.setLayout(layout);
    buttonBar.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

    final Button removeBindingButton = new Button(buttonBar, SWT.PUSH);
    removeBindingButton.setText(Messages.getString("KeyPreferencePage.remove_shortcuts")); //$NON-NLS-1$
    removeBindingButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public final void widgetSelected(final SelectionEvent event) {
            if (selectedCommand != null) {
                Binding b = commandMap.get(selectedCommand.getId());
                if (b != null) {
                    Binding userBinding = new KeyBinding((KeySequence) b.getTriggerSequence(), null,
                            activeSchemeId, b.getContextId(), null, null, null, Binding.USER);
                    userMap.put(userBinding.getTriggerSequence(), userBinding);
                    commandMap.remove(selectedCommand.getId());
                }
                refreshViewer();
                doValidate();
            }
        }
    });

    final Button restore = new Button(buttonBar, SWT.PUSH);
    restore.setText(Messages.getString("KeyPreferencePage.restore_command")); //$NON-NLS-1$
    restore.addSelectionListener(new SelectionAdapter() {
        @Override
        public final void widgetSelected(final SelectionEvent event) {
            if (selectedCommand != null) {
                String id = selectedCommand.getId();
                Binding b = commandMap.get(id);
                userMap.remove(b.getTriggerSequence());
                for (Binding sb : systemMap.values()) {
                    if (sb.getParameterizedCommand() != null
                            && sb.getParameterizedCommand().getId().equals(id)) {
                        commandMap.put(sb.getParameterizedCommand().getId(), sb);
                        break;
                    }
                }
                refreshViewer();
                doValidate();
            }
        }
    });
    return buttonBar;
}

From source file:com.bdaum.zoom.ui.internal.preferences.KeyPreferencePage.java

License:Open Source License

@SuppressWarnings("unused")
private void createDefinitionArea(Composite parent) {
    final Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    composite.setLayout(new GridLayout(2, false));
    new Label(composite, SWT.NONE).setText(Messages.getString("KeyPreferencePage.command2")); //$NON-NLS-1$
    nameField = new Text(composite, SWT.SINGLE | SWT.LEAD | SWT.BORDER | SWT.READ_ONLY);
    nameField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    new Label(composite, SWT.NONE).setText(Messages.getString("KeyPreferencePage.description")); //$NON-NLS-1$
    descriptionField = new Text(composite, SWT.MULTI | SWT.LEAD | SWT.BORDER | SWT.READ_ONLY | SWT.WRAP);
    GridData layoutData = new GridData(SWT.FILL, SWT.CENTER, true, false);
    layoutData.heightHint = 50;/* ww w  . ja  v  a2s.  com*/
    descriptionField.setLayoutData(layoutData);
    new Label(composite, SWT.NONE).setText(Messages.getString("KeyPreferencePage.key_sequence")); //$NON-NLS-1$
    Composite keyGroup = new Composite(composite, SWT.NONE);
    keyGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true));
    GridLayout layout = new GridLayout(2, false);
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    keyGroup.setLayout(layout);
    keyField = new Text(keyGroup, SWT.SINGLE | SWT.LEAD | SWT.BORDER);
    keyField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    keySequenceField = new KeySequenceText(keyField);
    keySequenceField.setKeyStrokeLimit(2);
    keySequenceField.addPropertyChangeListener(new IPropertyChangeListener() {
        public final void propertyChange(final PropertyChangeEvent event) {
            if (!event.getOldValue().equals(event.getNewValue())) {
                final KeySequence keySequence = keySequenceField.getKeySequence();
                if (selectedCommand == null || !keySequence.isComplete())
                    return;
                boolean empty = keySequence.isEmpty();
                Binding newBinding;
                Binding b = commandMap.get(selectedCommand.getId());
                if (b != null) {
                    if (!keySequence.equals(b.getTriggerSequence())) {
                        newBinding = new KeyBinding(keySequence, empty ? null : b.getParameterizedCommand(),
                                activeSchemeId, b.getContextId(), null, null, null, Binding.USER);
                        userMap.remove(b.getTriggerSequence());
                        userMap.put(keySequence, newBinding);
                        if (empty)
                            commandMap.remove(selectedCommand.getId());
                        else
                            commandMap.put(selectedCommand.getId(), newBinding);
                    }
                } else if (!empty) {
                    ParameterizedCommand pc = new ParameterizedCommand(selectedCommand, null);
                    newBinding = new KeyBinding(keySequence, pc, activeSchemeId,
                            "org.eclipse.ui.contexts.window", //$NON-NLS-1$
                            null, null, null, Binding.USER);
                    userMap.put(keySequence, newBinding);
                    commandMap.put(selectedCommand.getId(), newBinding);
                }
                refreshViewer();
                doValidate();
                keyField.setSelection(keyField.getTextLimit());
            }
        }
    });
    final Button helpButton = new Button(keyGroup, SWT.ARROW | SWT.LEFT);
    helpButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
    helpButton.setToolTipText(Messages.getString("KeyPreferencePage.add_a_special_key")); //$NON-NLS-1$
    // Arrow buttons aren't normally added to the tab list. Let's fix that.
    final Control[] tabStops = keyGroup.getTabList();
    final ArrayList<Control> newTabStops = new ArrayList<Control>();
    for (int i = 0; i < tabStops.length; i++) {
        Control tabStop = tabStops[i];
        newTabStops.add(tabStop);
        if (keyField.equals(tabStop))
            newTabStops.add(helpButton);
    }
    keyGroup.setTabList(newTabStops.toArray(new Control[newTabStops.size()]));

    // Construct the menu to attach to the above button.
    final Menu addKeyMenu = new Menu(helpButton);
    final Iterator<?> trappedKeyItr = KeySequenceText.TRAPPED_KEYS.iterator();
    while (trappedKeyItr.hasNext()) {
        final KeyStroke trappedKey = (KeyStroke) trappedKeyItr.next();
        final MenuItem menuItem = new MenuItem(addKeyMenu, SWT.PUSH);
        menuItem.setText(trappedKey.format());
        menuItem.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                keySequenceField.insert(trappedKey);
                keyField.setFocus();
                keyField.setSelection(keyField.getTextLimit());
            }
        });
    }
    helpButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent selectionEvent) {
            Point buttonLocation = helpButton.getLocation();
            buttonLocation = composite.toDisplay(buttonLocation.x, buttonLocation.y);
            Point buttonSize = helpButton.getSize();
            addKeyMenu.setLocation(buttonLocation.x, buttonLocation.y + buttonSize.y);
            addKeyMenu.setVisible(true);
        }
    });
    new Label(composite, SWT.NONE);
    userLabel = new Label(composite, SWT.NONE);
    userLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
}

From source file:com.bdaum.zoom.ui.internal.preferences.KeyPreferencePage.java

License:Open Source License

private void updateDetails() {
    selectedCommand = (Command) bindingViewer.getStructuredSelection().getFirstElement();
    if (selectedCommand != null) {
        try {//from ww  w  .jav a2  s  .c om
            String name = selectedCommand.getName();
            nameField.setText(name == null ? "" : name); //$NON-NLS-1$
            String description = selectedCommand.getDescription();
            descriptionField.setText(description == null ? "" //$NON-NLS-1$
                    : description);
            Binding binding = commandMap.get(selectedCommand.getId());
            if (binding != null) {
                TriggerSequence triggerSequence = binding.getTriggerSequence();
                if (triggerSequence instanceof KeySequence)
                    keySequenceField.setKeySequence((KeySequence) triggerSequence);
                else
                    keySequenceField.setKeySequence(null);
                userLabel.setText(
                        binding.getType() == Binding.USER ? Messages.getString("KeyPreferencePage.user_defined") //$NON-NLS-1$
                                : ""); //$NON-NLS-1$
            } else {
                keySequenceField.setKeySequence(null);
                userLabel.setText(""); //$NON-NLS-1$
            }
        } catch (NotDefinedException e) {
            // ignore
        }
    }
}

From source file:com.google.dart.tools.ui.internal.preferences.DartKeyBindingPersistence.java

License:Open Source License

private Element createBindingElement(Binding binding, Document document) {
    // binding is known to have a ParameterizedCommand whose command ID matches a registered Command
    String keys = binding.getTriggerSequence().toString();
    String platform = binding.getPlatform();
    String commandName;/*from w  ww .  j a  va2  s.  c  om*/
    try {
        commandName = binding.getParameterizedCommand().getName();
    } catch (NotDefinedException ex) {
        return null;
    }
    String id = keys + commandName + (platform == null ? "" : platform);
    if (knownBindings.containsKey(id)) {
        if (binding.getType() == Binding.USER) {
            // A SYSTEM binding has already been created
            return null; // do not add it again
        } else {
            // A USER binding has already been created; update its standard key binding
            Element element = knownBindings.get(id);
            element.setAttribute(XML_ATTRIBUTE_KEYS, binding.getTriggerSequence().toString());
            return null;
        }
    }
    Element element = document.createElement(XML_NODE_BINDING);
    element.setAttribute(XML_ATTRIBUTE_KEYS, keys);
    element.setAttribute(XML_ATTRIBUTE_COMMANDID, commandName);
    if (platform != null) {
        element.setAttribute(XML_ATTRIBUTE_PLATFORM, platform);
    }
    knownBindings.put(id, element);
    return element;
}

From source file:com.google.dart.tools.ui.internal.preferences.DartKeyBindingPersistence.java

License:Open Source License

private void initBindingManager() {
    bindingManager = new BindingManager(new ContextManager(), new CommandManager());
    Scheme[] definedSchemes = bindingService.getDefinedSchemes();
    try {/*from w w w.j a va2  s.  c  om*/
        for (int i = 0; i < definedSchemes.length; i++) {
            Scheme scheme = definedSchemes[i];
            Scheme copy = bindingManager.getScheme(scheme.getId());
            copy.define(scheme.getName(), scheme.getDescription(), scheme.getParentId());
        }
        bindingManager.setActiveScheme(bindingService.getActiveScheme());
    } catch (NotDefinedException e) {
        throw new Error("Internal error in DartKeyBindingPersistence"); //$NON-NLS-1$
    }
    bindingManager.setLocale(bindingService.getLocale());
    bindingManager.setPlatform(bindingService.getPlatform());

    Binding[] currentBindings = bindingService.getBindings();
    Set<Binding> trimmedBindings = new HashSet<Binding>();
    if (currentBindings != null) {
        for (Binding binding : currentBindings) {
            if (binding.getType() != Binding.USER) {
                trimmedBindings.add(binding);
            }
        }
    }
    Binding[] trimmedBindingArray = trimmedBindings.toArray(new Binding[trimmedBindings.size()]);
    bindingManager.setBindings(trimmedBindingArray);
}

From source file:com.google.dart.tools.ui.internal.preferences.DartKeyBindingPersistence.java

License:Open Source License

private void updateKeyBinding(Map<String, String> map) throws CoreException {
    try {//from  w  w  w.ja  va 2  s  .  com
        String platform = map.get(XML_ATTRIBUTE_PLATFORM);
        String commandName = map.get(XML_ATTRIBUTE_COMMANDID);
        String stdKeys = map.get(XML_ATTRIBUTE_KEYS);
        Binding binding = findBinding(commandName, platform);
        if (binding == null) {
            return;
        }
        Command command = binding.getParameterizedCommand().getCommand();
        ParameterizedCommand cmd = new ParameterizedCommand(command, null);
        String schemeId = binding.getSchemeId();
        String contextId = binding.getContextId();
        String locale = binding.getLocale();
        String wm = null;
        int type = Binding.USER;
        KeySequence stdSeq = KeySequence.getInstance(stdKeys);
        Binding newBind = new KeyBinding(stdSeq, cmd, schemeId, contextId, locale, platform, wm, type);
        bindingManager.removeBindings(stdSeq, schemeId, contextId, null, null, null, type);
        bindingManager.addBinding(newBind);
    } catch (NotDefinedException ex) {
        throw createException(ex, ex.getMessage());
    } catch (ParseException ex) {
        throw createException(ex, ex.getMessage());
    }
}

From source file:com.google.eclipse.mechanic.core.keybinding.KeyBindings.java

License:Open Source License

KeyBindings(MechanicLog log, Binding[] bindings) {
    this.log = log;
    List<Binding> ub = new ArrayList<Binding>();
    List<Binding> sb = new ArrayList<Binding>();

    for (Binding binding : bindings) {
        if (binding.getType() == Binding.USER) {
            ub.add(binding);/*from w ww  . ja va2 s  . co m*/
        } else if (binding.getType() == Binding.SYSTEM) {
            sb.add(binding);
        } else {
            throw new UnsupportedOperationException("Unexpected binding type: " + binding.getType());
        }
    }
    this.userBindings = ub;
    this.systemBindings = Collections.unmodifiableList(sb);
    this.userBindingsMap = buildQualifierToBindingMap(userBindings);
    this.systemBindingsMap = buildQualifierToBindingMap(systemBindings);
}

From source file:com.google.eclipse.mechanic.core.keybinding.KeyBindings.java

License:Open Source License

private void addUserBinding(Binding binding) {
    if (binding.getType() != Binding.USER) {
        throw new IllegalArgumentException("Can only accept user bindings.");
    }// ww  w .j  ava 2s.c  o  m
    userBindings.add(binding);
}

From source file:com.google.eclipse.mechanic.core.keybinding.KeyBindings.java

License:Open Source License

private Binding createBinding(Scheme scheme, String platform, String contextId, KeySequence triggerSequence,
        ParameterizedCommand parameterizedCommand) {

    Binding newBinding = new KeyBinding(triggerSequence, parameterizedCommand, scheme.getId(), contextId, null,
            platform, null, Binding.USER);

    return newBinding;
}