Example usage for org.eclipse.jface.action LegacyActionTools convertAccelerator

List of usage examples for org.eclipse.jface.action LegacyActionTools convertAccelerator

Introduction

In this page you can find the example usage for org.eclipse.jface.action LegacyActionTools convertAccelerator.

Prototype

public static int convertAccelerator(final String acceleratorText) 

Source Link

Document

Parses the given accelerator text, and converts it to an accelerator key code.

Usage

From source file:com.application.areca.launcher.gui.menus.AppAction.java

License:Open Source License

public AppAction(String resPrefixKey, Image image, Image bigImage, String actionCommand) {
    // Mnemonic//from   ww  w .j a v  a 2s.  c o m
    mnemonic = RM.getChar(resPrefixKey + ".mnemonic");

    // Accelerator
    String strAccel = RM.getLabel(resPrefixKey + ".accel", (String) null);
    if (strAccel != null) {
        accel = LegacyActionTools.convertAccelerator(strAccel);
    }

    // Label
    label = normalizeMenuLabel(RM.getLabel(resPrefixKey + ".label"), mnemonic, accel);

    // Icon
    if (image != null) {
        icon = image;
    }

    if (bigImage != null) {
        bigIcon = bigImage;
    }

    // Tooltip
    toolTip = RM.getLabel(resPrefixKey + ".tooltip", (String) null);

    command = actionCommand;
}

From source file:com.application.areca.launcher.gui.menus.AppAction.java

License:Open Source License

private static String normalizeMenuLabel(String label, char mnemonic, int accel) {
    label = addMnemonic(label, mnemonic);

    int defaultSize = 30;
    int size = Math.max(label.length(), defaultSize);
    StringBuffer sb = new StringBuffer(label);
    while (sb.length() < size) {
        sb.append(' ');
    }// w w w. j  av a2 s.  c  o m

    if (accel != -1) {
        sb.append("\t").append(LegacyActionTools.convertAccelerator(accel));
    }

    return sb.toString();
}

From source file:com.nokia.carbide.remoteconnections.view.ConnectionsView.java

License:Open Source License

