commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gu...@apache.org
Subject svn commit: r953000 - in /commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/src/org/apache/commons/scxml/modeling/export: ExportProgressMonitor.java ModelingDocumentExportWizard.java
Date Wed, 09 Jun 2010 13:41:15 GMT
Author: guixl
Date: Wed Jun  9 13:41:14 2010
New Revision: 953000

URL: http://svn.apache.org/viewvc?rev=953000&view=rev
Log:
add SCXML document export progress monitor 

Added:
    commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/src/org/apache/commons/scxml/modeling/export/ExportProgressMonitor.java
  (with props)
Modified:
    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/ExportProgressMonitor.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/ExportProgressMonitor.java?rev=953000&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/ExportProgressMonitor.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/ExportProgressMonitor.java
Wed Jun  9 13:41:14 2010
@@ -0,0 +1,56 @@
+package org.apache.commons.scxml.modeling.export;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+
+public class ExportProgressMonitor implements IProgressMonitor{
+
+	/**
+	 * Indicates whether cancel has been requested.
+	 */
+	private boolean cancelled = false;
+	
+	@Override
+	public void beginTask(String name, int totalWork) {
+		
+	}
+
+	@Override
+	public void done() {
+		
+	}
+
+	@Override
+	public void internalWorked(double work) {
+		// TODO Auto-generated method stub
+		
+	}
+
+	@Override
+	public boolean isCanceled() {
+		return cancelled;
+	}
+
+	@Override
+	public void setCanceled(boolean value) {
+		this.cancelled = cancelled;
+	}
+
+	@Override
+	public void setTaskName(String name) {
+		// TODO Auto-generated method stub
+		
+	}
+
+	@Override
+	public void subTask(String name) {
+		// TODO Auto-generated method stub
+		
+	}
+
+	@Override
+	public void worked(int work) {
+		// TODO Auto-generated method stub
+		
+	}
+
+}

Propchange: commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.modeling.diagram/src/org/apache/commons/scxml/modeling/export/ExportProgressMonitor.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/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=953000&r1=952999&r2=953000&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/ModelingDocumentExportWizard.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/ModelingDocumentExportWizard.java
Wed Jun  9 13:41:14 2010
@@ -19,7 +19,7 @@ package org.apache.commons.scxml.modelin
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.util.ArrayList;
+import java.lang.reflect.InvocationTargetException;
 import java.util.LinkedList;
 import java.util.List;
 
@@ -29,23 +29,19 @@ import org.apache.commons.scxml.modeling
 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.dialogs.ProgressMonitorDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
 import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.jface.wizard.Wizard;
 import org.eclipse.osgi.util.NLS;
