Author: Grid.Qian
Date: 2008-09-01 22:11:06 -0400 (Mon, 01 Sep 2008)
New Revision: 10007
Added:
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/bpmnto/action/
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/bpmnto/action/BpmnToAction.java
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/bpmnto/dialog/
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/bpmnto/dialog/GeneratedFilesLocationDialog.java
Modified:
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/b2j/action/B2JAction.java
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/b2j/messages/B2J.properties
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/b2j/messages/B2JMessages.java
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/b2j/translate/BPMN2JPDL.java
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/bpmnto/util/BPMNToUtil.java
Log:
add some dialogs for translate
Modified:
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/b2j/action/B2JAction.java
===================================================================
---
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/b2j/action/B2JAction.java 2008-09-01
23:13:10 UTC (rev 10006)
+++
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/b2j/action/B2JAction.java 2008-09-02
02:11:06 UTC (rev 10007)
@@ -11,16 +11,24 @@
package org.jboss.tools.b2j.action;
+import java.util.ArrayList;
+import java.util.List;
+
import org.dom4j.Document;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.dialogs.ListDialog;
import org.jboss.tools.b2j.messages.B2JMessages;
import org.jboss.tools.b2j.translate.BPMN2JPDL;
import org.jboss.tools.b2j.translate.GraphicalFileGenerator;
@@ -30,7 +38,7 @@
/**
* @author Grid Qian
*
- * the popup menu action for bpmn ->jpdl
+ * the popup menu action for bpmn ->jpdl
*/
public class B2JAction implements IObjectActionDelegate {
@@ -44,6 +52,60 @@
String bpmnFileName = bpmnFile.getName();
String bpmnFileParentPath = bpmnFile.getParent().getLocation()
.toOSString();
+ translateBpmn(bpmnFileParentPath, bpmnFileName);
+ }
+
+ public void translateBpmn(String bpmnFileParentPath, String bpmnFileName) {
+ Document bpmnDocument = getDocument(bpmnFileParentPath, bpmnFileName);
+
+ List<String> warningList = new ArrayList<String>();
+ List<String> errorList = new ArrayList<String>();
+
+ List<String> poolIdList =
BPMNToUtil.selectElement(BPMNToUtil.getPoolIDsFromDocument(bpmnDocument));
+ BPMN2JPDL translator = new BPMN2JPDL(bpmnFileName, bpmnFileParentPath,poolIdList,
bpmnDocument);
+
+ translator.translateToFiles(BPMNToUtil.getGeneratedFileLocation() == null ?
bpmnFileParentPath:BPMNToUtil.getGeneratedFileLocation());
+
+ warningList.addAll(translator.getWarnings());
+ errorList.addAll(translator.getErrors());
+
+ // generate jpdl gpd file from *.bpmn_diagram
+ Document bpmnDiagramDocument = getDocument(bpmnFileParentPath,
+ TranslateHelper.getBpmnDiagramName(bpmnFileName));
+ GraphicalFileGenerator generator = new GraphicalFileGenerator(
+ bpmnDiagramDocument, translator.getMap(), bpmnFileParentPath,
+ bpmnFileName);
+ generator.translateToFiles();
+
+ warningList.addAll(generator.getWarnings());
+ errorList.addAll(generator.getErrors());
+
+ showErrors(warningList,errorList);
+ refreshWorkspace();
+ }
+
+ private void showErrors(List<String> warningList, List<String> errorList) {
+ List<String> list = new ArrayList<String>();
+ list.addAll(errorList);
+ list.addAll(warningList);
+ if(list.size() == 0){
+ return;
+ }
+
+ ListDialog dialog = new ListDialog(Display.getCurrent().getActiveShell());
+ dialog.setTitle(B2JMessages.Bpmn_Translate_Message_Dialog_Title);
+ dialog.setMessage(B2JMessages.Bpmn_Translate_Message_Dialog_Message);
+
+ dialog.setInput(list);
+ ILabelProvider labelProvider = new LabelProvider();
+ ArrayContentProvider contentProvider = new ArrayContentProvider();
+ dialog.setContentProvider(contentProvider);
+ dialog.setLabelProvider(labelProvider);
+ dialog.open();
+ dialog.getResult();
+ }
+
+ public Document getDocument(String bpmnFileParentPath, String bpmnFileName) {
Document bpmnDocument = null;
try {
bpmnDocument = BPMNToUtil.parse(bpmnFileParentPath, bpmnFileName);
@@ -51,32 +113,14 @@
System.out.println(B2JMessages.Translate_Error_BpmnFile_CanNotRead
+ e1.getMessage());
}
- BPMN2JPDL translator = new BPMN2JPDL(bpmnFileName, bpmnFileParentPath,
- bpmnDocument);
- translator.translateToFiles();
+ return bpmnDocument;
+ }
- // generate jpdl gpd file from *.bpmn_diagram
- String bpmnDiagramFileName = TranslateHelper
- .getBpmnDiagramName(bpmnFileName);
- Document bpmnDiagramDocument = null;
+ public void refreshWorkspace() {
try {
- bpmnDiagramDocument = BPMNToUtil.parse(bpmnFileParentPath,
- bpmnDiagramFileName);
- } catch (Exception e1) {
- System.out
- .println(B2JMessages.Translate_Error_BpmnDiagramFile_CanNotRead
- + e1.getMessage());
- }
- GraphicalFileGenerator generator = new GraphicalFileGenerator(
- bpmnDiagramDocument, translator.getMap(), bpmnFileParentPath,
- bpmnFileName);
- generator.translateToFiles();
-
- try {
ResourcesPlugin.getWorkspace().getRoot().refreshLocal(
IResource.DEPTH_INFINITE, null);
} catch (CoreException e) {
- // TODO Auto-generated catch block
e.printStackTrace();
}
}
Modified:
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/b2j/messages/B2J.properties
===================================================================
---
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/b2j/messages/B2J.properties 2008-09-01
23:13:10 UTC (rev 10006)
+++
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/b2j/messages/B2J.properties 2008-09-02
02:11:06 UTC (rev 10007)
@@ -22,6 +22,12 @@
Bpmn_FlowTarget_Attribute_Name=target
Bpmn_FlowDefault_Attribute_Name=isDefault
Bpmn_Element_ID=iD
+Bpmn_Pool_Choose_Dialog_Message=Available BPMN Pools
+Bpmn_Pool_Choose_Dialog_Title=Select BPMN pools to translate
+Bpmn_GeneratedFile_Location_Dialog_Message=Please choose the generated files location. If
click Cancel, the generated files will be put under the project
+Bpmn_GeneratedFile_Location_Dialog_Title=Select the generated files location
+Bpmn_Translate_Message_Dialog_Title=Warnings and Errors
+Bpmn_Translate_Message_Dialog_Message=The messages are errors and warnings during the
translation:
Jpdl_Suffix=jpdl
Jpdl_Process_Definition_Name=processdefinition.xml
Jpdl_32_Namespace_Url=urn:jbpm.org:jpdl-3.2
@@ -41,12 +47,12 @@
Gpd_Element_Name=element
Gpd_Process_Diagram_Name=process-diagram
Gpd_Label_Element_Name=label
-Translate_Error_GpdFile_CanNotGenerate=Couldn't write gpd.xml:
-Translate_Error_GpdFile_CanNotWrite=Couldn't write gpd definition to a gpd.xml:
-Translate_Error_JpdlProcess_Definition_Null=The JPDL process definition is null.
-Translate_Error_JpdlFile_CanNotGenerate=Couldn't write process definition xml:
-Translate_Error_JpdlFile_CanNotWrite=Couldn't write process definition to a jpdl
file:
-Translate_Error_BpmnFile_CanNotRead=Couldn't read or parse bpmn file to a DOM
document:
+Translate_Error_GpdFile_CanNotGenerate=Errror: Couldn't write gpd.xml:
+Translate_Error_GpdFile_CanNotWrite=Errror: Couldn't write gpd definition to a
gpd.xml:
+Translate_Error_JpdlProcess_Definition_Null=Errror: The JPDL process definition is null.
+Translate_Error_JpdlFile_CanNotGenerate=Errror: Couldn't write process definition
xml:
+Translate_Error_JpdlFile_CanNotWrite=Errror: Couldn't write process definition to a
jpdl file:
+Translate_Error_BpmnFile_CanNotRead=Errror: Couldn't read or parse bpmn file to a DOM
document:
Translate_Error_BpmnDiagramFile_CanNotRead=Couldn't read or parse bpmn_diagram file
to a DOM document:
-Translate_Warning_Bpmn_Element_Name= The bpmn element's name is null or same to
another element's name:
-Translate_Warning_Bpmn_Element_Type=The type of this bpmn element is not translated to
corresponding jpdl element:
\ No newline at end of file
+Translate_Warning_Bpmn_Element_Name=Warning: The bpmn element's name is null or same
to another element's name:
+Translate_Warning_Bpmn_Element_Type=Warning: The type of this bpmn element is not
translated to corresponding jpdl element:
\ No newline at end of file
Modified:
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/b2j/messages/B2JMessages.java
===================================================================
---
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/b2j/messages/B2JMessages.java 2008-09-01
23:13:10 UTC (rev 10006)
+++
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/b2j/messages/B2JMessages.java 2008-09-02
02:11:06 UTC (rev 10007)
@@ -29,6 +29,10 @@
public static String Folder_Name_Separator;
public static String Space;
public static String Underline;
+ public static String Width_Attribute_Name;
+ public static String Height_Attribute_Name;
+ public static String X_Attribute_Name;
+ public static String Y_Attribute_Name;
public static String Bpmn_Diagram_Name_Suffix;
public static String Bpmn_Pool_Element_Name;
public static String Bpmn_Element_ID;
@@ -38,14 +42,16 @@
public static String Bpmn_InFlow_Attribute_Name;
public static String Bpmn_XmiType_Attribute_Name;
public static String Bpmn_Href_Attribute_Name;
- public static String Width_Attribute_Name;
- public static String Height_Attribute_Name;
- public static String X_Attribute_Name;
- public static String Y_Attribute_Name;
public static String Bpmn_ActivityType_Attribute_Name;
public static String Bpmn_FlowSource_Attribute_Name;
public static String Bpmn_FlowTarget_Attribute_Name;
public static String Bpmn_FlowDefault_Attribute_Name;
+ public static String Bpmn_Pool_Choose_Dialog_Message;
+ public static String Bpmn_Pool_Choose_Dialog_Title;
+ public static String Bpmn_GeneratedFile_Location_Dialog_Message;
+ public static String Bpmn_GeneratedFile_Location_Dialog_Title;
+ public static String Bpmn_Translate_Message_Dialog_Title;
+ public static String Bpmn_Translate_Message_Dialog_Message;
public static String Jpdl_Suffix;
public static String Jpdl_Process_Definition_Name;
public static String Jpdl_ProcessState_Element_Name;
Modified:
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/b2j/translate/BPMN2JPDL.java
===================================================================
---
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/b2j/translate/BPMN2JPDL.java 2008-09-01
23:13:10 UTC (rev 10006)
+++
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/b2j/translate/BPMN2JPDL.java 2008-09-02
02:11:06 UTC (rev 10007)
@@ -82,7 +82,7 @@
/*
* Translate a bpmn diagram to file[]. Every file is a jpdl file
*/
- public void translateToFiles() {
+ public void translateToFiles(String fileLocation) {
String[] strForProcessDefs = translateToStrings();
String[] jpdlFileNames = new String[processDefs.size()];
@@ -93,7 +93,7 @@
}
try {
- TranslateHelper.createFiles(rootLocation, bpmnFileName,
+ TranslateHelper.createFiles(fileLocation, bpmnFileName,
strForProcessDefs, jpdlFileNames,
B2JMessages.Jpdl_Process_Definition_Name);
} catch (Exception e) {
Added:
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/bpmnto/action/BpmnToAction.java
===================================================================
---
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/bpmnto/action/BpmnToAction.java
(rev 0)
+++
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/bpmnto/action/BpmnToAction.java 2008-09-02
02:11:06 UTC (rev 10007)
@@ -0,0 +1,5 @@
+package org.jboss.tools.bpmnto.action;
+
+public class BpmnToAction {
+
+}
Added:
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/bpmnto/dialog/GeneratedFilesLocationDialog.java
===================================================================
---
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/bpmnto/dialog/GeneratedFilesLocationDialog.java
(rev 0)
+++
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/bpmnto/dialog/GeneratedFilesLocationDialog.java 2008-09-02
02:11:06 UTC (rev 10007)
@@ -0,0 +1,16 @@
+package org.jboss.tools.bpmnto.dialog;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.dialogs.TitleAreaDialog;
+
+public class GeneratedFilesLocationDialog {
+ MessageDialog dd = null;
+
+ TitleAreaDialog ee;
+
+ void get(){
+
+ }
+
+}
Modified:
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/bpmnto/util/BPMNToUtil.java
===================================================================
---
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/bpmnto/util/BPMNToUtil.java 2008-09-01
23:13:10 UTC (rev 10006)
+++
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/bpmnto/util/BPMNToUtil.java 2008-09-02
02:11:06 UTC (rev 10007)
@@ -18,19 +18,35 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.dom4j.Document;
+import org.dom4j.Element;
import org.dom4j.io.SAXReader;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.widgets.DirectoryDialog;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.dialogs.ListSelectionDialog;
+import org.jboss.tools.b2j.messages.B2JMessages;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
/**
* @author Grid Qian
*
- * this a util class
+ * this a util class
*/
public class BPMNToUtil {
@@ -63,7 +79,8 @@
*/
public static InputSource getInputSource(String parentFolder,
String fileName) throws FileNotFoundException {
- return new InputSource(BPMNToUtil.getInputStream(parentFolder, fileName));
+ return new InputSource(BPMNToUtil
+ .getInputStream(parentFolder, fileName));
}
@@ -85,8 +102,8 @@
throws Exception {
Document document = null;
SAXReader saxReader = createSaxReader();
- document = saxReader.read(BPMNToUtil
- .getInputSource(parentFolder, fileName));
+ document = saxReader.read(BPMNToUtil.getInputSource(parentFolder,
+ fileName));
return document;
}
@@ -127,4 +144,56 @@
return saxParserFactory;
}
+ /*
+ * get bpmn pool id list from a dom document
+ */
+ public static Set<Map.Entry<String, String>> getPoolIDsFromDocument(
+ Document document) {
+ Map<String, String> poolIDMap = new HashMap<String, String>();
+ Element diagram = document.getRootElement();
+ for (Object pool : diagram.elements(B2JMessages.Bpmn_Pool_Element_Name)) {
+ if (((Element) pool).attributeValue(B2JMessages.Bpmn_Element_ID) != null) {
+ poolIDMap.put(((Element) pool)
+ .attributeValue(B2JMessages.Bpmn_Element_ID),
+ ((Element) pool)
+ .attributeValue(B2JMessages.Dom_Element_Name));
+ }
+ }
+ return poolIDMap.entrySet();
+ }
+
+ /*
+ * choose some bpmn pool ids from a ids array
+ */
+ @SuppressWarnings("unchecked")
+ public static List<String> selectElement(
+ Set<Map.Entry<String, String>> idSet) {
+ Shell shell = Display.getCurrent().getActiveShell();
+ ILabelProvider labelProvider = new LabelProvider();
+ ArrayContentProvider contentProvider = new ArrayContentProvider();
+ ListSelectionDialog dialog = new ListSelectionDialog(shell, idSet,
+ contentProvider, labelProvider, null);
+ dialog.setMessage(B2JMessages.Bpmn_Pool_Choose_Dialog_Message);
+ dialog.setTitle(B2JMessages.Bpmn_Pool_Choose_Dialog_Title);
+ Object[] selected = null;
+ if (dialog.open() == Window.OK) {
+ selected = dialog.getResult();
+ }
+ List<String> list = new LinkedList<String>();
+ for (Object entry : selected) {
+ list.add(((Entry<String, String>) entry).getKey());
+ }
+ return list;
+ }
+
+ public static String getGeneratedFileLocation() {
+ DirectoryDialog dialog = new DirectoryDialog(Display.getCurrent()
+ .getActiveShell());
+ dialog.setText(B2JMessages.Bpmn_GeneratedFile_Location_Dialog_Title);
+ dialog
+ .setMessage(B2JMessages.Bpmn_GeneratedFile_Location_Dialog_Message);
+ String path = dialog.open();
+ return path;
+ }
+
}