1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.debug.ui;
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;
36 public class VariableDebuggerView extends ViewPart {
38 public static final String VIEW_ID = "org.simantics.debug.variableDebugger";
40 private ResourceInput input;
42 private Session session;
44 private VariableDebugger debugger;
46 private Action backAction;
47 private Action forwardAction;
48 private Action refreshAction;
49 private Action homeAction;
52 public void createPartControl(Composite parent) {
54 session = Simantics.getSession();
57 String sid = getViewSite().getSecondaryId();
60 input = ResourceInput.unmarshall(sid);
62 r = input.toResource(session);
63 } catch (DatabaseException e) {
64 ErrorLogger.defaultLogError(e);
69 parent.setLayout(LayoutUtils.createNoBorderGridLayout(1));
70 String initialURI = null;
73 initialURI = session.sync(new ResourceToPossibleURI(r));
74 } catch (Throwable e) {
76 debugger = new VariableDebugger(parent, SWT.NONE, session, initialURI);
77 debugger.defaultInitializeUI();
81 contributeActions(getViewSite().getActionBars());
86 public void dispose() {
90 private void makeActions() {
91 backAction = new BackAction();
92 forwardAction = new ForwardAction();
93 refreshAction = new RefreshAction();
94 homeAction = new HomeAction();
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);
107 public void setFocus() {
108 if (debugger != null)
112 private void refreshBrowser() {
113 debugger.refreshBrowser();
116 class RefreshAction extends Action {
117 public RefreshAction() {
118 super("Refresh", BundleUtils.getImageDescriptorFromPlugin(SimanticsUI.PLUGIN_ID, "icons/refresh.gif"));
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));
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));
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));
163 private void back() {
167 private void forward() {
171 private void navigateHome() {
172 Resource rootLibrary = session.getRootLibrary();
174 debugger.changeLocation(session.sync(new ResourceToURI(rootLibrary)));
175 } catch (DatabaseException e) {
176 Logger.defaultLogError(e);
180 private void updateActionStates() {
181 backAction.setEnabled(debugger.hasBackHistory());
182 forwardAction.setEnabled(debugger.hasForwardHistory());