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.Simantics;
24 import org.simantics.db.Resource;
25 import org.simantics.db.Session;
26 import org.simantics.db.exception.DatabaseException;
27 import org.simantics.ui.SimanticsUI;
28 import org.simantics.ui.workbench.ResourceInput;
29 import org.simantics.utils.ui.BundleUtils;
30 import org.simantics.utils.ui.ErrorLogger;
31 import org.simantics.utils.ui.LayoutUtils;
33 public class GraphicalDebuggerView extends ViewPart {
35 public static final String VIEW_ID = "org.simantics.debug.graphicalDebugger"; //$NON-NLS-1$
37 // private final boolean DEFAULT_RECYCLE_VIEW = true;
39 private ResourceInput input;
41 private Session session;
43 private GraphicalDebugger debugger;
45 // private Action recycleToggle;
46 private Action backAction;
47 private Action forwardAction;
48 private Action refreshAction;
49 private Action homeAction;
50 private Action increaseDepthAction;
51 private Action decreaseDepthAction;
54 public void createPartControl(Composite parent) {
55 // System.out.println("koss: " + getViewSite().getSecondaryId());
56 session = Simantics.getSession();
59 String sid = getViewSite().getSecondaryId();
62 input = ResourceInput.unmarshall(sid);
64 r = input.toResource(session);
65 } catch (DatabaseException e) {
66 ErrorLogger.defaultLogError(e);
71 parent.setLayout(LayoutUtils.createNoBorderGridLayout(1));
72 debugger = new GraphicalDebugger(parent, SWT.NONE, session, r);
73 debugger.defaultInitializeUI();
77 contributeActions(getViewSite().getActionBars());
82 public void dispose() {
86 private void makeActions() {
87 // recycleToggle = new RecycleToggle();
88 // recycleToggle.setChecked(DEFAULT_RECYCLE_VIEW);
90 backAction = new BackAction();
91 forwardAction = new ForwardAction();
92 refreshAction = new RefreshAction();
93 homeAction = new HomeAction();
94 increaseDepthAction = new IncreaseDepthAction();
95 decreaseDepthAction = new DecreaseDepthAction();
98 private void contributeActions(IActionBars actionBars) {
99 IToolBarManager toolBar = actionBars.getToolBarManager();
100 toolBar.add(backAction);
101 toolBar.add(forwardAction);
102 toolBar.add(new Separator());
103 toolBar.add(refreshAction);
104 toolBar.add(homeAction);
105 toolBar.add(new Separator());
106 toolBar.add(decreaseDepthAction);
107 toolBar.add(increaseDepthAction);
108 // toolBar.add(recycleToggle);
112 public void setFocus() {
113 if (debugger != null)
117 private void refreshBrowser() {
118 debugger.refreshBrowser();
121 // class RecycleToggle extends Action {
122 // public RecycleToggle() {
123 // super("Open New Views", Action.AS_CHECK_BOX);
124 // setImageDescriptor(Activator.getImageDescriptor("icons/reload.gif"));
125 // setToolTipText("Toggles whether or not to open new views when resource links are clicked.");
129 class RefreshAction extends Action {
130 public RefreshAction() {
131 super(Messages.GraphicalDebuggerView_Refresh, BundleUtils.getImageDescriptorFromPlugin(SimanticsUI.PLUGIN_ID, "icons/refresh.gif")); //$NON-NLS-2$
139 class BackAction extends Action {
140 public BackAction() {
141 super(Messages.GraphicalDebuggerView_Back, Action.AS_PUSH_BUTTON);
142 setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_BACK));
143 setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_BACK_DISABLED));
151 class ForwardAction extends Action {
152 public ForwardAction() {
153 super(Messages.GraphicalDebuggerView_Forward, Action.AS_PUSH_BUTTON);
154 setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_FORWARD));
155 setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_FORWARD_DISABLED));
163 class HomeAction extends Action {
164 public HomeAction() {
165 super(Messages.GraphicalDebuggerView_Home, Action.AS_PUSH_BUTTON);
166 setToolTipText(Messages.GraphicalDebuggerView_HomeTT);
167 setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_ETOOL_HOME_NAV));
168 setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_ETOOL_HOME_NAV_DISABLED));
176 class DecreaseDepthAction extends Action {
177 public DecreaseDepthAction() {
178 super(Messages.GraphicalDebuggerView_Decrease, Action.AS_PUSH_BUTTON);
179 setToolTipText(Messages.GraphicalDebuggerView_DecreaseTT);
180 setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_BACK));
181 setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_BACK_DISABLED));
189 class IncreaseDepthAction extends Action {
190 public IncreaseDepthAction() {
191 super(Messages.GraphicalDebuggerView_Increase, Action.AS_PUSH_BUTTON);
192 setToolTipText(Messages.GraphicalDebuggerView_IncreaseTT);
193 setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_FORWARD));
194 setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_FORWARD_DISABLED));
202 private void back() {
206 private void forward() {
210 private void decreaseDepth() {
211 debugger.setDepth(debugger.getDepth() - 1);
214 private void increaseDepth() {
215 debugger.setDepth(debugger.getDepth() + 1);
218 private void navigateHome() {
219 Resource rootLibrary = session.getRootLibrary();
220 debugger.changeLocation(rootLibrary);
223 private void updateActionStates() {
224 backAction.setEnabled(debugger.hasBackHistory());
225 forwardAction.setEnabled(debugger.hasForwardHistory());