]> gerrit.simantics Code Review - simantics/platform.git/blob - 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
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.debug.ui;\r
13 \r
14 import org.eclipse.jface.action.Action;\r
15 import org.eclipse.jface.action.IToolBarManager;\r
16 import org.eclipse.jface.action.Separator;\r
17 import org.eclipse.swt.SWT;\r
18 import org.eclipse.swt.widgets.Composite;\r
19 import org.eclipse.ui.IActionBars;\r
20 import org.eclipse.ui.ISharedImages;\r
21 import org.eclipse.ui.PlatformUI;\r
22 import org.eclipse.ui.part.ViewPart;\r
23 import org.simantics.db.Resource;\r
24 import org.simantics.db.Session;\r
25 import org.simantics.db.common.uri.ResourceToPossibleURI;\r
26 import org.simantics.db.common.uri.ResourceToURI;\r
27 import org.simantics.db.common.utils.Logger;\r
28 import org.simantics.db.exception.DatabaseException;\r
29 import org.simantics.ui.SimanticsUI;\r
30 import org.simantics.ui.workbench.ResourceInput;\r
31 import org.simantics.utils.ui.BundleUtils;\r
32 import org.simantics.utils.ui.ErrorLogger;\r
33 import org.simantics.utils.ui.LayoutUtils;\r
34 \r
35 public class VariableDebuggerView extends ViewPart {\r
36 \r
37     public static final String VIEW_ID              = "org.simantics.debug.variableDebugger";\r
38 \r
39     private ResourceInput      input;\r
40 \r
41     private Session            session;\r
42 \r
43     private VariableDebugger   debugger;\r
44 \r
45     private Action             backAction;\r
46     private Action             forwardAction;\r
47     private Action             refreshAction;\r
48     private Action             homeAction;\r
49 \r
50     @Override\r
51     public void createPartControl(Composite parent) {\r
52 \r
53         session = SimanticsUI.getSession();\r
54 \r
55         // Initialize input\r
56         String sid = getViewSite().getSecondaryId();\r
57         Resource r = null;\r
58         if (sid != null) {\r
59             input = ResourceInput.unmarshall(sid);\r
60             try {\r
61                 r = input.toResource(session);\r
62             } catch (DatabaseException e) {\r
63                 ErrorLogger.defaultLogError(e);\r
64             }\r
65         }\r
66         \r
67         // Create UI\r
68         parent.setLayout(LayoutUtils.createNoBorderGridLayout(1));\r
69         String initialURI = null;\r
70         try {\r
71                 if(r != null)\r
72                         initialURI = session.sync(new ResourceToPossibleURI(r));\r
73         } catch (Throwable e) {\r
74         }\r
75         debugger = new VariableDebugger(parent, SWT.NONE, session, initialURI);\r
76         debugger.defaultInitializeUI();\r
77 \r
78         // Contribute actions\r
79         makeActions();\r
80         contributeActions(getViewSite().getActionBars());\r
81         updateActionStates();\r
82     }\r
83 \r
84     @Override\r
85     public void dispose() {\r
86         super.dispose();\r
87     }\r
88 \r
89     private void makeActions() {\r
90         backAction = new BackAction();\r
91         forwardAction = new ForwardAction();\r
92         refreshAction = new RefreshAction();\r
93         homeAction = new HomeAction();\r
94     }\r
95 \r
96     private void contributeActions(IActionBars actionBars) {\r
97         IToolBarManager toolBar = actionBars.getToolBarManager();\r
98         toolBar.add(backAction);\r
99         toolBar.add(forwardAction);\r
100         toolBar.add(new Separator());\r
101         toolBar.add(refreshAction);\r
102         toolBar.add(homeAction);\r
103     }\r
104 \r
105     @Override\r
106     public void setFocus() {\r
107         if (debugger != null)\r
108             debugger.setFocus();\r
109     }\r
110 \r
111     private void refreshBrowser() {\r
112         debugger.refreshBrowser();\r
113     }\r
114 //\r
115     class RefreshAction extends Action {\r
116         public RefreshAction() {\r
117             super("Refresh", BundleUtils.getImageDescriptorFromPlugin(SimanticsUI.PLUGIN_ID, "icons/refresh.gif"));\r
118         }\r
119         @Override\r
120         public void run() {\r
121             refreshBrowser();\r
122         }\r
123     }\r
124 \r
125     class BackAction extends Action {\r
126         public BackAction() {\r
127             super("Back", Action.AS_PUSH_BUTTON);\r
128             setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_BACK));\r
129             setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_BACK_DISABLED));\r
130         }\r
131         @Override\r
132         public void run() {\r
133             back();\r
134         }\r
135     }\r
136 \r
137     class ForwardAction extends Action {\r
138         public ForwardAction() {\r
139             super("Forward", Action.AS_PUSH_BUTTON);\r
140             setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_FORWARD));\r
141             setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_FORWARD_DISABLED));\r
142         }\r
143         @Override\r
144         public void run() {\r
145             forward();\r
146         }\r
147     }\r
148 \r
149     class HomeAction extends Action {\r
150         public HomeAction() {\r
151             super("Home", Action.AS_PUSH_BUTTON);\r
152             setToolTipText("Navigate to root library");\r
153             setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_ETOOL_HOME_NAV));\r
154             setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_ETOOL_HOME_NAV_DISABLED));\r
155         }\r
156         @Override\r
157         public void run() {\r
158             navigateHome();\r
159         }\r
160     }\r
161 \r
162     private void back() {\r
163         debugger.back();\r
164     }\r
165 \r
166     private void forward() {\r
167         debugger.forward();\r
168     }\r
169 \r
170     private void navigateHome() {\r
171         Resource rootLibrary = session.getRootLibrary();\r
172         try {\r
173             debugger.changeLocation(session.sync(new ResourceToURI(rootLibrary)));\r
174         } catch (DatabaseException e) {\r
175             Logger.defaultLogError(e);\r
176         }\r
177     }\r
178 \r
179     private void updateActionStates() {\r
180         backAction.setEnabled(debugger.hasBackHistory());\r
181         forwardAction.setEnabled(debugger.hasForwardHistory());\r
182     }\r
183 \r
184 }\r