Search in sources :

Example 31 with IWorkbenchPartSite

use of org.eclipse.ui.IWorkbenchPartSite in project statecharts by Yakindu.

the class RenameElementHandler method isEnabled.

@Override
public boolean isEnabled() {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return false;
    }
    IWorkbenchPartSite site = window.getActivePage().getActiveEditor().getSite();
    if (site == null) {
        return false;
    }
    ISelectionProvider selectionProvider = site.getSelectionProvider();
    if (selectionProvider == null) {
        return false;
    }
    ISelection currentSelection = selectionProvider.getSelection();
    setContext(refactoring, currentSelection);
    return refactoring.isExecutable();
}
Also used : IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ISelection(org.eclipse.jface.viewers.ISelection)

Example 32 with IWorkbenchPartSite

use of org.eclipse.ui.IWorkbenchPartSite in project dsl-devkit by dsldevkit.

the class FixedHighlightingReconciler method getDisplay.

private Display getDisplay() {
    XtextEditor editor = this.editor;
    if (editor == null) {
        return null;
    }
    IWorkbenchPartSite site = editor.getSite();
    if (site == null) {
        return null;
    }
    Shell shell = site.getShell();
    if (shell == null || shell.isDisposed()) {
        return null;
    }
    Display display = shell.getDisplay();
    if (display == null || display.isDisposed()) {
        return null;
    }
    return display;
}
Also used : IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) Shell(org.eclipse.swt.widgets.Shell) XtextEditor(org.eclipse.xtext.ui.editor.XtextEditor) Display(org.eclipse.swt.widgets.Display)

Example 33 with IWorkbenchPartSite

use of org.eclipse.ui.IWorkbenchPartSite in project pmd-eclipse-plugin by pmd.

the class CPDCheckProjectAction method run.

/*
     * @see org.eclipse.ui.IActionDelegate#run(IAction)
     */
public void run(final IAction action) {
    // NOPMD:UnusedFormalParameter
    final IWorkbenchPartSite site = targetPartSite();
    final ISelection sel = site.getSelectionProvider().getSelection();
    final Shell shell = site.getShell();
    final String[] languages = LanguageFactory.supportedLanguages;
    final String[] formats = { SIMPLE_KEY, XML_KEY, CSV_KEY };
    final CPDCheckDialog dialog = new CPDCheckDialog(shell, languages, formats);
    if (dialog.open() == Dialog.OK && sel instanceof IStructuredSelection) {
        final StructuredSelection ss = (StructuredSelection) sel;
        final Iterator<?> i = ss.iterator();
        while (i.hasNext()) {
            final Object obj = i.next();
            if (obj instanceof IAdaptable) {
                final IAdaptable adaptable = (IAdaptable) obj;
                final IProject project = (IProject) adaptable.getAdapter(IProject.class);
                if (project == null) {
                    LOG.warn("The selected object cannot adapt to a project");
                    LOG.debug("   -> selected object : " + obj);
                } else {
                    this.detectCutAndPaste(project, dialog);
                }
            } else {
                LOG.warn("The selected object is not adaptable");
                LOG.debug("   -> selected object : " + obj);
            }
        }
    }
}
Also used : IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) IAdaptable(org.eclipse.core.runtime.IAdaptable) Shell(org.eclipse.swt.widgets.Shell) CPDCheckDialog(net.sourceforge.pmd.eclipse.ui.dialogs.CPDCheckDialog) ISelection(org.eclipse.jface.viewers.ISelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IProject(org.eclipse.core.resources.IProject)

Example 34 with IWorkbenchPartSite

use of org.eclipse.ui.IWorkbenchPartSite in project dbeaver by serge-rider.

the class NavigatorHandlerFilterObjectType method updateElement.

@Override
public void updateElement(UIElement element, Map parameters) {
    DatabaseNavigatorTreeFilterObjectType objectType = CommonUtils.valueOf(DatabaseNavigatorTreeFilterObjectType.class, CommonUtils.toString(parameters.get("type")), DatabaseNavigatorTreeFilterObjectType.table);
    DatabaseNavigatorTreeFilterObjectType curObjectType = DatabaseNavigatorTreeFilterObjectType.table;
    IWorkbenchPartSite partSite = UIUtils.getWorkbenchPartSite(element.getServiceLocator());
    if (partSite != null && partSite.getPart() instanceof DatabaseNavigatorView) {
        curObjectType = ((DatabaseNavigatorView) partSite.getPart()).getNavigatorTree().getFilterObjectType();
    }
    String text, toolTip;
    switch(objectType) {
        case connection:
            text = "Filter connections";
            toolTip = "Filter connections by name";
            break;
        case container:
            text = "Filter databases or schemas";
            toolTip = "Filter containers (databases or schemas) by name";
            break;
        case table:
            text = "Filter tables, procedures";
            toolTip = "Filter objects (tables, procedures, users, etc) by name";
            break;
        default:
            return;
    }
    element.setText(text);
    element.setTooltip(toolTip);
    element.setChecked(objectType == curObjectType);
}
Also used : IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) DatabaseNavigatorView(org.jkiss.dbeaver.ui.navigator.database.DatabaseNavigatorView) DatabaseNavigatorTreeFilterObjectType(org.jkiss.dbeaver.ui.navigator.database.DatabaseNavigatorTreeFilterObjectType)

