Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[stem-dev] Graph Editor

Hi all,


I have some problems with the eclipse SVN commit that's why I send a
patch -- the protocol svn+ssh is not known and I depend on the
administrators to install turtoise SVN with which I could tell eclipse
what tunnel to use. Or is this too complicated? I am grateful for any
help here... 

I tried to quickly implement the stuff we planned to do for the graph
editor. Now it was quite a hurry and I have not had the time to test
everything and some parts of the code are quite a work around that I
want to fix later. 
I added a patch to the bug
https://bugs.eclipse.org/bugs/show_bug.cgi?id=317129



I had some problems with the file saving, my quick'n'dirty solution is
to close the editor window after saving, I will have to take care of
this later. When graph of a model from the STEM repository is changed,
all models are saved locally in the models folder of the STEM project,
and references to the local graph copies are set. Unless you "save as",
then a new graph file is created out of the caninical graph.

I added some adapters in the package. The stem.core.graph and
stem.core.model packages got new interfaces and graph and model now
implement these interfaces. Otherwise, only changes in the grapheditor
project were made.

I remember that I read a mail that told me that some references in the
MANIFEST.MF because of the included libraries have been removed or
changed. Could not find it, unluckily.. Does anybody recall anything in
this matter?


Have a nice weekend...


Kind regards

Jan


### Eclipse Workspace Patch 1.0
#P org.eclipse.stem.ui.grapheditor
Index: src/org/eclipse/stem/ui/grapheditor/adapters/IdentifiableDelegateDisplayableCanonicalAdapterFactory.java
===================================================================
--- src/org/eclipse/stem/ui/grapheditor/adapters/IdentifiableDelegateDisplayableCanonicalAdapterFactory.java	(revision 0)
+++ src/org/eclipse/stem/ui/grapheditor/adapters/IdentifiableDelegateDisplayableCanonicalAdapterFactory.java	(revision 0)
@@ -0,0 +1,44 @@
+// IdentifiableDelegateModifiableAdapterFactory.java
+package org.eclipse.stem.ui.grapheditor.adapters;
+
+/*******************************************************************************
+ * Copyright (c) 2008 IBM Corporation and others.
+ * 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:
+ *     IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+import org.eclipse.stem.core.common.Identifiable;
+import org.eclipse.stem.core.model.DisplayableCanonical;
+import org.eclipse.stem.jobs.adapters.identifiable.IdentifiableAdapterFactory;
+import org.eclipse.stem.ui.views.IdentifiableDelegate;
+
+/**
+ * This class is an {@link IdentifiableAdapterFactory} that adapts
+ * {@link IdentifiableDelegate}s to {@link Identifiable}s.
+ */
+public class IdentifiableDelegateDisplayableCanonicalAdapterFactory extends
+		IdentifiableAdapterFactory {
+
+	/**
+	 * @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object,
+	 *      java.lang.Class)
+	 */
+	public Object getAdapter(Object adaptableObject, Class adapterType) {
+		Identifiable retValue = null;
+		// It it what we're looking for?
+		if (adaptableObject instanceof IdentifiableDelegate
+				&& adapterType.equals(DisplayableCanonical.class)) {
+			// Yes
+			final Identifiable temp = ((IdentifiableDelegate) adaptableObject).getIdentifiable();
+			
+			retValue = temp != null && temp instanceof DisplayableCanonical ? temp : null;
+		} // if
+		return retValue;
+	} // getAdapter
+
+} // IdentifiableDelegateModifiableAdapterFactory
Index: src/org/eclipse/stem/ui/grapheditor/TextModifyListener.java
===================================================================
--- src/org/eclipse/stem/ui/grapheditor/TextModifyListener.java	(revision 1544)
+++ src/org/eclipse/stem/ui/grapheditor/TextModifyListener.java	(working copy)
@@ -66,7 +66,7 @@
 		case EDGE_TITLE: connectionData.setEdgeTitle(text.getText()); break;
 		case EDGE_AURI: connectionData.setNodeAURI(text.getText()); break;
 		case EDGE_BURI: connectionData.setNodeBURI(text.getText()); break;
-		case EDGE_LABEL_VALUE: connectionData.setNodeLabelValue(text.getText()); break;
+		case EDGE_LABEL_VALUE: connectionData.setEdgeLabelValue(text.getText()); break;
 		
 		}
 			
Index: src/org/eclipse/stem/ui/grapheditor/adapters/IdentifiableDelegateDisplayableAdapterFactory.java
===================================================================
--- src/org/eclipse/stem/ui/grapheditor/adapters/IdentifiableDelegateDisplayableAdapterFactory.java	(revision 0)
+++ src/org/eclipse/stem/ui/grapheditor/adapters/IdentifiableDelegateDisplayableAdapterFactory.java	(revision 0)
@@ -0,0 +1,44 @@
+// IdentifiableDelegateModifiableAdapterFactory.java
+package org.eclipse.stem.ui.grapheditor.adapters;
+
+/*******************************************************************************
+ * Copyright (c) 2008 IBM Corporation and others.
+ * 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:
+ *     IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+import org.eclipse.stem.core.common.Identifiable;
+import org.eclipse.stem.core.graph.Displayable;
+import org.eclipse.stem.jobs.adapters.identifiable.IdentifiableAdapterFactory;
+import org.eclipse.stem.ui.views.IdentifiableDelegate;
+
+/**
+ * This class is an {@link IdentifiableAdapterFactory} that adapts
+ * {@link IdentifiableDelegate}s to {@link Identifiable}s.
+ */
+public class IdentifiableDelegateDisplayableAdapterFactory extends
+		IdentifiableAdapterFactory {
+
+	/**
+	 * @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object,
+	 *      java.lang.Class)
+	 */
+	public Object getAdapter(Object adaptableObject, Class adapterType) {
+		Identifiable retValue = null;
+		// It it what we're looking for?
+		if (adaptableObject instanceof IdentifiableDelegate
+				&& adapterType.equals(Displayable.class)) {
+			// Yes
+			final Identifiable temp = ((IdentifiableDelegate) adaptableObject).getIdentifiable();
+			
+			retValue = temp != null && temp instanceof Displayable ? temp : null;
+		} // if
+		return retValue;
+	} // getAdapter
+
+} // IdentifiableDelegateModifiableAdapterFactory
Index: src/org/eclipse/stem/ui/grapheditor/GraphCanvas.java
===================================================================
--- src/org/eclipse/stem/ui/grapheditor/GraphCanvas.java	(revision 1544)
+++ src/org/eclipse/stem/ui/grapheditor/GraphCanvas.java	(working copy)
@@ -16,6 +16,7 @@
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IFolder;
 import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
 import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IPath;
@@ -23,17 +24,20 @@
 import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.core.runtime.Platform;
 import org.eclipse.draw2d.ColorConstants;
+import org.eclipse.emf.common.util.EList;
 import org.eclipse.emf.common.util.EMap;
 import org.eclipse.emf.common.util.URI;
 import org.eclipse.emf.ecore.util.EcoreUtil;
 import org.eclipse.emf.ecore.xmi.XMIResource;
 import org.eclipse.stem.adapters.file.File;
+import org.eclipse.stem.core.STEMURI;
 import org.eclipse.stem.core.Utility;
 import org.eclipse.stem.core.common.Identifiable;
 import org.eclipse.stem.core.graph.Edge;
 import org.eclipse.stem.core.graph.EdgeLabel;
 import org.eclipse.stem.core.graph.Node;
 import org.eclipse.stem.core.graph.NodeLabel;
+import org.eclipse.stem.core.model.Model;
 import org.eclipse.stem.definitions.adapters.spatial.SpatialProviderAdapter;
 import org.eclipse.stem.definitions.adapters.spatial.geo.InlineLatLongDataProvider;
 import org.eclipse.stem.definitions.adapters.spatial.geo.LatLong;
@@ -41,14 +45,17 @@
 import org.eclipse.stem.definitions.adapters.spatial.geo.LatLongProviderAdapterFactory;
 import org.eclipse.stem.definitions.adapters.spatial.geo.LatLong.Segment;
 import org.eclipse.stem.definitions.adapters.spatial.geo.LatLong.SegmentBuilder;
+import org.eclipse.stem.definitions.edges.MigrationEdge;
 import org.eclipse.stem.definitions.edges.MigrationEdgeLabel;
 import org.eclipse.stem.definitions.labels.AreaLabel;
+import org.eclipse.stem.definitions.labels.CommonBorderRelationshipLabel;
 import org.eclipse.stem.definitions.labels.LabelsFactory;
 import org.eclipse.stem.definitions.labels.PopulationLabel;
 import org.eclipse.stem.definitions.labels.RelativePhysicalRelationshipLabel;
 import org.eclipse.stem.definitions.labels.impl.AreaLabelImpl;
 import org.eclipse.stem.definitions.labels.impl.PopulationLabelImpl;
 import org.eclipse.stem.ui.Activator;
+import org.eclipse.stem.ui.grapheditor.handlers.SaveInProjectDialog;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.MenuListener;
 import org.eclipse.swt.events.MouseEvent;
@@ -107,6 +114,7 @@
 	final static int 	UNDEFINED = GraphDefs.UNDEFINED , 
 						MIGRATION_EDGE = GraphDefs.MIGRATION_EDGE, 
 						CONTAINMENT_EDGE = GraphDefs.CONTAINMENT_EDGE,
+						COMMON_BORDER_EDGE = GraphDefs.COMMON_BORDER_EDGE,
 						AREA_LABEL = GraphDefs.AREA_LABEL,
 						POPULATION_LABEL = GraphDefs.POPULATION_LABEL,
 	 					NODE_TITLE= GraphDefs.NODE_TITLE,
@@ -132,23 +140,29 @@
 
 	List<DisplayPolygon> polygonsToDraw = new ArrayList<DisplayPolygon>();
 	Map<String,GraphNode> GraphNodes = new HashMap<String, GraphNode>();
+	Map<String,GraphConnection> GraphConnections = new HashMap<String, GraphConnection>();
+	
+	
 	List<double[]> centers = new ArrayList<double[]>();
 	Map<String,Set<DisplayPolygon>> nodeID2Poly = new HashMap<String, Set<DisplayPolygon>>();
+	Map<URI,List<org.eclipse.stem.core.graph.NodeLabel>> nodeURI2Label = new HashMap<URI,List<org.eclipse.stem.core.graph.NodeLabel>>();
+	List<org.eclipse.stem.core.graph.Graph> graphList;
 	
