Search in sources :

Example 1 with ContributionInfo

use of org.eclipse.ui.testing.ContributionInfo in project eclipse.platform.ui by eclipse-platform.

the class CompatibilityEditor method createPartControl.

@Override
protected boolean createPartControl(final IWorkbenchPart legacyPart, Composite parent) {
    super.createPartControl(legacyPart, parent);
    clearMenuItems();
    part.getContext().set(IEditorPart.class, (IEditorPart) legacyPart);
    EditorDescriptor descriptor = reference.getDescriptor();
    if (descriptor != null) {
        IConfigurationElement element = descriptor.getConfigurationElement();
        if (element != null) {
            String iconURI = MenuHelper.getIconURI(element, IWorkbenchRegistryConstants.ATT_ICON);
            part.setIconURI(iconURI);
        }
        if (descriptor.getPluginId() != null) {
            parent.setData(new ContributionInfo(descriptor.getPluginId(), ContributionInfoMessages.ContributionInfo_Editor, null));
        }
    }
    if (legacyPart instanceof AbstractMultiEditor && !(legacyPart instanceof MultiEditor)) {
        try {
            createMultiEditorChildren(legacyPart, reference.getEditorInput());
        } catch (PartInitException e) {
            handlePartInitException(e);
            return false;
        }
    }
    return true;
}
Also used : ContributionInfo(org.eclipse.ui.testing.ContributionInfo) AbstractMultiEditor(org.eclipse.ui.part.AbstractMultiEditor) MultiEditor(org.eclipse.ui.part.MultiEditor) AbstractMultiEditor(org.eclipse.ui.part.AbstractMultiEditor) PartInitException(org.eclipse.ui.PartInitException) EditorDescriptor(org.eclipse.ui.internal.registry.EditorDescriptor) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement)

Example 2 with ContributionInfo

use of org.eclipse.ui.testing.ContributionInfo 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 3 with ContributionInfo

use of org.eclipse.ui.testing.ContributionInfo 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)

Example 4 with ContributionInfo

use of org.eclipse.ui.testing.ContributionInfo in project eclipse.platform.ui by eclipse-platform.

the class StartupPreferencePage method createEarlyStartupSelection.

protected void createEarlyStartupSelection(Composite parent) {
    Label label = new Label(parent, SWT.NONE);
    label.setText(WorkbenchMessages.StartupPreferencePage_label);
    label.setFont(parent.getFont());
    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    label.setLayoutData(data);
    pluginsList = new Table(parent, SWT.BORDER | SWT.CHECK | SWT.H_SCROLL | SWT.V_SCROLL);
    data = new GridData(GridData.FILL_BOTH);
    pluginsList.setFont(parent.getFont());
    pluginsList.setLayoutData(data);
    TableViewer viewer = new TableViewer(pluginsList);
    viewer.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            return Platform.getBundle(((ContributionInfo) element).getBundleId()).getHeaders().get(Constants.BUNDLE_NAME);
        }
    });
    viewer.setContentProvider(ArrayContentProvider.getInstance());
    viewer.setInput(workbench.getEarlyActivatedPlugins());
    updateCheckState();
}
Also used : Table(org.eclipse.swt.widgets.Table) ContributionInfo(org.eclipse.ui.testing.ContributionInfo) Label(org.eclipse.swt.widgets.Label) GridData(org.eclipse.swt.layout.GridData) TableViewer(org.eclipse.jface.viewers.TableViewer) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 5 with ContributionInfo

use of org.eclipse.ui.testing.ContributionInfo in project eclipse.platform.ui by eclipse-platform.

the class StartupPreferencePage method updateCheckState.

private void updateCheckState() {
    HashSet<String> disabledPlugins = new HashSet<>(Arrays.asList(workbench.getDisabledEarlyActivatedPlugins()));
    for (int i = 0; i < pluginsList.getItemCount(); i++) {
        TableItem item = pluginsList.getItem(i);
        String pluginId = ((ContributionInfo) item.getData()).getBundleId();
        item.setChecked(!disabledPlugins.contains(pluginId));
    }
}
Also used : ContributionInfo(org.eclipse.ui.testing.ContributionInfo) TableItem(org.eclipse.swt.widgets.TableItem) HashSet(java.util.HashSet)

Aggregations

ContributionInfo (org.eclipse.ui.testing.ContributionInfo)7 Point (org.eclipse.swt.graphics.Point)2 Table (org.eclipse.swt.widgets.Table)2 TableItem (org.eclipse.swt.widgets.TableItem)2 EditorDescriptor (org.eclipse.ui.internal.registry.EditorDescriptor)2 ViewDescriptor (org.eclipse.ui.internal.registry.ViewDescriptor)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)1 IExtension (org.eclipse.core.runtime.IExtension)1 IExtensionPoint (org.eclipse.core.runtime.IExtensionPoint)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