Author: guixl
Date: Sun May 30 02:17:38 2010
New Revision: 949459

URL: http://svn.apache.org/viewvc?rev=949459&view=rev
Log:
amend data model : State has 0 or more sub States

Added:
    
commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/icons/obj16/ScxmlDocumentExport.gif
   (with props)
    
commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/src/org/apache/commons/scxml/modeling/export/
    
commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/src/org/apache/commons/scxml/modeling/export/ModelingDocumentExportWizard.java
   (with props)
    
commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/src/org/apache/commons/scxml/modeling/export/ScxmlDocumentExportMenu.java
   (with props)
Modified:
    
commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/messages.properties
    
commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/plugin.properties
    
commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/plugin.xml
    
commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/src/org/apache/commons/scxml/modeling/diagram/part/Messages.java

Added: 
commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/icons/obj16/ScxmlDocumentExport.gif
URL: 
http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/icons/obj16/ScxmlDocumentExport.gif?rev=949459&view=auto
==============================================================================
Binary file - no diff available.

Propchange: 
commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/icons/obj16/ScxmlDocumentExport.gif
------------------------------------------------------------------------------
    svn:mime-type = image/gif

Modified: 
commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/messages.properties
URL: 
http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/messages.properties?rev=949459&r1=949458&r2=949459&view=diff
==============================================================================
--- 
commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/messages.properties
 (original)
+++ 
commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/messages.properties
 Sun May 30 02:17:38 2010
@@ -24,6 +24,7 @@ ModelingDocumentProvider_SaveAsOperation
 ModelingInitDiagramFileAction_InitDiagramFileResourceErrorDialogTitle=Error
 ModelingInitDiagramFileAction_InitDiagramFileResourceErrorDialogMessage=Model 
file loading failed
 ModelingInitDiagramFileAction_InitDiagramFileWizardTitle=Initialize new {0} 
diagram file
+ModelingInitDiagramFileAction_ExportScxmlDocumentWizardTitle=Export scxml data 
model  file to document
 ModelingInitDiagramFileAction_OpenModelFileDialogTitle=Select domain model
 ModelingNewDiagramFileWizard_CreationPageName=Initialize new diagram file
 ModelingNewDiagramFileWizard_CreationPageTitle=Diagram file
@@ -43,6 +44,23 @@ ModelingDiagramEditor_SaveErrorTitle=Sav
 ModelingDiagramEditor_SaveErrorMessage=Could not save file.
 ModelingElementChooserDialog_SelectModelElementTitle=Select model element
 ModelElementSelectionPageMessage=Select model element:
+
+
+#model export label
+ModelingNewScxmlFileWizard_CreationPageName=Initialize new scxml file
+ModelingNewScxmlFileWizard_CreationPageTitle=Scxml file
+ModelingNewScxmlFileWizard_CreationPageDescription=Create new scxml based on 
{0} model content
+ModelingNewScxmlFileWizard_RootSelectionPageName=Select scxml file root element
+ModelingNewScxmlFileWizard_RootSelectionPageTitle=Scxml service root element
+ModelingNewScxmlFileWizard_RootSelectionPageDescription=Select semantic model 
element to be depicted on diagram
+ModelingNewScxmlFileWizard_RootSelectionPageSelectionTitle=Select scxml root 
element:
+ModelingNewScxmlFileWizard_RootSelectionPageNoSelectionMessage=Scxml root 
element is not selected
+ModelingNewScxmlFileWizard_RootSelectionPageInvalidSelectionMessage=Invalid 
scxml root element is selected
+ModelingNewScxmlFileWizard_InitDiagramCommand=Initializing scxml contents
+ModelingNewScxmlFileWizard_IncorrectRootError=Incorrect model object stored as 
a root resource object
+
+
+
 ValidateActionMessage=Validate
 ScxmlGroup_title_State=Scxml State Element
 ScxmlGroup_title_ExecuteContent=Execute Content

