diff options
| author | Florian Barbin | 2015-11-19 15:20:04 +0000 |
|---|---|---|
| committer | Florian Barbin | 2015-11-30 10:06:34 +0000 |
| commit | c79daf76b4b70387e65db6d32b8308013b6dac9c (patch) | |
| tree | 15682b64f6ab5346f94f648ceb610caf4244e787 | |
| parent | 548ff3598beccdc3ea64d5fb45bb875e97f906d6 (diff) | |
| download | org.eclipse.sirius-c79daf76b4b70387e65db6d32b8308013b6dac9c.tar.gz org.eclipse.sirius-c79daf76b4b70387e65db6d32b8308013b6dac9c.tar.xz org.eclipse.sirius-c79daf76b4b70387e65db6d32b8308013b6dac9c.zip | |
[481573] Defines the API to contribute a specific tabbar
Bug: 481573
Change-Id: I7c4e0e470bb67b31c5a94691d3a21c5719f83cd8
Signed-off-by: Florian Barbin <florian.barbin@obeo.fr>
16 files changed, 1470 insertions, 30 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.ui/META-INF/MANIFEST.MF b/plugins/org.eclipse.sirius.diagram.ui/META-INF/MANIFEST.MF index d8046e6c0a..bdad7333b0 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.sirius.diagram.ui/META-INF/MANIFEST.MF @@ -106,6 +106,7 @@ Export-Package: org.eclipse.sirius.diagram.description.concern.provider;version= org.eclipse.sirius.diagram.ui.tools.api.decorators;version="2.1.0", org.eclipse.sirius.diagram.ui.tools.api.draw2d.ui.figures;version="2.0.4", org.eclipse.sirius.diagram.ui.tools.api.editor;version="2.1.0", + org.eclipse.sirius.diagram.ui.tools.api.editor.tabbar;version="4.0.0", org.eclipse.sirius.diagram.ui.tools.api.figure;version="3.1.0", org.eclipse.sirius.diagram.ui.tools.api.figure.anchor;version="2.0.4", org.eclipse.sirius.diagram.ui.tools.api.figure.locator;version="3.0.0", diff --git a/plugins/org.eclipse.sirius.diagram.ui/plugin.properties b/plugins/org.eclipse.sirius.diagram.ui/plugin.properties index 1ef73d6f88..7fb5007bc2 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/plugin.properties +++ b/plugins/org.eclipse.sirius.diagram.ui/plugin.properties @@ -85,6 +85,7 @@ extension-point.layoutDataManager.name = org.eclipse.sirius.diagram.ui.layoutDat extension-point.layoutProvider.name = org.eclipse.sirius.diagram.ui.layoutProvider extension-point.styleConfigurationProvider..name = org.eclipse.sirius.diagram.ui.styleConfigurationProvider extension-point.viewOrderingProvider.name = org.eclipse.sirius.diagram.ui.viewOrderingProvider +extension-point.tabbarContributor.name = Tabbar Contributor Extension extension.diagramProblems.name = Sirius diagram editor Plugin problems menu.find.label = Find menu.showHide.label = Show/Hide @@ -829,8 +830,10 @@ DNodeListViewNodeListCompartment2EditPart_title=ViewNodeListCompartment DNodeListViewNodeListCompartmentEditPart_title=ViewNodeListCompartment DeactivateBehaviorToolsCommand_label = Deactivate behavior tools DeactivateFiltersCommand_label = Deactivate filters -DeactivateRulesCommand_label = Dectivate validation rules +DeactivateRulesCommand_label = Deactivate validation rules DefaultLayerName = Default +DefaultTabbarContributorProvider_contributionError = Cannot instantiate the ITabbarContributor contribution +DefaultTabbarContributorProvider_contributionError_withId = Cannot instantiate the ITabbarContributor contribution in {0} extension DeleteRelatedNoteAttachmentsTask_label = Delete Related GMF note attachments DeleteRelatedNotesTask_label = Delete Related GMF notes DeselectAllAction_label = Deselect All diff --git a/plugins/org.eclipse.sirius.diagram.ui/plugin.xml b/plugins/org.eclipse.sirius.diagram.ui/plugin.xml index 2f8d4b66a0..be9a26134e 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/plugin.xml +++ b/plugins/org.eclipse.sirius.diagram.ui/plugin.xml @@ -18,6 +18,7 @@ <extension-point id="layoutProvider" name="%extension-point.layoutProvider.name" schema="schema/layoutProvider.exsd"/> <extension-point id="layoutDataManager" name="%extension-point.layoutDataManager.name" schema="schema/layoutDataManager.exsd"/> <extension-point id="imageSelector" name="%extension-point.imageSelector.name" schema="schema/imageSelector.exsd"/> + <extension-point id="tabbarContributor" name="%extension-point.tabbarContributor.name" schema="schema/tabbarContributor.exsd"/> <extension point="org.eclipse.ui.elementFactories"> <factory diff --git a/plugins/org.eclipse.sirius.diagram.ui/schema/tabbarContributor.exsd b/plugins/org.eclipse.sirius.diagram.ui/schema/tabbarContributor.exsd new file mode 100644 index 0000000000..8273cfbab5 --- /dev/null +++ b/plugins/org.eclipse.sirius.diagram.ui/schema/tabbarContributor.exsd @@ -0,0 +1,199 @@ +<?xml version='1.0' encoding='UTF-8'?> +<!-- Schema file written by PDE --> +<schema targetNamespace="org.eclipse.sirius.diagram.ui" xmlns="http://www.w3.org/2001/XMLSchema"> +<annotation> + <appInfo> + <meta.schema plugin="org.eclipse.sirius.diagram.ui" id="tabbarContributor" name="Tabbar Contributor Extension"/> + </appInfo> + <documentation> + This extension-point allows providing a full customized tab-bar by implementing the <code>org.eclipse.sirius.diagram.ui.tools.api.editor.tabbar.ITabbarContributor</code>. See the ITabbarContributor documentation for more details. + </documentation> + </annotation> + + <element name="extension"> + <annotation> + <appInfo> + <meta.element /> + </appInfo> + </annotation> + <complexType> + <sequence minOccurs="1" maxOccurs="unbounded"> + <element ref="tabbarContributor"/> + </sequence> + <attribute name="point" type="string" use="required"> + <annotation> + <documentation> + The fully qualified identifier of the target extension point. + </documentation> + </annotation> + </attribute> + <attribute name="id" type="string"> + <annotation> + <documentation> + An optional identifier of the extension instance. + </documentation> + </annotation> + </attribute> + <attribute name="name" type="string"> + <annotation> + <documentation> + An optional name of the extension instance. + </documentation> + <appInfo> + <meta.attribute translatable="true"/> + </appInfo> + </annotation> + </attribute> + </complexType> + </element> + + <element name="tabbarContributor"> + <annotation> + <documentation> + ITabbarContributor implementation + </documentation> + </annotation> + <complexType> + <attribute name="class" type="string" use="required"> + <annotation> + <documentation> + An implementation of ITabbarContributor. An abstract implementation AbstractTabbarContributor is available to reuse the existing Sirius actions. See the interface javadoc for more details. + </documentation> + <appInfo> + <meta.attribute kind="java" basedOn=":org.eclipse.sirius.diagram.ui.tools.api.editor.tabbar.ITabbarContributor"/> + </appInfo> + </annotation> + </attribute> + </complexType> + </element> + + <annotation> + <appInfo> + <meta.section type="since"/> + </appInfo> + <documentation> + This extension-point is available since Sirius 4.0.0. + </documentation> + </annotation> + + <annotation> + <appInfo> + <meta.section type="examples"/> + </appInfo> + <documentation> + <pre><extension + point="org.eclipse.sirius.diagram.ui.tabbarContributor"> + <tabbarContributor + class="org.eclipse.sirius.tests.swtbot.tabbar.SampleTabbarExt"> + </tabbarContributor> +</extension> +</pre> +Example of ITabbarContributor implementation. In this example, we provide two different contributions when the diagram background is selected or when a diagram element is selected. If an edge is selected, the accept method return false. Thus, the tabbar will be empty. +<pre> +public class SampleTabbarExt extends AbstractTabbarContributor { + + private ArrayList<IContributionItem> diagramContributionItems; + + private ArrayList<IContributionItem> diagramElementContributionItems; + + @Override + public List<IContributionItem> getContributionItems(ISelection selection, IDiagramWorkbenchPart part, ToolBarManager manager) { + List<IContributionItem> contributionItems = new ArrayList<IContributionItem>(); + if (selection instanceof IStructuredSelection) { + Object firstElement = ((IStructuredSelection) selection).getFirstElement(); + if (firstElement instanceof AbstractDDiagramEditPart) { + //If the user selects the diagram background, a specifc contribution items list is returned. + contributionItems = getDiagramContributionItem(part, manager); + } else if (firstElement instanceof IAbstractDiagramNodeEditPart) { + //If the user selects a DDIagramElement, another contribution items list is returned. + contributionItems = getDiagramElementContributionItem(part, manager); + } + } + return contributionItems; + } + + @Override + public boolean accept(ISelection selection) { + boolean accept = false; + if (selection == null) { + accept = true; + } else if (selection instanceof IStructuredSelection) { + Object firstElement = ((IStructuredSelection) selection).getFirstElement(); + if (firstElement instanceof AbstractDDiagramEditPart || firstElement instanceof IAbstractDiagramNodeEditPart) { + accept = true; + } + } + return accept; + } + + @Override + public List<IContributionItem> getContributionItems(IDiagramWorkbenchPart part, ToolBarManager manager) { + return getDiagramContributionItem(part, manager); + } + + private List<IContributionItem> getDiagramContributionItem(IDiagramWorkbenchPart part, ToolBarManager manager) { + if (diagramContributionItems == null) { + diagramContributionItems = new ArrayList<IContributionItem>(); + diagramContributionItems.add(createArrangeMenuManager(part)); + diagramContributionItems.add(createSelectMenuManager()); + diagramContributionItems.add(createLayerContribution(part, manager)); + diagramContributionItems.add(createZoomInContribution(part)); + diagramContributionItems.add(createLayoutingModeContributionItem(part)); + diagramContributionItems.add(createCopyAppearancePropertiesContribution(part)); + diagramContributionItems.add(createCopyLayoutContribution(part)); + } + return diagramContributionItems; + } + + private List<IContributionItem> getDiagramElementContributionItem(IDiagramWorkbenchPart part, ToolBarManager manager) { + if (diagramElementContributionItems == null) { + diagramElementContributionItems = new ArrayList<IContributionItem>(); + diagramElementContributionItems.add(createArrangeMenuManager(part)); + diagramElementContributionItems.add(createAlignMenuManager()); + diagramElementContributionItems.add(createHideElementLabelContribution(part)); + diagramElementContributionItems.add(createHideElementContribution(part)); + diagramElementContributionItems.add(createDeleteFromDiagramContribution(part)); + diagramElementContributionItems.add(createDeleteFromModelContribution(part)); + IContributionItem pinElementContributionItem = createPinElementContribution(part); + diagramElementContributionItems.add(pinElementContributionItem); + diagramElementContributionItems.add(createUnPinElementContribution(part, pinElementContributionItem)); + diagramElementContributionItems.add(createAutoSizeContribution(part)); + } + return diagramElementContributionItems; + } + </pre> + </documentation> + </annotation> + + <annotation> + <appInfo> + <meta.section type="apiinfo"/> + </appInfo> + <documentation> + org.eclipse.sirius.diagram.ui.tools.api.editor.tabbar.ITabbarContributor allows providing a customized tab-bar for a specific selection. See "Supplied Implementation" to reuse the default Sirius actions. + </documentation> + </annotation> + + <annotation> + <appInfo> + <meta.section type="implementation"/> + </appInfo> + <documentation> + org.eclipse.sirius.diagram.ui.tools.api.editor.tabbar.AbstractTabbarContributor is an abstract implementation of ITabbarContributor that allows reusing one or several of the default Sirius contribution items. + </documentation> + </annotation> + + <annotation> + <appInfo> + <meta.section type="copyright"/> + </appInfo> + <documentation> + Copyright (c) 2015 Obeo<br/> +All rights reserved. This program and the accompanying materials +are made available under the terms of the Eclipse Public License v1.0 +which accompanies this distribution, and is available at +<a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a> + </documentation> + </annotation> + +</schema> diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/editor/tabbar/AbstractTabbarContributor.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/editor/tabbar/AbstractTabbarContributor.java new file mode 100644 index 0000000000..9d42f3d03d --- /dev/null +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/editor/tabbar/AbstractTabbarContributor.java @@ -0,0 +1,652 @@ +/******************************************************************************* + * Copyright (c) 2015 Obeo. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.sirius.diagram.ui.tools.api.editor.tabbar; + +import org.eclipse.gef.ui.actions.ZoomComboContributionItem; +import org.eclipse.gmf.runtime.diagram.ui.actions.ActionIds; +import org.eclipse.gmf.runtime.diagram.ui.actions.internal.AutoSizeAction; +import org.eclipse.gmf.runtime.diagram.ui.actions.internal.CopyAppearancePropertiesAction; +import org.eclipse.gmf.runtime.diagram.ui.actions.internal.FontDialogAction; +import org.eclipse.gmf.runtime.diagram.ui.actions.internal.FontStyleAction; +import org.eclipse.gmf.runtime.diagram.ui.internal.l10n.DiagramUIPluginImages; +import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramUIMessages; +import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramWorkbenchPart; +import org.eclipse.jface.action.ActionContributionItem; +import org.eclipse.jface.action.ContributionItem; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.action.IContributionItem; +import org.eclipse.jface.action.ToolBarManager; +import org.eclipse.sirius.diagram.DDiagram; +import org.eclipse.sirius.diagram.ui.part.SiriusDiagramActionBarContributor; +import org.eclipse.sirius.diagram.ui.provider.DiagramUIPlugin; +import org.eclipse.sirius.diagram.ui.tools.api.editor.DDiagramEditor; +import org.eclipse.sirius.diagram.ui.tools.api.image.DiagramImagesPath; +import org.eclipse.sirius.diagram.ui.tools.internal.actions.SaveAsImageFileAction; +import org.eclipse.sirius.diagram.ui.tools.internal.actions.SelectHiddenElementsAction; +import org.eclipse.sirius.diagram.ui.tools.internal.actions.SelectPinnedElementsAction; +import org.eclipse.sirius.diagram.ui.tools.internal.actions.SizeBothAction; +import org.eclipse.sirius.diagram.ui.tools.internal.actions.delete.DeleteFromDiagramAction; +import org.eclipse.sirius.diagram.ui.tools.internal.actions.delete.DeleteFromModelWithHookAction; +import org.eclipse.sirius.diagram.ui.tools.internal.actions.layout.CopyLayoutAction; +import org.eclipse.sirius.diagram.ui.tools.internal.actions.layout.PasteLayoutAction; +import org.eclipse.sirius.diagram.ui.tools.internal.actions.refresh.RefreshDiagramAction; +import org.eclipse.sirius.diagram.ui.tools.internal.actions.style.ResetStylePropertiesToDefaultValuesAction; +import org.eclipse.sirius.diagram.ui.tools.internal.actions.style.SetStyleToWorkspaceImageAction; +import org.eclipse.sirius.diagram.ui.tools.internal.actions.visibility.HideDDiagramElementAction; +import org.eclipse.sirius.diagram.ui.tools.internal.editor.tabbar.FiltersContributionItem; +import org.eclipse.sirius.diagram.ui.tools.internal.editor.tabbar.LayersContribution; +import org.eclipse.sirius.diagram.ui.tools.internal.editor.tabbar.LayoutingModeSwitchingAction; +import org.eclipse.sirius.diagram.ui.tools.internal.editor.tabbar.actions.DiagramActionContributionItem; +import org.eclipse.sirius.diagram.ui.tools.internal.editor.tabbar.actions.HideDDiagramElementLabelActionContributionItem; +import org.eclipse.sirius.diagram.ui.tools.internal.editor.tabbar.actions.TabbarAlignMenuManager; +import org.eclipse.sirius.diagram.ui.tools.internal.editor.tabbar.actions.TabbarArrangeMenuManager; +import org.eclipse.sirius.diagram.ui.tools.internal.editor.tabbar.actions.TabbarColorPropertyContributionItem; +import org.eclipse.sirius.diagram.ui.tools.internal.editor.tabbar.actions.TabbarDistributeMenuManager; +import org.eclipse.sirius.diagram.ui.tools.internal.editor.tabbar.actions.TabbarPinElementsEclipseAction; +import org.eclipse.sirius.diagram.ui.tools.internal.editor.tabbar.actions.TabbarRouterMenuManager; +import org.eclipse.sirius.diagram.ui.tools.internal.editor.tabbar.actions.TabbarSelectMenuManager; +import org.eclipse.sirius.diagram.ui.tools.internal.editor.tabbar.actions.TabbarUnpinElementsEclipseAction; +import org.eclipse.sirius.diagram.ui.tools.internal.editor.tabbar.actions.TabbarZoomAction; +import org.eclipse.sirius.diagram.ui.tools.internal.editor.tabbar.actions.TabbarZoomInAction; +import org.eclipse.sirius.diagram.ui.tools.internal.editor.tabbar.actions.TabbarZoomOutAction; +import org.eclipse.sirius.diagram.ui.tools.internal.editor.tabbar.contributions.SiriusTabbarExtensionContributionFactory.TabbarActionContributionItem; +import org.eclipse.sirius.diagram.ui.tools.internal.editor.tabbar.contributions.ZoomExtensionContributionFactory.ZoomContributionItem; +import org.eclipse.swt.widgets.ToolBar; +import org.eclipse.swt.widgets.ToolItem; +import org.eclipse.ui.IWorkbenchPartSite; + +/** + * Abstract implementation of {@link ITabbarContributor}. Inherit from this class + * allows creating one or several contribution items of the default Sirius + * tabbar. + * + * @author Florian Barbin + * + */ +@SuppressWarnings("restriction") +public abstract class AbstractTabbarContributor implements ITabbarContributor { + + /** + * Creates the Automatic Layout contribution item. Organized in a drop-down + * menu, this item is used to trigger an automatic layout of the elements on + * the diagram. + * + * @param part + * the current IDiagramWorkbenchPart. + * @return the {@link IContributionItem}. + */ + protected IContributionItem createArrangeMenuManager(IDiagramWorkbenchPart part) { + TabbarArrangeMenuManager arrangeMenu = new TabbarArrangeMenuManager(part); + arrangeMenu.setVisible(true); + return arrangeMenu; + } + + /** + * Creates the Select menu manager contribution item. Organized in a + * drop-down menu, can be used to select groups of diagram elements in a + * single operation. + * + * @return the {@link IContributionItem}. + */ + protected IContributionItem createSelectMenuManager() { + TabbarSelectMenuManager selectMenu = new TabbarSelectMenuManager(); + selectMenu.setVisible(true); + return selectMenu; + } + + /** + * Creates the Alignment contribution item. This menu contains several + * operations which can be used to align several graphical elements in + * various ways. + * + * @return the {@link IContributionItem}. + */ + protected IContributionItem createAlignMenuManager() { + TabbarAlignMenuManager alignMenu = new TabbarAlignMenuManager(); + alignMenu.setVisible(true); + return alignMenu; + } + + /** + * Creates the Layer Selection contribution item. + * + * @param part + * the diagram workbench part. + * @param manager + * the toolbar manager. + * + * @return the {@link IContributionItem}. + */ + protected IContributionItem createLayerContribution(IDiagramWorkbenchPart part, ToolBarManager manager) { + LayersContribution layersContribution = new LayersContribution(); + ContributionItem layerItem = layersContribution.createContributionItem(manager); + layersContribution.setPart(part); + return layerItem; + } + + /** + * Creates the Filter Selection contribution item. + * + * @param part + * the diagram workbench part. + * @param manager + * the toolbar manager. + * @return the {@link IContributionItem}. + */ + protected IContributionItem createFilterContribution(IDiagramWorkbenchPart part, ToolBarManager manager) { + FiltersContributionItem filtersContribution = new FiltersContributionItem(); + ContributionItem filterItem = filtersContribution.createContributionItem(manager); + filtersContribution.setPart(part); + return filterItem; + } + + /** + * Creates the Select Hidden Elements contribution item. + * + * @param part + * the current IDiagramWorkbenchPart. + * @return the {@link IContributionItem} or null if the workbench part is + * being initialized. + */ + protected IContributionItem createSelectHiddenElementsContribution(IDiagramWorkbenchPart part) { + IWorkbenchPartSite site = part.getSite(); + if (site != null) { + SelectHiddenElementsAction selectHiddenElementsAction = new SelectHiddenElementsAction(site.getPage(), part); + return new ActionContributionItem(selectHiddenElementsAction); + } + return null; + } + + /** + * Creates the Hide Element contribution item. This button hides all the + * selected elements from view. + * + * @param part + * the current IDiagramWorkbenchPart. + * @return the {@link IContributionItem}. + */ + protected IContributionItem createHideElementContribution(IDiagramWorkbenchPart part) { + HideDDiagramElementAction hideDDiagramElementAction = new HideDDiagramElementAction(SiriusDiagramActionBarContributor.HIDE_ELEMENT); + hideDDiagramElementAction.setActionPart(part); + return new TabbarActionContributionItem(hideDDiagramElementAction, part); + } + + /** + * Creates the Hide Element Label contribution item. This button hides the + * label of the selected elements. + * + * @param part + * the current IDiagramWorkbenchPart. + * @return the {@link IContributionItem}. + */ + protected IContributionItem createHideElementLabelContribution(IDiagramWorkbenchPart part) { + HideDDiagramElementLabelActionContributionItem contributionItem = new HideDDiagramElementLabelActionContributionItem(part); + return contributionItem; + } + + /** + * Creates the Delete From Diagram contribution item. This action removes + * the selected graphical element from the diagram, but does not delete the + * corresponding semantic elements. + * + * @param part + * the current IDiagramWorkbenchPart. + * @return the {@link IContributionItem}. + */ + protected IContributionItem createDeleteFromDiagramContribution(IDiagramWorkbenchPart part) { + DeleteFromDiagramAction deleteFromDiagramAction = new DeleteFromDiagramAction(DiagramUIMessages.DiagramEditor_Delete_from_Diagram, SiriusDiagramActionBarContributor.DELETE_FROM_DIAGRAM, + ActionIds.ACTION_DELETE_FROM_DIAGRAM, DiagramUIPlugin.Implementation.getBundledImageDescriptor(DiagramImagesPath.DELETE_FROM_DIAGRAM_ICON)); + return new TabbarActionContributionItem(deleteFromDiagramAction, part); + } + + /** + * Creates the Delete From Model contribution item. This action removes both + * the selected graphical element and the corresponding semantic elements. + * + * @param part + * the current IDiagramWorkbenchPart. + * @return the {@link IContributionItem} or null if the workbench part is + * being initialized. + */ + protected IContributionItem createDeleteFromModelContribution(IDiagramWorkbenchPart part) { + IWorkbenchPartSite site = part.getSite(); + if (site != null) { + DeleteFromModelWithHookAction deleteFromModelAction = new DeleteFromModelWithHookAction(site.getPage(), part); + deleteFromModelAction.init(); + return new DiagramActionContributionItem(deleteFromModelAction); + } + return null; + } + + /** + * Creates the Select Pinned elements contribution item. + * + * @param part + * the current IDiagramWorkbenchPart. + * @return the {@link IContributionItem} or null if the workbench part is + * being initialized. + */ + protected IContributionItem createSelectPinnedElementsContribution(IDiagramWorkbenchPart part) { + IWorkbenchPartSite site = part.getSite(); + if (site != null) { + SelectPinnedElementsAction pinnedElementsAction = new SelectPinnedElementsAction(site.getPage(), part); + + return new ActionContributionItem(pinnedElementsAction); + } + return null; + } + + /** + * Creates the Pin element contribution item. Mark all the selected elements + * as pinned. + * + * @param part + * the current IDiagramWorkbenchPart. + * @return the {@link IContributionItem}. + */ + protected IContributionItem createPinElementContribution(IDiagramWorkbenchPart part) { + TabbarPinElementsEclipseAction pinAction = new TabbarPinElementsEclipseAction(); + return new TabbarActionContributionItem(pinAction, part); + } + + /** + * Creates the Unpin element contribution item. Mark all the selected + * elements as un-pinned. + * + * @param part + * the current IDiagramWorkbenchPart. + * @param pinElementContributionItem + * the opposite pin contribution item. Can be null. + * @return the {@link IContributionItem}. + */ + protected IContributionItem createUnPinElementContribution(IDiagramWorkbenchPart part, IContributionItem pinElementContributionItem) { + + TabbarUnpinElementsEclipseAction unpinAction = new TabbarUnpinElementsEclipseAction(); + if (pinElementContributionItem instanceof TabbarActionContributionItem) { + IAction pinAction = ((TabbarActionContributionItem) pinElementContributionItem).getAction(); + if (pinAction instanceof TabbarPinElementsEclipseAction) { + ((TabbarPinElementsEclipseAction) pinAction).setOppositePinAction(unpinAction); + } + unpinAction.setOppositePinAction(pinAction); + } + return new TabbarActionContributionItem(unpinAction, part); + } + + /** + * Creates the Zoom combo contribution item. + * + * @param part + * the current IDiagramWorkbenchPart. + * @return the {@link IContributionItem} or null if the workbench part is + * being initialized. + */ + protected IContributionItem createZoomContribution(IDiagramWorkbenchPart part) { + IWorkbenchPartSite site = part.getSite(); + if (site != null) { + ZoomComboContributionItem zoomItem = new ZoomComboContributionItem(site.getPage()) { + + @Override + public void fill(ToolBar parent, int index) { + super.fill(parent, index); + ToolItem addedItem = parent.getItem(parent.getItemCount() - 1); + addedItem.setToolTipText(DiagramUIMessages.ZoomActionMenu_ZoomLabel); + } + + }; + return zoomItem; + } + return null; + } + + /** + * Creates the Zoom-in contribution item. + * + * @param part + * the current IDiagramWorkbenchPart. + * @return the {@link IContributionItem} or null if the workbench part is + * being initialized. + */ + protected IContributionItem createZoomInContribution(IDiagramWorkbenchPart part) { + IWorkbenchPartSite site = part.getSite(); + if (site != null) { + TabbarZoomAction zoomIn = new TabbarZoomInAction(); + zoomIn.setImageDescriptor(DiagramUIPluginImages.DESC_ZOOM_IN); + zoomIn.setText(DiagramUIMessages.ZoomAction_ZoomIn); + return new ZoomContributionItem(zoomIn, site.getPage()); + } + return null; + } + + /** + * Creates the Zoom-out contribution item. + * + * @param part + * the current IDiagramWorkbenchPart. + * @return the {@link IContributionItem} or null if the workbench part is + * being initialized. + */ + protected IContributionItem createZoomOutContribution(IDiagramWorkbenchPart part) { + IWorkbenchPartSite site = part.getSite(); + if (site != null) { + TabbarZoomAction zoomOut = new TabbarZoomOutAction(); + zoomOut.setImageDescriptor(DiagramUIPluginImages.DESC_ZOOM_OUT); + zoomOut.setText(DiagramUIMessages.ZoomAction_ZoomOut); + return new ZoomContributionItem(zoomOut, site.getPage()); + } + return null; + } + + /** + * Creates the Font Color contribution item. + * + * @param part + * the current IDiagramWorkbenchPart. + * @return the {@link IContributionItem} or null if the workbench part is + * being initialized. + */ + protected IContributionItem createFontColorContribution(IDiagramWorkbenchPart part) { + IWorkbenchPartSite site = part.getSite(); + if (site != null) { + TabbarColorPropertyContributionItem fontColorMenu = TabbarColorPropertyContributionItem.createFontColorContributionItem(site.getPage()); + fontColorMenu.setActionWorkbenchPart(part); + return fontColorMenu; + } + return null; + } + + /** + * Creates the Bold font contribution item. + * + * @param part + * the current IDiagramWorkbenchPart. + * @return the {@link IContributionItem} or null if the workbench part is + * being initialized. + */ + protected IContributionItem createBoldFontStyleContribution(IDiagramWorkbenchPart part) { + IWorkbenchPartSite site = part.getSite(); + if (site != null) { + FontStyleAction fontStyleBoldAction = FontStyleAction.createBoldFontStyleAction(site.getPage()); + return new ActionContributionItem(fontStyleBoldAction); + } + return null; + } + + /** + * Creates the Italic font contribution item. + * + * @param part + * the current IDiagramWorkbenchPart. + * @return the {@link IContributionItem} or null if the workbench part is + * being initialized. + */ + protected IContributionItem createItalicFontStyleContribution(IDiagramWorkbenchPart part) { + IWorkbenchPartSite site = part.getSite(); + if (site != null) { + FontStyleAction fontStyleItalicAction = FontStyleAction.createItalicFontStyleAction(site.getPage()); + return new ActionContributionItem(fontStyleItalicAction); + } + return null; + } + + /** + * Creates the Font dialog contribution item. + * + * @param part + * the current IDiagramWorkbenchPart. + * @return the {@link IContributionItem} or null if the workbench part is + * being initialized. + */ + protected IContributionItem createFontDialogContribution(IDiagramWorkbenchPart part) { + IWorkbenchPartSite site = part.getSite(); + if (site != null) { + IAction fontDialogAction = new FontDialogAction(site.getPage()); + fontDialogAction.setImageDescriptor(DiagramUIPlugin.Implementation.getBundledImageDescriptor(DiagramImagesPath.FONT_WIZARD)); + return new ActionContributionItem(fontDialogAction); + } + return null; + } + + /** + * Creates the Fill Color contribution item. + * + * @param part + * the current IDiagramWorkbenchPart. + * @return the {@link IContributionItem} or null if the workbench part is + * being initialized. + */ + protected IContributionItem createFillColorContribution(IDiagramWorkbenchPart part) { + IWorkbenchPartSite site = part.getSite(); + if (site != null) { + TabbarColorPropertyContributionItem fillColorMenu = TabbarColorPropertyContributionItem.createFillColorContributionItem(site.getPage()); + fillColorMenu.setActionWorkbenchPart(part); + return fillColorMenu; + } + return null; + } + + /** + * Creates the Line Color contribution item. + * + * @param part + * the current IDiagramWorkbenchPart. + * @return the {@link IContributionItem} or null if the workbench part is + * being initialized. + */ + protected IContributionItem createLineColorPropertyContribution(IDiagramWorkbenchPart part) { + IWorkbenchPartSite site = part.getSite(); + if (site != null) { + TabbarColorPropertyContributionItem lineColorMenu = TabbarColorPropertyContributionItem.createLineColorContributionItem(site.getPage()); + lineColorMenu.setActionWorkbenchPart(part); + return lineColorMenu; + } + return null; + } + + /** + * Creates the Cancel Custom Style contribution item. The Cancel Custom + * Style button resets all the style attributes of an element to its default + * values and un-marks it as customized. + * + * @param part + * the current IDiagramWorkbenchPart. + * @return the {@link IContributionItem} or null if the workbench part is + * being initialized. + */ + protected IContributionItem createResetStylePropertyContribution(IDiagramWorkbenchPart part) { + IWorkbenchPartSite site = part.getSite(); + if (site != null) { + ResetStylePropertiesToDefaultValuesAction resetStylePropertiesToDefaultValuesAction = new ResetStylePropertiesToDefaultValuesAction(site.getPage()); + return new TabbarActionContributionItem(resetStylePropertiesToDefaultValuesAction, part); + } + return null; + } + + /** + * Creates the set style to workspace image contribution item. The Workspace + * image button can be used to replace the graphical representation of an + * element by an image that you can select from anywhere in your Eclipse + * workspace. + * + * @param part + * the current IDiagramWorkbenchPart. + * @return the {@link IContributionItem}. + */ + protected IContributionItem createSetStyleToWorkspaceImageContribution(IDiagramWorkbenchPart part) { + return new TabbarActionContributionItem(new SetStyleToWorkspaceImageAction(), part); + } + + /** + * Creates the Distribute menu contribution item. This menu contains several + * actions which can be used to distribute the selected diagram elements + * horizontally/vertically with a same space between their centers or their + * bounds. + * + * @return the {@link IContributionItem}. + */ + protected IContributionItem createDistributeContribution() { + TabbarDistributeMenuManager distributeMenu = new TabbarDistributeMenuManager(); + return distributeMenu; + } + + /** + * Creates the Export As Image contribution item.This button can be used to + * export the current diagram as an image file stored on disk. + * + * @return the {@link IContributionItem}. + */ + protected IContributionItem createSaveAsImageContributionItem() { + SaveAsImageFileAction saveAsImageFileAction = new SaveAsImageFileAction(); + return new ActionContributionItem(saveAsImageFileAction); + } + + /** + * Creates the Layout Mode contribution item. This button enables a special + * "layout mode", in which some operations are prevented from having an + * effect on the semantic model. + * + * @param part + * the current IDiagramWorkbenchPart. + * @return the {@link IContributionItem} or null if the workbench part is + * being initialized or if the diagram doesn't allow the layouting + * mode. + */ + protected IContributionItem createLayoutingModeContributionItem(IDiagramWorkbenchPart part) { + IWorkbenchPartSite site = part.getSite(); + if (site != null && part instanceof DDiagramEditor) { + final DDiagramEditor editor = (DDiagramEditor) part; + DDiagram editorDiagram = (DDiagram) editor.getRepresentation(); + if (LayoutingModeSwitchingAction.diagramAllowsLayoutingMode(editorDiagram)) { + LayoutingModeSwitchingAction layoutingModeSwitchingAction = new LayoutingModeSwitchingAction(site.getPage(), editorDiagram); + return new TabbarActionContributionItem(layoutingModeSwitchingAction); + } + } + return null; + } + + /** + * Creates the Router contribution item. This action allows changing the + * line style of edges (Rectilinear, Oblique, Tree) + * + * @return the {@link IContributionItem}. + */ + protected IContributionItem createRouterContribution() { + TabbarRouterMenuManager routerMenu = new TabbarRouterMenuManager(); + routerMenu.setVisible(true); + return routerMenu; + } + + /** + * Creates the Apply Style contribution item. Use this button to reproduce + * the visual style of an element onto others. + * + * @param part + * the current IDiagramWorkbenchPart. + * @return the {@link IContributionItem} or null if the workbench part is + * being initialized. + */ + protected IContributionItem createCopyAppearancePropertiesContribution(IDiagramWorkbenchPart part) { + IWorkbenchPartSite site = part.getSite(); + if (site != null) { + CopyAppearancePropertiesAction copyAppearancePropertiesAction = new CopyAppearancePropertiesAction(site.getPage()); + return new ActionContributionItem(copyAppearancePropertiesAction); + } + return null; + } + + /** + * Creates the copy layout contribution item. This tool can be used to + * duplicate the layout of some diagram elements from this diagram into + * another. + * + * @param part + * the current IDiagramWorkbenchPart. + * @return the {@link IContributionItem} or null if the workbench part is + * being initialized. + */ + protected IContributionItem createCopyLayoutContribution(IDiagramWorkbenchPart part) { + IWorkbenchPartSite site = part.getSite(); + if (site != null) { + CopyLayoutAction copyLayoutAction = new CopyLayoutAction(site.getPage(), part); + return new ActionContributionItem(copyLayoutAction); + } + return null; + } + + /** + * Creates the Paste Layout contribution item. + * + * @param part + * the current IDiagramWorkbenchPart. + * @return the {@link IContributionItem} or null if the workbench part is + * being initialized. + */ + protected IContributionItem createPasteLayoutContribution(IDiagramWorkbenchPart part) { + IWorkbenchPartSite site = part.getSite(); + if (site != null) { + PasteLayoutAction pasteLayoutAction = new PasteLayoutAction(site.getPage(), part); + return new ActionContributionItem(pasteLayoutAction); + } + return null; + } + + /** + * Creates the Refresh action contribution item. This operation, which can + * also be invoked with the F5 keyboard shortcut, will force an update of + * the diagram's content according to the latest version of the underlying + * semantic model. + * + * @return the {@link IContributionItem}. + */ + protected IContributionItem createRefreshContribution() { + RefreshDiagramAction action = new RefreshDiagramAction(SiriusDiagramActionBarContributor.REFRESH_DIAGRAM, + DiagramUIPlugin.Implementation.getBundledImageDescriptor(DiagramImagesPath.REFRESH_IMG)); + return new ActionContributionItem(action); + } + + /** + * Creates the Make Same Size contribution item. When multiple elements are + * selected, clicking on this tool will resize all of them to have the same + * size (both width and height). + * + * @param part + * the current IDiagramWorkbenchPart. + * @return the {@link IContributionItem} or null if the workbench part is + * being initialized. + */ + protected IContributionItem createSizeBothContribution(IDiagramWorkbenchPart part) { + IWorkbenchPartSite site = part.getSite(); + if (site != null) { + SizeBothAction sizeBothAction = new SizeBothAction(site.getPage()); + sizeBothAction.init(); + return new ActionContributionItem(sizeBothAction); + } + return null; + } + + /** + * Creates the Auto-Size contribution item. This button marks the selected + * elements as auto-sized. + * + * @param part + * the current IDiagramWorkbenchPart. + * @return the {@link IContributionItem} or null if the workbench part is + * being initialized. + */ + protected IContributionItem createAutoSizeContribution(IDiagramWorkbenchPart part) { + IWorkbenchPartSite site = part.getSite(); + if (site != null) { + AutoSizeAction autoSizeAction = new AutoSizeAction(site.getPage()); + return new ActionContributionItem(autoSizeAction); + } + return null; + } + +} diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/editor/tabbar/ITabbarContributor.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/editor/tabbar/ITabbarContributor.java new file mode 100644 index 0000000000..e836547404 --- /dev/null +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/editor/tabbar/ITabbarContributor.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2015 Obeo. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.sirius.diagram.ui.tools.api.editor.tabbar; + +import java.util.List; + +import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramWorkbenchPart; +import org.eclipse.jface.action.IContributionItem; +import org.eclipse.jface.action.ToolBarManager; +import org.eclipse.jface.viewers.ISelection; + +/** + * A tabbar contributor aims to provide a specific list of + * {@link IContributionItem} that will be displayed in the tabbar. + * + * @author Florian Barbin + * + */ +public interface ITabbarContributor { + + /** + * Provides the {@link IContributionItem} if there is no specific selection + * (at the diagram opening for instance). + * + * @param part + * the current workbench part. + * @param toolBarManager + * the toolbar manager + * @return the {@link IContributionItem} list. + */ + List<IContributionItem> getContributionItems(IDiagramWorkbenchPart part, ToolBarManager toolBarManager); + + /** + * Provides the {@link IContributionItem} according to the current + * selection. Keep in mind that this method will be called each time the + * selection changes. To avoid adding too much instances of a same kind of + * contribution item, you should return the same instance list for each kind + * of selection. + * + * @param selection + * the current selection. + * @param part + * the current workbench part. + * @param toolBarManager + * the toolbar manager + * @return the {@link IContributionItem} list. + */ + List<IContributionItem> getContributionItems(ISelection selection, IDiagramWorkbenchPart part, ToolBarManager toolBarManager); + + /** + * Returns whether this TabbarContributor provides a list of + * {@link IContributionItem} for this kind of selection. + * + * @param selection + * the current selection or null if no selection. + * @return true if it provides a {@link IContributionItem} list, otherwise + * false. + */ + boolean accept(ISelection selection); +} diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/tabbar/ExtensionPointTabbarContributorProvider.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/tabbar/ExtensionPointTabbarContributorProvider.java new file mode 100644 index 0000000000..b06e6c52c2 --- /dev/null +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/tabbar/ExtensionPointTabbarContributorProvider.java @@ -0,0 +1,98 @@ +/******************************************************************************* + * Copyright (c) 2015 Obeo. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.sirius.diagram.ui.tools.internal.editor.tabbar; + +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExtension; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.sirius.common.tools.api.util.EclipseUtil; +import org.eclipse.sirius.common.tools.api.util.StringUtil; +import org.eclipse.sirius.diagram.ui.provider.DiagramUIPlugin; +import org.eclipse.sirius.diagram.ui.provider.Messages; +import org.eclipse.sirius.diagram.ui.tools.api.editor.tabbar.ITabbarContributor; +import org.eclipse.sirius.viewpoint.SiriusPlugin; + +/** + * This implementation of {@link ITabbarContributorProvider} looks for extension + * in the extension point. + * + * @author Florian Barbin + * + */ +public class ExtensionPointTabbarContributorProvider implements ITabbarContributorProvider { + + /** + * The tabbar extension point ID. + */ + public static final String EXTENSION_ID = "org.eclipse.sirius.diagram.ui.tabbarContributor"; //$NON-NLS-1$ + + private List<ITabbarContributor> loadedExtensions; + + @Override + public boolean hasContributor() { + if (loadedExtensions == null) { + loadExtensions(); + } + return !loadedExtensions.isEmpty(); + } + + @Override + public ITabbarContributor getContributor() { + return getContributor(null); + } + + @Override + public ITabbarContributor getContributor(ISelection selection) { + if (loadedExtensions == null) { + loadExtensions(); + } + for (ITabbarContributor extension : loadedExtensions) { + if (extension.accept(selection)) { + return extension; + } + } + return null; + } + + private void loadExtensions() { + this.loadedExtensions = new ArrayList<ITabbarContributor>(); + + IConfigurationElement[] configurationElements = EclipseUtil.getConfigurationElementsFor(EXTENSION_ID); + for (IConfigurationElement configurationElement : configurationElements) { + try { + Object contribution = configurationElement.createExecutableExtension("class"); //$NON-NLS-1$ + if (contribution instanceof ITabbarContributor) { + loadedExtensions.add((ITabbarContributor) contribution); + } + } catch (CoreException e) { + String extensionId = null; + Object parent = configurationElement.getParent(); + if (parent instanceof IExtension) { + extensionId = ((IExtension) parent).getUniqueIdentifier(); + } + String message = StringUtil.EMPTY_STRING; + if (extensionId != null) { + message = MessageFormat.format(Messages.DefaultTabbarContributorProvider_contributionError_withId, extensionId); + } else { + message = Messages.DefaultTabbarContributorProvider_contributionError; + } + SiriusPlugin.getDefault().getLog().log(new Status(IStatus.WARNING, DiagramUIPlugin.ID, message, e)); + } + } + } +} diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/tabbar/ITabbarContributorProvider.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/tabbar/ITabbarContributorProvider.java new file mode 100644 index 0000000000..4644b46e89 --- /dev/null +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/tabbar/ITabbarContributorProvider.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2015 Obeo. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.sirius.diagram.ui.tools.internal.editor.tabbar; + +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.sirius.diagram.ui.tools.api.editor.tabbar.ITabbarContributor; + +/** + * + * A ITabbarContributorProvider allows providing {@link ITabbarContributor}. + * + * @author Florian Barbin + * + */ +public interface ITabbarContributorProvider { + + /** + * Returns whether tabbar contributors are available. + * + * @return true if at least one contributor has been provided, otherwise + * false. + */ + boolean hasContributor(); + + /** + * Provides the first {@link ITabbarContributor} accepting an empty + * selection. + * + * @return the first {@link ITabbarContributor} if found, otherwise null. + */ + ITabbarContributor getContributor(); + + /** + * Provides the first {@link ITabbarContributor} accepting the given + * selection. + * + * @param selection + * the current selection. + * @return the first {@link ITabbarContributor} if found, otherwise null. + */ + ITabbarContributor getContributor(ISelection selection); + +} diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/tabbar/Tabbar.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/tabbar/Tabbar.java index d92e068552..91aa13c954 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/tabbar/Tabbar.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/tabbar/Tabbar.java @@ -21,6 +21,7 @@ import org.eclipse.jface.action.IContributionItem; import org.eclipse.jface.action.IToolBarManager; import org.eclipse.jface.action.ToolBarManager; import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.sirius.business.api.session.Session; import org.eclipse.sirius.common.ui.tools.api.util.EclipseUIUtil; import org.eclipse.sirius.diagram.ui.tools.api.editor.DDiagramEditor; @@ -63,6 +64,10 @@ public class Tabbar extends Composite implements ISelectionListener, IAuthorityL private IPermissionAuthority permissionAuthority; + private ITabbarContributorProvider tabbarContributorProvider; + + private Collection<Object> currentSelection; + /** * Instantiate a new tab bar. * @@ -81,6 +86,7 @@ public class Tabbar extends Composite implements ISelectionListener, IAuthorityL layout.marginHeight = 0; layout.marginWidth = 0; this.setLayout(layout); + this.tabbarContributorProvider = new ExtensionPointTabbarContributorProvider(); createToolBar(); fillForDiagram(); } @@ -117,10 +123,14 @@ public class Tabbar extends Composite implements ISelectionListener, IAuthorityL } private void fillForDiagram() { - if (canBeDynamic()) { - diagramFiller = new TabbarFillerWithContributions(manager, page); + if (tabbarContributorProvider.hasContributor()) { + diagramFiller = new TabbarFillerWithContributor(manager, page, tabbarContributorProvider); } else { - diagramFiller = new TabbarFillerWithoutContributions(manager, page); + if (canBeDynamic()) { + diagramFiller = new TabbarFillerWithContributions(manager, page); + } else { + diagramFiller = new TabbarFillerWithoutContributions(manager, page); + } } diagramFiller.setPart(part); diagramFiller.fill(); @@ -150,10 +160,28 @@ public class Tabbar extends Composite implements ISelectionListener, IAuthorityL return canBeDynamic; } + @SuppressWarnings("unchecked") @Override public void selectionChanged(IWorkbenchPart partSelected, ISelection selection) { - // nothing to do here. Each item contribution is now responsible for - // refresh himself when selection change. + if (diagramFiller instanceof TabbarFillerWithContributor && partSelected == this.part) { + if (currentSelection == null || !sameSelection(selection)) { + if (selection instanceof StructuredSelection) { + currentSelection = ((StructuredSelection) selection).toList(); + } + reinitToolBar(selection); + } + } + } + + @SuppressWarnings("rawtypes") + private boolean sameSelection(ISelection selection) { + if (selection instanceof StructuredSelection) { + List newSelection = ((StructuredSelection) selection).toList(); + if (newSelection.size() == currentSelection.size()) { + return currentSelection.containsAll(newSelection); + } + } + return false; } /** @@ -163,6 +191,9 @@ public class Tabbar extends Composite implements ISelectionListener, IAuthorityL * the selection */ public void reinitToolBar(ISelection iSelection) { + if (diagramFiller instanceof TabbarFillerWithContributor) { + ((TabbarFillerWithContributor) diagramFiller).update(iSelection); + } updateAllItems(); } diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/tabbar/TabbarFillerWithContributor.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/tabbar/TabbarFillerWithContributor.java new file mode 100644 index 0000000000..d1d078c97a --- /dev/null +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/tabbar/TabbarFillerWithContributor.java @@ -0,0 +1,91 @@ +/******************************************************************************* + * Copyright (c) 2015 Obeo. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.sirius.diagram.ui.tools.internal.editor.tabbar; + +import java.util.Arrays; +import java.util.List; + +import org.eclipse.jface.action.IContributionItem; +import org.eclipse.jface.action.ToolBarManager; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.sirius.diagram.ui.tools.api.editor.tabbar.ITabbarContributor; +import org.eclipse.ui.IWorkbenchPage; + +/** + * A Tabbar Filler that will retrieve contribution items from Tabbar + * Contributors. + * + * @author Florian Barbin + * + */ +public class TabbarFillerWithContributor extends AbstractTabbarFiller { + + private ITabbarContributorProvider tabbarContributorProvider; + + /** + * Default Constructor. + * + * @param manager + * the {@link ToolBarManager}. + * @param page + * the current {@link IWorkbenchPage}. + * @param tabbarContributorProvider + * the tabbar contributor provider. + */ + public TabbarFillerWithContributor(ToolBarManager manager, IWorkbenchPage page, ITabbarContributorProvider tabbarContributorProvider) { + super(manager, page); + this.tabbarContributorProvider = tabbarContributorProvider; + } + + @Override + protected void doFill() { + ITabbarContributor contributor = this.tabbarContributorProvider.getContributor(); + if (contributor != null) { + List<IContributionItem> contributionItems = contributor.getContributionItems(part, manager); + for (IContributionItem item : contributionItems) { + manager.add(item); + } + } + } + + /** + * Updates the tabbar according to the given selection. + * + * @param iSelection + * the current selection. + */ + public void update(ISelection iSelection) { + ITabbarContributor contributor = this.tabbarContributorProvider.getContributor(iSelection); + List<IContributionItem> existingItems = Arrays.asList(manager.getItems()); + for (IContributionItem current : existingItems) { + current.setVisible(false); + } + if (contributor != null) { + List<IContributionItem> contributionItems = contributor.getContributionItems(iSelection, part, manager); + for (IContributionItem item : contributionItems) { + if (existingItems.contains(item)) { + item.setVisible(true); + } else { + manager.add(item); + } + } + } + manager.update(true); + } + + @Override + public void dispose() { + tabbarContributorProvider = null; + manager.dispose(); + super.dispose(); + } + +} diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/tabbar/contributions/ZoomExtensionContributionFactory.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/tabbar/contributions/ZoomExtensionContributionFactory.java index 8f5e50f660..bfb1a49289 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/tabbar/contributions/ZoomExtensionContributionFactory.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/tabbar/contributions/ZoomExtensionContributionFactory.java @@ -66,7 +66,7 @@ public class ZoomExtensionContributionFactory extends SiriusTabbarExtensionContr zoomIn.setText(DiagramUIMessages.ZoomAction_ZoomIn); TabbarZoomAction zoomOut = new TabbarZoomOutAction(); zoomOut.setImageDescriptor(DiagramUIPluginImages.DESC_ZOOM_OUT); - zoomIn.setText(DiagramUIMessages.ZoomAction_ZoomOut); + zoomOut.setText(DiagramUIMessages.ZoomAction_ZoomOut); additions.addContributionItem(new ZoomContributionItem(zoomIn, getPage()), new DDiagramTabbarExpression()); additions.addContributionItem(new ZoomContributionItem(zoomOut, getPage()), new DDiagramTabbarExpression()); @@ -97,6 +97,7 @@ public class ZoomExtensionContributionFactory extends SiriusTabbarExtensionContr super(action); this.page = page; listener = new IPartListener() { + @Override public void partActivated(IWorkbenchPart part) { if (part instanceof DDiagramEditor) { final ZoomManager zoomManager = (ZoomManager) part.getAdapter(ZoomManager.class); @@ -106,15 +107,19 @@ public class ZoomExtensionContributionFactory extends SiriusTabbarExtensionContr } } + @Override public void partBroughtToTop(IWorkbenchPart p) { } + @Override public void partClosed(IWorkbenchPart p) { } + @Override public void partDeactivated(IWorkbenchPart p) { } + @Override public void partOpened(IWorkbenchPart p) { } }; diff --git a/plugins/org.eclipse.sirius.diagram.ui/src/org/eclipse/sirius/diagram/ui/provider/Messages.java b/plugins/org.eclipse.sirius.diagram.ui/src/org/eclipse/sirius/diagram/ui/provider/Messages.java index 87409792e7..f7754a1cbe 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src/org/eclipse/sirius/diagram/ui/provider/Messages.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src/org/eclipse/sirius/diagram/ui/provider/Messages.java @@ -276,6 +276,12 @@ public final class Messages { public static String DefaultLayerName; @TranslatableMessage + public static String DefaultTabbarContributorProvider_contributionError_withId; + + @TranslatableMessage + public static String DefaultTabbarContributorProvider_contributionError; + + @TranslatableMessage public static String DeleteRelatedNoteAttachmentsTask_label; @TranslatableMessage diff --git a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html index 837fe6509b..fcfac68244 100644 --- a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html +++ b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html @@ -99,6 +99,24 @@ </li> </ul> <h3 id="DeveloperVisibleChanges">Developer-Visible Changes</h3> + <ul> + <li><span class="label label-success">Added</span> It is now possible to provide a full customized tab-bar by implementing the + <code>ITabbarContributor</code> through the + <code>org.eclipse.sirius.diagram.ui.tabbarContributor</code> extension-point. See the developer documentation for more details. + </li> + </ul> + <h4 id="Changesinorg.eclipse.sirius.diagram.ui">Changes in + <code>org.eclipse.sirius.diagram.ui</code> + </h4> + <ul> + <li><span class="label label-success">Added</span> + <code>org.eclipse.sirius.diagram.ui.tools.api.editor.tabbar.ITabbarContributor</code> interface has been added to provide a customized tab-bar for a specific selection. + </li> + <li><span class="label label-success">Added</span> + <code>org.eclipse.sirius.diagram.ui.tools.api.editor.tabbar.AbstractTabbarContributor</code> is an abstract implementation of + <code>ITabbarContributor</code> that allows reusing one or several of the default Sirius contribution items. + </li> + </ul> <h4 id="Changesinorg.eclipse.sirius.ext.emf.ui">Changes in <code>org.eclipse.sirius.ext.emf.ui</code> </h4> @@ -233,7 +251,7 @@ </ul> <h3 id="DeveloperVisibleChanges3">Developer-Visible Changes</h3> <h4 id="Partialsupportforinternationalization">Partial support for internationalization</h4> - <p>Sirius 3.1 introduces partial support for internationalization: all literal strings from the runtime part of Sirius are now externalized and can be localized by third parties by providing the appropriate «language packs» as OSGi fragments. Note that this does not concern the VSM editor’s UI, the VSMs themselves, or the parts of the UI inherited from Eclipse/EMF/GEF/GMF and other libraries and frameworks used by Sirius.</p> + <p>Sirius 3.1 introduces partial support for internationalization: all literal strings from the runtime part of Sirius are now externalized and can be localized by third parties by providing the appropriate “language packs” as OSGi fragments. Note that this does not concern the VSM editor’s UI, the VSMs themselves, or the parts of the UI inherited from Eclipse/EMF/GEF/GMF and other libraries and frameworks used by Sirius.</p> <p>Some API changes were required to enable this. While technically breaking changes if interpreting strictly the OSGi versioning rules, the major version number of the impacted bundles was not incremented as the changes only concern classes that should not impact the vast majority of users. Most breaking changes concern the plug-in/activator classes from each bundle. They are:</p> <ul> <li><span class="label label-success">Added</span> @@ -524,7 +542,7 @@ <code>IEditorPart</code> through the navigation history view. </li> </ul> - <h4 id="Changesinorg.eclipse.sirius.diagram.ui">Changes in + <h4 id="Changesinorg.eclipse.sirius.diagram.ui2">Changes in <code>org.eclipse.sirius.diagram.ui</code> </h4> <ul> @@ -702,7 +720,7 @@ </li> <li><span class="label label-success">Added</span> On diagrams, it is now possible to set a custom background image on list containers.</li> <li><span class="label label-info">Modified</span> In the - <em>Viewpoint Selection</em> dialog and wizard page, the «plug-in» decorator for viewpoints loaded from plug-ins is removed, and a «Folder» decorator for viewpoints loaded from the current workspace has been added. This makes the icons more visible in the most common where viewpoints come from installed plug-ins. + <em>Viewpoint Selection</em> dialog and wizard page, the “plug-in” decorator for viewpoints loaded from plug-ins is removed, and a “Folder” decorator for viewpoints loaded from the current workspace has been added. This makes the icons more visible in the most common where viewpoints come from installed plug-ins. </li> </ul> <h3 id="SpecifierVisibleChanges4">Specifier-Visible Changes</h3> @@ -725,12 +743,12 @@ <li><span class="label label-success">Added</span> Compressed SVG images ( <code>*.svgz</code>) are now supported everywhere normal SVG images were supported. </li> - <li><span class="label label-success">Added</span> When developing a modeler in «live mode», with the VSM in the same workspace as the sample session(s) which use it, VSM expressions which use + <li><span class="label label-success">Added</span> When developing a modeler in “live mode”, with the VSM in the same workspace as the sample session(s) which use it, VSM expressions which use <code>service:</code> or <code>aql:</code> can now invoke Java services which are defined in the workspace (with no need to launch a separate runtime). </li> <li><span class="label label-success">Added</span> A quick outline is now accessible in the VSM editor by using the shortcut <kbd>Ctrl+o</kbd>. It supports filtering on both an element’s name and properties for quick, keyboard-only navigation in complex VSMs.</li> - <li><span class="label label-success">Added</span> The «hide label by default capability» has been added to the container styles.</li> + <li><span class="label label-success">Added</span> The “hide label by default capability” has been added to the container styles.</li> <li><span class="label label-success">Added</span> In addition to <em>Bold</em> and <em>Italic</em>, @@ -763,7 +781,7 @@ </li> <li><span class="label label-success">Improved</span> The precision of the VSM validation, especially regarding the typing of computed expressions, has been greatly improved. Other validation rules like static image paths have also been added or improved.</li> <li><span class="label label-info">Modified</span> In the VSM editor, the context menu entries (categories and items) have been reorganized to put most common actions/items first.</li> - <li><span class="label label-info">Modified</span> In diagrams, the style previously named «Lozenge» is now called «Diamond».</li> + <li><span class="label label-info">Modified</span> In diagrams, the style previously named “Lozenge” is now called “Diamond”.</li> <li><span class="label label-info">Modified</span> In the <em>Open</em> menu on a representation, the menu is computed from the navigation tool’s label instead of its name/id. </li> @@ -1218,7 +1236,7 @@ <code>ComputedStyleDescriptionRegistry.computedStyleDescriptions</code> list. </li> </ul> - <h4 id="Changesinorg.eclipse.sirius.diagram.ui2">Changes in + <h4 id="Changesinorg.eclipse.sirius.diagram.ui3">Changes in <code>org.eclipse.sirius.diagram.ui</code> </h4> <ul> @@ -1646,13 +1664,13 @@ <img border="0" src="images/containerResize-changedBehavior.gif"/> </p> <ul> - <li>The «snap to shapes» is now enabled by default (see + <li>The “snap to shapes” is now enabled by default (see <em>Sirius > Sirius Diagram > Rulers and Grid</em> preference page). This is true only for new diagrams. The existing diagrams are not impacted. </li> - <li>The «Navigate» top-level contextual menu entry with mixed actions for creating new representations and opening existing ones has been changed by two top-level menus: + <li>The “Navigate” top-level contextual menu entry with mixed actions for creating new representations and opening existing ones has been changed by two top-level menus: <ul> - <li>One named «New», which lists only the available actions to create new representations on the selected element.</li> - <li>One named «Open», which lists only the existing representations on the selected element. </li> + <li>One named “New”, which lists only the available actions to create new representations on the selected element.</li> + <li>One named “Open”, which lists only the existing representations on the selected element. </li> </ul> </li> <li>When a shape is resized (no matter the direction), the edge(s) connection location (toward or from this one) is kept. Before that, edges connections moved according to the ratio of the resizing.</li> @@ -1677,19 +1695,19 @@ <li>Distribute centers vertically</li> </ul> </li> - <li>The end user can now remove all bend-points between the two edge ends. This action is available on edge context menu «Remove Bend-points» or by using the shortcut «Ctrl» + «Shift» + «-».</li> + <li>The end user can now remove all bend-points between the two edge ends. This action is available on edge context menu “Remove Bend-points” or by using the shortcut “Ctrl” + “Shift” + “-”.</li> <li>Reconnection of an edge will only now move the minimum necessary bendpoints instead of reseting it to default.</li> <li>A new action has been added to reset the diagram (or container) origin: the diagram (or container) bounds (the rectangle formed by the highest, the leftmost, the lowest and the rightmost children elements) can have a negative origin or can be shifted toward the bottom-right with a blank zone at the top-left. This action aims to move all diagram (or container) elements so that the it retrieves its origin while keeping elements layout.</li> </ul> <h3 id="SpecifierVisibleChanges5">Specifier-Visible Changes</h3> <ul> - <li>The specifier can now choose to hold the edge ends toward the center of the source, target or both. New fields within the «advance» tab of EdgeStyle description have been added to choose for which source or target mappings an edge should be centered. See + <li>The specifier can now choose to hold the edge ends toward the center of the source, target or both. New fields within the “advance” tab of EdgeStyle description have been added to choose for which source or target mappings an edge should be centered. See <a href="specifier/diagrams/Diagrams.html#edges_styles">Edges Styles > Edge Centering</a> in the specifier manual for more details. </li> <li>When creating a new Viewpoint Specification Project using the supplied wizard: - <em>New > Viewpoint Specification Project</em>, the VSM name is now given according to the project name. If the project name is suffixed with «design», the VSM name is provided by the last word before this suffix. Otherwise, the VSM name is given by the last word of the project name. + <em>New > Viewpoint Specification Project</em>, the VSM name is now given according to the project name. If the project name is suffixed with “design”, the VSM name is provided by the last word before this suffix. Otherwise, the VSM name is given by the last word of the project name. </li> - <li>«Lozenge» is replaced by «Diamond» in diagram style.</li> + <li>“Lozenge” is replaced by “Diamond” in diagram style.</li> </ul> <h3 id="APIChanges">API Changes</h3> <h4 id="Changesinorg.eclipse.sirius4">Changes in @@ -1850,7 +1868,7 @@ <code>org.eclipse.sirius.diagram.description.CenteringStyle</code>, to determine whether the edge target or source ends should be centered. </li> </ul> - <h4 id="Changesinorg.eclipse.sirius.diagram.ui3">Changes in + <h4 id="Changesinorg.eclipse.sirius.diagram.ui4">Changes in <code>org.eclipse.sirius.diagram.ui</code> </h4> <ul> diff --git a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile index 067cd5f890..94a97cf0ea 100644 --- a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile +++ b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile @@ -18,6 +18,14 @@ h3. Specifier-Visible Changes h3. Developer-Visible Changes +* <span class="label label-success">Added</span> It is now possible to provide a full customized tab-bar by implementing the @ITabbarContributor@ through the @org.eclipse.sirius.diagram.ui.tabbarContributor@ extension-point. See the developer documentation for more details. + + +h4. Changes in @org.eclipse.sirius.diagram.ui@ + +* <span class="label label-success">Added</span> @org.eclipse.sirius.diagram.ui.tools.api.editor.tabbar.ITabbarContributor@ interface has been added to provide a customized tab-bar for a specific selection. +* <span class="label label-success">Added</span> @org.eclipse.sirius.diagram.ui.tools.api.editor.tabbar.AbstractTabbarContributor@ is an abstract implementation of @ITabbarContributor@ that allows reusing one or several of the default Sirius contribution items. + h4. Changes in @org.eclipse.sirius.ext.emf.ui@ * <span class="label label-info">Modified</span> @org.eclipse.sirius.ext.emf.ui.properties.ExtensiblePropertySource.collector@ field is now in protected visibility to be modifiable and accessible by subclass. diff --git a/plugins/org.eclipse.sirius.doc/doc/developer/extensions-provide_tabbar_extensions.html b/plugins/org.eclipse.sirius.doc/doc/developer/extensions-provide_tabbar_extensions.html index 1552069065..97cee60acb 100644 --- a/plugins/org.eclipse.sirius.doc/doc/developer/extensions-provide_tabbar_extensions.html +++ b/plugins/org.eclipse.sirius.doc/doc/developer/extensions-provide_tabbar_extensions.html @@ -21,7 +21,7 @@ <img border="0" src="images/tabbar02.png"/> </p> <p>Sirius allows to define new operations and to add them at the end of the tab-bar.</p> - <h2 id="Defineatabbarextension">Define a tab-bar extension</h2> + <h2 id="Addanewtabbaritem">Add a new tab-bar item</h2> <p>Sirius asks the workbench’s <code>IMenuService</code> service to populate the tab-bar with provided contributions. This service leans on the <code>org.eclipse.ui.menus</code> extension point. @@ -40,7 +40,7 @@ <em>org.eclipse.sirius.diagram.ui.isDDiagram</em> and <em>org.eclipse.sirius.diagram.ui.isDDiagramElement</em>, but you can define your own domain specific testers. </p> - <h3 id="Provideyourtabbarextensionusingtheorg.eclipse.ui.menusextensionpoint">Provide your tab-bar extension using the + <h3 id="Provideyourtabbaritemsusingtheorg.eclipse.ui.menusextensionpoint">Provide your tab-bar items using the <code>org.eclipse.ui.menus</code> extension point </h3> <p>Please refer to this extension point documentation for more details.</p> @@ -48,7 +48,7 @@ <code>org.eclipse.ui.commands</code> extension point </h3> <p>Please refer to this extension point documentation for more details.</p> - <h2 id="Example">Example</h2> + <h3 id="Example">Example</h3> <p>The following example defines a new push button for the tab-bar. The contribution will only be visible when an element is selected on diagram which correspond to a specific description.</p> <p>You have to add your menu contribution in the plugin.xml file.</p> <p> @@ -108,7 +108,7 @@ <em>activeEditorId</em> and the Sirius Diagram Editor id. </li> <li>it asks a property tester if the active editor should trigger the contribution visibility (see next section for the sample property tester explanation)</li> - <li>it iterates over the selection with a «OR» operator between elements and a false result for empty selection: + <li>it iterates over the selection with a “OR” operator between elements and a false result for empty selection: <ul> <li>it uses the Sirius predefined property tester to check that a selected element is a diagram element.</li> <li>it asks a property tester if the current element should trigger the contribution visibility (see next section for the sample property tester explanation)</li> @@ -186,5 +186,110 @@ public class SampleTestTabbarExtensionActivationPropertyTester extends PropertyT <p> <img border="0" src="images/tabbar_extension_result.png"/> </p> + <h2 id="Contributeafullcustomizedtabbar">Contribute a full customized tab-bar</h2> + <p>Sirius lets the possibility to contribute an entire customized tabbar. To do so, the developer has to contribute an + <code>org.eclipse.sirius.diagram.ui.tools.api.editor.tabbar.ITabbarContributor</code> to the + <code>org.eclipse.sirius.diagram.ui.tabbarContributor</code> extension-point. An abstract implementation of + <code>ITabbarContributor</code> exists: + <code>org.eclipse.sirius.diagram.ui.tools.api.editor.tabbar.AbstractTabbarContributor</code>. This implementation contains protected methods that allows creating one or several contributions of the default Sirius tabbar. + </p> + <p>here is an example of + <code>ITabbarContributor</code> implementation: + </p> + <pre><code>public class TestTabbarExt extends AbstractTabbarContributor { + + private ArrayList<IContributionItem> diagramContributionItems; + + private ArrayList<IContributionItem> diagramElementContributionItems; + + @Override + public List<IContributionItem> getContributionItems(ISelection selection, IDiagramWorkbenchPart part, ToolBarManager manager) { + List<IContributionItem> contributionItems = new ArrayList<IContributionItem>(); + if (selection instanceof IStructuredSelection) { + Object firstElement = ((IStructuredSelection) selection).getFirstElement(); + if (firstElement instanceof AbstractDDiagramEditPart) { + contributionItems = getDiagramContributionItem(part, manager); + } else if (firstElement instanceof IAbstractDiagramNodeEditPart) { + contributionItems = getDiagramElementContributionItem(part, manager); + } + } + return contributionItems; + } + + @Override + public boolean accept(ISelection selection) { + boolean accept = false; + if (selection == null) { + accept = true; + } else if (selection instanceof IStructuredSelection) { + Object firstElement = ((IStructuredSelection) selection).getFirstElement(); + if (firstElement instanceof AbstractDDiagramEditPart || firstElement instanceof IAbstractDiagramNodeEditPart) { + accept = true; + } + } + return accept; + } + + @Override + public List<IContributionItem> getContributionItems(IDiagramWorkbenchPart part, ToolBarManager manager) { + return getDiagramContributionItem(part, manager); + } + + private List<IContributionItem> getDiagramContributionItem(IDiagramWorkbenchPart part, ToolBarManager manager) { + if (diagramContributionItems == null) { + diagramContributionItems = new ArrayList<IContributionItem>(); + diagramContributionItems.add(createArrangeMenuManager(part)); + diagramContributionItems.add(createSelectMenuManager()); + diagramContributionItems.add(createLayerContribution(part, manager)); + diagramContributionItems.add(createZoomInContribution(part)); + diagramContributionItems.add(createZoomOutContribution(part)); + diagramContributionItems.add(createZoomContribution(part)); + diagramContributionItems.add(createSelectPinnedElementsContribution(part)); + diagramContributionItems.add(createSelectHiddenElementsContribution(part)); + diagramContributionItems.add(createFilterContribution(part, manager)); + diagramContributionItems.add(createPasteLayoutContribution(part)); + diagramContributionItems.add(createRefreshContribution()); + diagramContributionItems.add(createSaveAsImageContributionItem()); + diagramContributionItems.add(createLayoutingModeContributionItem(part)); + diagramContributionItems.add(createCopyAppearancePropertiesContribution(part)); + diagramContributionItems.add(createCopyLayoutContribution(part)); + } + return diagramContributionItems; + } + + private List<IContributionItem> getDiagramElementContributionItem(IDiagramWorkbenchPart part, ToolBarManager manager) { + if (diagramElementContributionItems == null) { + diagramElementContributionItems = new ArrayList<IContributionItem>(); + diagramElementContributionItems.add(createArrangeMenuManager(part)); + diagramElementContributionItems.add(createAlignMenuManager()); + diagramElementContributionItems.add(createHideElementLabelContribution(part)); + diagramElementContributionItems.add(createHideElementContribution(part)); + diagramElementContributionItems.add(createDeleteFromDiagramContribution(part)); + diagramElementContributionItems.add(createDeleteFromModelContribution(part)); + IContributionItem pinElementContributionItem = createPinElementContribution(part); + diagramElementContributionItems.add(pinElementContributionItem); + diagramElementContributionItems.add(createUnPinElementContribution(part, pinElementContributionItem)); + diagramElementContributionItems.add(createFontColorContribution(part)); + diagramElementContributionItems.add(createPasteLayoutContribution(part)); + diagramElementContributionItems.add(createBoldFontStyleContribution(part)); + diagramElementContributionItems.add(createItalicFontStyleContribution(part)); + diagramElementContributionItems.add(createFontDialogContribution(part)); + diagramElementContributionItems.add(createFillColorContribution(part)); + diagramElementContributionItems.add(createLineColorPropertyContribution(part)); + diagramElementContributionItems.add(createResetStylePropertyContribution(part)); + diagramElementContributionItems.add(createSetStyleToWorkspaceImageContribution(part)); + diagramElementContributionItems.add(createSaveAsImageContributionItem()); + diagramElementContributionItems.add(createDistributeContribution()); + diagramElementContributionItems.add(createLayoutingModeContributionItem(part)); + diagramElementContributionItems.add(createRouterContribution()); + diagramElementContributionItems.add(createCopyAppearancePropertiesContribution(part)); + diagramElementContributionItems.add(createCopyLayoutContribution(part)); + diagramElementContributionItems.add(createSizeBothContribution(part)); + diagramElementContributionItems.add(createAutoSizeContribution(part)); + } + return diagramElementContributionItems; + } + +</code></pre> </body> </html>
\ No newline at end of file diff --git a/plugins/org.eclipse.sirius.doc/doc/developer/extensions-provide_tabbar_extensions.textile b/plugins/org.eclipse.sirius.doc/doc/developer/extensions-provide_tabbar_extensions.textile index 85054cb2c8..e2363c5884 100644 --- a/plugins/org.eclipse.sirius.doc/doc/developer/extensions-provide_tabbar_extensions.textile +++ b/plugins/org.eclipse.sirius.doc/doc/developer/extensions-provide_tabbar_extensions.textile @@ -12,7 +12,7 @@ The tab-bar contains a different set of actions when at least one element is sel Sirius allows to define new operations and to add them at the end of the tab-bar. -h2. Define a tab-bar extension +h2. Add a new tab-bar item Sirius asks the workbench's @IMenuService@ service to populate the tab-bar with provided contributions. This service leans on the @org.eclipse.ui.menus@ extension point. @@ -23,7 +23,7 @@ You can use the insertion point part of the _locationUri_ to organize your contr You can choose when to make your contribution visible (see the example) with the _visibleWhen_ element and some property testers: show a menu for diagram selection or only on some diagram with a specific description, ... Sirius defines several property testers like _org.eclipse.sirius.diagram.ui.isDDiagram_ and _org.eclipse.sirius.diagram.ui.isDDiagramElement_, but you can define your own domain specific testers. -h3. Provide your tab-bar extension using the @org.eclipse.ui.menus@ extension point +h3. Provide your tab-bar items using the @org.eclipse.ui.menus@ extension point Please refer to this extension point documentation for more details. @@ -31,7 +31,7 @@ h3. Provide your operation using the @org.eclipse.ui.commands@ extension point Please refer to this extension point documentation for more details. -h2. Example +h3. Example The following example defines a new push button for the tab-bar. The contribution will only be visible when an element is selected on diagram which correspond to a specific description. @@ -158,3 +158,106 @@ public class SampleTestTabbarExtensionActivationPropertyTester extends PropertyT p. The a new button is added to the tab-bar only when the selection contains an abstract @EClass@ is selected and the active editor corresponds to the expected description id: !images/tabbar_extension_result.png! + + +h2. Contribute a full customized tab-bar + +Sirius lets the possibility to contribute an entire customized tabbar. To do so, the developer has to contribute an @org.eclipse.sirius.diagram.ui.tools.api.editor.tabbar.ITabbarContributor@ to the @org.eclipse.sirius.diagram.ui.tabbarContributor@ extension-point. An abstract implementation of @ITabbarContributor@ exists: @org.eclipse.sirius.diagram.ui.tools.api.editor.tabbar.AbstractTabbarContributor@. This implementation contains protected methods that allows creating one or several contributions of the default Sirius tabbar. + +here is an example of @ITabbarContributor@ implementation: + +bc.. +public class TestTabbarExt extends AbstractTabbarContributor { + + private ArrayList<IContributionItem> diagramContributionItems; + + private ArrayList<IContributionItem> diagramElementContributionItems; + + @Override + public List<IContributionItem> getContributionItems(ISelection selection, IDiagramWorkbenchPart part, ToolBarManager manager) { + List<IContributionItem> contributionItems = new ArrayList<IContributionItem>(); + if (selection instanceof IStructuredSelection) { + Object firstElement = ((IStructuredSelection) selection).getFirstElement(); + if (firstElement instanceof AbstractDDiagramEditPart) { + contributionItems = getDiagramContributionItem(part, manager); + } else if (firstElement instanceof IAbstractDiagramNodeEditPart) { + contributionItems = getDiagramElementContributionItem(part, manager); + } + } + return contributionItems; + } + + @Override + public boolean accept(ISelection selection) { + boolean accept = false; + if (selection == null) { + accept = true; + } else if (selection instanceof IStructuredSelection) { + Object firstElement = ((IStructuredSelection) selection).getFirstElement(); + if (firstElement instanceof AbstractDDiagramEditPart || firstElement instanceof IAbstractDiagramNodeEditPart) { + accept = true; + } + } + return accept; + } + + @Override + public List<IContributionItem> getContributionItems(IDiagramWorkbenchPart part, ToolBarManager manager) { + return getDiagramContributionItem(part, manager); + } + + private List<IContributionItem> getDiagramContributionItem(IDiagramWorkbenchPart part, ToolBarManager manager) { + if (diagramContributionItems == null) { + diagramContributionItems = new ArrayList<IContributionItem>(); + diagramContributionItems.add(createArrangeMenuManager(part)); + diagramContributionItems.add(createSelectMenuManager()); + diagramContributionItems.add(createLayerContribution(part, manager)); + diagramContributionItems.add(createZoomInContribution(part)); + diagramContributionItems.add(createZoomOutContribution(part)); + diagramContributionItems.add(createZoomContribution(part)); + diagramContributionItems.add(createSelectPinnedElementsContribution(part)); + diagramContributionItems.add(createSelectHiddenElementsContribution(part)); + diagramContributionItems.add(createFilterContribution(part, manager)); + diagramContributionItems.add(createPasteLayoutContribution(part)); + diagramContributionItems.add(createRefreshContribution()); + diagramContributionItems.add(createSaveAsImageContributionItem()); + diagramContributionItems.add(createLayoutingModeContributionItem(part)); + diagramContributionItems.add(createCopyAppearancePropertiesContribution(part)); + diagramContributionItems.add(createCopyLayoutContribution(part)); + } + return diagramContributionItems; + } + + private List<IContributionItem> getDiagramElementContributionItem(IDiagramWorkbenchPart part, ToolBarManager manager) { + if (diagramElementContributionItems == null) { + diagramElementContributionItems = new ArrayList<IContributionItem>(); + diagramElementContributionItems.add(createArrangeMenuManager(part)); + diagramElementContributionItems.add(createAlignMenuManager()); + diagramElementContributionItems.add(createHideElementLabelContribution(part)); + diagramElementContributionItems.add(createHideElementContribution(part)); + diagramElementContributionItems.add(createDeleteFromDiagramContribution(part)); + diagramElementContributionItems.add(createDeleteFromModelContribution(part)); + IContributionItem pinElementContributionItem = createPinElementContribution(part); + diagramElementContributionItems.add(pinElementContributionItem); + diagramElementContributionItems.add(createUnPinElementContribution(part, pinElementContributionItem)); + diagramElementContributionItems.add(createFontColorContribution(part)); + diagramElementContributionItems.add(createPasteLayoutContribution(part)); + diagramElementContributionItems.add(createBoldFontStyleContribution(part)); + diagramElementContributionItems.add(createItalicFontStyleContribution(part)); + diagramElementContributionItems.add(createFontDialogContribution(part)); + diagramElementContributionItems.add(createFillColorContribution(part)); + diagramElementContributionItems.add(createLineColorPropertyContribution(part)); + diagramElementContributionItems.add(createResetStylePropertyContribution(part)); + diagramElementContributionItems.add(createSetStyleToWorkspaceImageContribution(part)); + diagramElementContributionItems.add(createSaveAsImageContributionItem()); + diagramElementContributionItems.add(createDistributeContribution()); + diagramElementContributionItems.add(createLayoutingModeContributionItem(part)); + diagramElementContributionItems.add(createRouterContribution()); + diagramElementContributionItems.add(createCopyAppearancePropertiesContribution(part)); + diagramElementContributionItems.add(createCopyLayoutContribution(part)); + diagramElementContributionItems.add(createSizeBothContribution(part)); + diagramElementContributionItems.add(createAutoSizeContribution(part)); + } + return diagramElementContributionItems; + } + |
