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