yuxc
2025-01-15 c09f81131e8b7c83937206d7cf76f34d2020be75
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package com.vci.client.workflow.editor.ui;
 
import java.awt.Dimension;
import java.awt.Toolkit;
 
import javax.swing.JComponent;
import javax.swing.JEditorPane;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTabbedPane;
import javax.swing.SingleSelectionModel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
 
import com.mxgraph.model.mxCell;
import com.mxgraph.swing.mxGraphComponent;
import com.mxgraph.view.mxGraph;
import com.vci.client.workflow.editor.BasicGraphEditor;
import com.vci.client.workflow.editor.EditorCreateXmlToJbpm;
import com.vci.client.workflow.editor.ProcessComponentFactory;
import com.vci.corba.common.VCIError;
 
public class FlowEditor extends JSplitPane {
    private static final long serialVersionUID = 7562492732674456910L;
    
    private mxGraph graph = null;
    private BasicGraphEditor basicGraphEditor = null;
 
    private JEditorPane xmlPane;
    
    public mxGraph getGraph() {
        return graph;
    }
 
    public FlowEditor(BasicGraphEditor basicGraphEditor) {
        this.basicGraphEditor = basicGraphEditor;
        mxGraphComponent graphComponent = basicGraphEditor.getGraphComponent();
        this.graph = graphComponent.getGraph();
        
        JTabbedPane editor = new JTabbedPane(JTabbedPane.BOTTOM);
        editor.add("Design", graphComponent);
        xmlPane = new JEditorPane();
        editor.add("Source", new JScrollPane(xmlPane));
        editor.getModel().addChangeListener(new ChangeListener() {
            public void stateChanged(ChangeEvent e) {
                SingleSelectionModel source = (SingleSelectionModel)e.getSource();
                int selectedIndex = source.getSelectedIndex();
                freshGraphEditor(selectedIndex);
            }
        });
        this.setOrientation(JSplitPane.VERTICAL_SPLIT);
        this.setTopComponent(editor);
 
        mxCell cell = (mxCell)getGraph().getModel().getRoot();
        this.setBottomComponent((JComponent)cell.getValue());
 
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        this.setDividerLocation(screenSize.height - 280);
        this.setDividerSize(7);
        this.setOneTouchExpandable(true);
    }
 
    private void freshGraphEditor(int selectedIndex) {
        if(selectedIndex == 1){//1是source属性页的index
            EditorCreateXmlToJbpm getXml= new  EditorCreateXmlToJbpm(basicGraphEditor);
            xmlPane.setText(getXml.getsXml());
            xmlPane.setCaretPosition(0);
        }
    }
 
    public void updatePanel(Object cell) throws VCIError {
        Object value = ((mxCell)cell).getValue();
        if(value instanceof JComponent) {
            this.setBottomComponent((JComponent)value);
        } else if(value instanceof String) {
            JComponent component = ProcessComponentFactory.getComponent(graph, ((mxCell)cell));
            ((mxCell)cell).setValue(component);
            this.setBottomComponent(component);
        }
        int location = this.getDividerLocation();
        this.setDividerLocation(location);
    }
    
    public String getXml(){
        return xmlPane.getText();
    }
 
}