Modified: 
commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/plugin.properties
URL: 
http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/plugin.properties?rev=949459&r1=949458&r2=949459&view=diff
==============================================================================
--- 
commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/plugin.properties
 (original)
+++ 
commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/plugin.properties
 Sun May 30 02:17:38 2010
@@ -14,6 +14,7 @@ context.name=In Modeling Diagram Editor
 newWizardName=Modeling Diagram
 newWizardDesc=Creates Modeling diagram.
 
+exportScxmlDocumentLabel=Export Scxml Document
 initDiagramActionLabel=Initialize modeling_diagram diagram file
 loadResourceActionLabel=Load Resource...
 

Modified: 
commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/plugin.xml
URL: 
http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/plugin.xml?rev=949459&r1=949458&r2=949459&view=diff
==============================================================================
--- 
commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/plugin.xml
 (original)
+++ 
commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/plugin.xml
 Sun May 30 02:17:38 2010
@@ -81,10 +81,28 @@
                
class="org.apache.commons.scxml.modeling.diagram.part.ModelingInitDiagramFileAction"
                menubarPath="additions"
                enablesFor="1"
+                icon="icons/obj16/ModelingDiagramFile.gif"
                
id="org.apache.commons.scxml.modeling.diagram.InitDiagramAction">
          </action>
       </objectContribution>
    </extension>
+   
+   <extension point="org.eclipse.ui.popupMenus">
+   <objectContribution
+            objectClass="org.eclipse.core.resources.IFile"
+            nameFilter="*.modeling"
+            id="org.apache.commons.scxml.modeling.export">
+         <action
+                  enablesFor="1"
+               label="%exportScxmlDocumentLabel"
+               tooltip="%exportScxmlDocumentLabel"
+               
class="org.apache.commons.scxml.modeling.export.ScxmlDocumentExportMenu"
+               icon="icons/obj16/ScxmlDocumentExport.gif"
+               menubarPath="additions"
+               id="org.apache.commons.scxml.modeling.exportAction">
+         </action>
+      </objectContribution>
+      </extension>
        
    <extension 
point="org.eclipse.gmf.runtime.common.ui.services.action.globalActionHandlerProviders">
       <?gmfgen generated="true"?>

Modified: 
commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/src/org/apache/commons/scxml/modeling/diagram/part/Messages.java
URL: 
http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/src/org/apache/commons/scxml/modeling/diagram/part/Messages.java?rev=949459&r1=949458&r2=949459&view=diff
==============================================================================
--- 
commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/src/org/apache/commons/scxml/modeling/diagram/part/Messages.java
 (original)
+++ 
commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/src/org/apache/commons/scxml/modeling/diagram/part/Messages.java
 Sun May 30 02:17:38 2010
@@ -850,6 +850,21 @@ public class Messages extends NLS {
         * @generated
         */
        public static String ModelingModelingAssistantProviderMessage;
+       
+       public static String 
ModelingInitDiagramFileAction_ExportScxmlDocumentWizardTitle;
+       
+       public static String ModelingNewScxmlFileWizard_CreationPageName;
+       
+       public static String ModelingNewScxmlFileWizard_CreationPageTitle;
+       public static String ModelingNewScxmlFileWizard_CreationPageDescription;
+       public static String ModelingNewScxmlFileWizard_RootSelectionPageName;
+       public static String ModelingNewScxmlFileWizard_RootSelectionPageTitle;
+       public static String 
ModelingNewScxmlFileWizard_RootSelectionPageDescription;
+       public static String 
ModelingNewScxmlFileWizard_RootSelectionPageSelectionTitle;
+       public static String 
ModelingNewScxmlFileWizard_RootSelectionPageNoSelectionMessage;
+       public static String 
ModelingNewScxmlFileWizard_RootSelectionPageInvalidSelectionMessage;
+       public static String ModelingNewScxmlFileWizard_InitDiagramCommand;
+       public static String ModelingNewScxmlFileWizard_IncorrectRootError;
 
        //TODO: put accessor fields manually    
 }

