Author: DartPeng
Date: 2009-01-07 04:19:28 -0500 (Wed, 07 Jan 2009)
New Revision: 12915
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/analyzer/SmooksFileBuilder.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/editors/SmooksFormEditor.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/editors/SmooksGraphicalFormPage.java
Log:
JBIDE-3429
change the graphical model and source page text when the page was changed
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/analyzer/SmooksFileBuilder.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/analyzer/SmooksFileBuilder.java 2009-01-07
07:38:16 UTC (rev 12914)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/analyzer/SmooksFileBuilder.java 2009-01-07
09:19:28 UTC (rev 12915)
@@ -12,6 +12,7 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.emf.common.command.BasicCommandStack;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.command.CommandStack;
@@ -54,6 +55,9 @@
SmooksConfigurationFileGenerateContext context,
IProgressMonitor monitor) throws SmooksAnalyzerException,
IOException, CoreException {
+ if(monitor == null){
+ monitor = new NullProgressMonitor();
+ }
AnalyzerFactory factory = AnalyzerFactory.getInstance();
IMappingAnalyzer analyzer = factory.getMappingAnalyzer(context
.getSourceDataTypeID(), context.getTargetDataTypeID());
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/editors/SmooksFormEditor.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/editors/SmooksFormEditor.java 2009-01-07
07:38:16 UTC (rev 12914)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/editors/SmooksFormEditor.java 2009-01-07
09:19:28 UTC (rev 12915)
@@ -10,11 +10,19 @@
******************************************************************************/
package org.jboss.tools.smooks.ui.editors;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
+import org.dom4j.Document;
+import org.dom4j.Element;
+import org.dom4j.io.OutputFormat;
+import org.dom4j.io.SAXReader;
+import org.dom4j.io.XMLWriter;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.common.command.BasicCommandStack;
@@ -38,7 +46,6 @@
import org.jboss.tools.smooks.analyzer.NormalSmooksModelBuilder;
import org.jboss.tools.smooks.analyzer.NormalSmooksModelPackage;
import org.jboss.tools.smooks.model.DocumentRoot;
-import org.jboss.tools.smooks.model.ResourceType;
import org.jboss.tools.smooks.model.SmooksFactory;
import org.jboss.tools.smooks.model.SmooksResourceListType;
import org.jboss.tools.smooks.model.provider.SmooksItemProviderAdapterFactory;
@@ -53,7 +60,7 @@
* @Date Jul 28, 2008
*/
public class SmooksFormEditor extends FormEditor implements
- ITabbedPropertySheetPageContributor , IAnalyzeListener{
+ ITabbedPropertySheetPageContributor, IAnalyzeListener {
private SmooksTextEdtor xmlTextEditor;
@@ -324,9 +331,61 @@
}
public void endAnalyze(AnalyzeResult result) {
- if(result.getError() != null){
+ if (result.getError() != null) {
this.setActivePage(2);
}
}
+ private boolean prettyXMLOutput = true;
+
+ @Override
+ protected void pageChange(int newPageIndex) {
+ int oldPageIndex = this.getCurrentPage();
+ if (oldPageIndex == -1 || oldPageIndex == newPageIndex) {
+ super.pageChange(newPageIndex);
+ return;
+ }
+
+ if(!isDirty()){
+ super.pageChange(newPageIndex);
+ return;
+ }
+
+ ByteArrayOutputStream tempStream = null;
+ XMLWriter writer = null;
+ try {
+ if (oldPageIndex == 0 && newPageIndex == 2) {
+ InputStream stream = graphicalPage.generateSmooksContents(null);
+ SAXReader reader = new SAXReader();
+ Document rootElement = reader.read(stream);
+ if (prettyXMLOutput) {
+ tempStream = new ByteArrayOutputStream();
+ OutputFormat format = OutputFormat.createPrettyPrint();
+ writer = new XMLWriter(tempStream, format);
+ writer.write(rootElement);
+ }
+ String text = null;
+ if (prettyXMLOutput) {
+ text = new String(tempStream.toByteArray());
+ } else {
+ text = rootElement.asXML();
+ }
+ xmlTextEditor.getTextViewer().getDocument().set(text);
+ }
+ if (newPageIndex == 0 && oldPageIndex == 2) {
+ String contents = xmlTextEditor.getTextViewer().getDocument().get();
+ graphicalPage.refreshAllGUI(new ByteArrayInputStream(contents.getBytes()));
+ }
+ } catch (Exception e) {
+
+ }finally{
+ try{
+ if(writer != null) writer.close();
+ if(tempStream != null) tempStream.close();
+ }catch(Exception e){
+
+ }
+ }
+ super.pageChange(newPageIndex);
+ }
}
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/editors/SmooksGraphicalFormPage.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/editors/SmooksGraphicalFormPage.java 2009-01-07
07:38:16 UTC (rev 12914)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/editors/SmooksGraphicalFormPage.java 2009-01-07
09:19:28 UTC (rev 12915)
@@ -128,6 +128,7 @@
import org.jboss.tools.smooks.model.SmooksFactory;
import org.jboss.tools.smooks.model.SmooksResourceListType;
import org.jboss.tools.smooks.model.util.SmooksModelConstants;
+import org.jboss.tools.smooks.model.util.SmooksResourceFactoryImpl;
import org.jboss.tools.smooks.ui.AnalyzeResult;
import org.jboss.tools.smooks.ui.IAnalyzeListener;
import org.jboss.tools.smooks.ui.IStructuredDataCreationWizard;
@@ -557,6 +558,38 @@
problemSection.setLayoutData(gd);
problemSection.setVisible(false);
}
+
+ public void refreshAllGUI(InputStream stream){
+ sourceTreeViewerInputModel = null;
+ targetTreeViewerInputModel = null;
+ Throwable throwable = null;
+ try {
+ analyzeGraphicalModel(stream);
+ } catch (Throwable e) {
+ throwable = e;
+ }
+ if (throwable == null) {
+ this.disableMappingGUI = false;
+ if (mappingGUISection != null)
+ mappingGUISection.setEnabled(true);
+ if (initSourceTreeViewerProviders()) {
+ initSourceTreeViewer();
+ expandSourceConnectionModel();
+ }
+ if (initTargetTreeViewerProviders()) {
+ initTargetTreeViewer();
+ expandTargetConnectionModel();
+ }
+ this.redrawMappingPanel();
+ notifyAnalyzeListeners(null);
+ } else {
+ cleanMappingPanel();
+ this.disableMappingGUI = true;
+ if (mappingGUISection != null)
+ mappingGUISection.setEnabled(false);
+ this.notifyAnalyzeListeners(throwable);
+ }
+ }
public void refreshAllGUI() {
sourceTreeViewerInputModel = null;
@@ -697,7 +730,7 @@
if (needAdd)
this.rootModel.addChild(model);
}
- }else{
+ } else {
((TreeItemRelationModel) model).setTreeItem(item);
}
}
@@ -808,13 +841,13 @@
}
}
}
-
- private void deAssosiateGraphAndTransformModel(Object graphModel){
- if(graph_trasform_data_map.containsValue(graphModel)){
+
+ private void deAssosiateGraphAndTransformModel(Object graphModel) {
+ if (graph_trasform_data_map.containsValue(graphModel)) {
Iterator it = graph_trasform_data_map.keySet().iterator();
- while(it.hasNext()){
+ while (it.hasNext()) {
Object key = it.next();
- if(graphModel == graph_trasform_data_map.get(key)){
+ if (graphModel == graph_trasform_data_map.get(key)) {
graph_trasform_data_map.put(key, null);
graph_trasform_data_map.remove(key);
break;
@@ -867,9 +900,20 @@
*/
@Override
public boolean isDirty() {
- return commandStackChanged || super.isDirty();
+ return commandStackChanged;
}
+ public InputStream generateSmooksContents(IProgressMonitor monitor)
+ throws SmooksAnalyzerException, IOException, CoreException {
+ SmooksFileBuilder builder = this.getSmooksFileBuilder();
+ builder.setSmooksResource(this.smooksResource);
+ SmooksConfigurationFileGenerateContext context = this
+ .getSmooksConfigurationFileGenerateContext();
+ Exception exp = null;
+ this.cleanMappingResourceConfig();
+ return builder.generateSmooksFile(context, monitor);
+ }
+
/*
* (non-Javadoc)
*
@@ -892,16 +936,10 @@
if (cleanError)
return;
}
- SmooksFileBuilder builder = this.getSmooksFileBuilder();
- builder.setSmooksResource(this.smooksResource);
- SmooksConfigurationFileGenerateContext context = this
- .getSmooksConfigurationFileGenerateContext();
- this.initSmooksConfigurationFileGenerateContext(context);
Exception exp = null;
try {
// generate smooks configuration file
- this.cleanMappingResourceConfig();
- InputStream stream = builder.generateSmooksFile(context, monitor);
+ InputStream stream = generateSmooksContents(monitor);
IFile file = ((IFileEditorInput) this.getEditorInput()).getFile();
if (file.exists()) {
file.setContents(stream, IResource.FORCE, monitor);
@@ -909,7 +947,8 @@
// save graphical informations
if (this.graphicalInformationSaver != null) {
- graphicalInformationSaver.doSave(monitor, context);
+ graphicalInformationSaver.doSave(monitor,
+ getSmooksConfigurationFileGenerateContext());
}
} catch (CoreException e) {
exp = e;
@@ -1174,6 +1213,7 @@
// ignore
}
IFile file = ((IFileEditorInput) input).getFile();
+ // if the type id is null, open a dialog to select
if (sourceDataTypeID == null || targetDataTypeID == null) {
TypeIDSelectionWizard wizard = new TypeIDSelectionWizard();
wizard.setSourceDataTypeID(sourceDataTypeID);
@@ -1205,6 +1245,19 @@
}
}
+ public void analyzeGraphicalModel(InputStream stream) throws IOException, CoreException,
InvocationTargetException {
+ Resource resource = new SmooksResourceFactoryImpl()
+ .createResource(null);
+ resource.load(stream, Collections.EMPTY_MAP);
+ SmooksResourceListType listType = ((DocumentRoot) resource
+ .getContents().get(0)).getSmooksResourceList();
+ GraphInformations graph = null;
+ if (graphicalInformationSaver != null)
+ graph = graphicalInformationSaver.doLoad();
+ this.analyzeGraphicalModel(listType, graph,
+ ((IFileEditorInput) getEditorInput()).getFile());
+ }
+
private boolean requiredSelectDataSource(String typeID) {
for (int i = 0; i < this.REQUIRED_SOURCE_SELECT_TYPE.length; i++) {
String s = REQUIRED_SOURCE_SELECT_TYPE[i];
@@ -1552,10 +1605,11 @@
modelClass = SourceModel.class;
}
createGraphModels(tree.getItems(), modelClass);
-// if (tree.getData(TreeItemRelationModel.PRO_TREE_REPAINT) != null) {
-// // System.out.println("Block a event fire !!");
-// return;
-// }
+ // if (tree.getData(TreeItemRelationModel.PRO_TREE_REPAINT) != null)
+ // {
+ // // System.out.println("Block a event fire !!");
+ // return;
+ // }
rootModel.firePropertyChange(
AbstractStructuredDataModel.P_REFRESH_PANEL, null,
new Object());
@@ -1614,8 +1668,8 @@
public SmooksConfigurationFileGenerateContext
getSmooksConfigurationFileGenerateContext() {
if (smooksConfigurationFileGenerateContext == null) {
smooksConfigurationFileGenerateContext = createContext();
- initSmooksConfigurationFileGenerateContext(smooksConfigurationFileGenerateContext);
}
+ initSmooksConfigurationFileGenerateContext(smooksConfigurationFileGenerateContext);
return smooksConfigurationFileGenerateContext;
}