Example usage for org.eclipse.jface.util Util WS_COCOA

List of usage examples for org.eclipse.jface.util Util WS_COCOA

Introduction

In this page you can find the example usage for org.eclipse.jface.util Util WS_COCOA.

Prototype

String WS_COCOA

To view the source code for org.eclipse.jface.util Util WS_COCOA.

Click Source Link

Document

Windowing system constant.

Usage

From source file:org.eclipse.e4.ui.keybinding.tests.BindingPersistenceTest.java

License:Open Source License

public final void testSinglePlatform() throws Exception {
    // Get the services.
    ICommandService commandService = (ICommandService) fWorkbench.getAdapter(ICommandService.class);
    IBindingService bindingService = (IBindingService) fWorkbench.getAdapter(IBindingService.class);

    ParameterizedCommand about = new ParameterizedCommand(
            commandService.getCommand("org.eclipse.ui.help.aboutAction"), null);
    KeySequence m18A = KeySequence.getInstance("M1+8 A");
    KeySequence m18B = KeySequence.getInstance("M1+8 B");
    int numAboutBindings = 0;

    Binding[] bindings = bindingService.getBindings();
    for (int i = 0; i < bindings.length; i++) {
        final Binding binding = bindings[i];
        if (binding.getType() == Binding.SYSTEM) {
            String platform = binding.getPlatform();
            int idx = (platform == null ? -1 : platform.indexOf(','));
            assertEquals(binding.toString(), -1, idx);
            if (about.equals(binding.getParameterizedCommand())) {
                if (m18A.equals(binding.getTriggerSequence())) {
                    numAboutBindings++;//from  w ww. j  a v a 2s  . c  o  m
                    assertNull("M+8 A", binding.getPlatform());
                } else if (m18B.equals(binding.getTriggerSequence())) {
                    numAboutBindings++;
                    // assertEquals(Util.WS_CARBON, binding.getPlatform());
                    // temp work around for honouring carbon bindings
                    assertTrue("failure for platform: " + binding.getPlatform(),
                            Util.WS_CARBON.equals(binding.getPlatform())
                                    || Util.WS_COCOA.equals(binding.getPlatform()));
                }
            }
        }
    }
    if (Util.WS_CARBON.equals(SWT.getPlatform()) || Util.WS_COCOA.equals(SWT.getPlatform())) {
        assertEquals(2, numAboutBindings);
    } else {
        assertEquals(1, numAboutBindings);
    }
}

From source file:org.eclipse.e4.ui.keybinding.tests.BindingPersistenceTest.java

License:Open Source License

public final void testBindingTransform() throws Exception {
    ICommandService commandService = (ICommandService) fWorkbench.getAdapter(ICommandService.class);
    IBindingService bindingService = (IBindingService) fWorkbench.getAdapter(IBindingService.class);

    ParameterizedCommand addWS = new ParameterizedCommand(
            commandService.getCommand("org.eclipse.ui.navigate.addToWorkingSet"), null);
    KeySequence m18w = KeySequence.getInstance("M1+8 W");
    KeySequence m28w = KeySequence.getInstance("M2+8 W");
    boolean foundDeleteMarker = false;
    int numOfMarkers = 0;
    Binding[] bindings = bindingService.getBindings();
    for (int i = 0; i < bindings.length; i++) {
        final Binding binding = bindings[i];
        if (binding.getType() == Binding.SYSTEM) {
            String platform = binding.getPlatform();
            int idx = (platform == null ? -1 : platform.indexOf(','));
            assertEquals(binding.toString(), -1, idx);
            if (addWS.equals(binding.getParameterizedCommand())) {
                if (m18w.equals(binding.getTriggerSequence())) {
                    numOfMarkers++;/*w w  w .ja  v  a2s.  c  o  m*/
                    assertNull(m18w.format(), binding.getPlatform());
                } else if (m28w.equals(binding.getTriggerSequence())) {
                    numOfMarkers++;
                    assertTrue(platform, Util.WS_CARBON.equals(platform) || Util.WS_COCOA.equals(platform)
                            || Util.WS_GTK.equals(platform) || Util.WS_WIN32.equals(platform));
                }
            } else if (binding.getParameterizedCommand() == null && m18w.equals(binding.getTriggerSequence())) {
                assertTrue(platform, Util.WS_CARBON.equals(platform) || Util.WS_COCOA.equals(platform)
                        || Util.WS_GTK.equals(platform) || Util.WS_WIN32.equals(platform));
                numOfMarkers++;
                foundDeleteMarker = true;
            }
        }
    }
    assertEquals(3, numOfMarkers);
    assertTrue("Unable to find delete marker", foundDeleteMarker);
    TriggerSequence[] activeBindingsFor = bindingService.getActiveBindingsFor(addWS);
    assertEquals(1, activeBindingsFor.length);
}

