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;
\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 GraphDebuggerEditor extends ResourceEditorPart {
\r
41 public static final String EDITOR_ID = "org.simantics.debug.graphDebuggerEditor";
\r
43 private GraphDebugger 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
52 public void createPartControl(Composite parent) {
\r
54 parent.setLayout(LayoutUtils.createNoBorderGridLayout(1));
\r
56 debugger = new GraphDebugger(parent, SWT.NONE, getSession(), getInputResource(), getSite());
\r
57 debugger.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
\r
58 debugger.setLayout(LayoutUtils.createNoBorderGridLayout(1));
\r
60 Composite bar = new Composite(debugger, SWT.NONE);
\r
61 bar.setLayout(new GridLayout(3, false));
\r
62 bar.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
\r
64 backAction = new BackAction();
\r
65 forwardAction = new ForwardAction();
\r
66 refreshAction = new RefreshAction();
\r
67 findAction = new FindAction();
\r
68 addStatementAction = new AddStatementAction();
\r
69 addResourceAction = new AddResourceAction();
\r
71 ToolBar toolBar = new ToolBar(bar, SWT.HORIZONTAL | SWT.FLAT);
\r
73 new ActionContributionItem(backAction).fill(toolBar, 0);
\r
74 new ActionContributionItem(forwardAction).fill(toolBar, 1);
\r
75 new Separator().fill(toolBar, 2);
\r
76 new ActionContributionItem(refreshAction).fill(toolBar, 3);
\r
77 new Separator().fill(toolBar, 4);
\r
78 new ActionContributionItem(findAction).fill(toolBar, 5);
\r
79 new ActionContributionItem(addStatementAction).fill(toolBar, 6);
\r
80 new ActionContributionItem(addResourceAction).fill(toolBar, 7);
\r
82 debugger.createResourceText(bar);
\r
83 Control dropLabel = debugger.createDropLabel(bar);
\r
84 GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.FILL).hint(SWT.DEFAULT, 20).span(3, 1).applyTo(dropLabel);
\r
85 Control browser = debugger.createBrowser(debugger);
\r
86 GridDataFactory.fillDefaults().grab(true, true).span(3, 1).applyTo(browser);
\r
88 debugger.addHistoryListener(new GraphDebugger.HistoryListener() {
\r
90 public void historyChanged() {
\r
91 updateActionStates();
\r
95 updateActionStates();
\r
99 public void setFocus() {
\r
100 if (debugger != null)
\r
101 debugger.setFocus();
\r
104 public void back() {
\r
108 public void forward() {
\r
109 debugger.forward();
\r
112 public void refreshBrowser() {
\r
113 debugger.refreshBrowser();
\r
116 private void updateActionStates() {
\r
117 backAction.setEnabled(!debugger.hasBackHistory());
\r
118 forwardAction.setEnabled(!debugger.hasForwardHistory());
\r
121 class RefreshAction extends Action {
\r
122 public RefreshAction() {
\r
123 super("Refresh", BundleUtils.getImageDescriptorFromPlugin(SimanticsUI.PLUGIN_ID, "icons/refresh.gif"));
\r
124 setToolTipText("Refresh");
\r
127 public void run() {
\r
132 class FindAction extends Action {
\r
133 public FindAction() {
\r
134 super("Find", BundleUtils.getImageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/cog_blue.png"));
\r
135 setToolTipText("Find Resource");
\r
138 public void run() {
\r
139 DebugUtils.find(Simantics.getSession(), debugger);
\r
143 class AddStatementAction extends Action {
\r
144 public AddStatementAction() {
\r
145 super("AddStatement", BundleUtils.getImageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/cog_add.png"));
\r
146 setToolTipText("Add Statement Between Existing Resources");
\r
149 public void run() {
\r
151 DebugUtils.addStatement(Simantics.getSession(), debugger);
\r
152 } catch (DatabaseException e) {
\r
153 Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e));
\r
158 class AddResourceAction extends Action {
\r
159 public AddResourceAction() {
\r
160 super("AddResource", BundleUtils.getImageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/cog_add.png"));
\r
161 setToolTipText("Add New Related Resource");
\r
164 public void run() {
\r
166 DebugUtils.addResource(Simantics.getSession(), debugger);
\r
167 } catch (DatabaseException e) {
\r
168 Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e));
\r
173 class BackAction extends Action {
\r
174 public BackAction() {
\r
175 super("Back", Action.AS_PUSH_BUTTON);
\r
176 setToolTipText("Back");
\r
177 setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_BACK));
\r
178 setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_BACK_DISABLED));
\r
181 public void run() {
\r
183 updateActionStates();
\r
187 class ForwardAction extends Action {
\r
188 public ForwardAction() {
\r
189 super("Forward", Action.AS_PUSH_BUTTON);
\r
190 setToolTipText("Forward");
\r
191 setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_FORWARD));
\r
192 setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_FORWARD_DISABLED));
\r
195 public void run() {
\r
197 updateActionStates();
\r