Skip to content

Commit

Permalink
Merge branch 'master' into rtotaro/ft/190/TriQuetrumCommandLanguage
Browse files Browse the repository at this point in the history
Conflicts:
	org.eclipse.triquetrum.workflow.editor/META-INF/MANIFEST.MF
  • Loading branch information
rtotaro committed Jan 25, 2017
2 parents b7332d4 + f7b89c4 commit 24c3e57
Show file tree
Hide file tree
Showing 6 changed files with 227 additions and 54 deletions.
3 changes: 2 additions & 1 deletion org.eclipse.triquetrum.workflow.editor/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,19 @@ When undefined, it is assumed to be 0.
</documentation>
</annotation>
</attribute>
<attribute name="provider" type="string">
<annotation>
<documentation>
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).
</documentation>
<appinfo>
<meta.attribute kind="java" basedOn=":org.eclipse.triquetrum.workflow.editor.palette.PaletteEntryProvider"/>
</appinfo>
</annotation>
</attribute>
</complexType>
</element>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -156,14 +158,8 @@ public ICreateConnectionFeature[] getCreateConnectionFeatures() {

@Override
public ICreateFeature[] getCreateFeatures() {
List<ICreateFeature> 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
Expand Down Expand Up @@ -265,51 +261,25 @@ public IDirectEditingFeature getDirectEditingFeature(IDirectEditingContext conte
return super.getDirectEditingFeature(context);
}

public void handlePaletteEntry(List<ICreateFeature> 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<String, String> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -68,28 +72,28 @@ 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 {
priority = Integer.valueOf("-" + priorityStr);
} 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);
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String, String> 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<String, String> 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;
}
}
Original file line number Diff line number Diff line change
@@ -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();

}

0 comments on commit 24c3e57

Please sign in to comment.