Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [bpel-dev] [patch3 - moving-process-commandStack-ExtensionMapResource]

Hi Vitaly,

I have rewieved patch3  - and it looks good.
I am not sure yet whether I like the idea to access the process model via
an Adapter - but since I dont have a better idea at the moment, I will
leave it for now.

I will now take a look at patch4 and if I find patch 4 to be OK, too, then
I will relase everything into the DOM_FACADE branch ...

Cheers
Simoin


Simon Moser, M.Eng.


                                                                          
 Websphere Integration       Mail:           IBM Deutschland Entwicklung  
 Developer Development       smoser@xxxxxx.  GmbH                         
 Team Lead BPEL Editor       com             Vorsitzender des             
 Dept. 4722, Bldg.           Phone:          Aufsichtsrats: Martin Jetter 
 71032-01, Room 086          +49-7031-16-43  Geschäftsführung: Herbert    
 Websphere Solutions and     04              Kircher                      
 Services                    Fax:            Sitz der Gesellschaft:       
 IBM Deutschland             +49-7031-16-48  Böblingen                    
 Entwicklung GmbH            90              Registergericht: Amtsgericht 
 Schönaicherstr. 220, D –                    Stuttgart, HRB 243294        
 71032 Boeblingen                                                         
                                                                          








                                                                           
             "Tishkov, Vitaly                                              
             V"                                                            
             <vitaly.v.tishkov                                          To 
             @intel.com>               "BPEL Designer project developer    
             Sent by:                  discussions."                       
             bpel-dev-bounces@         <bpel-dev@xxxxxxxxxxx>              
             eclipse.org                                                cc 
                                                                           
                                                                   Subject 
             07/02/2007 05:28          [bpel-dev] [patch3 -                
             PM                        moving-process-commandStack-Extensi 
                                       onMapResource]                      
                                                                           
             Please respond to                                             
              "BPEL Designer                                               
             project developer                                             
               discussions."                                               
             <bpel-dev@eclipse                                             
                   .org>                                                   
                                                                           
                                                                           




Hello Simon,

Please find the next patch for MultiTab-DomFacade branch. I’m continuing
the move of ‘core’ functionality from BPELEditor to
BPELMultipageEditorPart.
It took more time than usual to create this patch because it became more
and more difficult to modify just a bit of code – changes affect many other
parts.

What is in the patch.

   1. The following fields and related code are migrated from BPELEditor to
      BPELMultipageEditorPart:
      +          private Process process;
   +          private DefaultEditDomain editDomain;
   +          protected ModelListenerAdapter modelListenerAdapter;
   +          private Resource extensionsResource;
   +          private ExtensionMap extensionMap;

   2. BPELEditor still needs to access process and some other fields.
      I didn’t want to introduce one more field in BPELEditor
      (BPELMultipageEditorPart multipageEditorPart) in order to leave
      BPELEditor as separated from BPELMultipageEditorPart as possible.

      I decided to use adapters to access them. All the adapters look like
      this one:
   //it’s a method in BPELEditor
               public Process getProcess() {
               IWorkbenchPartSite editorSite = getSite();
                           if (editorSite instanceof MultiPageEditorSite) {
                                      return
   (Process)((org.eclipse.ui.part.MultiPageEditorSite)getSite()).getMultiPageEditor().getAdapter(Process.class);
                           }
                           return null;
            }

   Is it a good approach of there is a better one?

   3. New bugs.
      1. Do not try to save a file if you modified its source – you’ll get
      an exception. The problem lays in the SynchronizationManager – only
      graphic edit model knows about it, text edit model doesn’t know
      anything. I assume it’s better to work on it during the phase 2
      (synchronizing EMF and DOM models).

Please apply the patch or let me know what’s bad in this one.

Thanks,
            Vitaly.

            (See attached file:
patch3-moving-process-commandStack-ExtensionMapResource.txt)
_______________________________________________
bpel-dev mailing list
bpel-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/bpel-dev
### Eclipse Workspace Patch 1.0
#P org.eclipse.bpel.ui
Index: src/org/eclipse/bpel/ui/BPELEditor.java
===================================================================
RCS file: /cvsroot/technology/org.eclipse.bpel/plugins/org.eclipse.bpel.ui/src/org/eclipse/bpel/ui/BPELEditor.java,v
retrieving revision 1.16.2.1
diff -u -r1.16.2.1 BPELEditor.java
--- src/org/eclipse/bpel/ui/BPELEditor.java	8 Jun 2007 08:58:50 -0000	1.16.2.1
+++ src/org/eclipse/bpel/ui/BPELEditor.java	2 Jul 2007 14:57:21 -0000
@@ -151,6 +151,7 @@
 import org.eclipse.ui.IFileEditorInput;
 import org.eclipse.ui.IWorkbench;
 import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPartSite;
 import org.eclipse.ui.PartInitException;
 import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.actions.ActionFactory;
