Example usage for org.eclipse.jface.action Action setEnabled

List of usage examples for org.eclipse.jface.action Action setEnabled

Introduction

In this page you can find the example usage for org.eclipse.jface.action Action setEnabled.

Prototype

@Override
    public void setEnabled(boolean enabled) 

Source Link

Usage

From source file:ch.elexis.core.ui.views.ReminderView.java

License:Open Source License

private List<IContributionItem> createActionList() {
    Action labelFilter = new Action("Anzeige filtern") {
    };// ww w .  j  a  va 2 s .  co m
    labelFilter.setEnabled(false);

    Action labelResponsibility = new Action("Anzeige erweitern") {
    };
    labelResponsibility.setEnabled(false);

    Action labelSorter = new Action("Anzeige sortieren") {
    };
    labelSorter.setEnabled(false);

    MenuManager typeFilterSubMenu = new MenuManager("Nach Aktionstyp");
    List<IContributionItem> ca = ViewMenus.convertActionsToContributionItems((filterActionType));
    for (IContributionItem iContributionItem : ca) {
        typeFilterSubMenu.add(iContributionItem);
    }
    return Arrays.asList(new ActionContributionItem(newReminderAction), null,
            new ActionContributionItem(labelSorter), new ActionContributionItem(sortByDueDate), null,
            new ActionContributionItem(labelFilter),
            new ActionContributionItem(showOnlyOwnDueReminderToggleAction), typeFilterSubMenu, null,
            new ActionContributionItem(labelResponsibility),
            new ActionContributionItem(showSelfCreatedReminderAction),
            new ActionContributionItem(showOthersRemindersAction), null);
}

From source file:ch.elexis.core.ui.views.textsystem.PlatzhalterView.java

License:Open Source License

@Override
public void createPartControl(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(1, false));

    Text txtInfo = new Text(composite, SWT.MULTI | SWT.READ_ONLY | SWT.BORDER | SWT.WRAP);
    txtInfo.setText(Messages.PlatzhalterView_message_Info);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(txtInfo);

    viewer = new TreeViewer(composite);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(viewer.getTree());

    viewer.setLabelProvider(new PlatzhalterLabelProvider());
    viewer.setContentProvider(new PlatzhalterContentProvider());
    viewer.setInput(getTreeData());//w  ww .  j  av a  2  s .  c o m
    ColumnViewerToolTipSupport.enableFor(viewer, ToolTip.NO_RECREATE);

    // Popup-Menu "Kopieren"
    MenuManager popupMenuManager = new MenuManager();
    Menu menu = popupMenuManager.createContextMenu(viewer.getTree());
    viewer.getTree().setMenu(menu);

    final Action copyAction = new Action(Messages.PlatzhalterView_menu_copy) {
        @Override
        public String getId() {
            return "copyId"; //$NON-NLS-1$
        }

        @Override
        public void run() {
            copyToClipboard();
        }
    };
    popupMenuManager.add(copyAction);

    viewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            copyAction.setEnabled(getSelectedKey() != null);
        }
    });

    // CTRL+C
    viewer.getTree().addKeyListener(new KeyAdapter() {
        private final static int C = 99;

        private boolean isActive(final int stateMask, final int keyCode) {
            boolean modifiersOk = true;
            if ((stateMask & SWT.CTRL) == 0) {
                modifiersOk = false;
            }
            return modifiersOk && keyCode == C;
        }

        @Override
        public void keyPressed(KeyEvent e) {
            if (isActive(e.stateMask, e.keyCode)) {
                copyToClipboard();
            }
        }
    });

    // Doubleclick
    viewer.getTree().addMouseListener(new MouseAdapter() {
        @Override
        public void mouseDoubleClick(MouseEvent e) {
            String key = getSelectedKey();
            if (key != null) {
                for (IViewReference viewRef : getViewSite().getPage().getViewReferences()) {
                    if (TextView.ID.equals(viewRef.getId())) {
                        TextView txtView = (TextView) viewRef.getPart(false);
                        if (txtView != null) {
                            txtView.getTextContainer().getPlugin().insertText((Object) null, key, SWT.LEFT);
                        }
                    }
                }
            }
        }
    });

    // Drag & Drop
    DragSource dragSource = new DragSource(viewer.getTree(), DND.DROP_COPY);
    dragSource.setTransfer(new Transfer[] { TextTransfer.getInstance() });
    dragSource.addDragListener(new DragSourceAdapter() {
        public void dragStart(DragSourceEvent event) {
            event.doit = getSelectedKey() != null;
        }

        public void dragSetData(DragSourceEvent event) {
            if (TextTransfer.getInstance().isSupportedType(event.dataType)) {
                String key = getSelectedKey();
                if (key != null) {
                    event.data = key;
                }
            }
        }
    });
}

