- jgraph.getLocationOnScreen().x, dsde.getY()
- jgraph.getLocationOnScreen().y);
DefaultGraphCell endCell = (DefaultGraphCell) GraphView.this.jgraph
.getSelectionCell();
if (endCell != null) {
ModelGraph endGraph = GuiUtils.find(
state.getGraphs(),
((ModelNode) endCell.getUserObject()).getId());
if (!endGraph.getModel().isParentType()
|| GuiUtils.isSubGraph(moveGraph, endGraph))
return;
if (moveGraph.getParent() == null)
state.removeGraph(moveGraph);
else
GuiUtils.removeNode(state.getGraphs(),
moveGraph.getModel());
GraphView.this.removeShift(state, moveGraph);
GuiUtils.addChild(state.getGraphs(), endGraph
.getModel().getId(), moveGraph);
GraphView.this.notifyListeners();
} else {
if (moveGraph.getParent() != null) {
GuiUtils.removeNode(state.getGraphs(),
moveGraph.getModel());
state.addGraph(moveGraph);
}
Point shiftPoint = new Point(
(int) ((dropPoint.x - (dge.getDragOrigin().x - (bounds
.getX() * scale))) / scale),
(int) ((dropPoint.y - (dge.getDragOrigin().y - (bounds
.getY() * scale))) / scale));
GraphView.this.setShift(state, moveGraph,
shiftPoint);
GraphView.this.notifyListeners();
}
}
public void dragEnter(DragSourceDragEvent dsde) {
mouseOverCell = (DefaultGraphCell) GraphView.this.jgraph
.getFirstCellForLocation(
dsde.getX() - jgraph.getLocationOnScreen().x,
dsde.getY() - jgraph.getLocationOnScreen().y);
mouseOverGraph = GuiUtils.find(state.getGraphs(),
((ModelNode) mouseOverCell.getUserObject())
.getId());
}
public void dragExit(DragSourceEvent dse) {
System.out.println("DRAG EXIT!!!!");
}
public void dragOver(DragSourceDragEvent dsde) {
if (state.getMode().equals(Mode.EDIT)) {
if (mouseOverCell != null) {
Rectangle2D currentBounds = (Rectangle2D) mouseOverCell
.getAttributes().get(GraphConstants.BOUNDS);
Point currentPoint = new Point(dsde.getX()
- jgraph.getLocationOnScreen().x, dsde.getY()
- jgraph.getLocationOnScreen().y);
if (currentBounds.contains(currentPoint)) {
for (ModelGraph child : mouseOverGraph
.getChildren()) {
DefaultGraphCell mouseOverCellLoc = GraphView.this.m_jgAdapter
.getVertexCell(child.getModel());
currentBounds = (Rectangle2D) mouseOverCellLoc
.getAttributes().get(
GraphConstants.BOUNDS);
if (currentBounds.contains(currentPoint)) {
mouseOverCell = mouseOverCellLoc;
mouseOverGraph = child;
break;
}
}
} else {
if (mouseOverGraph.getParent() != null
&& (!mouseOverGraph.isCondition() || (mouseOverGraph
.isCondition() && mouseOverGraph
.getParent().isCondition()))) {
mouseOverCell = GraphView.this.m_jgAdapter
.getVertexCell((mouseOverGraph = mouseOverGraph
.getParent()).getModel());
currentBounds = (Rectangle2D) mouseOverCell
.getAttributes().get(
GraphConstants.BOUNDS);
} else {
mouseOverCell = null;
mouseOverGraph = null;
}
}
} else {
mouseOverCell = (DefaultGraphCell) GraphView.this.jgraph
.getFirstCellForLocation(
dsde.getX()
- jgraph.getLocationOnScreen().x,
dsde.getY()
- jgraph.getLocationOnScreen().y);
if (mouseOverCell != null)
mouseOverGraph = GuiUtils.find(state
.getGraphs(), ((ModelNode) mouseOverCell
.getUserObject()).getId());
else
mouseOverGraph = null;
}
if (mouseOverGraph != null) {
if (GuiUtils.isDummyNode(mouseOverGraph
.getModel())) {
mouseOverGraph = mouseOverGraph.getParent();
} else {
while (mouseOverGraph != null
&& mouseOverGraph.getModel().isRef())
mouseOverGraph = mouseOverGraph.getParent();
}
if (mouseOverGraph != null)
mouseOverCell = GraphView.this.m_jgAdapter
.getVertexCell(mouseOverGraph.getModel());
else
mouseOverCell = null;
}
GraphView.this.jgraph
.setSelectionCells(new Object[] { mouseOverCell });
}
}
public void dropActionChanged(DragSourceDragEvent dsde) {
System.out.println("DRAG CHANGE!!!!");
}
});
}
}
}
}
});
List<Line> lines = GuiUtils.findLines(state.getGraphs());
for (Line line : lines) {
if (!this.directedGraph.containsVertex(line.getFromModel()))
this.directedGraph.addVertex(line.getFromModel());
if (line.getToModel() != null) {
if (!this.directedGraph.containsVertex(line.getToModel()))
this.directedGraph.addVertex(line.getToModel());
IdentifiableEdge edge = new IdentifiableEdge(line.getFromModel(), line.getToModel());
directedGraph.addEdge(edge, line.getFromModel(), line.getToModel());
this.edgeMap.put(edge.id, new Pair(line.getFromModel() != null ? line
.getFromModel().getId() : null, line.getToModel().getId()));
}
}
JGraphFacade facade = new JGraphFacade(jgraph);
facade.setIgnoresUnconnectedCells(false);
JGraphHierarchicalLayout layout = new JGraphHierarchicalLayout();
layout.setOrientation(SwingConstants.WEST);
layout.setIntraCellSpacing(70.0);
layout.setLayoutFromSinks(false);
layout.run(facade);
Map nested = facade.createNestedMap(true, true);
if (nested != null) {
this.hideDummyNodes(nested);
this.addGroups(state.getGraphs(), nested, state);
this.ensureNoOverlap(nested, state);
nested = this.shiftMap(nested, state);
jgraph.getGraphLayoutCache().edit(nested);
}
String edgeDisplayMode = state.getFirstPropertyValue(EDGE_DISPLAY_MODE);
if (edgeDisplayMode == null)
state.setProperty(EDGE_DISPLAY_MODE, edgeDisplayMode = WORKFLOW_MODE);
if (edgeDisplayMode.equals(WORKFLOW_MODE)) {
this.edgeMap = new HashMap<String, Pair>();
removeAllEdges(this.directedGraph);
lines = GuiUtils.findSequentialLines(state.getGraphs());
for (Line line : lines) {
IdentifiableEdge edge = new IdentifiableEdge(line.getFromModel(), line.getToModel());
directedGraph.addEdge(edge, line.getFromModel(), line.getToModel());
this.edgeMap.put(edge.id, new Pair(line.getFromModel() != null ? line
.getFromModel().getId() : null, line.getToModel().getId()));
}
}
if (state.getSelected() != null) {
ModelGraph graph = GuiUtils.find(state.getGraphs(), state.getSelected()
.getModel().getId());
if (graph != null) {
DefaultGraphCell cell = this.m_jgAdapter
.getVertexCell(graph.getModel());
if (cell != null)
this.jgraph.setSelectionCells(new Object[] { cell });
else
this.jgraph.setSelectionCells(new Object[] {});
} else