18 |
18 |
import org.eclipse.ui.part.EditorPart;
|
19 |
19 |
import org.graphstream.graph.Graph;
|
20 |
20 |
import org.graphstream.graph.implementations.DefaultGraph;
|
|
21 |
import org.graphstream.stream.file.FileSource;
|
21 |
22 |
import org.graphstream.stream.file.FileSourceDOT;
|
|
23 |
import org.graphstream.stream.file.FileSourceFactory;
|
|
24 |
import org.graphstream.stream.file.FileSourceGML;
|
|
25 |
import org.graphstream.stream.file.FileSourceParser;
|
22 |
26 |
import org.txm.chartsengine.graphstream.rcp.swt.GSComposite;
|
23 |
27 |
|
24 |
28 |
public class GSEditor extends EditorPart {
|
... | ... | |
33 |
37 |
@Override
|
34 |
38 |
public void doSave(IProgressMonitor monitor) {
|
35 |
39 |
// TODO Auto-generated method stub
|
36 |
|
|
|
40 |
|
37 |
41 |
}
|
38 |
42 |
|
39 |
43 |
@Override
|
40 |
44 |
public void doSaveAs() {
|
41 |
45 |
// TODO Auto-generated method stub
|
42 |
|
|
|
46 |
|
43 |
47 |
}
|
44 |
48 |
|
45 |
49 |
@Override
|
... | ... | |
60 |
64 |
|
61 |
65 |
@Override
|
62 |
66 |
public void createPartControl(Composite parent) {
|
63 |
|
parent.setLayout(new GridLayout(2, true));
|
64 |
|
|
|
67 |
parent.setLayout(new GridLayout(1, true));
|
|
68 |
|
65 |
69 |
loadButton = new Button(parent, SWT.PUSH);
|
66 |
70 |
loadButton.setText("Load Graph file...");
|
67 |
71 |
loadButton.addSelectionListener(new SelectionListener() {
|
68 |
|
|
|
72 |
|
69 |
73 |
@Override
|
70 |
74 |
public void widgetSelected(SelectionEvent e) {
|
71 |
|
|
|
75 |
|
72 |
76 |
FileDialog dialog = new FileDialog(e.display.getActiveShell(), SWT.OPEN);
|
73 |
|
dialog.setFilterExtensions(new String[] {"*.dot"});
|
|
77 |
dialog.setFilterExtensions(new String[] {"*.*", "*.dot", "*.gml", "*.gexf", "*.graphml"});
|
74 |
78 |
String path = dialog.open();
|
75 |
79 |
if (path == null) {
|
76 |
80 |
return;
|
77 |
81 |
}
|
78 |
|
|
|
82 |
|
79 |
83 |
Graph g = new DefaultGraph("g"); //$NON-NLS-1$
|
80 |
|
FileSourceDOT fs = new FileSourceDOT();
|
81 |
|
fs.addSink(g);
|
|
84 |
// FileSource fs = null;
|
|
85 |
// if (path.endsWith(".dot")) {
|
|
86 |
// fs = new FileSourceDOT();
|
|
87 |
// fs.addSink(g);
|
|
88 |
// try {
|
|
89 |
// fs.readAll(path);
|
|
90 |
// } catch (IOException e1) {
|
|
91 |
// e1.printStackTrace();
|
|
92 |
// return;
|
|
93 |
// } finally {
|
|
94 |
// fs.removeSink(g);
|
|
95 |
// }
|
|
96 |
// } else if (path.endsWith(".gml")) {
|
|
97 |
// fs = new FileSourceGML();
|
|
98 |
// } else if (path.endsWith(".gexf")) {
|
|
99 |
//
|
|
100 |
// } else if (path.endsWith(".graphml")) {
|
|
101 |
//
|
|
102 |
// }
|
|
103 |
|
82 |
104 |
try {
|
83 |
|
fs.readAll(path);
|
|
105 |
FileSource fs = new FileSourceFactory().sourceFor(path);
|
|
106 |
|
|
107 |
if (fs != null) {
|
|
108 |
fs = new FileSourceDOT();
|
|
109 |
fs.addSink(g);
|
|
110 |
try {
|
|
111 |
fs.readAll(path);
|
|
112 |
main.loadChart(g);
|
|
113 |
main.redraw();
|
|
114 |
} catch (IOException e1) {
|
|
115 |
e1.printStackTrace();
|
|
116 |
return;
|
|
117 |
} finally {
|
|
118 |
fs.removeSink(g);
|
|
119 |
}
|
|
120 |
}
|
84 |
121 |
} catch (IOException e1) {
|
|
122 |
// TODO Auto-generated catch block
|
85 |
123 |
e1.printStackTrace();
|
86 |
|
return;
|
87 |
|
} finally {
|
88 |
|
fs.removeSink(g);
|
89 |
124 |
}
|
90 |
|
main.loadChart(g);
|
91 |
125 |
}
|
92 |
|
|
|
126 |
|
93 |
127 |
@Override
|
94 |
128 |
public void widgetDefaultSelected(SelectionEvent e) { }
|
95 |
129 |
});
|