Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoratikhomirov2006-04-10 09:28:14 -0400
committeratikhomirov2006-04-10 09:28:14 -0400
commitf7785d38dbd02b79548af6642d853a0a250b8603 (patch)
treeaf7c34d44b6fb20c26aa661b763d43f3280c0822 /plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal
parent2965ccd72595dc3991499815279105b4542683a0 (diff)
downloadorg.eclipse.gmf-tooling-f7785d38dbd02b79548af6642d853a0a250b8603.tar.gz
org.eclipse.gmf-tooling-f7785d38dbd02b79548af6642d853a0a250b8603.tar.xz
org.eclipse.gmf-tooling-f7785d38dbd02b79548af6642d853a0a250b8603.zip
Refactor latest fix for #128779 - StandaloneGalleryConverter moved to gmfgraph.codegen, dependencies of oeg.tests and oeg.graphdef.codegen.ui updated.
Diffstat (limited to 'plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal')
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/StandaloneGalleryConverter.java120
1 files changed, 120 insertions, 0 deletions
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
new file mode 100644
index 000000000..29a4d259f
--- /dev/null
+++ b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/StandaloneGalleryConverter.java
@@ -0,0 +1,120 @@
+/*
+ * 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());
+
+ result.getChildren().addAll(children);
+ result.getCompartments().addAll(compartments);
+ result.getLabels().addAll(labels);
+ result.getNodes().addAll(nodes);
+ }
+ }
+ }
+ 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