]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/graph/GraphicalDebuggerView.java
ca2089a39ddc2efee90cd6767bb994c814660ab2
[simantics/platform.git] / bundles / org.simantics.debug.ui / src / org / simantics / debug / ui / graph / GraphicalDebuggerView.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.debug.ui.graph;
13
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;
31
32 public class GraphicalDebuggerView extends ViewPart {
33
34     public static final String VIEW_ID              = "org.simantics.debug.graphicalDebugger";
35
36 //    private final boolean      DEFAULT_RECYCLE_VIEW = true;
37
38     private ResourceInput      input;
39
40     private Session            session;
41
42     private GraphicalDebugger      debugger;
43
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;
51
52     @Override
53     public void createPartControl(Composite parent) {
54 //      System.out.println("koss: " + getViewSite().getSecondaryId());
55         session = SimanticsUI.getSession();
56
57         // Initialize input
58         String sid = getViewSite().getSecondaryId();
59         Resource r = null;
60         if (sid != null) {
61             input = ResourceInput.unmarshall(sid);
62             try {
63                 r = input.toResource(session);
64             } catch (DatabaseException e) {
65                 ErrorLogger.defaultLogError(e);
66             }
67         }
68
69         // Create UI
70         parent.setLayout(LayoutUtils.createNoBorderGridLayout(1));
71         debugger = new GraphicalDebugger(parent, SWT.NONE, session, r);
72         debugger.defaultInitializeUI();
73
74         // Contribute actions
75         makeActions();
76         contributeActions(getViewSite().getActionBars());
77         updateActionStates();
78     }
79
80     @Override
81     public void dispose() {
82         super.dispose();
83     }
84
85     private void makeActions() {
86 //        recycleToggle = new RecycleToggle();
87 //        recycleToggle.setChecked(DEFAULT_RECYCLE_VIEW);
88
89         backAction = new BackAction();
90         forwardAction = new ForwardAction();
91         refreshAction = new RefreshAction();
92         homeAction = new HomeAction();
93         increaseDepthAction = new IncreaseDepthAction();
94         decreaseDepthAction = new DecreaseDepthAction();
95     }
96
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);
108     }
109
110     @Override
111     public void setFocus() {
112         if (debugger != null)
113             debugger.setFocus();
114     }
115
116     private void refreshBrowser() {
117         debugger.refreshBrowser();
118     }
119
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.");
125 //        }
126 //    }
127 //
128     class RefreshAction extends Action {
129         public RefreshAction() {
130             super("Refresh", BundleUtils.getImageDescriptorFromPlugin(SimanticsUI.PLUGIN_ID, "icons/refresh.gif"));
131         }
132         @Override
133         public void run() {
134             refreshBrowser();
135         }
136     }
137
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));
143         }
144         @Override
145         public void run() {
146             back();
147         }
148     }
149
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));
155         }
156         @Override
157         public void run() {
158             forward();
159         }
160     }
161
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));
168         }
169         @Override
170         public void run() {
171             navigateHome();
172         }
173     }
174     
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));
181         }
182         @Override
183         public void run() {
184             decreaseDepth();
185         }
186     }
187
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));
194         }
195         @Override
196         public void run() {
197             increaseDepth();
198         }
199     }
200
201     private void back() {
202         debugger.back();
203     }
204
205     private void forward() {
206         debugger.forward();
207     }
208     
209     private void decreaseDepth() {
210         debugger.setDepth(debugger.getDepth() - 1);
211     }
212
213     private void increaseDepth() {
214          debugger.setDepth(debugger.getDepth() + 1);
215     }
216
217     private void navigateHome() {
218         Resource rootLibrary = session.getRootLibrary();
219         debugger.changeLocation(rootLibrary);
220     }
221
222     private void updateActionStates() {
223         backAction.setEnabled(debugger.hasBackHistory());
224         forwardAction.setEnabled(debugger.hasForwardHistory());
225     }
226
227 }