Search in sources :

Example 36 with IWorkbenchPartSite

use of org.eclipse.ui.IWorkbenchPartSite in project cubrid-manager by CUBRID.

the class CubridNavigatorView method createPartControl.

/**
	 * Create the part control
	 *
	 * @param parent Composite
	 */
public void createPartControl(Composite parent) {
    ViewForm viewForm = new ViewForm(parent, SWT.NONE);
    viewForm.setLayout(new GridLayout());
    tv = new TreeViewer(viewForm, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
    tv.setFilters(NodeFilterManager.getInstance().getViewerFilter());
    //create the navigator
    createNavigator();
    //get the isShowGroup configuration
    isShowGroup = savedIsShowGroup();
    //set the tree view's input.
    setTreeInput();
    toolTip = new ToolTip(tv.getTree().getShell(), SWT.BALLOON);
    toolTip.setAutoHide(true);
    //Create the context menu
    MenuManager contextMenuManager = new MenuManager("#PopupMenu", "navigatorContextMenu");
    contextMenuManager.setRemoveAllWhenShown(true);
    contextMenuManager.addMenuListener(new IMenuListener() {

        public void menuAboutToShow(IMenuManager manager) {
            buildPopupMenu(manager);
        }
    });
    Menu contextMenu = contextMenuManager.createContextMenu(tv.getControl());
    tv.getControl().setMenu(contextMenu);
    // register the context menu for providing extension by extension point
    IWorkbenchPartSite site = getSite();
    site.registerContextMenu(contextMenuManager, tv);
    site.setSelectionProvider(tv);
    //add the select the object text composite to top left of toolbar
    ToolBar toolBar = new ToolBar(viewForm, SWT.FLAT);
    ToolBarManager toolBarManager = new ToolBarManager(toolBar);
    SelectTreeObjContrItem textContrItem = new SelectTreeObjContrItem(tv);
    toolBarManager.add(textContrItem);
    toolBarManager.update(true);
    viewForm.setContent(tv.getControl());
    viewForm.setTopLeft(toolBar);
    //add the other actions to the top right of toolbar
    toolBar = new ToolBar(viewForm, SWT.FLAT | SWT.CENTER);
    toolBarManager = new ToolBarManager(toolBar);
    buildToolBar(toolBarManager);
    toolBarManager.update(true);
    viewForm.setTopRight(toolBar);
    //Add the actions to view menu bar, you can add them by extension point or code define
    IActionBars actionBar = getViewSite().getActionBars();
    final IMenuManager menuManager = actionBar.getMenuManager();
    menuManager.addMenuListener(new IMenuListener2() {

        //reserve these actions by code define,these codes rebuild every time.
        //hence when hide, remove them not including these actions by extension point
        private IMenuManager lastMenuManager = new MenuManager();

        public void menuAboutToShow(IMenuManager manager) {
            lastMenuManager.removeAll();
            //build the code defined actions
            buildViewMenu(lastMenuManager);
            for (IContributionItem item : lastMenuManager.getItems()) {
                manager.add(item);
            }
        }

        public void menuAboutToHide(IMenuManager manager) {
            for (IContributionItem item : lastMenuManager.getItems()) {
                manager.remove(item);
            }
        }
    });
    menuManager.add(new Separator());
    activeContext();
    addListener();
    setFocus();
}
Also used : ToolTip(org.eclipse.swt.widgets.ToolTip) TreeViewer(org.eclipse.jface.viewers.TreeViewer) IContributionItem(org.eclipse.jface.action.IContributionItem) IMenuListener(org.eclipse.jface.action.IMenuListener) IToolBarManager(org.eclipse.jface.action.IToolBarManager) ToolBarManager(org.eclipse.jface.action.ToolBarManager) IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) ViewForm(org.eclipse.swt.custom.ViewForm) GridLayout(org.eclipse.swt.layout.GridLayout) IMenuListener2(org.eclipse.jface.action.IMenuListener2) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) ToolBar(org.eclipse.swt.widgets.ToolBar) IMenuManager(org.eclipse.jface.action.IMenuManager) Menu(org.eclipse.swt.widgets.Menu) IActionBars(org.eclipse.ui.IActionBars) Separator(org.eclipse.jface.action.Separator)

Example 37 with IWorkbenchPartSite

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

the class ResultSetModeToggleModeHandler method updateElement.

@Override
public void updateElement(UIElement element, Map parameters) {
    if (element.getServiceLocator() instanceof IWorkbenchPartSite) {
        IWorkbenchPartSite partSite = (IWorkbenchPartSite) element.getServiceLocator();
        if (partSite.getPart() instanceof IResultSetContainer) {
            IResultSetController rsv = ((IResultSetContainer) partSite.getPart()).getResultSetController();
            if (rsv != null) {
                if (!rsv.isRecordMode()) {
                    element.setText("Switch to record mode");
                    element.setChecked(true);
                } else {
                    element.setText("Switch to grid mode");
                    element.setChecked(false);
                }
            }
        }
    }
}
Also used : IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite)

Example 38 with IWorkbenchPartSite

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

the class CompileHandler method updateElement.

