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