-
 	
 	
 	
 	
+	public void display(List<org.eclipse.stem.core.graph.Graph> graphList, File file, IProject project)
+	{
+		display(graphList, file, project, null );
+	}
 	
 	
-	
-	
-	public void display(List<org.eclipse.stem.core.graph.Graph> graphList, File file, IProject project)
+	public void display(List<org.eclipse.stem.core.graph.Graph> graphList, File file, IProject project, Model model)
 	{
 		//org.eclipse.stem.core.graph.Graph stemGraph =
 		//org.eclipse.stem.core.graph.Graph copyGraph = (org.eclipse.stem.core.graph.Graph) EcoreUtil.copy(stemGraph);
-		
+		this.graphList = graphList;
 		org.eclipse.stem.core.graph.Graph canonicalGraph = null;
 		for (org.eclipse.stem.core.graph.Graph graph : graphList)
 		{
@@ -166,12 +180,21 @@
 		
 		
 		
+		
+		
+
 		final Display display = Activator.getDefault().getWorkbench().getDisplay();
 		final Shell shell = new Shell(display);		
 		shell.setText("STEM Graph Editor");
 		
-		String topCompositeText;
-		if (graphList.size() > 1) topCompositeText = "Canonical Graph of " + project.getName();
+		String topCompositeText = "";
+		if (graphList.size() > 1) 
+		{
+		 	topCompositeText = "Canonical Graph of ";
+			if (project != null) topCompositeText += "\"" + project.getName() + "\"";
+			if (model != null) topCompositeText += "\"" + model.getDublinCore().getTitle()+"\"";
+			if (topCompositeText.equals("")) topCompositeText = stemGraph.getURI().lastSegment();
+		}
 		else topCompositeText = stemGraph.getURI().lastSegment();
 		final Composite topComposite = createTopComposite(shell, topCompositeText);		
 		final Graph zestGraph = new Graph(shell, SWT.NONE);
@@ -222,9 +245,32 @@
 	
 		
 	
+		//assign map: URI -> labels that have this URI as target
+		EMap<URI,org.eclipse.stem.core.graph.NodeLabel> graphNodeLabelList = stemGraph.getNodeLabels();
+		for(Map.Entry<URI,org.eclipse.stem.core.graph.NodeLabel> nodeLabel : graphNodeLabelList.entrySet()) 
+		{
+			URI labelURI = nodeLabel.getKey();
+			org.eclipse.stem.core.graph.NodeLabel tmpLabel = nodeLabel.getValue();					
+			
+			if (tmpLabel != null)
+			{
+				if(nodeURI2Label.get(tmpLabel.getURIOfIdentifiableToBeLabeled()) == null)
+				{
+					List<org.eclipse.stem.core.graph.NodeLabel> labels = new ArrayList<org.eclipse.stem.core.graph.NodeLabel>();
+					labels.add(tmpLabel);
+					nodeURI2Label.put(tmpLabel.getURIOfIdentifiableToBeLabeled(), labels);
+				}
+				else 
+				{
+					nodeURI2Label.get(tmpLabel.getURIOfIdentifiableToBeLabeled()).add(tmpLabel);
+				}
+			}
+			
+		}
 		
 		
-		// Fill GraphDisplay with nodes	
+		
+		//assign nodes to index in list of graphs that were given to this graphCanvas Instance	
 		int numnodes = stemGraph.getNodes().size();
 		final Map<URI, GraphNode> URI2Graphnodes = new HashMap<URI, GraphNode>();
 		int[] assign = new int[numnodes]; 
@@ -246,6 +292,13 @@
 			}
 		}
 		
+		
+		
+		
+		
+		// Fill GraphDisplay with nodes
+		
+		
 		// The spatial information in translated into polygons. Each polygon has a zest node 
 		// in its center. Via the lists "nodeID2Poly" and "GraphNodes" STEM nodes and polygons/zest nodes
 		// are mapped
@@ -257,8 +310,21 @@
 			LatLongProvider latLongProvider = (LatLongProvider) LatLongProviderAdapterFactory.INSTANCE
 			.adaptNew(n, LatLongProvider.class);				
 			
-	
-			LatLong tmp = latLongProvider.getLatLong();
+			//if node has no labels, add them from canonical graph info if available 
+			if (n.getLabels().size() == 0)
+			{
+				URI nURI = n.getURI();				
+				if (nodeURI2Label.get(nURI) != null)
+				{	List<org.eclipse.stem.core.graph.NodeLabel> labelList = nodeURI2Label.get(nURI);  
+					for (org.eclipse.stem.core.graph.NodeLabel label: labelList)
+					{						
+						n.getLabels().add(label);					
+					}
+				}
+			}
+			
+			
+			
 			List<Segment> segments = latLongProvider.getLatLong().getSegments();
 			
 			Segment segment = null;
@@ -344,7 +410,7 @@
 			  GraphConnection gc = new GraphConnection(zestGraph, SWT.NONE, 
 					URI2Graphnodes.get(nodeAURI), URI2Graphnodes.get(nodeBURI));
 			  gc.setData(new ConnectionData(nodeAURI, nodeBURI, edgeURI, edgeLabel, edgeTitle, edgeIdentifier));
-			  
+			  GraphConnections.put(edgeIdentifier, gc);
 			}
 		
 		}
@@ -550,54 +616,141 @@
 
 	
 