@Override
public void updateElement(UIElement element, Map parameters) {
    List<OracleSourceObject> objects = new ArrayList<>();
    IWorkbenchPartSite partSite = UIUtils.getWorkbenchPartSite(element.getServiceLocator());
    if (partSite != null) {
        final ISelectionProvider selectionProvider = partSite.getSelectionProvider();
        if (selectionProvider != null) {
            ISelection selection = selectionProvider.getSelection();
            if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
                for (Iterator<?> iter = ((IStructuredSelection) selection).iterator(); iter.hasNext(); ) {
                    final Object item = iter.next();
                    final OracleSourceObject sourceObject = RuntimeUtils.getObjectAdapter(item, OracleSourceObject.class);
                    if (sourceObject != null) {
                        objects.add(sourceObject);
                    }
                }
            }
        }
        if (objects.isEmpty()) {
            final IWorkbenchPart activePart = partSite.getPart();
            final OracleSourceObject sourceObject = RuntimeUtils.getObjectAdapter(activePart, OracleSourceObject.class);
            if (sourceObject != null) {
                objects.add(sourceObject);
            }
        }
    }
    if (!objects.isEmpty()) {
        if (objects.size() > 1) {
            element.setText("Compile " + objects.size() + " objects");
        } else {
            final OracleSourceObject sourceObject = objects.get(0);
            String objectType = TextUtils.formatWord(sourceObject.getSourceType().name());
            element.setText("Compile " + objectType);
        }
    }
}
Also used : IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ArrayList(java.util.ArrayList) ISelection(org.eclipse.jface.viewers.ISelection) OracleSourceObject(org.jkiss.dbeaver.ext.oracle.model.source.OracleSourceObject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) OracleSourceObject(org.jkiss.dbeaver.ext.oracle.model.source.OracleSourceObject)

Example 39 with IWorkbenchPartSite

use of org.eclipse.ui.IWorkbenchPartSite in project dbeaver by dbeaver.

the class PgSqlLocalLaunchShortcut method createConfiguration.

@Override
protected ILaunchConfiguration createConfiguration(DBSObject launchable) throws CoreException {
    ILaunchConfigurationWorkingCopy workingCopy = PostgreSqlDebugCore.createConfiguration(launchable);
    workingCopy.setAttribute(DebugCore.ATTR_ATTACH_KIND, DBGController.ATTACH_KIND_LOCAL);
    IWorkbenchPartSite site = getWorkbenchPartSite();
    String script = workingCopy.getAttribute(DebugCore.ATTR_SCRIPT_TEXT, DebugCore.ATTR_SCRIPT_TEXT_DEFAULT);
    String inputName = "Script";
    DatabaseScriptDialog dialog = new DatabaseScriptDialog(getShell(), site, inputName, script, launchable);
    dialog.create();
    dialog.setTitle("Specify script to be executed");
    dialog.setMessage("Specify script to be executed to start debug.");
    int open = dialog.open();
    if (IDialogConstants.CANCEL_ID == open) {
        return null;
    }
    String modified = dialog.getScriptTextValue();
    workingCopy.setAttribute(DebugCore.ATTR_SCRIPT_TEXT, modified);
    return workingCopy.doSave();
}
Also used : IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) DatabaseScriptDialog(org.jkiss.dbeaver.debug.ui.DatabaseScriptDialog)

Example 40 with IWorkbenchPartSite

use of org.eclipse.ui.IWorkbenchPartSite in project eclipse.platform.text by eclipse.

the class AbstractTextEditor method findContributedAction.

/**
 * Returns the action with the given action id that has been contributed via XML to this editor.
 * The lookup honors the dependencies of plug-ins.
 *
 * @param actionID the action id to look up
 * @return the action that has been contributed
 * @since 2.0
 */
private IAction findContributedAction(String actionID) {
    List<IConfigurationElement> actions = new ArrayList<>();
    // $NON-NLS-1$
    IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor(PlatformUI.PLUGIN_ID, "editorActions");
    for (int i = 0; i < elements.length; i++) {
        IConfigurationElement element = elements[i];
        if (TAG_CONTRIBUTION_TYPE.equals(element.getName())) {
            IWorkbenchPartSite site = getSite();
            if (site == null) {
                return null;
            }
            if (// $NON-NLS-1$
            !site.getId().equals(element.getAttribute("targetID")))
                continue;
            // $NON-NLS-1$
            IConfigurationElement[] children = element.getChildren("action");
            for (int j = 0; j < children.length; j++) {
                IConfigurationElement child = children[j];
                if (// $NON-NLS-1$
                actionID.equals(child.getAttribute("actionID")))
                    actions.add(child);
            }
        }
    }
    int actionSize = actions.size();
    if (actionSize > 0) {
        IConfigurationElement element;
        if (actionSize > 1) {
            IConfigurationElement[] actionArray = actions.toArray(new IConfigurationElement[actionSize]);
            ConfigurationElementSorter sorter = new ConfigurationElementSorter() {

                @Override
                public IConfigurationElement getConfigurationElement(Object object) {
                    return (IConfigurationElement) object;
                }
            };
            sorter.sort(actionArray);
            element = actionArray[0];
        } else
            element = actions.get(0);
        try {
            return new ContributedAction(getSite(), element);
        } catch (CommandNotMappedException e) {
        // out of luck, no command action mapping
        }
    }
    return null;
}
Also used : IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) CommandNotMappedException(org.eclipse.ui.actions.CommandNotMappedException) ContributedAction(org.eclipse.ui.actions.ContributedAction) ArrayList(java.util.ArrayList) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) Point(org.eclipse.swt.graphics.Point)

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