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
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.debug.ui;
\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
35 public class VariableDebuggerView extends ViewPart {
\r
37 public static final String VIEW_ID = "org.simantics.debug.variableDebugger";
\r
39 private ResourceInput input;
\r
41 private Session session;
\r
43 private VariableDebugger debugger;
\r
45 private Action backAction;
\r
46 private Action forwardAction;
\r
47 private Action refreshAction;
\r
48 private Action homeAction;
\r
51 public void createPartControl(Composite parent) {
\r
53 session = SimanticsUI.getSession();
\r
56 String sid = getViewSite().getSecondaryId();
\r
59 input = ResourceInput.unmarshall(sid);
\r
61 r = input.toResource(session);
\r
62 } catch (DatabaseException e) {
\r
63 ErrorLogger.defaultLogError(e);
\r
68 parent.setLayout(LayoutUtils.createNoBorderGridLayout(1));
\r
69 String initialURI = null;
\r
72 initialURI = session.sync(new ResourceToPossibleURI(r));
\r
73 } catch (Throwable e) {
\r
75 debugger = new VariableDebugger(parent, SWT.NONE, session, initialURI);
\r
76 debugger.defaultInitializeUI();
\r
78 // Contribute actions
\r
80 contributeActions(getViewSite().getActionBars());
\r
81 updateActionStates();
\r
85 public void dispose() {
\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
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
106 public void setFocus() {
\r
107 if (debugger != null)
\r
108 debugger.setFocus();
\r
111 private void refreshBrowser() {
\r
112 debugger.refreshBrowser();
\r
115 class RefreshAction extends Action {
\r
116 public RefreshAction() {
\r
117 super("Refresh", BundleUtils.getImageDescriptorFromPlugin(SimanticsUI.PLUGIN_ID, "icons/refresh.gif"));
\r
120 public void run() {
\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
132 public void run() {
\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
144 public void run() {
\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
157 public void run() {
\r
162 private void back() {
\r
166 private void forward() {
\r
167 debugger.forward();
\r
170 private void navigateHome() {
\r
171 Resource rootLibrary = session.getRootLibrary();
\r
173 debugger.changeLocation(session.sync(new ResourceToURI(rootLibrary)));
\r
174 } catch (DatabaseException e) {
\r
175 Logger.defaultLogError(e);
\r
179 private void updateActionStates() {
\r
180 backAction.setEnabled(debugger.hasBackHistory());
\r
181 forwardAction.setEnabled(debugger.hasForwardHistory());
\r