Author: DartPeng
Date: 2008-10-21 05:20:19 -0400 (Tue, 21 Oct 2008)
New Revision: 11035
Added:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/icons/full/obj16/esb16.png
trunk/smooks/plugins/org.jboss.tools.smooks.ui/libs/dom4j.license
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/META-INF/MANIFEST.MF
trunk/smooks/plugins/org.jboss.tools.smooks.ui/plugin.xml
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/editors/TypeIDSelectionWizardPage.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/wizards/NewResourceConfigWizardPage.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/wizards/SmooksConfigFileNewWizard.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/wizards/SmooksConfigFileNewWizardPage.java
Log:
JBIDE-2846
Thanks John for helping me to modify that
Modified: trunk/smooks/plugins/org.jboss.tools.smooks.ui/META-INF/MANIFEST.MF
===================================================================
--- trunk/smooks/plugins/org.jboss.tools.smooks.ui/META-INF/MANIFEST.MF 2008-10-21
09:18:30 UTC (rev 11034)
+++ trunk/smooks/plugins/org.jboss.tools.smooks.ui/META-INF/MANIFEST.MF 2008-10-21
09:20:19 UTC (rev 11035)
@@ -21,7 +21,8 @@
org.eclipse.emf.edit,
org.eclipse.emf.edit.ui,
org.eclipse.xsd.edit,
- org.jboss.tools.smooks.core
+ org.jboss.tools.smooks.core,
+ org.jboss.tools.common.model.ui
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-ClassPath: .,
Added: trunk/smooks/plugins/org.jboss.tools.smooks.ui/icons/full/obj16/esb16.png
===================================================================
(Binary files differ)
Property changes on:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/icons/full/obj16/esb16.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/smooks/plugins/org.jboss.tools.smooks.ui/libs/dom4j.license
===================================================================
--- trunk/smooks/plugins/org.jboss.tools.smooks.ui/libs/dom4j.license
(rev 0)
+++ trunk/smooks/plugins/org.jboss.tools.smooks.ui/libs/dom4j.license 2008-10-21 09:20:19
UTC (rev 11035)
@@ -0,0 +1,13 @@
+BSD style license
+
+Redistribution and use of this software and associated documentation
("Software"), with or without modification, are permitted provided that the
following conditions are met:
+
+ 1. Redistributions of source code must retain copyright statements and notices.
Redistributions must also contain a copy of this document.
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list
of conditions and the following disclaimer in the documentation and/or other materials
provided with the distribution.
+ 3. The name "DOM4J" must not be used to endorse or promote products derived
from this Software without prior written permission of MetaStuff, Ltd. For written
permission, please contact dom4j-info(a)metastuff.com.
+ 4. Products derived from this Software may not be called "DOM4J" nor may
"DOM4J" appear in their names without prior written permission of MetaStuff,
Ltd. DOM4J is a registered trademark of MetaStuff, Ltd.
+ 5. Due credit should be given to the DOM4J Project -
http://www.dom4j.org
+
+THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND ANY
EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
METASTUFF, LTD. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved. \ No newline at end of file
Modified: trunk/smooks/plugins/org.jboss.tools.smooks.ui/plugin.xml
===================================================================
--- trunk/smooks/plugins/org.jboss.tools.smooks.ui/plugin.xml 2008-10-21 09:18:30 UTC (rev
11034)
+++ trunk/smooks/plugins/org.jboss.tools.smooks.ui/plugin.xml 2008-10-21 09:20:19 UTC (rev
11035)
@@ -1,161 +1,161 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<?eclipse version="3.2"?>
-<plugin>
- <extension-point id="viewerInitor" name="viewerInitor"
schema="schema/viewerInitor.exsd"/>
- <extension-point id="analyzer" name="analyzer"
schema="schema/analyzer.exsd"/>
- <extension point="org.eclipse.emf.ecore.generated_package">
- <package
- uri = "http://www.jboss.org/tools/smooks/graphicalInformation"
- class = "org.jboss.tools.smooks.graphical.GraphicalPackage"
- genModel = "model/graphical.genmodel" />
- </extension>
-
- <extension
- point="org.eclipse.ui.editors">
- <editor
- name="Smooks Form Editor"
- extensions="smooks"
- icon="icons/sample.gif"
- class="org.jboss.tools.smooks.ui.editors.SmooksFormEditor"
- id="org.jboss.tools.smooks.ui.editors.SmooksFormEditor">
- </editor>
- </extension>
- <extension
- point="org.eclipse.ui.views.properties.tabbed.propertySections">
- <propertySections
-
contributorId="org.jboss.tools.smooks.ui.editors.SmooksFormEditor">
- <propertySection
- class="org.jboss.tools.smooks.ui.ConnectionPropertySection"
- id="org.jboss.tools.smooks.ui.connection.propertyTab.Section"
- tab="org.jboss.tools.smooks.ui.connection.propertyTab">
- <input
-
type="org.jboss.tools.smooks.ui.gef.model.LineConnectionModel">
- </input>
- </propertySection>
- </propertySections>
- </extension>
- <extension
-
point="org.eclipse.ui.views.properties.tabbed.propertyContributor">
- <propertyContributor
- contributorId="org.jboss.tools.smooks.ui.editors.SmooksFormEditor"
-
typeMapper="org.jboss.tools.smooks.ui.SmooksGraphPropertyTypeMapper">
- <propertyCategory
- category="connection"></propertyCategory>
- </propertyContributor>
- </extension>
- <extension
- point="org.eclipse.ui.views.properties.tabbed.propertyTabs">
- <propertyTabs
-
contributorId="org.jboss.tools.smooks.ui.editors.SmooksFormEditor">
- <propertyTab
- category="connection"
- id="org.jboss.tools.smooks.ui.connection.propertyTab"
- label="Mapping Properties">
- </propertyTab>
- </propertyTabs>
- </extension>
- <extension
- point="org.eclipse.ui.newWizards">
- <category
- id="org.jboss.tools.smooks.ui.wizards"
- name="Smooks">
- </category>
- <wizard
- category="org.jboss.tools.smooks.ui.wizards"
-
class="org.jboss.tools.smooks.ui.wizards.SmooksConfigFileNewWizard"
- icon="icons/sample.gif"
- id="org.jboss.tools.smooks.ui.wizards.SmooksConfigFileNewWizard"
- name="Smooks Configuration File">
- </wizard>
- </extension>
-
- <extension
- point="org.jboss.tools.smooks.ui.viewerInitor">
- <viewerInitor
-
contentProvider="org.jboss.tools.smooks.xml.ui.XMLStructuredDataContentProvider"
-
creationWizard="org.jboss.tools.smooks.xml.ui.XMLStructuredDataWizard"
- description="XML data type comes from any .xml file."
-
labelProvider="org.jboss.tools.smooks.xml.ui.XMLStructuredDataLabelProvider"
- name="XML Data Type"
- typeID="org.jboss.tools.smooks.xml.viewerInitor.xml">
- </viewerInitor>
- </extension>
- <extension
- point="org.jboss.tools.smooks.ui.analyzer">
- <mappingAnalyzer
- class="org.jboss.tools.smooks.xml2xml.XML2XMLAnalyzer"
- name="XML2XML Analyzer"
- typeID="org.jboss.tools.smooks.xml.viewerInitor.xml">
- <targetSourceType
- id="org.jboss.tools.smooks.xml.viewerInitor.xml"
- name="XML">
- </targetSourceType>
- </mappingAnalyzer>
- </extension>
- <extension
- point="org.jboss.tools.smooks.ui.viewerInitor">
- <viewerInitor
-
contentProvider="org.jboss.tools.smooks.javabean.model.BeanContentProvider"
-
creationWizard="org.jboss.tools.smooks.javabean.ui.NewJavaBeanStrucutredDataWizard"
- description="This data type can get from any Java .class."
-
labelProvider="org.jboss.tools.smooks.javabean.model.BeanlabelProvider"
- name="JavaBean Data Type"
- typeID="org.jboss.tools.smooks.ui.viewerInitor.javabean">
- </viewerInitor>
- </extension>
- <extension
- point="org.jboss.tools.smooks.ui.analyzer">
- <mappingAnalyzer
- class="org.jboss.tools.smooks.javabean.analyzer.JavaBeanAnalyzer"
- name="JavaBean Analyzer"
- typeID="org.jboss.tools.smooks.ui.viewerInitor.javabean">
- <targetSourceType
- id="org.jboss.tools.smooks.ui.viewerInitor.javabean"
- name="java2java">
- </targetSourceType>
- </mappingAnalyzer>
- <sourceModelAnalyzer
- class="org.jboss.tools.smooks.javabean.analyzer.JavaBeanAnalyzer"
- level="0"
- name="JavaBean SourceModel Analyzer"
- typeID="org.jboss.tools.smooks.ui.viewerInitor.javabean">
- </sourceModelAnalyzer>
- <targetModelAnalyzer
- class="org.jboss.tools.smooks.javabean.analyzer.JavaBeanAnalyzer"
- level="0"
- name="JavaBean TargetModel Analyzer"
- typeID="org.jboss.tools.smooks.ui.viewerInitor.javabean">
- </targetModelAnalyzer>
- </extension>
-
- <extension
- point="org.jboss.tools.smooks.ui.analyzer">
- <mappingAnalyzer
- class="org.jboss.tools.smooks.java2xml.analyzer.Java2XMLAnalyzer"
- name="Java Bean"
- typeID="org.jboss.tools.smooks.ui.viewerInitor.javabean">
- <targetSourceType
- id="org.jboss.tools.smooks.xml.viewerInitor.xml"
- name="XML">
- </targetSourceType>
- </mappingAnalyzer>
- </extension>
-
- <extension
- point="org.jboss.tools.smooks.ui.analyzer">
- <mappingAnalyzer
- class="org.jboss.tools.smooks.xml2java.analyzer.XML2JavaAnalyzer"
- name="XML2Java"
- typeID="org.jboss.tools.smooks.xml.viewerInitor.xml">
- <targetSourceType
- id="org.jboss.tools.smooks.ui.viewerInitor.javabean"
- name="JavaBean">
- </targetSourceType>
- </mappingAnalyzer>
- <sourceModelAnalyzer
-
class="org.jboss.tools.smooks.xml2java.analyzer.XMLSourceModelAnalyzer"
- name="XML"
- typeID="org.jboss.tools.smooks.xml.viewerInitor.xml">
- </sourceModelAnalyzer>
- </extension>
-</plugin>
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.2"?>
+<plugin>
+ <extension-point id="viewerInitor" name="viewerInitor"
schema="schema/viewerInitor.exsd"/>
+ <extension-point id="analyzer" name="analyzer"
schema="schema/analyzer.exsd"/>
+ <extension point="org.eclipse.emf.ecore.generated_package">
+ <package
+ uri = "http://www.jboss.org/tools/smooks/graphicalInformation"
+ class = "org.jboss.tools.smooks.graphical.GraphicalPackage"
+ genModel = "model/graphical.genmodel" />
+ </extension>
+
+ <extension
+ point="org.eclipse.ui.editors">
+ <editor
+ name="Smooks Form Editor"
+ extensions="smooks"
+ icon="icons/sample.gif"
+ class="org.jboss.tools.smooks.ui.editors.SmooksFormEditor"
+ id="org.jboss.tools.smooks.ui.editors.SmooksFormEditor">
+ </editor>
+ </extension>
+ <extension
+ point="org.eclipse.ui.views.properties.tabbed.propertySections">
+ <propertySections
+
contributorId="org.jboss.tools.smooks.ui.editors.SmooksFormEditor">
+ <propertySection
+ class="org.jboss.tools.smooks.ui.ConnectionPropertySection"
+ id="org.jboss.tools.smooks.ui.connection.propertyTab.Section"
+ tab="org.jboss.tools.smooks.ui.connection.propertyTab">
+ <input
+
type="org.jboss.tools.smooks.ui.gef.model.LineConnectionModel">
+ </input>
+ </propertySection>
+ </propertySections>
+ </extension>
+ <extension
+
point="org.eclipse.ui.views.properties.tabbed.propertyContributor">
+ <propertyContributor
+ contributorId="org.jboss.tools.smooks.ui.editors.SmooksFormEditor"
+
typeMapper="org.jboss.tools.smooks.ui.SmooksGraphPropertyTypeMapper">
+ <propertyCategory
+ category="connection"></propertyCategory>
+ </propertyContributor>
+ </extension>
+ <extension
+ point="org.eclipse.ui.views.properties.tabbed.propertyTabs">
+ <propertyTabs
+
contributorId="org.jboss.tools.smooks.ui.editors.SmooksFormEditor">
+ <propertyTab
+ category="connection"
+ id="org.jboss.tools.smooks.ui.connection.propertyTab"
+ label="Mapping Properties">
+ </propertyTab>
+ </propertyTabs>
+ </extension>
+ <extension
+ point="org.eclipse.ui.newWizards">
+ <category
+ id="org.jboss.tools.smooks.ui.wizards"
+ name="Smooks">
+ </category>
+ <wizard
+ category="org.jboss.tools.smooks.ui.wizards"
+
class="org.jboss.tools.smooks.ui.wizards.SmooksConfigFileNewWizard"
+ icon="icons/full/obj16/esb16.png"
+ id="org.jboss.tools.smooks.ui.wizards.SmooksConfigFileNewWizard"
+ name="Smooks Configuration File">
+ </wizard>
+ </extension>
+
+ <extension
+ point="org.jboss.tools.smooks.ui.viewerInitor">
+ <viewerInitor
+
contentProvider="org.jboss.tools.smooks.xml.ui.XMLStructuredDataContentProvider"
+
creationWizard="org.jboss.tools.smooks.xml.ui.XMLStructuredDataWizard"
+ description="XML data type comes from any .xml file."
+
labelProvider="org.jboss.tools.smooks.xml.ui.XMLStructuredDataLabelProvider"
+ name="XML Data Type"
+ typeID="org.jboss.tools.smooks.xml.viewerInitor.xml">
+ </viewerInitor>
+ </extension>
+ <extension
+ point="org.jboss.tools.smooks.ui.analyzer">
+ <mappingAnalyzer
+ class="org.jboss.tools.smooks.xml2xml.XML2XMLAnalyzer"
+ name="XML2XML Analyzer"
+ typeID="org.jboss.tools.smooks.xml.viewerInitor.xml">
+ <targetSourceType
+ id="org.jboss.tools.smooks.xml.viewerInitor.xml"
+ name="XML">
+ </targetSourceType>
+ </mappingAnalyzer>
+ </extension>
+ <extension
+ point="org.jboss.tools.smooks.ui.viewerInitor">
+ <viewerInitor
+
contentProvider="org.jboss.tools.smooks.javabean.model.BeanContentProvider"
+
creationWizard="org.jboss.tools.smooks.javabean.ui.NewJavaBeanStrucutredDataWizard"
+ description="This data type can get from any Java .class."
+
labelProvider="org.jboss.tools.smooks.javabean.model.BeanlabelProvider"
+ name="JavaBean Data Type"
+ typeID="org.jboss.tools.smooks.ui.viewerInitor.javabean">
+ </viewerInitor>
+ </extension>
+ <extension
+ point="org.jboss.tools.smooks.ui.analyzer">
+ <mappingAnalyzer
+ class="org.jboss.tools.smooks.javabean.analyzer.JavaBeanAnalyzer"
+ name="JavaBean Analyzer"
+ typeID="org.jboss.tools.smooks.ui.viewerInitor.javabean">
+ <targetSourceType
+ id="org.jboss.tools.smooks.ui.viewerInitor.javabean"
+ name="java2java">
+ </targetSourceType>
+ </mappingAnalyzer>
+ <sourceModelAnalyzer
+ class="org.jboss.tools.smooks.javabean.analyzer.JavaBeanAnalyzer"
+ level="0"
+ name="JavaBean SourceModel Analyzer"
+ typeID="org.jboss.tools.smooks.ui.viewerInitor.javabean">
+ </sourceModelAnalyzer>
+ <targetModelAnalyzer
+ class="org.jboss.tools.smooks.javabean.analyzer.JavaBeanAnalyzer"
+ level="0"
+ name="JavaBean TargetModel Analyzer"
+ typeID="org.jboss.tools.smooks.ui.viewerInitor.javabean">
+ </targetModelAnalyzer>
+ </extension>
+
+ <extension
+ point="org.jboss.tools.smooks.ui.analyzer">
+ <mappingAnalyzer
+ class="org.jboss.tools.smooks.java2xml.analyzer.Java2XMLAnalyzer"
+ name="Java Bean"
+ typeID="org.jboss.tools.smooks.ui.viewerInitor.javabean">
+ <targetSourceType
+ id="org.jboss.tools.smooks.xml.viewerInitor.xml"
+ name="XML">
+ </targetSourceType>
+ </mappingAnalyzer>
+ </extension>
+
+ <extension
+ point="org.jboss.tools.smooks.ui.analyzer">
+ <mappingAnalyzer
+ class="org.jboss.tools.smooks.xml2java.analyzer.XML2JavaAnalyzer"
+ name="XML2Java"
+ typeID="org.jboss.tools.smooks.xml.viewerInitor.xml">
+ <targetSourceType
+ id="org.jboss.tools.smooks.ui.viewerInitor.javabean"
+ name="JavaBean">
+ </targetSourceType>
+ </mappingAnalyzer>
+ <sourceModelAnalyzer
+
class="org.jboss.tools.smooks.xml2java.analyzer.XMLSourceModelAnalyzer"
+ name="XML"
+ typeID="org.jboss.tools.smooks.xml.viewerInitor.xml">
+ </sourceModelAnalyzer>
+ </extension>
+</plugin>
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/editors/TypeIDSelectionWizardPage.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/editors/TypeIDSelectionWizardPage.java 2008-10-21
09:18:30 UTC (rev 11034)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/editors/TypeIDSelectionWizardPage.java 2008-10-21
09:20:19 UTC (rev 11035)
@@ -1,483 +1,503 @@
-/*******************************************************************************
- * 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.smooks.ui.editors;
-
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.viewers.CheckStateChangedEvent;
-import org.eclipse.jface.viewers.CheckboxTableViewer;
-import org.eclipse.jface.viewers.ICheckStateListener;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.ITableLabelProvider;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jface.wizard.IWizard;
-import org.eclipse.jface.wizard.IWizardContainer;
-import org.eclipse.jface.wizard.IWizardNode;
-import org.eclipse.jface.wizard.IWizardPage;
-import org.eclipse.jface.wizard.WizardPage;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Image;
-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.swt.widgets.TableColumn;
-import org.eclipse.ui.INewWizard;
-import org.eclipse.ui.forms.events.HyperlinkEvent;
-import org.eclipse.ui.forms.events.IHyperlinkListener;
-import org.eclipse.ui.forms.widgets.Hyperlink;
-import org.jboss.tools.smooks.analyzer.AnalyzerFactory;
-import org.jboss.tools.smooks.analyzer.DataTypeID;
-import org.jboss.tools.smooks.ui.IStructuredDataCreationWizard;
-import org.jboss.tools.smooks.ui.IViewerInitor;
-import org.jboss.tools.smooks.ui.StructuredDataCreationWizardDailog;
-import org.jboss.tools.smooks.ui.ViewerInitorStore;
-import org.jboss.tools.smooks.ui.wizards.ISmooksDataCreationAddtionWizard;
-import org.jboss.tools.smooks.ui.wizards.TransformSelectWizardNode;
-
-/**
- * @author Dart Peng<br>
- * Date : Sep 5, 2008
- */
-public class TypeIDSelectionWizardPage extends WizardPage {
- protected IWizard sourceDataCreationWizard;
-
- protected IWizard targetDataCreationWizard;
-
- private Object sourceTreeViewerInputContents;
-
- private Object targetTreeViewerInputContents;
-
- protected CheckboxTableViewer source;
- protected CheckboxTableViewer target;
- private List sourceList;
- private String sourceID = null;
- private String targetID = null;
- private String oldSourceID = null;
- private String oldTargetID = null;
- private IStructuredSelection selection;
- private boolean showDataSelectPage = false;
-
- private Hyperlink sourceDataLink;
-
- private Hyperlink targetDataLink;
-
- public IStructuredSelection getSelection() {
- return selection;
- }
-
- public void setSelection(IStructuredSelection selection) {
- this.selection = selection;
- }
-
- public String getSourceID() {
- return sourceID;
- }
-
- public void setSourceID(String sourceID) {
- this.sourceID = sourceID;
- }
-
- public String getTargetID() {
- return targetID;
- }
-
- public void setTargetID(String targetID) {
- this.targetID = targetID;
- }
-
- public TypeIDSelectionWizardPage(String pageName, boolean showDataSelectPage) {
- super(pageName);
- this.showDataSelectPage = showDataSelectPage;
- }
-
- @Override
- public boolean canFlipToNextPage() {
- if (this.getSourceID() != null || getTargetID() != null) {
- return true;
- }
- return false;
- }
-
- @Override
- public IWizardPage getNextPage() {
- String sourceID = this.getSourceID();
- String targetID = this.getTargetID();
- IStructuredDataCreationWizard sourceWizard = null;
- IStructuredDataCreationWizard targetWizard = null;
- IWizard rootWizard = getWizard();
- ISmooksDataCreationAddtionWizard wizard = (ISmooksDataCreationAddtionWizard)
rootWizard;
- if (sourceID == null) {
- wizard.clearSourceWizardPages();
- }
- if (targetID == null) {
- wizard.clearTargetWizardPages();
- }
- if (sourceID != null && (!sourceID.equals(oldSourceID))) {
- sourceWizard = ViewerInitorStore.getInstance()
- .getStructuredDataCreationWizard(sourceID);
- oldSourceID = sourceID;
- }
- if (targetID != null && (!targetID.equals(oldTargetID))) {
- targetWizard = ViewerInitorStore.getInstance()
- .getStructuredDataCreationWizard(targetID);
- oldTargetID = targetID;
- }
- if (!wizardIsCreated(sourceWizard) && sourceWizard != null) {
- if (sourceWizard instanceof INewWizard) {
- ((INewWizard) sourceWizard).init(null, selection);
- }
- sourceWizard.addPages();
- }
- if (!wizardIsCreated(targetWizard) && targetWizard != null) {
- if (targetWizard instanceof INewWizard) {
- ((INewWizard) targetWizard).init(null, selection);
- }
- targetWizard.addPages();
- }
- addDataCreationPages(sourceWizard, targetWizard);
- return super.getNextPage();
- }
-
- private void addDataCreationPages(IWizard sourceWizard, IWizard targetWizard) {
- IWizard rootWizard = getWizard();
- if (rootWizard instanceof ISmooksDataCreationAddtionWizard) {
- ISmooksDataCreationAddtionWizard wizard = (ISmooksDataCreationAddtionWizard)
rootWizard;
- if (sourceWizard != null) {
- wizard.clearSourceWizardPages();
- IWizardPage[] pages = sourceWizard.getPages();
- for (int i = 0; i < pages.length; i++) {
- IWizardPage p = pages[i];
- wizard.addSourceWizardPage(p);
- p.setWizard(rootWizard);
- }
- }
-
- if (targetWizard != null) {
- wizard.clearTargetWizardPages();
- IWizardPage[] pages = targetWizard.getPages();
- for (int i = 0; i < pages.length; i++) {
- IWizardPage p = pages[i];
- wizard.addTargetWizardPage(p);
- p.setWizard(rootWizard);
- }
- }
- }
- sourceDataCreationWizard = sourceWizard;
- targetDataCreationWizard = targetWizard;
- }
-
- private boolean wizardIsCreated(IWizard wizard) {
- if (wizard == null)
- return false;
- if (wizard.getPageCount() <= 0) {
- return false;
- }
- return true;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
- */
- public void createControl(Composite parent) {
- Composite mainComposite = new Composite(parent, SWT.NONE);
- GridLayout gl = new GridLayout();
- gl.numColumns = 2;
- gl.makeColumnsEqualWidth = true;
- mainComposite.setLayout(gl);
- sourceList = AnalyzerFactory.getInstance().getRegistrySourceIDList();
- Label sl = new Label(mainComposite, SWT.NONE);
- sl.setText("Source Data Type ID List : ");
-
- Label tl = new Label(mainComposite, SWT.NONE);
- tl.setText("Target Data Type ID List : ");
-
- source = createTableViewer(mainComposite);
- GridData gd = new GridData(GridData.FILL_BOTH);
- source.getTable().setLayoutData(gd);
- target = createTableViewer(mainComposite);
- target.getTable().setLayoutData(gd);
-
- source.setInput(sourceList);
- target.setInput(sourceList);
- initViewer();
-
- sourceDataLink = new Hyperlink(mainComposite, SWT.NONE);
- sourceDataLink.setText("Source Model Select:Empty");
- sourceDataLink.addHyperlinkListener(new IHyperlinkListener() {
-
- public void linkActivated(HyperlinkEvent e) {
- openSourceWizard();
- }
-
- public void linkEntered(HyperlinkEvent e) {
-
- }
-
- public void linkExited(HyperlinkEvent e) {
-
- }
-
- });
- // TODO don't show this
- sourceDataLink.setVisible(false);
- targetDataLink = new Hyperlink(mainComposite, SWT.NONE);
- targetDataLink.setText("Target Model Select:Empty");
- targetDataLink.addHyperlinkListener(new IHyperlinkListener() {
-
- public void linkActivated(HyperlinkEvent e) {
- openTargetWizard();
- }
-
- public void linkEntered(HyperlinkEvent e) {
-
- }
-
- public void linkExited(HyperlinkEvent e) {
-
- }
-
- });
- // TODO don't show this
- targetDataLink.setVisible(false);
-
- this.setControl(mainComposite);
- }
-
- protected void openTargetWizard() {
- targetTreeViewerInputContents = getReturnObjectFromWizard(getTargetID());
- resetLinkText();
- }
-
- protected IWizard getWizardViaDataID(String dataID) {
- if (dataID == null)
- return null;
- IWizardNode wn = getSourceWizard(dataID);
- // setSelectedNode(wn);
- IWizard sw = wn.getWizard();
- if (sw instanceof IStructuredDataCreationWizard) {
- // ((IStrucutredDataCreationWizard)sw).i
- }
- if (sw instanceof INewWizard) {
- ((INewWizard) sw).init(null, this.getSelection());
- }
- return sw;
- }
-
- protected Object getReturnObjectFromWizard(String dataID) {
- IWizard wizard = getWizardViaDataID(dataID);
- if (wizard != null) {
- StructuredDataCreationWizardDailog dialog = new StructuredDataCreationWizardDailog(
- getShell(), wizard);
- if (dialog.open() == Dialog.OK) {
- return dialog.getCurrentCreationWizard()
- .getTreeViewerInputContents();
- }
- } else {
- MessageDialog.openInformation(getShell(), "Info",
- "Please select the data type first");
- }
-
- return null;
- }
-
- protected void openSourceWizard() {
- sourceTreeViewerInputContents = getReturnObjectFromWizard(getSourceID());
- resetLinkText();
- }
-
- private void resetLinkText() {
- if (sourceTreeViewerInputContents != null) {
- sourceDataLink.setText("Source Model Select");
- }
-
- if (targetTreeViewerInputContents != null) {
- targetDataLink.setText("Target Model Select");
- }
- }
-
- protected String getDataTypeID(CheckboxTableViewer viewer) {
- Object[] objs = viewer.getCheckedElements();
- if (objs == null)
- return null;
- if (objs.length <= 0)
- return null;
- DataTypeID d = (DataTypeID) objs[0];
- return d.getId();
- }
-
- protected void initViewer() {
- IWizard wizard = this.getWizard();
- if (wizard instanceof TypeIDSelectionWizard) {
- String s = ((TypeIDSelectionWizard) wizard).getSourceDataTypeID();
- String t = ((TypeIDSelectionWizard) wizard).getTargetDataTypeID();
- this.setSourceID(s);
- this.setTargetID(t);
- if (initViewerCheckState(s, source)) {
- source.getTable().setEnabled(false);
- }
- if (initViewerCheckState(t, target)) {
- target.getTable().setEnabled(false);
- }
- }
- }
-
- protected boolean initViewerCheckState(String id, CheckboxTableViewer viewer) {
- if (id == null)
- return false;
- List l = (List) viewer.getInput();
- for (Iterator iterator = l.iterator(); iterator.hasNext();) {
- DataTypeID dti = (DataTypeID) iterator.next();
- if (id.equals(dti.getId())) {
- viewer.setChecked(dti, true);
- return true;
- }
- }
- return false;
- }
-
- private IWizardNode getSourceWizard(String id) {
- Collection<IViewerInitor> viewers = ViewerInitorStore.getInstance()
- .getViewerInitorCollection();
- for (Iterator iterator = viewers.iterator(); iterator.hasNext();) {
- IViewerInitor viewerInitor = (IViewerInitor) iterator.next();
- if (viewerInitor.getTypeID().equals(id)) {
- TransformSelectWizardNode wn = new TransformSelectWizardNode();
- IStructuredDataCreationWizard wizard = viewerInitor
- .getStructuredDataLoadWizard();
- if (wizard == null)
- return null;
- wn.setWizard(wizard);
- wn.setName(viewerInitor.getName());
- wn.setIconPath(viewerInitor.getWizardIconPath());
- wn.setDescription(viewerInitor.getDescription());
- return wn;
- }
- }
- return null;
- }
-
- protected CheckboxTableViewer createTableViewer(Composite parent) {
- final CheckboxTableViewer viewer = CheckboxTableViewer.newCheckList(
- parent, SWT.FULL_SELECTION);
- viewer.addCheckStateListener(new ICheckStateListener() {
- private boolean fireEvent = true;
-
- public void checkStateChanged(CheckStateChangedEvent event) {
- if (!fireEvent)
- return;
- boolean check = event.getChecked();
- if (check) {
- fireEvent = false;
- viewer.setAllChecked(false);
- viewer.setChecked(event.getElement(), true);
- fireEvent = true;
- }
-
- if (viewer == source) {
- String sourceID = getDataTypeID(source);
- setSourceID(sourceID);
- }
-
- if (viewer == target) {
- String targetID = getDataTypeID(target);
- setTargetID(targetID);
- }
- IWizardContainer container = getContainer();
- if (container != null) {
- container.updateButtons();
- }
- }
-
- });
- TableColumn nameColumn = new TableColumn(viewer.getTable(), SWT.NONE);
- nameColumn.setWidth(100);
- nameColumn.setText("Name");
- viewer.setContentProvider(new TypeIDContentProvider());
- viewer.setLabelProvider(new TypeIDLabelProvider());
- return viewer;
- }
-
- private class TypeIDContentProvider implements IStructuredContentProvider {
-
- public Object[] getElements(Object inputElement) {
- if (inputElement instanceof List) {
- return ((List) inputElement).toArray();
- }
- return new Object[] {};
- }
-
- public void dispose() {
-
- }
-
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- }
-
- }
-
- private class TypeIDLabelProvider extends LabelProvider implements
- ITableLabelProvider {
-
- public Image getColumnImage(Object element, int columnIndex) {
-
- return null;
- }
-
- public String getColumnText(Object element, int columnIndex) {
- if (element instanceof DataTypeID) {
- switch (columnIndex) {
- case 0:
- return ((DataTypeID) element).getName();
- // case 1:
- // return ((DataTypeID) element).getId();
- }
- }
- return "";
- }
-
- }
-
-
- public Object getSourceTreeViewerInputContents() {
- return sourceTreeViewerInputContents;
- }
-
- public void setSourceTreeViewerInputContents(
- Object sourceTreeViewerInputContents) {
- this.sourceTreeViewerInputContents = sourceTreeViewerInputContents;
- }
-
- public Object getTargetTreeViewerInputContents() {
- return targetTreeViewerInputContents;
- }
-
- public void setTargetTreeViewerInputContents(
- Object targetTreeViewerInputContents) {
- this.targetTreeViewerInputContents = targetTreeViewerInputContents;
- }
-
- public IWizard getSourceDataCreationWizard() {
- return sourceDataCreationWizard;
- }
-
- public IWizard getTargetDataCreationWizard() {
- return targetDataCreationWizard;
- }
-}
+/*******************************************************************************
+ * 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.smooks.ui.editors;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.draw2d.ColorConstants;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.CheckStateChangedEvent;
+import org.eclipse.jface.viewers.CheckboxTableViewer;
+import org.eclipse.jface.viewers.ICheckStateListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.wizard.IWizard;
+import org.eclipse.jface.wizard.IWizardContainer;
+import org.eclipse.jface.wizard.IWizardNode;
+import org.eclipse.jface.wizard.IWizardPage;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.FillLayout;
+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.swt.widgets.TableColumn;
+import org.eclipse.ui.INewWizard;
+import org.eclipse.ui.forms.events.HyperlinkEvent;
+import org.eclipse.ui.forms.events.IHyperlinkListener;
+import org.eclipse.ui.forms.widgets.Hyperlink;
+import org.jboss.tools.smooks.analyzer.AnalyzerFactory;
+import org.jboss.tools.smooks.analyzer.DataTypeID;
+import org.jboss.tools.smooks.ui.IStructuredDataCreationWizard;
+import org.jboss.tools.smooks.ui.IViewerInitor;
+import org.jboss.tools.smooks.ui.StructuredDataCreationWizardDailog;
+import org.jboss.tools.smooks.ui.ViewerInitorStore;
+import org.jboss.tools.smooks.ui.wizards.ISmooksDataCreationAddtionWizard;
+import org.jboss.tools.smooks.ui.wizards.TransformSelectWizardNode;
+
+/**
+ * @author Dart Peng<br>
+ * Date : Sep 5, 2008
+ */
+public class TypeIDSelectionWizardPage extends WizardPage {
+ protected IWizard sourceDataCreationWizard;
+
+ protected IWizard targetDataCreationWizard;
+
+ private Object sourceTreeViewerInputContents;
+
+ private Object targetTreeViewerInputContents;
+
+ protected CheckboxTableViewer source;
+ protected CheckboxTableViewer target;
+ private List sourceList;
+ private String sourceID = null;
+ private String targetID = null;
+ private String oldSourceID = null;
+ private String oldTargetID = null;
+ private IStructuredSelection selection;
+ private boolean showDataSelectPage = false;
+
+ private Hyperlink sourceDataLink;
+
+ private Hyperlink targetDataLink;
+
+ public IStructuredSelection getSelection() {
+ return selection;
+ }
+
+ public void setSelection(IStructuredSelection selection) {
+ this.selection = selection;
+ }
+
+ public String getSourceID() {
+ return sourceID;
+ }
+
+ public void setSourceID(String sourceID) {
+ this.sourceID = sourceID;
+ }
+
+ public String getTargetID() {
+ return targetID;
+ }
+
+ public void setTargetID(String targetID) {
+ this.targetID = targetID;
+ }
+
+ public TypeIDSelectionWizardPage(String pageName, boolean showDataSelectPage) {
+ super(pageName);
+ this.showDataSelectPage = showDataSelectPage;
+ setTitle("Select Source/Target Data Type");
+ setDescription("Select the data type for source/target data");
+ }
+
+ @Override
+ public boolean canFlipToNextPage() {
+ if (this.getSourceID() != null && getTargetID() != null) {
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public IWizardPage getNextPage() {
+ String sourceID = this.getSourceID();
+ String targetID = this.getTargetID();
+ IStructuredDataCreationWizard sourceWizard = null;
+ IStructuredDataCreationWizard targetWizard = null;
+ IWizard rootWizard = getWizard();
+ ISmooksDataCreationAddtionWizard wizard = (ISmooksDataCreationAddtionWizard)
rootWizard;
+ if (sourceID == null) {
+ wizard.clearSourceWizardPages();
+ }
+ if (targetID == null) {
+ wizard.clearTargetWizardPages();
+ }
+ if (sourceID != null && (!sourceID.equals(oldSourceID))) {
+ sourceWizard = ViewerInitorStore.getInstance()
+ .getStructuredDataCreationWizard(sourceID);
+ oldSourceID = sourceID;
+ }
+ if (targetID != null && (!targetID.equals(oldTargetID))) {
+ targetWizard = ViewerInitorStore.getInstance()
+ .getStructuredDataCreationWizard(targetID);
+ oldTargetID = targetID;
+ }
+ if (!wizardIsCreated(sourceWizard) && sourceWizard != null) {
+ if (sourceWizard instanceof INewWizard) {
+ ((INewWizard) sourceWizard).init(null, selection);
+ }
+ sourceWizard.addPages();
+ }
+ if (!wizardIsCreated(targetWizard) && targetWizard != null) {
+ if (targetWizard instanceof INewWizard) {
+ ((INewWizard) targetWizard).init(null, selection);
+ }
+ targetWizard.addPages();
+ }
+ addDataCreationPages(sourceWizard, targetWizard);
+ return super.getNextPage();
+ }
+
+ private void addDataCreationPages(IWizard sourceWizard, IWizard targetWizard) {
+ IWizard rootWizard = getWizard();
+ if (rootWizard instanceof ISmooksDataCreationAddtionWizard) {
+ ISmooksDataCreationAddtionWizard wizard = (ISmooksDataCreationAddtionWizard)
rootWizard;
+ if (sourceWizard != null) {
+ wizard.clearSourceWizardPages();
+ IWizardPage[] pages = sourceWizard.getPages();
+ for (int i = 0; i < pages.length; i++) {
+ IWizardPage p = pages[i];
+ wizard.addSourceWizardPage(p);
+ p.setWizard(rootWizard);
+ }
+ }
+
+ if (targetWizard != null) {
+ wizard.clearTargetWizardPages();
+ IWizardPage[] pages = targetWizard.getPages();
+ for (int i = 0; i < pages.length; i++) {
+ IWizardPage p = pages[i];
+ wizard.addTargetWizardPage(p);
+ p.setWizard(rootWizard);
+ }
+ }
+ }
+ sourceDataCreationWizard = sourceWizard;
+ targetDataCreationWizard = targetWizard;
+ }
+
+ private boolean wizardIsCreated(IWizard wizard) {
+ if (wizard == null)
+ return false;
+ if (wizard.getPageCount() <= 0) {
+ return false;
+ }
+ return true;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
+ */
+ public void createControl(Composite parent) {
+ Composite mainComposite = new Composite(parent, SWT.NONE);
+ GridLayout gl = new GridLayout();
+ gl.numColumns = 2;
+ gl.makeColumnsEqualWidth = true;
+ mainComposite.setLayout(gl);
+ sourceList = AnalyzerFactory.getInstance().getRegistrySourceIDList();
+ Label sl = new Label(mainComposite, SWT.NONE);
+ sl.setText("Source Data Type ID List : ");
+
+ Label tl = new Label(mainComposite, SWT.NONE);
+ tl.setText("Target Data Type ID List : ");
+
+ Composite sourceBorder = new Composite(mainComposite,SWT.NONE);
+ sourceBorder.setBackground(ColorConstants.black);
+ FillLayout sbLayout = new FillLayout();
+ sbLayout.marginHeight = 1;
+ sbLayout.marginWidth = 1;
+ sourceBorder.setLayout(sbLayout);
+ source = createTableViewer(sourceBorder);
+ GridData gd = new GridData(GridData.FILL_BOTH);
+ sourceBorder.setLayoutData(gd);
+
+
+ Composite targetBorder = new Composite(mainComposite,SWT.NONE);
+ targetBorder.setBackground(ColorConstants.black);
+ FillLayout tbLayout = new FillLayout();
+ tbLayout.marginHeight = 1;
+ tbLayout.marginWidth = 1;
+ targetBorder.setLayout(tbLayout);
+ target = createTableViewer(targetBorder);
+ targetBorder.setLayoutData(gd);
+
+ source.setInput(sourceList);
+ target.setInput(sourceList);
+ initViewer();
+
+ sourceDataLink = new Hyperlink(mainComposite, SWT.NONE);
+ sourceDataLink.setText("Source Model Select:Empty");
+ sourceDataLink.addHyperlinkListener(new IHyperlinkListener() {
+
+ public void linkActivated(HyperlinkEvent e) {
+ openSourceWizard();
+ }
+
+ public void linkEntered(HyperlinkEvent e) {
+
+ }
+
+ public void linkExited(HyperlinkEvent e) {
+
+ }
+
+ });
+ // TODO don't show this
+ sourceDataLink.setVisible(false);
+ targetDataLink = new Hyperlink(mainComposite, SWT.NONE);
+ targetDataLink.setText("Target Model Select:Empty");
+ targetDataLink.addHyperlinkListener(new IHyperlinkListener() {
+
+ public void linkActivated(HyperlinkEvent e) {
+ openTargetWizard();
+ }
+
+ public void linkEntered(HyperlinkEvent e) {
+
+ }
+
+ public void linkExited(HyperlinkEvent e) {
+
+ }
+
+ });
+ // TODO don't show this
+ targetDataLink.setVisible(false);
+
+ this.setControl(mainComposite);
+ }
+
+ protected void openTargetWizard() {
+ targetTreeViewerInputContents = getReturnObjectFromWizard(getTargetID());
+ resetLinkText();
+ }
+
+ protected IWizard getWizardViaDataID(String dataID) {
+ if (dataID == null)
+ return null;
+ IWizardNode wn = getSourceWizard(dataID);
+ // setSelectedNode(wn);
+ IWizard sw = wn.getWizard();
+ if (sw instanceof IStructuredDataCreationWizard) {
+ // ((IStrucutredDataCreationWizard)sw).i
+ }
+ if (sw instanceof INewWizard) {
+ ((INewWizard) sw).init(null, this.getSelection());
+ }
+ return sw;
+ }
+
+ protected Object getReturnObjectFromWizard(String dataID) {
+ IWizard wizard = getWizardViaDataID(dataID);
+ if (wizard != null) {
+ StructuredDataCreationWizardDailog dialog = new StructuredDataCreationWizardDailog(
+ getShell(), wizard);
+ if (dialog.open() == Dialog.OK) {
+ return dialog.getCurrentCreationWizard()
+ .getTreeViewerInputContents();
+ }
+ } else {
+ MessageDialog.openInformation(getShell(), "Info",
+ "Please select the data type first");
+ }
+
+ return null;
+ }
+
+ protected void openSourceWizard() {
+ sourceTreeViewerInputContents = getReturnObjectFromWizard(getSourceID());
+// resetLinkText();
+ }
+/**
+ * @deprecated
+ */
+ private void resetLinkText() {
+ // if (sourceTreeViewerInputContents != null) {
+ // sourceDataLink.setText("Source Model Select");
+ // }
+ //
+ // if (targetTreeViewerInputContents != null) {
+ // targetDataLink.setText("Target Model Select");
+ // }
+ }
+
+ protected String getDataTypeID(CheckboxTableViewer viewer) {
+ Object[] objs = viewer.getCheckedElements();
+ if (objs == null)
+ return null;
+ if (objs.length <= 0)
+ return null;
+ DataTypeID d = (DataTypeID) objs[0];
+ return d.getId();
+ }
+
+ protected void initViewer() {
+ IWizard wizard = this.getWizard();
+ if (wizard instanceof TypeIDSelectionWizard) {
+ String s = ((TypeIDSelectionWizard) wizard).getSourceDataTypeID();
+ String t = ((TypeIDSelectionWizard) wizard).getTargetDataTypeID();
+ this.setSourceID(s);
+ this.setTargetID(t);
+ if (initViewerCheckState(s, source)) {
+ source.getTable().setEnabled(false);
+ }
+ if (initViewerCheckState(t, target)) {
+ target.getTable().setEnabled(false);
+ }
+ }
+ }
+
+ protected boolean initViewerCheckState(String id, CheckboxTableViewer viewer) {
+ if (id == null)
+ return false;
+ List l = (List) viewer.getInput();
+ for (Iterator iterator = l.iterator(); iterator.hasNext();) {
+ DataTypeID dti = (DataTypeID) iterator.next();
+ if (id.equals(dti.getId())) {
+ viewer.setChecked(dti, true);
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private IWizardNode getSourceWizard(String id) {
+ Collection<IViewerInitor> viewers = ViewerInitorStore.getInstance()
+ .getViewerInitorCollection();
+ for (Iterator iterator = viewers.iterator(); iterator.hasNext();) {
+ IViewerInitor viewerInitor = (IViewerInitor) iterator.next();
+ if (viewerInitor.getTypeID().equals(id)) {
+ TransformSelectWizardNode wn = new TransformSelectWizardNode();
+ IStructuredDataCreationWizard wizard = viewerInitor
+ .getStructuredDataLoadWizard();
+ if (wizard == null)
+ return null;
+ wn.setWizard(wizard);
+ wn.setName(viewerInitor.getName());
+ wn.setIconPath(viewerInitor.getWizardIconPath());
+ wn.setDescription(viewerInitor.getDescription());
+ return wn;
+ }
+ }
+ return null;
+ }
+
+ protected CheckboxTableViewer createTableViewer(Composite parent) {
+ final CheckboxTableViewer viewer = CheckboxTableViewer.newCheckList(
+ parent, SWT.FULL_SELECTION);
+ viewer.addCheckStateListener(new ICheckStateListener() {
+ private boolean fireEvent = true;
+
+ public void checkStateChanged(CheckStateChangedEvent event) {
+ if (!fireEvent)
+ return;
+ boolean check = event.getChecked();
+ if (check) {
+ fireEvent = false;
+ viewer.setAllChecked(false);
+ viewer.setChecked(event.getElement(), true);
+ fireEvent = true;
+ }
+
+ if (viewer == source) {
+ String sourceID = getDataTypeID(source);
+ setSourceID(sourceID);
+ }
+
+ if (viewer == target) {
+ String targetID = getDataTypeID(target);
+ setTargetID(targetID);
+ }
+ IWizardContainer container = getContainer();
+ if (container != null) {
+ container.updateButtons();
+ }
+ }
+
+ });
+ TableColumn nameColumn = new TableColumn(viewer.getTable(), SWT.NONE);
+ nameColumn.setWidth(250);
+ nameColumn.setText("Name");
+ viewer.setContentProvider(new TypeIDContentProvider());
+ viewer.setLabelProvider(new TypeIDLabelProvider());
+ return viewer;
+ }
+
+ private class TypeIDContentProvider implements IStructuredContentProvider {
+
+ public Object[] getElements(Object inputElement) {
+ if (inputElement instanceof List) {
+ return ((List) inputElement).toArray();
+ }
+ return new Object[] {};
+ }
+
+ public void dispose() {
+
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+
+ }
+
+ private class TypeIDLabelProvider extends LabelProvider implements
+ ITableLabelProvider {
+
+ public Image getColumnImage(Object element, int columnIndex) {
+
+ return null;
+ }
+
+ public String getColumnText(Object element, int columnIndex) {
+ if (element instanceof DataTypeID) {
+ switch (columnIndex) {
+ case 0:
+ return ((DataTypeID) element).getName();
+ // case 1:
+ // return ((DataTypeID) element).getId();
+ }
+ }
+ return "";
+ }
+
+ }
+
+
+ public Object getSourceTreeViewerInputContents() {
+ return sourceTreeViewerInputContents;
+ }
+
+ public void setSourceTreeViewerInputContents(
+ Object sourceTreeViewerInputContents) {
+ this.sourceTreeViewerInputContents = sourceTreeViewerInputContents;
+ }
+
+ public Object getTargetTreeViewerInputContents() {
+ return targetTreeViewerInputContents;
+ }
+
+ public void setTargetTreeViewerInputContents(
+ Object targetTreeViewerInputContents) {
+ this.targetTreeViewerInputContents = targetTreeViewerInputContents;
+ }
+
+ public IWizard getSourceDataCreationWizard() {
+ return sourceDataCreationWizard;
+ }
+
+ public IWizard getTargetDataCreationWizard() {
+ return targetDataCreationWizard;
+ }
+}
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/wizards/NewResourceConfigWizardPage.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/wizards/NewResourceConfigWizardPage.java 2008-10-21
09:18:30 UTC (rev 11034)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/wizards/NewResourceConfigWizardPage.java 2008-10-21
09:20:19 UTC (rev 11035)
@@ -1,128 +1,131 @@
-/*******************************************************************************
- * 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.smooks.ui.wizards;
-
-import java.util.List;
-
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jface.wizard.WizardPage;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.widgets.Composite;
-
-/**
- * @author Dart Peng<br>
- * Date : Sep 18, 2008
- */
-public class NewResourceConfigWizardPage extends WizardPage implements
ISelectionChangedListener{
-
- private NewResourceConfigKey selectedKey = null;
-
- public NewResourceConfigWizardPage(String pageName, String title,
- ImageDescriptor titleImage) {
- super(pageName, title, titleImage);
- // TODO Auto-generated constructor stub
- }
-
- public NewResourceConfigWizardPage(String pageName) {
- super(pageName);
- }
-
- /* (non-Javadoc)
- * @see
org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
- */
- public void createControl(Composite parent) {
- Composite mainComposite = new Composite(parent,SWT.NONE);
- FillLayout layout = new FillLayout();
-// layout.marginHeight = 350;
- mainComposite.setLayout(layout);
- TableViewer viewer = new TableViewer(mainComposite);
- viewer.setContentProvider(new NewResourceConfigKeyContentProvider());
- viewer.setLabelProvider(new NewResourceConfigKeyLabelProvider());
- viewer.setInput(NewResourceConfigFactory.getInstance().getAllIDs());
- viewer.addSelectionChangedListener(this);
- setControl(mainComposite);
-
- validatePageFinish();
- }
-
- protected void validatePageFinish(){
- String error = null;
- if(selectedKey == null){
- error = "Please select one key";
- }
-
- setErrorMessage(error);
- setPageComplete(error == null);
- }
-
- private class NewResourceConfigKeyContentProvider implements
IStructuredContentProvider{
-
- public Object[] getElements(Object inputElement) {
- if(inputElement instanceof List){
- return ((List)inputElement).toArray();
- }
- if(inputElement.getClass().isArray()){
- return (Object[])inputElement;
- }
- return new Object[]{};
- }
-
- public void dispose() {
-
- }
-
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
-
- }
-
- }
-
- private class NewResourceConfigKeyLabelProvider extends LabelProvider{
-
- public Image getImage(Object element) {
- if(element instanceof NewResourceConfigKey){
- return ((NewResourceConfigKey)element).getImage();
- }
- return super.getImage(element);
- }
-
- public String getText(Object element) {
- if(element instanceof NewResourceConfigKey){
- return ((NewResourceConfigKey)element).getName();
- }
- return super.getText(element);
- }
-
- }
-
- public void selectionChanged(SelectionChangedEvent event) {
- Object obj = ((IStructuredSelection)event.getSelection()).getFirstElement();
- if(obj != null && obj instanceof NewResourceConfigKey){
- selectedKey = (NewResourceConfigKey)obj;
- }
-
- validatePageFinish();
- }
-
- public NewResourceConfigKey getSelectedKey() {
- return selectedKey;
- }
-
-}
+/*******************************************************************************
+ * 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.smooks.ui.wizards;
+
+import java.util.List;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Composite;
+
+/**
+ * @author Dart Peng<br>
+ * Date : Sep 18, 2008
+ */
+public class NewResourceConfigWizardPage extends WizardPage implements
ISelectionChangedListener{
+
+ private NewResourceConfigKey selectedKey = null;
+
+
+ public NewResourceConfigWizardPage(String pageName, String title,
+ ImageDescriptor titleImage) {
+ super(pageName, "Select New ResourceConfig Type", titleImage);
+ setDescription("Select the ResourceConfig type to add into the config
file");
+ }
+
+ public NewResourceConfigWizardPage(String pageName) {
+ super(pageName);
+ setTitle("Select New ResourceConfig Type");
+ setDescription("Select the ResourceConfig type to add into the config
file");
+ }
+
+ /* (non-Javadoc)
+ * @see
org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
+ */
+ public void createControl(Composite parent) {
+ Composite mainComposite = new Composite(parent,SWT.NONE);
+ FillLayout layout = new FillLayout();
+// layout.marginHeight = 350;
+ mainComposite.setLayout(layout);
+ TableViewer viewer = new TableViewer(mainComposite);
+ viewer.setContentProvider(new NewResourceConfigKeyContentProvider());
+ viewer.setLabelProvider(new NewResourceConfigKeyLabelProvider());
+ viewer.setInput(NewResourceConfigFactory.getInstance().getAllIDs());
+ viewer.addSelectionChangedListener(this);
+ setControl(mainComposite);
+
+ validatePageFinish();
+ }
+
+ protected void validatePageFinish(){
+ String error = null;
+ if(selectedKey == null){
+ error = "Please select one key";
+ }
+
+ setErrorMessage(error);
+ setPageComplete(error == null);
+ }
+
+ private class NewResourceConfigKeyContentProvider implements
IStructuredContentProvider{
+
+ public Object[] getElements(Object inputElement) {
+ if(inputElement instanceof List){
+ return ((List)inputElement).toArray();
+ }
+ if(inputElement.getClass().isArray()){
+ return (Object[])inputElement;
+ }
+ return new Object[]{};
+ }
+
+ public void dispose() {
+
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+
+ }
+
+ }
+
+ private class NewResourceConfigKeyLabelProvider extends LabelProvider{
+
+ public Image getImage(Object element) {
+ if(element instanceof NewResourceConfigKey){
+ return ((NewResourceConfigKey)element).getImage();
+ }
+ return super.getImage(element);
+ }
+
+ public String getText(Object element) {
+ if(element instanceof NewResourceConfigKey){
+ return ((NewResourceConfigKey)element).getName();
+ }
+ return super.getText(element);
+ }
+
+ }
+
+ public void selectionChanged(SelectionChangedEvent event) {
+ Object obj = ((IStructuredSelection)event.getSelection()).getFirstElement();
+ if(obj != null && obj instanceof NewResourceConfigKey){
+ selectedKey = (NewResourceConfigKey)obj;
+ }
+
+ validatePageFinish();
+ }
+
+ public NewResourceConfigKey getSelectedKey() {
+ return selectedKey;
+ }
+
+}
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/wizards/SmooksConfigFileNewWizard.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/wizards/SmooksConfigFileNewWizard.java 2008-10-21
09:18:30 UTC (rev 11034)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/wizards/SmooksConfigFileNewWizard.java 2008-10-21
09:20:19 UTC (rev 11035)
@@ -1,301 +1,304 @@
-package org.jboss.tools.smooks.ui.wizards;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.lang.reflect.InvocationTargetException;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.operation.IRunnableWithProgress;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.wizard.IWizard;
-import org.eclipse.jface.wizard.IWizardPage;
-import org.eclipse.jface.wizard.Wizard;
-import org.eclipse.ui.INewWizard;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.ide.IDE;
-import org.jboss.tools.smooks.graphical.util.GraphicalInformationSaver;
-import org.jboss.tools.smooks.ui.IStructuredDataCreationWizard;
-import org.jboss.tools.smooks.ui.editors.SmooksFileEditorInput;
-import org.jboss.tools.smooks.ui.editors.SmooksFormEditor;
-import org.jboss.tools.smooks.ui.editors.TypeIDSelectionWizardPage;
-
-/**
- * This is a sample new wizard. Its role is to create a new file resource in the
- * provided container. If the container resource (a folder or a project) is
- * selected in the workspace when the wizard is opened, it will accept it as the
- * target container. The wizard creates one file with the extension "smooks".
If
- * a sample multi-page editor (also available as a template) is registered for
- * the same extension, it will be able to open it.
- */
-
-public class SmooksConfigFileNewWizard extends Wizard implements INewWizard,
- ISmooksDataCreationAddtionWizard {
- private SmooksConfigFileNewWizardPage page;
- private TypeIDSelectionWizardPage typeIDPage;
-
- private List<IWizardPage> sourceCreationPages = new
ArrayList<IWizardPage>();
-
- private List<IWizardPage> targetCreationPages = new
ArrayList<IWizardPage>();
-
- private IStructuredSelection selection;
-
- private IWorkbench workbench;
-
- /**
- * Constructor for SmooksConfigFileNewWizard.
- */
- public SmooksConfigFileNewWizard() {
- super();
- setNeedsProgressMonitor(true);
- }
-
- /**
- * Adding the page to the wizard.
- */
- public void addPages() {
- page = new SmooksConfigFileNewWizardPage("newSmooksFile1",
- getSelection());
- addPage(page);
- // TODO don't use the WizardSelectionPage
- typeIDPage = new TypeIDSelectionWizardPage("", false);
- typeIDPage.setSelection(selection);
- addPage(typeIDPage);
- }
-
- /**
- * This method is called when 'Finish' button is pressed in the wizard. We
- * will create an operation and run it using wizard as execution context.
- */
- public boolean performFinish() {
- // final String containerName = page.getContainerName();
- // final String fileName = page.getFileName();
- final IFile file = page.createNewFile();
- IRunnableWithProgress op = new IRunnableWithProgress() {
- public void run(IProgressMonitor monitor)
- throws InvocationTargetException {
- try {
- doFinish(file, monitor);
- } catch (CoreException e) {
- throw new InvocationTargetException(e);
- } finally {
- monitor.done();
- }
- }
- };
- try {
- getContainer().run(true, false, op);
- } catch (InterruptedException e) {
- return false;
- } catch (InvocationTargetException e) {
- Throwable realException = e.getTargetException();
- MessageDialog.openError(getShell(), "Error", realException
- .getMessage());
- return false;
- }
- return true;
- }
-
- /**
- * The worker method. It will find the container, create the file if missing
- * or just replace its contents, and open the editor on the newly created
- * file.
- */
-
- private void doFinish(final IFile file, IProgressMonitor monitor)
- throws CoreException {
- // create a sample file
- String sourceTypeID = typeIDPage.getSourceID();
- String targetTypeID = typeIDPage.getTargetID();
-
- try {
- InputStream stream = openContentStream();
- if (file.exists()) {
- file.setContents(stream, true, true, monitor);
- } else {
- file.create(stream, true, monitor);
- }
- stream.close();
- GraphicalInformationSaver ginforSave = new GraphicalInformationSaver(
- file);
- ginforSave.doSave(monitor, sourceTypeID, targetTypeID);
- } catch (IOException e) {
- }
- monitor.worked(1);
- monitor.setTaskName("Opening file for editing...");
- getShell().getDisplay().asyncExec(new Runnable() {
- public void run() {
- IWorkbenchPage page = PlatformUI.getWorkbench()
- .getActiveWorkbenchWindow().getActivePage();
- try {
- SmooksFileEditorInput input = new SmooksFileEditorInput(
- file);
- IWizard sourceWizard = typeIDPage
- .getSourceDataCreationWizard();
- IWizard targetWizard = typeIDPage
- .getTargetDataCreationWizard();
- if (sourceWizard != null) {
- sourceWizard.performFinish();
- }
- if (targetWizard != null) {
- targetWizard.performFinish();
- }
- if (sourceWizard instanceof IStructuredDataCreationWizard) {
- Object sourceObj = ((IStructuredDataCreationWizard) sourceWizard)
- .getTreeViewerInputContents();
-// if (sourceObj instanceof List) {
-// if (!((List) sourceObj).isEmpty()) {
-// sourceObj = ((List) sourceObj).get(0);
-// }
-// }
- input.setSourceTreeViewerInputContents(sourceObj);
- }
-
- if (targetWizard instanceof IStructuredDataCreationWizard) {
- Object targetObj = ((IStructuredDataCreationWizard) targetWizard)
- .getTreeViewerInputContents();
-// if (targetObj instanceof List) {
-// if (!((List) targetObj).isEmpty()) {
-// targetObj = ((List) targetObj).get(0);
-// }
-// }
- input.setTargetTreeViewerInputContents(targetObj);
-
- }
-
- IDE.openEditor(page, input, SmooksFormEditor.EDITOR_ID,
- true);// openEditor(page, file, true);
- } catch (PartInitException e) {
- }
- }
- });
- monitor.worked(1);
- }
-
- /**
- * We will initialize file contents with a sample text.
- */
-
- private InputStream openContentStream() {
- String contents = "<?xml version=\"1.0\"
encoding=\"UTF-8\"?>\n"
- + " <smooks-resource-list
xmlns=\"http://www.milyn.org/xsd/smooks-1.0.xsd\"/>";
- return new ByteArrayInputStream(contents.getBytes());
- }
-
- private void throwCoreException(String message) throws CoreException {
- IStatus status = new Status(IStatus.ERROR, "org.jboss.tools.smooks.ui",
- IStatus.OK, message, null);
- throw new CoreException(status);
- }
-
- public void init(IWorkbench workbench, IStructuredSelection selection) {
- this.workbench = workbench;
- this.selection = selection;
- }
-
- public IStructuredSelection getSelection() {
- return selection;
- }
-
- public void setSelection(IStructuredSelection selection) {
- this.selection = selection;
- }
-
- public void addSourceWizardPage(IWizardPage page) {
- sourceCreationPages.add(page);
- page.setTitle("Source Data Selection Page");
- }
-
- public void addTargetWizardPage(IWizardPage page) {
- targetCreationPages.add(page);
- page.setTitle("Target Data Selection Page");
- }
-
- public void clearSourceWizardPages() {
- // for (Iterator iterator = sourceCreationPages.iterator();
- // iterator.hasNext();) {
- // IWizardPage page = (IWizardPage) iterator.next();
- // if(page != null){
- // page.dispose();
- // }
- // }
- sourceCreationPages.clear();
- }
-
- private IWizardPage getSourceCreationPage(IWizardPage page) {
- if (page == typeIDPage) {
- if (sourceCreationPages.isEmpty())
- return null;
- return (IWizardPage) sourceCreationPages.get(0);
- }
- if (sourceCreationPages.contains(page)) {
- int i = sourceCreationPages.indexOf(page);
- if ((i + 1) >= sourceCreationPages.size()) {
- return null;
- }
- return (IWizardPage) sourceCreationPages.get(i + 1);
- }
- return null;
- }
-
- private IWizardPage getTargetCreationPage(IWizardPage page) {
- if (page == typeIDPage) {
- if (targetCreationPages.isEmpty())
- return null;
- return (IWizardPage) targetCreationPages.get(0);
- }
- if (targetCreationPages.contains(page)) {
- int i = targetCreationPages.indexOf(page);
- if ((i + 1) >= targetCreationPages.size()) {
- return null;
- }
- return (IWizardPage) targetCreationPages.get(i + 1);
- }
- if (sourceCreationPages.contains(page)) {
- if (sourceCreationPages.get(sourceCreationPages.size() - 1) == page) {
- return (IWizardPage) targetCreationPages.get(0);
- }
- }
- return null;
- }
-
- @Override
- public IWizardPage getNextPage(IWizardPage page) {
- IWizardPage p = getSourceCreationPage(page);
- if (p != null)
- return p;
- p = getTargetCreationPage(page);
- if (p != null)
- return p;
- return super.getNextPage(page);
- }
-
- public void clearTargetWizardPages() {
- // for (Iterator iterator = sourceCreationPages.iterator();
- // iterator.hasNext();) {
- // IWizardPage page = (IWizardPage) iterator.next();
- // if(page != null){
- // page.dispose();
- // }
- // }
- targetCreationPages.clear();
- }
-
- public void removeSourceWIzardPage(IWizardPage page) {
- sourceCreationPages.remove(page);
- }
-
- public void removeTargetWIzardPage(IWizardPage page) {
- targetCreationPages.remove(page);
- }
+package org.jboss.tools.smooks.ui.wizards;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.IWizard;
+import org.eclipse.jface.wizard.IWizardPage;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.ui.INewWizard;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.ide.IDE;
+import org.jboss.tools.common.model.ui.ModelUIImages;
+import org.jboss.tools.smooks.graphical.util.GraphicalInformationSaver;
+import org.jboss.tools.smooks.ui.IStructuredDataCreationWizard;
+import org.jboss.tools.smooks.ui.editors.SmooksFileEditorInput;
+import org.jboss.tools.smooks.ui.editors.SmooksFormEditor;
+import org.jboss.tools.smooks.ui.editors.TypeIDSelectionWizardPage;
+
+/**
+ * This is a sample new wizard. Its role is to create a new file resource in the
+ * provided container. If the container resource (a folder or a project) is
+ * selected in the workspace when the wizard is opened, it will accept it as the
+ * target container. The wizard creates one file with the extension "smooks".
If
+ * a sample multi-page editor (also available as a template) is registered for
+ * the same extension, it will be able to open it.
+ */
+
+public class SmooksConfigFileNewWizard extends Wizard implements INewWizard,
+ ISmooksDataCreationAddtionWizard {
+ private SmooksConfigFileNewWizardPage page;
+ private TypeIDSelectionWizardPage typeIDPage;
+
+ private List<IWizardPage> sourceCreationPages = new
ArrayList<IWizardPage>();
+
+ private List<IWizardPage> targetCreationPages = new
ArrayList<IWizardPage>();
+
+ private IStructuredSelection selection;
+
+ private IWorkbench workbench;
+
+ /**
+ * Constructor for SmooksConfigFileNewWizard.
+ */
+ public SmooksConfigFileNewWizard() {
+ super();
+ setNeedsProgressMonitor(true);
+ super.setWindowTitle("New Smooks Configuration File");
+ setDefaultPageImageDescriptor(ModelUIImages.getImageDescriptor(ModelUIImages.WIZARD_NEW_PROJECT));
+ }
+
+ /**
+ * Adding the page to the wizard.
+ */
+ public void addPages() {
+ page = new SmooksConfigFileNewWizardPage("newSmooksFile1",
+ getSelection());
+ addPage(page);
+ // TODO don't use the WizardSelectionPage
+ typeIDPage = new TypeIDSelectionWizardPage("", false);
+ typeIDPage.setSelection(selection);
+ addPage(typeIDPage);
+ }
+
+ /**
+ * This method is called when 'Finish' button is pressed in the wizard. We
+ * will create an operation and run it using wizard as execution context.
+ */
+ public boolean performFinish() {
+ // final String containerName = page.getContainerName();
+ // final String fileName = page.getFileName();
+ final IFile file = page.createNewFile();
+ IRunnableWithProgress op = new IRunnableWithProgress() {
+ public void run(IProgressMonitor monitor)
+ throws InvocationTargetException {
+ try {
+ doFinish(file, monitor);
+ } catch (CoreException e) {
+ throw new InvocationTargetException(e);
+ } finally {
+ monitor.done();
+ }
+ }
+ };
+ try {
+ getContainer().run(true, false, op);
+ } catch (InterruptedException e) {
+ return false;
+ } catch (InvocationTargetException e) {
+ Throwable realException = e.getTargetException();
+ MessageDialog.openError(getShell(), "Error", realException
+ .getMessage());
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * The worker method. It will find the container, create the file if missing
+ * or just replace its contents, and open the editor on the newly created
+ * file.
+ */
+
+ private void doFinish(final IFile file, IProgressMonitor monitor)
+ throws CoreException {
+ // create a sample file
+ String sourceTypeID = typeIDPage.getSourceID();
+ String targetTypeID = typeIDPage.getTargetID();
+
+ try {
+ InputStream stream = openContentStream();
+ if (file.exists()) {
+ file.setContents(stream, true, true, monitor);
+ } else {
+ file.create(stream, true, monitor);
+ }
+ stream.close();
+ GraphicalInformationSaver ginforSave = new GraphicalInformationSaver(
+ file);
+ ginforSave.doSave(monitor, sourceTypeID, targetTypeID);
+ } catch (IOException e) {
+ }
+ monitor.worked(1);
+ monitor.setTaskName("Opening file for editing...");
+ getShell().getDisplay().asyncExec(new Runnable() {
+ public void run() {
+ IWorkbenchPage page = PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow().getActivePage();
+ try {
+ SmooksFileEditorInput input = new SmooksFileEditorInput(
+ file);
+ IWizard sourceWizard = typeIDPage
+ .getSourceDataCreationWizard();
+ IWizard targetWizard = typeIDPage
+ .getTargetDataCreationWizard();
+ if (sourceWizard != null) {
+ sourceWizard.performFinish();
+ }
+ if (targetWizard != null) {
+ targetWizard.performFinish();
+ }
+ if (sourceWizard instanceof IStructuredDataCreationWizard) {
+ Object sourceObj = ((IStructuredDataCreationWizard) sourceWizard)
+ .getTreeViewerInputContents();
+// if (sourceObj instanceof List) {
+// if (!((List) sourceObj).isEmpty()) {
+// sourceObj = ((List) sourceObj).get(0);
+// }
+// }
+ input.setSourceTreeViewerInputContents(sourceObj);
+ }
+
+ if (targetWizard instanceof IStructuredDataCreationWizard) {
+ Object targetObj = ((IStructuredDataCreationWizard) targetWizard)
+ .getTreeViewerInputContents();
+// if (targetObj instanceof List) {
+// if (!((List) targetObj).isEmpty()) {
+// targetObj = ((List) targetObj).get(0);
+// }
+// }
+ input.setTargetTreeViewerInputContents(targetObj);
+
+ }
+
+ IDE.openEditor(page, input, SmooksFormEditor.EDITOR_ID,
+ true);// openEditor(page, file, true);
+ } catch (PartInitException e) {
+ }
+ }
+ });
+ monitor.worked(1);
+ }
+
+ /**
+ * We will initialize file contents with a sample text.
+ */
+
+ private InputStream openContentStream() {
+ String contents = "<?xml version=\"1.0\"
encoding=\"UTF-8\"?>\n"
+ + " <smooks-resource-list
xmlns=\"http://www.milyn.org/xsd/smooks-1.0.xsd\"/>";
+ return new ByteArrayInputStream(contents.getBytes());
+ }
+
+ private void throwCoreException(String message) throws CoreException {
+ IStatus status = new Status(IStatus.ERROR, "org.jboss.tools.smooks.ui",
+ IStatus.OK, message, null);
+ throw new CoreException(status);
+ }
+
+ public void init(IWorkbench workbench, IStructuredSelection selection) {
+ this.workbench = workbench;
+ this.selection = selection;
+ }
+
+ public IStructuredSelection getSelection() {
+ return selection;
+ }
+
+ public void setSelection(IStructuredSelection selection) {
+ this.selection = selection;
+ }
+
+ public void addSourceWizardPage(IWizardPage page) {
+ sourceCreationPages.add(page);
+ page.setTitle("Source Data Selection");
+ }
+
+ public void addTargetWizardPage(IWizardPage page) {
+ targetCreationPages.add(page);
+ page.setTitle("Target Data Selection");
+ }
+
+ public void clearSourceWizardPages() {
+ // for (Iterator iterator = sourceCreationPages.iterator();
+ // iterator.hasNext();) {
+ // IWizardPage page = (IWizardPage) iterator.next();
+ // if(page != null){
+ // page.dispose();
+ // }
+ // }
+ sourceCreationPages.clear();
+ }
+
+ private IWizardPage getSourceCreationPage(IWizardPage page) {
+ if (page == typeIDPage) {
+ if (sourceCreationPages.isEmpty())
+ return null;
+ return (IWizardPage) sourceCreationPages.get(0);
+ }
+ if (sourceCreationPages.contains(page)) {
+ int i = sourceCreationPages.indexOf(page);
+ if ((i + 1) >= sourceCreationPages.size()) {
+ return null;
+ }
+ return (IWizardPage) sourceCreationPages.get(i + 1);
+ }
+ return null;
+ }
+
+ private IWizardPage getTargetCreationPage(IWizardPage page) {
+ if (page == typeIDPage) {
+ if (targetCreationPages.isEmpty())
+ return null;
+ return (IWizardPage) targetCreationPages.get(0);
+ }
+ if (targetCreationPages.contains(page)) {
+ int i = targetCreationPages.indexOf(page);
+ if ((i + 1) >= targetCreationPages.size()) {
+ return null;
+ }
+ return (IWizardPage) targetCreationPages.get(i + 1);
+ }
+ if (sourceCreationPages.contains(page)) {
+ if (sourceCreationPages.get(sourceCreationPages.size() - 1) == page) {
+ return (IWizardPage) targetCreationPages.get(0);
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public IWizardPage getNextPage(IWizardPage page) {
+ IWizardPage p = getSourceCreationPage(page);
+ if (p != null)
+ return p;
+ p = getTargetCreationPage(page);
+ if (p != null)
+ return p;
+ return super.getNextPage(page);
+ }
+
+ public void clearTargetWizardPages() {
+ // for (Iterator iterator = sourceCreationPages.iterator();
+ // iterator.hasNext();) {
+ // IWizardPage page = (IWizardPage) iterator.next();
+ // if(page != null){
+ // page.dispose();
+ // }
+ // }
+ targetCreationPages.clear();
+ }
+
+ public void removeSourceWIzardPage(IWizardPage page) {
+ sourceCreationPages.remove(page);
+ }
+
+ public void removeTargetWIzardPage(IWizardPage page) {
+ targetCreationPages.remove(page);
+ }
}
\ No newline at end of file
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/wizards/SmooksConfigFileNewWizardPage.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/wizards/SmooksConfigFileNewWizardPage.java 2008-10-21
09:18:30 UTC (rev 11034)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/wizards/SmooksConfigFileNewWizardPage.java 2008-10-21
09:20:19 UTC (rev 11035)
@@ -1,37 +1,40 @@
-package org.jboss.tools.smooks.ui.wizards;
-
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
-
-/**
- *
- * @author dart
- *
- */
-public class SmooksConfigFileNewWizardPage extends WizardNewFileCreationPage {
- public SmooksConfigFileNewWizardPage(String pageName,
- IStructuredSelection selection) {
- super(pageName, selection);
- setFileExtension("smooks");
- }
-
- @Override
- protected boolean validatePage() {
- boolean flag = super.validatePage();
- String name = this.getFileName();
- if (name.indexOf(".") == -1)
- return flag;
- String extensionName = name.substring(name.indexOf(".") + 1, name
- .length());
- String error = null;
- if (extensionName.equalsIgnoreCase(this.getFileExtension())) {
-
- } else {
- error = "file extension must be \"smooks\"";
- }
- if (error != null) {
- this.setErrorMessage(error);
- }
- return (error == null);
- }
+package org.jboss.tools.smooks.ui.wizards;
+
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
+
+/**
+ *
+ * @author dart
+ *
+ */
+public class SmooksConfigFileNewWizardPage extends WizardNewFileCreationPage {
+ public SmooksConfigFileNewWizardPage(String pageName,
+ IStructuredSelection selection) {
+ super(pageName, selection);
+ setFileExtension("smooks");
+ super.setTitle("Smooks Configuration");
+ super.setDescription("Create a new Smooks configuration file");
+ this.setFileName("newConfig.smooks");
+ }
+
+ @Override
+ protected boolean validatePage() {
+ boolean flag = super.validatePage();
+ String name = this.getFileName();
+ if (name.indexOf(".") == -1)
+ return flag;
+ String extensionName = name.substring(name.indexOf(".") + 1, name
+ .length());
+ String error = null;
+ if (extensionName.equalsIgnoreCase(this.getFileExtension())) {
+
+ } else {
+ error = "file extension must be \"smooks\"";
+ }
+ if (error != null) {
+ this.setErrorMessage(error);
+ }
+ return (error == null);
+ }
}
\ No newline at end of file