Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoratikhomirov2006-05-23 21:09:42 +0000
committeratikhomirov2006-05-23 21:09:42 +0000
commit75be767d67889534d4a7244730345759cd9a0cca (patch)
tree205af0dbb8b47be3c840db8b7b3e18261f8d5c00 /plugins/org.eclipse.gmf.graphdef.codegen/src
parentc770635d5e748877687c9c6347dc28162ea5af29 (diff)
downloadorg.eclipse.gmf-tooling-75be767d67889534d4a7244730345759cd9a0cca.tar.gz
org.eclipse.gmf-tooling-75be767d67889534d4a7244730345759cd9a0cca.tar.xz
org.eclipse.gmf-tooling-75be767d67889534d4a7244730345759cd9a0cca.zip
#140887 Remove Child interface from GMFGraph.
Although the need to reference child figures persist, thus FigureHandle was introduced, to allow diagramElements to reference either *generateable* figures (Figure subclasses) or *just-use* figures (like CustomFigure and FigureAccessor). Refactoring performed with #131365 "Mirror GMFGraph model when generating standalone figure plugin" in mind
Diffstat (limited to 'plugins/org.eclipse.gmf.graphdef.codegen/src')
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/FigureGenerator.java11
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/StandaloneGenerator.java95
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/CanvasProcessor.java141
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/DiagramElementsCopier.java52
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/GalleryMirrorProcessor.java88
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/GalleryProcessor.java67
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/StandaloneGalleryConverter.java122
7 files changed, 379 insertions, 197 deletions
diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/FigureGenerator.java b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/FigureGenerator.java
index 9bc208004..9d7e34145 100644
--- a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/FigureGenerator.java
+++ b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/FigureGenerator.java
@@ -170,12 +170,12 @@ public class FigureGenerator implements TextEmitter {
public String generate(IProgressMonitor monitor, Object[] arguments) throws InterruptedException, InvocationTargetException, UnexpectedBehaviourException {
if (arguments == null || arguments.length != 2 || false == arguments[0] instanceof Figure || false == arguments[1] instanceof ImportAssistant) {
- throw new UnexpectedBehaviourException("Single Figure expected as argument: " + arguments);
+ throw new UnexpectedBehaviourException("(Figure, ImportAssistant) expected as arguments, not " + arguments);
}
return go((Figure) arguments[0], (ImportAssistant) arguments[1]);
}
- public String go(Figure fig, ImportAssistant importManager) {
+ public String go(Figure fig, ImportAssistant importManager/*, Feedback feedback*/) {
String res = null;
myTopDispatcher.setImportManager(importManager);
myInnerDispatcher.setImportManager(importManager);
@@ -186,4 +186,11 @@ public class FigureGenerator implements TextEmitter {
}
return res;
}
+/*
+ public static class Feedback {
+ void registerChildAccessor(Figure parent, Figure child, String getterName, String setterName) {
+ // do nothing
+ }
+ }
+*/
}
diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/StandaloneGenerator.java b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/StandaloneGenerator.java
index e866c134f..190b8525e 100644
--- a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/StandaloneGenerator.java
+++ b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/StandaloneGenerator.java
@@ -12,20 +12,12 @@
package org.eclipse.gmf.graphdef.codegen;
import java.net.URL;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.HashSet;
-import java.util.IdentityHashMap;
-import java.util.Iterator;
-import java.util.Map;
import org.eclipse.core.runtime.Path;
import org.eclipse.emf.codegen.util.CodeGenUtil;
import org.eclipse.gmf.common.UnexpectedBehaviourException;
import org.eclipse.gmf.common.codegen.ImportAssistant;
import org.eclipse.gmf.gmfgraph.Figure;
-import org.eclipse.gmf.gmfgraph.FigureGallery;
import org.eclipse.gmf.gmfgraph.util.FigureQualifiedNameSwitch;
import org.eclipse.gmf.internal.common.codegen.DelegateImportManager;
import org.eclipse.gmf.internal.common.codegen.GeneratorBase;
@@ -33,19 +25,12 @@ import org.eclipse.gmf.internal.common.codegen.ImportUtil;
public class StandaloneGenerator extends GeneratorBase {
private final Config myArgs;
- private final FigureGallery[] myInput;
private final FigureGenerator myFigureGenerator;
private DelegateImportManager myMapModeImportHack;
private final StandaloneEmitters myAuxiliaryGenerators;
private boolean mySkipPluginStructire;
private final FigureQualifiedNameSwitch myFigureNameSwitch;
- private final GenerationInfoImpl myGenerationInfo;
-
- public interface GenerationInfo {
- public Config getConfig();
- public Enumeration/*<Figure>*/ getProcessedFigures();
- public String getGeneratedClassFQN(Figure figure);
- }
+ private Processor myProcessor;
public interface Config {
public String getPluginID();
@@ -117,14 +102,23 @@ public class StandaloneGenerator extends GeneratorBase {
}
}
- public StandaloneGenerator(FigureGallery input, Config config, FigureQualifiedNameSwitch fqnSwitch) {
- this(new FigureGallery[] {input}, config, fqnSwitch);
+ public static abstract class Processor {
+ public abstract void go(ProcessorCallback callback) throws InterruptedException ;
+
+ public String[] getRequiredBundles(FigureQualifiedNameSwitch fqnSwitch) {
+ return new String[0];
+ }
}
- public StandaloneGenerator(FigureGallery[] input, Config config, FigureQualifiedNameSwitch fqnSwitch) {
- assert input != null && config != null && fqnSwitch != null && !Arrays.asList(input).contains(null);
+ public interface ProcessorCallback {
+ public String visitFigure(Figure f) throws InterruptedException;
+ }
+
+
+ public StandaloneGenerator(Processor p, Config config, FigureQualifiedNameSwitch fqnSwitch) {
+ assert p != null && config != null && fqnSwitch != null;
myArgs = config;
- myInput = input;
+ myProcessor = p;
myFigureNameSwitch = fqnSwitch;
String pluginActivatorFQN = composePluginActivatorClassFQN(config);
MapModeCodeGenStrategy strategy;
@@ -137,11 +131,6 @@ public class StandaloneGenerator extends GeneratorBase {
myFigureGenerator = new FigureGenerator(fqnSwitch, strategy);
myAuxiliaryGenerators = new StandaloneEmitters();
- myGenerationInfo = new GenerationInfoImpl(myArgs);
- }
-
- public GenerationInfo getGenerationInfo() {
- return myGenerationInfo;
}
/**
@@ -181,39 +170,26 @@ public class StandaloneGenerator extends GeneratorBase {
private void generatePluginStructure() throws UnexpectedBehaviourException, InterruptedException {
doGenerateFile(myAuxiliaryGenerators.getBuildPropertiesEmitter(), new Path("build.properties"), new Object[] { myArgs });
- doGenerateFile(myAuxiliaryGenerators.getManifestMFEmitter(), new Path("META-INF/MANIFEST.MF"), new Object[] { new Object[] { myArgs, getRequiredBundles() } });
+ doGenerateFile(myAuxiliaryGenerators.getManifestMFEmitter(), new Path("META-INF/MANIFEST.MF"), new Object[] { new Object[] { myArgs, myProcessor.getRequiredBundles(myFigureNameSwitch) } });
doGenerateFile(myAuxiliaryGenerators.getPluginPropertiesEmitter(), new Path("plugin.properties"), new Object[] { myArgs });
}
- private String[] getRequiredBundles() {
- HashSet rv = new HashSet();
- for (int i = 0; i < myInput.length; i++) {
- if (myInput[i].getImplementationBundle() != null && myInput[i].getImplementationBundle().trim().length() > 0) {
- rv.add(myInput[i].getImplementationBundle());
- }
- String[] additional = myFigureNameSwitch.getDependencies(myInput[i]);
- rv.addAll(Arrays.asList(additional));
- }
- return (String[]) rv.toArray(new String[rv.size()]);
- }
-
private void generateTopLevelFigures() throws InterruptedException {
- for (int i = 0; i < myInput.length; i++) {
- for (Iterator it = myInput[i].getFigures().iterator(); it.hasNext();){
- Figure next = (Figure) it.next();
- visitFigure(next);
+ myProcessor.go(new ProcessorCallback() {
+ public String visitFigure(Figure f) throws InterruptedException {
+ return StandaloneGenerator.this.visitFigure(f);
}
- }
+ });
}
- private void visitFigure(Figure figure) throws InterruptedException {
+ private String visitFigure(Figure figure) throws InterruptedException {
final ImportAssistant importAssistant = new ImportUtil(getPackageName(), CodeGenUtil.validJavaIdentifier(figure.getName()));
Object[] args = new Object[] { figure, importAssistant };
if (myMapModeImportHack != null) {
myMapModeImportHack.setDelegate(importAssistant);
}
doGenerateJavaClass(myFigureGenerator, getPackageName(), importAssistant.getCompilationUnitName(), args);
- myGenerationInfo.registerFQN(figure, composeFQN(getPackageName(), importAssistant.getCompilationUnitName()));
+ return composeFQN(getPackageName(), importAssistant.getCompilationUnitName());
}
private String getPackageName(){
@@ -229,31 +205,4 @@ public class StandaloneGenerator extends GeneratorBase {
private static String composeFQN(String packageName, String className){
return packageName == null || "".equals(packageName) ? className : packageName + "." + className;
}
-
- private static class GenerationInfoImpl implements GenerationInfo {
- private final Map myFigure2FQN = new IdentityHashMap();
- private final Config myConfig;
-
- public GenerationInfoImpl(Config config){
- myConfig = config;
- }
-
- public Config getConfig() {
- return myConfig;
- }
-
- public void registerFQN(Figure figure, String fqn){
- myFigure2FQN.put(figure, fqn);
- }
-
- public String getGeneratedClassFQN(Figure figure) {
- return (String)myFigure2FQN.get(figure);
- }
-
- public Enumeration getProcessedFigures() {
- return Collections.enumeration(myFigure2FQN.keySet());
- }
-
- }
-
}
diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/CanvasProcessor.java b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/CanvasProcessor.java
new file mode 100644
index 000000000..9a3a3f5f1
--- /dev/null
+++ b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/CanvasProcessor.java
@@ -0,0 +1,141 @@
+/*
+ * Copyright (c) 2006 Borland Software Corporation
+ *
+ * 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:
+ * Artem Tikhomirov (Borland) - initial API and implementation
+ */
+package org.eclipse.gmf.internal.graphdef.codegen;
+
+import java.util.Iterator;
+
+import org.eclipse.emf.codegen.util.CodeGenUtil;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.gmf.gmfgraph.Canvas;
+import org.eclipse.gmf.gmfgraph.Compartment;
+import org.eclipse.gmf.gmfgraph.Connection;
+import org.eclipse.gmf.gmfgraph.CustomFigure;
+import org.eclipse.gmf.gmfgraph.DiagramLabel;
+import org.eclipse.gmf.gmfgraph.Figure;
+import org.eclipse.gmf.gmfgraph.FigureAccessor;
+import org.eclipse.gmf.gmfgraph.FigureGallery;
+import org.eclipse.gmf.gmfgraph.GMFGraphFactory;
+import org.eclipse.gmf.gmfgraph.Node;
+import org.eclipse.gmf.graphdef.codegen.StandaloneGenerator.Processor;
+import org.eclipse.gmf.graphdef.codegen.StandaloneGenerator.ProcessorCallback;
+
+public class CanvasProcessor extends Processor {
+ private final DiagramElementsCopier myElementCopier;
+ private ProcessorCallback myCallback;
+ final Canvas myInput;
+ private Canvas myOutcome;
+ private FigureGallery myOutcomeGallery;
+
+ public CanvasProcessor(Canvas input) {
+ assert input != null;
+ myInput = input;
+ myElementCopier = new DiagramElementsCopier();
+ }
+
+ public Canvas getOutcome() {
+ return myOutcome;
+ }
+
+ public void go(ProcessorCallback callback) throws InterruptedException {
+ myCallback = callback;
+ myOutcomeGallery = GMFGraphFactory.eINSTANCE.createFigureGallery();
+ myOutcomeGallery.setName(myInput.getFigures().size() == 1 ? ((FigureGallery) myInput.getFigures().get(0)).getName() : "GeneratedGallery");
+ handleNodes();
+ handleLinks();
+ handleCompartments();
+ handleLabels();
+ // can't use
+ // = (Canvas) diagramElementCopier.copy(myInput);
+ // here because Copier.copy doesn't respect already copied elements
+ myOutcome = GMFGraphFactory.eINSTANCE.createCanvas();
+ myOutcome.setName(myInput.getName());
+ myOutcome.getFigures().add(myOutcomeGallery);
+
+ myOutcome.getCompartments().addAll(myElementCopier.copyAll(myInput.getCompartments()));
+ myOutcome.getLabels().addAll(myElementCopier.copyAll(myInput.getLabels()));
+ myOutcome.getNodes().addAll(myElementCopier.copyAll(myInput.getNodes()));
+ myOutcome.getConnections().addAll(myElementCopier.copyAll(myInput.getConnections()));
+
+ if (!myOutcome.eContents().isEmpty()) {
+ myElementCopier.copyReferences();
+ }
+ myCallback = null;
+ }
+
+ private void handleNodes() throws InterruptedException {
+ for (Iterator it = myInput.getNodes().iterator(); it.hasNext();) {
+ Node next = (Node) it.next();
+ handleFigure(next.getNodeFigure());
+ }
+ }
+
+ private void handleLinks() throws InterruptedException {
+ for (Iterator it = myInput.getConnections().iterator(); it.hasNext();) {
+ Connection next = (Connection) it.next();
+ handleFigure(next.getConnectionFigure());
+ }
+ }
+
+ private void handleCompartments() throws InterruptedException {
+ for (Iterator it = myInput.getCompartments().iterator(); it.hasNext();) {
+ Compartment next = (Compartment) it.next();
+ if (next.getFigure() instanceof Figure) {
+ handleFigure((Figure) next.getFigure());
+ } else {
+ throw new IllegalStateException("Don't support accessors for compartments yet");
+ }
+ }
+ }
+
+ private void handleLabels() throws InterruptedException {
+ for (Iterator it = myInput.getLabels().iterator(); it.hasNext();) {
+ DiagramLabel next = (DiagramLabel) it.next();
+ if (next.getFigure() instanceof FigureAccessor) {
+ assert myElementCopier.containsKey(next.getFigure()) : "Should be copied as part of previously referenced CustomFigure";
+ } else {
+ assert next.getFigure() instanceof Figure;
+ Figure f = (Figure) next.getFigure();
+ if (isInsideProcessedFigure(f)) {
+ // obviously, fact we got here means f is !getReferencingElements().isEmpty()
+ // feedback.findAccessorFor(f)
+ FigureAccessor accessor = GMFGraphFactory.eINSTANCE.createFigureAccessor();
+ accessor.setAccessor("get" + CodeGenUtil.capName(f.getName()));
+ myElementCopier.put(f, accessor);
+ } else {
+ handleFigure(f);
+ }
+
+ }
+ }
+ }
+
+ private boolean isInsideProcessedFigure(Figure f) {
+ return EcoreUtil.isAncestor(myElementCopier.keySet(), f);
+ }
+
+ private void handleFigure(Figure figure) throws InterruptedException {
+ if (figure instanceof CustomFigure /* && isPlainBareFigureHandle()*/) {
+ myElementCopier.copy(figure);
+ } else {
+ String fqn = myCallback.visitFigure(figure);
+ myElementCopier.registerSubstitution(figure, createCustomFigure(figure, fqn));
+ }
+ }
+
+ private CustomFigure createCustomFigure(Figure original, String fqn) {
+ CustomFigure cf = DiagramElementsCopier.createCustomFigure(original);
+ cf.setName(original.getName());
+ cf.setQualifiedClassName(fqn);
+ myOutcomeGallery.getFigures().add(cf);
+ return cf;
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/DiagramElementsCopier.java b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/DiagramElementsCopier.java
new file mode 100644
index 000000000..9e857d7c4
--- /dev/null
+++ b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/DiagramElementsCopier.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2006 Borland Software Corporation
+ *
+ * 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:
+ * Artem Tikhomirov (Borland) - initial API and implementation
+ */
+package org.eclipse.gmf.internal.graphdef.codegen;
+
+import java.util.HashSet;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.gmf.gmfgraph.ConnectionFigure;
+import org.eclipse.gmf.gmfgraph.CustomFigure;
+import org.eclipse.gmf.gmfgraph.DecorationFigure;
+import org.eclipse.gmf.gmfgraph.Figure;
+import org.eclipse.gmf.gmfgraph.GMFGraphFactory;
+
+class DiagramElementsCopier extends EcoreUtil.Copier {
+ private final HashSet myOriginalFigures = new HashSet();
+
+ public void registerSubstitution(Figure original, CustomFigure substituted){
+ put(original, substituted);
+ myOriginalFigures.add(original);
+ }
+
+ protected void copyReference(EReference eReference, EObject eObject, EObject copyEObject) {
+ if (EcoreUtil.isAncestor(myOriginalFigures, eObject)){
+ //no such features in the CustomFigure's
+ return;
+ }
+ super.copyReference(eReference, eObject, copyEObject);
+ }
+
+ static CustomFigure createCustomFigure(Figure original){
+ GMFGraphFactory factory = GMFGraphFactory.eINSTANCE;
+ if (original instanceof DecorationFigure){
+ return factory.createCustomDecoration();
+ }
+ if (original instanceof ConnectionFigure){
+ return factory.createCustomConnection();
+ }
+ return factory.createCustomFigure();
+ }
+
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/GalleryMirrorProcessor.java b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/GalleryMirrorProcessor.java
new file mode 100644
index 000000000..6730f8864
--- /dev/null
+++ b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/GalleryMirrorProcessor.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2006 Borland Software Corporation
+ *
+ * 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:
+ * Artem Tikhomirov (Borland) - initial API and implementation
+ */
+package org.eclipse.gmf.internal.graphdef.codegen;
+
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.IdentityHashMap;
+import java.util.Map;
+
+import org.eclipse.gmf.gmfgraph.CustomFigure;
+import org.eclipse.gmf.gmfgraph.Figure;
+import org.eclipse.gmf.gmfgraph.FigureGallery;
+import org.eclipse.gmf.gmfgraph.GMFGraphFactory;
+import org.eclipse.gmf.graphdef.codegen.StandaloneGenerator.Config;
+
+/**
+ * In addition to {@link GalleryProcessor} activities, collects names of transformed figures and
+ * allows to create {@link FigureGallery} full of them.
+ * @author artem
+ */
+public class GalleryMirrorProcessor extends GalleryProcessor {
+ private final GenerationInfoImpl myGenerationInfo;
+
+ public GalleryMirrorProcessor(FigureGallery[] input) {
+ super(input);
+ myGenerationInfo = new GenerationInfoImpl();
+ }
+
+ public FigureGallery convertFigureGallery(Config config){
+ FigureGallery result = GMFGraphFactory.eINSTANCE.createFigureGallery();
+ String generatedBundle = config.getPluginID();
+ result.setName("GeneratedGallery"); // FIXME smth reasonable
+ result.setImplementationBundle(generatedBundle);
+
+ for (Enumeration originalFigures = myGenerationInfo.getProcessedFigures(); originalFigures.hasMoreElements();){
+ Figure nextOriginal = (Figure) originalFigures.nextElement();
+ String nextConvertedFqn = myGenerationInfo.getGeneratedClassFQN(nextOriginal);
+ CustomFigure custom = DiagramElementsCopier.createCustomFigure(nextOriginal);
+ custom.setName(nextOriginal.getName());
+ custom.setBundleName(generatedBundle);
+ custom.setQualifiedClassName(nextConvertedFqn);
+
+ result.getFigures().add(custom);
+ }
+ return result;
+ }
+
+ public GenerationInfo getGenerationInfo() {
+ return myGenerationInfo;
+ }
+
+ protected void handle(Figure next, String fqn) {
+ myGenerationInfo.registerFQN(next, fqn);
+ }
+
+ public interface GenerationInfo {
+ public Enumeration/*<Figure>*/ getProcessedFigures();
+ public String getGeneratedClassFQN(Figure figure);
+ }
+
+ private static class GenerationInfoImpl implements GenerationInfo {
+ private final Map myFigure2FQN = new IdentityHashMap();
+
+ public GenerationInfoImpl(){
+ }
+
+ public void registerFQN(Figure figure, String fqn){
+ myFigure2FQN.put(figure, fqn);
+ }
+
+ public String getGeneratedClassFQN(Figure figure) {
+ return (String)myFigure2FQN.get(figure);
+ }
+
+ public Enumeration getProcessedFigures() {
+ return Collections.enumeration(myFigure2FQN.keySet());
+ }
+ }
+}
diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/GalleryProcessor.java b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/GalleryProcessor.java
new file mode 100644
index 000000000..4ece43f43
--- /dev/null
+++ b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/GalleryProcessor.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2006 Borland Software Corporation
+ *
+ * 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:
+ * Artem Tikhomirov (Borland) - initial API and implementation
+ */
+package org.eclipse.gmf.internal.graphdef.codegen;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Iterator;
+
+import org.eclipse.gmf.gmfgraph.Figure;
+import org.eclipse.gmf.gmfgraph.FigureGallery;
+import org.eclipse.gmf.gmfgraph.util.FigureQualifiedNameSwitch;
+import org.eclipse.gmf.graphdef.codegen.StandaloneGenerator.Processor;
+import org.eclipse.gmf.graphdef.codegen.StandaloneGenerator.ProcessorCallback;
+
+/**
+ * Straighforwardly transforms all top-level figures from supplied galleries
+ * @author artem
+ */
+public class GalleryProcessor extends Processor {
+ private final FigureGallery[] myInput;
+
+ public GalleryProcessor(FigureGallery input) {
+ this(new FigureGallery[] { input });
+ }
+
+ public GalleryProcessor(FigureGallery[] input) {
+ assert !Arrays.asList(input).contains(null);
+ myInput = input;
+ }
+
+ public void go(ProcessorCallback callback) throws InterruptedException {
+ for (int i = 0; i < myInput.length; i++) {
+ for (Iterator it = myInput[i].getFigures().iterator(); it.hasNext();) {
+ Figure next = (Figure) it.next();
+ String fqn = callback.visitFigure(next);
+ handle(next, fqn);
+ }
+ }
+ }
+
+ /**
+ * does nothing by default, override to do smth usable
+ */
+ protected void handle(Figure next, String fqn) {
+ }
+
+ public String[] getRequiredBundles(FigureQualifiedNameSwitch fqnSwitch) {
+ HashSet rv = new HashSet();
+ for (int i = 0; i < myInput.length; i++) {
+ if (myInput[i].getImplementationBundle() != null && myInput[i].getImplementationBundle().trim().length() > 0) {
+ rv.add(myInput[i].getImplementationBundle());
+ }
+ String[] additional = fqnSwitch.getDependencies(myInput[i]);
+ rv.addAll(Arrays.asList(additional));
+ }
+ return (String[]) rv.toArray(new String[rv.size()]);
+ }
+}
diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/StandaloneGalleryConverter.java b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/StandaloneGalleryConverter.java
deleted file mode 100644
index 0c30ee3bf..000000000
--- a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/StandaloneGalleryConverter.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * Copyright (c) 2006 Borland Software Corporation
- *
- * 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:
- * Michael Golubev (Borland) - initial API and implementation
- */
-
-package org.eclipse.gmf.internal.graphdef.codegen;
-
-import java.util.Collection;
-import java.util.Enumeration;
-import java.util.HashSet;
-import java.util.Iterator;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EReference;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.util.EcoreUtil;
-import org.eclipse.gmf.gmfgraph.Canvas;
-import org.eclipse.gmf.gmfgraph.ConnectionFigure;
-import org.eclipse.gmf.gmfgraph.CustomFigure;
-import org.eclipse.gmf.gmfgraph.DecorationFigure;
-import org.eclipse.gmf.gmfgraph.Figure;
-import org.eclipse.gmf.gmfgraph.FigureGallery;
-import org.eclipse.gmf.gmfgraph.GMFGraphFactory;
-import org.eclipse.gmf.graphdef.codegen.StandaloneGenerator;
-
-public class StandaloneGalleryConverter {
- private final StandaloneGenerator.GenerationInfo myGenerationInfo;
- private final DiagramElementsCopier myDiagramElementsCopier;
-
- public StandaloneGalleryConverter(StandaloneGenerator.GenerationInfo generationInfo){
- myGenerationInfo = generationInfo;
- myDiagramElementsCopier = new DiagramElementsCopier();
- }
-
- public FigureGallery convertFigureGallery(){
- FigureGallery result = GMFGraphFactory.eINSTANCE.createFigureGallery();
- String generatedBundle = myGenerationInfo.getConfig().getPluginID();
- result.setImplementationBundle(generatedBundle);
-
- for (Enumeration originalFigures = myGenerationInfo.getProcessedFigures(); originalFigures.hasMoreElements();){
- Figure nextOriginal = (Figure) originalFigures.nextElement();
- String nextConvertedFqn = myGenerationInfo.getGeneratedClassFQN(nextOriginal);
- CustomFigure custom = createCustomFigure(nextOriginal);
- custom.setName(nextOriginal.getName());
- custom.setBundleName(generatedBundle);
- custom.setQualifiedClassName(nextConvertedFqn);
-
- result.getFigures().add(custom);
- myDiagramElementsCopier.registerSubstitution(nextOriginal, custom);
- }
- return result;
- }
-
- public Canvas mirrorDiagramElements(Collection resources){
- Canvas result = null;
- for (Iterator it = resources.iterator(); it.hasNext();){
- Resource next = (Resource)it.next();
- if (!next.getContents().isEmpty()){
- EObject root = (EObject) next.getContents().get(0);
- if (root instanceof Canvas){
- Canvas original = (Canvas)root;
- if (result == null){
- result = GMFGraphFactory.eINSTANCE.createCanvas();
- result.setName(original.getName());
- }
- Collection children = myDiagramElementsCopier.copyAll(original.getChildren());
- Collection compartments = myDiagramElementsCopier.copyAll(original.getCompartments());
- Collection labels = myDiagramElementsCopier.copyAll(original.getLabels());
- Collection nodes = myDiagramElementsCopier.copyAll(original.getNodes());
- Collection connections = myDiagramElementsCopier.copyAll(original.getConnections());
-
- result.getChildren().addAll(children);
- result.getCompartments().addAll(compartments);
- result.getLabels().addAll(labels);
- result.getNodes().addAll(nodes);
- result.getConnections().addAll(connections);
- }
- }
- }
- if (result != null && !result.eContents().isEmpty()){
- myDiagramElementsCopier.copyReferences();
- }
- return result;
- }
-
- private CustomFigure createCustomFigure(Figure original){
- GMFGraphFactory factory = GMFGraphFactory.eINSTANCE;
- if (original instanceof DecorationFigure){
- return factory.createCustomDecoration();
- }
- if (original instanceof ConnectionFigure){
- return factory.createCustomConnection();
- }
- return factory.createCustomFigure();
- }
-
- private static class DiagramElementsCopier extends EcoreUtil.Copier {
- private final HashSet myOriginalFigures = new HashSet();
-
- public void registerSubstitution(Figure original, CustomFigure substituted){
- put(original, substituted);
- myOriginalFigures.add(original);
- }
-
- protected void copyReference(EReference eReference, EObject eObject, EObject copyEObject) {
- if (EcoreUtil.isAncestor(myOriginalFigures, eObject)){
- //no such features in the CustomFigure's
- return;
- }
- super.copyReference(eReference, eObject, copyEObject);
- }
-
- }
-
-}

Back to the top