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.db.Resource;
24 import org.simantics.db.Session;
25 import org.simantics.db.common.uri.ResourceToPossibleURI;
26 import org.simantics.db.common.uri.ResourceToURI;
27 import org.simantics.db.common.utils.Logger;
28 import org.simantics.db.exception.DatabaseException;
29 import org.simantics.ui.SimanticsUI;
30 import org.simantics.ui.workbench.ResourceInput;
31 import org.simantics.utils.ui.BundleUtils;
32 import org.simantics.utils.ui.ErrorLogger;
33 import org.simantics.utils.ui.LayoutUtils;
35 public class VariableDebuggerView extends ViewPart {
37 public static final String VIEW_ID = "org.simantics.debug.variableDebugger";
39 private ResourceInput input;
41 private Session session;
43 private VariableDebugger debugger;
45 private Action backAction;
46 private Action forwardAction;
47 private Action refreshAction;
48 private Action homeAction;
51 public void createPartControl(Composite parent) {
53 session = SimanticsUI.getSession();
56 String sid = getViewSite().getSecondaryId();
59 input = ResourceInput.unmarshall(sid);
61 r = input.toResource(session);
62 } catch (DatabaseException e) {
63 ErrorLogger.defaultLogError(e);
68 parent.setLayout(LayoutUtils.createNoBorderGridLayout(1));
69 String initialURI = null;
72 initialURI = session.sync(new ResourceToPossibleURI(r));
73 } catch (Throwable e) {
75 debugger = new VariableDebugger(parent, SWT.NONE, session, initialURI);
76 debugger.defaultInitializeUI();
80 contributeActions(getViewSite().getActionBars());
85 public void dispose() {
89 private void makeActions() {
90 backAction = new BackAction();
91 forwardAction = new ForwardAction();
92 refreshAction = new RefreshAction();
93 homeAction = new HomeAction();
96 private void contributeActions(IActionBars actionBars) {
97 IToolBarManager toolBar = actionBars.getToolBarManager();
98 toolBar.add(backAction);
99 toolBar.add(forwardAction);
100 toolBar.add(new Separator());
101 toolBar.add(refreshAction);
102 toolBar.add(homeAction);
106 public void setFocus() {
107 if (debugger != null)
111 private void refreshBrowser() {
112 debugger.refreshBrowser();
115 class RefreshAction extends Action {
116 public RefreshAction() {
117 super("Refresh", BundleUtils.getImageDescriptorFromPlugin(SimanticsUI.PLUGIN_ID, "icons/refresh.gif"));
125 class BackAction extends Action {
126 public BackAction() {
127 super("Back", Action.AS_PUSH_BUTTON);
128 setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_BACK));
129 setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_BACK_DISABLED));
137 class ForwardAction extends Action {
138 public ForwardAction() {
139 super("Forward", Action.AS_PUSH_BUTTON);
140 setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_FORWARD));
141 setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_FORWARD_DISABLED));
149 class HomeAction extends Action {
150 public HomeAction() {
151 super("Home", Action.AS_PUSH_BUTTON);
152 setToolTipText("Navigate to root library");
153 setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_ETOOL_HOME_NAV));
154 setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_ETOOL_HOME_NAV_DISABLED));
162 private void back() {
166 private void forward() {
170 private void navigateHome() {
171 Resource rootLibrary = session.getRootLibrary();
173 debugger.changeLocation(session.sync(new ResourceToURI(rootLibrary)));
174 } catch (DatabaseException e) {
175 Logger.defaultLogError(e);
179 private void updateActionStates() {
180 backAction.setEnabled(debugger.hasBackHistory());
181 forwardAction.setEnabled(debugger.hasForwardHistory());