Search in sources :

Example 1 with ViewDescriptor

use of org.eclipse.ui.internal.registry.ViewDescriptor in project eclipse.platform.ui by eclipse-platform.

the class CompatibilityView method createPartControl.

@Override
protected boolean createPartControl(IWorkbenchPart legacyPart, Composite parent) {
    clearMenuItems();
    part.getContext().set(IViewPart.class, (IViewPart) legacyPart);
    final IEclipseContext partContext = getModel().getContext();
    IRendererFactory rendererFactory = partContext.get(IRendererFactory.class);
    // Some views (i.e. Console) require that the actual ToolBar be
    // instantiated before they are
    final IActionBars actionBars = ((IViewPart) legacyPart).getViewSite().getActionBars();
    ToolBarManager tbm = (ToolBarManager) actionBars.getToolBarManager();
    Composite toolBarParent = new Composite(parent, SWT.NONE);
    tbm.createControl(toolBarParent);
    MenuManager mm = (MenuManager) actionBars.getMenuManager();
    MMenu menu = getViewMenu();
    if (menu == null) {
        menu = modelService.createModelElement(MMenu.class);
        // If the id contains a ':' use the part before it as the descriptor
        // id
        String partId = part.getElementId();
        int colonIndex = partId.indexOf(':');
        String descId = colonIndex == -1 ? partId : partId.substring(0, colonIndex);
        menu.setElementId(descId);
        menu.getTags().add(StackRenderer.TAG_VIEW_MENU);
        menu.getTags().add(ContributionsAnalyzer.MC_MENU);
        part.getMenus().add(menu);
    }
    AbstractPartRenderer apr = rendererFactory.getRenderer(menu, parent);
    if (apr instanceof MenuManagerRenderer) {
        MenuManagerRenderer renderer = (MenuManagerRenderer) apr;
        renderer.linkModelToManager(menu, mm);
    }
    // Construct the toolbar (if necessary)
    MToolBar toolbar = part.getToolbar();
    if (toolbar == null) {
        toolbar = modelService.createModelElement(MToolBar.class);
        // If the id contains a ':' use the part before it as the descriptor
        // id
        String partId = part.getElementId();
        int colonIndex = partId.indexOf(':');
        String descId = colonIndex == -1 ? partId : partId.substring(0, colonIndex);
        toolbar.setElementId(descId);
        part.setToolbar(toolbar);
    } else {
        // clear out the model entries so they can be re-created by
        // contributions
        // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=402561
        toolbar.getChildren().clear();
    }
    apr = rendererFactory.getRenderer(toolbar, parent);
    if (apr instanceof ToolBarManagerRenderer) {
        ((ToolBarManagerRenderer) apr).linkModelToManager(toolbar, tbm);
    }
    super.createPartControl(legacyPart, parent);
    ViewDescriptor desc = reference.getDescriptor();
    if (desc != null && desc.getPluginId() != null) {
        parent.setData(new ContributionInfo(desc.getPluginId(), ContributionInfoMessages.ContributionInfo_View, null));
    }
    // dispose the tb, it will be re-created when the tab is shown
    toolBarParent.dispose();
    apr = rendererFactory.getRenderer(menu, parent);
    if (apr instanceof MenuManagerRenderer) {
        MenuManagerRenderer renderer = (MenuManagerRenderer) apr;
        // create opaque items for any contribution items that were added
        // directly to the manager
        renderer.reconcileManagerToModel(mm, menu);
    }
    apr = rendererFactory.getRenderer(toolbar, parent);
    if (apr instanceof ToolBarManagerRenderer) {
        // create opaque items for any contribution items that were added
        // directly to the manager
        ((ToolBarManagerRenderer) apr).reconcileManagerToModel(tbm, toolbar);
    }
    final AtomicBoolean toolbarContributed = new AtomicBoolean();
    final IContextFunction func = new ContextFunction() {

        @Override
        public Object compute(IEclipseContext context, String contextKey) {
            if (toolbarContributed.getAndSet(true)) {
                // fix for bug 448873: don't contribute to the toolbar twice
                return null;
            }
            final ViewActionBuilder actionBuilder = new ViewActionBuilder();
            actionBuilder.readActionExtensions(getView());
            ActionDescriptor[] actionDescriptors = actionBuilder.getExtendedActions();
            if (actionDescriptors != null) {
                IHandlerService hs = partContext.get(IHandlerService.class);
                for (ActionDescriptor actionDescriptor : actionDescriptors) {
                    if (actionDescriptor != null) {
                        IAction action = actionDescriptor.getAction();
                        if (action != null && action.getActionDefinitionId() != null) {
                            hs.activateHandler(action.getActionDefinitionId(), new ActionHandler(action));
                        }
                    }
                }
            }
            actionBars.updateActionBars();
            Runnable dispose = actionBuilder::dispose;
            return dispose;
        }
    };
    if (toolbar.getWidget() == null) {
        toolbar.getTransientData().put(ToolBarManagerRenderer.POST_PROCESSING_FUNCTION, func);
    } else {
        toolbar.getTransientData().put(ToolBarManagerRenderer.POST_PROCESSING_DISPOSE, func.compute(partContext, null));
    }
    return true;
}
Also used : ActionDescriptor(org.eclipse.ui.internal.ActionDescriptor) ToolBarManager(org.eclipse.jface.action.ToolBarManager) ViewDescriptor(org.eclipse.ui.internal.registry.ViewDescriptor) IContextFunction(org.eclipse.e4.core.contexts.IContextFunction) IRendererFactory(org.eclipse.e4.ui.workbench.swt.factories.IRendererFactory) IActionBars(org.eclipse.ui.IActionBars) Composite(org.eclipse.swt.widgets.Composite) ContributionInfo(org.eclipse.ui.testing.ContributionInfo) IAction(org.eclipse.jface.action.IAction) MMenu(org.eclipse.e4.ui.model.application.ui.menu.MMenu) MToolBar(org.eclipse.e4.ui.model.application.ui.menu.MToolBar) ViewActionBuilder(org.eclipse.ui.internal.ViewActionBuilder) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ContextFunction(org.eclipse.e4.core.contexts.ContextFunction) IContextFunction(org.eclipse.e4.core.contexts.IContextFunction) AbstractPartRenderer(org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer) ToolBarManagerRenderer(org.eclipse.e4.ui.workbench.renderers.swt.ToolBarManagerRenderer) IHandlerService(org.eclipse.ui.handlers.IHandlerService) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) MenuManager(org.eclipse.jface.action.MenuManager) MenuManagerRenderer(org.eclipse.e4.ui.workbench.renderers.swt.MenuManagerRenderer) ActionHandler(org.eclipse.jface.commands.ActionHandler)

