Author: tfennelly
Date: 2011-06-22 09:19:52 -0400 (Wed, 22 Jun 2011)
New Revision: 32287
Added:
branches/jbosstools-3.2.x/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/editparts/freemarker/FreemarkerRemoveConnectionsExecutor.java
Modified:
branches/jbosstools-3.2.x/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/gef/tree/editparts/CreateConnectionCommand.java
branches/jbosstools-3.2.x/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/editparts/freemarker/FreemarkerTemplateConnectionEditPart.java
branches/jbosstools-3.2.x/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/editparts/freemarker/FreemarkerXMLNodeEditPart.java
branches/jbosstools-3.2.x/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/model/freemarker/FreemarkerTemplateNodeGraphicalModel.java
Log:
JBIDE-7309: Testing a direct-to-source mapping errors out
https://issues.jboss.org/browse/JBIDE-7309
Modified:
branches/jbosstools-3.2.x/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/gef/tree/editparts/CreateConnectionCommand.java
===================================================================
---
branches/jbosstools-3.2.x/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/gef/tree/editparts/CreateConnectionCommand.java 2011-06-22
12:59:49 UTC (rev 32286)
+++
branches/jbosstools-3.2.x/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/gef/tree/editparts/CreateConnectionCommand.java 2011-06-22
13:19:52 UTC (rev 32287)
@@ -9,6 +9,7 @@
import org.jboss.tools.smooks.gef.tree.model.TreeNodeConnection;
import org.jboss.tools.smooks.gef.tree.model.TriggerConnection;
import org.jboss.tools.smooks.gef.tree.model.ValueBindingConnection;
+import
org.jboss.tools.smooks.graphical.editors.editparts.freemarker.FreemarkerRemoveConnectionsExecutor;
import org.jboss.tools.smooks.graphical.editors.model.InputDataTreeNodeModel;
import
org.jboss.tools.smooks.graphical.editors.model.freemarker.FreemarkerTemplateConnection;
import
org.jboss.tools.smooks.graphical.editors.model.freemarker.FreemarkerXMLNodeGraphicalModel;
@@ -21,6 +22,7 @@
*/
public class CreateConnectionCommand extends Command {
+ private FreemarkerRemoveConnectionsExecutor removeExecutor = new
FreemarkerRemoveConnectionsExecutor();
private AbstractSmooksGraphicalModel source;
private AbstractSmooksGraphicalModel target;
@@ -55,23 +57,37 @@
}
connection.connect();
- tempConnectionHandle = connection;
+ if(connection instanceof FreemarkerTemplateConnection) {
+ removeExecutor.execute(connection,
((FreemarkerTemplateConnection)connection).getRemoveMappings());
+ }
}
}
@Override
public void redo() {
- if (tempConnectionHandle != null) {
- tempConnectionHandle.connect();
+ if(tempConnectionHandle instanceof FreemarkerTemplateConnection) {
+ for(TreeNodeConnection connection : removeExecutor.getRelatedConnections()) {
+ connection.connect();
+ }
} else {
- execute();
+ if (tempConnectionHandle != null) {
+ tempConnectionHandle.connect();
+ } else {
+ execute();
+ }
}
}
@Override
public void undo() {
- if (tempConnectionHandle != null) {
- tempConnectionHandle.disconnect();
+ if(tempConnectionHandle instanceof FreemarkerTemplateConnection) {
+ for(TreeNodeConnection connection : removeExecutor.getRelatedConnections()) {
+ connection.disconnect();
+ }
+ } else {
+ if (tempConnectionHandle != null) {
+ tempConnectionHandle.disconnect();
+ }
}
}
Copied:
branches/jbosstools-3.2.x/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/editparts/freemarker/FreemarkerRemoveConnectionsExecutor.java
(from rev 32286,
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/editparts/freemarker/FreemarkerRemoveConnectionsExecutor.java)
===================================================================
---
branches/jbosstools-3.2.x/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/editparts/freemarker/FreemarkerRemoveConnectionsExecutor.java
(rev 0)
+++
branches/jbosstools-3.2.x/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/editparts/freemarker/FreemarkerRemoveConnectionsExecutor.java 2011-06-22
13:19:52 UTC (rev 32287)
@@ -0,0 +1,84 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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.editparts.freemarker;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.jboss.tools.smooks.gef.model.AbstractSmooksGraphicalModel;
+import org.jboss.tools.smooks.gef.tree.model.TreeNodeConnection;
+import org.jboss.tools.smooks.gef.tree.model.TreeNodeModel;
+import
org.jboss.tools.smooks.graphical.editors.model.freemarker.FreemarkerTemplateConnection;
+import
org.jboss.tools.smooks.graphical.editors.model.freemarker.FreemarkerTemplateNodeGraphicalModel;
+import org.jboss.tools.smooks.templating.template.Mapping;
+
+/**
+ *
+ * @author <a
href="mailto:tom.fennelly@gmail.com">tom.fennelly@gmail.com</a>
+ */
+public class FreemarkerRemoveConnectionsExecutor {
+ private List<TreeNodeConnection> relatedConnections = new
ArrayList<TreeNodeConnection>();
+
+ public List<TreeNodeConnection> removeMappingConnections(
+ List<Mapping> removeMappings, AbstractSmooksGraphicalModel node) {
+ if (removeMappings == null || removeMappings.isEmpty()) {
+ return Collections.emptyList();
+ }
+
+ // Remove from all the children first...
+ for (AbstractSmooksGraphicalModel child : node.getChildren()) {
+ if (child instanceof TreeNodeModel) {
+ relatedConnections.addAll(removeMappingConnections(
+ removeMappings, (TreeNodeModel) child));
+ }
+ }
+
+ // Now remove from this node...
+ if (node.getTargetConnections() != null &&
!node.getTargetConnections().isEmpty()) {
+ List<TreeNodeConnection> connectionsToRemove = new
ArrayList<TreeNodeConnection>();
+ for (TreeNodeConnection connection : node
+ .getTargetConnections()) {
+ Object connectionData = connection.getData();
+ if (connectionData instanceof Mapping) {
+ for (Mapping mapping : removeMappings) {
+ if(mapping.getMappingNode() == ((Mapping)connectionData).getMappingNode()
&&
+ mapping.getSrcPath().equals(((Mapping)connectionData).getSrcPath())){
+ connectionsToRemove.add(connection);
+ }
+ }
+ }
+ }
+ return connectionsToRemove;
+ }
+ return Collections.emptyList();
+ }
+
+ public void execute(TreeNodeConnection connectionHandle, List<Mapping>
removeMappings) {
+ Object target = connectionHandle.getTargetNode();
+ if (target instanceof FreemarkerTemplateNodeGraphicalModel) {
+ if(removeMappings!=null){
+ relatedConnections.clear();
+ relatedConnections.addAll(removeMappingConnections(removeMappings,
(FreemarkerTemplateNodeGraphicalModel)target));
+ for (TreeNodeConnection con : relatedConnections) {
+ con.disconnect();
+ }
+ }
+ }
+ }
+
+ /**
+ * @return
+ */
+ public List<TreeNodeConnection> getRelatedConnections() {
+ return relatedConnections;
+ }
+}
Modified:
branches/jbosstools-3.2.x/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/editparts/freemarker/FreemarkerTemplateConnectionEditPart.java
===================================================================
---
branches/jbosstools-3.2.x/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/editparts/freemarker/FreemarkerTemplateConnectionEditPart.java 2011-06-22
12:59:49 UTC (rev 32286)
+++
branches/jbosstools-3.2.x/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/editparts/freemarker/FreemarkerTemplateConnectionEditPart.java 2011-06-22
13:19:52 UTC (rev 32287)
@@ -10,10 +10,6 @@
******************************************************************************/
package org.jboss.tools.smooks.graphical.editors.editparts.freemarker;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.commands.Command;
@@ -25,10 +21,8 @@
import org.jboss.tools.smooks.gef.model.AbstractSmooksGraphicalModel;
import org.jboss.tools.smooks.gef.tree.command.DeleteConnectionCommand;
import org.jboss.tools.smooks.gef.tree.editparts.TreeNodeConnectionEditPart;
-import org.jboss.tools.smooks.gef.tree.editpolicy.TreeNodeConnectionEditPolicy;
import org.jboss.tools.smooks.gef.tree.editpolicy.TreeNodeEndpointEditPolicy;
import org.jboss.tools.smooks.gef.tree.model.TreeNodeConnection;
-import org.jboss.tools.smooks.gef.tree.model.TreeNodeModel;
import
org.jboss.tools.smooks.graphical.editors.model.freemarker.FreemarkerModelAnalyzer;
import
org.jboss.tools.smooks.graphical.editors.model.freemarker.FreemarkerTemplateNodeGraphicalModel;
import org.jboss.tools.smooks.templating.template.Mapping;
@@ -100,7 +94,7 @@
public class DeleteFreeMarkerConnectionCommand extends
DeleteConnectionCommand {
- private List<TreeNodeConnection> relatedConnections = new
ArrayList<TreeNodeConnection>();
+ private FreemarkerRemoveConnectionsExecutor removeConnectionExecutor = new
FreemarkerRemoveConnectionsExecutor();
public DeleteFreeMarkerConnectionCommand(TreeNodeConnection connection) {
super(connection);
@@ -118,13 +112,10 @@
if (builder == null || mapping == null)
return;
if (mapping instanceof Mapping) {
- relatedConnections.clear();
removeResult = builder.removeMapping((Mapping) mapping);
- relatedConnections.addAll(removeMappingConnections(
- removeResult.getRemoveMappings(),
- (FreemarkerTemplateNodeGraphicalModel) target));
+ removeConnectionExecutor.execute(connection, removeResult.getRemoveMappings());
}
- for (TreeNodeConnection con : relatedConnections) {
+ for (TreeNodeConnection con : removeConnectionExecutor.getRelatedConnections()) {
con.disconnect();
}
} catch (Exception e) {
@@ -142,43 +133,9 @@
@Override
public void undo() {
super.undo();
- for (TreeNodeConnection c : relatedConnections) {
+ for (TreeNodeConnection c : removeConnectionExecutor.getRelatedConnections()) {
c.connect();
}
}
-
- public List<TreeNodeConnection> removeMappingConnections(
- List<Mapping> removeMappings, AbstractSmooksGraphicalModel node) {
- if (removeMappings == null || removeMappings.isEmpty()) {
- return Collections.emptyList();
- }
-
- // Remove from all the children first...
- for (AbstractSmooksGraphicalModel child : node.getChildren()) {
- if (child instanceof TreeNodeModel) {
- relatedConnections.addAll(removeMappingConnections(
- removeMappings, (TreeNodeModel) child));
- }
- }
-
- // Now remove from this node...
- if (node.getTargetConnections() != null &&
!node.getTargetConnections().isEmpty()) {
- List<TreeNodeConnection> connectionsToRemove = new
ArrayList<TreeNodeConnection>();
- for (TreeNodeConnection connection : node
- .getTargetConnections()) {
- Object connectionData = connection.getData();
- if (connectionData instanceof Mapping) {
- for (Mapping mapping : removeMappings) {
- if(mapping.getMappingNode() == ((Mapping)connectionData).getMappingNode()
&&
- mapping.getSrcPath().equals(((Mapping)connectionData).getSrcPath())){
- connectionsToRemove.add(connection);
- }
- }
- }
- }
- return connectionsToRemove;
- }
- return Collections.emptyList();
- }
}
}
Modified:
branches/jbosstools-3.2.x/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/editparts/freemarker/FreemarkerXMLNodeEditPart.java
===================================================================
---
branches/jbosstools-3.2.x/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/editparts/freemarker/FreemarkerXMLNodeEditPart.java 2011-06-22
12:59:49 UTC (rev 32286)
+++
branches/jbosstools-3.2.x/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/editparts/freemarker/FreemarkerXMLNodeEditPart.java 2011-06-22
13:19:52 UTC (rev 32287)
@@ -173,64 +173,20 @@
}
}
- public class CreateFreemarkerXMLConnectionCommand extends CreateConnectionCommand{
- private List<TreeNodeConnection> relatedConnections = new
ArrayList<TreeNodeConnection>();
+ public class CreateFreemarkerXMLConnectionCommand extends CreateConnectionCommand {
+ private FreemarkerRemoveConnectionsExecutor removeExecutor = new
FreemarkerRemoveConnectionsExecutor();
- public List<TreeNodeConnection> removeMappingConnections(
- List<Mapping> removeMappings, AbstractSmooksGraphicalModel node) {
- if (removeMappings == null || removeMappings.isEmpty()) {
- return Collections.emptyList();
- }
-
- // Remove from all the children first...
- for (AbstractSmooksGraphicalModel child : node.getChildren()) {
- if (child instanceof TreeNodeModel) {
- relatedConnections.addAll(removeMappingConnections(
- removeMappings, (TreeNodeModel) child));
- }
- }
-
- // Now remove from this node...
- if (node.getTargetConnections() != null &&
!node.getTargetConnections().isEmpty()) {
- List<TreeNodeConnection> connectionsToRemove = new
ArrayList<TreeNodeConnection>();
- for (TreeNodeConnection connection : node
- .getTargetConnections()) {
- Object connectionData = connection.getData();
- if (connectionData instanceof Mapping) {
- for (Mapping mapping : removeMappings) {
- if(mapping.getMappingNode() == ((Mapping)connectionData).getMappingNode()
&&
- mapping.getSrcPath().equals(((Mapping)connectionData).getSrcPath())){
- connectionsToRemove.add(connection);
- }
- }
- }
- }
- return connectionsToRemove;
- }
- return Collections.emptyList();
- }
-
@Override
public void execute() {
super.execute();
- Object target = getTempConnectionHandle().getTargetNode();
- if (target instanceof FreemarkerTemplateNodeGraphicalModel) {
- FreemarkerTemplateConnection connection =
(FreemarkerTemplateConnection)this.getTempConnectionHandle();
- List<Mapping> removeMappings = connection.getRemoveMappings();
- if(removeMappings!=null){
- relatedConnections.clear();
- relatedConnections.addAll(removeMappingConnections(removeMappings,
(FreemarkerTemplateNodeGraphicalModel)target));
- for (TreeNodeConnection con : relatedConnections) {
- con.disconnect();
- }
- }
- }
+ TreeNodeConnection tempConnectionHandle = getTempConnectionHandle();
+ removeExecutor.execute(tempConnectionHandle,
((FreemarkerTemplateConnection)tempConnectionHandle).getRemoveMappings());
}
@Override
public void undo() {
super.undo();
- for (TreeNodeConnection c : relatedConnections) {
+ for (TreeNodeConnection c : removeExecutor.getRelatedConnections()) {
c.connect();
}
}
Modified:
branches/jbosstools-3.2.x/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/model/freemarker/FreemarkerTemplateNodeGraphicalModel.java
===================================================================
---
branches/jbosstools-3.2.x/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/model/freemarker/FreemarkerTemplateNodeGraphicalModel.java 2011-06-22
12:59:49 UTC (rev 32286)
+++
branches/jbosstools-3.2.x/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/model/freemarker/FreemarkerTemplateNodeGraphicalModel.java 2011-06-22
13:19:52 UTC (rev 32287)
@@ -26,6 +26,7 @@
import org.jboss.tools.smooks.gef.model.AbstractSmooksGraphicalModel;
import org.jboss.tools.smooks.gef.tree.model.TreeNodeConnection;
import org.jboss.tools.smooks.gef.tree.model.TreeNodeModel;
+import
org.jboss.tools.smooks.graphical.editors.editparts.freemarker.FreemarkerRemoveConnectionsExecutor;
import
org.jboss.tools.smooks.graphical.editors.model.AbstractResourceConfigChildNodeGraphModel;
import org.jboss.tools.smooks.graphical.editors.model.InputDataTreeNodeModel;
import org.jboss.tools.smooks.graphical.editors.model.javamapping.JavaBeanGraphModel;
@@ -184,7 +185,6 @@
if(connection instanceof FreemarkerTemplateConnection){
((FreemarkerTemplateConnection)connection).setRemoveMappingConnections(mappingResult.getRemoveMappings());
}
-// ((TreeNodeModel)getModelRootNode()).removeMappingConnections(mappingResult.getRemoveMappings());
} else if (isMappingValueConnection(connection)) {
String mappingString = null;
@@ -361,9 +361,9 @@
if (builder == null || mapping == null)
return;
if (mapping instanceof Mapping) {
- removeResult = builder.removeMapping((Mapping) mapping);
-
- connection.setData(removeResult);
+ removeResult = builder.removeMapping((Mapping) mapping);
+ FreemarkerRemoveConnectionsExecutor removeConnectionExecutor = new
FreemarkerRemoveConnectionsExecutor();
+ removeConnectionExecutor.execute(connection, removeResult.getRemoveMappings());
}
changeFreemarkerContents();
super.removeTargetConnection(connection);