From source file:org.eclipse.ui.internal.keys.BindingPersistence.java

License:Open Source License

/**
 * Reads all of the binding definitions from the commands extension point.
 * /*from  w  w  w.j ava2 s  .co m*/
 * @param configurationElements
 *            The configuration elements in the commands extension point;
 *            must not be <code>null</code>, but may be empty.
 * @param configurationElementCount
 *            The number of configuration elements that are really in the
 *            array.
 * @param bindingManager
 *            The binding manager to which the bindings should be added;
 *            must not be <code>null</code>.
 * @param commandService
 *            The command service for the workbench; must not be
 *            <code>null</code>.
 */
private static final void readBindingsFromRegistry(final IConfigurationElement[] configurationElements,
        final int configurationElementCount, final BindingManager bindingManager,
        final CommandManager commandService) {
    final Collection bindings = new ArrayList(configurationElementCount);
    final List warningsToLog = new ArrayList(1);

    HashSet cocoaTempList = new HashSet();
    // IViewRegistry viewRegistry =
    // PlatformUI.getWorkbench().getViewRegistry();

    // the local cache for the sequence modifiers
    IConfigurationElement[] sequenceModifiers = new IConfigurationElement[0];
    if (configurationElementCount > 0)
        sequenceModifiers = getSequenceModifierElements(configurationElements[0]);

    for (int i = 0; i < configurationElementCount; i++) {
        final IConfigurationElement configurationElement = configurationElements[i];

        // different extension. update the cache ...
        if (i > 0 && !configurationElement.getDeclaringExtension()
                .equals(configurationElements[i - 1].getDeclaringExtension()))
            sequenceModifiers = getSequenceModifierElements(configurationElement);

        /*
         * Read out the command id. Doing this before determining if the key
         * binding is actually valid is a bit wasteful. However, it is
         * helpful to have the command identifier when logging syntax
         * errors.
         */
        String commandId = readCommandId(configurationElement);

        String viewParameter = null;
        final Command command;
        if (commandId != null) {
            // TODO should we still try processing keybindings to viewIds?
            // if (viewRegistry.find(commandId) == null) {
            command = commandService.getCommand(commandId);
            if (!command.isDefined()) {
                // Reference to an undefined command. This is invalid.
                addWarning(warningsToLog, "Cannot bind to an undefined command", //$NON-NLS-1$
                        configurationElement, commandId);
                continue;
            }
        } else {
            command = null;
        }

        // Read out the scheme id.
        String schemeId = readSchemeId(configurationElement, warningsToLog, commandId);
        if (isEmpty(schemeId))
            continue;

        // Read out the context id.
        String contextId = readContextId(configurationElement);

        String keySequenceText = readKeySequenceText(configurationElement);
        if (isEmpty(keySequenceText)) {
            // The key sequence should never be null. This is pointless
            addWarning(warningsToLog, "Defining a key binding with no key sequence has no effect", //$NON-NLS-1$
                    configurationElement, commandId);
            continue;
        }

        // Read out the key sequence.
        KeySequence keySequence = readKeySequence(configurationElement, warningsToLog, commandId,
                keySequenceText);
        if (keySequence == null)
            continue;

        // Read out the locale and platform.

        String locale = readNonEmptyAttribute(configurationElement, ATT_LOCALE);
        String platform = readNonEmptyAttribute(configurationElement, ATT_PLATFORM);

        // Read out the parameters, if any.
        ParameterizedCommand parameterizedCommand = readParameterizedCommand(warningsToLog,
                configurationElement, viewParameter, command);

        List modifiedBindings = applyModifiers(keySequence, keySequenceText, platform, sequenceModifiers,
                parameterizedCommand, schemeId, contextId, locale, warningsToLog);

        KeyBinding binding = (KeyBinding) modifiedBindings.get(0);
        if (modifiedBindings.size() > 1) {
            for (int j = 1; j < modifiedBindings.size(); j++) {
                bindings.add(modifiedBindings.get(j));
            }
        }

        if (Util.WS_COCOA.equals(platform)) {
            cocoaTempList.add(binding);
        } else if (Util.WS_CARBON.equals(platform)) {
            bindings.add(binding);
            // temp work around ... simply honour the carbon
            // bindings for cocoa.
            cocoaTempList.add(new KeyBinding(keySequence, parameterizedCommand, schemeId, contextId, locale,
                    Util.WS_COCOA, null, Binding.SYSTEM));
        } else {
            bindings.add(binding);
        }
    }
    if (cocoaTempList.size() > 0) {
        bindings.addAll(cocoaTempList);
    }

    final Binding[] bindingArray = (Binding[]) bindings.toArray(new Binding[bindings.size()]);
    bindingManager.setBindings(bindingArray);

    logWarnings(warningsToLog,
            "Warnings while parsing the key bindings from the 'org.eclipse.ui.commands' extension point"); //$NON-NLS-1$
}

