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.graph;
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.exception.DatabaseException;
26 import org.simantics.ui.SimanticsUI;
27 import org.simantics.ui.workbench.ResourceInput;
28 import org.simantics.utils.ui.BundleUtils;
29 import org.simantics.utils.ui.ErrorLogger;
30 import org.simantics.utils.ui.LayoutUtils;
32 public class GraphicalDebuggerView extends ViewPart {
34 public static final String VIEW_ID = "org.simantics.debug.graphicalDebugger";
36 // private final boolean DEFAULT_RECYCLE_VIEW = true;
38 private ResourceInput input;
40 private Session session;
42 private GraphicalDebugger debugger;
44 // private Action recycleToggle;
45 private Action backAction;
46 private Action forwardAction;
47 private Action refreshAction;
48 private Action homeAction;
49 private Action increaseDepthAction;
50 private Action decreaseDepthAction;
53 public void createPartControl(Composite parent) {
54 // System.out.println("koss: " + getViewSite().getSecondaryId());
55 session = SimanticsUI.getSession();
58 String sid = getViewSite().getSecondaryId();
61 input = ResourceInput.unmarshall(sid);
63 r = input.toResource(session);
64 } catch (DatabaseException e) {
65 ErrorLogger.defaultLogError(e);
70 parent.setLayout(LayoutUtils.createNoBorderGridLayout(1));
71 debugger = new GraphicalDebugger(parent, SWT.NONE, session, r);
72 debugger.defaultInitializeUI();
76 contributeActions(getViewSite().getActionBars());
81 public void dispose() {
85 private void makeActions() {
86 // recycleToggle = new RecycleToggle();
87 // recycleToggle.setChecked(DEFAULT_RECYCLE_VIEW);
89 backAction = new BackAction();
90 forwardAction = new ForwardAction();
91 refreshAction = new RefreshAction();
92 homeAction = new HomeAction();
93 increaseDepthAction = new IncreaseDepthAction();
94 decreaseDepthAction = new DecreaseDepthAction();
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 toolBar.add(new Separator());
105 toolBar.add(decreaseDepthAction);
106 toolBar.add(increaseDepthAction);
107 // toolBar.add(recycleToggle);
111 public void setFocus() {
112 if (debugger != null)
116 private void refreshBrowser() {
117 debugger.refreshBrowser();
120 // class RecycleToggle extends Action {
121 // public RecycleToggle() {
122 // super("Open New Views", Action.AS_CHECK_BOX);
123 // setImageDescriptor(Activator.getImageDescriptor("icons/reload.gif"));
124 // setToolTipText("Toggles whether or not to open new views when resource links are clicked.");
128 class RefreshAction extends Action {
129 public RefreshAction() {
130 super("Refresh", BundleUtils.getImageDescriptorFromPlugin(SimanticsUI.PLUGIN_ID, "icons/refresh.gif"));
138 class BackAction extends Action {
139 public BackAction() {
140 super("Back", Action.AS_PUSH_BUTTON);
141 setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_BACK));
142 setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_BACK_DISABLED));
150 class ForwardAction extends Action {
151 public ForwardAction() {
152 super("Forward", Action.AS_PUSH_BUTTON);
153 setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_FORWARD));
154 setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_FORWARD_DISABLED));
162 class HomeAction extends Action {
163 public HomeAction() {
164 super("Home", Action.AS_PUSH_BUTTON);
165 setToolTipText("Navigate to root library");
166 setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_ETOOL_HOME_NAV));
167 setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_ETOOL_HOME_NAV_DISABLED));
175 class DecreaseDepthAction extends Action {
176 public DecreaseDepthAction() {
177 super("Decrease", Action.AS_PUSH_BUTTON);
178 setToolTipText("Decrease Depth");
179 setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_BACK));
180 setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_BACK_DISABLED));
188 class IncreaseDepthAction extends Action {
189 public IncreaseDepthAction() {
190 super("Increase", Action.AS_PUSH_BUTTON);
191 setToolTipText("Increase Depth");
192 setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_FORWARD));
193 setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_FORWARD_DISABLED));
201 private void back() {
205 private void forward() {
209 private void decreaseDepth() {
210 debugger.setDepth(debugger.getDepth() - 1);
213 private void increaseDepth() {
214 debugger.setDepth(debugger.getDepth() + 1);
217 private void navigateHome() {
218 Resource rootLibrary = session.getRootLibrary();
219 debugger.changeLocation(rootLibrary);
222 private void updateActionStates() {
223 backAction.setEnabled(debugger.hasBackHistory());
224 forwardAction.setEnabled(debugger.hasForwardHistory());