1 /*******************************************************************************
2 * Copyright (c) 2007, 2013 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.graph;
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.ActionContributionItem;
19 import org.eclipse.jface.action.IAction;
20 import org.eclipse.jface.action.Separator;
21 import org.eclipse.jface.layout.GridDataFactory;
22 import org.eclipse.swt.SWT;
23 import org.eclipse.swt.layout.GridData;
24 import org.eclipse.swt.layout.GridLayout;
25 import org.eclipse.swt.widgets.Composite;
26 import org.eclipse.swt.widgets.Control;
27 import org.eclipse.swt.widgets.ToolBar;
28 import org.eclipse.ui.ISharedImages;
29 import org.eclipse.ui.PlatformUI;
30 import org.simantics.Simantics;
31 import org.simantics.db.exception.DatabaseException;
32 import org.simantics.debug.ui.internal.Activator;
33 import org.simantics.debug.ui.internal.DebugUtils;
34 import org.simantics.ui.SimanticsUI;
35 import org.simantics.ui.workbench.ResourceEditorPart;
36 import org.simantics.utils.ui.BundleUtils;
37 import org.simantics.utils.ui.LayoutUtils;
39 public class GraphicalDebuggerEditor extends ResourceEditorPart {
41 public static final String EDITOR_ID = "org.simantics.debug.graphicalDebuggerEditor";
43 private GraphicalDebugger debugger;
44 private IAction backAction;
45 private IAction forwardAction;
46 private IAction refreshAction;
47 private IAction findAction;
48 private IAction addStatementAction;
49 private IAction addResourceAction;
50 private Action increaseDepthAction;
51 private Action decreaseDepthAction;
54 public void createPartControl(Composite parent) {
56 parent.setLayout(LayoutUtils.createNoBorderGridLayout(1));
58 debugger = new GraphicalDebugger(parent, SWT.NONE, getSession(), getInputResource());
59 debugger.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
60 debugger.setLayout(LayoutUtils.createNoBorderGridLayout(1));
62 Composite bar = new Composite(debugger, SWT.NONE);
63 bar.setLayout(new GridLayout(3, false));
64 bar.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
66 backAction = new BackAction();
67 forwardAction = new ForwardAction();
68 refreshAction = new RefreshAction();
69 findAction = new FindAction();
70 addStatementAction = new AddStatementAction();
71 addResourceAction = new AddResourceAction();
72 increaseDepthAction = new IncreaseDepthAction();
73 decreaseDepthAction = new DecreaseDepthAction();
75 ToolBar toolBar = new ToolBar(bar, SWT.HORIZONTAL | SWT.FLAT);
77 new ActionContributionItem(backAction).fill(toolBar, 0);
78 new ActionContributionItem(forwardAction).fill(toolBar, 1);
79 new Separator().fill(toolBar, 2);
80 new ActionContributionItem(refreshAction).fill(toolBar, 3);
81 new Separator().fill(toolBar, 4);
82 new ActionContributionItem(findAction).fill(toolBar, 5);
83 new ActionContributionItem(addStatementAction).fill(toolBar, 6);
84 new ActionContributionItem(addResourceAction).fill(toolBar, 7);
85 new Separator().fill(toolBar, 8);
86 new ActionContributionItem(decreaseDepthAction).fill(toolBar, 9);
87 new ActionContributionItem(increaseDepthAction).fill(toolBar, 10);
89 debugger.createResourceText(bar);
90 Control dropLabel = debugger.createDropLabel(bar);
91 GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.FILL).hint(SWT.DEFAULT, 20).span(3, 1).applyTo(dropLabel);
92 Control browser = debugger.createGraph(debugger);
93 GridDataFactory.fillDefaults().grab(true, true).span(3, 1).applyTo(browser);
95 debugger.addHistoryListener(new GraphicalDebugger.HistoryListener() {
97 public void historyChanged() {
102 updateActionStates();
106 public void setFocus() {
107 if (debugger != null)
115 public void forward() {
119 public void refreshBrowser() {
120 debugger.refreshBrowser();
123 private void decreaseDepth() {
124 debugger.setDepth(debugger.getDepth() - 1);
127 private void increaseDepth() {
128 debugger.setDepth(debugger.getDepth() + 1);
131 private void updateActionStates() {
132 backAction.setEnabled(!debugger.hasBackHistory());
133 forwardAction.setEnabled(!debugger.hasForwardHistory());
136 class RefreshAction extends Action {
137 public RefreshAction() {
138 super("Refresh", BundleUtils.getImageDescriptorFromPlugin(SimanticsUI.PLUGIN_ID, "icons/refresh.gif"));
146 class FindAction extends Action {
147 public FindAction() {
148 super("Find", BundleUtils.getImageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/cog_blue.png"));
149 setToolTipText("Find Resource");
153 DebugUtils.find(Simantics.getSession(), debugger);
157 class AddStatementAction extends Action {
158 public AddStatementAction() {
159 super("AddStatement", BundleUtils.getImageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/cog_add.png"));
160 setToolTipText("Add Statement Between Existing Resources");
165 DebugUtils.addStatement(Simantics.getSession(), debugger);
166 } catch (DatabaseException e) {
167 Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e));
171 class AddResourceAction extends Action {
172 public AddResourceAction() {
173 super("AddResource", BundleUtils.getImageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/cog_add.png"));
174 setToolTipText("Add New Related Resource");
179 DebugUtils.addResource(Simantics.getSession(), debugger);
180 } catch (DatabaseException e) {
181 Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e));
185 class BackAction extends Action {
186 public BackAction() {
187 super("Back", Action.AS_PUSH_BUTTON);
188 setToolTipText("Back");
189 setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_BACK));
190 setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_BACK_DISABLED));
195 updateActionStates();
199 class ForwardAction extends Action {
200 public ForwardAction() {
201 super("Forward", Action.AS_PUSH_BUTTON);
202 setToolTipText("Forward");
203 setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_FORWARD));
204 setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_FORWARD_DISABLED));
209 updateActionStates();
213 class DecreaseDepthAction extends Action {
214 public DecreaseDepthAction() {
215 super("Decrease", Action.AS_PUSH_BUTTON);
216 setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_BACK));
217 setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_BACK_DISABLED));
225 class IncreaseDepthAction extends Action {
226 public IncreaseDepthAction() {
227 super("Increase", Action.AS_PUSH_BUTTON);
228 setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_FORWARD));
229 setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_FORWARD_DISABLED));