Added: 
commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/src/org/apache/commons/scxml/modeling/export/ModelingDocumentExportWizard.java
URL: 
http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/src/org/apache/commons/scxml/modeling/export/ModelingDocumentExportWizard.java?rev=949459&view=auto
==============================================================================
--- 
commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/src/org/apache/commons/scxml/modeling/export/ModelingDocumentExportWizard.java
 (added)
+++ 
commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/src/org/apache/commons/scxml/modeling/export/ModelingDocumentExportWizard.java
 Sun May 30 02:17:38 2010
@@ -0,0 +1,227 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.scxml.modeling.export;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.LinkedList;
+import java.util.List;
+
+import 
org.apache.commons.scxml.modeling.diagram.edit.parts.ServiceTemplateEditPart;
+import org.apache.commons.scxml.modeling.diagram.part.Messages;
+import 
org.apache.commons.scxml.modeling.diagram.part.ModelElementSelectionPage;
+import 
org.apache.commons.scxml.modeling.diagram.part.ModelingDiagramEditorPlugin;
+import 
org.apache.commons.scxml.modeling.diagram.part.ModelingDiagramEditorUtil;
+import org.apache.commons.scxml.modeling.diagram.part.ModelingVisualIDRegistry;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.operations.OperationHistoryFactory;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.diagram.core.services.ViewService;
+import 
org.eclipse.gmf.runtime.diagram.core.services.view.CreateDiagramViewOperation;
+import 
org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
+
+/**
+ * Scxml document export wizard
+ * @author Gui Xun Long (gu...@apache.org)
+ */
+public class ModelingDocumentExportWizard extends Wizard {
+
+       /**
+        * @generated
+        */
+       private WizardNewFileCreationPage myFileCreationPage;
+
+       /**
+        * @generated
+        */
+       private ModelElementSelectionPage diagramRootElementSelectionPage;
+
+       /**
+        * @generated
+        */
+       private TransactionalEditingDomain myEditingDomain;
+       
+       /**
+        * model file 
+        */
+       private IFile modelFile;
+
+       /**
+        * @generated
+        */
+       public ModelingDocumentExportWizard(IFile file,URI domainModelURI,
+                       EObject diagramRoot, TransactionalEditingDomain 
editingDomain) {
+               modelFile=file;
+               assert domainModelURI != null : "Domain model uri must be 
specified"; //$NON-NLS-1$
+               assert diagramRoot != null : "Doagram root element must be 
specified"; //$NON-NLS-1$
+               assert editingDomain != null : "Editing domain must be 
specified"; //$NON-NLS-1$
+
+               myFileCreationPage = new WizardNewFileCreationPage(
+                               
Messages.ModelingNewScxmlFileWizard_CreationPageName,
+                               StructuredSelection.EMPTY);
+               myFileCreationPage
+                               
.setTitle(Messages.ModelingNewScxmlFileWizard_CreationPageTitle);
+               myFileCreationPage.setDescription(NLS.bind(
+                               
Messages.ModelingNewScxmlFileWizard_CreationPageDescription,
+                               ServiceTemplateEditPart.MODEL_ID));
+               IPath filePath;
+               String fileName = 
domainModelURI.trimFileExtension().lastSegment();
+               if (domainModelURI.isPlatformResource()) {
+                       filePath = new Path(domainModelURI.trimSegments(1)
+                                       .toPlatformString(true));
+               } else if (domainModelURI.isFile()) {
+                       filePath = new 
Path(domainModelURI.trimSegments(1).toFileString());
+               } else {
+                       throw new IllegalArgumentException(
+                                       "Unsupported URI: " + domainModelURI); 
//$NON-NLS-1$
+               }
+               myFileCreationPage.setContainerFullPath(filePath);
+               myFileCreationPage.setFileName(ModelingDiagramEditorUtil
+                               .getUniqueFileName(filePath, fileName, "xml")); 
//$NON-NLS-1$
+
+               diagramRootElementSelectionPage = new 
DiagramRootElementSelectionPage(
+                               
Messages.ModelingNewScxmlFileWizard_RootSelectionPageName);
+               diagramRootElementSelectionPage
+                               
.setTitle(Messages.ModelingNewScxmlFileWizard_RootSelectionPageTitle);
+               diagramRootElementSelectionPage
+                               
.setDescription(Messages.ModelingNewScxmlFileWizard_RootSelectionPageDescription);
+               diagramRootElementSelectionPage.setModelElement(diagramRoot);
+
+               myEditingDomain = editingDomain;
+               
+       }
+       
+       /**
+        * 
+        * @param is
+        * @return change InputStream to String object
+        * @throws IOException
+        */
+       public static String inputStream2String(InputStream is) throws 
IOException {  
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();  
+         int i = -1;  
+         while ((i = is.read()) != -1) {  
+             baos.write(i);  
+         }  
+         return baos.toString();  
+     }
+
+       /**
+        * @generated
+        */
+       public void addPages() {
+               addPage(myFileCreationPage);
+               addPage(diagramRootElementSelectionPage);
+       }
+
+       /**
+        * @generated
+        */
+       public boolean performFinish() {                
+               List affectedFiles = new LinkedList();
+               final IFile xmlFile = myFileCreationPage.createNewFile();
+               affectedFiles.add(xmlFile);
+               AbstractTransactionalCommand command = new 
AbstractTransactionalCommand(
+                               myEditingDomain,
+                               "Export scxml command",
+                               affectedFiles) {
+
+                       protected CommandResult doExecuteWithResult(
+                                       IProgressMonitor monitor, IAdaptable 
info)
+                                       throws ExecutionException {
+                               int diagramVID = ModelingVisualIDRegistry
+                                               
.getDiagramVisualID(diagramRootElementSelectionPage
+                                                               
.getModelElement());
+                               if (diagramVID != 
ServiceTemplateEditPart.VISUAL_ID) {
+                                       return CommandResult
+                                                       
.newErrorCommandResult(Messages.ModelingNewScxmlFileWizard_IncorrectRootError);
+                               }
+                               try {
+                                       
xmlFile.setContents(modelFile.getContents(), 1, null);
+                               }  catch (CoreException e) {
+                                       e.printStackTrace();
+                               }
+                               return CommandResult.newOKCommandResult();
+                       }
+               };
+
+               try {
+                       
OperationHistoryFactory.getOperationHistory().execute(command,new 
NullProgressMonitor(), null);
+               } catch (ExecutionException e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               }
+               return true;
+       }
+
+       /**
+        * @generated
+        */
+       private static class DiagramRootElementSelectionPage extends
+                       ModelElementSelectionPage {
+
+               /**
+                * @generated
+                */
+               protected DiagramRootElementSelectionPage(String pageName) {
+                       super(pageName);
+               }
+
+               /**
+                * @generated
+                */
+               protected String getSelectionTitle() {
+                       return 
Messages.ModelingNewScxmlFileWizard_RootSelectionPageSelectionTitle;
+               }
+
+               /**
+                * @generated
+                */
+               protected boolean validatePage() {
+                       if (selectedModelElement == null) {
+                               
setErrorMessage(Messages.ModelingNewScxmlFileWizard_RootSelectionPageNoSelectionMessage);
+                               return false;
+                       }
+                       boolean result = ViewService
+                                       .getInstance()
+                                       .provides(
+                                                       new 
CreateDiagramViewOperation(
+                                                                       new 
EObjectAdapter(selectedModelElement),
+                                                                       
ServiceTemplateEditPart.MODEL_ID,
+                                                                       
ModelingDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT));
+                       setErrorMessage(result ? null
+                                       : 
Messages.ModelingNewScxmlFileWizard_RootSelectionPageInvalidSelectionMessage);
+                       return result;
+               }
+       }
+}

