]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/VariableDebuggerView.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.debug.ui / src / org / simantics / debug / ui / VariableDebuggerView.java
diff --git a/bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/VariableDebuggerView.java b/bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/VariableDebuggerView.java
new file mode 100644 (file)
index 0000000..7fc66f7
--- /dev/null
@@ -0,0 +1,184 @@
+/*******************************************************************************\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 org.eclipse.jface.action.Action;\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.db.Resource;\r
+import org.simantics.db.Session;\r
+import org.simantics.db.common.uri.ResourceToPossibleURI;\r
+import org.simantics.db.common.uri.ResourceToURI;\r
+import org.simantics.db.common.utils.Logger;\r
+import org.simantics.db.exception.DatabaseException;\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 VariableDebuggerView extends ViewPart {\r
+\r
+    public static final String VIEW_ID              = "org.simantics.debug.variableDebugger";\r
+\r
+    private ResourceInput      input;\r
+\r
+    private Session            session;\r
+\r
+    private VariableDebugger   debugger;\r
+\r
+    private Action             backAction;\r
+    private Action             forwardAction;\r
+    private Action             refreshAction;\r
+    private Action             homeAction;\r
+\r
+    @Override\r
+    public void createPartControl(Composite parent) {\r
+\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
+        String initialURI = null;\r
+        try {\r
+               if(r != null)\r
+                       initialURI = session.sync(new ResourceToPossibleURI(r));\r
+        } catch (Throwable e) {\r
+        }\r
+        debugger = new VariableDebugger(parent, SWT.NONE, session, initialURI);\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
+        backAction = new BackAction();\r
+        forwardAction = new ForwardAction();\r
+        refreshAction = new RefreshAction();\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(homeAction);\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 RefreshAction extends Action {\r
+        public RefreshAction() {\r
+            super("Refresh", BundleUtils.getImageDescriptorFromPlugin(SimanticsUI.PLUGIN_ID, "icons/refresh.gif"));\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
+            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
+            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
+    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
+        try {\r
+            debugger.changeLocation(session.sync(new ResourceToURI(rootLibrary)));\r
+        } catch (DatabaseException e) {\r
+            Logger.defaultLogError(e);\r
+        }\r
+    }\r
+\r
+    private void updateActionStates() {\r
+        backAction.setEnabled(debugger.hasBackHistory());\r
+        forwardAction.setEnabled(debugger.hasForwardHistory());\r
+    }\r
+\r
+}\r