Example 2 with ViewDescriptor

use of org.eclipse.ui.internal.registry.ViewDescriptor in project eclipse.platform.ui by eclipse-platform.

the class PluginContributionAdapterFactory method getAdapter.

@Override
public <T> T getAdapter(Object adaptableObject, Class<T> adapterType) {
    if (adapterType != ContributionInfo.class) {
        return null;
    }
    if (adaptableObject instanceof IPluginContribution) {
        IPluginContribution contribution = (IPluginContribution) adaptableObject;
        String elementType;
        if (contribution instanceof EditorDescriptor) {
            elementType = ContributionInfoMessages.ContributionInfo_Editor;
        } else if (contribution instanceof ViewDescriptor) {
            elementType = ContributionInfoMessages.ContributionInfo_View;
        } else if (contribution instanceof ActionSetDescriptor) {
            elementType = ContributionInfoMessages.ContributionInfo_ActionSet;
        } else if (contribution instanceof Category) {
            elementType = ContributionInfoMessages.ContributionInfo_Category;
        } else if (contribution instanceof IViewCategory) {
            elementType = ContributionInfoMessages.ContributionInfo_Category;
        } else if (contribution instanceof ThemeElementCategory) {
            elementType = ContributionInfoMessages.ContributionInfo_Category;
        } else if (contribution instanceof WizardCollectionElement) {
            elementType = ContributionInfoMessages.ContributionInfo_Category;
        } else if (contribution instanceof ColorDefinition) {
            elementType = ContributionInfoMessages.ContributionInfo_ColorDefinition;
        } else if (contribution instanceof WorkbenchWizardElement) {
            elementType = ContributionInfoMessages.ContributionInfo_Wizard;
        } else if (contribution instanceof PerspectiveDescriptor) {
            elementType = ContributionInfoMessages.ContributionInfo_Perspective;
        } else if (contribution instanceof WorkbenchPreferenceExpressionNode) {
            elementType = ContributionInfoMessages.ContributionInfo_Page;
        } else if (contribution instanceof DecoratorDefinition) {
            elementType = ContributionInfoMessages.ContributionInfo_LabelDecoration;
        } else {
            elementType = ContributionInfoMessages.ContributionInfo_Unknown;
        }
        return adapterType.cast(new ContributionInfo(contribution.getPluginId(), elementType, null));
    }
    if (adaptableObject instanceof JobInfo) {
        JobInfo jobInfo = (JobInfo) adaptableObject;
        Job job = jobInfo.getJob();
        if (job != null) {
            Bundle bundle = FrameworkUtil.getBundle(job.getClass());
            if (bundle != null) {
                return adapterType.cast(new ContributionInfo(bundle.getSymbolicName(), ContributionInfoMessages.ContributionInfo_Job, null));
            }
        }
    }
    return null;
}
Also used : ColorDefinition(org.eclipse.ui.internal.themes.ColorDefinition) IViewCategory(org.eclipse.ui.views.IViewCategory) Category(org.eclipse.ui.internal.registry.Category) ThemeElementCategory(org.eclipse.ui.internal.themes.ThemeElementCategory) ThemeElementCategory(org.eclipse.ui.internal.themes.ThemeElementCategory) WorkbenchPreferenceExpressionNode(org.eclipse.ui.internal.preferences.WorkbenchPreferenceExpressionNode) ContributionInfo(org.eclipse.ui.testing.ContributionInfo) Bundle(org.osgi.framework.Bundle) ActionSetDescriptor(org.eclipse.ui.internal.registry.ActionSetDescriptor) EditorDescriptor(org.eclipse.ui.internal.registry.EditorDescriptor) ViewDescriptor(org.eclipse.ui.internal.registry.ViewDescriptor) IViewCategory(org.eclipse.ui.views.IViewCategory) JobInfo(org.eclipse.ui.internal.progress.JobInfo) IPluginContribution(org.eclipse.ui.IPluginContribution) WizardCollectionElement(org.eclipse.ui.internal.dialogs.WizardCollectionElement) WorkbenchWizardElement(org.eclipse.ui.internal.dialogs.WorkbenchWizardElement) DecoratorDefinition(org.eclipse.ui.internal.decorators.DecoratorDefinition) Job(org.eclipse.core.runtime.jobs.Job) PerspectiveDescriptor(org.eclipse.ui.internal.registry.PerspectiveDescriptor)

