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