diff --git a/org.eclipse.triquetrum.workflow.editor/META-INF/MANIFEST.MF b/org.eclipse.triquetrum.workflow.editor/META-INF/MANIFEST.MF index 9319cc1f..61f2bd40 100644 --- a/org.eclipse.triquetrum.workflow.editor/META-INF/MANIFEST.MF +++ b/org.eclipse.triquetrum.workflow.editor/META-INF/MANIFEST.MF @@ -111,4 +111,5 @@ Service-Component: OSGI-INF/colorRendererService.xml,OSGI-INF/attributesRenderer OSGI-INF/ModelBuilderService.xml Bundle-ActivationPolicy: lazy Export-Package: org.eclipse.triquetrum.workflow.editor, - org.eclipse.triquetrum.workflow.editor.features + org.eclipse.triquetrum.workflow.editor.features, + org.eclipse.triquetrum.workflow.editor.palette.spi diff --git a/org.eclipse.triquetrum.workflow.editor/schema/org.eclipse.triquetrum.workflow.editor.paletteContribution.exsd b/org.eclipse.triquetrum.workflow.editor/schema/org.eclipse.triquetrum.workflow.editor.paletteContribution.exsd index e4b079d3..458de0d0 100644 --- a/org.eclipse.triquetrum.workflow.editor/schema/org.eclipse.triquetrum.workflow.editor.paletteContribution.exsd +++ b/org.eclipse.triquetrum.workflow.editor/schema/org.eclipse.triquetrum.workflow.editor.paletteContribution.exsd @@ -179,6 +179,19 @@ When undefined, it is assumed to be 0. + + + + An optional provider for palette entries in this group. + +This can be used to dynamically populate a palette group based on some external resources or other logic. +The obtained entries will be added next to the statically defined entries in plugin.xml files (if any). + + + + + + diff --git a/org.eclipse.triquetrum.workflow.editor/src/main/java/org/eclipse/triquetrum/workflow/editor/TriqFeatureProvider.java b/org.eclipse.triquetrum.workflow.editor/src/main/java/org/eclipse/triquetrum/workflow/editor/TriqFeatureProvider.java index 6e5456d9..32479c27 100644 --- a/org.eclipse.triquetrum.workflow.editor/src/main/java/org/eclipse/triquetrum/workflow/editor/TriqFeatureProvider.java +++ b/org.eclipse.triquetrum.workflow.editor/src/main/java/org/eclipse/triquetrum/workflow/editor/TriqFeatureProvider.java @@ -10,16 +10,18 @@ *******************************************************************************/ package org.eclipse.triquetrum.workflow.editor; -import java.util.ArrayList; +import static org.eclipse.triquetrum.workflow.editor.palette.spi.PaletteConfigurationElement.CLASS; +import static org.eclipse.triquetrum.workflow.editor.palette.spi.PaletteConfigurationElement.DISPLAY_NAME; +import static org.eclipse.triquetrum.workflow.editor.palette.spi.PaletteConfigurationElement.ICON; +import static org.eclipse.triquetrum.workflow.editor.palette.spi.PaletteConfigurationElement.ICON_TYPE; +import static org.eclipse.triquetrum.workflow.editor.palette.spi.PaletteConfigurationElement.PROPERTY; +import static org.eclipse.triquetrum.workflow.editor.palette.spi.PaletteConfigurationElement.TYPE; + import java.util.HashMap; -import java.util.List; import java.util.Map; import org.apache.commons.lang.StringUtils; import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IExtension; -import org.eclipse.core.runtime.IExtensionPoint; -import org.eclipse.core.runtime.Platform; import org.eclipse.emf.common.util.URI; import org.eclipse.graphiti.dt.IDiagramTypeProvider; import org.eclipse.graphiti.features.IAddFeature; @@ -76,8 +78,8 @@ import org.eclipse.triquetrum.workflow.editor.features.ModelElementResizeFeature; import org.eclipse.triquetrum.workflow.editor.features.ParameterAddFeature; import org.eclipse.triquetrum.workflow.editor.features.ParameterUpdateFeature; -import org.eclipse.triquetrum.workflow.editor.features.PortUpdateFeature; import org.eclipse.triquetrum.workflow.editor.features.PortAddFeature; +import org.eclipse.triquetrum.workflow.editor.features.PortUpdateFeature; import org.eclipse.triquetrum.workflow.editor.features.VertexAddFeature; import org.eclipse.triquetrum.workflow.editor.util.EditorUtils; import org.eclipse.triquetrum.workflow.model.Actor; @@ -156,14 +158,8 @@ public ICreateConnectionFeature[] getCreateConnectionFeatures() { @Override public ICreateFeature[] getCreateFeatures() { - List results = new ArrayList<>(); - IExtensionPoint extPoint = Platform.getExtensionRegistry().getExtensionPoint(PALETTE_CONTRIBUTION_EXTENSION_ID); - for (IExtension ext : extPoint.getExtensions()) { - for (IConfigurationElement cfgElem : ext.getConfigurationElements()) { - handlePaletteEntry(results, null, cfgElem); - } - } - return results.toArray(new ICreateFeature[0]); + // these are all managed via the palette construction + return new ICreateFeature[0]; } @Override @@ -265,51 +261,25 @@ public IDirectEditingFeature getDirectEditingFeature(IDirectEditingContext conte return super.getDirectEditingFeature(context); } - public void handlePaletteEntry(List results, IConfigurationElement parentGroupElem, IConfigurationElement cfgElem) { - switch (cfgElem.getName()) { - case "entry": { - ModelElementCreateFeature mecf = buildCreateFeature(parentGroupElem, cfgElem); - if (mecf != null) { - results.add(mecf); - } - break; - } - case "group": { - String label = cfgElem.getAttribute("displayName"); - // this should enforce a single level of groups, i.e. children of subgroups are traversed and added, - // but they all get linked to their "top-level" parent group. - IConfigurationElement groupElement = parentGroupElem; - if (parentGroupElem == null) { - groupElement = cfgElem; - // no parent, so store this group as a root group - rootgroupsByName.put(label, cfgElem); - } - for (IConfigurationElement child : cfgElem.getChildren()) { - handlePaletteEntry(results, groupElement, child); - } - } - } - } - public ModelElementCreateFeature buildCreateFeature(IConfigurationElement parentGroupElem, IConfigurationElement cfgElem) { ModelElementCreateFeature mecf = null; - String group = parentGroupElem != null ? parentGroupElem.getAttribute("displayName") : null; - String label = cfgElem.getAttribute("displayName"); - String clazz = cfgElem.getAttribute("class"); + String group = parentGroupElem != null ? parentGroupElem.getAttribute(DISPLAY_NAME) : null; + String label = cfgElem.getAttribute(DISPLAY_NAME); + String clazz = cfgElem.getAttribute(CLASS); - String iconResource = cfgElem.getAttribute("icon"); + String iconResource = cfgElem.getAttribute(ICON); iconResource = !StringUtils.isBlank(iconResource) ? iconResource : DEFAULT_ACTOR_IMG; - String iconType = cfgElem.getAttribute("iconType"); + String iconType = cfgElem.getAttribute(ICON_TYPE); iconType = StringUtils.isBlank(iconType) ? ICONTYPE_IMG : iconType; - String categoryTypeStr = cfgElem.getAttribute("type"); + String categoryTypeStr = cfgElem.getAttribute(TYPE); try { BoCategory category = BoCategory.valueOf(categoryTypeStr); // look for (optional) attributes Map properties = new HashMap<>(); for (IConfigurationElement child : cfgElem.getChildren()) { - if ("property".equals(child.getName())) { + if (PROPERTY.equals(child.getName())) { String name = child.getAttribute("name"); String value = child.getAttribute("value"); properties.put(name, value); diff --git a/org.eclipse.triquetrum.workflow.editor/src/main/java/org/eclipse/triquetrum/workflow/editor/palette/TriqPaletteBehavior.java b/org.eclipse.triquetrum.workflow.editor/src/main/java/org/eclipse/triquetrum/workflow/editor/palette/TriqPaletteBehavior.java index 66fa18fd..8d6fcbe2 100644 --- a/org.eclipse.triquetrum.workflow.editor/src/main/java/org/eclipse/triquetrum/workflow/editor/palette/TriqPaletteBehavior.java +++ b/org.eclipse.triquetrum.workflow.editor/src/main/java/org/eclipse/triquetrum/workflow/editor/palette/TriqPaletteBehavior.java @@ -13,7 +13,10 @@ import java.util.Collections; import java.util.Comparator; +import static org.eclipse.triquetrum.workflow.editor.palette.spi.PaletteConfigurationElement.*; + import org.apache.commons.lang.StringUtils; +import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IExtension; import org.eclipse.core.runtime.IExtensionPoint; @@ -30,6 +33,7 @@ import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.triquetrum.workflow.editor.TriqDiagramTypeProvider; import org.eclipse.triquetrum.workflow.editor.TriqFeatureProvider; +import org.eclipse.triquetrum.workflow.editor.palette.spi.PaletteEntryProvider; import org.eclipse.triquetrum.workflow.editor.palette.ui.PaletteTreeViewerProvider; import org.eclipse.ui.plugin.AbstractUIPlugin; @@ -68,7 +72,7 @@ protected PaletteRoot createPaletteRoot() { @SuppressWarnings("unchecked") public synchronized void handlePaletteEntry(PaletteContainer parent, IConfigurationElement parentGroupElem, IConfigurationElement cfgElem) { - String priorityStr = cfgElem.getAttribute("priority"); + String priorityStr = cfgElem.getAttribute(PRIORITY); priorityStr = StringUtils.isBlank(priorityStr) ? "0" : priorityStr; Integer priority = 0; try { @@ -76,20 +80,20 @@ public synchronized void handlePaletteEntry(PaletteContainer parent, IConfigurat } catch (NumberFormatException e) { // just ignore this and take the default value 0 } - String label = cfgElem.getAttribute("displayName"); - String iconType = cfgElem.getAttribute("iconType"); + String label = cfgElem.getAttribute(DISPLAY_NAME); + String iconType = cfgElem.getAttribute(ICON_TYPE); iconType = StringUtils.isBlank(iconType) ? TriqFeatureProvider.ICONTYPE_IMG : iconType; - String iconResource = cfgElem.getAttribute("icon"); + String iconResource = cfgElem.getAttribute(ICON); iconResource = !StringUtils.isBlank(iconResource) ? iconResource : null; iconResource = TriqFeatureProvider.ICONTYPE_IMG.equalsIgnoreCase(iconType) ? iconResource : null; ImageDescriptor imgDescriptor = null; if (iconResource != null) { getDiagramTypeProvider().getImageProvider().myAddImageFilePath(cfgElem.getContributor().getName(), iconResource, iconResource); - imgDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin(cfgElem.getDeclaringExtension().getContributor().getName(), iconResource); + imgDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin(cfgElem.getContributor().getName(), iconResource); } switch (cfgElem.getName()) { case "entry": { - String clazz = cfgElem.getAttribute("class"); + String clazz = cfgElem.getAttribute(CLASS); ICreateFeature createFeature = getFeatureProvider().buildCreateFeature(parentGroupElem, cfgElem); TriqPaletteRoot.DefaultCreationFactory cf = new TriqPaletteRoot.DefaultCreationFactory(createFeature, ICreateFeature.class); CombinedTemplateCreationEntry pe = new CombinedTemplateCreationEntry(label, clazz, cf, cf, imgDescriptor, imgDescriptor); @@ -125,6 +129,23 @@ public synchronized void handlePaletteEntry(PaletteContainer parent, IConfigurat for (IConfigurationElement child : cfgElem.getChildren()) { handlePaletteEntry(pg, cfgElem, child); } + + String providerClazz = cfgElem.getAttribute(PROVIDER); + if(providerClazz!=null) { + try { + PaletteEntryProvider pep = (PaletteEntryProvider) cfgElem.createExecutableExtension(PROVIDER); + for (IConfigurationElement child : pep.getPaletteEntries()) { + handlePaletteEntry(pg, cfgElem, child); + } + } catch (CoreException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } } Collections.sort(parent.getChildren(), new PaletteEntryComparator()); diff --git a/org.eclipse.triquetrum.workflow.editor/src/main/java/org/eclipse/triquetrum/workflow/editor/palette/spi/PaletteConfigurationElement.java b/org.eclipse.triquetrum.workflow.editor/src/main/java/org/eclipse/triquetrum/workflow/editor/palette/spi/PaletteConfigurationElement.java new file mode 100644 index 00000000..5427706f --- /dev/null +++ b/org.eclipse.triquetrum.workflow.editor/src/main/java/org/eclipse/triquetrum/workflow/editor/palette/spi/PaletteConfigurationElement.java @@ -0,0 +1,145 @@ +/******************************************************************************* + * Copyright (c) 2016 iSencia Belgium NV. + * 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: + * Erwin De Ley - initial API and implementation and/or initial documentation + *******************************************************************************/ +package org.eclipse.triquetrum.workflow.editor.palette.spi; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.core.runtime.ContributorFactorySimple; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IContributor; +import org.eclipse.core.runtime.IExtension; +import org.eclipse.core.runtime.InvalidRegistryObjectException; + +/** + * + * TODO : finalize contributor setup in combination with usage of SVG or Ptolemy actor icons (see TriqFeatureProvider.buildCreateFeature()). + */ +public class PaletteConfigurationElement implements IConfigurationElement { + + public static final String CLASS = "class"; + public static final String DISPLAY_NAME = "displayName"; + public static final String ICON = "icon"; + public static final String ICON_TYPE = "iconType"; + public static final String PRIORITY = "priority"; + public static final String PROPERTY = "property"; + public static final String PROVIDER = "provider"; + public static final String TYPE = "type"; + + private final String name; + private IContributor contributor; + private final Map attributes = new HashMap<>(); + + /** + * Constructor for manually creating a PaletteConfigurationElement. + * + * This can be used in {@link PaletteEntryProvider} implementations. + * + * @param name + * @param contributorName + * @param attributes + */ + public PaletteConfigurationElement(String name, String contributorName, Map attributes) { + this.name = name; + if(contributorName!=null) { + contributor = ContributorFactorySimple.createContributor(contributorName); + } + if (attributes != null) { + this.attributes.putAll(attributes); + } + } + + @Override + public Object createExecutableExtension(String propertyName) throws CoreException { + throw new UnsupportedOperationException(); + } + + @Override + public String getAttribute(String name) throws InvalidRegistryObjectException { + return attributes.get(name); + } + + @Override + public String getAttribute(String attrName, String locale) throws InvalidRegistryObjectException { + throw new UnsupportedOperationException(); + } + + @Override + public String getAttributeAsIs(String name) throws InvalidRegistryObjectException { + return attributes.get(name); + } + + @Override + public String[] getAttributeNames() throws InvalidRegistryObjectException { + return attributes.keySet().toArray(new String[0]); + } + + @Override + public IConfigurationElement[] getChildren() throws InvalidRegistryObjectException { + return new IConfigurationElement[0]; + } + + @Override + public IConfigurationElement[] getChildren(String name) throws InvalidRegistryObjectException { + return new IConfigurationElement[0]; + } + + @Override + public IExtension getDeclaringExtension() throws InvalidRegistryObjectException { + throw new UnsupportedOperationException(); + } + + @Override + public String getName() throws InvalidRegistryObjectException { + return name; + } + + @Override + public Object getParent() throws InvalidRegistryObjectException { + throw new UnsupportedOperationException(); + } + + @Override + public String getValue() throws InvalidRegistryObjectException { + throw new UnsupportedOperationException(); + } + + @Override + public String getValue(String locale) throws InvalidRegistryObjectException { + throw new UnsupportedOperationException(); + } + + @Override + public String getValueAsIs() throws InvalidRegistryObjectException { + throw new UnsupportedOperationException(); + } + + @Override + public String getNamespace() throws InvalidRegistryObjectException { + throw new UnsupportedOperationException(); + } + + @Override + public String getNamespaceIdentifier() throws InvalidRegistryObjectException { + throw new UnsupportedOperationException(); + } + + @Override + public IContributor getContributor() throws InvalidRegistryObjectException { + return contributor; + } + + @Override + public boolean isValid() { + return true; + } +} diff --git a/org.eclipse.triquetrum.workflow.editor/src/main/java/org/eclipse/triquetrum/workflow/editor/palette/spi/PaletteEntryProvider.java b/org.eclipse.triquetrum.workflow.editor/src/main/java/org/eclipse/triquetrum/workflow/editor/palette/spi/PaletteEntryProvider.java new file mode 100644 index 00000000..28392716 --- /dev/null +++ b/org.eclipse.triquetrum.workflow.editor/src/main/java/org/eclipse/triquetrum/workflow/editor/palette/spi/PaletteEntryProvider.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2016 iSencia Belgium NV. + * 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: + * Erwin De Ley - initial API and implementation and/or initial documentation + *******************************************************************************/ +package org.eclipse.triquetrum.workflow.editor.palette.spi; + +import org.eclipse.core.runtime.IConfigurationElement; + +public interface PaletteEntryProvider { + + /** + * + * @return the palette entries from this provider, as configuration elements + */ + IConfigurationElement[] getPaletteEntries(); + +}