List of usage examples for org.eclipse.jface.action Action convertAccelerator
public static int convertAccelerator(String acceleratorText)
From source file:com.github.haixing_hu.swt.action.ActionContributionItemEx.java
License:Open Source License
/** * Synchronizes the UI with the given property. * * @param propertyName/* w ww.j av a 2 s .c o m*/ * the name of the property, or <code>null</code> meaning all * applicable properties */ @Override public void update(String propertyName) { if (widget != null) { // determine what to do final boolean textChanged = (propertyName == null) || propertyName.equals(IAction.TEXT); boolean imageChanged = (propertyName == null) || propertyName.equals(IAction.IMAGE); final boolean tooltipTextChanged = (propertyName == null) || propertyName.equals(IAction.TOOL_TIP_TEXT); final boolean enableStateChanged = (propertyName == null) || propertyName.equals(IAction.ENABLED) || propertyName.equals(IContributionManagerOverrides.P_ENABLED); final boolean checkChanged = ((action.getStyle() == IAction.AS_CHECK_BOX) || (action.getStyle() == IAction.AS_RADIO_BUTTON)) && ((propertyName == null) || propertyName.equals(IAction.CHECKED)); if (!showImage) { // do not update the image if not show image imageChanged = false; } if (widget instanceof ToolItem) { final ToolItem ti = (ToolItem) widget; String text = action.getText(); // the set text is shown only if there is no image or if forced // by MODE_FORCE_TEXT final boolean showText = (text != null) && (((getMode() & MODE_FORCE_TEXT) != 0) || !hasImages(action)); // only do the trimming if the text will be used if (showText && (text != null)) { text = Action.removeAcceleratorText(text); text = Action.removeMnemonics(text); } if (textChanged) { final String textToSet = showText ? text : ""; //$NON-NLS-1$ final boolean rightStyle = (ti.getParent().getStyle() & SWT.RIGHT) != 0; if (rightStyle || !ti.getText().equals(textToSet)) { // In addition to being required to update the text if // it // gets nulled out in the action, this is also a // workaround // for bug 50151: Using SWT.RIGHT on a ToolBar leaves // blank space ti.setText(textToSet); } } if (imageChanged) { // only substitute a missing image if it has no text updateImages(!showText); } if (tooltipTextChanged || textChanged) { String toolTip = action.getToolTipText(); if ((toolTip == null) || (toolTip.length() == 0)) { toolTip = text; } final ExternalActionManager.ICallback callback = ExternalActionManager.getInstance() .getCallback(); final String commandId = action.getActionDefinitionId(); if ((callback != null) && (commandId != null) && (toolTip != null)) { final String acceleratorText = callback.getAcceleratorText(commandId); if ((acceleratorText != null) && (acceleratorText.length() != 0)) { toolTip = JFaceResources.format("Toolbar_Tooltip_Accelerator", //$NON-NLS-1$ new Object[] { toolTip, acceleratorText }); } } // if the text is showing, then only set the tooltip if // different if (!showText || ((toolTip != null) && !toolTip.equals(text))) { ti.setToolTipText(toolTip); } else { ti.setToolTipText(null); } } if (enableStateChanged) { final boolean shouldBeEnabled = action.isEnabled() && isEnabledAllowed(); if (ti.getEnabled() != shouldBeEnabled) { ti.setEnabled(shouldBeEnabled); } } if (checkChanged) { final boolean bv = action.isChecked(); if (ti.getSelection() != bv) { ti.setSelection(bv); } } return; } if (widget instanceof MenuItem) { final MenuItem mi = (MenuItem) widget; if (textChanged) { int accelerator = 0; String acceleratorText = null; final ActionEx updatedAction = getAction(); String text = null; accelerator = updatedAction.getAccelerator(); final ExternalActionManager.ICallback callback = ExternalActionManager.getInstance() .getCallback(); // Block accelerators that are already in use. if ((accelerator != 0) && (callback != null) && (callback.isAcceleratorInUse(accelerator))) { accelerator = 0; } /* * Process accelerators on GTK in a special way to avoid Bug 42009. We * will override the native input method by allowing these reserved * accelerators to be placed on the menu. We will only do this for * "Ctrl+Shift+[0-9A-FU]". */ final String commandId = updatedAction.getActionDefinitionId(); if ((Util.isGtk()) && (callback instanceof IBindingManagerCallback) && (commandId != null)) { final IBindingManagerCallback bindingManagerCallback = (IBindingManagerCallback) callback; final IKeyLookup lookup = KeyLookupFactory.getDefault(); final TriggerSequence[] triggerSequences = bindingManagerCallback .getActiveBindingsFor(commandId); for (final TriggerSequence triggerSequence : triggerSequences) { final Trigger[] triggers = triggerSequence.getTriggers(); if (triggers.length == 1) { final Trigger trigger = triggers[0]; if (trigger instanceof KeyStroke) { final KeyStroke currentKeyStroke = (KeyStroke) trigger; final int currentNaturalKey = currentKeyStroke.getNaturalKey(); if ((currentKeyStroke .getModifierKeys() == (lookup.getCtrl() | lookup.getShift())) && (((currentNaturalKey >= '0') && (currentNaturalKey <= '9')) || ((currentNaturalKey >= 'A') && (currentNaturalKey <= 'F')) || (currentNaturalKey == 'U'))) { accelerator = currentKeyStroke.getModifierKeys() | currentNaturalKey; acceleratorText = triggerSequence.format(); break; } } } } } if (accelerator == 0) { if ((callback != null) && (commandId != null)) { acceleratorText = callback.getAcceleratorText(commandId); } } IContributionManagerOverrides overrides = null; if (getParent() != null) { overrides = getParent().getOverrides(); } if (overrides != null) { text = getParent().getOverrides().getText(this); } mi.setAccelerator(accelerator); if (text == null) { text = updatedAction.getText(); } if ((text != null) && (acceleratorText == null)) { // use extracted accelerator text in case accelerator // cannot be fully represented in one int (e.g. // multi-stroke keys) acceleratorText = LegacyActionTools.extractAcceleratorText(text); if ((acceleratorText == null) && (accelerator != 0)) { acceleratorText = Action.convertAccelerator(accelerator); } } if (text == null) { text = ""; //$NON-NLS-1$ } else { text = Action.removeAcceleratorText(text); } // add "..." if the action will show a dialog if (updatedAction.isShowDialog()) { text = text + dialogIndicator; } if (acceleratorText == null) { mi.setText(text); } else { mi.setText(text + '\t' + acceleratorText); } } if (imageChanged) { updateImages(false); } if (enableStateChanged) { final boolean shouldBeEnabled = action.isEnabled() && isEnabledAllowed(); if (mi.getEnabled() != shouldBeEnabled) { mi.setEnabled(shouldBeEnabled); } } if (checkChanged) { final boolean bv = action.isChecked(); if (mi.getSelection() != bv) { mi.setSelection(bv); } } return; } if (widget instanceof Button) { final Button button = (Button) widget; if (imageChanged) { updateImages(false); } if (textChanged) { String text = action.getText(); final boolean showText = (text != null) && (((getMode() & MODE_FORCE_TEXT) != 0) || !hasImages(action)); // only do the trimming if the text will be used if (showText) { text = Action.removeAcceleratorText(text); } final String textToSet = showText ? text : ""; //$NON-NLS-1$ button.setText(textToSet); } if (tooltipTextChanged) { button.setToolTipText(action.getToolTipText()); } if (enableStateChanged) { final boolean shouldBeEnabled = action.isEnabled() && isEnabledAllowed(); if (button.getEnabled() != shouldBeEnabled) { button.setEnabled(shouldBeEnabled); } } if (checkChanged) { final boolean bv = action.isChecked(); if (button.getSelection() != bv) { button.setSelection(bv); } } return; } } }
From source file:org.cishell.reference.gui.menumanager.menu.MenuAdapter.java
License:Open Source License
private static int determineActionAcceleratorKeyCode(ServiceReference serviceReference, Action action) { String shortcutString = (String) serviceReference.getProperty(SHORTCUT); if (shortcutString != null) { return Action.convertAccelerator(shortcutString); } else {/*from w w w. j ava 2s . c o m*/ return 0; } }
From source file:org.eclipse.ui.internal.ActionDescriptor.java
License:Open Source License
/** * Process the accelerator definition. If it is a number * then process the code directly - if not then parse it * and create the code//from www . j ava2s . co m */ private void processAccelerator(IAction action, String acceleratorText) { if (acceleratorText.length() == 0) { return; } //Is it a numeric definition? if (Character.isDigit(acceleratorText.charAt(0))) { try { action.setAccelerator(Integer.valueOf(acceleratorText).intValue()); } catch (NumberFormatException e) { WorkbenchPlugin.log("Invalid accelerator declaration for action: " + id, e); //$NON-NLS-1$ } } else { action.setAccelerator(Action.convertAccelerator(acceleratorText)); } }
From source file:org.springframework.ide.eclipse.boot.dash.util.ToolbarPulldownContributionItem.java
License:Open Source License
/** * Synchronizes the UI with the given property. * * @param propertyName//from w w w. j ava2 s . c o m * the name of the property, or <code>null</code> meaning all * applicable properties */ @Override public void update(String propertyName) { if (widget != null) { // determine what to do boolean textChanged = propertyName == null || propertyName.equals(IAction.TEXT); boolean imageChanged = propertyName == null || propertyName.equals(IAction.IMAGE); boolean tooltipTextChanged = propertyName == null || propertyName.equals(IAction.TOOL_TIP_TEXT); boolean enableStateChanged = propertyName == null || propertyName.equals(IAction.ENABLED) || propertyName.equals(IContributionManagerOverrides.P_ENABLED); boolean checkChanged = (action.getStyle() == IAction.AS_CHECK_BOX || action.getStyle() == IAction.AS_RADIO_BUTTON) && (propertyName == null || propertyName.equals(IAction.CHECKED)); if (widget instanceof ToolItem) { ToolItem ti = (ToolItem) widget; String text = action.getText(); // the set text is shown only if there is no image or if forced // by MODE_FORCE_TEXT boolean showText = text != null && ((getMode() & MODE_FORCE_TEXT) != 0 || !hasImages(action)); // only do the trimming if the text will be used if (showText && text != null) { text = Action.removeAcceleratorText(text); text = Action.removeMnemonics(text); } if (textChanged) { String textToSet = showText ? text : ""; //$NON-NLS-1$ boolean rightStyle = (ti.getParent().getStyle() & SWT.RIGHT) != 0; if (rightStyle || !ti.getText().equals(textToSet)) { // In addition to being required to update the text if // it // gets nulled out in the action, this is also a // workaround // for bug 50151: Using SWT.RIGHT on a ToolBar leaves // blank space ti.setText(textToSet); } } if (imageChanged) { // only substitute a missing image if it has no text updateImages(!showText); } if (tooltipTextChanged || textChanged) { String toolTip = action.getToolTipText(); if ((toolTip == null) || (toolTip.length() == 0)) { toolTip = text; } ExternalActionManager.ICallback callback = ExternalActionManager.getInstance().getCallback(); String commandId = action.getActionDefinitionId(); if ((callback != null) && (commandId != null) && (toolTip != null)) { String acceleratorText = callback.getAcceleratorText(commandId); if (acceleratorText != null && acceleratorText.length() != 0) { toolTip = JFaceResources.format("Toolbar_Tooltip_Accelerator", //$NON-NLS-1$ new Object[] { toolTip, acceleratorText }); } } // if the text is showing, then only set the tooltip if // different if (!showText || toolTip != null && !toolTip.equals(text)) { ti.setToolTipText(toolTip); } else { ti.setToolTipText(null); } } if (enableStateChanged) { boolean shouldBeEnabled = action.isEnabled() && isEnabledAllowed(); if (ti.getEnabled() != shouldBeEnabled) { ti.setEnabled(shouldBeEnabled); } } if (checkChanged) { boolean bv = action.isChecked(); if (ti.getSelection() != bv) { ti.setSelection(bv); } } return; } if (widget instanceof MenuItem) { MenuItem mi = (MenuItem) widget; if (textChanged) { int accelerator = 0; String acceleratorText = null; IAction updatedAction = getAction(); String text = null; accelerator = updatedAction.getAccelerator(); ExternalActionManager.ICallback callback = ExternalActionManager.getInstance().getCallback(); // Block accelerators that are already in use. if ((accelerator != 0) && (callback != null) && (callback.isAcceleratorInUse(accelerator))) { accelerator = 0; } /* * Process accelerators on GTK in a special way to avoid Bug * 42009. We will override the native input method by * allowing these reserved accelerators to be placed on the * menu. We will only do this for "Ctrl+Shift+[0-9A-FU]". */ final String commandId = updatedAction.getActionDefinitionId(); if ((Util.isGtk()) && (callback instanceof IBindingManagerCallback) && (commandId != null)) { final IBindingManagerCallback bindingManagerCallback = (IBindingManagerCallback) callback; final IKeyLookup lookup = KeyLookupFactory.getDefault(); final TriggerSequence[] triggerSequences = bindingManagerCallback .getActiveBindingsFor(commandId); for (int i = 0; i < triggerSequences.length; i++) { final TriggerSequence triggerSequence = triggerSequences[i]; final Trigger[] triggers = triggerSequence.getTriggers(); if (triggers.length == 1) { final Trigger trigger = triggers[0]; if (trigger instanceof KeyStroke) { final KeyStroke currentKeyStroke = (KeyStroke) trigger; final int currentNaturalKey = currentKeyStroke.getNaturalKey(); if ((currentKeyStroke .getModifierKeys() == (lookup.getCtrl() | lookup.getShift())) && ((currentNaturalKey >= '0' && currentNaturalKey <= '9') || (currentNaturalKey >= 'A' && currentNaturalKey <= 'F') || (currentNaturalKey == 'U'))) { accelerator = currentKeyStroke.getModifierKeys() | currentNaturalKey; acceleratorText = triggerSequence.format(); break; } } } } } if (accelerator == 0) { if ((callback != null) && (commandId != null)) { acceleratorText = callback.getAcceleratorText(commandId); } } IContributionManagerOverrides overrides = null; if (getParent() != null) { overrides = getParent().getOverrides(); } if (overrides != null) { text = getParent().getOverrides().getText(this); } mi.setAccelerator(accelerator); if (text == null) { text = updatedAction.getText(); } if (text != null && acceleratorText == null) { // use extracted accelerator text in case accelerator // cannot be fully represented in one int (e.g. // multi-stroke keys) acceleratorText = LegacyActionTools.extractAcceleratorText(text); if (acceleratorText == null && accelerator != 0) { acceleratorText = Action.convertAccelerator(accelerator); } } if (text == null) { text = ""; //$NON-NLS-1$ } else { text = Action.removeAcceleratorText(text); } if (acceleratorText == null) { mi.setText(text); } else { mi.setText(text + '\t' + acceleratorText); } } if (imageChanged) { updateImages(false); } if (enableStateChanged) { boolean shouldBeEnabled = action.isEnabled() && isEnabledAllowed(); if (mi.getEnabled() != shouldBeEnabled) { mi.setEnabled(shouldBeEnabled); } } if (checkChanged) { boolean bv = action.isChecked(); if (mi.getSelection() != bv) { mi.setSelection(bv); } } return; } if (widget instanceof Button) { Button button = (Button) widget; if (imageChanged) { updateImages(false); } if (textChanged) { String text = action.getText(); boolean showText = text != null && ((getMode() & MODE_FORCE_TEXT) != 0 || !hasImages(action)); // only do the trimming if the text will be used if (showText) { text = Action.removeAcceleratorText(text); } String textToSet = showText ? text : ""; //$NON-NLS-1$ button.setText(textToSet); } if (tooltipTextChanged) { button.setToolTipText(action.getToolTipText()); } if (enableStateChanged) { boolean shouldBeEnabled = action.isEnabled() && isEnabledAllowed(); if (button.getEnabled() != shouldBeEnabled) { button.setEnabled(shouldBeEnabled); } } if (checkChanged) { boolean bv = action.isChecked(); if (button.getSelection() != bv) { button.setSelection(bv); } } return; } } }
From source file:org.wso2.developerstudio.eclipse.greg.manager.remote.views.RegistryBrowserView.java
License:Open Source License
public void createActions(final Composite parent) { parentComposite = parent;/*from w ww . ja va2 s .c o m*/ //Getting the Handler service IHandlerService handlerService = (IHandlerService) getSite().getService(IHandlerService.class); addRegistryAction = new Action("Add Registry...") { public void run() { addItem(parent); } }; addRegistryAction.setImageDescriptor(ImageUtils.getImageDescriptor(ImageUtils.ACTION_ADD_REGSISTY)); refreshAction = new Action("Refresh") { public void run() { refreshItem(); } }; refreshAction.setImageDescriptor(ImageUtils.getImageDescriptor(ImageUtils.ACTION_REFERESH)); refreshAction.setAccelerator(SWT.F5); refreshAction.setActionDefinitionId("org.wso2.developerstudio.registry.browser.commands.refresh"); activateRefreshHandler = handlerService.activateHandler( "org.wso2.developerstudio.registry.browser.commands.refresh", new ActionHandler(refreshAction)); addCollectionAction = new Action("Add a new Collection..") { public void run() { RegistryResourceNode r = (RegistryResourceNode) selectedObj; ResourceEditorInput ei = RemoteContentManager.getEditorInput(r, true); ei.setCollection(true); RemoteContentManager.openFormEditor(ei); } }; addCollectionAction.setImageDescriptor(ImageUtils.getImageDescriptor(ImageUtils.ACTION_ADD_COLLECTION)); addCollectionAction.setAccelerator(SWT.INSERT); addResourceAction = new Action("Add a new Resource..") { public void run() { RegistryResourceNode r = (RegistryResourceNode) selectedObj; ResourceEditorInput ei = RemoteContentManager.getEditorInput(r, true); ei.setCollection(false); RemoteContentManager.openFormEditor(ei); } }; addResourceAction.setImageDescriptor(ImageUtils.getImageDescriptor(ImageUtils.ACTION_ADD_RESOURCE)); addResourceAction.setAccelerator(Action.convertAccelerator("Ctrl+Insert")); addResourceAction.setActionDefinitionId("org.wso2.developerstudio.registry.browser.commands.addresource"); activateAddResourceHandler = handlerService.activateHandler( "org.wso2.developerstudio.registry.browser.commands.addresource", new ActionHandler(addResourceAction)); deleteAction = new Action("Delete..") { public void run() { deleteItem(parent); } }; deleteAction.setImageDescriptor(ImageUtils.getImageDescriptor(ImageUtils.STATE_DELETED)); deleteAction.setAccelerator(SWT.DEL); deleteAction.setActionDefinitionId("org.wso2.developerstudio.registry.browser.commands.delete"); activateDeleteHandler = handlerService.activateHandler( "org.wso2.developerstudio.registry.browser.commands.delete", new ActionHandler(deleteAction)); // try { // IViewPart createView = PlatformUI.getWorkbench().getViewRegistry().find("org.wso2.developerstudio.registry.remote.registry.view").createView(); // createView.init(getViewSite()); // createView. // getSite().getService(IHandlerService.class); // } catch (CoreException e1) { // TODO Auto-generated catch block // e1.printStackTrace(); // } // getSite().getService(IHandlerService.class); renameAction = new Action("Rename..") { public void run() { renameItem(parent); } }; renameAction.setImageDescriptor(ImageUtils.getImageDescriptor(ImageUtils.ICON_RENAME)); renameAction.setAccelerator(SWT.F2); renameAction.setActionDefinitionId("org.wso2.developerstudio.registry.browser.commands.rename"); activateRenameHandler = handlerService.activateHandler( "org.wso2.developerstudio.registry.browser.commands.rename", new ActionHandler(renameAction)); communityAction = new Action("Community...") { public void run() { } }; communityAction.setImageDescriptor(ImageUtils.getImageDescriptor(ImageUtils.ACTION_COMMUNITY_FEATURES)); metaDataAction = new Action("Metadata...") { public void run() { } }; metaDataAction.setImageDescriptor(ImageUtils.getImageDescriptor(ImageUtils.ACTION_ADD_METADATA)); commentsAction = new Action("Add Comment...") { public void run() { RegistryResourceNode r = (RegistryResourceNode) selectedObj; ResourceEditorInput ei = RemoteContentManager.getEditorInput(r); RegistryResourceEditor openFormEditor = RemoteContentManager.openFormEditor(ei); openFormEditor.performAction(IRegistryFormEditorPage.PAGE_COMMENTS, IRegistryFormEditorPage.ACTION_ADD_COMMENT, null); } }; commentsAction.setImageDescriptor(ImageUtils.getImageDescriptor(ImageUtils.ACTION_ADD_COMMENT)); tagsAction = new Action("Add a tag...") { public void run() { RegistryResourceNode r = (RegistryResourceNode) selectedObj; ResourceEditorInput ei = RemoteContentManager.getEditorInput(r); RegistryResourceEditor openFormEditor = RemoteContentManager.openFormEditor(ei); openFormEditor.performAction(IRegistryFormEditorPage.PAGE_TAGS, IRegistryFormEditorPage.ACTION_ADD_TAGS, null); } }; tagsAction.setImageDescriptor(ImageUtils.getImageDescriptor(ImageUtils.ACTION_ADD_TAGS)); ratingsAction = new Action("Add a Rating...") { public void run() { RegistryResourceNode r = (RegistryResourceNode) selectedObj; ResourceEditorInput ei = RemoteContentManager.getEditorInput(r); RegistryResourceEditor openFormEditor = RemoteContentManager.openFormEditor(ei); RegistryResourceType selectedType = r.getResourceType(); int page = -1; if (selectedType.equals(RegistryResourceType.RESOURCE)) { page = IRegistryFormEditorPage.PAGE_RESOURCE; } else if (selectedType.equals(RegistryResourceType.COLLECTION)) { page = IRegistryFormEditorPage.PAGE_COLLECTION; } if (page != -1) { openFormEditor.performAction(page, IRegistryFormEditorPage.ACTION_VIEW_INFORMATION, null); } } }; ratingsAction.setImageDescriptor(ImageUtils.getImageDescriptor(ImageUtils.RATINGS_STAR0)); propertyAction = new Action("Add a Property...") { public void run() { RegistryResourceNode r = (RegistryResourceNode) selectedObj; ResourceEditorInput ei = RemoteContentManager.getEditorInput(r); RegistryResourceEditor openFormEditor = RemoteContentManager.openFormEditor(ei); openFormEditor.performAction(IRegistryFormEditorPage.PAGE_PROPERTIES, IRegistryFormEditorPage.ACTION_ADD_PROPERTY, null); } }; propertyAction.setImageDescriptor(ImageUtils.getImageDescriptor(ImageUtils.ACTION_ADD_PROPERTIES)); lifeCyclesAction = new Action("Add a Lifecycle...") { public void run() { } }; lifeCyclesAction.setImageDescriptor(ImageUtils.getImageDescriptor(ImageUtils.ACTION_ADD_LIFECYCLE)); dependenciesAction = new Action("Add a Dependency...") { public void run() { RegistryResourceNode r = (RegistryResourceNode) selectedObj; ResourceEditorInput ei = RemoteContentManager.getEditorInput(r); RegistryResourceEditor openFormEditor = RemoteContentManager.openFormEditor(ei); openFormEditor.performAction(IRegistryFormEditorPage.PAGE_DEPENDENCY, IRegistryFormEditorPage.ACTION_ADD_DEPENDENCY, null); } }; dependenciesAction.setImageDescriptor(ImageUtils.getImageDescriptor(ImageUtils.ACTION_ADD_DEPENDENCY)); associationAction = new Action("Add an Association...") { public void run() { RegistryResourceNode r = (RegistryResourceNode) selectedObj; ResourceEditorInput ei = RemoteContentManager.getEditorInput(r); RegistryResourceEditor openFormEditor = RemoteContentManager.openFormEditor(ei); openFormEditor.performAction(IRegistryFormEditorPage.PAGE_ASSOCIATIONS, IRegistryFormEditorPage.ACTION_ADD_ASSOCIATION, null); } }; associationAction.setImageDescriptor(ImageUtils.getImageDescriptor(ImageUtils.ACTION_ADD_ASSOCIATION)); enableAction = new Action("Re-Connect") { public void run() { changeRegistryUrlStatus(true); } }; enableAction.setImageDescriptor(ImageUtils.getImageDescriptor(ImageUtils.ACTION_RECONNECT_REGISTRY)); disableAction = new Action("Disconnect...") { public void run() { changeRegistryUrlStatus(false); } }; disableAction.setImageDescriptor(ImageUtils.getImageDescriptor(ImageUtils.ACTION_DISCONNECT_REGISTRY)); multipleFileAction = new Action("multiple files...") { public void run() { addMultipleFiles(); } }; multipleFileAction.setImageDescriptor(ImageUtils.getImageDescriptor(ImageUtils.ACTION_ADD_MULTIPLE_FILES)); multipleFolderAction = new Action("folder...") { public void run() { addMultipleFolders(); } }; multipleFolderAction.setImageDescriptor(ImageUtils.getImageDescriptor(ImageUtils.ACTION_ADD_FOLDER)); resourceInformationAction = new Action("Information") { public void run() { RegistryResourceNode r = (RegistryResourceNode) selectedObj; ResourceEditorInput ei = RemoteContentManager.getEditorInput(r); RegistryResourceEditor openFormEditor = RemoteContentManager.openFormEditor(ei); // RemoteContentManager.openFormEditor(ei); // RegistryResourceEditor openFormEditor = RemoteContentManager.openFormEditor(ei); if (r.getResourceType() == RegistryResourceType.RESOURCE) { openFormEditor.performAction(IRegistryFormEditorPage.PAGE_RESOURCE, IRegistryFormEditorPage.ACTION_VIEW_INFORMATION, null); } else { openFormEditor.performAction(IRegistryFormEditorPage.PAGE_COLLECTION, IRegistryFormEditorPage.ACTION_VIEW_INFORMATION, null); } } }; resourceInformationAction.setImageDescriptor(ImageUtils.getImageDescriptor(ImageUtils.ICON_INFORMATION)); treeViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { updateActionEnablement(); } }); importFromAction = new Action("Import From") { public void run() { RegistryTreeBrowserDialog r = new RegistryTreeBrowserDialog(Display.getCurrent().getActiveShell(), RegistryTreeBrowserDialog.SELECT_REGISTRY_PATH); r.create(); List<RegistryURLInfo> allRegistryUrls = RegistryUrlStore.getInstance().getAllRegistryUrls(); for (RegistryURLInfo registryURLInfo : allRegistryUrls) { r.addRegistryNode(registryURLInfo, null); } r.selectRegistryPath(regResourceNode.getConnectionInfo(), regResourceNode.getRegistryResourcePath()); if (r.open() == Window.OK) { targetRegResourceNode = r.getSelectedRegistryResourceNode(); try { importExportResource(targetRegResourceNode, regResourceNode, DragDropUtils.ACTION_IMPORT); } catch (Exception e) { log.error(e); } } } }; importFromAction.setImageDescriptor(ImageUtils.getImageDescriptor(ImageUtils.ACTION_IMPORT_TO_REGISTRY)); exportToAction = new Action("Export To") { public void run() { RegistryTreeBrowserDialog r = new RegistryTreeBrowserDialog(Display.getCurrent().getActiveShell(), RegistryTreeBrowserDialog.SELECT_REGISTRY_PATH); r.create(); List<RegistryURLInfo> allRegistryUrls = RegistryUrlStore.getInstance().getAllRegistryUrls(); for (RegistryURLInfo registryURLInfo : allRegistryUrls) { r.addRegistryNode(registryURLInfo, null); } r.selectRegistryPath(regResourceNode.getConnectionInfo(), regResourceNode.getRegistryResourcePath()); if (r.open() == Window.OK) { targetRegResourceNode = r.getSelectedRegistryResourceNode(); try { for (int i = 0; i < selectedItemList.size(); i++) { if (selectedItemList.get(i) instanceof RegistryResourceNode) { regResourceNode = (RegistryResourceNode) selectedItemList.get(i); importExportResource(regResourceNode, targetRegResourceNode, DragDropUtils.ACTION_EXPORT); } } Display.getDefault().asyncExec(new Runnable() { public void run() { try { targetRegResourceNode.refreshChildren(); } catch (InvalidRegistryURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (UnknownRegistryException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); } catch (Exception e) { log.error(e); } } } }; exportToAction.setImageDescriptor(ImageUtils.getImageDescriptor(ImageUtils.ACTION_EXPORT_TO_REGISTRY)); versionSubMenu = new MenuManager("Versions", ImageUtils.getImageDescriptor(ImageUtils.ICON_VERSIONS), "org.eclipse.community.submenu"); changeRolePermission = new Action("Change Permission") { public void run() { ChangePermissionWizard wizard = new ChangePermissionWizard(regUserRole, regResourceNode); WizardDialog dialog = new WizardDialog(new Shell(), wizard); dialog.create(); dialog.open(); } }; changeRolePermission .setImageDescriptor(ImageUtils.getImageDescriptor(ImageUtils.ACTION_MODIFY_PERMISSION_ROLE)); modifyResourcePermission = new Action("Modify Permissions") { public void run() { UserPermissionDialog dialog = new UserPermissionDialog(parent.getShell(), regResourceNode); dialog.setBlockOnOpen(true); dialog.create(); dialog.getShell().setSize(600, 500); dialog.open(); } }; modifyResourcePermission .setImageDescriptor(ImageUtils.getImageDescriptor(ImageUtils.ACTION_MODIFY_PERMISSION_RESOURCE)); addUsers = new Action("Add User") { public void run() { AddUserWizard wizard = new AddUserWizard(selectedObj, true, regNode); WizardDialog dialog = new WizardDialog(new Shell(), wizard); dialog.create(); if (dialog.open() == dialog.OK) { regUserContainer.setIterativeRefresh(true); regUserContainer.getRegistryUserManagerContainer().getUserRoleContent() .setIterativeRefresh(true); regUserContainer.getRegistryUserManagerContainer().getRegistryData().getRegUrlData() .dataChanged(false); } } }; addUsers.setImageDescriptor(ImageUtils.getImageDescriptor(ImageUtils.ICON_USERS_ROLES)); addRoles = new Action("Add Role") { public void run() { RegistryNode node = ((RegistryUserRoleContainer) selectedObj).getConnectionInfo(); // node.getRegistryContent().getRegistryContent().get(0). String path = null; RegistryResourceNode resourceNode = null; try { path = searchRegistryNodeForResource(node, "Permission"); resourceNode = searchRegistryNodeForResourceNode(node, "Permission"); } catch (InvalidRegistryURLException e) { e.printStackTrace(); } catch (UnknownRegistryException e) { e.printStackTrace(); } if (path == null) { path = node.getRegistryStartingPath(); } AddRoleWizard wizard = new AddRoleWizard(((RegistryUserRoleContainer) selectedObj), node, path, resourceNode); WizardDialog dialog = new WizardDialog(new Shell(), wizard); dialog.create(); // dialog.open(); if (dialog.open() == dialog.OK) { regRoleContainer.setIterativeRefresh(true); regRoleContainer.getRegistryUserManagerContainer().getUserRoleContent() .setIterativeRefresh(true); regRoleContainer.getRegistryUserManagerContainer().getRegistryData().getRegUrlData() .dataChanged(false); } } }; addRoles.setImageDescriptor(ImageUtils.getImageDescriptor(ImageUtils.ICON_ROLES)); modifyUserInfo = new Action("Modify User Info") { public void run() { AddUserWizard wizard = new AddUserWizard(selectedObj, false, regUrlNode.getUrlInfoList().get(0)); WizardDialog dialog = new WizardDialog(new Shell(), wizard); dialog.create(); dialog.open(); } }; modifyUserInfo.setImageDescriptor(ImageUtils.getImageDescriptor(ImageUtils.ICON_USERS_ROLES)); linkWithEditorAction = new Action("Link with Editor", IAction.AS_CHECK_BOX) { public void run() { setLinkedWithEditor(isChecked()); } }; linkWithEditorAction .setImageDescriptor(ImageUtils.getImageDescriptor(ImageUtils.ACTION_TOGGLE_SHOW_IN_REGISTRY_VIEW)); copyAction = new Action("Copy") { public void run() { copyResource(); } }; copyAction.setImageDescriptor(ImageUtils.getImageDescriptor(ImageUtils.ICON_COPY)); copyAction.setAccelerator(SWT.CTRL + 'C'); copyAction.setActionDefinitionId("org.wso2.developerstudio.registry.browser.commands.copy"); activateCopyHandler = handlerService.activateHandler( "org.wso2.developerstudio.registry.browser.commands.copy", new ActionHandler(copyAction)); pasteAction = new Action("Paste") { public void run() { try { pasteResource(); } catch (Exception e) { log.error(e); } } }; pasteAction.setImageDescriptor(ImageUtils.getImageDescriptor(ImageUtils.ICON_PASTE)); pasteAction.setAccelerator(SWT.CTRL + 'V'); pasteAction.setActionDefinitionId("org.wso2.developerstudio.registry.browser.commands.paste"); activatePasteHandler = handlerService.activateHandler( "org.wso2.developerstudio.registry.browser.commands.paste", new ActionHandler(pasteAction)); }
From source file:org.xmind.ui.color.ColorPicker.java
License:Open Source License
/** * Synchronizes the UI with the given property. ATTN: Brian Sun * /* w ww . j a v a 2 s . c om*/ * @param propertyName * the name of the property, or <code>null</code> meaning all * applicable properties */ public void update(String propertyName) { if (widget != null) { // determine what to do boolean textChanged = propertyName == null || propertyName.equals(IAction.TEXT); boolean imageChanged = propertyName == null || propertyName.equals(IAction.IMAGE); boolean tooltipTextChanged = propertyName == null || propertyName.equals(IAction.TOOL_TIP_TEXT); boolean enableStateChanged = propertyName == null || propertyName.equals(IAction.ENABLED) || propertyName.equals(IContributionManagerOverrides.P_ENABLED); boolean checkChanged = (action.getStyle() == IAction.AS_CHECK_BOX || action.getStyle() == IAction.AS_RADIO_BUTTON) && (propertyName == null || propertyName.equals(IAction.CHECKED)); boolean colorChanged = propertyName == null || propertyName.equals(IColorAction.COLOR); if (widget instanceof ToolItem) { //int toolbarStyle = SWT.NONE; ToolItem ti = (ToolItem) widget; String text = action.getText(); // the set text is shown only if there is no image or if forced by MODE_FORCE_TEXT boolean showText = text != null && ((getMode() & MODE_FORCE_TEXT) != 0 || !hasImages(action)); // && ((toolbarStyle & BFaceConstants.TOOLBAR_TEXT)!=0 || // ((toolbarStyle & BFaceConstants.TOOLBAR_TEXT_RIGHT)!=0 && hasRightText)); // only do the trimming if the text will be used if (showText && text != null) { text = Action.removeAcceleratorText(text); text = Action.removeMnemonics(text); } if (textChanged) { String textToSet = showText ? text : ""; //$NON-NLS-1$ boolean rightStyle = (ti.getParent().getStyle() & SWT.RIGHT) != 0; if (rightStyle || !ti.getText().equals(textToSet)) { // In addition to being required to update the text if it // gets nulled out in the action, this is also a workaround // for bug 50151: Using SWT.RIGHT on a ToolBar leaves blank space ti.setText(textToSet); } } if (imageChanged) { // only substitute a missing image if it has no text updateImages(!showText); } if (tooltipTextChanged || textChanged) { String toolTip = action.getToolTipText(); if ((toolTip == null) || (toolTip.length() == 0)) { toolTip = text; } // if the text is showing, then only set the tooltip if // different if (!showText || toolTip != null) { // && !toolTip.equals(text)) { ti.setToolTipText(toolTip); } else { ti.setToolTipText(null); } } if (enableStateChanged) { boolean shouldBeEnabled = action.isEnabled(); // && isEnabledAllowed(); if (ti.getEnabled() != shouldBeEnabled) { ti.setEnabled(shouldBeEnabled); } } if (checkChanged) { boolean bv = action.isChecked(); if (ti.getSelection() != bv) { ti.setSelection(bv); } } if (colorChanged) { updateColors(); } return; } if (widget instanceof MenuItem) { MenuItem mi = (MenuItem) widget; if (textChanged) { int accelerator = 0; String acceleratorText = null; IAction updatedAction = getAction(); String text = null; accelerator = updatedAction.getAccelerator(); ExternalActionManager.ICallback callback = ExternalActionManager.getInstance().getCallback(); // Block accelerators that are already in use. if ((accelerator != 0) && (callback != null) && (callback.isAcceleratorInUse(accelerator))) { accelerator = 0; } /* * Process accelerators on GTK in a special way to avoid Bug * 42009. We will override the native input method by * allowing these reserved accelerators to be placed on the * menu. We will only do this for "Ctrl+Shift+[0-9A-FU]". */ final String commandId = updatedAction.getActionDefinitionId(); if (("gtk".equals(SWT.getPlatform())) && (callback instanceof IBindingManagerCallback) //$NON-NLS-1$ && (commandId != null)) { final IBindingManagerCallback bindingManagerCallback = (IBindingManagerCallback) callback; final IKeyLookup lookup = KeyLookupFactory.getDefault(); final TriggerSequence[] triggerSequences = bindingManagerCallback .getActiveBindingsFor(commandId); for (int i = 0; i < triggerSequences.length; i++) { final TriggerSequence triggerSequence = triggerSequences[i]; final Trigger[] triggers = triggerSequence.getTriggers(); if (triggers.length == 1) { final Trigger trigger = triggers[0]; if (trigger instanceof KeyStroke) { final KeyStroke currentKeyStroke = (KeyStroke) trigger; final int currentNaturalKey = currentKeyStroke.getNaturalKey(); if ((currentKeyStroke .getModifierKeys() == (lookup.getCtrl() | lookup.getShift())) && ((currentNaturalKey >= '0' && currentNaturalKey <= '9') || (currentNaturalKey >= 'A' && currentNaturalKey <= 'F') || (currentNaturalKey == 'U'))) { accelerator = currentKeyStroke.getModifierKeys() | currentNaturalKey; acceleratorText = triggerSequence.format(); break; } } } } } if (accelerator == 0) { if ((callback != null) && (commandId != null)) { acceleratorText = callback.getAcceleratorText(commandId); } } else { acceleratorText = Action.convertAccelerator(accelerator); } IContributionManagerOverrides overrides = null; if (getParent() != null) { overrides = getParent().getOverrides(); } if (overrides != null) { text = getParent().getOverrides().getText(this); } mi.setAccelerator(accelerator); if (text == null) { text = updatedAction.getText(); } if (text == null) { text = ""; //$NON-NLS-1$ } else { text = Action.removeAcceleratorText(text); } if (acceleratorText == null) { mi.setText(text); } else { mi.setText(text + '\t' + acceleratorText); } } if (imageChanged) { updateImages(false); } if (enableStateChanged) { boolean shouldBeEnabled = action.isEnabled(); // && isEnabledAllowed(); if (mi.getEnabled() != shouldBeEnabled) { mi.setEnabled(shouldBeEnabled); } } if (checkChanged) { boolean bv = action.isChecked(); if (mi.getSelection() != bv) { mi.setSelection(bv); } } if (colorChanged) { updateColors(); } return; } if (widget instanceof Button) { Button button = (Button) widget; if (imageChanged && updateImages(false)) { textChanged = false; // don't update text if it has an image } if (textChanged) { String text = action.getText(); if (text == null) { text = ""; //$NON-NLS-1$ } else { text = Action.removeAcceleratorText(text); } button.setText(text); } if (tooltipTextChanged) { button.setToolTipText(action.getToolTipText()); } if (enableStateChanged) { boolean shouldBeEnabled = action.isEnabled(); // && isEnabledAllowed(); if (button.getEnabled() != shouldBeEnabled) { button.setEnabled(shouldBeEnabled); } } if (checkChanged) { boolean bv = action.isChecked(); if (button.getSelection() != bv) { button.setSelection(bv); } } if (colorChanged) { updateColors(); } return; } } }