]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/GraphDebuggerView.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.debug.ui / src / org / simantics / debug / ui / GraphDebuggerView.java
index 31745691ea813c29736cde62ac73484840cc069a..1840d2e62aa7f2377bcc143ea053cdb97562b509 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
- *     Semantum Oy - index based searching and graph manipulation (#4255)\r
- *******************************************************************************/\r
-package org.simantics.debug.ui;\r
-\r
-import org.eclipse.core.runtime.IStatus;\r
-import org.eclipse.core.runtime.Status;\r
-import org.eclipse.jface.action.Action;\r
-import org.eclipse.jface.action.IAction;\r
-import org.eclipse.jface.action.IToolBarManager;\r
-import org.eclipse.jface.action.Separator;\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.widgets.Composite;\r
-import org.eclipse.ui.IActionBars;\r
-import org.eclipse.ui.ISharedImages;\r
-import org.eclipse.ui.PlatformUI;\r
-import org.eclipse.ui.part.ViewPart;\r
-import org.simantics.Simantics;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.Session;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.debug.ui.internal.Activator;\r
-import org.simantics.debug.ui.internal.DebugUtils;\r
-import org.simantics.ui.SimanticsUI;\r
-import org.simantics.ui.workbench.ResourceInput;\r
-import org.simantics.utils.ui.BundleUtils;\r
-import org.simantics.utils.ui.ErrorLogger;\r
-import org.simantics.utils.ui.LayoutUtils;\r
-\r
-public class GraphDebuggerView extends ViewPart {\r
-\r
-    public static final String VIEW_ID              = "org.simantics.debug.graphDebugger";\r
-\r
-//    private final boolean      DEFAULT_RECYCLE_VIEW = true;\r
-\r
-    private ResourceInput      input;\r
-\r
-    private Session            session;\r
-\r
-    private GraphDebugger      debugger;\r
-\r
-//    private IAction            recycleToggle;\r
-    private IAction            backAction;\r
-    private IAction            forwardAction;\r
-    private IAction            refreshAction;\r
-    private IAction            findAction;\r
-    private IAction            addStatementAction;\r
-    private IAction            addResourceAction;\r
-    private IAction            homeAction;\r
-\r
-    @Override\r
-    public void createPartControl(Composite parent) {\r
-//      System.out.println("koss: " + getViewSite().getSecondaryId());\r
-        session = SimanticsUI.getSession();\r
-\r
-        // Initialize input\r
-        String sid = getViewSite().getSecondaryId();\r
-        Resource r = null;\r
-        if (sid != null) {\r
-            input = ResourceInput.unmarshall(sid);\r
-            try {\r
-                r = input.toResource(session);\r
-            } catch (DatabaseException e) {\r
-                ErrorLogger.defaultLogError(e);\r
-            }\r
-        }\r
-\r
-        // Create UI\r
-        parent.setLayout(LayoutUtils.createNoBorderGridLayout(1));\r
-        debugger = new GraphDebugger(parent, SWT.NONE, session, r, getSite());\r
-        debugger.defaultInitializeUI();\r
-\r
-        // Contribute actions\r
-        makeActions();\r
-        contributeActions(getViewSite().getActionBars());\r
-        updateActionStates();\r
-    }\r
-\r
-    @Override\r
-    public void dispose() {\r
-        super.dispose();\r
-    }\r
-\r
-    private void makeActions() {\r
-//        recycleToggle = new RecycleToggle();\r
-//        recycleToggle.setChecked(DEFAULT_RECYCLE_VIEW);\r
-\r
-        backAction = new BackAction();\r
-        forwardAction = new ForwardAction();\r
-        refreshAction = new RefreshAction();\r
-        findAction = new FindAction();\r
-        addStatementAction = new AddStatementAction();\r
-        addResourceAction = new AddResourceAction();\r
-        homeAction = new HomeAction();\r
-    }\r
-\r
-    private void contributeActions(IActionBars actionBars) {\r
-        IToolBarManager toolBar = actionBars.getToolBarManager();\r
-        toolBar.add(backAction);\r
-        toolBar.add(forwardAction);\r
-        toolBar.add(new Separator());\r
-        toolBar.add(refreshAction);\r
-        toolBar.add(new Separator());\r
-        toolBar.add(findAction);\r
-        toolBar.add(addStatementAction);\r
-        toolBar.add(addResourceAction);\r
-        toolBar.add(new Separator());\r
-        toolBar.add(homeAction);\r
-\r
-//        toolBar.add(recycleToggle);\r
-    }\r
-\r
-    @Override\r
-    public void setFocus() {\r
-        if (debugger != null)\r
-            debugger.setFocus();\r
-    }\r
-\r
-    private void refreshBrowser() {\r
-        debugger.refreshBrowser();\r
-    }\r
-\r
-//    class RecycleToggle extends Action {\r
-//        public RecycleToggle() {\r
-//            super("Open New Views", Action.AS_CHECK_BOX);\r
-//            setImageDescriptor(Activator.getImageDescriptor("icons/reload.gif"));\r
-//            setToolTipText("Toggles whether or not to open new views when resource links are clicked.");\r
-//        }\r
-//    }\r
-//\r
-    class RefreshAction extends Action {\r
-        public RefreshAction() {\r
-            super("Refresh", BundleUtils.getImageDescriptorFromPlugin(SimanticsUI.PLUGIN_ID, "icons/refresh.gif"));\r
-            setToolTipText("Refresh");\r
-        }\r
-        @Override\r
-        public void run() {\r
-            refreshBrowser();\r
-        }\r
-    }\r
-\r
-    class BackAction extends Action {\r
-        public BackAction() {\r
-            super("Back", Action.AS_PUSH_BUTTON);\r
-            setToolTipText("Back");\r
-            setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_BACK));\r
-            setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_BACK_DISABLED));\r
-        }\r
-        @Override\r
-        public void run() {\r
-            back();\r
-        }\r
-    }\r
-\r
-    class ForwardAction extends Action {\r
-        public ForwardAction() {\r
-            super("Forward", Action.AS_PUSH_BUTTON);\r
-            setToolTipText("Forward");\r
-            setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_FORWARD));\r
-            setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_FORWARD_DISABLED));\r
-        }\r
-        @Override\r
-        public void run() {\r
-            forward();\r
-        }\r
-    }\r
-\r
-    class HomeAction extends Action {\r
-        public HomeAction() {\r
-            super("Home", Action.AS_PUSH_BUTTON);\r
-            setToolTipText("Navigate to root library");\r
-            setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_ETOOL_HOME_NAV));\r
-            setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_ETOOL_HOME_NAV_DISABLED));\r
-        }\r
-        @Override\r
-        public void run() {\r
-            navigateHome();\r
-        }\r
-    }\r
-\r
-    class FindAction extends Action {\r
-        public FindAction() {\r
-            super("Find", BundleUtils.getImageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/cog_blue.png"));\r
-            setToolTipText("Find Resource");\r
-        }\r
-        @Override\r
-        public void run() {\r
-            DebugUtils.find(Simantics.getSession(), debugger);\r
-        }\r
-    }\r
-\r
-    class AddStatementAction extends Action {\r
-        public AddStatementAction() {\r
-            super("AddStatement", BundleUtils.getImageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/cog_add.png"));\r
-            setToolTipText("Add Statement Between Existing Resources");\r
-        }\r
-        @Override\r
-        public void run() {\r
-            try {\r
-                DebugUtils.addStatement(Simantics.getSession(), debugger);\r
-            } catch (DatabaseException e) {\r
-                Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e));\r
-            }\r
-        }\r
-    }\r
-\r
-    class AddResourceAction extends Action {\r
-        public AddResourceAction() {\r
-            super("AddResource", BundleUtils.getImageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/cog_add.png"));\r
-            setToolTipText("Add New Related Resource");\r
-        }\r
-        @Override\r
-        public void run() {\r
-            try {\r
-                DebugUtils.addResource(Simantics.getSession(), debugger);\r
-            } catch (DatabaseException e) {\r
-                Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e));\r
-            }\r
-        }\r
-    }\r
-\r
-    private void back() {\r
-        debugger.back();\r
-    }\r
-\r
-    private void forward() {\r
-        debugger.forward();\r
-    }\r
-\r
-    private void navigateHome() {\r
-        Resource rootLibrary = session.getRootLibrary();\r
-        debugger.changeLocation(rootLibrary);\r
-    }\r
-\r
-    private void updateActionStates() {\r
-        backAction.setEnabled(debugger.hasBackHistory());\r
-        forwardAction.setEnabled(debugger.hasForwardHistory());\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
+ *     Semantum Oy - index based searching and graph manipulation (#4255)
+ *******************************************************************************/
+package org.simantics.debug.ui;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.ISharedImages;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.part.ViewPart;
+import org.simantics.Simantics;
+import org.simantics.db.Resource;
+import org.simantics.db.Session;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.debug.ui.internal.Activator;
+import org.simantics.debug.ui.internal.DebugUtils;
+import org.simantics.ui.SimanticsUI;
+import org.simantics.ui.workbench.ResourceInput;
+import org.simantics.utils.ui.BundleUtils;
+import org.simantics.utils.ui.ErrorLogger;
+import org.simantics.utils.ui.LayoutUtils;
+
+public class GraphDebuggerView extends ViewPart {
+
+    public static final String VIEW_ID              = "org.simantics.debug.graphDebugger";
+
+//    private final boolean      DEFAULT_RECYCLE_VIEW = true;
+
+    private ResourceInput      input;
+
+    private Session            session;
+
+    private GraphDebugger      debugger;
+
+//    private IAction            recycleToggle;
+    private IAction            backAction;
+    private IAction            forwardAction;
+    private IAction            refreshAction;
+    private IAction            findAction;
+    private IAction            addStatementAction;
+    private IAction            addResourceAction;
+    private IAction            homeAction;
+
+    @Override
+    public void createPartControl(Composite parent) {
+//      System.out.println("koss: " + getViewSite().getSecondaryId());
+        session = SimanticsUI.getSession();
+
+        // Initialize input
+        String sid = getViewSite().getSecondaryId();
+        Resource r = null;
+        if (sid != null) {
+            input = ResourceInput.unmarshall(sid);
+            try {
+                r = input.toResource(session);
+            } catch (DatabaseException e) {
+                ErrorLogger.defaultLogError(e);
+            }
+        }
+
+        // Create UI
+        parent.setLayout(LayoutUtils.createNoBorderGridLayout(1));
+        debugger = new GraphDebugger(parent, SWT.NONE, session, r, getSite());
+        debugger.defaultInitializeUI();
+
+        // Contribute actions
+        makeActions();
+        contributeActions(getViewSite().getActionBars());
+        updateActionStates();
+    }
+
+    @Override
+    public void dispose() {
+        super.dispose();
+    }
+
+    private void makeActions() {
+//        recycleToggle = new RecycleToggle();
+//        recycleToggle.setChecked(DEFAULT_RECYCLE_VIEW);
+
+        backAction = new BackAction();
+        forwardAction = new ForwardAction();
+        refreshAction = new RefreshAction();
+        findAction = new FindAction();
+        addStatementAction = new AddStatementAction();
+        addResourceAction = new AddResourceAction();
+        homeAction = new HomeAction();
+    }
+
+    private void contributeActions(IActionBars actionBars) {
+        IToolBarManager toolBar = actionBars.getToolBarManager();
+        toolBar.add(backAction);
+        toolBar.add(forwardAction);
+        toolBar.add(new Separator());
+        toolBar.add(refreshAction);
+        toolBar.add(new Separator());
+        toolBar.add(findAction);
+        toolBar.add(addStatementAction);
+        toolBar.add(addResourceAction);
+        toolBar.add(new Separator());
+        toolBar.add(homeAction);
+
+//        toolBar.add(recycleToggle);
+    }
+
+    @Override
+    public void setFocus() {
+        if (debugger != null)
+            debugger.setFocus();
+    }
+
+    private void refreshBrowser() {
+        debugger.refreshBrowser();
+    }
+
+//    class RecycleToggle extends Action {
+//        public RecycleToggle() {
+//            super("Open New Views", Action.AS_CHECK_BOX);
+//            setImageDescriptor(Activator.getImageDescriptor("icons/reload.gif"));
+//            setToolTipText("Toggles whether or not to open new views when resource links are clicked.");
+//        }
+//    }
+//
+    class RefreshAction extends Action {
+        public RefreshAction() {
+            super("Refresh", BundleUtils.getImageDescriptorFromPlugin(SimanticsUI.PLUGIN_ID, "icons/refresh.gif"));
+            setToolTipText("Refresh");
+        }
+        @Override
+        public void run() {
+            refreshBrowser();
+        }
+    }
+
+    class BackAction extends Action {
+        public BackAction() {
+            super("Back", Action.AS_PUSH_BUTTON);
+            setToolTipText("Back");
+            setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_BACK));
+            setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_BACK_DISABLED));
+        }
+        @Override
+        public void run() {
+            back();
+        }
+    }
+
+    class ForwardAction extends Action {
+        public ForwardAction() {
+            super("Forward", Action.AS_PUSH_BUTTON);
+            setToolTipText("Forward");
+            setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_FORWARD));
+            setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_FORWARD_DISABLED));
+        }
+        @Override
+        public void run() {
+            forward();
+        }
+    }
+
+    class HomeAction extends Action {
+        public HomeAction() {
+            super("Home", Action.AS_PUSH_BUTTON);
+            setToolTipText("Navigate to root library");
+            setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_ETOOL_HOME_NAV));
+            setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_ETOOL_HOME_NAV_DISABLED));
+        }
+        @Override
+        public void run() {
+            navigateHome();
+        }
+    }
+
+    class FindAction extends Action {
+        public FindAction() {
+            super("Find", BundleUtils.getImageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/cog_blue.png"));
+            setToolTipText("Find Resource");
+        }
+        @Override
+        public void run() {
+            DebugUtils.find(Simantics.getSession(), debugger);
+        }
+    }
+
+    class AddStatementAction extends Action {
+        public AddStatementAction() {
+            super("AddStatement", BundleUtils.getImageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/cog_add.png"));
+            setToolTipText("Add Statement Between Existing Resources");
+        }
+        @Override
+        public void run() {
+            try {
+                DebugUtils.addStatement(Simantics.getSession(), debugger);
+            } catch (DatabaseException e) {
+                Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e));
+            }
+        }
+    }
+
+    class AddResourceAction extends Action {
+        public AddResourceAction() {
+            super("AddResource", BundleUtils.getImageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/cog_add.png"));
+            setToolTipText("Add New Related Resource");
+        }
+        @Override
+        public void run() {
+            try {
+                DebugUtils.addResource(Simantics.getSession(), debugger);
+            } catch (DatabaseException e) {
+                Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e));
+            }
+        }
+    }
+
+    private void back() {
+        debugger.back();
+    }
+
+    private void forward() {
+        debugger.forward();
+    }
+
+    private void navigateHome() {
+        Resource rootLibrary = session.getRootLibrary();
+        debugger.changeLocation(rootLibrary);
+    }
+
+    private void updateActionStates() {
+        backAction.setEnabled(debugger.hasBackHistory());
+        forwardAction.setEnabled(debugger.hasForwardHistory());
+    }
+
+}