private void makeActions() {
    actions = new ArrayList<Action>();
    connectionSelectedActions = new ArrayList<Action>();
    serviceSelectedActions = new ArrayList<Action>();

    Action action = new Action(Messages.getString("ConnectionsView.NewActionLabel"), CONNECTION_NEW_IMGDESC) { //$NON-NLS-1$
        @Override//from  w  ww .  java  2s.c o m
        public void run() {
            SettingsWizard wizard = new SettingsWizard();
            wizard.open(getViewSite().getShell());
        }

    };
    action.setId(NEW_ACTION);
    actions.add(action);
    action.setEnabled(!Registry.instance().getConnectionTypes().isEmpty());

    String editLabel = Messages.getString("ConnectionsView.EditActionLabel"); //$NON-NLS-1$
    action = new Action(editLabel, CONNECTION_EDIT_IMGDESC) { //$NON-NLS-1$
        @Override
        public void run() {
            ISelection selection = viewer.getSelection();
            if (selection.isEmpty())
                return;
            TreeNode node = (TreeNode) ((IStructuredSelection) selection).getFirstElement();
            Object value = node.getValue();
            if (value instanceof IConnection) {
                SettingsWizard wizard = new SettingsWizard((IConnection) value);
                wizard.open(getViewSite().getShell());
            }
        }
    };
    action.setId(EDIT_ACTION);
    actions.add(action);
    connectionSelectedActions.add(action);

    action = new Action() {
        @Override
        public void run() {
            ISelection selection = viewer.getSelection();
            if (selection.isEmpty())
                return;
            TreeNode node = (TreeNode) ((IStructuredSelection) selection).getFirstElement();
            Object value = node.getValue();
            if (value instanceof IConnection) {
                viewer.editElement(node, 0);
            }
        }

        @Override
        public boolean isEnabled() {
            return selectionCanBeEdited();
        }
    };
    action.setId(RENAME_ACTION);
    action.setAccelerator(SWT.F2);
    action.setText(Messages.getString("ConnectionsView.RenameMenuLabel") + //$NON-NLS-1$
            "\t" + //$NON-NLS-1$
            LegacyActionTools.convertAccelerator(action.getAccelerator()));
    actions.add(action);
    connectionSelectedActions.add(action);

    action = new EnableConnectedServiceAction();
    action.setId(ENABLE_SERVICE_ACTION);
    actions.add(action);
    serviceSelectedActions.add(action);

    action = new Action(Messages.getString("ConnectionsView.RefreshActionLabel"), CONNECTION_REFRESH_IMGDESC) { //$NON-NLS-1$
        @Override
        public void run() {
            IConnectionsManager connectionsManager = Registry.instance();
            for (IConnection connection : connectionsManager.getConnections()) {
                Collection<IConnectedService> connectedServices = connectionsManager
                        .getConnectedServices(connection);
                for (IConnectedService connectedService : connectedServices) {
                    connectedService.setEnabled(true);
                    connectedService.testStatus();
                }
            }
            ((EnableConnectedServiceAction) getAction(ENABLE_SERVICE_ACTION)).updateLabel();
        }
    };
    action.setAccelerator(SWT.F5);
    action.setId(REFRESH_ACTION);
    action.setEnabled(RemoteConnectionsActivator.getDefault().getShouldTestServices());
    actions.add(action);

    action = new Action(Messages.getString("ConnectionsView.DeleteActionLabel"), //$NON-NLS-1$
            PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_DELETE)) {
        @Override
        public void run() {
            ISelection selection = viewer.getSelection();
            if (selection.isEmpty() || !canBeEdited(selection))
                return;
            TreeNode node = (TreeNode) ((IStructuredSelection) selection).getFirstElement();
            Object value = node.getValue();
            if (value instanceof IConnection) {
                Registry.instance().removeConnection((IConnection) value);
                Registry.instance().storeConnections();
            }
        }

        @Override
        public boolean isEnabled() {
            return selectionCanBeEdited();
        }
    };
    action.setAccelerator(SWT.DEL);
    action.setId(DELETE_ACTION);
    actions.add(action);
    connectionSelectedActions.add(action);

    Image image = JFaceResources.getImage(org.eclipse.jface.dialogs.Dialog.DLG_IMG_HELP);
    ImageDescriptor desc = ImageDescriptor.createFromImage(image);
    action = new Action(Messages.getString("ConnectionsView.NoHelpActionLabel"), desc) { //$NON-NLS-1$

        private String getHelpContextFromSelection() {
            IConnection connection = getSelectedConnection();
            if (connection != null) {
                return connection.getConnectionType().getHelpContext();
            }
            return null;
        }

        @Override
        public String getText() {
            if (isEnabled()) {
                IConnection connection = getSelectedConnection();
                IConnectionType connectionType = connection.getConnectionType();
                String displayName = connectionType.getDisplayName();
                String pattern = Messages.getString("ConnectionsView.HelpActionLabel"); //$NON-NLS-1$
                return MessageFormat.format(pattern, displayName);
            }
            return super.getText();
        }

        @Override
        public boolean isEnabled() {
            return getHelpContextFromSelection() != null;
        }

        @Override
        public void run() {
            PlatformUI.getWorkbench().getHelpSystem().displayHelp(getHelpContextFromSelection());
        }
    };
    action.setId(HELP_ACTION);
    actions.add(action);
    connectionSelectedActions.add(action);

    desc = ConnectionUIUtils.CONNECTION_IMGDESC;
    action = new Action(Messages.getString("ConnectionsView.SetCurrentActionLabel"), desc) { //$NON-NLS-1$

        @Override
        public boolean isEnabled() {
            return !ObjectUtils.equals(Registry.instance().getCurrentConnection(), getSelectedConnection());
        }

        @Override
        public void run() {
            Registry.instance().setCurrentConnection(getSelectedConnection());
            setEnabled(false);
        }
    };
    action.setId(SET_CURRENT_ACTION);
    actions.add(action);
    connectionSelectedActions.add(action);

    action = new Action(Messages.getString("ConnectionsView.ToggleServicesLabel"), IAction.AS_CHECK_BOX) { //$NON-NLS-1$
        public void setChecked(boolean checked) {
            if (isChecked() != checked) {
                super.setChecked(checked);
                RemoteConnectionsActivator.getDefault().setShouldTestServices(checked);
                setImageDescriptor(checked ? SERVICE_TEST_IMGDESC : SERVICE_TEST_DISABLED_IMGDESC);
            }
        };
    };
    action.setId(TOGGLE_SERVICES_ACTION);
    action.setChecked(RemoteConnectionsActivator.getDefault().getShouldTestServices());
    action.setImageDescriptor(action.isChecked() ? SERVICE_TEST_IMGDESC : SERVICE_TEST_DISABLED_IMGDESC);
    actions.add(action);

    enableConnectionSelectedActions(false);
    enableServiceSelectedActions(false);

    makeToggleDiscoveryAgentActions();

    toggleServicesTestingListener = new IToggleServicesTestingListener() {
        public void servicesTestingToggled(boolean enabled) {
            getAction(TOGGLE_SERVICES_ACTION).setChecked(enabled);
            getAction(REFRESH_ACTION).setEnabled(enabled);
        }
    };
    RemoteConnectionsActivator.getDefault().addToggleServicesTestingListener(toggleServicesTestingListener);
}

From source file:org.seasar.uruma.renderer.RendererSupportUtil.java

License:Apache License

/**
 * ? {@code int} ??????<br />/*from  w ww .  j  a  v  a 2  s. com*/
 * 
 * 
 * @param value
 *        ?
 * @return ??
 */
public static int convertAccelerator(final String value) {
    return LegacyActionTools.convertAccelerator(value);
}