Author: DartPeng
Date: 2008-08-28 05:23:55 -0400 (Thu, 28 Aug 2008)
New Revision: 9933
Modified:
workspace/dart/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/editors/SmooksGraphicalFormPage.java
Log:
add a function to generate new graphical information file , and parse it
Modified:
workspace/dart/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/editors/SmooksGraphicalFormPage.java
===================================================================
---
workspace/dart/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/editors/SmooksGraphicalFormPage.java 2008-08-28
02:32:39 UTC (rev 9932)
+++
workspace/dart/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/editors/SmooksGraphicalFormPage.java 2008-08-28
09:23:55 UTC (rev 9933)
@@ -12,14 +12,18 @@
import java.io.IOException;
import java.io.InputStream;
+import java.lang.reflect.InvocationTargetException;
+import java.util.Collections;
import java.util.EventObject;
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.core.runtime.IProgressMonitor;
-import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.ConnectionLayer;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.gef.DefaultEditDomain;
import org.eclipse.gef.GraphicalViewer;
import org.eclipse.gef.KeyStroke;
@@ -75,8 +79,12 @@
import org.eclipse.ui.forms.widgets.Hyperlink;
import org.eclipse.ui.forms.widgets.ScrolledForm;
import org.eclipse.ui.forms.widgets.Section;
+import org.jboss.tools.smooks.analyzer.AnalyzerFactory;
+import org.jboss.tools.smooks.analyzer.IAnalyzer;
import org.jboss.tools.smooks.analyzer.SmooksAnalyzerException;
import org.jboss.tools.smooks.analyzer.SmooksFileBuilder;
+import org.jboss.tools.smooks.graphical.GraphInformations;
+import org.jboss.tools.smooks.graphical.MappingDataType;
import org.jboss.tools.smooks.graphical.util.GraphicalInformationSaver;
import org.jboss.tools.smooks.ui.IStrucutredDataCreationWizard;
import org.jboss.tools.smooks.ui.IViewerInitor;
@@ -94,7 +102,9 @@
import org.jboss.tools.smooks.ui.modelparser.SmooksConfigurationFileGenerateContext;
import org.jboss.tools.smooks.ui.wizards.TransformDataSelectionWizard;
import org.jboss.tools.smooks.utils.UIUtils;
+import org.milyn.xsd.smooks.SmooksResourceListType;
import org.milyn.xsd.smooks.util.SmooksConstants;
+import org.milyn.xsd.smooks.util.SmooksResourceFactoryImpl;
/**
* @author Dart Peng
@@ -102,6 +112,7 @@
*/
public class SmooksGraphicalFormPage extends FormPage implements
ISelectionChangedListener {
+ protected SmooksConfigurationFileGenerateContext
smooksConfigurationFileGenerateContext;
protected IViewerInitor sourceViewerInitor;
protected IViewerInitor targetViewerInitor;
protected TreeViewer targetViewer;
@@ -112,7 +123,6 @@
protected GraphRootModel rootModel;
protected Hyperlink sourceLink = null;
protected Hyperlink targetLink = null;
- protected int itemY = 0;
protected String sourceDataTypeID = null;
protected String targetDataTypeID = null;
protected SmooksFileBuilder smooksFileBuilder = null;
@@ -364,14 +374,12 @@
protected void createSourceGraphModels() {
Tree tree = sourceViewer.getTree();
TreeItem[] items = tree.getItems();
- itemY = 0;
createGraphModels(items, SourceModel.class);
}
protected void createTargetGraphModels() {
Tree tree = targetViewer.getTree();
TreeItem[] items = tree.getItems();
- itemY = 0;
createGraphModels(items, TargetModel.class);
}
@@ -418,7 +426,9 @@
@Override
public void doSave(IProgressMonitor monitor) {
SmooksFileBuilder builder = this.getSmooksFileBuilder();
- SmooksConfigurationFileGenerateContext context = createContext();
+ SmooksConfigurationFileGenerateContext context = this
+ .getSmooksConfigurationFileGenerateContext();
+ this.initSmooksConfigurationFileGenerateContext(context);
Exception exp = null;
try {
// generate smooks configuration file
@@ -429,7 +439,7 @@
}
// save graphical informations
- if(this.graphicalInformationSaver != null){
+ if (this.graphicalInformationSaver != null) {
graphicalInformationSaver.doSave(monitor, context);
}
} catch (CoreException e) {
@@ -450,15 +460,14 @@
protected SmooksConfigurationFileGenerateContext createContext() {
SmooksConfigurationFileGenerateContext context = new
SmooksConfigurationFileGenerateContext();
- context.setSourceDataTypeID(this.sourceDataTypeID);
- context.setTargetDataTypeID(this.targetDataTypeID);
- context.setSmooksType(SmooksConstants.SAX);
- context.setDataMappingRootModel(this.rootModel);
return context;
}
protected void initSmooksConfigurationFileGenerateContext(
SmooksConfigurationFileGenerateContext context) {
+ context.setSourceDataTypeID(this.sourceDataTypeID);
+ context.setTargetDataTypeID(this.targetDataTypeID);
+ context.setSmooksType(SmooksConstants.SAX);
context.setDataMappingRootModel(this.rootModel);
}
@@ -487,10 +496,6 @@
protected void initGraphicalViewer() {
createActions();
-
- this.getGraphicalViewer().getControl().setBackground(
- ColorConstants.white);
-
rootModel = new GraphRootModel();
this.createSourceGraphModels();
this.createTargetGraphModels();
@@ -581,8 +586,39 @@
public void init(IEditorSite site, IEditorInput input) {
super.init(site, input);
graphicalInformationSaver = new GraphicalInformationSaver(input);
+ try {
+ GraphInformations graph = graphicalInformationSaver.doLoad();
+ initFormEditorWithGraphInfo(graph);
+
+ String path = ResourcesPlugin.getWorkspace().getRoot().getLocation().append(
+ ((IFileEditorInput) input).getFile().getFullPath()).toString();
+ Resource resource = new SmooksResourceFactoryImpl()
+ .createResource(URI.createFileURI(path));
+ resource.load(Collections.EMPTY_MAP);
+ IAnalyzer analyzer = AnalyzerFactory.getInstance().getAnalyzer(
+ sourceDataTypeID, targetDataTypeID);
+
+
+ Object obj = analyzer.buildSourceInputObjects(graph,
+ (SmooksResourceListType) resource.getContents().get(0),
+ ((IFileEditorInput) input).getFile());
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (CoreException e) {
+ e.printStackTrace();
+ } catch (InvocationTargetException e) {
+ e.printStackTrace();
+ }
}
+ protected void initFormEditorWithGraphInfo(GraphInformations graph) {
+ MappingDataType mapping = graph.getMappingType();
+ if (mapping != null) {
+ this.sourceDataTypeID = mapping.getSourceTypeID();
+ this.targetDataTypeID = mapping.getTargetTypeID();
+ }
+ }
+
/**
*
* @param viewer
@@ -745,7 +781,7 @@
public void paintControl(PaintEvent e) {
Tree tree = (Tree) e.getSource();
if (tree.getData(TreeItemRelationModel.PRO_TREE_REPAINT) != null) {
- System.out.println("Block a event fire !!");
+ // System.out.println("Block a event fire !!");
return;
}
rootModel.firePropertyChange(RootModel.P_REFRESH_PANEL, null,
@@ -767,4 +803,11 @@
}
}
+ public SmooksConfigurationFileGenerateContext
getSmooksConfigurationFileGenerateContext() {
+ if (smooksConfigurationFileGenerateContext == null) {
+ smooksConfigurationFileGenerateContext = createContext();
+ }
+ return smooksConfigurationFileGenerateContext;
+ }
+
}
Show replies by date