@@ -160,6 +161,7 @@
 import org.eclipse.ui.internal.views.properties.tabbed.view.TabbedPropertyViewer;
 import org.eclipse.ui.part.FileEditorInput;
 import org.eclipse.ui.part.IPageSite;
+import org.eclipse.ui.part.MultiPageEditorSite;
 import org.eclipse.ui.part.PageBook;
 import org.eclipse.ui.views.properties.IPropertySheetPage;
 import org.eclipse.ui.views.properties.tabbed.ISection;
@@ -172,24 +174,17 @@
 /**
  * BPELEditor is the Eclipse editor part for editing BPEL files.
  */
-public class BPELEditor extends GraphicalEditorWithPaletteAndTray implements IEditModelListener/*, IGotoMarker */{
-
-	// The process that we are editing
-	private Process process;
+public class BPELEditor extends GraphicalEditorWithPaletteAndTray /*, IGotoMarker */{
 
+	//FIXME can't move it to MultiPageEditor because of chicken and egg problem
 	// TODO: comment
 	protected BPELEditModelClient editModelClient;
 
-	protected ModelListenerAdapter modelListenerAdapter; 
-	
 	protected BPELEditorAdapter editorAdapter;
 	
 	// transfer buffer (clipboard) for graph copies
 	private TransferBuffer transferBuffer;
 
-	private Resource extensionsResource;
-	private ExtensionMap extensionMap;
-	
 	// This records all model changes for automatic undo/redo purposes.
 	private ModelAutoUndoRecorder modelAutoUndoRecorder;
 
@@ -233,9 +228,9 @@
 	
 	protected ICommandFramework commandFramework;
 	
-	public BPELEditor() {
+	public BPELEditor(DefaultEditDomain ed) {
 		super();
-		setEditDomain(new BPELEditDomain(this));
+		setEditDomain(ed);
 
 		transferBuffer = new TransferBuffer();
 
@@ -264,19 +259,21 @@
 	    return null;
 	}
 
-	//increasing visibility
-	public DefaultEditDomain getEditDomain() {
-		return super.getEditDomain();
+	public BPELEditModelClient getEditModelClient() {	
+		return editModelClient;
 	}
 	
-	public BPELEditModelClient getEditModelClient() {	return editModelClient; }
-	
+	public void setEditModelClient(BPELEditModelClient cl) {	
+		this.editModelClient = cl;
+	}
+
 	public ResourceSet getResourceSet() {
-		return editModelClient.getEditModel().getResourceSet();
+		return getEditModelClient().getEditModel().getResourceSet();
 	}
 
-	public Resource getResource() { return process.eResource(); }
+	public Resource getResource() { return getProcess().eResource(); }
 	public ModelAutoUndoRecorder getModelAutoUndoRecorder() { return modelAutoUndoRecorder; }
+	
 	public TransferBuffer getTransferBuffer() { return transferBuffer; }
 
 	public Set getAppendNewActions() { return appendNewActions; }
@@ -434,11 +431,13 @@
 	 * @see org.eclipse.ui.IWorkbenchPart#dispose()
 	 */
 	public void dispose() {
+		
 		if (editModelClient != null) {
-			editModelClient.getEditModel().getResourceSet().eAdapters().remove(editorAdapter);
+			editModelClient.getEditModel().getResourceSet().eAdapters().remove(getEditorAdapter());
 			editModelClient.dispose();
 			editModelClient = null;
 		}
+
 		if (getGraphicalViewer() != null) {
 			if (selectionChangeListener != null) {
 				getGraphicalViewer().removeSelectionChangedListener(selectionChangeListener);
@@ -457,6 +456,7 @@
 		if (getEditDomain() != null) {
 			getEditDomain().setPaletteViewer(null);
 		}
+		
 		if (getPaletteViewer() != null) {
 			getPaletteViewer().setContents(null);
 		}
@@ -494,7 +494,7 @@
 		// Hacks to work around memory leaks: break references to large structures.
 		// Various objects are holding onto a BPELEditor or ResourceSet and that's hard to fix.
 		transferBuffer.setContents(null);
-		process = null;
+
 		if (getEditDomain() != null) {
 			((BPELEditDomain)getEditDomain()).setProcess(null);
 		}
@@ -623,8 +623,8 @@
 
 		removeUnusedExtensions();
 		// Add all imports and namespaces to the artifacts file before saving.
-		if (editModelClient.getArtifactsResourceInfo() != null) {
-			Resource artifactsResource = editModelClient.getArtifactsResourceInfo().getResource();
+		if (getEditModelClient().getArtifactsResourceInfo() != null) {
+			Resource artifactsResource = getEditModelClient().getArtifactsResourceInfo().getResource();
 			
 			if (artifactsResource instanceof WSDLResourceImpl) {
 				// Add any missing imports/namespaces before saving!
@@ -654,8 +654,8 @@
 			}
 		}
 		try {
-			extensionsResource.setModified(false);			
-			editModelClient.saveAll(progressMonitor);					
+			getExtensionsResource().setModified(false);			
+			getEditModelClient().saveAll(progressMonitor);					
 			
 			//getModelDirtyTracker().markSaveLocation();
 
@@ -663,12 +663,12 @@
 			updateTitle();
 		}
 		// Put the timestamp of the bpel file into the bpelex file.
-		IFile bpelFile = BPELUtil.getBPELFile(process);
+		IFile bpelFile = BPELUtil.getBPELFile(getProcess());
 		long modificationStamp = bpelFile.getLocalTimeStamp();
-		ProcessExtension processExtension = (ProcessExtension)ModelHelper.getExtension(process);
+		ProcessExtension processExtension = (ProcessExtension)ModelHelper.getExtension(getProcess());
    		processExtension.setModificationStamp(modificationStamp);
-	    extensionsResource.setModified(true);
-	    editModelClient.saveAll(progressMonitor); 
+   		getExtensionsResource().setModified(true);
+   		getEditModelClient().saveAll(progressMonitor); 
 	}
 
 	// Disable our Save As functionality.
@@ -692,7 +692,7 @@
 		
 		IPath path = saveAsDialog.getResult();
 		if (path != null) {
-			return editModelClient.savePrimaryResourceAs(
+			return getEditModelClient().savePrimaryResourceAs(
 				ResourcesPlugin.getWorkspace().getRoot().getFile(path), 
 				getEditorSite().getActionBars().getStatusLineManager().getProgressMonitor());	
 		}
@@ -712,14 +712,10 @@
 	/**
 	 * @see org.eclipse.ui.IEditorPart#isDirty()
 	 */
-	public boolean isDirty() {
+	/*public boolean isDirty() {
 		return getCommandStack().isDirty();
-	}
+	}*/
 
-	public ExtensionMap getExtensionMap() {
-		return extensionMap;
-	}
-	
 	/**
 	 * @see org.eclipse.gef.ui.parts.GraphicalEditor#initializeGraphicalViewer()
 	 */
@@ -730,7 +726,10 @@
 		
 		BPELUIPlugin.getPlugin().getPreferenceStore().setValue(IBPELUIConstants.PREF_SHOW_FREEFORM_FLOW, true);
 		
-		getGraphicalViewer().setContents(process);
+
+		
+		getGraphicalViewer().setContents(getProcess());
+
 		this.selectionChangeListener = new ISelectionChangedListener() {
 			public void selectionChanged(SelectionChangedEvent event) {
 				StructuredSelection selection = (StructuredSelection)event.getSelection();
@@ -782,7 +781,7 @@
 		// Make a list of all FlowEditParts whose children all have no positional metadata
 		List flowsToArrange = new ArrayList();
 
-		for (TreeIterator it = process.eAllContents(); it.hasNext(); ) {
+		for (TreeIterator it = getProcess().eAllContents(); it.hasNext(); ) {
 			Object model = it.next();
 			if (model instanceof Flow) {
 				boolean missingLoc = false;
@@ -1109,18 +1108,48 @@
 	}
 	
 	public Process getProcess() {
-		return process;
+		IWorkbenchPartSite editorSite = getSite();
+		if (editorSite instanceof MultiPageEditorSite) {
+			return (Process)((org.eclipse.ui.part.MultiPageEditorSite)getSite()).getMultiPageEditor().getAdapter(Process.class);
+		}
+		return null;
+	}
+
+	public Resource getExtensionsResource (){
+		IWorkbenchPartSite editorSite = getSite();
+		if (editorSite instanceof MultiPageEditorSite) {
+			return (Resource)((org.eclipse.ui.part.MultiPageEditorSite)getSite()).getMultiPageEditor().getAdapter(Resource.class);
+		}
+		return null;
+	}
+
+	public ExtensionMap getExtensionMap (){
+		IWorkbenchPartSite editorSite = getSite();
+		if (editorSite instanceof MultiPageEditorSite) {
+			return (ExtensionMap)((org.eclipse.ui.part.MultiPageEditorSite)getSite()).getMultiPageEditor().getAdapter(ExtensionMap.class);
+		}
+		return null;
+	}
+
+	//FIXME should we kill it and move all the model listener adapter related
+	//things to BPELMultipageEditorPart?
+	public ModelListenerAdapter getModelListenerAdapter() { 
+		IWorkbenchPartSite editorSite = getSite();
+		if (editorSite instanceof MultiPageEditorSite) {
+			return (ModelListenerAdapter)((org.eclipse.ui.part.MultiPageEditorSite)getSite()).getMultiPageEditor().getAdapter(ModelListenerAdapter.class);
+		}
+		return null;
 	}
 	
 	/**
-	 * Increase the visibility of getCommandStack() so that the details area
-	 * can see it.
-	 * 
-	 * NOTE: This code is equivalent to GraphicalEditor.getCommandStack().
-	 * We explicitly use getEditDomain() to ensure consistency with replaceCommandStack().
+	 * Overriding to use BPELMultipageEditorPart command stack
 	 */
 	public CommandStack getCommandStack() {
-		return getEditDomain().getCommandStack();
+		IWorkbenchPartSite editorSite = getSite();
+		if (editorSite instanceof MultiPageEditorSite) {
+			return (CommandStack)((org.eclipse.ui.part.MultiPageEditorSite)getSite()).getMultiPageEditor().getAdapter(CommandStack.class);
+		}
+		return null;
 	}
 
 	public void setAutoFlowLayout(boolean autoLayout) {
@@ -1249,6 +1278,10 @@
 		return filteredEditPartSelectionProvider;
 	}
 
+	protected BPELEditorAdapter getEditorAdapter() {
+		return editorAdapter;
+	}
+
 	/**
 	 * Override getGraphicalViewer() to make the method public
 	 */
@@ -1320,6 +1353,7 @@
 	 * This is called during startup.
 	 */
 	public void init(IEditorSite site, IEditorInput editorInput) throws PartInitException {
+		
 		if (editorInput instanceof IFileEditorInput) {
 			try {
 				super.init(site, editorInput);
@@ -1327,22 +1361,15 @@
 				// remove the listener on the command stack created by the graphical editor
 				getCommandStack().removeCommandStackListener(this);
 
-				editModelClient = new BPELEditModelClient(this, getFileInput(), this, null);
-				getEditDomain().setCommandStack(editModelClient.getCommandStack());
-				
-				ResourceSet resourceSet = editModelClient.getEditModel().getResourceSet();
+				ResourceSet resourceSet = getEditModelClient().getEditModel().getResourceSet();
 
 				// TODO: does this stuff have to go?  it won't work with shared models..
-				modelListenerAdapter = new ModelListenerAdapter();
-				resourceSet.eAdapters().add(modelListenerAdapter);
+				resourceSet.eAdapters().add(getModelListenerAdapter());
 				resourceSet.eAdapters().add(editorAdapter = new BPELEditorAdapter());
-				this.modelListenerAdapter.setLinkNotificationAdapter(new LinkNotificationAdapter(this));
-				getCommandStack().addCommandStackListener(modelListenerAdapter);
+				getModelListenerAdapter().setLinkNotificationAdapter(new LinkNotificationAdapter(this));
+				getCommandStack().addCommandStackListener(getModelListenerAdapter());
 				
-				loadModel();
-				updateTitle();
-
-				commandFramework = new EditModelCommandFramework(editModelClient.getCommandStack());
+				commandFramework = new EditModelCommandFramework(getEditModelClient().getCommandStack());
 
 				// add a listener to the shared command stack
 				getCommandStack().addCommandStackListener(this);
@@ -1380,12 +1407,12 @@
 	// This is for loading the model within the editor
 	// REMINDER: Any changes to this method, consider corresponding changes to
 	// the loadModelWithoutEditModel() method!
-	protected void loadModel() {
+	/*protected void loadModel() {
 		// TODO: This two lines are a workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=72565
 		EcorePackage instance = EcorePackage.eINSTANCE;
-		instance.eAdapters();
+		instance.eAdapters();*/
 
-		Resource bpelResource = editModelClient.getPrimaryResourceInfo().getResource();
+		/*Resource bpelResource = editModelClient.getPrimaryResourceInfo().getResource();
 
 		IFile file = getFileInput();
 		BPELReader reader = new BPELReader();
@@ -1398,7 +1425,7 @@
 	    this.extensionsResource = reader.getExtensionsResource();
 	    this.extensionMap = reader.getExtensionMap();
 	    
-		this.modelListenerAdapter.setExtensionMap(extensionMap);
+		this.modelListenerAdapter.setExtensionMap(extensionMap);*/
 
 //		ProcessExtension processExtension = (ProcessExtension)ModelHelper.getExtension(process);
 //		long stamp = processExtension.getModificationStamp();
@@ -1420,59 +1447,7 @@
 //  		        //extensionMap = null;
 //   		    }
 //   		}
-	}
-	
-	// This is a hack for the report generator.
-	// REMINDER: Any changes to this method, consider corresponding changes to
-	// the loadModel() method!
-	public void loadModelWithoutEditModel() {
-		// TODO: This two lines are a workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=72565
-		EcorePackage instance = EcorePackage.eINSTANCE;
-		instance.eAdapters();
-
-		ResourceSet resourceSet = new ResourceSetImpl();
-		IFile file = getFileInput();
-		URI uri = URI.createPlatformResourceURI(file.getFullPath().toString());
-		Resource bpelResource = resourceSet.getResource(uri, true);
-
-		BPELReader reader = new BPELReader();
-	    reader.read(bpelResource, file, resourceSet);
-	    
-	    this.process = reader.getProcess();
-	    if (getEditDomain() != null) {
-	    	((BPELEditDomain)getEditDomain()).setProcess(process);
-	    }
-	    this.extensionsResource = reader.getExtensionsResource();
-	    this.extensionMap = reader.getExtensionMap();
-	    
-		modelListenerAdapter = new ModelListenerAdapter();
-		resourceSet.eAdapters().add(modelListenerAdapter);
-		resourceSet.eAdapters().add(new BPELEditorAdapter());
-	    
-		this.modelListenerAdapter.setExtensionMap(extensionMap);
-
-//		ProcessExtension processExtension = (ProcessExtension)ModelHelper.getExtension(process);
-//		long stamp = processExtension.getModificationStamp();
-//   		// Be nice if the file is old or doesn't yet have a stamp.
-//   		if (stamp != 0) {
-//   		    long actualStamp = file.getLocalTimeStamp();
-//   		    if (stamp != actualStamp) {
-//   		        // Inform the user that visual information will be discarded,
-//   		        // and null out the extension map. 
-//   		        // Only inform the user if we actually have a shell; headless clients
-//   		        // will not be informed.
-//   		        if (getSite() != null) {
-//   		            MessageDialog.openWarning(getSite().getShell(), "Process Out Of Sync", "The Process has been modified outside the editor and does not match the layout information stored for it.");
-//   		        }
-//   		        // TODO: Null out and recreate the extension map. Perhaps we need
-//   		        // to preserve some interesting bits of info about spec compliance
-//   		        // and implicit sequences. Don't null it out yet until we understand
-//   		        // all the cases in which this could occur.
-//  		        //extensionMap = null;
-//   		    }
-//   		}
-	    
-	}
+	/*}*/
 	
 	public ICommandFramework getCommandFramework() { return commandFramework; }
 
@@ -1489,7 +1464,7 @@
 		getTrayViewer().setContextMenu(provider);
 		getSite().registerContextMenu("org.eclipse.bpel.editor.tray.contextmenu", //$NON-NLS-1$
 			provider, getSite().getSelectionProvider());
-		getTrayViewer().setContents(process);
+		getTrayViewer().setContents(getProcess());
 
 		// Setup the drop target and add our listener to it.
 		// This will allow us to accept drops from the navigator.
@@ -1517,49 +1492,14 @@
 		getMultiViewerSelectionProvider().addViewer(viewer);		
 	}
 	
-
-	public void modelDeleted(ResourceInfo resourceInfo) {
-		if (!isDirty()) {
-			getSite().getPage().closeEditor(this, false);
-		}
-	}
-	
-	public void modelDirtyStateChanged(ResourceInfo resourceInfo) {
-		firePropertyChange(PROP_DIRTY);
-	}
-	
-	public void modelLocationChanged(ResourceInfo resourceInfo, IFile movedToFile) {
-		// TODO!
-		//updateInputFile(movedToFile.getFullPath());
+	/**
+	 * The editor part name should be the same as the one appearing in the logical view.
+	 */
+	//FIXME should be moved to multi or even removed at all
+	protected void updateTitle() {
+		setPartName(getProcess().getName());
 	}
 
-	public void modelReloaded(ResourceInfo resourceInfo) {
-		Resource bpelResource = editModelClient.getPrimaryResourceInfo().getResource();
-
-		IFile file = getFileInput();
-		BPELReader reader = new BPELReader();
-	    reader.read(bpelResource, file, getResourceSet());
-		 
-	    this.process = reader.getProcess();
-	    if (getEditDomain() != null) {
-	    	((BPELEditDomain)getEditDomain()).setProcess(process);
-	    }
-	    this.extensionMap = reader.getExtensionMap();
-	    
-		this.modelListenerAdapter.setExtensionMap(extensionMap);
-	
-		getGraphicalViewer().setContents(process);
-
-		// The ProcessTrayEditPart tries to remove its selection listener on deactivate.
-		// In this case, it will fail because the edit part can't find the editor because
-		// the process no longer belongs to a resource. Help it out and remove the
-		// listener manually.
-		ProcessTrayEditPart processTrayEditPart = (ProcessTrayEditPart)getTrayViewer().getContents();
-		getGraphicalViewer().removeSelectionChangedListener(processTrayEditPart.getSelectionChangedListener());
-		
-		getTrayViewer().setContents(process);
-	}
-	
 	protected boolean updateInputFile(IPath filePath) {
 		if (filePath == null) {
 			return false;
@@ -1576,13 +1516,6 @@
 		return true;
 	}
 	
-	/**
-	 * The editor part name should be the same as the one appearing in the logical view.
-	 */
-	protected void updateTitle() {
-		setPartName(process.getName());
-	}
-	
 	/** 
 	 * because our extensions are managed independently of the model and stored in a separate map, we have to make sure
 	 * that any extensions that are not used are removed before we serialize
Index: src/org/eclipse/bpel/ui/BPELMultipageEditorPart.java
===================================================================
RCS file: /cvsroot/technology/org.eclipse.bpel/plugins/org.eclipse.bpel.ui/src/org/eclipse/bpel/ui/Attic/BPELMultipageEditorPart.java,v
retrieving revision 1.1.2.2
diff -u -r1.1.2.2 BPELMultipageEditorPart.java
--- src/org/eclipse/bpel/ui/BPELMultipageEditorPart.java	8 Jun 2007 08:58:50 -0000	1.1.2.2
+++ src/org/eclipse/bpel/ui/BPELMultipageEditorPart.java	2 Jul 2007 14:57:21 -0000
@@ -12,16 +12,25 @@
 
 package org.eclipse.bpel.ui;
 
+import org.eclipse.bpel.common.extension.model.ExtensionMap;
+import org.eclipse.bpel.common.ui.editmodel.IEditModelListener;
+import org.eclipse.bpel.common.ui.editmodel.ResourceInfo;
 import org.eclipse.bpel.model.Activity;
 import org.eclipse.bpel.model.CorrelationSet;
 import org.eclipse.bpel.model.ExtensibleElement;
 import org.eclipse.bpel.model.PartnerLink;
+import org.eclipse.bpel.model.Process;
 import org.eclipse.bpel.model.Variable;
+import org.eclipse.bpel.ui.BPELEditor.BPELEditorAdapter;
+import org.eclipse.bpel.ui.editparts.ProcessTrayEditPart;
 import org.eclipse.bpel.ui.editparts.util.OutlineTreePartFactory;
 import org.eclipse.bpel.ui.properties.BPELPropertySection;
 import org.eclipse.bpel.ui.uiextensionmodel.StartNode;
+import org.eclipse.bpel.ui.util.BPELEditModelClient;
+import org.eclipse.bpel.ui.util.BPELReader;
 import org.eclipse.bpel.ui.util.ModelHelper;
 
+import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IMarker;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IProgressMonitor;
@@ -31,13 +40,17 @@
 import org.eclipse.draw2d.parts.ScrollableThumbnail;
 import org.eclipse.draw2d.parts.Thumbnail;
 import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
 import org.eclipse.gef.ContextMenuProvider;
+import org.eclipse.gef.DefaultEditDomain;
 import org.eclipse.gef.EditPart;
 import org.eclipse.gef.EditPartViewer;
 import org.eclipse.gef.GraphicalEditPart;
 import org.eclipse.gef.GraphicalViewer;
 import org.eclipse.gef.LayerConstants;
 import org.eclipse.gef.RootEditPart;
+import org.eclipse.gef.commands.CommandStack;
 import org.eclipse.gef.editparts.ZoomManager;
 import org.eclipse.gef.ui.actions.ActionRegistry;
 import org.eclipse.gef.ui.parts.ContentOutlinePage;
@@ -63,8 +76,10 @@
 import org.eclipse.ui.IActionBars;
 import org.eclipse.ui.IEditorInput;
 import org.eclipse.ui.IEditorSite;
+import org.eclipse.ui.IFileEditorInput;
 import org.eclipse.ui.IWorkbench;
 import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPartSite;
 import org.eclipse.ui.PartInitException;
 import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.actions.ActionFactory;
@@ -74,6 +89,7 @@
 import org.eclipse.ui.internal.views.properties.tabbed.view.TabbedPropertyViewer;
 import org.eclipse.ui.part.IPageSite;
 import org.eclipse.ui.part.MultiPageEditorPart;
+import org.eclipse.ui.part.MultiPageEditorSite;
 import org.eclipse.ui.part.PageBook;
 import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
 import org.eclipse.ui.views.properties.IPropertySheetPage;
@@ -85,7 +101,8 @@
 import org.w3c.dom.Element;
 
 public class BPELMultipageEditorPart extends MultiPageEditorPart 
-										implements IGotoMarker {
+										implements IEditModelListener, 
+										           IGotoMarker {
 
 	class OutlinePage extends ContentOutlinePage {
 		private PageBook pageBook;
@@ -106,7 +123,7 @@
 		}
 
 		private void configureOutlineViewer() {
-			getViewer().setEditDomain(fDesignViewer.getEditDomain());
+			getViewer().setEditDomain(getEditDomain());
 			getViewer().setEditPartFactory(new OutlineTreePartFactory());
 
 			fDesignViewer.registerViewer(getViewer());
@@ -160,8 +177,7 @@
 			// TODO: Add to the adapting selection provider
 			//getSelectionSynchronizer().addViewer(getViewer());
 
-			//FIXME move process to this class
-			getViewer().setContents(fDesignViewer.getProcess());
+			getViewer().setContents(getProcess());
 		}
 
 		private void initializeOverview() {
@@ -212,6 +228,15 @@
 		}
 	}
 
+	private Process process;
+	
+	private DefaultEditDomain editDomain;
+	
+	protected ModelListenerAdapter modelListenerAdapter;
+	
+	private Resource extensionsResource;
+	
+	private ExtensionMap extensionMap;
 	
 	private StructuredTextEditor fTextEditor = null;
 	private BPELEditor fDesignViewer = null;
@@ -221,7 +246,12 @@
 	
 	private static int DESIGN_PAGE_INDEX = 0;
 	private static int SOURCE_PAGE_INDEX = 1;
+
 	
+	public BPELMultipageEditorPart() {
+		super();
+		setEditDomain(new BPELEditDomain(this));
+	}
 	/**
 	 * Adds the source page of the multi-page editor.
 	 */
@@ -290,8 +320,9 @@
 	}
 
 	private void createAndAddDesignPage() {
-		fDesignViewer = new BPELEditor();
-
+		fDesignViewer = new BPELEditor(getEditDomain());
+		loadModel();
+		
 		try
 	    {
 			addPage(DESIGN_PAGE_INDEX, fDesignViewer, getEditorInput());
@@ -323,16 +354,24 @@
 			//Logger.logException(e);
 			throw new RuntimeException(e);
 		} 
+		
+		//updateTitle();
 	}
 
 
 	public void dispose() {
-		if (outlinePage != null && outlinePage.getViewer() != null) {
+		/*if (outlinePage != null && outlinePage.getViewer() != null) {
 			outlinePage.getViewer().setContents(null);
-		}
+		}*/
 		outlinePage = null;
-		fDesignViewer.dispose();
-		fTextEditor.dispose();
+ 
+		process = null;
+
+		//FIXME should we call them? Looks like no.
+		//fDesignViewer.dispose();
+		//fTextEditor.dispose();
+
+		super.dispose();
 	}
 	
 	/**
@@ -365,6 +404,34 @@
 
 	
 	public Object getAdapter(Class type) {
+		if (type == Process.class) {
+			return process;
+		}
+		
+		if (type == BPELEditModelClient.class) {
+			return process;
+		}
+
+		//FIXME should we kill it?
+		if (type == ModelListenerAdapter.class) {
+			return modelListenerAdapter;
+		}
+
+		//FIXME should we kill it?
+		if (type == Resource.class) {
+			return extensionsResource;
+		}
+
+		//FIXME should we kill it?
+		if (type == ExtensionMap.class) {
+			return extensionMap;
+		}
+
+		//FIXME should we kill it?
+		if (type == CommandStack.class) {
+			return getCommandStack();
+		}
+
 		if (type == IContentOutlinePage.class) {
 			if (outlinePage == null) {
 				outlinePage = new OutlinePage(new TreeViewer());
@@ -382,6 +449,26 @@
 	    return super.getAdapter(type);
 	  }
 
+	public CommandStack getCommandStack() {
+		return getEditDomain().getCommandStack();
+	}
+	
+	/**
+	 * Returns the edit domain.
+	 * @return the edit domain
+	 */
+	protected DefaultEditDomain getEditDomain() {
+		return editDomain;
+	}
+
+	protected IFile getFileInput() {
+		return ((IFileEditorInput) getEditorInput()).getFile();
+	}
+
+	public Process getProcess() {
+		return process;
+	}
+
 	StructuredTextEditor getTextEditor() {
 		return fTextEditor;
 	}
@@ -539,16 +626,6 @@
 		}
 	}
 	
-	protected void showPropertiesView() {
-		IWorkbench workbench = PlatformUI.getWorkbench();
-		IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
-		try {
-			page.showView(IBPELUIConstants.PROPERTY_VIEW_ID);
-		} catch (PartInitException e) {
-			BPELUIPlugin.log(e);
-		}
-	}
-
 	/*
 	 * (non-Javadoc)
 	 * 
@@ -572,5 +649,96 @@
 	public boolean isSaveAsAllowed() {
 		return false;
 	}
-}
 
+	private void loadModel() {
+		//FIXME WSDLEditor has gef command stack; in order to have gef command stack we need to add design page first 
+		BPELEditModelClient editModelClient = new BPELEditModelClient(this, ((IFileEditorInput) getEditorInput()).getFile(), this, null);
+		fDesignViewer.setEditModelClient(editModelClient);
+		getEditDomain().setCommandStack(editModelClient.getCommandStack());
+
+		Resource bpelResource = editModelClient.getPrimaryResourceInfo().getResource();
+		IFile file = getFileInput();
+		BPELReader reader = new BPELReader();
+	    reader.read(bpelResource, file, fDesignViewer.getResourceSet());
+	    process = reader.getProcess();
+	    
+	    if (getEditDomain() != null) {
+	    	((BPELEditDomain)getEditDomain()).setProcess(getProcess());
+	    }
+	    extensionsResource = reader.getExtensionsResource();
+	    extensionMap = reader.getExtensionMap();
+
+	    modelListenerAdapter = new ModelListenerAdapter();
+	    modelListenerAdapter.setExtensionMap(extensionMap);
+		
+	}
+
+	public void modelDeleted(ResourceInfo resourceInfo) {
+		if (!isDirty()) {
+			getSite().getPage().closeEditor(this, false);
+		}
+	}
+	
+	public void modelDirtyStateChanged(ResourceInfo resourceInfo) {
+		firePropertyChange(PROP_DIRTY);
+	}
+	
+	public void modelLocationChanged(ResourceInfo resourceInfo, IFile movedToFile) {
+		// TODO!
+		//updateInputFile(movedToFile.getFullPath());
+	}
+
+	public void modelReloaded(ResourceInfo resourceInfo) {
+		Resource bpelResource = fDesignViewer.getEditModelClient().getPrimaryResourceInfo().getResource();
+
+		IFile file = getFileInput();
+		BPELReader reader = new BPELReader();
+	    reader.read(bpelResource, file, fDesignViewer.getResourceSet());
+		 
+	    process = reader.getProcess();
+	    if (getEditDomain() != null) {
+	    	((BPELEditDomain)getEditDomain()).setProcess(getProcess());
+	    }
+	    extensionMap = reader.getExtensionMap();
+	    
+		modelListenerAdapter.setExtensionMap(fDesignViewer.getExtensionMap());
+	
+		fDesignViewer.getGraphicalViewer().setContents(getProcess());
+
+		// The ProcessTrayEditPart tries to remove its selection listener on deactivate.
+		// In this case, it will fail because the edit part can't find the editor because
+		// the process no longer belongs to a resource. Help it out and remove the
+		// listener manually.
+		ProcessTrayEditPart processTrayEditPart = (ProcessTrayEditPart)fDesignViewer.getTrayViewer().getContents();
+		fDesignViewer.getGraphicalViewer().removeSelectionChangedListener(processTrayEditPart.getSelectionChangedListener());
+		
+		fDesignViewer.getTrayViewer().setContents(getProcess());
+	}
+	
+
+	/**
+	 * Sets the EditDomain for this EditorPart.
+	 * @param ed the domain
+	 */
+	protected void setEditDomain(DefaultEditDomain ed) {
+		this.editDomain = ed;
+	}
+
+	protected void showPropertiesView() {
+		IWorkbench workbench = PlatformUI.getWorkbench();
+		IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
+		try {
+			page.showView(IBPELUIConstants.PROPERTY_VIEW_ID);
+		} catch (PartInitException e) {
+			BPELUIPlugin.log(e);
+		}
+	}
+	
+	/**
+	 * The editor part name should be the same as the one appearing in the logical view.
+	 */
+	protected void updateTitle() {
+		setPartName(getProcess().getName());
+	}
+
+}

Back to the top