Author: DartPeng
Date: 2008-09-02 02:58:19 -0400 (Tue, 02 Sep 2008)
New Revision: 10012
Modified:
workspace/dart/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/editors/SmooksGraphicalFormPage.java
Log:
change more :
1.when tree viewer is repain , recalculate the model for graphicalviewer
2.pack UI when show tree viewer contents
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-09-02
06:57:04 UTC (rev 10011)
+++
workspace/dart/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/editors/SmooksGraphicalFormPage.java 2008-09-02
06:58:19 UTC (rev 10012)
@@ -13,8 +13,10 @@
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.EventObject;
+import java.util.List;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
@@ -58,6 +60,8 @@
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
+import org.eclipse.swt.events.TreeEvent;
+import org.eclipse.swt.events.TreeListener;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
@@ -115,6 +119,7 @@
*/
public class SmooksGraphicalFormPage extends FormPage implements
ISelectionChangedListener {
+ private static final String REFERENCE_MODEL = "__reference_model";
protected SmooksConfigurationFileGenerateContext
smooksConfigurationFileGenerateContext;
protected IViewerInitor sourceViewerInitor;
protected IViewerInitor targetViewerInitor;
@@ -131,6 +136,8 @@
protected SmooksFileBuilder smooksFileBuilder = null;
protected GraphicalInformationSaver graphicalInformationSaver = null;
+ protected Object sourceTreeViewerInputModel = null;
+ protected Object targetTreeViewerInputModel = null;
protected boolean commandStackChanged = false;
protected ActionRegistry actionRegistry;
@@ -205,10 +212,6 @@
new TreePaintControlListener());
sourceViewer.getTree().addListener(SWT.PaintItem,
new TreeItemPaintListener());
-
- if (initSourceTreeViewerProviders()) {
- initSourceTreeViewer();
- }
composite1.setLayoutData(gd);
composite1.setBackground(GraphicsConstants.groupBorderColor);
}
@@ -249,11 +252,6 @@
new TreePaintControlListener());
targetViewer.getTree().addListener(SWT.PaintItem,
new TreeItemPaintListener());
-
- if (initTargetTreeViewerProviders()) {
- initTargetTreeViewer();
- }
- targetViewer.expandAll();
composite3.setBackground(GraphicsConstants.groupBorderColor);
}
@@ -305,9 +303,17 @@
section1.setLayoutData(sgd1);
toolkit.paintBordersFor(rootMainControl);
+
+ form.pack();
+
this.hookGraphicalViewer();
this.initGraphicalViewer();
-
+ if (initSourceTreeViewerProviders()) {
+ initSourceTreeViewer();
+ }
+ if (initTargetTreeViewerProviders()) {
+ initTargetTreeViewer();
+ }
getSite().getSelectionProvider().addSelectionChangedListener(this);
}
@@ -316,7 +322,11 @@
}
protected void initTargetTreeViewer() {
- targetViewer.expandAll();
+ if (this.targetTreeViewerInputModel != null) {
+ List list = new ArrayList();
+ list.add(targetTreeViewerInputModel);
+ targetViewer.setInput(list);
+ }
}
protected boolean initTargetTreeViewerProviders() {
@@ -334,7 +344,11 @@
}
protected void initSourceTreeViewer() {
- sourceViewer.expandAll();
+ if (this.sourceTreeViewerInputModel != null) {
+ List list = new ArrayList();
+ list.add(sourceTreeViewerInputModel);
+ sourceViewer.setInput(list);
+ }
}
protected boolean initSourceTreeViewerProviders() {
@@ -351,22 +365,27 @@
Class<? extends Object> modelClass) {
for (int i = 0; i < items.length; i++) {
TreeItem item = (TreeItem) items[i];
- AbstractStructuredDataModel model = null;
- if (modelClass == SourceModel.class) {
- model = new SourceModel();
+ if (item.getData(REFERENCE_MODEL) != null) {
+
+ } else {
+ AbstractStructuredDataModel model = null;
+ if (modelClass == SourceModel.class) {
+ model = new SourceModel();
+ }
+ if (modelClass == TargetModel.class) {
+ model = new TargetModel();
+ }
+ if (model != null && model instanceof TreeItemRelationModel) {
+ model.setReferenceEntityModel(item.getData());
+ ((TreeItemRelationModel) model).setTreeItem(item);
+ item.setData(REFERENCE_MODEL, model);
+ this.rootModel.addChild(model);
+ }
}
- if (modelClass == TargetModel.class) {
- model = new TargetModel();
+ if (item.getExpanded() && item.getItemCount() > 0) {
+ createGraphModels(item.getItems(), modelClass);
+ } else {
}
- if (model != null && model instanceof TreeItemRelationModel) {
- model.setReferenceEntityModel(item.getData());
- ((TreeItemRelationModel) model).setTreeItem(item);
- this.rootModel.addChild(model);
- if (item.getExpanded() && item.getItemCount() > 0) {
- createGraphModels(item.getItems(), modelClass);
- } else {
- }
- }
}
}
@@ -602,12 +621,14 @@
Resource resource = new SmooksResourceFactoryImpl()
.createResource(URI.createFileURI(path));
resource.load(Collections.EMPTY_MAP);
- IAnalyzer sourceModelAnalyzer =
AnalyzerFactory.getInstance().getSmooksModelAnalyzer(sourceDataTypeID);
+ IAnalyzer sourceModelAnalyzer = AnalyzerFactory.getInstance()
+ .getSmooksModelAnalyzer(sourceDataTypeID);
SmooksResourceListType listType = ((DocumentRoot) resource
.getContents().get(0)).getSmooksResourceList();
- Object obj = sourceModelAnalyzer.buildSourceInputObjects(graph, listType,
- ((IFileEditorInput) input).getFile());
+ sourceTreeViewerInputModel = sourceModelAnalyzer
+ .buildSourceInputObjects(graph, listType,
+ ((IFileEditorInput) input).getFile());
} catch (IOException e) {
e.printStackTrace();
} catch (CoreException e) {
@@ -645,7 +666,7 @@
// the viewer must be expanded , then the graphics model can
// calculate the location correctly
try {
- viewer.expandAll();
+ // viewer.expandAll();
if (viewer == this.sourceViewer) {
this.createSourceGraphModels();
sourceDataTypeID = typeID;
@@ -786,6 +807,11 @@
*/
public void paintControl(PaintEvent e) {
Tree tree = (Tree) e.getSource();
+ Class modelClass = TargetModel.class;
+ if (tree == sourceViewer.getTree()) {
+ modelClass = SourceModel.class;
+ }
+ createGraphModels(new TreeItem[] { tree.getTopItem() }, modelClass);
if (tree.getData(TreeItemRelationModel.PRO_TREE_REPAINT) != null) {
// System.out.println("Block a event fire !!");
return;
@@ -816,4 +842,22 @@
return smooksConfigurationFileGenerateContext;
}
+ private class StructuredDataTreeListener implements TreeListener {
+
+ public void treeCollapsed(TreeEvent e) {
+
+ }
+
+ public void treeExpanded(TreeEvent e) {
+ // Tree tree = (Tree) e.getSource();
+ // Class modelClass = TargetModel.class;
+ // if (tree == sourceViewer.getTree()) {
+ // modelClass = SourceModel.class;
+ // }
+ // createGraphModels(new TreeItem[] { tree.getTopItem() },
+ // modelClass);
+ }
+
+ }
+
}
Show replies by date