Propchange: 
commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/src/org/apache/commons/scxml/modeling/export/ModelingDocumentExportWizard.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/src/org/apache/commons/scxml/modeling/export/ScxmlDocumentExportMenu.java
URL: 
http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/src/org/apache/commons/scxml/modeling/export/ScxmlDocumentExportMenu.java?rev=949459&view=auto
==============================================================================
--- 
commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/src/org/apache/commons/scxml/modeling/export/ScxmlDocumentExportMenu.java
 (added)
+++ 
commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/src/org/apache/commons/scxml/modeling/export/ScxmlDocumentExportMenu.java
 Sun May 30 02:17:38 2010
@@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.scxml.modeling.export;
+
+import 
org.apache.commons.scxml.modeling.diagram.edit.parts.ServiceTemplateEditPart;
+import org.apache.commons.scxml.modeling.diagram.part.Messages;
+import 
org.apache.commons.scxml.modeling.diagram.part.ModelingDiagramEditorPlugin;
+import 
org.apache.commons.scxml.modeling.diagram.part.ModelingDiagramEditorUtil;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.common.util.WrappedException;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.emf.core.GMFEditingDomainFactory;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.IWorkbenchPart;
+
+/**
+ * Scxml document export wizard
+ * @author Gui Xun Long (gu...@apache.org)
+ */
+public class ScxmlDocumentExportMenu implements IObjectActionDelegate{
+       /**
+        * @generated
+        */
+       private IWorkbenchPart targetPart;
+
+       /**
+        * @generated
+        */
+       private URI domainModelURI;
+       
+       private IFile file;
+
+       /**
+        * @generated
+        */
+       public void setActivePart(IAction action, IWorkbenchPart targetPart) {
+               this.targetPart = targetPart;
+       }
+
+       /**
+        * @generated
+        */
+       public void selectionChanged(IAction action, ISelection selection) {
+               domainModelURI = null;
+               action.setEnabled(false);
+               if (selection instanceof IStructuredSelection == false
+                               || selection.isEmpty()) {
+                       return;
+               }
+               file = (IFile) ((IStructuredSelection) selection)
+                               .getFirstElement();             
+               
+               domainModelURI = 
URI.createPlatformResourceURI(file.getFullPath()
+                               .toString(), true);
+               action.setEnabled(true);
+       }
+
+       /**
+        * @generated
+        */
+       private Shell getShell() {
+               return targetPart.getSite().getShell();
+       }
+
+       /**
+        * @generated
+        */
+       public void run(IAction action) {
+               TransactionalEditingDomain editingDomain = 
GMFEditingDomainFactory.INSTANCE
+                               .createEditingDomain();
+               ResourceSet resourceSet = editingDomain.getResourceSet();
+               EObject diagramRoot = null;
+               try {
+                       Resource resource = 
resourceSet.getResource(domainModelURI, true);
+                       diagramRoot = (EObject) resource.getContents().get(0);
+               } catch (WrappedException ex) {
+                       ModelingDiagramEditorPlugin.getInstance().logError(
+                                       "Unable to load resource: " + 
domainModelURI, ex); //$NON-NLS-1$
+               }
+               if (diagramRoot == null) {
+                       MessageDialog
+                                       .openError(
+                                                       getShell(),
+                                                       
Messages.ModelingInitDiagramFileAction_InitDiagramFileResourceErrorDialogTitle,
+                                                       
Messages.ModelingInitDiagramFileAction_InitDiagramFileResourceErrorDialogMessage);
+                       return;
+               }
+               Wizard wizard = new 
ModelingDocumentExportWizard(file,domainModelURI,
+                               diagramRoot, editingDomain);
+               wizard
+                               .setWindowTitle(NLS
+                                               .bind(
+                                                               
Messages.ModelingInitDiagramFileAction_ExportScxmlDocumentWizardTitle,
+                                                               
ServiceTemplateEditPart.MODEL_ID));
+               ModelingDiagramEditorUtil.runWizard(getShell(), wizard,
+                               "ExportScxmlDocument"); //$NON-NLS-1$
+       }
+}

Propchange: 
commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/src/org/apache/commons/scxml/modeling/export/ScxmlDocumentExportMenu.java
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to