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 * Semantum Oy - index based searching and graph manipulation (#4255)
12 *******************************************************************************/
13 package org.simantics.debug.ui;
15 import org.eclipse.core.runtime.IStatus;
16 import org.eclipse.core.runtime.Status;
17 import org.eclipse.jface.action.Action;
18 import org.eclipse.jface.action.IAction;
19 import org.eclipse.jface.action.IToolBarManager;
20 import org.eclipse.jface.action.Separator;
21 import org.eclipse.swt.SWT;
22 import org.eclipse.swt.widgets.Composite;
23 import org.eclipse.ui.IActionBars;
24 import org.eclipse.ui.ISharedImages;
25 import org.eclipse.ui.PlatformUI;
26 import org.eclipse.ui.part.ViewPart;
27 import org.simantics.Simantics;
28 import org.simantics.db.Resource;
29 import org.simantics.db.Session;
30 import org.simantics.db.exception.DatabaseException;
31 import org.simantics.debug.ui.internal.Activator;
32 import org.simantics.debug.ui.internal.DebugUtils;
33 import org.simantics.ui.SimanticsUI;
34 import org.simantics.ui.workbench.ResourceInput;
35 import org.simantics.utils.ui.BundleUtils;
36 import org.simantics.utils.ui.ErrorLogger;
37 import org.simantics.utils.ui.LayoutUtils;
39 public class GraphDebuggerView extends ViewPart {
41 public static final String VIEW_ID = "org.simantics.debug.graphDebugger";
43 // private final boolean DEFAULT_RECYCLE_VIEW = true;
45 private ResourceInput input;
47 private Session session;
49 private GraphDebugger debugger;
51 // private IAction recycleToggle;
52 private IAction backAction;
53 private IAction forwardAction;
54 private IAction refreshAction;
55 private IAction findAction;
56 private IAction addStatementAction;
57 private IAction addResourceAction;
58 private IAction homeAction;
61 public void createPartControl(Composite parent) {
62 // System.out.println("koss: " + getViewSite().getSecondaryId());
63 session = SimanticsUI.getSession();
66 String sid = getViewSite().getSecondaryId();
69 input = ResourceInput.unmarshall(sid);
71 r = input.toResource(session);
72 } catch (DatabaseException e) {
73 ErrorLogger.defaultLogError(e);
78 parent.setLayout(LayoutUtils.createNoBorderGridLayout(1));
79 debugger = new GraphDebugger(parent, SWT.NONE, session, r, getSite());
80 debugger.defaultInitializeUI();
84 contributeActions(getViewSite().getActionBars());
89 public void dispose() {
93 private void makeActions() {
94 // recycleToggle = new RecycleToggle();
95 // recycleToggle.setChecked(DEFAULT_RECYCLE_VIEW);
97 backAction = new BackAction();
98 forwardAction = new ForwardAction();
99 refreshAction = new RefreshAction();
100 findAction = new FindAction();
101 addStatementAction = new AddStatementAction();
102 addResourceAction = new AddResourceAction();
103 homeAction = new HomeAction();
106 private void contributeActions(IActionBars actionBars) {
107 IToolBarManager toolBar = actionBars.getToolBarManager();
108 toolBar.add(backAction);
109 toolBar.add(forwardAction);
110 toolBar.add(new Separator());
111 toolBar.add(refreshAction);
112 toolBar.add(new Separator());
113 toolBar.add(findAction);
114 toolBar.add(addStatementAction);
115 toolBar.add(addResourceAction);
116 toolBar.add(new Separator());
117 toolBar.add(homeAction);
119 // toolBar.add(recycleToggle);
123 public void setFocus() {
124 if (debugger != null)
128 private void refreshBrowser() {
129 debugger.refreshBrowser();
132 // class RecycleToggle extends Action {
133 // public RecycleToggle() {
134 // super("Open New Views", Action.AS_CHECK_BOX);
135 // setImageDescriptor(Activator.getImageDescriptor("icons/reload.gif"));
136 // setToolTipText("Toggles whether or not to open new views when resource links are clicked.");
140 class RefreshAction extends Action {
141 public RefreshAction() {
142 super("Refresh", BundleUtils.getImageDescriptorFromPlugin(SimanticsUI.PLUGIN_ID, "icons/refresh.gif"));
143 setToolTipText("Refresh");
151 class BackAction extends Action {
152 public BackAction() {
153 super("Back", Action.AS_PUSH_BUTTON);
154 setToolTipText("Back");
155 setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_BACK));
156 setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_BACK_DISABLED));
164 class ForwardAction extends Action {
165 public ForwardAction() {
166 super("Forward", Action.AS_PUSH_BUTTON);
167 setToolTipText("Forward");
168 setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_FORWARD));
169 setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_FORWARD_DISABLED));
177 class HomeAction extends Action {
178 public HomeAction() {
179 super("Home", Action.AS_PUSH_BUTTON);
180 setToolTipText("Navigate to root library");
181 setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_ETOOL_HOME_NAV));
182 setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_ETOOL_HOME_NAV_DISABLED));
190 class FindAction extends Action {
191 public FindAction() {
192 super("Find", BundleUtils.getImageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/cog_blue.png"));
193 setToolTipText("Find Resource");
197 DebugUtils.find(Simantics.getSession(), debugger);
201 class AddStatementAction extends Action {
202 public AddStatementAction() {
203 super("AddStatement", BundleUtils.getImageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/cog_add.png"));
204 setToolTipText("Add Statement Between Existing Resources");
209 DebugUtils.addStatement(Simantics.getSession(), debugger);
210 } catch (DatabaseException e) {
211 Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e));
216 class AddResourceAction extends Action {
217 public AddResourceAction() {
218 super("AddResource", BundleUtils.getImageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/cog_add.png"));
219 setToolTipText("Add New Related Resource");
224 DebugUtils.addResource(Simantics.getSession(), debugger);
225 } catch (DatabaseException e) {
226 Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e));
231 private void back() {
235 private void forward() {
239 private void navigateHome() {
240 Resource rootLibrary = session.getRootLibrary();
241 debugger.changeLocation(rootLibrary);
244 private void updateActionStates() {
245 backAction.setEnabled(debugger.hasBackHistory());
246 forwardAction.setEnabled(debugger.hasForwardHistory());