Author: Grid.Qian
Date: 2008-10-08 03:42:08 -0400 (Wed, 08 Oct 2008)
New Revision: 10729
Added:
workspace/grid/org.jboss.tools.bpmnTo/icons/
workspace/grid/org.jboss.tools.bpmnTo/icons/sample.gif
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/b2j/wizard/
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/b2j/wizard/B2JExportWizard.java
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/bpmnto/wizard/BPMNResourcesChoicePage.java
Removed:
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/b2j/action/
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/bpmnto/action/
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/bpmnto/wizard/BpmnToWizardDialog.java
Modified:
workspace/grid/org.jboss.tools.bpmnTo/META-INF/MANIFEST.MF
workspace/grid/org.jboss.tools.bpmnTo/plugin.properties
workspace/grid/org.jboss.tools.bpmnTo/plugin.xml
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
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/bpmnto/wizard/BpmnPoolsChoicePage.java
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/bpmnto/wizard/BpmnToWizard.java
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/bpmnto/wizard/ErrorMessagesPage.java
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/bpmnto/wizard/GeneratedFileLocationPage.java
Log:
JBIDE-2842: create export wizard for bpmn -> jpdl
Modified: workspace/grid/org.jboss.tools.bpmnTo/META-INF/MANIFEST.MF
===================================================================
--- workspace/grid/org.jboss.tools.bpmnTo/META-INF/MANIFEST.MF 2008-10-08 07:40:58 UTC
(rev 10728)
+++ workspace/grid/org.jboss.tools.bpmnTo/META-INF/MANIFEST.MF 2008-10-08 07:42:08 UTC
(rev 10729)
@@ -14,8 +14,9 @@
lib/dom4j-1.6.1.jar,
bin/
Bundle-Vendor: %PLUGIN_PROVIDER
-Import-Package: org.eclipse.core.resources
+Import-Package: org.eclipse.core.resources,
+ org.eclipse.ui.model
Export-Package: org.jboss.tools.bpmnto,
- org.jboss.tools.bpmnto.action,
org.jboss.tools.bpmnto.translate,
- org.jboss.tools.bpmnto.util
+ org.jboss.tools.bpmnto.util,
+ org.jboss.tools.bpmnto.wizard
Added: workspace/grid/org.jboss.tools.bpmnTo/icons/sample.gif
===================================================================
(Binary files differ)
Property changes on: workspace/grid/org.jboss.tools.bpmnTo/icons/sample.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Modified: workspace/grid/org.jboss.tools.bpmnTo/plugin.properties
===================================================================
--- workspace/grid/org.jboss.tools.bpmnTo/plugin.properties 2008-10-08 07:40:58 UTC (rev
10728)
+++ workspace/grid/org.jboss.tools.bpmnTo/plugin.properties 2008-10-08 07:42:08 UTC (rev
10729)
@@ -1,4 +1,5 @@
-b2jaction=BPMN -> JPDL
-bpmnto=BPMN TO
-PLUGIN_NAME=BPMNTO
+wizard.name=BPMN -> JPDL
+wizard.description = Export a BPMN file to JPDL
+category.name=BPMN Export
+PLUGIN_NAME=BPMNExport
PLUGIN_PROVIDER=Red Hat, Inc.
\ No newline at end of file
Modified: workspace/grid/org.jboss.tools.bpmnTo/plugin.xml
===================================================================
--- workspace/grid/org.jboss.tools.bpmnTo/plugin.xml 2008-10-08 07:40:58 UTC (rev 10728)
+++ workspace/grid/org.jboss.tools.bpmnTo/plugin.xml 2008-10-08 07:42:08 UTC (rev 10729)
@@ -1,32 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.2"?>
-<plugin>
-<extension
- point="org.eclipse.ui.popupMenus">
-
-
- <objectContribution
- id="org.jboss.tools.b2j.objectContribution.bpmnfile"
- nameFilter="*.bpmn"
- objectClass="org.eclipse.core.resources.IFile">
+<plugin>
+ <extension point="org.eclipse.ui.exportWizards">
+ <category name="%category.name"
+ id="org.jboss.tools.flow.convert.export.category"/>
+ <wizard name="%wizard.name"
+ icon="icons/sample.gif"
+ category="org.jboss.tools.flow.convert.export.category"
+ class="org.jboss.tools.b2j.wizard.B2JExportWizard"
+ id="org.jboss.tools.flow.convert.export.b2jexportwizard">
+ <description>%wizard.description</description>
+ <selection name="*.bpmn"
class="org.eclipse.core.resources.IFile"/>
+ </wizard>
+ </extension>
- <menu
- label="%bpmnto"
- id="org.jboss.tools.bpmnTo.ActionSet"
- path="additions">
- <separator
- name="group">
- </separator>
- </menu>
-
- <action
- label="%b2jaction"
- class="org.jboss.tools.b2j.action.B2JAction"
- menubarPath="org.jboss.tools.bpmnTo.ActionSet/group"
- enablesFor="+"
- id="org.jboss.tools.b2j.B2JAction">
- </action>
- </objectContribution>
- </extension>
-
</plugin>
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-10-08
07:40:58 UTC (rev 10728)
+++
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/b2j/messages/B2J.properties 2008-10-08
07:42:08 UTC (rev 10729)
@@ -25,12 +25,23 @@
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:
+Bpmn_Wizard_Title=BPMN to jPDL Conversion
+Bpmn_File_Choose_WizardPage_Name=FileChoosePage
+Bpmn_File_Choose_WizardPage_Title=BPMN Resources
+Bpmn_File_Choose_WizardPage_ViewerTitle=BPMN resources
+Bpmn_File_Choose_WizardPage_Message=Select BPMN resources to convert
+Bpmn_Pool_Choose_WizardPage_Name=PoolPage
+Bpmn_Pool_Choose_WizardPage_Message=Available BPMN Pools
+Bpmn_Pool_Choose_WizardPage_Title=Select BPMN pools to translate
+Bpmn_GeneratedFile_Location_WizardPage_Name=LocationPage
+Bpmn_GeneratedFile_Location_WizardPage_Message=Select the target location
+Bpmn_GeneratedFile_Location_WizardPage_Title=Target Location
+Bpmn_GeneratedFile_Location_WizardPage_ViewerTitle=Target location
+Bpmn_GeneratedFile_Location_WizardPage_CheckBox=Overwrite existing resources
+Bpmn_Translate_Message_WizardPage_Name=MessagePage
+Bpmn_Translate_Message_WizardPage_Title=Conversion Warnings and Errors
+Bpmn_Translate_Message_WizardPage_Message=Warnings and Errors that occured during
conversion
+Bpmn_Translate_Message_WizardpageViewer_Title=Warnings and Errors
Bpmn_EAnnotations_Element_Name=eAnnotations
Bpmn_Details_Element_Name=details
Bpmn_Value_Attribute_Name=value
@@ -38,6 +49,7 @@
Jpdl_Element_Decision_Suffix=Decision
Jpdl_Element_Complete_Suffix=Complete
Jpdl_Element_Cancel_Suffix=Cancel
+Jpdl_Element_Successful_Name=Successful?
Jpdl_Process_Definition_Name=processdefinition.xml
Jpdl_32_Namespace_Url=urn:jbpm.org:jpdl-3.2
Jpdl_Process_Definition_Element_Name=process-definition
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-10-08
07:40:58 UTC (rev 10728)
+++
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/b2j/messages/B2JMessages.java 2008-10-08
07:42:08 UTC (rev 10729)
@@ -49,12 +49,23 @@
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 Bpmn_Wizard_Title;
+ public static String Bpmn_File_Choose_WizardPage_Name;
+ public static String Bpmn_File_Choose_WizardPage_Title;
+ public static String Bpmn_File_Choose_WizardPage_Message;
+ public static String Bpmn_File_Choose_WizardPage_ViewerTitle;
+ public static String Bpmn_Pool_Choose_WizardPage_Name;
+ public static String Bpmn_Pool_Choose_WizardPage_Message;
+ public static String Bpmn_Pool_Choose_WizardPage_Title;
+ public static String Bpmn_GeneratedFile_Location_WizardPage_Name;
+ public static String Bpmn_GeneratedFile_Location_WizardPage_Message;
+ public static String Bpmn_GeneratedFile_Location_WizardPage_Title;
+ public static String Bpmn_GeneratedFile_Location_WizardPage_ViewerTitle;
+ public static String Bpmn_GeneratedFile_Location_WizardPage_CheckBox;
+ public static String Bpmn_Translate_Message_WizardPage_Name;
+ public static String Bpmn_Translate_Message_WizardPage_Title;
+ public static String Bpmn_Translate_Message_WizardPage_Message;
+ public static String Bpmn_Translate_Message_WizardpageViewer_Title;
public static String Bpmn_EAnnotations_Element_Name;
public static String Bpmn_Details_Element_Name;
public static String Bpmn_Value_Attribute_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-10-08
07:40:58 UTC (rev 10728)
+++
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/b2j/translate/BPMN2JPDL.java 2008-10-08
07:42:08 UTC (rev 10729)
@@ -33,6 +33,7 @@
Document bpmnDocument;
List<Document> processDefs = new ArrayList<Document>();
+
Map<String, Element> map = new HashMap<String, Element>();
public Map<String, Element> getMap() {
@@ -452,5 +453,13 @@
.attributeValue(B2JMessages.Dom_Element_Name));
}
+
+ public List<Document> getProcessDefs() {
+ return processDefs;
+ }
+ public void setProcessDefs(List<Document> processDefs) {
+ this.processDefs = processDefs;
+ }
+
}
Added:
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/b2j/wizard/B2JExportWizard.java
===================================================================
---
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/b2j/wizard/B2JExportWizard.java
(rev 0)
+++
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/b2j/wizard/B2JExportWizard.java 2008-10-08
07:42:08 UTC (rev 10729)
@@ -0,0 +1,157 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.b2j.wizard;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.dom4j.Document;
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.osgi.util.NLS;
+import org.jboss.tools.b2j.messages.B2JMessages;
+import org.jboss.tools.b2j.translate.BPMN2JPDL;
+import org.jboss.tools.b2j.translate.GraphicalFileGenerator;
+import org.jboss.tools.b2j.translate.TranslateHelper;
+import org.jboss.tools.bpmnto.BpmnToPlugin;
+import org.jboss.tools.bpmnto.wizard.BpmnToWizard;
+
+/**
+ * @author Grid Qian
+ *
+ * the wizard for bpmn to jpdl translation
+ */
+public class B2JExportWizard extends BpmnToWizard {
+
+ private List<String> strForProcessList = new ArrayList<String>();
+ private List<String> strForGpdList = new ArrayList<String>();
+ private List<String> generatedFoldersList = new ArrayList<String>();
+
+ public void createGeneratedFile() {
+ String[] jpdlFolderNames = new String[this.generatedFoldersList.size()];
+
+ int i = 0;
+ for (String name : this.generatedFoldersList) {
+ jpdlFolderNames[i] = name;
+ i++;
+ }
+
+ String location = super.getContainerPath((IContainer) super
+ .getTargetLocationSelection().getFirstElement());
+
+ if (this.strForProcessList.size() > 0) {
+ i = 0;
+ String[] strs = new String[strForProcessList.size()];
+ for (String pro : this.strForProcessList) {
+ strs[i] = pro;
+ i++;
+ }
+ try {
+ TranslateHelper.createFiles(location, bpmnFileName, strs,
+ jpdlFolderNames,
+ B2JMessages.Jpdl_Process_Definition_Name);
+ } catch (Exception e) {
+ BpmnToPlugin.getDefault().logError(e.getMessage());
+ }
+ }
+
+ if (this.strForGpdList.size() > 0) {
+ i = 0;
+ String[] strs = new String[strForGpdList.size()];
+ for (String pro : this.strForGpdList) {
+ strs[i] = pro;
+ i++;
+ }
+ try {
+ TranslateHelper.createFiles(location, bpmnFileName, strs,
+ jpdlFolderNames, B2JMessages.Gpd_Definition_Name);
+ } catch (Exception e) {
+ BpmnToPlugin.getDefault().logError(e.getMessage());
+ }
+ }
+
+ }
+
+ public List<String> translateBpmnToStrings() {
+ List<String> warningList = new ArrayList<String>();
+ List<String> errorList = new ArrayList<String>();
+
+ Document bpmnDocument = null;
+ try {
+ bpmnDocument = getDocument(bpmnFileParentPath, bpmnFileName);
+ } catch (Exception e) {
+ errorList.add(NLS.bind(B2JMessages.Translate_Error_File_CanNotRead,
+ bpmnFileName));
+ }
+
+ BPMN2JPDL translator = new BPMN2JPDL(bpmnFileName, bpmnFileParentPath,
+ poolIdList, bpmnDocument);
+
+ this.setStrForProcessList(Arrays
+ .asList(translator.translateToStrings()));
+
+ for (Document def : translator.getProcessDefs()) {
+ this.generatedFoldersList.add(def.getName());
+ }
+
+ warningList.addAll(translator.getWarnings());
+ errorList.addAll(translator.getErrors());
+
+ // generate jpdl gpd file from *.bpmn_diagram
+ Document bpmnDiagramDocument = null;
+ try {
+ bpmnDiagramDocument = getDocument(bpmnFileParentPath,
+ TranslateHelper.getBpmnDiagramName(bpmnFileName));
+ } catch (Exception e) {
+ errorList.add(NLS.bind(B2JMessages.Translate_Error_File_CanNotRead,
+ TranslateHelper.getBpmnDiagramName(bpmnFileName)));
+ }
+ GraphicalFileGenerator generator = new GraphicalFileGenerator(
+ bpmnDiagramDocument, translator.getMap(), bpmnFileParentPath,
+ bpmnFileName);
+
+ this.setStrForGpdList(Arrays.asList(generator.translateToStrings()));
+
+ warningList.addAll(generator.getWarnings());
+ errorList.addAll(generator.getErrors());
+
+ List<String> list = new ArrayList<String>();
+ list.addAll(errorList);
+ list.addAll(warningList);
+
+ return list;
+ }
+
+ public List<String> getStrForProcessList() {
+ return strForProcessList;
+ }
+
+ public void setStrForProcessList(List<String> strForProcessList) {
+ this.strForProcessList = strForProcessList;
+ }
+
+ public List<String> getStrForGpdList() {
+ return strForGpdList;
+ }
+
+ public void setStrForGpdList(List<String> strForGpdList) {
+ this.strForGpdList = strForGpdList;
+ }
+
+ public List<String> getGeneratedFoldersList() {
+ return generatedFoldersList;
+ }
+
+ public void setGeneratedFoldersList(List<String> generatedFoldersList) {
+ this.generatedFoldersList = generatedFoldersList;
+ }
+}
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-10-08
07:40:58 UTC (rev 10728)
+++
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/bpmnto/util/BPMNToUtil.java 2008-10-08
07:42:08 UTC (rev 10729)
@@ -19,6 +19,7 @@
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.Map;
import javax.xml.parsers.SAXParser;
@@ -27,6 +28,13 @@
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
import org.jboss.tools.b2j.messages.B2JMessages;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
@@ -149,4 +157,39 @@
}
return poolIDMap;
}
+
+
+ public static Composite createComposite(Composite parent, int numColumns) {
+ Composite composite = new Composite(parent, SWT.NULL);
+
+ GridLayout layout = new GridLayout();
+ layout.numColumns = numColumns;
+ composite.setLayout(layout);
+ composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ return composite;
+ }
+
+ @SuppressWarnings("unchecked")
+ public static boolean checkSelectedResources(ISelection selectedResources) {
+ boolean res = true;
+ if (selectedResources instanceof IStructuredSelection
+ && !selectedResources.isEmpty()) {
+ IStructuredSelection ss = (IStructuredSelection)selectedResources;
+ for (Iterator it = ss.iterator(); it.hasNext(); ){
+ Object o = it.next();
+ if (o instanceof IFile) {
+ if (!((IFile)o).getFileExtension().equalsIgnoreCase("bpmn")) {
+ res = false;
+ break;
+ }
+ } else {
+ res = false;
+ break;
+ }
+ }
+ } else {
+ res = false;
+ }
+ return res;
+ }
}
Added:
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/bpmnto/wizard/BPMNResourcesChoicePage.java
===================================================================
---
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/bpmnto/wizard/BPMNResourcesChoicePage.java
(rev 0)
+++
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/bpmnto/wizard/BPMNResourcesChoicePage.java 2008-10-08
07:42:08 UTC (rev 10729)
@@ -0,0 +1,147 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.bpmnto.wizard;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerFilter;
+import org.eclipse.jface.wizard.IWizard;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.ui.model.WorkbenchContentProvider;
+import org.eclipse.ui.model.WorkbenchLabelProvider;
+import org.jboss.tools.b2j.messages.B2JMessages;
+import org.jboss.tools.bpmnto.util.BPMNToUtil;
+
+/**
+ * @author Grid Qian
+ *
+ * the wizardpage used by user to choose the bpmn file
+ */
+public class BPMNResourcesChoicePage extends WizardPage {
+
+ private TreeViewer viewer;
+ private ISelection currentSelection;
+ private IWizard wizard;
+
+ public BPMNResourcesChoicePage(String pageName, String title,
+ String description) {
+ super(pageName);
+ this.setTitle(title);
+ this.setDescription(description);
+ }
+
+ public void createControl(Composite parent) {
+ Composite composite = createDialogArea(parent);
+
+ createListTitleArea(composite);
+ createListViewer(composite);
+ super.setControl(composite);
+
+ initializePage();
+ }
+
+ private Label createListTitleArea(Composite composite) {
+ Label label = new Label(composite, SWT.NONE);
+ label.setText(B2JMessages.Bpmn_File_Choose_WizardPage_ViewerTitle);
+ label.setFont(composite.getFont());
+ return label;
+ }
+
+ private void createListViewer(Composite composite) {
+ viewer = new TreeViewer(composite, SWT.BORDER | SWT.MULTI
+ | SWT.H_SCROLL | SWT.V_SCROLL);
+ viewer.getTree().setLayoutData(new GridData(GridData.FILL_BOTH));
+ viewer.setLabelProvider(new WorkbenchLabelProvider());
+ WorkbenchContentProvider cp = new WorkbenchContentProvider();
+ viewer.setContentProvider(cp);
+ viewer.setFilters(new ViewerFilter[] { new ProjectFilter() });
+ viewer.addPostSelectionChangedListener(new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent event) {
+ updateControls();
+ currentSelection = viewer.getSelection();
+ ((BpmnToWizard) wizard)
+ .setSelection((IStructuredSelection) currentSelection);
+
+ }
+ });
+ }
+
+ private void initializePage() {
+ wizard = this.getWizard();
+ viewer.setInput(ResourcesPlugin.getWorkspace());
+ if (this.currentSelection != null) {
+ viewer.setSelection(currentSelection, true);
+ }
+ }
+
+ @Override
+ public boolean isPageComplete() {
+ if (viewer != null) {
+ return BPMNToUtil.checkSelectedResources(viewer.getSelection());
+ }
+ return super.isPageComplete();
+ }
+
+ private void updateControls() {
+ super.getWizard().getContainer().updateButtons();
+ }
+
+ private Composite createDialogArea(Composite parent) {
+ // create a composite with standard margins and spacing
+ Composite composite = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout();
+ layout.marginHeight = 7;
+ layout.marginWidth = 7;
+ layout.verticalSpacing = 4;
+ layout.horizontalSpacing = 4;
+ composite.setLayout(layout);
+ composite.setLayoutData(new GridData(GridData.FILL_BOTH));
+ return composite;
+ }
+
+ public void setSelection(ISelection selection) {
+ this.currentSelection = selection;
+ }
+
+ public ISelection getSelection() {
+ return currentSelection;
+ }
+}
+
+class ProjectFilter extends ViewerFilter {
+ @Override
+ public boolean select(Viewer viewer, Object parent, Object element) {
+ boolean res = false;
+ if (element instanceof IFile) {
+ IFile file = (IFile) element;
+ if (file.getFileExtension().equalsIgnoreCase("bpmn")) {
+ res = true;
+ }
+ }
+ if (element instanceof IContainer) {
+ res = true;
+ }
+ return res;
+ }
+}
Modified:
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/bpmnto/wizard/BpmnPoolsChoicePage.java
===================================================================
---
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/bpmnto/wizard/BpmnPoolsChoicePage.java 2008-10-08
07:40:58 UTC (rev 10728)
+++
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/bpmnto/wizard/BpmnPoolsChoicePage.java 2008-10-08
07:42:08 UTC (rev 10729)
@@ -45,54 +45,60 @@
CheckboxTableViewer listViewer;
String listTitle;
private Map<String, String> idMap;
+
private IWizard wizard;
- public BpmnPoolsChoicePage(String pageName, String listTitle,
- Map<String, String> idMap) {
+ public BpmnPoolsChoicePage(String pageName, String title, String listTitle) {
super(pageName);
this.listTitle = listTitle;
- this.idMap = idMap;
- this.setTitle(pageName);
+ this.setTitle(title);
}
public void createControl(Composite parent) {
Composite composite = createDialogArea(parent);
+
createListTitleArea(composite);
-
createListViewer(composite);
-
addSelectionButtons(composite);
+ setControl(composite);
- setControl(composite);
initializePage();
- initializeViewerSelection();
+ initializeViewer();
}
- private void initializeViewerSelection() {
- wizard = this.getWizard();
- List<String> poolIdList = ((BpmnToWizard) wizard).getPoolIdList();
- if (poolIdList.size() == 0) {
- listViewer.setAllChecked(false);
- } else {
- for (String id : poolIdList) {
- Set<Entry<String, String>> set = idMap.entrySet();
- Entry<String, String> selectedEntry = null;
- for (Entry<String, String> entry : set) {
- if (entry.getKey().equals(id)) {
- selectedEntry = entry;
- break;
- }
+ private Label createListTitleArea(Composite composite) {
+ Label label = new Label(composite, SWT.NONE);
+ label.setText(listTitle);
+ label.setFont(composite.getFont());
+ return label;
+ }
+
+ private void createListViewer(Composite composite) {
+ listViewer = CheckboxTableViewer.newCheckList(composite, SWT.BORDER);
+ GridData data = new GridData(GridData.FILL_BOTH);
+ data.heightHint = 250;
+ data.widthHint = 300;
+ listViewer.getTable().setLayoutData(data);
+
+ listViewer.setLabelProvider(new LabelProvider());
+ listViewer.setContentProvider(new ArrayContentProvider());
+ listViewer.addCheckStateListener(new ICheckStateListener() {
+ @SuppressWarnings("unchecked")
+ public void checkStateChanged(CheckStateChangedEvent event) {
+ if (event.getChecked()) {
+ (((BpmnToWizard) wizard)).getPoolIdList().add(
+ ((Entry<String, String>) event.getElement())
+ .getKey());
+ } else {
+ (((BpmnToWizard) wizard)).getPoolIdList().remove(
+ ((Entry<String, String>) event.getElement())
+ .getKey());
}
- listViewer.setChecked(selectedEntry, true);
+ changeComplete();
}
- }
+ });
}
- private void initializePage() {
- setPageComplete(false);
- listViewer.setInput(idMap.entrySet());
- }
-
private void addSelectionButtons(Composite composite) {
Composite buttonComposite = new Composite(composite, SWT.NONE);
GridLayout layout = new GridLayout();
@@ -103,8 +109,8 @@
buttonComposite.setLayoutData(new GridData(SWT.END, SWT.TOP, true,
false));
- Button selectButton = createButton(buttonComposite, B2JMessages.Label_Select_All,
- false);
+ Button selectButton = createButton(buttonComposite,
+ B2JMessages.Label_Select_All, false);
SelectionListener listener = new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
@@ -145,39 +151,34 @@
return button;
}
- private void createListViewer(Composite composite) {
- listViewer = CheckboxTableViewer.newCheckList(composite, SWT.BORDER);
- GridData data = new GridData(GridData.FILL_BOTH);
- data.heightHint = 250;
- data.widthHint = 300;
- listViewer.getTable().setLayoutData(data);
+ private void initializePage() {
+ setPageComplete(false);
+ }
- listViewer.setLabelProvider(new LabelProvider());
- listViewer.setContentProvider(new ArrayContentProvider());
- listViewer.addCheckStateListener(new ICheckStateListener() {
- @SuppressWarnings("unchecked")
- public void checkStateChanged(CheckStateChangedEvent event) {
- if (event.getChecked()) {
- (((BpmnToWizard) wizard)).getPoolIdList().add(
- ((Entry<String, String>) event.getElement())
- .getKey());
- } else {
- (((BpmnToWizard) wizard)).getPoolIdList().remove(
- ((Entry<String, String>) event.getElement())
- .getKey());
+ private void initializeViewer() {
+ if (listViewer == null) {
+ return;
+ }
+ listViewer.setInput(idMap.entrySet());
+ wizard = this.getWizard();
+ List<String> poolIdList = ((BpmnToWizard) wizard).getPoolIdList();
+ if (poolIdList.size() == 0) {
+ listViewer.setAllChecked(false);
+ } else {
+ for (String id : poolIdList) {
+ Set<Entry<String, String>> set = idMap.entrySet();
+ Entry<String, String> selectedEntry = null;
+ for (Entry<String, String> entry : set) {
+ if (entry.getKey().equals(id)) {
+ selectedEntry = entry;
+ break;
+ }
}
- changeComplete();
+ listViewer.setChecked(selectedEntry, true);
}
- });
+ }
}
- private Label createListTitleArea(Composite composite) {
- Label label = new Label(composite, SWT.NONE);
- label.setText(listTitle);
- label.setFont(composite.getFont());
- return label;
- }
-
private Composite createDialogArea(Composite parent) {
// create a composite with standard margins and spacing
Composite composite = new Composite(parent, SWT.NONE);
@@ -199,4 +200,13 @@
}
}
+ public Map<String, String> getIdMap() {
+ return idMap;
+ }
+
+ public void setIdMap(Map<String, String> idMap) {
+ this.idMap = idMap;
+ initializeViewer();
+ }
+
}
Modified:
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/bpmnto/wizard/BpmnToWizard.java
===================================================================
---
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/bpmnto/wizard/BpmnToWizard.java 2008-10-08
07:40:58 UTC (rev 10728)
+++
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/bpmnto/wizard/BpmnToWizard.java 2008-10-08
07:42:08 UTC (rev 10729)
@@ -15,47 +15,176 @@
import java.util.List;
import java.util.Map;
+import org.dom4j.Document;
+import org.eclipse.core.resources.IContainer;
+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.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.ui.IExportWizard;
+import org.eclipse.ui.IWorkbench;
import org.jboss.tools.b2j.messages.B2JMessages;
+import org.jboss.tools.bpmnto.util.BPMNToUtil;
+import org.jboss.tools.bpmnto.wizard.BPMNResourcesChoicePage;
/**
* @author Grid Qian
*
* the wizard for bpmn translation
*/
-public class BpmnToWizard extends Wizard{
+public abstract class BpmnToWizard extends Wizard implements IExportWizard {
- BpmnPoolsChoicePage poolsPage;
- GeneratedFileLocationPage locationPage;
- ErrorMessagesPage errorPage;
-
+ private BPMNResourcesChoicePage bpmnResPage;
+ private BpmnPoolsChoicePage poolsPage;
+ private GeneratedFileLocationPage locationPage;
+ private ErrorMessagesPage errorPage;
+
+ // the selected *.bpmn file
+ private IStructuredSelection selection;
+ // the selected folder to save these generated files
+ private IStructuredSelection targetLocationSelection;
// bpmn pool id:name map
- Map<String, String> idMap;
- List<String> poolIdList = new ArrayList<String>();
- String location;
- List<String> errorList = new ArrayList<String>();
+ private Map<String, String> idMap;
- public BpmnToWizard(String title,Map<String, String> idMap){
+ protected String bpmnFileName;
+ protected String bpmnFileParentPath;
+ protected List<String> poolIdList = new ArrayList<String>();
+ // the list contains errors or warnings when generating
+ protected List<String> errorList = new ArrayList<String>();
+
+ public BpmnToWizard() {
super();
- super.setWindowTitle(title);
- this.idMap = idMap;
+ super.setWindowTitle(B2JMessages.Bpmn_Wizard_Title);
}
-
- public void addPages(){
+
+ public void addPages() {
super.addPages();
- poolsPage = new BpmnPoolsChoicePage(B2JMessages.Bpmn_Pool_Choose_Dialog_Title,
B2JMessages.Bpmn_Pool_Choose_Dialog_Message,idMap);
- locationPage = new
GeneratedFileLocationPage(B2JMessages.Bpmn_GeneratedFile_Location_Dialog_Title,B2JMessages.Bpmn_GeneratedFile_Location_Dialog_Message);
- errorPage = new
ErrorMessagesPage(B2JMessages.Bpmn_Translate_Message_Dialog_Title,B2JMessages.Bpmn_Translate_Message_Dialog_Message);
+
+ bpmnResPage = new BPMNResourcesChoicePage(
+ B2JMessages.Bpmn_File_Choose_WizardPage_Name,
+ B2JMessages.Bpmn_File_Choose_WizardPage_Title,
+ B2JMessages.Bpmn_File_Choose_WizardPage_Message);
+ bpmnResPage.setSelection(selection);
+ poolsPage = new BpmnPoolsChoicePage(
+ B2JMessages.Bpmn_Pool_Choose_WizardPage_Name,
+ B2JMessages.Bpmn_Pool_Choose_WizardPage_Title,
+ B2JMessages.Bpmn_Pool_Choose_WizardPage_Message);
+ errorPage = new ErrorMessagesPage(
+ B2JMessages.Bpmn_Translate_Message_WizardPage_Name,
+ B2JMessages.Bpmn_Translate_Message_WizardPage_Title,
+ B2JMessages.Bpmn_Translate_Message_WizardPage_Message);
+ locationPage = new GeneratedFileLocationPage(
+ B2JMessages.Bpmn_GeneratedFile_Location_WizardPage_Name,
+ B2JMessages.Bpmn_GeneratedFile_Location_WizardPage_Title,
+ B2JMessages.Bpmn_GeneratedFile_Location_WizardPage_Message);
+ locationPage.setSelection(selection);
+ addPage(bpmnResPage);
addPage(poolsPage);
+ addPage(errorPage);
addPage(locationPage);
- addPage(errorPage);
}
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench,
+ * org.eclipse.jface.viewers.IStructuredSelection)
+ */
+ public void init(IWorkbench workbench, IStructuredSelection selection) {
+ this.selection = selection;
+ initialize();
+ }
+
+ /*
+ * do some initial tasks
+ */
+ private void initialize() {
+ if (selection.getFirstElement() instanceof IFile) {
+ IFile bpmnFile = (IFile) selection.getFirstElement();
+ bpmnFileName = bpmnFile.getName();
+ bpmnFileParentPath = bpmnFile.getParent().getLocation()
+ .toOSString();
+ try {
+ idMap = BPMNToUtil.getPoolIDsFromDocument(getDocument(
+ bpmnFileParentPath, bpmnFileName));
+ } catch (Exception e) {
+ errorList.add(0, NLS.bind(
+ B2JMessages.Translate_Error_File_CanNotRead,
+ bpmnFileName));
+ e.printStackTrace();
+ }
+ }
+ if (poolsPage != null) {
+ poolsPage.setIdMap(idMap);
+ }
+ }
+
+ public IWizardPage getNextPage(IWizardPage page) {
+ if (page.getName()
+ .equals(B2JMessages.Bpmn_Pool_Choose_WizardPage_Name)) {
+ errorList = translateBpmnToStrings();
+ if (errorList.size() == 0) {
+ return locationPage;
+ }
+ errorPage.getListViewer().setInput(errorList);
+ return super.getNextPage(page);
+ } else {
+ return super.getNextPage(page);
+ }
+
+ }
+
public boolean performFinish() {
-
+ createGeneratedFile();
+ refreshWorkspace();
return true;
}
-
-
+
+ /*
+ * do the translation from bpmn to string list the sub class need to create
+ * a string list to reserve these strings the return list is error or
+ * warning messages
+ */
+ public abstract List<String> translateBpmnToStrings();
+
+ /*
+ * write the generated strings to the files
+ */
+ public abstract void createGeneratedFile();
+
+ /*
+ * get the path of the eclipse workspace container
+ */
+ protected String getContainerPath(IContainer container) {
+ return container.getLocation().toOSString();
+ }
+
+ /*
+ * get the dom document from a given path and file name
+ */
+ public Document getDocument(String bpmnFileParentPath, String bpmnFileName)
+ throws Exception {
+ Document bpmnDocument = null;
+ bpmnDocument = BPMNToUtil.parse(bpmnFileParentPath, bpmnFileName);
+ return bpmnDocument;
+ }
+
+ /*
+ * refresh eclipse workspace
+ */
+ public void refreshWorkspace() {
+ try {
+ ResourcesPlugin.getWorkspace().getRoot().refreshLocal(
+ IResource.DEPTH_INFINITE, null);
+ } catch (CoreException e) {
+ e.printStackTrace();
+ }
+ }
+
public List<String> getPoolIdList() {
return poolIdList;
}
@@ -63,15 +192,7 @@
public void setPoolIdList(List<String> poolIdList) {
this.poolIdList = poolIdList;
}
-
- public String getLocation() {
- return location;
- }
- public void setLocation(String location) {
- this.location = location;
- }
-
public List<String> getErrorList() {
return errorList;
}
@@ -80,4 +201,37 @@
this.errorList = errorList;
}
+ public IStructuredSelection getSelection() {
+ return selection;
+ }
+
+ public void setSelection(IStructuredSelection selection) {
+ this.selection = selection;
+ initialize();
+ }
+
+ public String getBpmnFileName() {
+ return bpmnFileName;
+ }
+
+ public void setBpmnFileName(String bpmnFileName) {
+ this.bpmnFileName = bpmnFileName;
+ }
+
+ public String getBpmnFileParentPath() {
+ return bpmnFileParentPath;
+ }
+
+ public void setBpmnFileParentPath(String bpmnFileParentPath) {
+ this.bpmnFileParentPath = bpmnFileParentPath;
+ }
+
+ public IStructuredSelection getTargetLocationSelection() {
+ return targetLocationSelection;
+ }
+
+ public void setTargetLocationSelection(
+ IStructuredSelection targetLocationSelection) {
+ this.targetLocationSelection = targetLocationSelection;
+ }
}
Deleted:
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/bpmnto/wizard/BpmnToWizardDialog.java
===================================================================
---
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/bpmnto/wizard/BpmnToWizardDialog.java 2008-10-08
07:40:58 UTC (rev 10728)
+++
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/bpmnto/wizard/BpmnToWizardDialog.java 2008-10-08
07:42:08 UTC (rev 10729)
@@ -1,59 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at
http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-
-package org.jboss.tools.bpmnto.wizard;
-
-import java.util.List;
-
-import org.eclipse.jface.wizard.IWizard;
-import org.eclipse.jface.wizard.IWizardPage;
-import org.eclipse.jface.wizard.WizardDialog;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.IActionDelegate;
-import org.jboss.tools.bpmnto.action.BpmnToAction;
-
-/**
- * @author Grid Qian
- *
- * wizard dialog for bpmn tranlation
- */
-public class BpmnToWizardDialog extends WizardDialog {
-
- IActionDelegate action;
-
- public BpmnToWizardDialog(Shell parentShell, IWizard newWizard,
- IActionDelegate action) {
- super(parentShell, newWizard);
- this.action = action;
- }
-
- public void nextPressed() {
- IWizardPage page = this.getCurrentPage();
- if (page instanceof GeneratedFileLocationPage) {
- List<String> list = ((BpmnToAction) action).errorList;
- String location = ((BpmnToWizard) this.getWizard()).getLocation();
- if (location == null || "".equals(location)) {
- location = ((BpmnToAction) action).bpmnFile.getParent()
- .getLocation().toOSString();
- }
- list.addAll(((BpmnToAction) action).translateBpmn(
- ((BpmnToAction) action).bpmnFile.getParent().getLocation()
- .toOSString(), ((BpmnToAction) action).bpmnFile
- .getName(), ((BpmnToWizard) this.getWizard())
- .getPoolIdList(), location));
- ((BpmnToWizard) this.getWizard()).setErrorList(list);
- ((ErrorMessagesPage) page.getNextPage()).listViewer
- .setInput(((BpmnToWizard) this.getWizard()).getErrorList());
- }
- showPage(page.getNextPage());
- }
-
-}
Modified:
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/bpmnto/wizard/ErrorMessagesPage.java
===================================================================
---
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/bpmnto/wizard/ErrorMessagesPage.java 2008-10-08
07:40:58 UTC (rev 10728)
+++
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/bpmnto/wizard/ErrorMessagesPage.java 2008-10-08
07:42:08 UTC (rev 10729)
@@ -20,40 +20,43 @@
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
+import org.jboss.tools.b2j.messages.B2JMessages;
/**
* @author Grid Qian
*
* the wizardpage for showing the error and warning messages from translating
*/
-public class ErrorMessagesPage extends WizardPage{
-
- TableViewer listViewer;
- String listTitle;
-
- protected ErrorMessagesPage(String pageName, String listTitle) {
+public class ErrorMessagesPage extends WizardPage {
+
+ private TableViewer listViewer;
+
+ protected ErrorMessagesPage(String pageName, String title, String description) {
super(pageName);
- this.listTitle = listTitle;
- this.setTitle(pageName);
+ this.setDescription(description);
+ this.setTitle(title);
}
public void createControl(Composite parent) {
Composite composite = createDialogArea(parent);
-
+
createListTitleArea(composite);
createListViewer(composite);
setControl(composite);
- initializeViewer();
-
}
- private void initializeViewer() {
- listViewer.setInput(((BpmnToWizard)this.getWizard()).getErrorList());
+ private Label createListTitleArea(Composite composite) {
+ Label label = new Label(composite, SWT.NONE);
+ label
+ .setText(B2JMessages.Bpmn_Translate_Message_WizardpageViewer_Title);
+ label.setFont(composite.getFont());
+ return label;
}
private void createListViewer(Composite composite) {
- listViewer = new TableViewer(composite, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL |
SWT.BORDER);
+ listViewer = new TableViewer(composite, SWT.SINGLE | SWT.H_SCROLL
+ | SWT.V_SCROLL | SWT.BORDER);
GridData data = new GridData(GridData.FILL_BOTH);
data.heightHint = 250;
data.widthHint = 300;
@@ -63,13 +66,6 @@
listViewer.setContentProvider(new ArrayContentProvider());
}
- private Label createListTitleArea(Composite composite) {
- Label label = new Label(composite, SWT.NONE);
- label.setText(listTitle);
- label.setFont(composite.getFont());
- return label;
- }
-
private Composite createDialogArea(Composite parent) {
// create a composite with standard margins and spacing
Composite composite = new Composite(parent, SWT.NONE);
@@ -86,5 +82,14 @@
public boolean isPageComplete() {
return true;
}
+
+ public TableViewer getListViewer() {
+ return listViewer;
+ }
+
+ public void setListViewer(TableViewer listViewer) {
+ this.listViewer = listViewer;
+ }
+
}
Modified:
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/bpmnto/wizard/GeneratedFileLocationPage.java
===================================================================
---
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/bpmnto/wizard/GeneratedFileLocationPage.java 2008-10-08
07:40:58 UTC (rev 10728)
+++
workspace/grid/org.jboss.tools.bpmnTo/src/org/jboss/tools/bpmnto/wizard/GeneratedFileLocationPage.java 2008-10-08
07:42:08 UTC (rev 10729)
@@ -11,19 +11,28 @@
package org.jboss.tools.bpmnto.wizard;
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITreeSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.TreePath;
+import org.eclipse.jface.viewers.TreeSelection;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.jface.wizard.IWizard;
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.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.DirectoryDialog;
-import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.model.WorkbenchContentProvider;
+import org.eclipse.ui.model.WorkbenchLabelProvider;
import org.jboss.tools.b2j.messages.B2JMessages;
/**
@@ -31,74 +40,87 @@
*
* the wizardpage for the generated file location
*/
-public class GeneratedFileLocationPage extends WizardPage{
-
- String message;
- Text pathText;
+public class GeneratedFileLocationPage extends WizardPage {
+
+ private TreeViewer viewer;
+ private ISelection currentSelection;
+ private Button button;
private IWizard wizard;
- protected GeneratedFileLocationPage(String pageName, String message) {
+ protected GeneratedFileLocationPage(String pageName, String title,
+ String description) {
super(pageName);
- this.message = message;
- this.setTitle(pageName);
+ this.setDescription(description);
+ this.setTitle(title);
}
public void createControl(Composite parent) {
Composite composite = createDialogArea(parent);
- createMessageArea(composite);
- createLocationArea(composite);
-
- setControl(composite);
-
+
+ createListTitleArea(composite);
+ createListViewer(composite);
+ createCheckbox(composite);
+ super.setControl(composite);
+
+ initializePage();
+
}
-
- private void createLocationArea(Composite parent) {
- Group composite = new Group(parent, SWT.NONE);
- GridLayout layout = new GridLayout();
- layout.numColumns = 3;
- composite.setLayout(layout);
- composite.setLayoutData(new GridData(GridData.FILL_BOTH));
-
- Label label = new Label(composite, SWT.NONE);
- label.setText("Location:");
+
+ private Label createListTitleArea(Composite parent) {
+ Label label = new Label(parent, SWT.NONE);
+ label
+ .setText(B2JMessages.Bpmn_GeneratedFile_Location_WizardPage_ViewerTitle);
label.setFont(parent.getFont());
-
-
- pathText = new Text(composite, SWT.BORDER);
- pathText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- pathText.setEditable(false);
-
- Button browse = new Button(composite, SWT.PUSH);
- browse.setText(B2JMessages.Label_Button_Browse);
- browse.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- DirectoryDialog dialog = new DirectoryDialog(getShell(), SWT.OPEN);
- dialog.setText(B2JMessages.Bpmn_GeneratedFile_Location_Dialog_Title);
- dialog.setMessage(B2JMessages.Bpmn_GeneratedFile_Location_Dialog_Message);
- String path = dialog.open();
- if (path != null && path.length() > 0) {
- pathText.setText(path);
- ((BpmnToWizard)wizard).setLocation(path);
- }
+ return label;
+ }
+
+ private void createListViewer(Composite composite) {
+ viewer = new TreeViewer(composite, SWT.BORDER | SWT.MULTI
+ | SWT.H_SCROLL | SWT.V_SCROLL);
+ viewer.getTree().setLayoutData(new GridData(GridData.FILL_BOTH));
+ viewer.setLabelProvider(new WorkbenchLabelProvider());
+ WorkbenchContentProvider cp = new WorkbenchContentProvider();
+ viewer.setContentProvider(cp);
+ viewer.setFilters(new ViewerFilter[] { new ProFilter() });
+ viewer.addPostSelectionChangedListener(new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent event) {
+ updateControls();
+ currentSelection = viewer.getSelection();
+ ((BpmnToWizard) wizard)
+ .setTargetLocationSelection((IStructuredSelection) currentSelection);
+
}
});
-
- initializePage();
+ }
-
+ private Button createCheckbox(Composite parent) {
+ button = new Button(parent, SWT.CHECK | SWT.NONE);
+ button
+ .setText(B2JMessages.Bpmn_GeneratedFile_Location_WizardPage_CheckBox);
+ button.setFont(parent.getFont());
+ return button;
}
private void initializePage() {
wizard = this.getWizard();
- pathText.setText(((BpmnToWizard)wizard).getLocation() == null ?"" :
((BpmnToWizard)wizard).getLocation());
-
+ viewer.setInput(ResourcesPlugin.getWorkspace());
+ if (this.currentSelection != null) {
+ if (currentSelection != null
+ && currentSelection instanceof ITreeSelection) {
+ // Select the parent project of this first bpmn file chosen
+ ITreeSelection node = (ITreeSelection) currentSelection;
+ TreePath[] paths = node.getPaths();
+ TreePath projPath = new TreePath(new Object[] { paths[0]
+ .getFirstSegment() });
+ TreeSelection projSel = new TreeSelection(projPath);
+ viewer.setSelection(projSel, true);
+ }
+ }
+ button.setSelection(true);
}
- private Label createMessageArea(Composite parent) {
- Label label = new Label(parent, SWT.NONE);
- label.setText(message);
- label.setFont(parent.getFont());
- return label;
+ private void updateControls() {
+ super.getWizard().getContainer().updateButtons();
}
private Composite createDialogArea(Composite parent) {
@@ -113,9 +135,27 @@
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
return composite;
}
-
+
public boolean isPageComplete() {
+ if (viewer != null && viewer.getSelection() == null) {
+ return false;
+ }
return true;
}
+ public ISelection getSelection() {
+ return currentSelection;
+ }
+
+ public void setSelection(ISelection currentSelection) {
+ this.currentSelection = currentSelection;
+ }
+
}
+
+class ProFilter extends ViewerFilter {
+ @Override
+ public boolean select(Viewer viewer, Object parent, Object element) {
+ return element instanceof IContainer;
+ }
+}