-
-
-private void saveToStemGraph(File file, boolean saveAs, IProject project)
+private void saveGraph(List<org.eclipse.stem.core.graph.Graph> graphList, boolean saveAs, IProject project)
 {
+	/*System.err.println("------------------------------------------------------------------");
+	System.err.println("GraphList: (Size: "+ graphList.size() + ")");
+	for (org.eclipse.stem.core.graph.Graph graph : graphList)
+		System.err.println(graph.getURI());
+	System.err.println("------------------------------------------------------------------");
+	*/
+	
+	boolean canonical = graphList.size() > 1;
 	URI newURI = null;
 	
-	if (saveAs == true)
+	if (saveAs == true) 
 	{
-		final SaveAsDialog saveAsDialog = new SaveAsDialog(Activator.getDefault().getWorkbench().getDisplay().getActiveShell());
+		//final SaveAsDialog saveAsDialog = new SaveAsDialog(Activator.getDefault().getWorkbench().getDisplay().getActiveShell());
+		final SaveInProjectDialog saveAsDialog = new SaveInProjectDialog(Activator.getDefault().getWorkbench().getDisplay().getActiveShell());
 		saveAsDialog.open();
 		final IPath path = saveAsDialog.getResult();
+		
 		// Did we get a path?
 		if (path != null) {
 			// Yes
 			final IFile saveAsFile = ResourcesPlugin.getWorkspace().getRoot()
 					.getFile(path);
 			// Did we get a valid file?
+			project = saveAsFile.getProject();
 			if (saveAsFile != null) {			
 				newURI = URI.createPlatformResourceURI(saveAsFile.getFullPath().toString());				
-				String newname = newURI.toString();				
+				
+				/*String newname = newURI.toString();				
 				if (!newname.endsWith(".graph")) 
 				{				
 					newURI = URI.createURI(newname.concat(".graph"));
-				}					
-			}	
+				} */ //done by dialog					
+			}						
+						
 		}
+				
 	}
-	else // saveAs == false, only save 
-	{
-		XMIResource resource = file.getResource();
-		newURI = resource.getURI();
+	
+	
+	Map<URI,URI> orig2newGraphURI = new HashMap<URI,URI>();
+	Map<URI,URI> orig2newModelURI = new HashMap<URI,URI>();
+	if (!canonical) //either single graph or canonical graph (with save as)
+	{	
+		org.eclipse.stem.core.graph.Graph graph = graphList.get(0);
+		URI origURI = graph.getURI();
+		if (newURI ==null)
+		{
+			//transform filepaths to platform resource URI 
+			newURI = URI.createPlatformResourceURI(project.getName() + "/graphs/" + 
+					graph.getURI().lastSegment());
+		}
+		saving(graph, project, newURI);
+		//later: set new reference in models when saved (not save as)	
+		orig2newGraphURI.put(origURI, newURI);
+		try { project.refreshLocal(IResource.DEPTH_INFINITE, null); }
+		catch (Exception ex) {}
 		
 	}
+	else //if (canonical): it is a collection of graphs to be saved: save all graphs in their specific files
+	{
+		for (org.eclipse.stem.core.graph.Graph graph : graphList)
+		{
+			URI origURI = graph.getURI();
+			if (!saveAs) //every graph gets its own file URI, when save as, 
+			{
+				//transform filepaths to platform resource URI 
+				newURI = URI.createPlatformResourceURI(project.getName() + "/graphs/" + 
+						graph.getURI().lastSegment());
+			}
+			saving(graph, project, newURI);
+			//set new reference in models when saved (not save as)
+			orig2newGraphURI.put(origURI, newURI);
+			try { project.refreshLocal(IResource.DEPTH_INFINITE, null); }		
+			catch (Exception ex) {}
+		} 
+	}
 	
 	
-	EMap<URI, Node> stemNodes = stemGraph.getNodes();	
+	if (!saveAs) 
+		{	
+			List<Model> projectModels = new ArrayList<Model>();			
+			projectModels = addProjectModels(projectModels, project);
+			projectModels = getModels(projectModels);
+			
+			for (Model model : projectModels) { 
+				saveModel(model, project, orig2newModelURI);
+			}			
+			try { project.refreshLocal(IResource.DEPTH_INFINITE, null); }		
+			catch (Exception ex) {}
+			
+			projectModels = new ArrayList<Model>();			
+			projectModels = addProjectModels(projectModels, project);
+			projectModels = getModels(projectModels);
+			
+			
+			for (Model model : projectModels) { 
+				updateModelReferenceAndSave(model, project, orig2newGraphURI, orig2newModelURI );
+			}
+			//updateModelReferences(project, orig2newGraphURI);	
+		}
+		
+	
+}
 
+
+private void saving(org.eclipse.stem.core.graph.Graph graph, IProject project, URI newURI)
+{
+	String projectName = project.getName();	
 	
-	String fileURI = newURI.toString().substring(0,newURI.toString().lastIndexOf("/")+1);	
-	IPath workspace = ResourcesPlugin.getWorkspace().getRoot().getLocation();
-	String workspaceString = workspace.toString();	
-	String fileBaseName = newURI.lastSegment().substring(0, newURI.lastSegment().lastIndexOf("."));	
-	String projectName = project.getName();		
+	/*
+	System.err.println("------------------------------------------------------------------");
+	System.err.println("------subGraph-URI: " + graph.getURI());
+	System.err.println("------subGraph-Spatial: " + graph.getDublinCore().getSpatial());
+	System.err.println("\n");
+	*/
+	
+	//make a deep copy of the graph where all changes are made
+	ArrayList<Identifiable> newlist = new ArrayList<Identifiable>();
+	Identifiable id = (Identifiable) EcoreUtil.copy(graph); 		
+	id.setURI(newURI);
+	org.eclipse.stem.core.graph.Graph graphcopy = (org.eclipse.stem.core.graph.Graph) id;
+	
+	
+	
+	
+	
+	String fileBaseName = graphcopy.getURI().lastSegment().
+			substring(0, graphcopy.getURI().lastSegment().lastIndexOf("."));			
 	String  tail = projectName + "/.gml/" + fileBaseName + "_MAP.xml";
 	
-	//transform filepaths to platform resource URI
-	newURI = URI.createPlatformResourceURI(projectName + "/graphs/" + newURI.lastSegment());
 	
+	
+	
 	if(!project.getFolder(".gml").exists())
 	{
 		IProgressMonitor monitor = new NullProgressMonitor();
@@ -612,11 +765,82 @@
 		
 	}
 	
-	stemGraph.setURI(newURI);
 	
+	//LABELS
+	EMap<URI, NodeLabel> stemLabels = graphcopy.getNodeLabels();
+	EMap<URI, NodeLabel> stemLabels_stemGraph = stemGraph.getNodeLabels();
 	
 	
+	for (Map.Entry<URI,NodeLabel> entry : stemLabels_stemGraph.entrySet())
+	{
+		URI uri = entry.getKey();
+		NodeLabel nodeLabel = entry.getValue();
+			
+		if(stemLabels.containsKey(uri)) 
+		{	NodeLabel copyGraphNodeLabel = stemLabels.get(uri);
+			if ((nodeLabel != null) && (copyGraphNodeLabel != null)) 
+				if (!copyGraphNodeLabel.toString().equals(nodeLabel.toString()))
+					
+				//if (copyGraphNodeLabel != nodeLabel) 
+				{
+					
+					System.err.println("URI " + uri + " in beiden mit Werten "
+							+ nodeLabel.toString() + " und " + copyGraphNodeLabel.toString());
+					
+					//stemLabels.get(uri).setCurrentValue(nodeLabel.getCurrentValue());				
+					
+					if (stemLabels.get(uri) instanceof PopulationLabel) 
+					{	
+						((PopulationLabel)stemLabels.get(uri)).
+							setPopulationIdentifier(((PopulationLabel)nodeLabel).getPopulationIdentifier());
+						((PopulationLabel)stemLabels.get(uri)).
+						setName(((PopulationLabel)nodeLabel).getName());
+					}	
+					if (stemLabels.get(uri) instanceof AreaLabel)
+						((AreaLabel)stemLabels.get(uri)).
+						setCurrentValue(((AreaLabel)nodeLabel).getCurrentAreaValue());
+						
+				
+				}
+		}
+			
+	}	
 	
+
+	
+	//EDGES
+	EMap<URI, Edge> stemEdges = graphcopy.getEdges();
+	for (Map.Entry<URI,Edge> entry : stemEdges.entrySet())
+	{
+		URI uri = entry.getKey();
+		Edge e = entry.getValue();
+		String edgeID = e.getDublinCore().getIdentifier();
+		GraphConnection gc = GraphConnections.get(edgeID);
+		if (gc != null) 
+		{
+			ConnectionData edgeData = (ConnectionData) gc.getData();
+			//Title
+			e.getDublinCore().setTitle(edgeData.getEdgeTitle());	
+			
+			if (e.getLabel() instanceof MigrationEdgeLabel)
+			{
+				EdgeLabel edgeLabel = edgeData.getEdgeLabel();
+				double migRate = ((MigrationEdgeLabel)edgeLabel).getCurrentValue().getMigrationRate();
+				
+				((MigrationEdgeLabel)e.getLabel())
+				.getCurrentValue().setMigrationRate(migRate);
+												
+			}
+			
+		}
+		//System.err.println("Edge: " + uri + 
+		//					" \n\tTitle:" + e.getDublinCore().getTitle() +
+		//					" \n\tLabel:" + e.getLabel().toString());	
+	}
+	
+	
+	//NODES
+	EMap<URI, Node> stemNodes = graphcopy.getNodes();
 	Map<String,Set<GmlPolygon>> polygonMap = new HashMap<String,Set<GmlPolygon>>();	
 	SpatialGmlExporter sgmle = new SpatialGmlExporter();
 	
@@ -625,79 +849,81 @@
 		Node n = entry.getValue();		
 		String nodeID = n.getDublinCore().getIdentifier();
 		GraphNode gn = GraphNodes.get(nodeID);
-		NodeData nodeData = (NodeData) gn.getData();
+		if (gn != null) 
+		{
+			NodeData nodeData = (NodeData) gn.getData();
+			//Title
+			n.getDublinCore().setTitle(nodeData.getNodeTitle());	
 			
-		//Labels are saved automatically by the EList structure
+		}
 		
-		//Title
-		n.getDublinCore().setTitle(nodeData.getNodeTitle());
+					
 		
-
 		//Spatial 	
 		Set<DisplayPolygon> displayPolygons = nodeID2Poly.get(n.getDublinCore().getIdentifier());			
-		
-		if (n.getDublinCore().getSpatial().indexOf(SpatialProviderAdapter.STEM_SPATIAL_SCHEME_PREFIX+"inline") >= 0)
-		{ 
-			String spatialURIString = polygon2LatLong(displayPolygons); 			
-			n.getDublinCore().setSpatial(spatialURIString);	
-		}
-		
-		if (n.getDublinCore().getSpatial().indexOf(SpatialProviderAdapter.STEM_SPATIAL_SCHEME_PREFIX+"platform") >= 0)
-		{	
-			Set<GmlPolygon> gmlPolygons = new HashSet<GmlPolygon>();
-			for (DisplayPolygon dPolygon : displayPolygons)
-			{				
-				gmlPolygons.add(dPolygon.getUnscaledGmlPolygon());
+		if (displayPolygons != null)
+		{
+			if (n.getDublinCore().getSpatial().indexOf(SpatialProviderAdapter.STEM_SPATIAL_SCHEME_PREFIX+"inline") >= 0)
+			{ 
+				String spatialURIString = polygon2LatLong(displayPolygons); 			
+				n.getDublinCore().setSpatial(spatialURIString);	
 			}
-			polygonMap.put(n.getURI().lastSegment(), gmlPolygons);		
-
-			String nodeSpatialString = SpatialProviderAdapter.STEM_SPATIAL_SCHEME_PREFIX+"platform:/resource/" + tail + "#" + n.getURI().lastSegment();			
-			n.getDublinCore().setSpatial(nodeSpatialString);			
-		
+			
+			if (n.getDublinCore().getSpatial().indexOf(SpatialProviderAdapter.STEM_SPATIAL_SCHEME_PREFIX+"platform") >= 0)
+			{	
+				Set<GmlPolygon> gmlPolygons = new HashSet<GmlPolygon>();
+				for (DisplayPolygon dPolygon : displayPolygons)
+				{				
+					gmlPolygons.add(dPolygon.getUnscaledGmlPolygon());
+				}
+				polygonMap.put(n.getURI().lastSegment(), gmlPolygons);		
+	
+				String nodeSpatialString = SpatialProviderAdapter.STEM_SPATIAL_SCHEME_PREFIX+"platform:/resource/" + 
+											tail + "#" + n.getURI().lastSegment();			
+				n.getDublinCore().setSpatial(nodeSpatialString);						
+			}
 		}
-	}
+	}//node loop
 	
 	
-	//TODO  keep key and name etc for xml file?
-	/*if() //if it is a real map
-	{
-		int keyLevel = Utility.keyLevel(stemGraph.getURI().lastSegment());
-		sgmle.writeSpatialData(	polygonMap, 
-				workspaceString.concat("/" + tail ),
-				stemGraph.getURI().lastSegment(), 
-				keyLevel); 
-	}
-	else
-	{
-	*/
+	if (polygonMap.size() > 0)
 	
-	if (polygonMap.size() > 0)
-	{
+	{ 
+		
 		sgmle.writeSpatialData(	polygonMap, 
-				workspaceString.concat("/" + tail ),
-				stemGraph.getURI().lastSegment(), 
-				-1); 
-		String spatialString = SpatialProviderAdapter.STEM_SPATIAL_SCHEME_PREFIX+"platform:/resource/" + tail;
-		stemGraph.getDublinCore().setSpatial(spatialString);
+		ResourcesPlugin.getWorkspace().getRoot().getLocation().toString().concat("/" + tail ),
+		graphcopy.getURI().lastSegment(), 
+		-1); 		
+		String spatialString = SpatialProviderAdapter.STEM_SPATIAL_SCHEME_PREFIX+"platform:/resource/" + tail;		
+		graphcopy.getDublinCore().setSpatial(spatialString);
 		
+		
 	}
 	
 	
-	
-	try {
-		ArrayList<Identifiable> newlist = new ArrayList<Identifiable>();
-		Identifiable e = (Identifiable) EcoreUtil.copy(stemGraph); 		
-		e.setURI(newURI);
-		newlist.add(e);
+	// saving Graph 
+
+	try {	
+		graphcopy.getDublinCore().setTitle("");
+		newlist.add(graphcopy);	
 		Utility.serializeIdentifiables(newlist, newURI);
 	} catch(Exception e) {
 		Activator.logError(e.getMessage(), e);
-	}	
+	} 
 	
-
+	/*
+	System.err.println("------new URI: " + newURI);
+	System.err.println("------new subGraph-URI: " + graphcopy.getURI());
+	System.err.println("------new subGraph-Spatial: " + graphcopy.getDublinCore().getSpatial());
+	System.err.println("------------------------------------------------------------------");
+	*/
+	
 }
 
 
+
+
+
 private String polygon2LatLong(Set<DisplayPolygon> displayPolygons) 
 {
 	//LatLong latLong = new LatLong();
@@ -762,38 +988,42 @@
 	toolBar.setLayout(new FillLayout(SWT.HORIZONTAL));
 	
 	
-	if (file != null) // if file == null it is a canonical graph 
+	if (graphList.size() >= 1) //== // if file == null it is a canonical graph 
 	{
 		ToolItem saveButton = new ToolItem(toolBar, SWT.PUSH);
 		saveButton.setText("Save Graph");
 		saveButton.addSelectionListener(new SelectionListener() {
 			public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {				
-				saveToStemGraph(file, false, project);				
+				saveGraph(graphList, false, project);
+				Activator.getDefault().getWorkbench().getDisplay().getActiveShell().dispose();
 			}
 			
 			public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) {
 			}
 		});
+	}
 	
-	
 	ToolItem separator = new ToolItem(toolBar, SWT.SEPARATOR);
 	
 	
 	ToolItem saveAsButton = new ToolItem(toolBar, SWT.PUSH);
 	saveAsButton.setText("Save Graph As ...");
 	saveAsButton.addSelectionListener(new SelectionListener() {
-		public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
-			
-			saveToStemGraph(file,true, project);			
+		public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {			
+			List<org.eclipse.stem.core.graph.Graph> saveGraphList =
+				new ArrayList<org.eclipse.stem.core.graph.Graph>();
+			saveGraphList.add(stemGraph);
+			saveGraph(saveGraphList, true, project);
+			Activator.getDefault().getWorkbench().getDisplay().getActiveShell().dispose();
 		}
 		
 		public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) {
 		}
 	});