From source file:com.android.ide.eclipse.adt.internal.editors.layout.gle2.LayoutCanvas.java

License:Open Source License

/**
 * Helper for {@link #setupGlobalActionHandlers()}.
 * Copies the action attributes form the given {@link ActionFactory}'s action to
 * our action.//  ww  w.j a va 2 s  . co  m
 * <p/>
 * {@link ActionFactory} provides access to the standard global actions in Eclipse.
 * <p/>
 * This allows us to grab the standard labels and icons for the
 * global actions such as copy, cut, paste, delete and select-all.
 */
private void copyActionAttributes(Action action, ActionFactory factory) {
    IWorkbenchAction wa = factory.create(mEditorDelegate.getEditor().getEditorSite().getWorkbenchWindow());
    action.setId(wa.getId());
    action.setText(wa.getText());
    action.setEnabled(wa.isEnabled());
    action.setDescription(wa.getDescription());
    action.setToolTipText(wa.getToolTipText());
    action.setAccelerator(wa.getAccelerator());
    action.setActionDefinitionId(wa.getActionDefinitionId());
    action.setImageDescriptor(wa.getImageDescriptor());
    action.setHoverImageDescriptor(wa.getHoverImageDescriptor());
    action.setDisabledImageDescriptor(wa.getDisabledImageDescriptor());
    action.setHelpListener(wa.getHelpListener());
}

From source file:com.byterefinery.rmbench.export.DDLEditor.java

License:Open Source License

protected ISourceViewer createSourceViewer(Composite parent, IVerticalRuler ruler, int style) {

    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout());
    composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    toolBarMgr = new ToolBarManager(SWT.FLAT);
    ToolBar toolBar = toolBarMgr.createControl(composite);
    GridData gd = new GridData(SWT.FILL, SWT.TOP, false, false);
    gd.heightHint = 25;//  ww  w  .  j  a v a  2s  . c om
    toolBar.setLayoutData(gd);

    final Action executeScriptAction = new ExecuteScriptAction(this);
    final Action executeStmtAction = new ExecuteStatementAction(this);

    dbmodelContribution = new ChooseDBModelContribution(databaseInfo);
    dbmodelContribution.addConnectionListener(new ChooseDBModelContribution.Listener() {
        public void dbModelSelected(DBModel dbmodel) {
            executeScriptAction.setEnabled(dbmodel != null);
            executeStmtAction.setEnabled(dbmodel != null);
        }
    });
    toolBarMgr.add(dbmodelContribution);
    toolBarMgr.add(executeScriptAction);
    toolBarMgr.add(executeStmtAction);
    toolBarMgr.update(true);

    connectionListener = new ChooseDBModelContribution.EventManagerListener(toolBarMgr);
    connectionListener.register();

    sourceViewer = new SourceViewer(composite, ruler, SWT.H_SCROLL | SWT.V_SCROLL);
    sourceViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    PreferenceHandler.addPreferenceChangeListener(preferenceListener);
    return sourceViewer;
}

From source file:com.byterefinery.rmbench.export.ModelCompareEditor.java

License:Open Source License

private void createActions(CompareViewerPane lowerPane) {
    ToolBarManager toolbar = CompareViewerPane.getToolBarManager(lowerPane);

    final Action executeScriptAction = new ExecuteScriptAction(this);
    final Action executeStmtAction = new ExecuteStatementAction(this);

    dbmodelContribution = new ChooseDBModelContribution(databaseInfo);
    dbmodelContribution.addConnectionListener(new ChooseDBModelContribution.Listener() {
        public void dbModelSelected(DBModel dbmodel) {
            executeScriptAction.setEnabled(dbmodel != null);
            executeStmtAction.setEnabled(dbmodel != null);
        }//from  w w w  . j  a v a 2s.c  o m
    });
    connectionListener = new ChooseDBModelContribution.EventManagerListener(toolbar);
    connectionListener.register();

    toolbar.add(new Separator(GROUP_EXEC));
    toolbar.appendToGroup(GROUP_EXEC, dbmodelContribution);
    toolbar.appendToGroup(GROUP_EXEC, executeScriptAction);
    toolbar.appendToGroup(GROUP_EXEC, executeStmtAction);
    toolbar.add(new Separator());
    toolbar.add(new EditorModeAction());
    toolbar.update(true);
}