Example 35 with IWorkbenchPartSite

use of org.eclipse.ui.IWorkbenchPartSite in project dbeaver by serge-rider.

the class ItemListControl method fillCustomActions.

@Override
public void fillCustomActions(IContributionManager contributionManager) {
    super.fillCustomActions(contributionManager);
    final DBNNode rootNode = getRootNode();
    if (rootNode instanceof DBNDatabaseFolder && ((DBNDatabaseFolder) rootNode).getItemsMeta() != null) {
        contributionManager.add(new Action(UINavigatorMessages.obj_editor_properties_control_action_filter_setting, DBeaverIcons.getImageDescriptor(UIIcon.FILTER)) {

            @Override
            public void run() {
                NavigatorHandlerFilterConfig.configureFilters(getShell(), rootNode);
            }
        });
    }
    addColumnConfigAction(contributionManager);
    IWorkbenchSite workbenchSite = getWorkbenchSite();
    if (rootNode instanceof DBNDatabaseFolder) {
        contributionManager.add(new Separator());
        contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, NavigatorCommands.CMD_OBJECT_OPEN));
        {
            if (ObjectPropertyTester.canCreateObject(rootNode, true)) {
                contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, NavigatorCommands.CMD_OBJECT_CREATE));
            } else if (ObjectPropertyTester.canCreateObject(rootNode, false)) {
                contributionManager.add(new Action(null, Action.AS_DROP_DOWN_MENU) {

                    {
                        setActionDefinitionId(NavigatorCommands.CMD_OBJECT_CREATE);
                    }

                    @Override
                    public void run() {
                        super.run();
                    }

                    @Override
                    public IMenuCreator getMenuCreator() {
                        return new MenuCreator(control -> {
                            List<IContributionItem> items = NavigatorHandlerObjectCreateNew.fillCreateMenuItems((IWorkbenchPartSite) workbenchSite, rootNode);
                            MenuManager menuManager = new MenuManager();
                            for (IContributionItem cc : items) {
                                menuManager.add(cc);
                            }
                            return menuManager;
                        });
                    }
                });
            }
        }
        contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, NavigatorCommands.CMD_OBJECT_DELETE));
    }
    if (rootNode instanceof DBNDatabaseNode && rootNode.isPersisted()) {
        boolean hasReorder = false;
        List<Class<?>> childrenTypes = ((DBNDatabaseNode) rootNode).getChildrenTypes(null);
        for (Class<?> chilType : childrenTypes) {
            if (DBWorkbench.getPlatform().getEditorsRegistry().getObjectManager(chilType, DBEObjectReorderer.class) != null) {
                hasReorder = true;
                break;
            }
        }
        if (hasReorder) {
            contributionManager.add(new Separator());
            contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, NavigatorCommands.CMD_OBJECT_MOVE_UP));
            contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, NavigatorCommands.CMD_OBJECT_MOVE_DOWN));
        }
    }
    if (rootNode instanceof DBNDatabaseNode) {
        // Expand/collapse
        final List<DBXTreeNode> inlineMetas = collectInlineMetas((DBNDatabaseNode) rootNode, ((DBNDatabaseNode) rootNode).getMeta());
        if (!inlineMetas.isEmpty()) {
            contributionManager.add(new Separator());
            contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, IWorkbenchCommandConstants.NAVIGATE_COLLAPSE_ALL, null, UIIcon.TREE_COLLAPSE_ALL));
            contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, IWorkbenchCommandConstants.NAVIGATE_EXPAND_ALL, null, UIIcon.TREE_EXPAND_ALL));
        }
    }
    // Save/revert
    if (workbenchSite instanceof MultiPageEditorSite) {
        final MultiPageEditorPart editor = ((MultiPageEditorSite) workbenchSite).getMultiPageEditor();
        if (editor instanceof EntityEditor) {
            contributionManager.add(new Separator());
            DatabaseEditorUtils.contributeStandardEditorActions(workbenchSite, contributionManager);
        }
    }
}
Also used : IWorkbenchSite(org.eclipse.ui.IWorkbenchSite) MultiPageEditorPart(org.eclipse.ui.part.MultiPageEditorPart) DBWorkbench(org.jkiss.dbeaver.runtime.DBWorkbench) DatabaseLoadService(org.jkiss.dbeaver.model.runtime.load.DatabaseLoadService) ObjectPropertyTester(org.jkiss.dbeaver.ui.actions.ObjectPropertyTester) Arrays(java.util.Arrays) org.eclipse.jface.action(org.eclipse.jface.action) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) org.jkiss.dbeaver.ui(org.jkiss.dbeaver.ui) IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) IWorkbenchCommandConstants(org.eclipse.ui.IWorkbenchCommandConstants) NavigatorCommands(org.jkiss.dbeaver.ui.navigator.NavigatorCommands) PropertyEditorUtils(org.jkiss.dbeaver.ui.properties.PropertyEditorUtils) ArrayList(java.util.ArrayList) EntityEditor(org.jkiss.dbeaver.ui.editors.entity.EntityEditor) DBNUtils(org.jkiss.dbeaver.model.navigator.DBNUtils) Composite(org.eclipse.swt.widgets.Composite) NavigatorHandlerFilterConfig(org.jkiss.dbeaver.ui.navigator.actions.NavigatorHandlerFilterConfig) Log(org.jkiss.dbeaver.Log) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) ObjectPropertyDescriptor(org.jkiss.dbeaver.runtime.properties.ObjectPropertyDescriptor) Font(org.eclipse.swt.graphics.Font) DBPObjectStatisticsCollector(org.jkiss.dbeaver.model.DBPObjectStatisticsCollector) DBUtils(org.jkiss.dbeaver.model.DBUtils) IWorkbenchSite(org.eclipse.ui.IWorkbenchSite) Collection(java.util.Collection) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) DBSWrapper(org.jkiss.dbeaver.model.struct.DBSWrapper) ArrayUtils(org.jkiss.utils.ArrayUtils) org.eclipse.jface.viewers(org.eclipse.jface.viewers) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) UINavigatorMessages(org.jkiss.dbeaver.ui.internal.UINavigatorMessages) InvocationTargetException(java.lang.reflect.InvocationTargetException) MultiPageEditorSite(org.eclipse.ui.part.MultiPageEditorSite) List(java.util.List) Color(org.eclipse.swt.graphics.Color) SWT(org.eclipse.swt.SWT) DatabaseEditorUtils(org.jkiss.dbeaver.ui.editors.DatabaseEditorUtils) DBXTreeNode(org.jkiss.dbeaver.model.navigator.meta.DBXTreeNode) NavigatorHandlerObjectCreateNew(org.jkiss.dbeaver.ui.navigator.actions.NavigatorHandlerObjectCreateNew) DBEObjectReorderer(org.jkiss.dbeaver.model.edit.DBEObjectReorderer) DBNDatabaseFolder(org.jkiss.dbeaver.model.navigator.DBNDatabaseFolder) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) MultiPageEditorPart(org.eclipse.ui.part.MultiPageEditorPart) DBNDatabaseFolder(org.jkiss.dbeaver.model.navigator.DBNDatabaseFolder) IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) DBXTreeNode(org.jkiss.dbeaver.model.navigator.meta.DBXTreeNode) DBEObjectReorderer(org.jkiss.dbeaver.model.edit.DBEObjectReorderer) ArrayList(java.util.ArrayList) List(java.util.List) EntityEditor(org.jkiss.dbeaver.ui.editors.entity.EntityEditor) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) MultiPageEditorSite(org.eclipse.ui.part.MultiPageEditorSite)

Aggregations

IWorkbenchPartSite (org.eclipse.ui.IWorkbenchPartSite)73 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)13 ISelection (org.eclipse.jface.viewers.ISelection)12 IEditorPart (org.eclipse.ui.IEditorPart)12 ArrayList (java.util.ArrayList)10 MenuManager (org.eclipse.jface.action.MenuManager)9 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)9 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)9 Composite (org.eclipse.swt.widgets.Composite)9 Display (org.eclipse.swt.widgets.Display)9 Shell (org.eclipse.swt.widgets.Shell)9 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)9 Menu (org.eclipse.swt.widgets.Menu)7 IEditorSite (org.eclipse.ui.IEditorSite)7 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)7 SWT (org.eclipse.swt.SWT)6 PartInitException (org.eclipse.ui.PartInitException)6 List (java.util.List)5 IToolBarManager (org.eclipse.jface.action.IToolBarManager)4 Separator (org.eclipse.jface.action.Separator)4