-	}
 	
 	
-	/* TODO 
+	
+	/* TODO Reset Button
 	ToolItem resetButton = new ToolItem(toolBar, SWT.PUSH);
 	resetButton.setText("Reset");
 	resetButton.addSelectionListener(new SelectionListener() {
@@ -966,7 +1196,7 @@
   
     final Label coordinate_trans = new Label(infoComposite, SWT.NONE);
     coordinate_trans.setLayoutData(new RowData(200, SWT.DEFAULT));
-    coordinate_trans.setText("xy: ");
+    coordinate_trans.setText("XY: ");
           	    
     final Label zoom = new Label(infoComposite, SWT.NONE);
     zoom.setLayoutData(new RowData(100, SWT.DEFAULT));
@@ -1068,7 +1298,7 @@
 			
 			Point xy = zestGraph.toControl(Display.getCurrent().getCursorLocation());
 			double[] xy_trans = D2N(xy.x,xy.y);
-			coordinate_trans.setText("Coordinates: " + df.format(xy_trans[0]) + " " + df.format(xy_trans[1]) );
+			coordinate_trans.setText("Coordinates: " + df.format(-xy_trans[1]) + " " + df.format(xy_trans[0]) );
 			
 			//other coord systems
 			//coordinate2.setText("xy2: " + e.x + " " + e.y);
@@ -1115,7 +1345,7 @@
 							{	addTranslationToPoly(displayPolygon, newX, newY); }
 							addTranslationToNode(selectedNode, newX, newY);
 							double[] nodexy_trans = new double[]{((NodeData)selectedNode.getData()).getOrigX()/RFD, ((NodeData)selectedNode.getData()).getOrigY()/RFD};
-							nodeXY_edit.setText( df.format(nodexy_trans[0]) + " " + df.format(nodexy_trans[1]));
+							nodeXY_edit.setText( df.format(-nodexy_trans[1]) + " " + df.format(nodexy_trans[0]));
 							
 							zestGraph.redraw();
 						}
@@ -1212,7 +1442,7 @@
 						}		
 					}										
 					double[] xy_trans = new double[]{((NodeData)selectedNode.getData()).getOrigX()/RFD, ((NodeData)selectedNode.getData()).getOrigY()/RFD};
-					nodeXY_edit.setText( df.format(xy_trans[0]) + " " + df.format(xy_trans[1]));
+					nodeXY_edit.setText( df.format(-xy_trans[1]) + " " + df.format(xy_trans[0]));
 				}
 				
 				
@@ -1240,8 +1470,11 @@
 						case CONTAINMENT_EDGE:  RelativePhysicalRelationshipLabel rprl = (RelativePhysicalRelationshipLabel) ((ConnectionData)selectedEdge.getData()).getEdgeLabel();
 												edgeLabelType_edit.setText("Containment Edge");
 												//edgeLabelValue_edit.setText(rprl.getCurrentValue().toString());
+												edgeLabelValue_edit.setVisible(false);											
+												break;
+						case COMMON_BORDER_EDGE:CommonBorderRelationshipLabel cbrl = (CommonBorderRelationshipLabel) ((ConnectionData)selectedEdge.getData()).getEdgeLabel();
+												edgeLabelType_edit.setText("Common Border Edge");
 												edgeLabelValue_edit.setVisible(false);
-												
 												break;
 						case UNDEFINED:			edgeLabelType_edit.setText("");
 												edgeLabelValue_edit.setText("");
@@ -1515,4 +1748,126 @@
 }
 
 
+
+private List<Model> addProjectModels(List<Model> projectModels, IProject project)
+{
+	IFolder modelFolder = project.getFolder("models");
+	IResource[] models = null;
+	try {
+		models = modelFolder.members();
+	} catch(Exception e) {
+		e.printStackTrace();
+	}
+	if (models != null) {
+		for(IResource r:models) {					
+			
+			// ignore system files
+			if(r.getName().startsWith(".")) continue;
+			
+			try {
+				URI uri = URI.createURI(r.getLocationURI().toString());
+				Identifiable id = Utility.getIdentifiable(uri);				
+				if(id instanceof Model) 
+				{
+					projectModels.add((Model)id);
+				}
+			}
+			catch(Exception ex) { }
+		}
+	}
+	return projectModels;
+}
+
+private List<Model> getModels (List<Model> parentModel)
+{
+	
+	List<Model> modelsCollector = new ArrayList<Model>();
+	
+	for (Model model : parentModel)
+	{	
+		List<Model> models = getModels(model.getModels());
+		modelsCollector.addAll(models);
+	}
+	
+	parentModel.addAll(modelsCollector);
+	
+	return parentModel;
+}
+
+
+
+private void saveModel (Model model, IProject project, Map<URI,URI> orig2newModelURI)
+{
+	
+	URI modelURI = model.getURI();
+	URI newModelURI = URI.createPlatformResourceURI
+	(project.getName() + "/models/" + modelURI.lastSegment()); 
+	orig2newModelURI.put(modelURI, newModelURI);
+	
+	if (!newModelURI.equals(modelURI) )
+	{	ArrayList<Identifiable> newlist = new ArrayList<Identifiable>();
+		Identifiable modelCopy = (Model) EcoreUtil.copy(model); 		
+		modelCopy.setURI(newModelURI);
+		newlist.add(modelCopy);	
+		try {
+			
+			Utility.serializeIdentifiables(newlist, newModelURI);
+			//System.err.println("1761: gelungen: Writing " + newModelURI);
+		} 
+		catch (Exception ex) { //System.err.println("ERROR"); 
+		} 
+	}
+}
+
+
+
+private void updateModelReferenceAndSave(Model model, IProject project,  Map<URI,URI> orig2newGraphURI, Map<URI,URI> orig2newModelURI)
+{
+	try {
+											
+			URI modelURI = model.getURI();
+								
+			for (org.eclipse.stem.core.graph.Graph graph : model.getGraphs())
+			{	
+				URI graphURI = graph.getURI();
+				if (orig2newGraphURI.containsKey(graphURI))
+				{						
+					if(!graphURI.equals(orig2newGraphURI.get(graphURI)))						
+					{
+					graph.setURI(orig2newGraphURI.get(graphURI));
+					//System.err.println("1783: ersetze " +graphURI + " durch " + orig2newGraphURI.get(graphURI));
+					}
+				}
+				
+			}
+			
+			for (Model childModel : model.getModels())
+			{	
+				URI childModelURI = childModel.getURI();
+				if (orig2newModelURI.containsKey(childModelURI))
+				{						
+					if(!childModelURI.equals(orig2newModelURI.get(childModelURI)))						
+					{
+					childModel.setURI(orig2newModelURI.get(childModelURI));
+					//System.err.println("1797: ersetze " +childModelURI + " durch " + orig2newModelURI.get(childModelURI));
+					}
+				}
+				
+			}
+			
+
+			URI newModelURI = URI.createPlatformResourceURI
+			(project.getName() + "/models/" + modelURI.lastSegment()); 
+			//virgin test?
+			{	ArrayList<Identifiable> newlist = new ArrayList<Identifiable>();
+				Identifiable modelCopy = (Identifiable) EcoreUtil.copy(model); 		
+				modelCopy.setURI(newModelURI);
+				newlist.add(modelCopy);	
+				//System.err.println("1811: Writing " + newModelURI);
+				Utility.serializeIdentifiables(newlist, newModelURI);
+			}							
+	} catch(Exception e) {}
+}
+
+
 } //end of graph canvas 
Index: src/org/eclipse/stem/ui/grapheditor/handlers/CanonicalGraphDisplay.java
===================================================================
--- src/org/eclipse/stem/ui/grapheditor/handlers/CanonicalGraphDisplay.java	(revision 1544)
+++ src/org/eclipse/stem/ui/grapheditor/handlers/CanonicalGraphDisplay.java	(working copy)
@@ -12,10 +12,13 @@
 import org.eclipse.core.resources.IContainer;
 	import org.eclipse.core.resources.IProject;
 	import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
 	import org.eclipse.core.runtime.Platform;
 
+import org.eclipse.emf.common.util.EList;
 	import org.eclipse.emf.common.util.URI;
 	import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.edit.provider.DelegatingWrapperItemProvider;
 	import org.eclipse.jface.viewers.ISelection;
 	import org.eclipse.jface.viewers.StructuredSelection;
 	import org.eclipse.jface.viewers.TreePath;
@@ -29,20 +32,45 @@
 	import org.eclipse.stem.ui.views.explorer.IdentifiableTreeNode;
 	import org.eclipse.ui.handlers.HandlerUtil;	
 import org.eclipse.stem.core.graph.Graph;
+import org.eclipse.stem.core.model.Model;
+import org.eclipse.stem.core.model.impl.ModelImpl;
 
 
 	public class CanonicalGraphDisplay extends AbstractHandler
 	implements IHandler {
 
 		
+		IProject project;
 		
-		
 		public Object execute(final ExecutionEvent executionEvent)
 		throws ExecutionException {
 			
 			final ISelection selection = HandlerUtil
 			.getCurrentSelectionChecked(executionEvent);
 
+			
+			
+			
+			if(selection instanceof TreeSelection) {
+				TreeSelection ts = (TreeSelection)selection;
+				TreePath[] paths =  ts.getPaths();
+				if(paths.length > 0) {
+					TreePath parent = paths[0].getParentPath();
+					Object projectSegment = parent.getFirstSegment();
+					
+					//Object parentSeg = parent.getLastSegment();
+					if(projectSegment != null) {
+						project = null;					
+						if(projectSegment instanceof IdentifiableTreeNode)  
+							project =((IdentifiableTreeNode)projectSegment).getProject();					 
+						if(projectSegment instanceof IProject) 
+							project = (IProject)projectSegment;
+						
+					}
+				}
+			}
+			
+			
 			// Structured Selection?
 			if (selection instanceof StructuredSelection) {
 				
@@ -55,45 +83,85 @@
 					
 					File file = (File) Platform
 					.getAdapterManager().getAdapter(obj, File.class); 
-					org.eclipse.stem.ui.views.explorer.IdentifiableTreeNode idTreeNode = (org.eclipse.stem.ui.views.explorer.IdentifiableTreeNode) Platform.getAdapterManager().getAdapter(obj, org.eclipse.stem.ui.views.explorer.IdentifiableTreeNode.class);
-			
 					
-					// Were we successful in adapting?
-					if (idTreeNode != null) {
-						// Yes
-						doit(idTreeNode, file);
-					} // if
-					else {
-						// Internal error
-						Activator.logError(
-								"STEM Internal error display command applied to \""
-										+ obj.getClass().getName() + "\"", null);
+					if (obj instanceof ModelImpl)
+					{	
+										
+						ModelImpl model =
+						(ModelImpl) Platform.getAdapterManager().getAdapter(obj, ModelImpl.class);
+					
+						if (model != null)
+						{
+							doit(model);
+						}
+						else
+						{
+							// Internal error
+							Activator.logError(
+									"STEM Internal error display command applied to \""
+											+ obj.getClass().getName() + "\"", null);
+						}
 					}
+					else if (obj instanceof DelegatingWrapperItemProvider)
+					{
+											
+						Identifiable retValue = null;
+						DelegatingWrapperItemProvider dWIP = (DelegatingWrapperItemProvider) obj;			
+						
+						if (dWIP.getValue() instanceof Identifiable) {
+							// Yes
+							retValue = (Identifiable) dWIP.getValue();
+						} // if Identifiable
+						else {
+							// No
+							// Keep adapting...
+							retValue = (Identifiable) Platform.getAdapterManager()
+									.getAdapter(dWIP.getValue(), Identifiable.class);
+						}
+						ModelImpl model =
+							(ModelImpl) Platform.getAdapterManager().getAdapter(retValue, ModelImpl.class);
+									
+						
+						if (model != null)
+						{
+							doit(model);							
+						}
+						else
+						{
+							// Internal error
+							Activator.logError(
+									"STEM Internal error display command applied to \""
+											+ obj.getClass().getName() + "\"", null);
+						}
+					}
+					else if (obj instanceof org.eclipse.stem.ui.views.explorer.IdentifiableTreeNode)
+					{
+						
+						org.eclipse.stem.ui.views.explorer.IdentifiableTreeNode idTreeNode = 				
+						(org.eclipse.stem.ui.views.explorer.IdentifiableTreeNode) Platform.
+						getAdapterManager().getAdapter(
+								obj, org.eclipse.stem.ui.views.explorer.IdentifiableTreeNode.class);
+					
+					
+						// Were we successful in adapting?
+						if (idTreeNode != null) {
+							// Yes
+							doit(idTreeNode);
+						} // if
+						else {
+							// Internal error
+							Activator.logError(
+									"STEM Internal error display command applied to \""
+											+ obj.getClass().getName() + "\"", null);
+						}
+					}
+					
 				} // for each selection
 				
 				
 			} // if StructuredSelection
 			
-			if(selection instanceof TreeSelection) {
-				TreeSelection ts = (TreeSelection)selection;
-				TreePath[] paths =  ts.getPaths();
-				if(paths.length > 0) {
-					TreePath parent = paths[0].getParentPath();
-					Object parentSeg = parent.getLastSegment();
-					if(parentSeg != null) {
-						IProject project = null;
-						if(parentSeg instanceof IdentifiableTreeNode) { 
-							project =((IdentifiableTreeNode)parentSeg).getProject();
-						} if(parentSeg instanceof IProject) project = (IProject)parentSeg;
-						
-						try {
-							project.refreshLocal(IResource.DEPTH_INFINITE, null);
-						} catch(Exception e) {
-							Activator.logError(e.getMessage(), e);
-						}
-					}
-				}
-			}
+
 			
 			
 			return null;
@@ -101,15 +169,13 @@
 		
 		
 		
-		protected void doit(org.eclipse.stem.ui.views.explorer.IdentifiableTreeNode idTreeNode, File file) 
+		protected void doit(org.eclipse.stem.ui.views.explorer.IdentifiableTreeNode idTreeNode) 
 		{ 
 			
-			List<Graph> graphList = new ArrayList<Graph>();
-			
-			Graph canonicalGraph = null;																	
-			IProject project = idTreeNode.getProject();
+			List<Graph> graphList = new ArrayList<Graph>();																
+			if (project == null) project = idTreeNode.getProject();
 					
-			IContainer graphsFolder = project.getFolder("graphs");
+			IContainer graphsFolder = project.getFolder("models"); //before: graphs
 			IResource[] graphs = null;
 			try {
 				graphs = graphsFolder.members();
@@ -125,18 +191,12 @@
 						
 						URI uri = URI.createURI(r.getLocationURI().toString());
 						Identifiable id = Utility.getIdentifiable(uri);				
-						if (canonicalGraph == null) 
-						{
-							//canonicalGraph = ((Graph)id);
-							canonicalGraph = (Graph) EcoreUtil.copy((Graph)id);
+						if (id instanceof Model)
+						{	
+							graphList = getGraphs(graphList, (Model)id);
+							
 						}
-						else 
-						{
-							IdentifiableFilterImpl myFilter = new IdentifiableFilterImpl(canonicalGraph.getDublinCore().getCoverage());
-							//canonicalGraph.addGraph((Graph)id, myFilter);
-							canonicalGraph.addGraph((Graph) EcoreUtil.copy((Graph)id), myFilter);
-						}						
-						if (id != null) graphList.add((Graph)id);
+						else if (id instanceof Graph) graphList.add((Graph)id);
 					} catch(Exception e) {
 						// Skip bad file
 					}
@@ -148,13 +208,57 @@
 				GraphCanvas graphCanvas = new GraphCanvas();
 				graphCanvas.display(graphList, null, project);
 			}
+						
 			
-			
-			
 			//update all models in the project that used this graph
 			//TODO
-			    
+			    			
+		} //end doit with ExplorerTreeLeaf
+		
+		
+		
+		
+		
+		protected void doit(Model model) 
+		{ 	
+			List<Graph> graphList = new ArrayList<Graph>();	
+			graphList = getGraphs(graphList, model);
 			
+			if (project == null) //should not happen...
+			{
+				List<IProject> projects = org.eclipse.stem.ui.Utility.getSTEMProjectsFromWorkspace(ResourcesPlugin.getWorkspace());
+				for (IProject stemProject : projects)
+				{		
+					//System.err.println("project: " + project.getName()+ " graph:" + stemGraph.getURI());
+					//TODO contain is not enough, must be identical segment!
+					//note: when project cannot be found, it is a reference to STEM repository
+					if (model.getURI().toString().contains(stemProject.getName()) )
+					{
+						project = stemProject;
+					}
+				}		
+			}
+			if (graphList.size() != 0) {
+				GraphCanvas graphCanvas = new GraphCanvas();
+				graphCanvas.display(graphList, null, project, model);
+			}
 		}
+		
+		
+		
+		
+		protected List<Graph> getGraphs(List<Graph> parentgraphs, Model parentmodel)
+		{
+			EList<Model> models = parentmodel.getModels();
+			List<Graph> graphs = parentmodel.getGraphs();
+		
+			for (Model model : models)
+			{	
+				graphs.addAll(getGraphs(graphs, model));
+			}
+
+			parentgraphs.addAll(graphs);
+			return parentgraphs;
+		}
 	}
 
Index: src/org/eclipse/stem/ui/grapheditor/adapters/DelegatingWrapperItemProviderDisplayableCanonicalAdapterFactory.java
===================================================================
--- src/org/eclipse/stem/ui/grapheditor/adapters/DelegatingWrapperItemProviderDisplayableCanonicalAdapterFactory.java	(revision 0)
+++ src/org/eclipse/stem/ui/grapheditor/adapters/DelegatingWrapperItemProviderDisplayableCanonicalAdapterFactory.java	(revision 0)
@@ -0,0 +1,58 @@
+package org.eclipse.stem.ui.grapheditor.adapters;
+
+/*******************************************************************************
+ * Copyright (c) 2008 IBM Corporation and others.
+ * 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:
+ *     IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.emf.edit.provider.DelegatingWrapperItemProvider;
+import org.eclipse.stem.core.common.Identifiable;
+import org.eclipse.stem.core.model.DisplayableCanonical;
+import org.eclipse.stem.jobs.adapters.identifiable.IdentifiableAdapterFactory;
+
+/**
+ * This class is an {@link IdentifiableAdapterFactory} that adapts
+ * {@link DelegatingWrapperItemProvider}s to {@link Displayable}s.
+ */
+public class DelegatingWrapperItemProviderDisplayableCanonicalAdapterFactory extends
+		IdentifiableAdapterFactory {
+
+	/**
+	 * @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object,
+	 *      java.lang.Class)
+	 */
+	public Object getAdapter(Object adaptableObject, Class adapterType) {
+		DisplayableCanonical retValue = null;
+
+		// It it what we're looking for?
+		if (adaptableObject instanceof DelegatingWrapperItemProvider
+				&& adapterType.equals(DisplayableCanonical.class)) {
+			// Yes
+			final DelegatingWrapperItemProvider dwip = (DelegatingWrapperItemProvider) adaptableObject;
+			// Is this an Identifiable?
+			if (dwip.getValue() instanceof Identifiable) {
+				// Yes
+				// ...and is it Modifiable?
+				if (dwip.getValue() instanceof DisplayableCanonical) {
+					// Yes
+					retValue = (DisplayableCanonical) dwip.getValue();
+				}
+				// else NO
+			} // if Identifiable 
+			else {
+				// No
+				// Keep adapting...
+				retValue = (DisplayableCanonical) Platform.getAdapterManager()
+						.getAdapter(dwip.getValue(), DisplayableCanonical.class);
+			}
+		} // if
+		return retValue;
+	} // getAdapter
+} // DelegatingWrapperItemProviderModifiableAdapterFactory
Index: src/org/eclipse/stem/ui/grapheditor/GraphDefs.java
===================================================================
--- src/org/eclipse/stem/ui/grapheditor/GraphDefs.java	(revision 1544)
+++ src/org/eclipse/stem/ui/grapheditor/GraphDefs.java	(working copy)
@@ -6,6 +6,7 @@
 	final static int 	UNDEFINED = -1 , 
 						MIGRATION_EDGE = 0, 
 						CONTAINMENT_EDGE = 1,
