Author: guixl
Date: Fri Jun 25 06:03:07 2010
New Revision: 957811

URL: http://svn.apache.org/viewvc?rev=957811&view=rev
Log:
Finish SCXML document import wizard pages creation jobs

Added:
    
commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingImportWizard.java
   (with props)
Modified:
    
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/export/ScxmlExportStreamHandlerAction.java

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=957811&r1=957810&r2=957811&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
 Fri Jun 25 06:03:07 2010
@@ -68,7 +68,7 @@
             name="%importWizardName"
             icon="icons/obj16/ScxmlDocumentImport.gif"
             category="org.apache.commons.scxml.modeling.import"
-            
class="org.apache.commons.scxml.modeling.diagram.part.ModelingCreationWizard"
+            
class="org.apache.commons.scxml.modeling.diagram.part.ModelingImportWizard"
             
id="org.apache.commons.scxml.modeling.diagram.part.ModelingImportWizardID">
                 <description>%importWizardDesc</description>  
       </wizard>

Added: 
commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingImportWizard.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/ModelingImportWizard.java?rev=957811&view=auto
==============================================================================
--- 
commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingImportWizard.java
 (added)
+++ 
commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingImportWizard.java
 Fri Jun 25 06:03:07 2010
@@ -0,0 +1,355 @@
+/*
+ * 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.diagram.part;
+
+import java.io.BufferedReader;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.lang.reflect.InvocationTargetException;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.commons.scxml.modeling.export.ScxmlExportStreamHandlerAction;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.jface.dialogs.ProgressMonitorDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.INewWizard;
+import org.eclipse.ui.IWorkbench;
+
+/**
+ * @generated
+ */
+public class ModelingImportWizard extends Wizard implements INewWizard {
+
+       /**
+        * @generated
+        */
+       private IWorkbench workbench;
+
+       /**
+        * @generated
+        */
+       protected IStructuredSelection selection;
+
+       /**
+        * @generated
+        */
+       protected ModelingCreationWizardPage domainModelFilePage;
+
+       protected DiagramDocumentImportSelectionPage documentImportSelectPage;
+
+       /**
+        * @generated
+        */
+       protected Resource diagram;
+
+       /**
+        * @generated
+        */
+       private boolean openNewlyCreatedDiagramEditor = true;
+
+       /**
+        * @generated
+        */
+       public IWorkbench getWorkbench() {
+               return workbench;
+       }
+
+       /**
+        * @generated
+        */
+       public IStructuredSelection getSelection() {
+               return selection;
+       }
+
+       /**
+        * @generated
+        */
+       public final Resource getDiagram() {
+               return diagram;
+       }
+
+       /**
+        * @generated
+        */
+       public final boolean isOpenNewlyCreatedDiagramEditor() {
+               return openNewlyCreatedDiagramEditor;
+       }
+
+       /**
+        * @generated
+        */
+       public void setOpenNewlyCreatedDiagramEditor(
+                       boolean openNewlyCreatedDiagramEditor) {
+               this.openNewlyCreatedDiagramEditor = 
openNewlyCreatedDiagramEditor;
+       }
+
+       /**
+        * @generated
+        */
+       public void init(IWorkbench workbench, IStructuredSelection selection) {
+               this.workbench = workbench;
+               this.selection = selection;
+               setWindowTitle(Messages.ModelingCreationWizardTitle);
+               setDefaultPageImageDescriptor(ModelingDiagramEditorPlugin
+                               
.getBundledImageDescriptor("icons/wizban/NewModelingWizard.gif")); //$NON-NLS-1$
+               setNeedsProgressMonitor(true);
+       }
+
+       /**
+        * @generated
+        */
+       public void addPages() {
+               documentImportSelectPage = new 
DiagramDocumentImportSelectionPage(
+                               "instance document import select page");
+               documentImportSelectPage.setTitle("title");
+               documentImportSelectPage.setDescription("descriptioin");
+               addPage(documentImportSelectPage);
+
+               domainModelFilePage = new ModelingCreationWizardPage(
+                               "DomainModelFile", getSelection(), "modeling") 
{ //$NON-NLS-1$ //$NON-NLS-2$
+
+                       public void setVisible(boolean visible) {
+                               if (visible) {
+                                       String fileName = 
domainModelFilePage.getFileName();
+                                       fileName = fileName.substring(0, 
fileName.length()
+                                                       - 
".modeling".length()); //$NON-NLS-1$
+                                       
setFileName(ModelingDiagramEditorUtil.getUniqueFileName(
+                                                       getContainerFullPath(), 
fileName, "modeling")); //$NON-NLS-1$
+                               }
+                               super.setVisible(visible);
+                       }
+               };
+               domainModelFilePage
+                               
.setTitle(Messages.ModelingCreationWizard_DomainModelFilePageTitle);
+               domainModelFilePage
+                               
.setDescription(Messages.ModelingCreationWizard_DomainModelFilePageDescription);
+               addPage(domainModelFilePage);
+       }
+
+       /**
+        * @generated
+        */
+       public boolean performFinish() {
+               try {
+                       List affectedFiles = new LinkedList();
+                       final IFile xmlFile = 
domainModelFilePage.createNewFile();
+                       affectedFiles.add(xmlFile);
+                       new ProgressMonitorDialog(null).run(true, false,
+                                       new ScxmlImportOperation(false, 
xmlFile));
+               } catch (InvocationTargetException e1) {
+                       e1.printStackTrace();
+               } catch (InterruptedException e1) {
+                       e1.printStackTrace();
+               }
+
+               return true;
+       }
+
+       class ScxmlImportOperation implements IRunnableWithProgress {
+
+               private boolean indeterminate;
+               private IFile xmlFile;
+
+               /**
+                * LongRunningOperation constructor
+                * 
+                * @param indeterminate
+                *            whether the animation is unknown
+                */
+               public ScxmlImportOperation(boolean indeterminate, IFile file) {
+                       this.indeterminate = indeterminate;
+                       xmlFile = file;
+               }
+
+               public IFile getXmlFile() {
+                       return xmlFile;
+               }
+
+               public void setXmlFile(IFile xmlFile) {
+                       this.xmlFile = xmlFile;
+               }
+
+               /**
+                * Runs the long running operation
+                * 
+                * @param monitor
+                *            the progress monitor
+                */
+               public void run(IProgressMonitor monitor)
+                               throws InvocationTargetException, 
InterruptedException {
+                       monitor.beginTask("SCXML document export progress", 9);
+
+                       try {
+                               String content = documentImportSelectPage
+                                               .getImportSCXMLContent();
+                               monitor.worked(1);
+                               monitor.worked(1);
+                               monitor.worked(1);
+                               monitor.worked(1);
+                               monitor.worked(1);
+                               monitor.worked(1);
+                               monitor.worked(1);
+                               xmlFile.setContents(new 
ScxmlExportStreamHandlerAction()
+                                               .string2InputStream(content), 
1, null);
+                               monitor.worked(1);
+                               if (monitor.isCanceled())
+                                       throw new InterruptedException(
+                                                       "The SCXML document 
import operation was cancelled");
+                               monitor.done();
+                       } catch (CoreException e) {
+                               e.printStackTrace();
+                       }
+               }
+       }
+
+       /**
+        * Document import selection page
+        */
+       private static class DiagramDocumentImportSelectionPage extends 
WizardPage {
+
+               private Text filePath;
+
+               private String importSCXMLContent;
+
+               // get SCXML document content
+               public String getImportSCXMLContent() {
+                       return importSCXMLContent;
+               }
+
+               /**
+                * @generated
+                */
+               protected DiagramDocumentImportSelectionPage(String pageName) {
+                       super(pageName);
+               }
+
+               /**
+                * @generated
+                */
+               protected String getSelectionTitle() {
+                       return 
Messages.ModelingNewScxmlFileWizard_RootSelectionPageSelectionTitle;
+               }
+
+               /**
+                * @generated
+                */
+               protected boolean validatePage() {
+                       if (filePath.getText() != null
+                                       && 
!filePath.getText().trim().equals(""))
+                               return true;
+                       else
+                               return false;
+               }
+
+               @Override
+               public void createControl(Composite parent) {
+                       // add controls
+                       initializeDialogUnits(parent);
+
+                       Composite plate = new Composite(parent, SWT.NONE);
+                       plate.setLayoutData(new GridData(GridData.FILL_BOTH));
+                       GridLayout layout = new GridLayout();
+                       layout.marginWidth = 0;
+                       plate.setLayout(layout);
+                       setControl(plate);
+
+                       Label label = new Label(plate, SWT.NONE);
+                       label.setText(getSelectionTitle());
+                       label.setLayoutData(new GridData(
+                                       GridData.HORIZONTAL_ALIGN_BEGINNING));
+
+                       filePath = new Text(plate, SWT.BORDER | SWT.READ_ONLY);
+                       filePath.setBounds(new Rectangle(0, 0, 300, 30));
+                       filePath.setLayoutData(new 
GridData(GridData.FILL_HORIZONTAL));
+
+                       final Button loadConfigBt = new Button(plate, SWT.PUSH);
+                       // loadConfigBt.setLayoutData(new GridData(SWT.FILL, 
SWT.FILL,
+                       // false, false, 1, 1));
+                       loadConfigBt.setText("Load Scxml Document");
+
+                       // Selection configuration(.xml file)
+                       loadConfigBt.addSelectionListener(new 
SelectionAdapter() {
+                               public void widgetSelected(SelectionEvent e) {
+                                       FileDialog dialog = new FileDialog(new 
Shell(), SWT.OPEN
+                                                       | 
SWT.APPLICATION_MODAL);
+                                       dialog.setFilterExtensions(new String[] 
{ "*.xml" });
+                                       String path = dialog.open();
+                                       if (path != null) {
+                                               filePath.setText(path);
+                                               parse(path);
+                                       }
+                                       setPageComplete(validatePage());
+                               }
+                       });
+
+                       setPageComplete(validatePage());
+               }
+
+               // parse imported SCXML document
+               public boolean parse(String file) {
+                       BufferedReader fin = null;
+                       try {
+                               fin = new BufferedReader(new InputStreamReader(
+                                               new FileInputStream(file)));
+                               StringBuffer buffer = new StringBuffer();
+                               String line = "";
+                               try {
+                                       while ((line = fin.readLine()) != null) 
{
+                                               buffer.append(line);
+                                       }
+                               } catch (IOException e) {
+                                       e.printStackTrace();
+                               }
+                               importSCXMLContent = buffer.toString();
+                               return true;
+                       } catch (FileNotFoundException e) {
+                               e.printStackTrace();
+                               return false;
+                       } finally {
+                               if (fin != null) {
+                                       try {
+                                               fin.close();
+                                       } catch (IOException ioE) {
+                                               ioE.printStackTrace();
+                                       }
+                               }
+
+                       }
+               }
+       }
+}

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

Modified: 
commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/src/org/apache/commons/scxml/modeling/export/ScxmlExportStreamHandlerAction.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/ScxmlExportStreamHandlerAction.java?rev=957811&r1=957810&r2=957811&view=diff
==============================================================================
--- 
commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/src/org/apache/commons/scxml/modeling/export/ScxmlExportStreamHandlerAction.java
 (original)
+++ 
commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/src/org/apache/commons/scxml/modeling/export/ScxmlExportStreamHandlerAction.java
 Fri Jun 25 06:03:07 2010
@@ -69,6 +69,10 @@ public class ScxmlExportStreamHandlerAct
                this.streamContnet = streamContnet;
        }
 
+       public ScxmlExportStreamHandlerAction(){
+               
+       }
+       
        public ScxmlExportStreamHandlerAction(InputStream in) {
                input = in;
                inputStream2String(input);


Reply via email to