--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2013 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ * Semantum Oy - index based searching and graph manipulation (#4255)\r
+ *******************************************************************************/\r
+package org.simantics.debug.ui.graph;\r
+\r
+import org.eclipse.core.runtime.IStatus;\r
+import org.eclipse.core.runtime.Status;\r
+import org.eclipse.jface.action.Action;\r
+import org.eclipse.jface.action.ActionContributionItem;\r
+import org.eclipse.jface.action.IAction;\r
+import org.eclipse.jface.action.Separator;\r
+import org.eclipse.jface.layout.GridDataFactory;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.layout.GridData;\r
+import org.eclipse.swt.layout.GridLayout;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.eclipse.swt.widgets.Control;\r
+import org.eclipse.swt.widgets.ToolBar;\r
+import org.eclipse.ui.ISharedImages;\r
+import org.eclipse.ui.PlatformUI;\r
+import org.simantics.Simantics;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.debug.ui.internal.Activator;\r
+import org.simantics.debug.ui.internal.DebugUtils;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.ui.workbench.ResourceEditorPart;\r
+import org.simantics.utils.ui.BundleUtils;\r
+import org.simantics.utils.ui.LayoutUtils;\r
+\r
+public class GraphicalDebuggerEditor extends ResourceEditorPart {\r
+\r
+ public static final String EDITOR_ID = "org.simantics.debug.graphicalDebuggerEditor";\r
+\r
+ private GraphicalDebugger debugger;\r
+ private IAction backAction;\r
+ private IAction forwardAction;\r
+ private IAction refreshAction;\r
+ private IAction findAction;\r
+ private IAction addStatementAction;\r
+ private IAction addResourceAction;\r
+ private Action increaseDepthAction;\r
+ private Action decreaseDepthAction;\r
+\r
+ @Override\r
+ public void createPartControl(Composite parent) {\r
+ // Create UI\r
+ parent.setLayout(LayoutUtils.createNoBorderGridLayout(1));\r
+\r
+ debugger = new GraphicalDebugger(parent, SWT.NONE, getSession(), getInputResource());\r
+ debugger.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));\r
+ debugger.setLayout(LayoutUtils.createNoBorderGridLayout(1));\r
+\r
+ Composite bar = new Composite(debugger, SWT.NONE);\r
+ bar.setLayout(new GridLayout(3, false));\r
+ bar.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));\r
+\r
+ backAction = new BackAction();\r
+ forwardAction = new ForwardAction();\r
+ refreshAction = new RefreshAction();\r
+ findAction = new FindAction();\r
+ addStatementAction = new AddStatementAction();\r
+ addResourceAction = new AddResourceAction();\r
+ increaseDepthAction = new IncreaseDepthAction();\r
+ decreaseDepthAction = new DecreaseDepthAction();\r
+\r
+ ToolBar toolBar = new ToolBar(bar, SWT.HORIZONTAL | SWT.FLAT);\r
+\r
+ new ActionContributionItem(backAction).fill(toolBar, 0);\r
+ new ActionContributionItem(forwardAction).fill(toolBar, 1);\r
+ new Separator().fill(toolBar, 2);\r
+ new ActionContributionItem(refreshAction).fill(toolBar, 3);\r
+ new Separator().fill(toolBar, 4);\r
+ new ActionContributionItem(findAction).fill(toolBar, 5);\r
+ new ActionContributionItem(addStatementAction).fill(toolBar, 6);\r
+ new ActionContributionItem(addResourceAction).fill(toolBar, 7);\r
+ new Separator().fill(toolBar, 8);\r
+ new ActionContributionItem(decreaseDepthAction).fill(toolBar, 9);\r
+ new ActionContributionItem(increaseDepthAction).fill(toolBar, 10);\r
+\r
+ debugger.createResourceText(bar);\r
+ Control dropLabel = debugger.createDropLabel(bar);\r
+ GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.FILL).hint(SWT.DEFAULT, 20).span(3, 1).applyTo(dropLabel);\r
+ Control browser = debugger.createGraph(debugger);\r
+ GridDataFactory.fillDefaults().grab(true, true).span(3, 1).applyTo(browser);\r
+\r
+ debugger.addHistoryListener(new GraphicalDebugger.HistoryListener() {\r
+ @Override\r
+ public void historyChanged() {\r
+ updateActionStates();\r
+ }\r
+ });\r
+\r
+ updateActionStates();\r
+ }\r
+\r
+ @Override\r
+ public void setFocus() {\r
+ if (debugger != null)\r
+ debugger.setFocus();\r
+ }\r
+\r
+ public void back() {\r
+ debugger.back();\r
+ }\r
+\r
+ public void forward() {\r
+ debugger.forward();\r
+ }\r
+\r
+ public void refreshBrowser() {\r
+ debugger.refreshBrowser();\r
+ }\r
+\r
+ private void decreaseDepth() {\r
+ debugger.setDepth(debugger.getDepth() - 1);\r
+ }\r
+\r
+ private void increaseDepth() {\r
+ debugger.setDepth(debugger.getDepth() + 1);\r
+ }\r
+\r
+ private void updateActionStates() {\r
+ backAction.setEnabled(!debugger.hasBackHistory());\r
+ forwardAction.setEnabled(!debugger.hasForwardHistory());\r
+ }\r
+\r
+ class RefreshAction extends Action {\r
+ public RefreshAction() {\r
+ super("Refresh", BundleUtils.getImageDescriptorFromPlugin(SimanticsUI.PLUGIN_ID, "icons/refresh.gif"));\r
+ }\r
+ @Override\r
+ public void run() {\r
+ refreshBrowser();\r
+ }\r
+ }\r
+\r
+ class FindAction extends Action {\r
+ public FindAction() {\r
+ super("Find", BundleUtils.getImageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/cog_blue.png"));\r
+ setToolTipText("Find Resource");\r
+ }\r
+ @Override\r
+ public void run() {\r
+ DebugUtils.find(Simantics.getSession(), debugger);\r
+ }\r
+ }\r
+\r
+ class AddStatementAction extends Action {\r
+ public AddStatementAction() {\r
+ super("AddStatement", BundleUtils.getImageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/cog_add.png"));\r
+ setToolTipText("Add Statement Between Existing Resources");\r
+ }\r
+ @Override\r
+ public void run() {\r
+ try {\r
+ DebugUtils.addStatement(Simantics.getSession(), debugger);\r
+ } catch (DatabaseException e) {\r
+ Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e));\r
+ }\r
+ }\r
+ }\r
+ class AddResourceAction extends Action {\r
+ public AddResourceAction() {\r
+ super("AddResource", BundleUtils.getImageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/cog_add.png"));\r
+ setToolTipText("Add New Related Resource");\r
+ }\r
+ @Override\r
+ public void run() {\r
+ try {\r
+ DebugUtils.addResource(Simantics.getSession(), debugger);\r
+ } catch (DatabaseException e) {\r
+ Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e));\r
+ }\r
+ }\r
+ }\r
+ class BackAction extends Action {\r
+ public BackAction() {\r
+ super("Back", Action.AS_PUSH_BUTTON);\r
+ setToolTipText("Back");\r
+ setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_BACK));\r
+ setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_BACK_DISABLED));\r
+ }\r
+ @Override\r
+ public void run() {\r
+ back();\r
+ updateActionStates();\r
+ }\r
+ }\r
+\r
+ class ForwardAction extends Action {\r
+ public ForwardAction() {\r
+ super("Forward", Action.AS_PUSH_BUTTON);\r
+ setToolTipText("Forward");\r
+ setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_FORWARD));\r
+ setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_FORWARD_DISABLED));\r
+ }\r
+ @Override\r
+ public void run() {\r
+ forward();\r
+ updateActionStates();\r
+ }\r
+ }\r
+ \r
+ class DecreaseDepthAction extends Action {\r
+ public DecreaseDepthAction() {\r
+ super("Decrease", Action.AS_PUSH_BUTTON);\r
+ setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_BACK));\r
+ setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_BACK_DISABLED));\r
+ }\r
+ @Override\r
+ public void run() {\r
+ decreaseDepth();\r
+ }\r
+ }\r
+\r
+ class IncreaseDepthAction extends Action {\r
+ public IncreaseDepthAction() {\r
+ super("Increase", Action.AS_PUSH_BUTTON);\r
+ setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_FORWARD));\r
+ setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_FORWARD_DISABLED));\r
+ }\r
+ @Override\r
+ public void run() {\r
+ increaseDepth();\r
+ }\r
+ }\r
+}\r