Révision 2699
| tmp/org.txm.chartsengine.graphstream.rcp/plugin.xml (revision 2699) | ||
|---|---|---|
| 9 | 9 |
name="GS SWT Charts Components Provider"> |
| 10 | 10 |
</SWTChartsComponentsProvider> |
| 11 | 11 |
</extension> |
| 12 |
<extension |
|
| 13 |
point="org.eclipse.ui.commands"> |
|
| 14 |
<command |
|
| 15 |
defaultHandler="org.txm.chartsengine.graphstream.rcp.handler.OpenGraphFile" |
|
| 16 |
id="org.txm.chartsengine.graphstream.rcp.handler.OpenGraphFile" |
|
| 17 |
name="Open Graph file..."> |
|
| 18 |
</command> |
|
| 19 |
</extension> |
|
| 20 |
<extension |
|
| 21 |
point="org.eclipse.ui.menus"> |
|
| 22 |
<menuContribution |
|
| 23 |
locationURI="menu:menu.file"> |
|
| 24 |
<command |
|
| 25 |
commandId="org.txm.chartsengine.graphstream.rcp.handler.OpenGraphFile" |
|
| 26 |
icon="icons/graph.png" |
|
| 27 |
style="push" |
|
| 28 |
tooltip="Open a Graph file (dot)"> |
|
| 29 |
</command> |
|
| 30 |
</menuContribution> |
|
| 31 |
</extension> |
|
| 32 |
<extension |
|
| 33 |
point="org.eclipse.ui.editors"> |
|
| 34 |
<editor |
|
| 35 |
class="org.txm.chartsengine.graphstream.rcp.editor.GSEditor" |
|
| 36 |
default="false" |
|
| 37 |
icon="icons/graph.png" |
|
| 38 |
id="org.txm.chartsengine.graphstream.rcp.editor.GSEditor" |
|
| 39 |
name="Graph"> |
|
| 40 |
</editor> |
|
| 41 |
</extension> |
|
| 12 | 42 |
|
| 13 | 43 |
</plugin> |
| tmp/org.txm.chartsengine.graphstream.rcp/src/org/txm/chartsengine/graphstream/rcp/editor/GSEditor.java (revision 2699) | ||
|---|---|---|
| 1 |
package org.txm.chartsengine.graphstream.rcp.editor; |
|
| 2 |
|
|
| 3 |
import java.io.File; |
|
| 4 |
import java.io.IOException; |
|
| 5 |
|
|
| 6 |
import org.eclipse.core.runtime.IProgressMonitor; |
|
| 7 |
import org.eclipse.swt.SWT; |
|
| 8 |
import org.eclipse.swt.events.SelectionEvent; |
|
| 9 |
import org.eclipse.swt.events.SelectionListener; |
|
| 10 |
import org.eclipse.swt.layout.GridData; |
|
| 11 |
import org.eclipse.swt.layout.GridLayout; |
|
| 12 |
import org.eclipse.swt.widgets.Button; |
|
| 13 |
import org.eclipse.swt.widgets.Composite; |
|
| 14 |
import org.eclipse.swt.widgets.FileDialog; |
|
| 15 |
import org.eclipse.ui.IEditorInput; |
|
| 16 |
import org.eclipse.ui.IEditorSite; |
|
| 17 |
import org.eclipse.ui.PartInitException; |
|
| 18 |
import org.eclipse.ui.part.EditorPart; |
|
| 19 |
import org.graphstream.graph.Graph; |
|
| 20 |
import org.graphstream.graph.implementations.DefaultGraph; |
|
| 21 |
import org.graphstream.stream.file.FileSourceDOT; |
|
| 22 |
import org.txm.chartsengine.graphstream.rcp.swt.GSComposite; |
|
| 23 |
|
|
| 24 |
public class GSEditor extends EditorPart {
|
|
| 25 |
|
|
| 26 |
private GSComposite main; |
|
| 27 |
private Button loadButton; |
|
| 28 |
|
|
| 29 |
public GSEditor() {
|
|
| 30 |
// TODO Auto-generated constructor stub |
|
| 31 |
} |
|
| 32 |
|
|
| 33 |
@Override |
|
| 34 |
public void doSave(IProgressMonitor monitor) {
|
|
| 35 |
// TODO Auto-generated method stub |
|
| 36 |
|
|
| 37 |
} |
|
| 38 |
|
|
| 39 |
@Override |
|
| 40 |
public void doSaveAs() {
|
|
| 41 |
// TODO Auto-generated method stub |
|
| 42 |
|
|
| 43 |
} |
|
| 44 |
|
|
| 45 |
@Override |
|
| 46 |
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
|
|
| 47 |
this.setSite(site); |
|
| 48 |
this.setInput(input); |
|
| 49 |
} |
|
| 50 |
|
|
| 51 |
@Override |
|
| 52 |
public boolean isDirty() {
|
|
| 53 |
return false; |
|
| 54 |
} |
|
| 55 |
|
|
| 56 |
@Override |
|
| 57 |
public boolean isSaveAsAllowed() {
|
|
| 58 |
return false; |
|
| 59 |
} |
|
| 60 |
|
|
| 61 |
@Override |
|
| 62 |
public void createPartControl(Composite parent) {
|
|
| 63 |
parent.setLayout(new GridLayout(2, true)); |
|
| 64 |
|
|
| 65 |
loadButton = new Button(parent, SWT.PUSH); |
|
| 66 |
loadButton.setText("Load Graph file...");
|
|
| 67 |
loadButton.addSelectionListener(new SelectionListener() {
|
|
| 68 |
|
|
| 69 |
@Override |
|
| 70 |
public void widgetSelected(SelectionEvent e) {
|
|
| 71 |
|
|
| 72 |
FileDialog dialog = new FileDialog(e.display.getActiveShell(), SWT.OPEN); |
|
| 73 |
dialog.setFilterExtensions(new String[] {"*.dot"});
|
|
| 74 |
String path = dialog.open(); |
|
| 75 |
if (path == null) {
|
|
| 76 |
return; |
|
| 77 |
} |
|
| 78 |
|
|
| 79 |
Graph g = new DefaultGraph("g"); //$NON-NLS-1$
|
|
| 80 |
FileSourceDOT fs = new FileSourceDOT(); |
|
| 81 |
fs.addSink(g); |
|
| 82 |
try {
|
|
| 83 |
fs.readAll(path); |
|
| 84 |
} catch (IOException e1) {
|
|
| 85 |
e1.printStackTrace(); |
|
| 86 |
return; |
|
| 87 |
} finally {
|
|
| 88 |
fs.removeSink(g); |
|
| 89 |
} |
|
| 90 |
main.loadChart(g); |
|
| 91 |
} |
|
| 92 |
|
|
| 93 |
@Override |
|
| 94 |
public void widgetDefaultSelected(SelectionEvent e) { }
|
|
| 95 |
}); |
|
| 96 |
main = new GSComposite(null, parent); |
|
| 97 |
main.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true)); |
|
| 98 |
} |
|
| 99 |
|
|
| 100 |
@Override |
|
| 101 |
public void setFocus() {
|
|
| 102 |
loadButton.setFocus(); |
|
| 103 |
} |
|
| 104 |
} |
|
| 0 | 105 | |
| tmp/org.txm.chartsengine.graphstream.rcp/src/org/txm/chartsengine/graphstream/rcp/handler/OpenGraphFile.java (revision 2699) | ||
|---|---|---|
| 1 |
package org.txm.chartsengine.graphstream.rcp.handler; |
|
| 2 |
|
|
| 3 |
import java.io.File; |
|
| 4 |
|
|
| 5 |
import org.eclipse.core.commands.ExecutionEvent; |
|
| 6 |
import org.eclipse.core.commands.ExecutionException; |
|
| 7 |
import org.eclipse.core.filesystem.EFS; |
|
| 8 |
import org.eclipse.core.filesystem.IFileStore; |
|
| 9 |
import org.eclipse.swt.SWT; |
|
| 10 |
import org.eclipse.swt.widgets.FileDialog; |
|
| 11 |
import org.eclipse.swt.widgets.Shell; |
|
| 12 |
import org.eclipse.ui.IEditorPart; |
|
| 13 |
import org.eclipse.ui.IWorkbenchPage; |
|
| 14 |
import org.eclipse.ui.IWorkbenchWindow; |
|
| 15 |
import org.eclipse.ui.PartInitException; |
|
| 16 |
import org.eclipse.ui.handlers.HandlerUtil; |
|
| 17 |
import org.eclipse.ui.ide.FileStoreEditorInput; |
|
| 18 |
import org.txm.Toolbox; |
|
| 19 |
import org.txm.chartsengine.graphstream.rcp.editor.GSEditor; |
|
| 20 |
import org.txm.rcp.TXMWindows; |
|
| 21 |
import org.txm.rcp.handlers.BaseAbstractHandler; |
|
| 22 |
import org.txm.rcp.swt.dialog.LastOpened; |
|
| 23 |
|
|
| 24 |
public class OpenGraphFile extends BaseAbstractHandler {
|
|
| 25 |
|
|
| 26 |
public static String ID = OpenGraphFile.class.getName(); |
|
| 27 |
@Override |
|
| 28 |
public Object execute(ExecutionEvent event) throws ExecutionException {
|
|
| 29 |
|
|
| 30 |
Shell shell = HandlerUtil.getActiveWorkbenchWindowChecked(event).getShell(); |
|
| 31 |
String txmhome = Toolbox.getTxmHomePath(); |
|
| 32 |
|
|
| 33 |
FileDialog dialog = new FileDialog(shell, SWT.OPEN); |
|
| 34 |
if (LastOpened.getFile(ID) != null) {
|
|
| 35 |
dialog.setFilterPath(LastOpened.getFolder(ID)); |
|
| 36 |
dialog.setFileName(LastOpened.getFile(ID)); |
|
| 37 |
} else {
|
|
| 38 |
dialog.setFilterPath(txmhome); |
|
| 39 |
} |
|
| 40 |
if (dialog.open() == null) return null; |
|
| 41 |
String filepath = dialog.getFilterPath() + "/" + dialog.getFileName(); //$NON-NLS-1$ |
|
| 42 |
LastOpened.set(ID, dialog.getFilterPath(), dialog.getFileName()); |
|
| 43 |
|
|
| 44 |
try {
|
|
| 45 |
return open(new File(filepath)); |
|
| 46 |
} catch (PartInitException e) {
|
|
| 47 |
// TODO Auto-generated catch block |
|
| 48 |
e.printStackTrace(); |
|
| 49 |
return null; |
|
| 50 |
} |
|
| 51 |
} |
|
| 52 |
|
|
| 53 |
public static GSEditor open(File graphFile) throws PartInitException {
|
|
| 54 |
IWorkbenchWindow window = TXMWindows.getActiveWindow(); |
|
| 55 |
IWorkbenchPage page = window.getActivePage(); |
|
| 56 |
|
|
| 57 |
IFileStore fileOnLocalDisk = EFS.getLocalFileSystem().getStore(graphFile.toURI()); |
|
| 58 |
|
|
| 59 |
FileStoreEditorInput editorInput = new FileStoreEditorInput(fileOnLocalDisk); |
|
| 60 |
|
|
| 61 |
IEditorPart editor = page.openEditor(editorInput, GSEditor.class.getName(), true, IWorkbenchPage.MATCH_INPUT | IWorkbenchPage.MATCH_ID); |
|
| 62 |
if (editor != null && editor instanceof GSEditor) {
|
|
| 63 |
return (GSEditor)editor; |
|
| 64 |
} else {
|
|
| 65 |
return null; |
|
| 66 |
} |
|
| 67 |
} |
|
| 68 |
} |
|
| 0 | 69 | |
Formats disponibles : Unified diff