]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/VariableDebuggerView.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.debug.ui / src / org / simantics / debug / ui / VariableDebuggerView.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;
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.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;
34
35 public class VariableDebuggerView extends ViewPart {
36
37     public static final String VIEW_ID              = "org.simantics.debug.variableDebugger";
38
39     private ResourceInput      input;
40
41     private Session            session;
42
43     private VariableDebugger   debugger;
44
45     private Action             backAction;
46     private Action             forwardAction;
47     private Action             refreshAction;
48     private Action             homeAction;
49
50     @Override
51     public void createPartControl(Composite parent) {
52
53         session = SimanticsUI.getSession();
54
55         // Initialize input
56         String sid = getViewSite().getSecondaryId();
57         Resource r = null;
58         if (sid != null) {
59             input = ResourceInput.unmarshall(sid);
60             try {
61                 r = input.toResource(session);
62             } catch (DatabaseException e) {
63                 ErrorLogger.defaultLogError(e);
64             }
65         }
66         
67         // Create UI
68         parent.setLayout(LayoutUtils.createNoBorderGridLayout(1));
69         String initialURI = null;
70         try {
71                 if(r != null)
72                         initialURI = session.sync(new ResourceToPossibleURI(r));
73         } catch (Throwable e) {
74         }
75         debugger = new VariableDebugger(parent, SWT.NONE, session, initialURI);
76         debugger.defaultInitializeUI();
77
78         // Contribute actions
79         makeActions();
80         contributeActions(getViewSite().getActionBars());
81         updateActionStates();
82     }
83
84     @Override
85     public void dispose() {
86         super.dispose();
87     }
88
89     private void makeActions() {
90         backAction = new BackAction();
91         forwardAction = new ForwardAction();
92         refreshAction = new RefreshAction();
93         homeAction = new HomeAction();
94     }
95
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);
103     }
104
105     @Override
106     public void setFocus() {
107         if (debugger != null)
108             debugger.setFocus();
109     }
110
111     private void refreshBrowser() {
112         debugger.refreshBrowser();
113     }
114 //
115     class RefreshAction extends Action {
116         public RefreshAction() {
117             super("Refresh", BundleUtils.getImageDescriptorFromPlugin(SimanticsUI.PLUGIN_ID, "icons/refresh.gif"));
118         }
119         @Override
120         public void run() {
121             refreshBrowser();
122         }
123     }
124
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));
130         }
131         @Override
132         public void run() {
133             back();
134         }
135     }
136
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));
142         }
143         @Override
144         public void run() {
145             forward();
146         }
147     }
148
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));
155         }
156         @Override
157         public void run() {
158             navigateHome();
159         }
160     }
161
162     private void back() {
163         debugger.back();
164     }
165
166     private void forward() {
167         debugger.forward();
168     }
169
170     private void navigateHome() {
171         Resource rootLibrary = session.getRootLibrary();
172         try {
173             debugger.changeLocation(session.sync(new ResourceToURI(rootLibrary)));
174         } catch (DatabaseException e) {
175             Logger.defaultLogError(e);
176         }
177     }
178
179     private void updateActionStates() {
180         backAction.setEnabled(debugger.hasBackHistory());
181         forwardAction.setEnabled(debugger.hasForwardHistory());
182     }
183
184 }