1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2013 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 * Semantum Oy - index based searching and graph manipulation (#4255)
\r
12 *******************************************************************************/
\r
13 package org.simantics.debug.ui.graph;
\r
15 import org.eclipse.core.runtime.IStatus;
\r
16 import org.eclipse.core.runtime.Status;
\r
17 import org.eclipse.jface.action.Action;
\r
18 import org.eclipse.jface.action.ActionContributionItem;
\r
19 import org.eclipse.jface.action.IAction;
\r
20 import org.eclipse.jface.action.Separator;
\r
21 import org.eclipse.jface.layout.GridDataFactory;
\r
22 import org.eclipse.swt.SWT;
\r
23 import org.eclipse.swt.layout.GridData;
\r
24 import org.eclipse.swt.layout.GridLayout;
\r
25 import org.eclipse.swt.widgets.Composite;
\r
26 import org.eclipse.swt.widgets.Control;
\r
27 import org.eclipse.swt.widgets.ToolBar;
\r
28 import org.eclipse.ui.ISharedImages;
\r
29 import org.eclipse.ui.PlatformUI;
\r
30 import org.simantics.Simantics;
\r
31 import org.simantics.db.exception.DatabaseException;
\r
32 import org.simantics.debug.ui.internal.Activator;
\r
33 import org.simantics.debug.ui.internal.DebugUtils;
\r
34 import org.simantics.ui.SimanticsUI;
\r
35 import org.simantics.ui.workbench.ResourceEditorPart;
\r
36 import org.simantics.utils.ui.BundleUtils;
\r
37 import org.simantics.utils.ui.LayoutUtils;
\r
39 public class GraphicalDebuggerEditor extends ResourceEditorPart {
\r
41 public static final String EDITOR_ID = "org.simantics.debug.graphicalDebuggerEditor";
\r
43 private GraphicalDebugger debugger;
\r
44 private IAction backAction;
\r
45 private IAction forwardAction;
\r
46 private IAction refreshAction;
\r
47 private IAction findAction;
\r
48 private IAction addStatementAction;
\r
49 private IAction addResourceAction;
\r
50 private Action increaseDepthAction;
\r
51 private Action decreaseDepthAction;
\r
54 public void createPartControl(Composite parent) {
\r
56 parent.setLayout(LayoutUtils.createNoBorderGridLayout(1));
\r
58 debugger = new GraphicalDebugger(parent, SWT.NONE, getSession(), getInputResource());
\r
59 debugger.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
\r
60 debugger.setLayout(LayoutUtils.createNoBorderGridLayout(1));
\r
62 Composite bar = new Composite(debugger, SWT.NONE);
\r
63 bar.setLayout(new GridLayout(3, false));
\r
64 bar.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
\r
66 backAction = new BackAction();
\r
67 forwardAction = new ForwardAction();
\r
68 refreshAction = new RefreshAction();
\r
69 findAction = new FindAction();
\r
70 addStatementAction = new AddStatementAction();
\r
71 addResourceAction = new AddResourceAction();
\r
72 increaseDepthAction = new IncreaseDepthAction();
\r
73 decreaseDepthAction = new DecreaseDepthAction();
\r
75 ToolBar toolBar = new ToolBar(bar, SWT.HORIZONTAL | SWT.FLAT);
\r
77 new ActionContributionItem(backAction).fill(toolBar, 0);
\r
78 new ActionContributionItem(forwardAction).fill(toolBar, 1);
\r
79 new Separator().fill(toolBar, 2);
\r
80 new ActionContributionItem(refreshAction).fill(toolBar, 3);
\r
81 new Separator().fill(toolBar, 4);
\r
82 new ActionContributionItem(findAction).fill(toolBar, 5);
\r
83 new ActionContributionItem(addStatementAction).fill(toolBar, 6);
\r
84 new ActionContributionItem(addResourceAction).fill(toolBar, 7);
\r
85 new Separator().fill(toolBar, 8);
\r
86 new ActionContributionItem(decreaseDepthAction).fill(toolBar, 9);
\r
87 new ActionContributionItem(increaseDepthAction).fill(toolBar, 10);
\r
89 debugger.createResourceText(bar);
\r
90 Control dropLabel = debugger.createDropLabel(bar);
\r
91 GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.FILL).hint(SWT.DEFAULT, 20).span(3, 1).applyTo(dropLabel);
\r
92 Control browser = debugger.createGraph(debugger);
\r
93 GridDataFactory.fillDefaults().grab(true, true).span(3, 1).applyTo(browser);
\r
95 debugger.addHistoryListener(new GraphicalDebugger.HistoryListener() {
\r
97 public void historyChanged() {
\r
98 updateActionStates();
\r
102 updateActionStates();
\r
106 public void setFocus() {
\r
107 if (debugger != null)
\r
108 debugger.setFocus();
\r
111 public void back() {
\r
115 public void forward() {
\r
116 debugger.forward();
\r
119 public void refreshBrowser() {
\r
120 debugger.refreshBrowser();
\r
123 private void decreaseDepth() {
\r
124 debugger.setDepth(debugger.getDepth() - 1);
\r
127 private void increaseDepth() {
\r
128 debugger.setDepth(debugger.getDepth() + 1);
\r
131 private void updateActionStates() {
\r
132 backAction.setEnabled(!debugger.hasBackHistory());
\r
133 forwardAction.setEnabled(!debugger.hasForwardHistory());
\r
136 class RefreshAction extends Action {
\r
137 public RefreshAction() {
\r
138 super("Refresh", BundleUtils.getImageDescriptorFromPlugin(SimanticsUI.PLUGIN_ID, "icons/refresh.gif"));
\r
141 public void run() {
\r
146 class FindAction extends Action {
\r
147 public FindAction() {
\r
148 super("Find", BundleUtils.getImageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/cog_blue.png"));
\r
149 setToolTipText("Find Resource");
\r
152 public void run() {
\r
153 DebugUtils.find(Simantics.getSession(), debugger);
\r
157 class AddStatementAction extends Action {
\r
158 public AddStatementAction() {
\r
159 super("AddStatement", BundleUtils.getImageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/cog_add.png"));
\r
160 setToolTipText("Add Statement Between Existing Resources");
\r
163 public void run() {
\r
165 DebugUtils.addStatement(Simantics.getSession(), debugger);
\r
166 } catch (DatabaseException e) {
\r
167 Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e));
\r
171 class AddResourceAction extends Action {
\r
172 public AddResourceAction() {
\r
173 super("AddResource", BundleUtils.getImageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/cog_add.png"));
\r
174 setToolTipText("Add New Related Resource");
\r
177 public void run() {
\r
179 DebugUtils.addResource(Simantics.getSession(), debugger);
\r
180 } catch (DatabaseException e) {
\r
181 Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e));
\r
185 class BackAction extends Action {
\r
186 public BackAction() {
\r
187 super("Back", Action.AS_PUSH_BUTTON);
\r
188 setToolTipText("Back");
\r
189 setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_BACK));
\r
190 setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_BACK_DISABLED));
\r
193 public void run() {
\r
195 updateActionStates();
\r
199 class ForwardAction extends Action {
\r
200 public ForwardAction() {
\r
201 super("Forward", Action.AS_PUSH_BUTTON);
\r
202 setToolTipText("Forward");
\r
203 setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_FORWARD));
\r
204 setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_FORWARD_DISABLED));
\r
207 public void run() {
\r
209 updateActionStates();
\r
213 class DecreaseDepthAction extends Action {
\r
214 public DecreaseDepthAction() {
\r
215 super("Decrease", Action.AS_PUSH_BUTTON);
\r
216 setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_BACK));
\r
217 setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_BACK_DISABLED));
\r
220 public void run() {
\r
225 class IncreaseDepthAction extends Action {
\r
226 public IncreaseDepthAction() {
\r
227 super("Increase", Action.AS_PUSH_BUTTON);
\r
228 setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_FORWARD));
\r
229 setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_FORWARD_DISABLED));
\r
232 public void run() {
\r