From source file:org.eclipse.ui.tests.keys.BindingPersistenceTest.java

License:Open Source License

public final void testBindingTransform() throws Exception {
    ICommandService commandService = (ICommandService) fWorkbench.getAdapter(ICommandService.class);
    IBindingService bindingService = (IBindingService) fWorkbench.getAdapter(IBindingService.class);

    ParameterizedCommand addWS = new ParameterizedCommand(
            commandService.getCommand("org.eclipse.ui.navigate.addToWorkingSet"), null);
    KeySequence m18w = KeySequence.getInstance("M1+8 W");
    KeySequence m28w = KeySequence.getInstance("M2+8 W");
    boolean foundDeleteMarker = false;
    int numOfMarkers = 0;
    Binding[] bindings = bindingService.getBindings();
    for (int i = 0; i < bindings.length; i++) {
        final Binding binding = bindings[i];
        if (binding.getType() == Binding.SYSTEM) {
            String platform = binding.getPlatform();
            int idx = (platform == null ? -1 : platform.indexOf(','));
            assertEquals(binding.toString(), -1, idx);
            if (addWS.equals(binding.getParameterizedCommand())) {
                if (m18w.equals(binding.getTriggerSequence())) {
                    numOfMarkers++;//from w w  w  .  j  av a  2 s  . c  o  m
                    assertNull(m18w.format(), binding.getPlatform());
                } else if (m28w.equals(binding.getTriggerSequence())) {
                    numOfMarkers++;
                    assertTrue(platform, Util.WS_CARBON.equals(platform) || Util.WS_COCOA.equals(platform)
                            || Util.WS_GTK.equals(platform) || Util.WS_WIN32.equals(platform));
                }
            } else if (binding.getParameterizedCommand() == null && m18w.equals(binding.getTriggerSequence())) {
                assertTrue(platform, Util.WS_CARBON.equals(platform) || Util.WS_COCOA.equals(platform)
                        || Util.WS_GTK.equals(platform) || Util.WS_WIN32.equals(platform));
                numOfMarkers++;
                foundDeleteMarker = true;
            }
        }
    }
    assertEquals(3, numOfMarkers);
    assertTrue("Unable to find delete marker", foundDeleteMarker);

    // make sure that the proper contexts are currently active
    IContextService contextService = (IContextService) fWorkbench.getService(IContextService.class);
    contextService.activateContext(IContextService.CONTEXT_ID_DIALOG_AND_WINDOW);
    contextService.activateContext(IContextService.CONTEXT_ID_WINDOW);
    TriggerSequence[] activeBindingsFor = bindingService.getActiveBindingsFor(addWS);
    assertEquals(1, activeBindingsFor.length);
}