Aggregations

ViewDescriptor (org.eclipse.ui.internal.registry.ViewDescriptor)2 ContributionInfo (org.eclipse.ui.testing.ContributionInfo)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Job (org.eclipse.core.runtime.jobs.Job)1 ContextFunction (org.eclipse.e4.core.contexts.ContextFunction)1 IContextFunction (org.eclipse.e4.core.contexts.IContextFunction)1 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)1 AbstractPartRenderer (org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer)1 MMenu (org.eclipse.e4.ui.model.application.ui.menu.MMenu)1 MToolBar (org.eclipse.e4.ui.model.application.ui.menu.MToolBar)1 MenuManagerRenderer (org.eclipse.e4.ui.workbench.renderers.swt.MenuManagerRenderer)1 ToolBarManagerRenderer (org.eclipse.e4.ui.workbench.renderers.swt.ToolBarManagerRenderer)1 IRendererFactory (org.eclipse.e4.ui.workbench.swt.factories.IRendererFactory)1 IAction (org.eclipse.jface.action.IAction)1 MenuManager (org.eclipse.jface.action.MenuManager)1 ToolBarManager (org.eclipse.jface.action.ToolBarManager)1 ActionHandler (org.eclipse.jface.commands.ActionHandler)1 Composite (org.eclipse.swt.widgets.Composite)1 IActionBars (org.eclipse.ui.IActionBars)1 IPluginContribution (org.eclipse.ui.IPluginContribution)1