]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/SessionDebuggerView.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.debug.ui / src / org / simantics / debug / ui / SessionDebuggerView.java
index 77ff49804c8f7e19c991bff06addf4cb4e32d5d6..0e0363fa87ec842b59a65d9119db15cc2a4a4135 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.debug.ui;\r
-\r
-import java.io.File;\r
-import java.io.IOException;\r
-import java.io.PrintStream;\r
-import java.nio.file.Files;\r
-import java.nio.file.Path;\r
-import java.util.Collections;\r
-import java.util.LinkedList;\r
-import java.util.Set;\r
-\r
-import org.eclipse.core.runtime.IStatus;\r
-import org.eclipse.core.runtime.Status;\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.browser.Browser;\r
-import org.eclipse.swt.custom.CTabFolder;\r
-import org.eclipse.swt.custom.CTabItem;\r
-import org.eclipse.swt.events.KeyAdapter;\r
-import org.eclipse.swt.events.KeyEvent;\r
-import org.eclipse.swt.layout.GridData;\r
-import org.eclipse.swt.widgets.Composite;\r
-import org.eclipse.swt.widgets.Control;\r
-import org.eclipse.swt.widgets.Text;\r
-import org.eclipse.ui.IWorkbenchSite;\r
-import org.simantics.Simantics;\r
-import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
-import org.simantics.db.WriteGraph;\r
-import org.simantics.db.common.request.WriteRequest;\r
-import org.simantics.db.debug.ListenerReport;\r
-import org.simantics.db.exception.CancelTransactionException;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.management.ISessionContext;\r
-import org.simantics.db.service.DebugSupport;\r
-import org.simantics.debug.ui.internal.Activator;\r
-import org.simantics.ui.workbench.IPropertyPage;\r
-import org.simantics.utils.ui.LayoutUtils;\r
-import org.simantics.utils.ui.SWTUtils;\r
-import org.simantics.views.swt.SimanticsView;\r
-\r
-@SuppressWarnings("deprecation")\r
-public class SessionDebuggerView extends SimanticsView {\r
-\r
-    public static final String VIEW_ID = "org.simantics.debug.sessionDebugger";\r
-\r
-    private CTabFolder folder;\r
-    private Text commandLine;\r
-    private Browser console;\r
-\r
-    private final LinkedList<String> terminal = new LinkedList<String>();\r
-    private final LinkedList<String> history = new LinkedList<String>();\r
-    private int historyPosition = -1;\r
-\r
-    @Override\r
-    protected Set<String> getBrowseContexts() {\r
-        return Collections.singleton("");\r
-    }\r
-\r
-    private CTabItem createItem(int index, CTabFolder folder, Control control) {\r
-        CTabItem item = new CTabItem(folder, SWT.NONE, index);\r
-        item.setControl(control);\r
-        return item;\r
-    }\r
-\r
-    @Override\r
-    protected void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) {\r
-\r
-        body.setLayout(LayoutUtils.createNoBorderGridLayout(1));\r
-\r
-        folder = new CTabFolder(body, SWT.BOTTOM | SWT.FLAT);\r
-        folder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));\r
-\r
-        Composite shell = new Composite(folder, SWT.NONE);\r
-        shell.setLayout(LayoutUtils.createNoBorderGridLayout(1));\r
-\r
-        commandLine = new Text(shell, SWT.BORDER);\r
-        commandLine.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));\r
-\r
-        console = new Browser(shell, SWT.BORDER);\r
-        console.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));\r
-\r
-        commandLine.addKeyListener(new KeyAdapter() {\r
-            @Override\r
-            public void keyReleased(KeyEvent e) {\r
-                if (e.keyCode == SWT.ARROW_UP) {\r
-                    if (historyPosition > 10 || historyPosition >= (history.size() - 1)) {\r
-                        return;\r
-                    }\r
-                    commandLine.setText(history.get(++historyPosition));\r
-                } else if (e.keyCode == SWT.ARROW_DOWN) {\r
-                    if (historyPosition < 0) {\r
-                        return;\r
-                    } else if (historyPosition == 0) {\r
-                        commandLine.setText("");\r
-                        historyPosition = -1;\r
-                    } else {\r
-                        commandLine.setText(history.get(--historyPosition));\r
-                    }\r
-                } else if (e.keyCode == SWT.ESC) {\r
-                    historyPosition = -1;\r
-                    commandLine.setText("");\r
-                } else if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) {\r
-                    applyCommand(commandLine.getText());\r
-                }\r
-            }\r
-        });\r
-\r
-        CTabItem shellItem = createItem(0, folder, shell);\r
-        shellItem.setText("Shell");\r
-\r
-//        SessionDebugger deprecated = new SessionDebugger(folder, SWT.NONE, Simantics.getSession());\r
-//        deprecated.initializeUI();\r
-//        CTabItem debuggerItem = createItem(1, folder, deprecated);\r
-//        debuggerItem.setText("Debugger");\r
-\r
-        folder.setSelection(shellItem);\r
-    }\r
-\r
-    private void applyCommand(final String command) {\r
-        try {\r
-            Simantics.getSession().syncRequest(new WriteRequest() {\r
-                @Override\r
-                public void perform(WriteGraph graph) throws DatabaseException {\r
-                    DebugSupport support = graph.getService(DebugSupport.class);\r
-                    Object data = support.query(graph, command);\r
-                    apply(command, data);\r
-                }\r
-            });\r
-        } catch (CancelTransactionException e) {\r
-        } catch (DatabaseException e) {\r
-            Activator.getDefault().getLog().log(\r
-                    new Status(IStatus.ERROR, Activator.PLUGIN_ID,\r
-                            "Unexpected exception while applying command " + command, e));\r
-        }\r
-    }\r
-\r
-    private void addHistory(String command, Object output) {\r
-        if (output instanceof String) {\r
-            terminal.addFirst((String) output);\r
-        } else if (output instanceof Path) {\r
-            try {\r
-                Path p = (Path) output;\r
-                long size = Files.size(p);\r
-                if (size < (1L << 16)) {\r
-                    terminal.addFirst(new String(Files.readAllBytes(p), "UTF-8"));\r
-                }\r
-                terminal.addFirst("Wrote command '" + command + "' output to file " + p);\r
-            } catch (IOException e) {\r
-                Activator.getDefault().getLog().log(\r
-                        new Status(IStatus.ERROR, Activator.PLUGIN_ID,\r
-                                "Unexpected I/O exception while applying command " + command, e));\r
-            }\r
-        } else {\r
-            throw new IllegalArgumentException("Unsupported output argument type " + output);\r
-        }\r
-        if (terminal.size() > 10)\r
-            terminal.removeLast();\r
-\r
-        history.addFirst(command);\r
-        if (history.size() > 10)\r
-            history.removeLast();\r
-\r
-        historyPosition = -1;\r
-    }\r
-\r
-    private void apply(String command, Object data) {\r
-        if (data instanceof String) {\r
-            SWTUtils.asyncExec(commandLine, () -> {\r
-                commandLine.setText("");\r
-                addHistory(command, data);\r
-                console.setText(formatTerminal());\r
-            });\r
-        } else if (data instanceof ListenerReport) {\r
-            SWTUtils.asyncExec(commandLine, () -> {\r
-                try {\r
-                    addHistory(command, dumpListenerReport((ListenerReport) data));\r
-                    commandLine.setText("");\r
-                    console.setText(formatTerminal());\r
-                } catch (IOException e) {\r
-                    Activator.getDefault().getLog().log(\r
-                            new Status(IStatus.ERROR, Activator.PLUGIN_ID,\r
-                                    "Unexpected I/O exception while applying command " + command, e));\r
-                }\r
-            });\r
-        }\r
-    }\r
-\r
-    private Path dumpListenerReport(ListenerReport data) throws IOException {\r
-        File f = Simantics.getTempfile("debug", "listenerReport");\r
-        try (PrintStream out = new PrintStream(f, "UTF-8")) {\r
-            out.print("<pre>");\r
-            data.print(out);\r
-            out.print("</pre>");\r
-        }\r
-        return f.toPath();\r
-    }\r
-\r
-    private String formatTerminal() {\r
-        StringBuilder b = new StringBuilder();\r
-        b.append("<html><head/><body>\n");\r
-        for (String s : terminal)\r
-            b.append(s).append("<br/>\n");\r
-        b.append("</body></html>");\r
-        return b.toString();\r
-    }\r
-\r
-    @Override\r
-    public void setFocus() {\r
-        folder.setFocus();\r
-    }\r
-\r
-    @Override\r
-    protected IPropertyPage getPropertyPage() {\r
-        return null;\r
-    }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.debug.ui;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.Set;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.browser.Browser;
+import org.eclipse.swt.custom.CTabFolder;
+import org.eclipse.swt.custom.CTabItem;
+import org.eclipse.swt.events.KeyAdapter;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.IWorkbenchSite;
+import org.simantics.Simantics;
+import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.request.WriteRequest;
+import org.simantics.db.debug.ListenerReport;
+import org.simantics.db.exception.CancelTransactionException;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.management.ISessionContext;
+import org.simantics.db.service.DebugSupport;
+import org.simantics.debug.ui.internal.Activator;
+import org.simantics.ui.workbench.IPropertyPage;
+import org.simantics.utils.ui.LayoutUtils;
+import org.simantics.utils.ui.SWTUtils;
+import org.simantics.views.swt.SimanticsView;
+
+@SuppressWarnings("deprecation")
+public class SessionDebuggerView extends SimanticsView {
+
+    public static final String VIEW_ID = "org.simantics.debug.sessionDebugger";
+
+    private CTabFolder folder;
+    private Text commandLine;
+    private Browser console;
+
+    private final LinkedList<String> terminal = new LinkedList<String>();
+    private final LinkedList<String> history = new LinkedList<String>();
+    private int historyPosition = -1;
+
+    @Override
+    protected Set<String> getBrowseContexts() {
+        return Collections.singleton("");
+    }
+
+    private CTabItem createItem(int index, CTabFolder folder, Control control) {
+        CTabItem item = new CTabItem(folder, SWT.NONE, index);
+        item.setControl(control);
+        return item;
+    }
+
+    @Override
+    protected void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) {
+
+        body.setLayout(LayoutUtils.createNoBorderGridLayout(1));
+
+        folder = new CTabFolder(body, SWT.BOTTOM | SWT.FLAT);
+        folder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+
+        Composite shell = new Composite(folder, SWT.NONE);
+        shell.setLayout(LayoutUtils.createNoBorderGridLayout(1));
+
+        commandLine = new Text(shell, SWT.BORDER);
+        commandLine.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+
+        console = new Browser(shell, SWT.BORDER);
+        console.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+
+        commandLine.addKeyListener(new KeyAdapter() {
+            @Override
+            public void keyReleased(KeyEvent e) {
+                if (e.keyCode == SWT.ARROW_UP) {
+                    if (historyPosition > 10 || historyPosition >= (history.size() - 1)) {
+                        return;
+                    }
+                    commandLine.setText(history.get(++historyPosition));
+                } else if (e.keyCode == SWT.ARROW_DOWN) {
+                    if (historyPosition < 0) {
+                        return;
+                    } else if (historyPosition == 0) {
+                        commandLine.setText("");
+                        historyPosition = -1;
+                    } else {
+                        commandLine.setText(history.get(--historyPosition));
+                    }
+                } else if (e.keyCode == SWT.ESC) {
+                    historyPosition = -1;
+                    commandLine.setText("");
+                } else if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) {
+                    applyCommand(commandLine.getText());
+                }
+            }
+        });
+
+        CTabItem shellItem = createItem(0, folder, shell);
+        shellItem.setText("Shell");
+
+//        SessionDebugger deprecated = new SessionDebugger(folder, SWT.NONE, Simantics.getSession());
+//        deprecated.initializeUI();
+//        CTabItem debuggerItem = createItem(1, folder, deprecated);
+//        debuggerItem.setText("Debugger");
+
+        folder.setSelection(shellItem);
+    }
+
+    private void applyCommand(final String command) {
+        try {
+            Simantics.getSession().syncRequest(new WriteRequest() {
+                @Override
+                public void perform(WriteGraph graph) throws DatabaseException {
+                    DebugSupport support = graph.getService(DebugSupport.class);
+                    Object data = support.query(graph, command);
+                    apply(command, data);
+                }
+            });
+        } catch (CancelTransactionException e) {
+        } catch (DatabaseException e) {
+            Activator.getDefault().getLog().log(
+                    new Status(IStatus.ERROR, Activator.PLUGIN_ID,
+                            "Unexpected exception while applying command " + command, e));
+        }
+    }
+
+    private void addHistory(String command, Object output) {
+        if (output instanceof String) {
+            terminal.addFirst((String) output);
+        } else if (output instanceof Path) {
+            try {
+                Path p = (Path) output;
+                long size = Files.size(p);
+                if (size < (1L << 16)) {
+                    terminal.addFirst(new String(Files.readAllBytes(p), "UTF-8"));
+                }
+                terminal.addFirst("Wrote command '" + command + "' output to file " + p);
+            } catch (IOException e) {
+                Activator.getDefault().getLog().log(
+                        new Status(IStatus.ERROR, Activator.PLUGIN_ID,
+                                "Unexpected I/O exception while applying command " + command, e));
+            }
+        } else {
+            throw new IllegalArgumentException("Unsupported output argument type " + output);
+        }
+        if (terminal.size() > 10)
+            terminal.removeLast();
+
+        history.addFirst(command);
+        if (history.size() > 10)
+            history.removeLast();
+
+        historyPosition = -1;
+    }
+
+    private void apply(String command, Object data) {
+        if (data instanceof String) {
+            SWTUtils.asyncExec(commandLine, () -> {
+                commandLine.setText("");
+                addHistory(command, data);
+                console.setText(formatTerminal());
+            });
+        } else if (data instanceof ListenerReport) {
+            SWTUtils.asyncExec(commandLine, () -> {
+                try {
+                    addHistory(command, dumpListenerReport((ListenerReport) data));
+                    commandLine.setText("");
+                    console.setText(formatTerminal());
+                } catch (IOException e) {
+                    Activator.getDefault().getLog().log(
+                            new Status(IStatus.ERROR, Activator.PLUGIN_ID,
+                                    "Unexpected I/O exception while applying command " + command, e));
+                }
+            });
+        }
+    }
+
+    private Path dumpListenerReport(ListenerReport data) throws IOException {
+        File f = Simantics.getTempfile("debug", "listenerReport");
+        try (PrintStream out = new PrintStream(f, "UTF-8")) {
+            out.print("<pre>");
+            data.print(out);
+            out.print("</pre>");
+        }
+        return f.toPath();
+    }
+
+    private String formatTerminal() {
+        StringBuilder b = new StringBuilder();
+        b.append("<html><head/><body>\n");
+        for (String s : terminal)
+            b.append(s).append("<br/>\n");
+        b.append("</body></html>");
+        return b.toString();
+    }
+
+    @Override
+    public void setFocus() {
+        folder.setFocus();
+    }
+
+    @Override
+    protected IPropertyPage getPropertyPage() {
+        return null;
+    }
+
+}