+						COMMON_BORDER_EDGE = 2,
 						AREA_LABEL = 2, 
 						POPULATION_LABEL = 3,	
 						NODE_TITLE=4, 
Index: src/org/eclipse/stem/ui/grapheditor/SpatialGmlExporter.java
===================================================================
--- src/org/eclipse/stem/ui/grapheditor/SpatialGmlExporter.java	(revision 1544)
+++ src/org/eclipse/stem/ui/grapheditor/SpatialGmlExporter.java	(working copy)
@@ -11,6 +11,7 @@
  *     IBM Corporation - initial API and implementation
  *******************************************************************************/
 
+import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
 import java.io.Writer;
@@ -195,7 +196,10 @@
 	{
 		//if(log.logFlag) log.logEnter("XmlUtilities.write(" + document + ", " + xmlFile + ")");
 		try 
-		{			
+		{	
+			File file = new File(fileName);
+			file.delete();
+			
 			FileWriter fw = new FileWriter(fileName);
 			writeDocument(document,fw);
 			fw.close();
Index: src/org/eclipse/stem/ui/grapheditor/handlers/SaveInProjectDialog.java
===================================================================
--- src/org/eclipse/stem/ui/grapheditor/handlers/SaveInProjectDialog.java	(revision 0)
+++ src/org/eclipse/stem/ui/grapheditor/handlers/SaveInProjectDialog.java	(revision 0)
@@ -0,0 +1,448 @@
+package org.eclipse.stem.ui.grapheditor.handlers;
+
+
+/*******************************************************************************
+ * Copyright (c) 2000, 2009 IBM Corporation and others.
+ * 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:
+ *    IBM Corporation - initial API and implementation 
+ *    Bob Foster <bob@xxxxxxxxxx>
+ *     - Fix for bug 23025 - SaveAsDialog should not assume what is being saved is an IFile
+ *    Benjamin Muskalla <b.muskalla@xxxxxxx>
+ *     - Fix for bug 82541 - [Dialogs] SaveAsDialog should better handle closed projects
+ *******************************************************************************/
+
+
+import java.util.List;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.IDialogSettings;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.dialogs.TitleAreaDialog;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.osgi.util.TextProcessor;
+import org.eclipse.stem.core.common.Identifiable;
+import org.eclipse.stem.ui.Activator;
+import org.eclipse.stem.ui.Utility;
+import org.eclipse.stem.ui.views.explorer.IdentifiableTreeNode;
+import org.eclipse.stem.ui.wizards.NewIdentifiablePage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.layout.RowData;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.internal.ide.IDEInternalWorkbenchImages;
+import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
+import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
+import org.eclipse.ui.internal.ide.IIDEHelpContextIds;
+import org.eclipse.ui.internal.ide.misc.ResourceAndContainerGroup;
+
+/**
+ * A standard "Save As" dialog which solicits a path from the user. The
+ * <code>getResult</code> method returns the path. Note that the folder
+ * at the specified path might not exist and might need to be created.
+ * <p>
+ * This class may be instantiated; it is not intended to be subclassed.
+ * </p>
+ *
+ * @see org.eclipse.ui.dialogs.ContainerGenerator
+ * @noextend This class is not intended to be subclassed by clients.
+ */
+public class SaveInProjectDialog extends TitleAreaDialog {
+	
+	private static final String DIALOG_SETTINGS_SECTION = "SaveAsDialogSettings"; //$NON-NLS-1$
+	
+	private IFile originalFile = null;
+
+    private String originalName = null;
+
+    private IPath result;
+
+    // widgets
+    //private ResourceAndContainerGroup resourceGroup;
+    private Text resourceNameField;
+    private Button okButton;
+    private Combo projectCombo;
+
+    /**
+     * Image for title area
+     */
+    private Image dlgTitleImage = null;
+
+    /**
+     * Creates a new Save As dialog for no specific file.
+     *
+     * @param parentShell the parent shell
+     */
+    public SaveInProjectDialog(Shell parentShell) {
+        super(parentShell);
+        setShellStyle(getShellStyle() | SWT.SHEET);
+    }
+
+    /* (non-Javadoc)
+     * Method declared in Window.
+     */
+    protected void configureShell(Shell shell) {
+        super.configureShell(shell);
+        shell.setText(IDEWorkbenchMessages.SaveAsDialog_text);
+        PlatformUI.getWorkbench().getHelpSystem().setHelp(shell,
+				IIDEHelpContextIds.SAVE_AS_DIALOG);
+    }
+
+    /* (non-Javadoc)
+     * Method declared in Window.
+     */
+    protected Control createContents(Composite parent) {
+
+        Control contents = super.createContents(parent);     
+        validatePage();
+        //JFW resourceGroup.setFocus();
+        setTitle(IDEWorkbenchMessages.SaveAsDialog_title);
+        ImageDescriptor descriptor = IDEInternalWorkbenchImages.getImageDescriptor(
+                IDEInternalWorkbenchImages.IMG_DLGBAN_SAVEAS_DLG);
+        if(descriptor != null) {
+        	dlgTitleImage = descriptor.createImage();
+        	setTitleImage(dlgTitleImage);
+        }
+        setMessage(IDEWorkbenchMessages.SaveAsDialog_message);
+
+        return contents;
+    }
+
+    /** 
+     * The <code>SaveAsDialog</code> implementation of this <code>Window</code>
+     * method disposes of the banner image when the dialog is closed.
+     */
+    public boolean close() {
+        if (dlgTitleImage != null) {
+			dlgTitleImage.dispose();
+		}
+        return super.close();
+    }
+
+    /* (non-Javadoc)
+     * Method declared on Dialog.
+     */
+    protected void createButtonsForButtonBar(Composite parent) {
+        okButton = createButton(parent, IDialogConstants.OK_ID,
+                IDialogConstants.OK_LABEL, true);
+        okButton.setEnabled(true);
+        createButton(parent, IDialogConstants.CANCEL_ID,
+                IDialogConstants.CANCEL_LABEL, false);
+    }
+
+    /* (non-Javadoc)
+     * Method declared on Dialog.
+     */
+    protected Control createDialogArea(Composite parent) {
+        // top level composite
+        Composite parentComposite = (Composite) super.createDialogArea(parent);
+
+        // create a composite with standard margins and spacing
+        Composite composite = new Composite(parentComposite, SWT.NONE);
+        
+        GridLayout layout = new GridLayout();
+        layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
+        layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
+        layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
+        layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
+        composite.setLayout(layout);
+        composite.setLayoutData(new GridData(GridData.FILL_BOTH));
+        composite.setFont(parentComposite.getFont());
+        
+        Listener listener = new Listener() {
+            public void handleEvent(Event event) {
+                setDialogComplete(validatePage());
+            }
+        };
+        
+		GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL
+				| GridData.GRAB_HORIZONTAL);
+		data.widthHint = 250;
+        
+        Label selectProject = new Label(composite, SWT.None);
+        selectProject.setText("Select Project ");
+        
+        projectCombo = new Combo(composite, SWT.READ_ONLY);
+        initializeProjectCombo(projectCombo);
+        projectCombo.setLayoutData(data);
+        
+        Label sep = new Label(composite, SWT.NONE);
+        
+        Label fileLabel = new Label(composite, SWT.None);
+        fileLabel.setText("Name of new Graph File ");
+				
+		resourceNameField = new Text(composite, SWT.BORDER);
+		resourceNameField.setLayoutData(data);
+
+        
+         
+        return parentComposite;
+    }
+
+    /**
+     * Returns the full path entered by the user.
+     * <p>
+     * Note that the file and container might not exist and would need to be created.
+     * See the <code>IFile.create</code> method and the 
+     * <code>ContainerGenerator</code> class.
+     * </p>
+     *
+     * @return the path, or <code>null</code> if Cancel was pressed
+     */
+    public IPath getResult() {
+        return result;
+    }
+
+    /**
+     * Initializes the controls of this dialog.
+     */
+
+
+    /* (non-Javadoc)
+     * Method declared on Dialog.
+     */
+    protected void okPressed() {
+        // Get new path.
+        IProject pro = getSTEMProjects().get(projectCombo.getSelectionIndex());
+        String projectPath = pro.getFullPath().toPortableString();
+        String filePath = resourceNameField.getText();
+        IPath path = 
+        	new Path(TextProcessor.deprocess(projectPath + "/graphs/" + filePath)).makeAbsolute();
+        
+        
+        //If the user does not supply a file extension and if the save 
+        //as dialog was provided a default file name append the extension 
+        //of the default filename to the new name
+        if (path.getFileExtension() == null) { 
+        	path = path.addFileExtension("graph");			
+        }
+
+       
+        // If the path already exists then confirm overwrite.
+        IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
+        if (file.exists()) {
+            String[] buttons = new String[] { IDialogConstants.YES_LABEL,
+                    IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL };
+            String question = NLS.bind(
+					IDEWorkbenchMessages.SaveAsDialog_overwriteQuestion, path
+							.toString());
+			MessageDialog d = new MessageDialog(getShell(),
+                    IDEWorkbenchMessages.Question,
+                    null, question, MessageDialog.QUESTION, buttons, 0) {
+				protected int getShellStyle() {
+					return super.getShellStyle() | SWT.SHEET;
+				}
+			};
+            int overwrite = d.open();
+            switch (overwrite) {
+            case 0: // Yes
+                break;
+            case 1: // No
+                return;
+            case 2: // Cancel
+            default:
+                cancelPressed();
+                return;
+            }
+        }
+
+        // Store path and close.
+        result = path; 
+        close();
+    }
+
+    /**
+     * Sets the completion state of this dialog and adjusts the enable state of
+     * the Ok button accordingly.
+     *
+     * @param value <code>true</code> if this dialog is compelete, and
+     *  <code>false</code> otherwise
+     */
+    protected void setDialogComplete(boolean value) {
+        
+    }
+
+    /**
+     * Sets the original file to use.
+     *
+     * @param originalFile the original file
+     */
+    public void setOriginalFile(IFile originalFile) {
+        this.originalFile = originalFile;
+    }
+
+    /**
+     * Set the original file name to use.
+     * Used instead of <code>setOriginalFile</code>
+     * when the original resource is not an IFile.
+     * Must be called before <code>create</code>.
+     * @param originalName default file name
+     */
+    public void setOriginalName(String originalName) {
+        this.originalName = originalName;
+    }
+
+    /**
+     * Returns whether this page's visual components all contain valid values.
+     *
+     * @return <code>true</code> if valid, and <code>false</code> otherwise
+     */
+    private boolean validatePage() {
+        /*JFW if (!resourceGroup.areAllValuesValid()) {
+            if (!resourceGroup.getResource().equals("")) { //$NON-NLS-1$
+				setErrorMessage(resourceGroup.getProblemMessage());
+			} else {
+            	setErrorMessage(null);
+            }
+            return false;
+        }
+        
+        String resourceName = resourceGroup.getResource();
+        IWorkspace workspace = ResourcesPlugin.getWorkspace();
+        
+        // Do not allow a closed project to be selected
+        IPath fullPath = resourceGroup.getContainerFullPath();
+        if (fullPath != null) {
+        	String projectName = fullPath.segment(0);
+	        IStatus isValidProjectName = workspace.validateName(projectName, IResource.PROJECT);
+	        if(isValidProjectName.isOK()) {
+	        	IProject project = workspace.getRoot().getProject(projectName);
+	        	if(!project.isOpen()) {
+	        		setErrorMessage(IDEWorkbenchMessages.SaveAsDialog_closedProjectMessage);
+	        		return false;
+	        	}
+	        }
+        }
+        
+        IStatus result = workspace.validateName(resourceName, IResource.FILE);
+        if (!result.isOK()){
+        	setErrorMessage(result.getMessage());
+        	return false;
+        }
+        
+        setErrorMessage(null);
+        JFW END*/
+        return true;
+    }
+    
+	/* (non-Javadoc)
+     * @see org.eclipse.jface.window.Dialog#getDialogBoundsSettings()
+     * 
+     * @since 3.2
+     */
+	protected IDialogSettings getDialogBoundsSettings() {
+        IDialogSettings settings = IDEWorkbenchPlugin.getDefault().getDialogSettings();
+        IDialogSettings section = settings.getSection(DIALOG_SETTINGS_SECTION);
+        if (section == null) {
+            section = settings.addNewSection(DIALOG_SETTINGS_SECTION);
+        } 
+        return section;
+	}
+	
+    /*
+     * (non-Javadoc)
+     * @see org.eclipse.jface.dialogs.Dialog#isResizable()
+     */
+    protected boolean isResizable() {
+    	return true;
+    }
+    
+    private void initializeProjectCombo(final Combo projectCombo) {
+
+		IProject selectedProject = getWorkSpaceSelectedProject();
+
+		if(selectedProject == null) selectedProject = getSTEMProjects().get(0);
+		
+		// Get the Projects that are STEM projects
+		int index = 0;
+		int i = 0;
+		for (final IProject project : getSTEMProjects()) {
+			// Is the STEM project selected?
+			if (project.equals(selectedProject)) {
+				// Yes
+				index = i;
+			}
+
+			final String projectName = project.getName();
+			projectCombo.add(projectName);
+			i++;
+		} // for each STEM project
+		projectCombo.setFocus();
+		projectCombo.select(index);
+		//NewIdentifiablePage.lastProject = this.getSelectedProject();
+	} // initializeProjectField
+    
+    
+    
+    private List<IProject> getSTEMProjects() {
+		// Refresh
+    	List<IProject> stemProjects = Utility.getSTEMProjectsFromWorkspace();
+		return stemProjects;
+	} // getSTEMProjects
+    
+    private IProject getWorkSpaceSelectedProject() {
+		IProject retValue = null;
+		// Find the name of the currently selected project, if there is one
+		final ISelection selection = Activator.getDefault().getWorkbench()
+				.getActiveWorkbenchWindow().getSelectionService()
+				.getSelection();
+		// Structured Selection that might have a project?
+		if (selection instanceof IStructuredSelection) {
+			for (Object obj : ((IStructuredSelection) selection).toList()) {
+				// Project?
+				if (obj instanceof IProject) {
+					retValue = (IProject) obj;
+					break;
+				}
+				// File or Folder? (in a Project)
+				else if (obj instanceof IResource) {
+					// Yes
+					retValue = ((IResource) obj).getProject();
+					break;
+				} // else if File or Folder
+				// Identifiable?
+				else if (obj instanceof Identifiable) {
+					final IPath path = new Path(((Identifiable) obj).getURI()
+							.toPlatformString(true));
+					retValue = ResourcesPlugin.getWorkspace().getRoot()
+							.getFile(path).getProject();
+					break;
+				} // else if Identifiable
+				// IdentifiableTreeNode?
+				else if (obj instanceof IdentifiableTreeNode) {
+					retValue = ((IdentifiableTreeNode) obj).getProject();
+					break;
+				} // else if IdentifiableTreeNode
+
+			} // for each selected object
+		} // if structured selection
+
+		return retValue;
+	} // getWorkSpaceSelectedProject
+}
Index: src/org/eclipse/stem/ui/grapheditor/handlers/GraphDisplay.java
===================================================================
--- src/org/eclipse/stem/ui/grapheditor/handlers/GraphDisplay.java	(revision 1544)
+++ src/org/eclipse/stem/ui/grapheditor/handlers/GraphDisplay.java	(working copy)
@@ -7,6 +7,7 @@
 import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.core.commands.ExecutionException;
 import org.eclipse.core.commands.IHandler;
+import org.eclipse.core.internal.resources.Project;
 import org.eclipse.core.resources.IContainer;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResource;
@@ -14,8 +15,12 @@
 import org.eclipse.core.runtime.Platform;
 import org.eclipse.emf.common.util.EList;
 import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.edit.provider.DelegatingWrapperItemProvider;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TreePath;
+import org.eclipse.jface.viewers.TreeSelection;
 import org.eclipse.stem.adapters.file.File;
 
 import org.eclipse.stem.core.Utility;
@@ -23,16 +28,18 @@
 import org.eclipse.stem.core.model.Model;
 import org.eclipse.stem.ui.Activator;
 import org.eclipse.stem.ui.grapheditor.GraphCanvas;
+import org.eclipse.stem.ui.views.explorer.IdentifiableTreeNode;
 import org.eclipse.ui.handlers.HandlerUtil;
 import org.eclipse.stem.core.graph.Graph;
+import org.eclipse.stem.core.graph.impl.GraphImpl;
 
 
 public class GraphDisplay extends AbstractHandler
 implements IHandler {
 	
 	IProject project;
-
 	
+	
 
 	public Object execute(final ExecutionEvent executionEvent)
 	throws ExecutionException {
@@ -41,24 +48,67 @@
 		.getCurrentSelectionChecked(executionEvent);
 		
 		
-		
+		if(selection instanceof TreeSelection) {
+			TreeSelection ts = (TreeSelection)selection;
+			TreePath[] paths =  ts.getPaths();
+			if(paths.length > 0) {
+				TreePath parent = paths[0].getParentPath();
+				Object projectSegment = parent.getFirstSegment();
+				
+				//Object parentSeg = parent.getLastSegment();
+				if(projectSegment != null) {
+					project = null;					
+					if(projectSegment instanceof IdentifiableTreeNode)  
+						project =((IdentifiableTreeNode)projectSegment).getProject();					 
+					if(projectSegment instanceof IProject) 
+						project = (IProject)projectSegment;
+					
+				}
+			}
+		}
 	
 		// Structured Selection?
 		if (selection instanceof StructuredSelection) 
 		{
-			
+			Identifiable retValue = null;
 			// Yes
 			// Iterate through everything that's in the selection and put each
 			// object into the appropriate collection.
 			for (final Object obj : ((StructuredSelection) selection).toList()) {
 				// IExecutable executable = (IExecutable) ExecutableAdapterFactory.INSTANCE
-				// .adapt(obj, IExecutable.class);
+				// .adapt(obj, IExecutable.class)
+				if (obj instanceof GraphImpl)
+				{
+					retValue = (GraphImpl) obj;
+				}
+				else
+				{
+					DelegatingWrapperItemProvider dWIP = (DelegatingWrapperItemProvider) obj;			
+					
+					if (dWIP.getValue() instanceof Identifiable) {
+						// Yes
+						retValue = (Identifiable) dWIP.getValue();
+					} // if Identifiable
+					else {
+						// No
+						// Keep adapting...
+						retValue = (Identifiable) Platform.getAdapterManager()
+								.getAdapter(dWIP.getValue(), Identifiable.class);
+					}
+				}
 				
+				
 				File file = (File) Platform
-				.getAdapterManager().getAdapter(obj, File.class); 
+				.getAdapterManager().getAdapter(retValue, File.class); 		
 				
 				Graph stemGraph = (Graph) Platform
-				.getAdapterManager().getAdapter(obj, Graph.class);
+				.getAdapterManager().getAdapter(retValue, Graph.class);
+				
+				//File file = (File) Platform
+				//.getAdapterManager().getAdapter(obj, File.class); 
+				
+				//Graph stemGraph = (Graph) Platform
+				//.getAdapterManager().getAdapter(obj, Graph.class);
 		
 				// Were we successful in adapting?
 				if (stemGraph == null) {
@@ -67,29 +117,41 @@
 							"STEM Internal error display command applied to \""
 									+ obj.getClass().getName() + "\"", null);
 				} // Yes, successfully adapted Graph
-				else {
-				
-					List<IProject> projects = org.eclipse.stem.ui.Utility.getSTEMProjectsFromWorkspace(ResourcesPlugin.getWorkspace());
-					for (IProject stemProject : projects)
-					{		
-						//System.err.println("project: " + project.getName()+ " graph:" + stemGraph.getURI());
-						if (stemGraph.getURI().toString().contains(stemProject.getName()) )
-						{
-							project = stemProject;
-						}
-					}		
+				else 
+					{
+					if (project == null){	
+						List<IProject> projects = org.eclipse.stem.ui.Utility.getSTEMProjectsFromWorkspace(ResourcesPlugin.getWorkspace());
+						for (IProject stemProject : projects)
+						{		
+							//System.err.println("project: " + project.getName()+ " graph:" + stemGraph.getURI());
+							//TODO contain is not enough, must be identical segment!
+							if (stemGraph.getURI().toString().contains(stemProject.getName()) )
+							{
+								project = stemProject;
+							}
+						}	
+					}
 					
 					//start Display
 					doit(stemGraph, file, project);												
-		
-					//update graphs in all models of the project
-					IContainer modelFolder = project.getFolder("models");	
+					
+					//update graphs in all models of the project 
+					
+					/*
+					IContainer modelFolder = null;
 					IResource[] models = null;
+					
 					try {
-						models = modelFolder.members();
+						if (project != null) 
+							{ 	modelFolder = project.getFolder("models");	
+								models = modelFolder.members();
+							}
 					} catch(Exception e) {
 						e.printStackTrace();
 					}
+					
+					
+					
 					if (models != null) {
 						
 						for(IResource r:models) {
@@ -122,8 +184,10 @@
 							// Skip bad file
 							catch(Exception e) { }															
 						} // models iterator
-					} // models != null
-				} // Graph successfully adapted
+					} // models != null, end updating graphs
+					*/
+					
+				} // Graph successfully adapted, "doit" called, project models updated
 				
 			} // for each selection
 			
Index: src/org/eclipse/stem/ui/grapheditor/ConnectionData.java
===================================================================
--- src/org/eclipse/stem/ui/grapheditor/ConnectionData.java	(revision 1544)
+++ src/org/eclipse/stem/ui/grapheditor/ConnectionData.java	(working copy)
@@ -3,6 +3,7 @@
 import org.eclipse.emf.common.util.URI;
 import org.eclipse.stem.core.graph.EdgeLabel;
 import org.eclipse.stem.definitions.edges.MigrationEdgeLabel;
+import org.eclipse.stem.definitions.labels.CommonBorderRelationshipLabel;
 import org.eclipse.stem.definitions.labels.RelativePhysicalRelationshipLabel;
 
 public class ConnectionData
@@ -51,6 +52,8 @@
 			return GraphDefs.MIGRATION_EDGE;
 		if (this.edgeLabel instanceof RelativePhysicalRelationshipLabel)
 			return GraphDefs.CONTAINMENT_EDGE;	
+		if (this.edgeLabel instanceof CommonBorderRelationshipLabel)
+			return GraphDefs.COMMON_BORDER_EDGE;
 		return GraphDefs.UNDEFINED;
 	}		
 	
@@ -65,7 +68,7 @@
 	}
 	
 	
-	void setNodeLabelValue(String value)
+	void setEdgeLabelValue(String value)
 	{
 		
 		switch (this.getEdgeLabelType())
@@ -79,6 +82,7 @@
 				newRate = ((MigrationEdgeLabel)this.edgeLabel).getCurrentValue().getMigrationRate();
 			}
 			((MigrationEdgeLabel)this.edgeLabel).getCurrentValue().setMigrationRate(newRate);
+			break;
 		}
 	}
 	
Index: src/org/eclipse/stem/ui/grapheditor/adapters/DelegatingWrapperItemProviderDisplayableAdapterFactory.java
===================================================================
--- src/org/eclipse/stem/ui/grapheditor/adapters/DelegatingWrapperItemProviderDisplayableAdapterFactory.java	(revision 0)
+++ src/org/eclipse/stem/ui/grapheditor/adapters/DelegatingWrapperItemProviderDisplayableAdapterFactory.java	(revision 0)
@@ -0,0 +1,58 @@
+package org.eclipse.stem.ui.grapheditor.adapters;
+
+/*******************************************************************************
+ * Copyright (c) 2008 IBM Corporation and others.
+ * 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:
+ *     IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.emf.edit.provider.DelegatingWrapperItemProvider;
+import org.eclipse.stem.core.common.Identifiable;
+import org.eclipse.stem.core.graph.Displayable;
+import org.eclipse.stem.jobs.adapters.identifiable.IdentifiableAdapterFactory;
+
+/**
+ * This class is an {@link IdentifiableAdapterFactory} that adapts
+ * {@link DelegatingWrapperItemProvider}s to {@link Displayable}s.
+ */
+public class DelegatingWrapperItemProviderDisplayableAdapterFactory extends
+		IdentifiableAdapterFactory {
+
+	/**
+	 * @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object,
+	 *      java.lang.Class)
+	 */
+	public Object getAdapter(Object adaptableObject, Class adapterType) {
+		Displayable retValue = null;
+
+		// It it what we're looking for?
+		if (adaptableObject instanceof DelegatingWrapperItemProvider
+				&& adapterType.equals(Displayable.class)) {
+			// Yes
+			final DelegatingWrapperItemProvider dwip = (DelegatingWrapperItemProvider) adaptableObject;
+			// Is this an Identifiable?
+			if (dwip.getValue() instanceof Identifiable) {
+				// Yes
+				// ...and is it Modifiable?
+				if (dwip.getValue() instanceof Displayable) {
+					// Yes
+					retValue = (Displayable) dwip.getValue();
+				}
+				// else NO
+			} // if Identifiable 
+			else {
+				// No
+				// Keep adapting...
+				retValue = (Displayable) Platform.getAdapterManager()
+						.getAdapter(dwip.getValue(), Displayable.class);
+			}
+		} // if
+		return retValue;
+	} // getAdapter
+} // DelegatingWrapperItemProviderModifiableAdapterFactory
Index: plugin.xml
===================================================================
--- plugin.xml	(revision 1544)
+++ plugin.xml	(working copy)
@@ -60,7 +60,71 @@
   
   
   
+  
   <extension
+        point="org.eclipse.core.runtime.adapters">
+         <factory 
+            class="org.eclipse.stem.ui.adapters.executable.IdentifiableDelegateExecutableAdapterFactory" 
+            adaptableType="org.eclipse.stem.ui.views.IdentifiableDelegate">
+            <adapter type="org.eclipse.stem.jobs.execution.IExecutable"/>
+         </factory>
+         
+         <factory
+               adaptableType="org.eclipse.stem.ui.views.IdentifiableDelegate"
+               class="org.eclipse.stem.ui.adapters.identifiable.IdentifiableDelegateIdentifiableAdapterFactory">
+            <adapter
+                  type="org.eclipse.stem.core.common.Identifiable">
+            </adapter>
+         </factory>
+         
+         <factory
+               adaptableType="org.eclipse.emf.edit.provider.DelegatingWrapperItemProvider"
+               class="org.eclipse.stem.ui.adapters.identifiable.DelegatingWrapperItemProviderIdentifiableAdapterFactory">
+            <adapter
+                  type="org.eclipse.stem.core.common.Identifiable">
+            </adapter>
+         </factory>
+         
+         <factory
+               adaptableType="org.eclipse.stem.ui.views.IdentifiableDelegate"
+               class="org.eclipse.stem.ui.grapheditor.adapters.IdentifiableDelegateDisplayableAdapterFactory">
+            <adapter
+                  type="org.eclipse.stem.core.graph.Displayable">
+            </adapter>
+         </factory>
+         
+         <factory
+               adaptableType="org.eclipse.emf.edit.provider.DelegatingWrapperItemProvider"
+               class="org.eclipse.stem.ui.grapheditor.adapters.DelegatingWrapperItemProviderDisplayableAdapterFactory">
+            <adapter
+                  type="org.eclipse.stem.core.graph.Displayable">
+            </adapter>
+         </factory>
+         
+         
+         <factory
+               adaptableType="org.eclipse.stem.ui.views.IdentifiableDelegate"
+               class="org.eclipse.stem.ui.grapheditor.adapters.IdentifiableDelegateDisplayableCanonicalAdapterFactory">
+            <adapter
+                  type="org.eclipse.stem.core.model.DisplayableCanonical">
+            </adapter>
+         </factory>
+         
+         <factory
+               adaptableType="org.eclipse.emf.edit.provider.DelegatingWrapperItemProvider"
+               class="org.eclipse.stem.ui.grapheditor.adapters.DelegatingWrapperItemProviderDisplayableCanonicalAdapterFactory">
+            <adapter
+                  type="org.eclipse.stem.core.model.DisplayableCanonical">
+            </adapter>
+         </factory>
+  </extension>
+  
+  
+  
+  
+  
+  
+  <extension
         point="org.eclipse.ui.commands">
      <category
            description="%_UI_STEM_WizCmd_Cat_Desc"
@@ -88,42 +152,74 @@
   
   
   
+  
+  
   <extension
         point="org.eclipse.core.expressions.definitions">
      
      
      <definition
-           id="org.eclipse.stem.ui.isDisplayableIdentifiable">
+           id="org.eclipse.stem.ui.isDisplayableIdentifiable_old">
         <with
               variable="selection">
            <iterate
                  operator="and">
               <and>
                  <adapt
-                      type="org.eclipse.stem.core.graph.Graph">                
+				   type="org.eclipse.stem.core.graph.Graph"> 
+				<!--
+                       type="org.eclipse.emf.edit.provider.DelegatingWrapperItemProvider"> 
+                 -->               
                  </adapt>
               </and>
            </iterate>
         </with>
      </definition>
+     
+     
      <definition
-           id="org.eclipse.stem.ui.isDisplayableCanonicalIdentifiable">
+           id="org.eclipse.stem.ui.isDisplayableIdentifiable">
         <with
               variable="selection">
            <iterate
                  operator="and">
               <and>
                  <adapt
-                       type="org.eclipse.stem.ui.views.explorer.IdentifiableTreeNode$GraphsTreeNode">               
+                       type="org.eclipse.stem.core.graph.Displayable">
                  </adapt>
+                 <not>
+                    <reference
+                          definitionId="org.eclipse.stem.ui.isexecutable">
+                    </reference>
+                 </not>
               </and>
+              
            </iterate>
         </with>
      </definition>
-  </extension>
-  
-  
-  
-   
-
+     
+     
+     <definition id="org.eclipse.stem.ui.isDisplayableCanonicalIdentifiable">
+        <with variable="selection">
+           <iterate operator="or">
+              <or>
+                 <!--
+                 <adapt
+                       type="org.eclipse.stem.ui.views.explorer.IdentifiableTreeNode$ModelsTreeNode">               
+                 </adapt>
+                 -->
+              	 <adapt
+                       type="org.eclipse.stem.core.model.Model">               
+                 </adapt>
+                 <adapt
+                       type="org.eclipse.stem.core.model.DisplayableCanonical">               
+                 </adapt>
+              </or>
+           </iterate>
+        </with>
+     </definition>
+     
+     
+     
+  </extension>     
 </plugin>
\ No newline at end of file
#P org.eclipse.stem.core
Index: src/org/eclipse/stem/core/graph/Graph.java
===================================================================
--- src/org/eclipse/stem/core/graph/Graph.java	(revision 1544)
+++ src/org/eclipse/stem/core/graph/Graph.java	(working copy)
@@ -85,7 +85,7 @@
  * 
  * @model
  */
-public interface Graph extends Identifiable {
+public interface Graph extends Identifiable, Displayable {
 
 	/**
 	 * This is the segment of the type URI that prefixes all other segments in a
Index: src/org/eclipse/stem/core/model/Model.java
===================================================================
--- src/org/eclipse/stem/core/model/Model.java	(revision 1544)
+++ src/org/eclipse/stem/core/model/Model.java	(working copy)
@@ -16,6 +16,7 @@
 import org.eclipse.emf.common.util.URI;
 import org.eclipse.stem.core.common.Identifiable;
 import org.eclipse.stem.core.common.IdentifiableFilter;
+import org.eclipse.stem.core.model.DisplayableCanonical;
 import org.eclipse.stem.core.graph.Graph;
 
 /**
@@ -75,7 +76,7 @@
  * 
  * @model
  */
-public interface Model extends Identifiable {
+public interface Model extends Identifiable, DisplayableCanonical {
 
 	/**
 	 * This is the segment of the type URI that prefixes all other segments in a
Index: src/org/eclipse/stem/core/model/DisplayableCanonical.java
===================================================================
--- src/org/eclipse/stem/core/model/DisplayableCanonical.java	(revision 0)
+++ src/org/eclipse/stem/core/model/DisplayableCanonical.java	(revision 0)
@@ -0,0 +1,14 @@
+package org.eclipse.stem.core.model;
+
+import org.eclipse.emf.ecore.EObject;
+
+/**
+ * see Modifiable.java in org.eclipse.core.modifier
+ * 
+ * 
+ * @model interface="true"
+ */
+public interface DisplayableCanonical extends EObject {
+	// Nothing
+} // Modifiable
+
Index: src/org/eclipse/stem/core/graph/Displayable.java
===================================================================
--- src/org/eclipse/stem/core/graph/Displayable.java	(revision 0)
+++ src/org/eclipse/stem/core/graph/Displayable.java	(revision 0)
@@ -0,0 +1,16 @@
+package org.eclipse.stem.core.graph;
+
+import org.eclipse.emf.ecore.EObject;
+
+/**
+ * see Modifiable.java in org.eclipse.core.modifier
+ * 
+ * 
+ * @model interface="true"
+ */
+public interface Displayable extends EObject {
+	// Nothing
+} // Modifiable
+
+
+

Back to the top