Author: DartPeng
Date: 2009-10-27 01:58:58 -0400 (Tue, 27 Oct 2009)
New Revision: 18301
Added:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/ProcessAnalyzer.java
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/SelectorCreationDialog.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/edi/EDIDataParser.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/edireader12/EDIReader12UICreator.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/uitls/SmooksUIUtils.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/gef/tree/editparts/TreeNodeConnectionEditPart.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/SmooksGraphicalEditorMenuContextProvider.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/SmooksGraphicalEditorPart.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/SmooksProcessGraphicalEditor.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/TaskTypeManager.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/wizards/JavaBeanCreationWizardPage.java
Log:
JBIDE-5088
1. Auto add Input Task
2. Analyze the Smooks config file and find out which task types it related and add the
missed task type
3. Fix a nullpointexception problem.
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/SelectorCreationDialog.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/SelectorCreationDialog.java 2009-10-27
00:04:29 UTC (rev 18300)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/SelectorCreationDialog.java 2009-10-27
05:58:58 UTC (rev 18301)
@@ -11,6 +11,7 @@
package org.jboss.tools.smooks.configuration.editors;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.Iterator;
import java.util.List;
@@ -53,6 +54,7 @@
import org.jboss.tools.smooks.configuration.editors.xml.TagList;
import org.jboss.tools.smooks.configuration.editors.xml.XMLObjectAnalyzer;
import org.jboss.tools.smooks.configuration.editors.xml.XSDObjectAnalyzer;
+import org.jboss.tools.smooks.editor.ISmooksModelProvider;
import org.jboss.tools.smooks.model.graphics.ext.InputType;
import org.jboss.tools.smooks.model.graphics.ext.ParamType;
import org.jboss.tools.smooks.model.graphics.ext.SmooksGraphicsExtType;
@@ -440,7 +442,19 @@
}
protected List<Object> generateInputData() {
- Object obj = ((SmooksMultiFormEditor) editorPart).getSmooksModel();
+ Object obj = null;
+ if(editorPart instanceof ISmooksModelProvider){
+ obj = ((ISmooksModelProvider)editorPart).getSmooksModel();
+ }else{
+ ISmooksModelProvider provider = (ISmooksModelProvider)
editorPart.getAdapter(ISmooksModelProvider.class);
+ if(provider != null){
+ obj = provider.getSmooksModel();
+ }
+ }
+ if(obj == null){
+ List<Object> ll = Collections.emptyList();
+ return ll;
+ }
SmooksResourceListType resourceList = null;
if (obj instanceof DocumentRoot) {
resourceList = ((DocumentRoot) obj).getSmooksResourceList();
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/edi/EDIDataParser.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/edi/EDIDataParser.java 2009-10-27
00:04:29 UTC (rev 18300)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/edi/EDIDataParser.java 2009-10-27
05:58:58 UTC (rev 18301)
@@ -221,12 +221,14 @@
/* this codes are for the plug-in unit tests */
Bundle bundle = Platform.getBundle("org.jboss.tools.smooks.core.test");
- URL ur = bundle.getEntry("/src" + mappingModel);
- if (ur != null) {
- try {
- modelPath = ur.toURI().toString();
- } catch (URISyntaxException e) {
- e.printStackTrace();
+ if (bundle != null) {
+ URL ur = bundle.getEntry("/src" + mappingModel);
+ if (ur != null) {
+ try {
+ modelPath = ur.toURI().toString();
+ } catch (URISyntaxException e) {
+ e.printStackTrace();
+ }
}
}
}
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/edireader12/EDIReader12UICreator.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/edireader12/EDIReader12UICreator.java 2009-10-27
00:04:29 UTC (rev 18300)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/edireader12/EDIReader12UICreator.java 2009-10-27
05:58:58 UTC (rev 18301)
@@ -18,7 +18,6 @@
import org.jboss.tools.smooks.configuration.editors.AttributeFieldEditPart;
import org.jboss.tools.smooks.configuration.editors.PropertyUICreator;
import org.jboss.tools.smooks.configuration.editors.uitls.SmooksUIUtils;
-import org.jboss.tools.smooks.edimap.editor.EDIMapFormEditor;
import org.jboss.tools.smooks.editor.ISmooksModelProvider;
import org.jboss.tools.smooks.model.edi12.Edi12Package;
@@ -46,7 +45,7 @@
}
if (feature == Edi12Package.eINSTANCE.getEDI12Reader_MappingModel()) {
return SmooksUIUtils.createFileSelectionTextFieldEditor(null, parent, null, toolkit,
propertyDescriptor,
- model, SmooksUIUtils.VALUE_TYPE_VALUE, EDIMapFormEditor.EDITOR_ID, null);
+ model, SmooksUIUtils.VALUE_TYPE_VALUE, null, null);
}
return super.createPropertyUI(toolkit, parent, propertyDescriptor, model, feature,
formEditor, part);
}
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/uitls/SmooksUIUtils.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/uitls/SmooksUIUtils.java 2009-10-27
00:04:29 UTC (rev 18300)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/uitls/SmooksUIUtils.java 2009-10-27
05:58:58 UTC (rev 18301)
@@ -1004,6 +1004,7 @@
"Browse", new IFieldDialog() {
public Object open(Shell shell) {
SelectorCreationDialog dialog = new SelectorCreationDialog(shell, extType,
currentEditorPart);
+ try{
if (dialog.open() == Dialog.OK) {
Object currentSelection = dialog.getCurrentSelection();
SelectorAttributes sa = dialog.getSelectorAttributes();
@@ -1012,6 +1013,9 @@
return s;
}
}
+ }catch(Exception e){
+ e.printStackTrace();
+ }
return null;
}
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/gef/tree/editparts/TreeNodeConnectionEditPart.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/gef/tree/editparts/TreeNodeConnectionEditPart.java 2009-10-27
00:04:29 UTC (rev 18300)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/gef/tree/editparts/TreeNodeConnectionEditPart.java 2009-10-27
05:58:58 UTC (rev 18301)
@@ -3,6 +3,7 @@
*/
package org.jboss.tools.smooks.gef.tree.editparts;
+import org.eclipse.draw2d.BendpointConnectionRouter;
import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Connection;
import org.eclipse.draw2d.ConnectionAnchor;
@@ -36,8 +37,8 @@
public void changeLineAlpha(int alpha) {
this.alpha = alpha;
}
-
- protected IFigure createSourceFlagFigure(){
+
+ protected IFigure createSourceFlagFigure() {
Figure sourceFlagFigure = new Figure() {
/*
@@ -87,8 +88,8 @@
};
return sourceFlagFigure;
}
-
- protected IFigure createTargetFlagFigure(){
+
+ protected IFigure createTargetFlagFigure() {
Figure targetFlagFigure = new Figure() {
/*
* (non-Javadoc)
@@ -142,8 +143,8 @@
};
return targetFlagFigure;
}
-
- protected Connection createConnectionFigure(){
+
+ protected Connection createConnectionFigure() {
PolylineConnection connection = new PolylineConnection() {
@Override
@@ -198,7 +199,6 @@
public IFigure createFigure() {
Connection connection = createConnectionFigure();
- connection.setConnectionRouter(new ManhattanConnectionRouter());
IFigure targetFlagFigure = createTargetFlagFigure();
IFigure sourceFlagFigure = createSourceFlagFigure();
targetFlagFigure.setSize(7, 7);
@@ -207,6 +207,7 @@
connection.add(targetFlagFigure, targetLocator);
ConnectionLocator sourceLocator = new ConnectionLocator(connection,
ConnectionLocator.SOURCE);
connection.add(sourceFlagFigure, sourceLocator);
+ connection.setConnectionRouter(new BendpointConnectionRouter());
return connection;
}
}
Added:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/ProcessAnalyzer.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/ProcessAnalyzer.java
(rev 0)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/ProcessAnalyzer.java 2009-10-27
05:58:58 UTC (rev 18301)
@@ -0,0 +1,206 @@
+/*******************************************************************************
+ * 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.graphical.editors;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.jboss.tools.smooks.model.freemarker.Freemarker;
+import org.jboss.tools.smooks.model.graphics.ext.GraphFactory;
+import org.jboss.tools.smooks.model.graphics.ext.ProcessType;
+import org.jboss.tools.smooks.model.graphics.ext.ProcessesType;
+import org.jboss.tools.smooks.model.graphics.ext.SmooksGraphicsExtType;
+import org.jboss.tools.smooks.model.graphics.ext.TaskType;
+import org.jboss.tools.smooks.model.javabean.BindingsType;
+import org.jboss.tools.smooks.model.javabean12.BeanType;
+import org.jboss.tools.smooks.model.smooks.AbstractResourceConfig;
+import org.jboss.tools.smooks.model.smooks.SmooksResourceListType;
+import org.jboss.tools.smooks.model.xsl.Xsl;
+
+/**
+ * @author Dart
+ *
+ */
+public class ProcessAnalyzer {
+
+ public List<String> analyzeTaskID(SmooksResourceListType resourceList) {
+ List<String> taskIDs = new ArrayList<String>();
+ List<AbstractResourceConfig> resourceConfigList =
resourceList.getAbstractResourceConfig();
+ for (Iterator<?> iterator = resourceConfigList.iterator(); iterator.hasNext();)
{
+ AbstractResourceConfig abstractResourceConfig = (AbstractResourceConfig)
iterator.next();
+
+ // for java-mapping
+ if (abstractResourceConfig instanceof BeanType || abstractResourceConfig instanceof
BindingsType) {
+ if (taskIDs.contains(TaskTypeManager.TASK_ID_JAVA_MAPPING)) {
+ continue;
+ }
+ taskIDs.add(TaskTypeManager.TASK_ID_JAVA_MAPPING);
+ }
+ // for freemarker template
+ if (abstractResourceConfig instanceof Freemarker) {
+ if (taskIDs.contains(TaskTypeManager.TASK_ID_FREEMARKER_TEMPLATE)) {
+ continue;
+ }
+ taskIDs.add(TaskTypeManager.TASK_ID_FREEMARKER_TEMPLATE);
+ }
+ // for xsl template
+ if (abstractResourceConfig instanceof Xsl) {
+ // if (taskIDs.contains(TaskTypeManager.TASK_ID_JAVA_MAPPING)) {
+ // continue;
+ // }
+ // taskIDs.add(TaskTypeManager.TASK_ID_JAVA_MAPPING);
+ }
+ }
+ return taskIDs;
+ }
+
+ private SmooksGraphicsExtType getSmooksGraphicsType(SmooksResourceListType resouceList)
{
+ List<AbstractResourceConfig> resourceConfigList =
resouceList.getAbstractResourceConfig();
+ for (Iterator<?> iterator = resourceConfigList.iterator(); iterator.hasNext();)
{
+ AbstractResourceConfig abstractResourceConfig = (AbstractResourceConfig)
iterator.next();
+ if (abstractResourceConfig instanceof SmooksGraphicsExtType) {
+ return (SmooksGraphicsExtType) abstractResourceConfig;
+ }
+ }
+ return null;
+ }
+
+ private void fillAllTask(TaskType task, List<TaskType> taskList) {
+ taskList.add(task);
+ List<TaskType> children = task.getTask();
+ for (Iterator<?> iterator = children.iterator(); iterator.hasNext();) {
+ TaskType taskType = (TaskType) iterator.next();
+ fillAllTask(taskType, taskList);
+ }
+ }
+
+ /**
+ *
+ * @param resourceList
+ * @return If the smooks-resource-list was changed in this method return
+ * <code>true</code>
+ */
+ public boolean analyzeSmooksModels(SmooksResourceListType resourceList) {
+ boolean modelWasChanged = false;
+ SmooksGraphicsExtType ext = getSmooksGraphicsType(resourceList);
+ if (ext == null)
+ throw new RuntimeException("Can't find the smooks-graph-ext element");
+
+ ProcessesType processes = ext.getProcesses();
+ if (processes == null) {
+ processes = GraphFactory.eINSTANCE.createProcessesType();
+ ext.setProcesses(processes);
+ modelWasChanged = true;
+ }
+ ProcessType process = null;
+ if (processes != null) {
+ process = processes.getProcess();
+ }
+
+ if (process == null) {
+ process = GraphFactory.eINSTANCE.createProcessType();
+ processes.setProcess(process);
+ modelWasChanged = true;
+ }
+
+ List<TaskType> currentList = process.getTask();
+ List<TaskType> taskList = new ArrayList<TaskType>();
+ for (Iterator<?> iterator = currentList.iterator(); iterator.hasNext();) {
+ TaskType taskType = (TaskType) iterator.next();
+ this.fillAllTask(taskType, taskList);
+ }
+
+ if (taskList.isEmpty()) {
+ TaskType inputTask = GraphFactory.eINSTANCE.createTaskType();
+ inputTask.setId(TaskTypeManager.TASK_ID_INPUT);
+ inputTask.setName(TaskTypeManager.getTaskLabel(TaskTypeManager.TASK_ID_INPUT));
+ process.getTask().add(inputTask);
+ taskList.add(inputTask);
+ modelWasChanged = true;
+ }
+
+ List<String> taskIDs = analyzeTaskID(resourceList);
+
+ for (Iterator<String> iterator = taskIDs.iterator(); iterator.hasNext();) {
+ String taskId = (String) iterator.next();
+ if (!taskIDIsExist(taskId, taskList)) {
+ TaskType task = GraphFactory.eINSTANCE.createTaskType();
+ task.setId(taskId);
+ task.setName(TaskTypeManager.getTaskLabel(taskId));
+ taskList.add(task);
+ }
+ }
+ modelWasChanged = linkTask(taskList);
+ return modelWasChanged;
+ }
+
+ private TaskType getTaskType(String id, List<TaskType> taskList) {
+ for (Iterator<?> iterator = taskList.iterator(); iterator.hasNext();) {
+ TaskType taskType = (TaskType) iterator.next();
+ if (id.equals(taskType.getId())) {
+ return taskType;
+ }
+ }
+ return null;
+ }
+
+ private boolean linkTask(List<TaskType> taskList) {
+ TaskType first = getTaskType(TaskTypeManager.TASK_ID_INPUT, taskList);
+ if (first != null) {
+ return linkTask(first, taskList);
+ }
+ return false;
+ }
+
+ private boolean linkTask(TaskType taskType, List<TaskType> taskList) {
+ String id = taskType.getId();
+ String[] childrenIds = TaskTypeManager.getChildTaskIDs(id);
+ boolean changed = false;
+ if (childrenIds != null) {
+ for (int i = 0; i < childrenIds.length; i++) {
+ String childId = childrenIds[i];
+ TaskType childTask = getTaskType(childId, taskList);
+ if (childTask != null) {
+ if (!taskType.getTask().contains(childTask)
+ && ((childTask.eContainer() == null) || (childTask.eContainer() instanceof
ProcessType))) {
+ taskType.getTask().add(childTask);
+ changed = true;
+ }
+ taskList.remove(childTask);
+ boolean cchange = linkTask(childTask, taskList);
+ changed = (changed || cchange);
+ }
+ }
+ }
+ return changed;
+ }
+
+ private boolean taskIDIsExist(String taskId, List<TaskType> taskList) {
+ for (Iterator<?> iterator = taskList.iterator(); iterator.hasNext();) {
+ TaskType task = (TaskType) iterator.next();
+ if (task.getId().equals(taskId)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ // private boolean taskIsExist(TaskType task , List<String> taskIDs){
+ // for (Iterator<?> iterator = taskIDs.iterator(); iterator.hasNext();) {
+ // String id = (String) iterator.next();
+ // if(task.getId().equals(id)){
+ // return true;
+ // }
+ // }
+ // return false;
+ // }
+}
Property changes on:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/ProcessAnalyzer.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/SmooksGraphicalEditorMenuContextProvider.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/SmooksGraphicalEditorMenuContextProvider.java 2009-10-27
00:04:29 UTC (rev 18300)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/SmooksGraphicalEditorMenuContextProvider.java 2009-10-27
05:58:58 UTC (rev 18301)
@@ -14,6 +14,8 @@
import org.eclipse.gef.EditPartViewer;
import org.eclipse.gef.ui.actions.ActionRegistry;
+import org.eclipse.gef.ui.actions.GEFActionConstants;
+import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
@@ -58,6 +60,21 @@
}
}
}
+
+ Action layout = new Action(){
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.action.Action#run()
+ */
+ @Override
+ public void run() {
+ }
+
+ };
+
+ layout.setText("Auto Layout");
+
+// menu.appendToGroup(GEFActionConstants.ADD_EXT, layout);
}
}
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/SmooksGraphicalEditorPart.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/SmooksGraphicalEditorPart.java 2009-10-27
00:04:29 UTC (rev 18300)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/SmooksGraphicalEditorPart.java 2009-10-27
05:58:58 UTC (rev 18301)
@@ -13,11 +13,17 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.EventObject;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.graph.DirectedGraph;
+import org.eclipse.draw2d.graph.DirectedGraphLayout;
+import org.eclipse.draw2d.graph.Edge;
+import org.eclipse.draw2d.graph.Node;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.command.CommandWrapper;
import org.eclipse.emf.ecore.EObject;
@@ -30,6 +36,7 @@
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.gef.DefaultEditDomain;
import org.eclipse.gef.EditPart;
+import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.gef.commands.CommandStack;
import org.eclipse.gef.commands.CommandStackEvent;
import org.eclipse.gef.commands.CommandStackEventListener;
@@ -104,6 +111,10 @@
public static final int UNDO_COMMAND = 2;
+ private static final int SOURCE_CONNECT_TYPE = 1;
+
+ private static final int TARGET_CONNECT_TYPE = 0;
+
private DefaultEditDomain editDomain = null;
protected ISmooksModelProvider smooksModelProvider = null;
@@ -876,8 +887,8 @@
}
protected void applyGraphicalInformation(AbstractSmooksGraphicalModel graphicalModel) {
- GraphType graph = getSmooksGraphicsExtType().getGraph();
- applyGraphicalInformation(graph, graphicalModel);
+ GraphType graph1 = getSmooksGraphicsExtType().getGraph();
+ applyGraphicalInformation(graph1, graphicalModel);
}
protected void applyGraphicalInformation(GraphType graph, AbstractSmooksGraphicalModel
graphicalModel) {
@@ -896,6 +907,55 @@
}
protected void initModelGraphicsInformation(SmooksGraphicsExtType ext) {
+ if (false) {
+ DirectedGraph graph = new DirectedGraph();
+ EditPart rootEditorPart = this.getGraphicalViewer().getContents();
+ List<?> children = rootEditorPart.getChildren();
+ HashMap<Object, Node> nodeMap = new HashMap<Object, Node>();
+ // HashMap<Object, Edge> edgeMap = new HashMap<Object, Edge>();
+ for (Iterator<?> iterator = children.iterator(); iterator.hasNext();) {
+ Object object = (Object) iterator.next();
+ if (object instanceof GraphicalEditPart) {
+ IFigure figure = ((GraphicalEditPart) object).getFigure();
+ Node node = new Node();
+ nodeMap.put(object, node);
+ node.height = figure.getPreferredSize().height;
+ node.width = figure.getPreferredSize().width;
+ graph.nodes.add(node);
+ }
+ }
+
+ for (Iterator<?> iterator = children.iterator(); iterator.hasNext();) {
+ GraphicalEditPart object = (GraphicalEditPart) iterator.next();
+ for (Iterator<?> iterator2 = children.iterator(); iterator2.hasNext();) {
+ GraphicalEditPart testEditPart = (GraphicalEditPart) iterator2.next();
+ Node node = nodeMap.get(object);
+ Node testNode = nodeMap.get(testEditPart);
+ if (node != null && testNode != null) {
+ if (hasConnectionAssociation(object, testEditPart, SOURCE_CONNECT_TYPE)) {
+ Edge edge = new Edge(node, testNode);
+ graph.edges.add(edge);
+ }
+ if (hasConnectionAssociation(object, testEditPart, TARGET_CONNECT_TYPE)) {
+ Edge edge = new Edge(testNode, node);
+ graph.edges.add(edge);
+ }
+ }
+ }
+ }
+
+ DirectedGraphLayout layout = new DirectedGraphLayout();
+ layout.visit(graph);
+ Iterator<?> it = nodeMap.keySet().iterator();
+ while (it.hasNext()) {
+ GraphicalEditPart part = (GraphicalEditPart) it.next();
+ Node node = (Node) nodeMap.get(part);
+ IMoveableModel graphicalModel = (IMoveableModel) part.getModel();
+ ((IMoveableModel) graphicalModel).setLocation(new Point(node.x, node.y));
+ }
+ return;
+
+ }
GraphType graph = ext.getGraph();
if (graph == null)
return;
@@ -906,6 +966,58 @@
}
}
+ private boolean hasAssociation(Object model, GraphicalEditPart editPart) {
+ if (model == editPart.getModel()) {
+ return true;
+ }
+ AbstractSmooksGraphicalModel grphicalModel = (AbstractSmooksGraphicalModel)
editPart.getModel();
+ if (!grphicalModel.getChildrenWithoutDynamic().isEmpty()) {
+ List<?> children = editPart.getChildren();
+ for (Iterator<?> iterator2 = children.iterator(); iterator2.hasNext();) {
+ GraphicalEditPart gpart = (GraphicalEditPart) iterator2.next();
+ if (hasAssociation(model, gpart)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ private boolean hasConnectionAssociation(GraphicalEditPart editPart, GraphicalEditPart
testEditPart, int connectType) {
+ List<?> sourceConnections = null;
+ if (connectType == SOURCE_CONNECT_TYPE) {
+ sourceConnections = editPart.getSourceConnections();
+ }
+ if (connectType == TARGET_CONNECT_TYPE) {
+ sourceConnections = editPart.getTargetConnections();
+ }
+ for (Iterator<?> iterator = sourceConnections.iterator(); iterator.hasNext();) {
+ GraphicalEditPart object = (GraphicalEditPart) iterator.next();
+ TreeNodeConnection connection = (TreeNodeConnection) object.getModel();
+ Object testModel = null;
+ if (connectType == SOURCE_CONNECT_TYPE) {
+ testModel = connection.getTargetNode();
+ }
+ if (connectType == TARGET_CONNECT_TYPE) {
+ testModel = connection.getSourceNode();
+ }
+ if (hasAssociation(testModel, testEditPart)) {
+ return true;
+ }
+ }
+ AbstractSmooksGraphicalModel sourceGraphModel = (AbstractSmooksGraphicalModel)
editPart.getModel();
+ if (!sourceGraphModel.getChildrenWithoutDynamic().isEmpty()) {
+ List<?> children = editPart.getChildren();
+ for (Iterator<?> iterator = children.iterator(); iterator.hasNext();) {
+ GraphicalEditPart childEditPart = (GraphicalEditPart) iterator.next();
+ if (hasConnectionAssociation(childEditPart, testEditPart, connectType)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
@Override
public Object getAdapter(Class type) {
if (type == ISmooksModelProvider.class) {
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/SmooksProcessGraphicalEditor.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/SmooksProcessGraphicalEditor.java 2009-10-27
00:04:29 UTC (rev 18300)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/SmooksProcessGraphicalEditor.java 2009-10-27
05:58:58 UTC (rev 18301)
@@ -10,8 +10,10 @@
******************************************************************************/
package org.jboss.tools.smooks.graphical.editors;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.EventObject;
import java.util.HashMap;
import java.util.Iterator;
@@ -24,6 +26,8 @@
import org.eclipse.emf.common.command.CommandWrapper;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.gef.dnd.TemplateTransfer;
import org.eclipse.jface.action.IAction;
@@ -94,6 +98,7 @@
import org.jboss.tools.smooks.model.graphics.ext.SmooksGraphicsExtType;
import org.jboss.tools.smooks.model.graphics.ext.TaskType;
import org.jboss.tools.smooks.model.smooks.DocumentRoot;
+import org.jboss.tools.smooks.model.smooks.SmooksResourceListType;
/**
* @author Dart
@@ -183,23 +188,26 @@
protected void initProcessGraphicalViewer() {
SmooksGraphicsExtType ext = this.smooksModelProvider.getSmooksGraphicsExt();
ProcessesType processes = ext.getProcesses();
- if (processes == null) {
- processes = GraphFactory.eINSTANCE.createProcessesType();
- ext.setProcesses(processes);
- }
- ProcessType process = null;
+ boolean disableProcessViewer = false;
if (processes != null) {
- process = processes.getProcess();
+ ProcessType process = processes.getProcess();
+ if (process != null) {
+ getProcessGraphViewer().getControl().setBackground(
+ getManagedForm().getToolkit().getColors().getBackground());
+ getProcessGraphViewer().getControl().setEnabled(true);
+ getProcessGraphViewer().setInput(process);
+ } else {
+ disableProcessViewer = true;
+ }
+ } else {
+ disableProcessViewer = true;
}
-
- if (process == null) {
- process = GraphFactory.eINSTANCE.createProcessType();
- processes.setProcess(process);
+ if (disableProcessViewer) {
+ getProcessGraphViewer().getControl().setBackground(
+ getManagedForm().getToolkit().getColors().getBorderColor());
+ getProcessGraphViewer().setInput(null);
+ getProcessGraphViewer().getControl().setEnabled(false);
}
-
- if (process != null) {
- getProcessGraphViewer().setInput(process);
- }
}
protected void hookProcessGraphicalViewer() {
@@ -230,8 +238,11 @@
}
if (this.process != null) {
AddNextTaskNodeAction action = new AddInputTaskAction(smooksModelProvider);
-// IStructuredSelection selection = new StructuredSelection(taskType);
-// action.selectionChanged(new SelectionChangedEvent(getProcessGraphViewer(),
selection));
+ // IStructuredSelection selection = new
+ // StructuredSelection(taskType);
+ // action.selectionChanged(new
+ // SelectionChangedEvent(getProcessGraphViewer(),
+ // selection));
action.run();
return;
}
@@ -448,7 +459,8 @@
private Object data = null;
- public void dragStart(DragSourceEvent event) {this.data = null;
+ public void dragStart(DragSourceEvent event) {
+ this.data = null;
DragSource source = (DragSource) event.getSource();
ToolBar control = (ToolBar) source.getControl();
ToolItem item = control.getItem(new Point(event.x, event.y));
@@ -635,6 +647,23 @@
SmooksXSLTemplateGraphicalEditor xsltemplatePart = new
SmooksXSLTemplateGraphicalEditor(smooksModelProvider);
this.registeTaskDetailsPage(xsltemplatePart, TaskTypeManager.TASK_ID_XSL_TEMPLATE);
+ ProcessAnalyzer processAnalyzer = new ProcessAnalyzer();
+ EObject smooksModel = getSmooksResourceList();
+ if (smooksModel != null && smooksModel instanceof SmooksResourceListType) {
+ boolean needSave = processAnalyzer.analyzeSmooksModels((SmooksResourceListType)
smooksModel);
+ if (needSave) {
+ ResourceSet rs = this.smooksModelProvider.getEditingDomain().getResourceSet();
+ List<Resource> resourceLis = rs.getResources();
+ for (Iterator<?> iterator = resourceLis.iterator(); iterator.hasNext();) {
+ Resource resource = (Resource) iterator.next();
+ try {
+ resource.save(Collections.emptyMap());
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+ }
}
@Override
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/TaskTypeManager.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/TaskTypeManager.java 2009-10-27
00:04:29 UTC (rev 18300)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/TaskTypeManager.java 2009-10-27
05:58:58 UTC (rev 18301)
@@ -11,15 +11,20 @@
package org.jboss.tools.smooks.graphical.editors;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
import org.jboss.tools.smooks.configuration.editors.GraphicsConstants;
+import org.jboss.tools.smooks.model.graphics.ext.TaskType;
+import org.jboss.tools.smooks.model.smooks.AbstractResourceConfig;
+import org.jboss.tools.smooks.model.smooks.SmooksResourceListType;
/**
* @author Dart
*
*/
public class TaskTypeManager {
+
public static final String TASK_ID_INPUT = "input";
public static final String TASK_ID_JAVA_MAPPING = "java_mapping";
@@ -30,6 +35,19 @@
private static List<TaskTypeDescriptor> allTaskList = null;
+ public static String[] getChildTaskIDs(String parentId) {
+ if (parentId == null)
+ return null;
+ if (parentId.equals(TaskTypeManager.TASK_ID_INPUT)) {
+ return new String[] { TaskTypeManager.TASK_ID_JAVA_MAPPING,
TaskTypeManager.TASK_ID_XSL_TEMPLATE,
+ TaskTypeManager.TASK_ID_FREEMARKER_TEMPLATE };
+ }
+ if (parentId.equals(TaskTypeManager.TASK_ID_JAVA_MAPPING)) {
+ return new String[] { TaskTypeManager.TASK_ID_XSL_TEMPLATE,
TaskTypeManager.TASK_ID_FREEMARKER_TEMPLATE };
+ }
+ return null;
+ }
+
/**
* @return the allTaskList
*/
@@ -47,6 +65,55 @@
return allTaskList;
}
+ public static List<Object> getAssociatedSmooksElementsType(TaskType taskType) {
+ return null;
+ }
+
+ public static List<Object> getAssociatedSmooksElementsType(String taskID) {
+ return null;
+ }
+
+ public static String getTaskLabel(String taskId) {
+ if (taskId != null) {
+ if (taskId.equals(TASK_ID_FREEMARKER_TEMPLATE)) {
+ return "Apply Freemarker Template";
+ }
+ if (taskId.equals(TASK_ID_INPUT)) {
+ return "Input Task";
+ }
+ if (taskId.equals(TASK_ID_JAVA_MAPPING)) {
+ return "Java Mapping";
+ }
+ if (taskId.equals(TASK_ID_XSL_TEMPLATE)) {
+ return "Apply XSL Template";
+ }
+ }
+ return "";
+ }
+
+ /**
+ *
+ * @param taskID
+ * @param smooksResourceList
+ * @return
+ */
+ public static List<Object> getAssociatedSmooksElements(String taskID,
SmooksResourceListType smooksResourceList) {
+ List<Object> elementTypes = getAssociatedSmooksElementsType(taskID);
+ List<AbstractResourceConfig> resourceConfigList =
smooksResourceList.getAbstractResourceConfig();
+ List<Object> associatedElements = new ArrayList<Object>();
+ for (Iterator<?> iterator = resourceConfigList.iterator(); iterator.hasNext();)
{
+ AbstractResourceConfig abstractResourceConfig = (AbstractResourceConfig)
iterator.next();
+ if (isSameType(abstractResourceConfig, elementTypes)) {
+ associatedElements.add(abstractResourceConfig);
+ }
+ }
+ return associatedElements;
+ }
+
+ private static boolean isSameType(Object element, List<Object> elementTypes) {
+ return true;
+ }
+
public static final class TaskTypeDescriptor {
private String id;
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/wizards/JavaBeanCreationWizardPage.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/wizards/JavaBeanCreationWizardPage.java 2009-10-27
00:04:29 UTC (rev 18300)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/wizards/JavaBeanCreationWizardPage.java 2009-10-27
05:58:58 UTC (rev 18301)
@@ -12,8 +12,10 @@
import java.lang.reflect.Array;
import java.util.Collection;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaModelException;
@@ -22,6 +24,8 @@
import org.eclipse.jface.viewers.CheckboxTreeViewer;
import org.eclipse.jface.viewers.ICheckStateListener;
import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.ITreeViewerListener;
+import org.eclipse.jface.viewers.TreeExpansionEvent;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
@@ -34,6 +38,7 @@
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
+import org.eclipse.swt.widgets.TreeItem;
import org.jboss.tools.smooks.configuration.editors.javabean.JavaBeanModel;
import org.jboss.tools.smooks.configuration.editors.javabean.JavaBeanModelFactory;
import org.jboss.tools.smooks.configuration.editors.javabean.JavabeanContentProvider;
@@ -154,6 +159,35 @@
});
viewer.setLabelProvider(new JavabeanlabelProvider());
+ viewer.addTreeListener(new ITreeViewerListener() {
+
+ private Map<String, Object> expandRecord = new HashMap<String, Object>();
+
+ public void treeExpanded(TreeExpansionEvent event) {
+ Object element = event.getElement();
+ if (element instanceof TreeItem) {
+ element = ((TreeItem) element).getData();
+ }
+ if (element instanceof JavaBeanModel) {
+ Object key = expandRecord.get(((JavaBeanModel) element).getID().toString());
+ if (key == null) {
+ expandRecord.put(((JavaBeanModel) element).getID().toString(), new Object());
+ if (viewer.getChecked(element)) {
+ for (Iterator<?> iterator = ((JavaBeanModel)
element).getChildren().iterator(); iterator
+ .hasNext();) {
+ Object child = (Object) iterator.next();
+ viewer.setChecked(child, true);
+ }
+ }
+ }
+ }
+ }
+
+ public void treeCollapsed(TreeExpansionEvent event) {
+
+ }
+ });
+
viewer.addCheckStateListener(new ICheckStateListener() {
public void checkStateChanged(CheckStateChangedEvent event) {
@@ -162,6 +196,7 @@
boolean checked = event.getChecked();
if (checked) {
checkParents(element, viewer);
+ checkChildren((JavaBeanModel)element, true);
} else {
unCheckChildren(element, viewer);
}
@@ -181,6 +216,16 @@
}
}
+ private void checkChildren(JavaBeanModel model, boolean flag) {
+ if (((JavaBeanModel) model).isExpaned()) {
+ for (Iterator<?> iterator = ((JavaBeanModel) model).getChildren().iterator();
iterator.hasNext();) {
+ JavaBeanModel child = (JavaBeanModel) iterator.next();
+ viewer.setChecked(child, flag);
+ checkChildren(child, flag);
+ }
+ }
+ }
+
private void checkParents(Object element, final CheckboxTreeViewer viewer) {
ITreeContentProvider provider = (ITreeContentProvider) viewer.getContentProvider();
Object parent = provider.getParent(element);
@@ -405,7 +450,7 @@
arrayButton.setEnabled(false);
collectionClassBrowseButton.setEnabled(true);
colllectionClassText.setEnabled(true);
- }else{
+ } else {
collectionClassBrowseButton.setEnabled(false);
colllectionClassText.setEnabled(false);
colllectionClassText.setText("");