From source file:com.cisco.yangide.ext.model.editor.editors.YangDiagramModuleInfoPanel.java

License:Open Source License

protected void createPropertiesButtonToolbar(final Section editSection, final SashForm infoPane,
        final ScrolledForm pane) {
    ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
    ToolBar toolbar = toolBarManager.createControl(editSection);
    toolbar.setCursor(Display.getDefault().getSystemCursor(SWT.CURSOR_HAND));

    Action closeButton = new Action("Close properties section", IAction.AS_CHECK_BOX) {

        @Override// w  w w .  ja va  2  s  .  com
        public void run() {
            super.run();
            setChecked(false);
            setPropertiesPaneVisible(false);
        }
    };

    closeButton.setImageDescriptor(GraphitiUi.getImageService().getImageDescriptorForId(
            YangDiagramImageProvider.DIAGRAM_TYPE_PROVIDER_ID,
            YangDiagramImageProvider.IMG_COLLAPSE_ALL_TOOL_PROPOSAL));
    closeButton.setEnabled(true);
    toolBarManager.add(closeButton);
    toolBarManager.update(true);
    editSection.setTextClient(toolbar);
}

From source file:com.cisco.yangide.ext.model.editor.editors.YangDiagramModuleInfoPanel.java

License:Open Source License

protected void createImportButtonToolbar(Section section) {
    ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
    ToolBar toolbar = toolBarManager.createControl(section);
    toolbar.setCursor(Display.getDefault().getSystemCursor(SWT.CURSOR_HAND));

    Action addButton = new Action("Add new import", IAction.AS_CHECK_BOX) {
        @Override//from   w  w  w .j  av  a  2 s . co m
        public void run() {
            super.run();
            Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
            AddImportDialog dialog = new AddImportDialog(shell, module, file);
            if (0 <= dialog.open()) {
                YangModelUtil.add(module, dialog.getResultImport(), module.getChildren().size());
                updateImportTable();
            }
            setChecked(false);
        }
    };

    addButton.setImageDescriptor(GraphitiUi.getImageService().getImageDescriptorForId(
            YangDiagramImageProvider.DIAGRAM_TYPE_PROVIDER_ID, YangDiagramImageProvider.IMG_ADD_TOOL_PROPOSAL));
    addButton.setEnabled(true);
    toolBarManager.add(addButton);

    Action deleteButton = new Action("Delete selected import", IAction.AS_CHECK_BOX) {

        @SuppressWarnings("unchecked")
        @Override
        public void run() {
            super.run();
            if (importTable.getSelection() instanceof IStructuredSelection) {
                Iterator<Object> iter = ((IStructuredSelection) importTable.getSelection()).iterator();
                while (iter.hasNext()) {
                    module.getChildren().remove(iter.next());
                }
                updateImportTable();
                setChecked(false);
            }
        }
    };

    deleteButton.setImageDescriptor(GraphitiUi.getImageService().getImageDescriptorForId(
            YangDiagramImageProvider.DIAGRAM_TYPE_PROVIDER_ID,
            YangDiagramImageProvider.IMG_DELETE_TOOL_PROPOSAL));
    deleteButton.setEnabled(true);
    toolBarManager.add(deleteButton);
    toolBarManager.update(true);
    section.setTextClient(toolbar);
}

From source file:com.generalrobotix.ui.GrxPluginManager.java

License:Open Source License

/**
 * @brief// w w  w  .  java  2s .  c  om
 * @param cls
 * @return
 */
