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