List of usage examples for org.eclipse.jface.action Action getAccelerator
@Override
public int getAccelerator()
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 www .j a va2 s .c om 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:com.nokia.carbide.remoteconnections.view.ConnectionsView.java
License:Open Source License
private void hookAccelerators() { keyListener = new KeyAdapter() { public void keyPressed(KeyEvent e) { for (Action action : actions) { if (e.keyCode == action.getAccelerator()) { action.run();/*from w w w . j a v a 2s . com*/ break; } } } }; viewer.getControl().addKeyListener(keyListener); }
From source file:org.eclipse.emf.ecp.ecoreeditor.internal.ui.CreateNewChildDialog.java
License:Open Source License
@Override protected Control createDialogArea(Composite parentComposite) { final ChildrenDescriptorCollector childrenDescriptorCollector = new ChildrenDescriptorCollector(); final EditingDomain editingDomain = AdapterFactoryEditingDomain.getEditingDomainFor(parent); final Dialog currentDialog = this; final List<Action> actions = getNewChildActions(childrenDescriptorCollector.getDescriptors(parent), editingDomain, parent);/*from w w w . j a va 2 s.c o m*/ final TableViewer list = new TableViewer(parentComposite); list.getControl().setLayoutData(new GridData(GridData.FILL_BOTH)); list.setContentProvider(new ArrayContentProvider()); list.setLabelProvider(new LabelProvider() { @Override public String getText(Object element) { final Action action = (Action) element; final StringBuilder builder = new StringBuilder(action.getText()); if (action.getAccelerator() > 0) { builder.append(" ["); builder.append(Character.toUpperCase((char) action.getAccelerator())); builder.append("]"); } return builder.toString(); } @Override public Image getImage(Object element) { return ((Action) element).getImageDescriptor().createImage(); } }); list.setInput(actions.toArray()); list.addOpenListener(new IOpenListener() { @Override public void open(OpenEvent event) { final Action action = (Action) ((StructuredSelection) event.getSelection()).getFirstElement(); action.run(); currentDialog.close(); } }); list.getControl().addKeyListener(new KeyListener() { @Override public void keyReleased(KeyEvent e) { // NOP } @Override public void keyPressed(KeyEvent e) { for (final Action a : actions) { if (a.getAccelerator() == e.keyCode) { a.run(); currentDialog.close(); break; } } } }); return parentComposite; }
From source file:org.fusesource.ide.graph.GraphViewSupport.java
License:Open Source License
private void addRadioMenuItem(MenuManager subMenu, final Action action) { subMenu.add(new ContributionItem() { @Override/*from w ww .j av a2s .c o m*/ public void fill(Menu menu, int index) { MenuItem menuItem = new MenuItem(menu, SWT.RADIO); menuItem.setText(action.getText()); menuItem.setAccelerator(action.getAccelerator()); menuItem.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { action.run(); } }); if (!setLayoutChecked) { setLayoutChecked = true; menuItem.setSelection(true); } } }); // menuItem.setImage(image)e(action.getImageDescriptor().getImageData().get) }