public Vector<Action> getItemMenu(final Class<? extends GrxBaseItem> cls) {
    final PluginInfo pi = pinfoMap_.get(cls);
    Vector<Action> menu = pi.menu;
    if (menu != null) {
        dynamicChangeMenu(cls, menu);
        return menu;
    }
    menu = pi.menu = new Vector<Action>();

    // menu item : create
    Action create = new Action() {
        public String getText() {
            return MessageBundle.get("GrxPluginManager.menu.create"); //$NON-NLS-1$
        }

        public void run() {
            GrxBaseItem item = createItem(cls, null);
            itemChange(item, GrxPluginManager.ADD_ITEM);
            setSelectedItem(item, true);
        }
    };
    menu.add(create);

    // menu item : load
    Action load = new Action() {
        public String getText() {
            return MessageBundle.get("GrxPluginManager.menu.load"); //$NON-NLS-1$
        }

        public void run() {
            FileDialog fdlg = new FileDialog(GrxUIPerspectiveFactory.getCurrentShell(), SWT.OPEN);
            String[] fe = { pi.filter };
            fdlg.setFilterExtensions(fe);
            fdlg.setFilterPath(pi.lastDir.getAbsolutePath());
            String fPath = fdlg.open();
            if (fPath != null) {
                File f = new File(fPath);
                GrxBaseItem newItem = loadItem(cls, null, f.getAbsolutePath());
                if (newItem != null) {
                    itemChange(newItem, GrxPluginManager.ADD_ITEM);
                    setSelectedItem(newItem, true);
                    pi.lastDir = f.getParentFile();
                }
            }
        }
    };
    menu.add(load);

    // menu item : clear
    Action clear = new Action() {
        public String getText() {
            return MessageBundle.get("GrxPluginManager.menu.clear"); //$NON-NLS-1$
        }

        public void run() {
            String mes = MessageBundle.get("GrxPluginManager.dialog.message.removeItem"); //$NON-NLS-1$
            mes = NLS.bind(mes, new String[] { GrxPluginManager.this.getItemTitle(cls) });
            if (MessageDialog.openConfirm(null, MessageBundle.get("GrxPluginManager.dialog.title.removeItem"), //$NON-NLS-1$
                    mes)) {
                refuseItemChange();
                removeItems(cls);
                acceptItemChange();
            }
        }
    };
    menu.add(clear);

    // menu item : delete
    Action delete = new Action() {
        public String getText() {
            return MessageBundle.get("GrxPluginManager.menu.delete"); //$NON-NLS-1$
        }

        public void run() {
            String mes = MessageBundle.get("GrxPluginManager.dialog.message.deletePlugin"); //$NON-NLS-1$
            mes = NLS.bind(mes, new String[] { GrxPluginManager.this.getItemTitle(cls) });
            if (MessageDialog.openConfirm(null, MessageBundle.get("GrxPluginManager.dialog.title.deletePlugin"), //$NON-NLS-1$
                    mes))
                deletePlugin(cls);
        }
    };
    menu.add(delete);

    try {
        Method m = cls.getMethod("create", (Class[]) null); //$NON-NLS-1$
        Class<?> c = m.getDeclaringClass();
        create.setEnabled(!(c == GrxBaseItem.class));

        m = cls.getMethod("load", File.class); //$NON-NLS-1$
        c = m.getDeclaringClass();
        load.setEnabled(!(c == GrxBaseItem.class));
        m = cls.getMethod("paste", String.class); //$NON-NLS-1$
        c = m.getDeclaringClass();
        if (c != GrxBaseItem.class) {
            Action paste = new Action() {
                public String getText() {
                    return "paste"; //$NON-NLS-1$
                }

                public void run() {
                    GrxDebugUtil.println("GrxPluginManager.GrxModelItemClass paste Action"); //$NON-NLS-1$
                    // paste();
                }
            };
            paste.setEnabled(!isEmptyClipBord());
            menu.add(paste);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    // if plugin is user then delete menu is enable
    IPreferenceStore store = Activator.getDefault().getPreferenceStore();
    String itemClassList = store.getString(PreferenceConstants.ITEM + "." + PreferenceConstants.CLASS);
    String[] itemClass = itemClassList.split(PreferenceConstants.SEPARATOR, -1);
    boolean found = false;
    for (int i = 0; i < itemClass.length; i++) {
        if (cls.getName().equals(itemClass[i])) {
            found = true;
            break;
        }
    }
    if (!found)
        delete.setEnabled(true);
    else
        delete.setEnabled(false);
    return menu;
}

From source file:com.generalrobotix.ui.GrxPluginManager.java

License:Open Source License

/**
 * @brief//from   www  . j  a v  a2s  .c o  m
 */
private void dynamicChangeMenu(final Class<? extends GrxBaseItem> cls, Vector<Action> menu) {
    try {
        Method m = cls.getMethod("paste", String.class); //$NON-NLS-1$
        Class<?> c = m.getDeclaringClass();
        if (c != GrxBaseItem.class) {
            for (Action action : menu) {
                if (action.getText().equals("paste")) { //$NON-NLS-1$
                    action.setEnabled(!isEmptyClipBord());
                    break;
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.gorillalogic.monkeyconsole.actions.DropDownMenuAction.java

License:Open Source License

@Override
public void setEnabled(boolean enabled) {
    for (Action a : actions) {
        a.setEnabled(enabled);
    }// w  w w  . j  a v  a2s .  co  m
    if (selectedAction != null)
        selectedAction.setEnabled(enabled);
    super.setEnabled(enabled);
}