@@ -53,6 +49,7 @@ import org.eclipse.ui.dialogs.WizardNewF
 
 /**
  * Scxml document export wizard
+ * 
  * @author Gui Xun Long (guixl@apache.org)
  */
 public class ModelingDocumentExportWizard extends Wizard {
@@ -71,18 +68,18 @@ public class ModelingDocumentExportWizar
 	 * @generated
 	 */
 	private TransactionalEditingDomain myEditingDomain;
-	
+
 	/**
-	 * model file 
+	 * model file
 	 */
 	private IFile modelFile;
 
 	/**
 	 * @generated
 	 */
-	public ModelingDocumentExportWizard(IFile file,URI domainModelURI,
+	public ModelingDocumentExportWizard(IFile file, URI domainModelURI,
 			EObject diagramRoot, TransactionalEditingDomain editingDomain) {
-		modelFile=file;
+		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$
@@ -119,23 +116,23 @@ public class ModelingDocumentExportWizar
 		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();  
-     }
+	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
@@ -148,51 +145,106 @@ public class ModelingDocumentExportWizar
 	/**
 	 * @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 {
-					//get target list by regular expression
-					ScxmlExportStreamHandlerAction shc=new ScxmlExportStreamHandlerAction(modelFile.getContents());
-					shc.getTargetList();
-					shc.transferToXpath();
-					shc.getIdMap(modelFile.getContents());
-					shc.updateTargetId();
-					System.out.println(shc.getStreamContnet());
-					String content=shc.ExecuteXSL(shc.getStreamContnet(),this.getClass().getClassLoader().getResourceAsStream("xslt/export.xsl"));
-					xmlFile.setContents(shc.string2InputStream(content), 1, null);
-				}  catch (CoreException e) {
-					e.printStackTrace();
-				}
-				return CommandResult.newOKCommandResult();
-			}
-		};
-
+	public boolean performFinish() {
 		try {
-			OperationHistoryFactory.getOperationHistory().execute(command,new NullProgressMonitor(),
null);
-		} catch (ExecutionException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
+			List affectedFiles = new LinkedList();
+			final IFile xmlFile = myFileCreationPage.createNewFile();
+			affectedFiles.add(xmlFile);
+			new ProgressMonitorDialog(null).run(true, false,
+					new ScxmlExportOperation(false,xmlFile));
+		} catch (InvocationTargetException e1) {
+			e1.printStackTrace();
+		} catch (InterruptedException e1) {
+			e1.printStackTrace();
 		}
+
 		return true;
 	}
 
+	class ScxmlExportOperation implements IRunnableWithProgress {
+
+		private boolean indeterminate;
+		private IFile xmlFile;
+
+		/**
+		 * LongRunningOperation constructor
+		 * 
+		 * @param indeterminate
+		 *            whether the animation is unknown
+		 */
+		public ScxmlExportOperation(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 {
+
+			int diagramVID = ModelingVisualIDRegistry
+					.getDiagramVisualID(diagramRootElementSelectionPage
+							.getModelElement());
+			monitor.beginTask("SCXML document export progress",7);
+			
+			try {
+				
+				
+				// get target list by regular expression
+				ScxmlExportStreamHandlerAction shc = new ScxmlExportStreamHandlerAction(
+						modelFile.getContents());
+				shc.getTargetList();
+				monitor.worked(1);
+				shc.transferToXpath();
+				monitor.worked(1);
+				shc.getIdMap(modelFile.getContents());
+				monitor.worked(1);
+				shc.updateTargetId();
+				monitor.worked(1);
+				System.out.println(shc.getStreamContnet());
+				String content = shc.ExecuteXSL(shc.getStreamContnet(), this
+						.getClass().getClassLoader().getResourceAsStream(
+								"xslt/export.xsl"));
+				monitor.worked(1);
+				xmlFile.setContents(shc.string2InputStream(content), 1, null);
+				monitor.worked(1);
+				if (monitor.isCanceled()) throw new InterruptedException(
+				"The SCXML document export operation was cancelled");
+				
+				monitor.done();
+			} catch (CoreException e) {
+				e.printStackTrace();
+			}
+
+			/*// ¿ªÊ¼´¦Àí½ø¶È£¬Èç¹ûindeterminateΪfalse,Õû¸ö½ø¶ÈΪTOTAL_TIME
= 10000
+			// ·ñÔò£¬½ø¶ÈÌõΪ×Ô¶¯Ôö¼ÓµÄ
+			for (int total = 0; total < TOTAL_TIME && !monitor.isCanceled(); total += INCREMENT)
{
+				Thread.sleep(INCREMENT);
+				monitor.worked(INCREMENT);
+				// µ½´ïÒ»°ëµÄʱ¼äÏÔʾÏàÓ¦µÄÐÅÏ¢
+				if (total == TOTAL_TIME / 2)
+					monitor.subTask("Doing second half");
+			}
+			// Íê³ÉÈÎÎñ
+			monitor.done();
+			if (monitor.isCanceled())
+				throw new InterruptedException(
+						"The long running operation was cancelled");*/
+		}
+	}
+
 	/**
 	 * @generated
 	 */



Mime
View raw message