package com.vci.client.workflow.editor;
|
|
import java.awt.event.MouseAdapter;
|
import java.awt.event.MouseEvent;
|
import java.io.InputStream;
|
|
import javax.swing.ImageIcon;
|
import javax.xml.parsers.DocumentBuilder;
|
import javax.xml.parsers.DocumentBuilderFactory;
|
|
import org.w3c.dom.Document;
|
import org.w3c.dom.Element;
|
import org.w3c.dom.NodeList;
|
|
import com.mxgraph.swing.mxGraphComponent;
|
import com.mxgraph.swing.util.mxGraphTransferable;
|
import com.mxgraph.util.mxEvent;
|
import com.mxgraph.util.mxEventObject;
|
import com.mxgraph.util.mxEventSource.mxIEventListener;
|
import com.mxgraph.view.mxGraph;
|
import com.vci.client.workflow.editor.CustomGraphComponent.CustomGraph;
|
import com.vci.corba.common.VCIError;
|
|
public class FlowDesigner extends BasicGraphEditor {
|
|
private static final long serialVersionUID = -4716858349938153598L;
|
|
public FlowDesigner() throws VCIError {
|
this(new CustomGraphComponent());
|
}
|
|
public FlowDesigner(mxGraphComponent component) {
|
super(component);
|
((CustomGraphComponent)graphComponent).setFlowDesigner(this);
|
final mxGraph graph = getGraphComponent().getGraph();
|
getGraphComponent().getGraphControl().addMouseListener(new MouseAdapter() {
|
public void mouseClicked(MouseEvent e) {
|
try {
|
updatePanel(graph.getSelectionCell());
|
} catch (VCIError e1) {
|
// TODO Auto-generated catch block
|
e1.printStackTrace();
|
}
|
}
|
});
|
}
|
|
public void updatePanel(Object cell) throws VCIError{
|
if(cell == null){
|
cell = getGraphComponent().getGraph().getModel().getRoot();
|
}
|
getEditor().updatePanel(cell);
|
}
|
|
public boolean isEdit(boolean flag){
|
if ("1".equals(getDeployPanelFlag())) {
|
((FlowDeployPanel)getDeployPanel()).isEdit(flag);
|
} else if ("2".equals(getDeployPanelFlag())) {
|
((FlowDeployNewPanel)getDeployPanel()).isEdit(flag);
|
}
|
// getDeployPanel().isEdit(flag);
|
return flag;
|
}
|
public EditorPalette getEditorPalette() {
|
if(palette == null){
|
palette = new EditorPalette();
|
addTemplate(palette);
|
final mxGraph graph = graphComponent.getGraph();
|
|
// Sets the edge template to be used for creating new edges if an edge
|
// is clicked in the shape palette
|
palette.addListener(mxEvent.SELECT, new mxIEventListener() {
|
public void invoke(Object sender, mxEventObject evt) {
|
Object tmp = evt.getProperty("transferable");
|
if (tmp instanceof mxGraphTransferable) {
|
mxGraphTransferable t = (mxGraphTransferable) tmp;
|
Object cell = t.getCells()[0];
|
if (graph.getModel().isEdge(cell)) {
|
((CustomGraph) graph).setEdgeTemplate(cell);
|
}
|
}
|
}
|
});
|
}
|
|
return palette;
|
}
|
|
private void addTemplate(EditorPalette palette){
|
try {
|
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
DocumentBuilder db = dbf.newDocumentBuilder();
|
ClassLoader cl = FlowDesigner.class.getClassLoader();
|
InputStream in = cl.getResourceAsStream("flow-tools.xml");
|
Document doc = db.parse(in);
|
// Document doc = db.parse(FlowDesigner.class.getResource("/flow-tools.xml").toString());
|
NodeList nodelist = doc.getElementsByTagName("tool");
|
for (int i = 0; i < nodelist.getLength(); i++) {
|
String type = ((Element) nodelist.item(i)).getAttribute("type");
|
String label = ((Element) nodelist.item(i)).getAttribute("label");
|
String icon = ((Element) nodelist.item(i)).getAttribute("icon");
|
int width = Integer.parseInt(((Element) nodelist.item(i)).getAttribute("width"));
|
int height = Integer.parseInt(((Element) nodelist.item(i)).getAttribute("height"));
|
|
FlowNode tool = new FlowNode(type, label);
|
if (type != null && type.startsWith("transition_")) {
|
palette.addEdgeTemplate(label, new ImageIcon(
|
FlowDesigner.class.getResource(icon)), type,
|
width, height, tool);
|
} else {
|
palette.addTemplate(label,
|
new ImageIcon(FlowDesigner.class.getResource(icon)),
|
type, width, height, tool);
|
}
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
|
}
|