From 1be79a2ed53c79376c5e4e72da0ddeabe62f22a3 Mon Sep 17 00:00:00 2001 From: lempinen Date: Thu, 6 Jun 2013 07:58:43 +0000 Subject: [PATCH] SensitivityAnalysisExperimentTab displays information of the first parameter when the view is initialized (fixes #4309) git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@27510 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../SensitivityAnalysisExperimentTab.java | 53 +++++++++++++++++-- 1 file changed, 50 insertions(+), 3 deletions(-) diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/SensitivityAnalysisExperimentTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/SensitivityAnalysisExperimentTab.java index 68ae677c..2dcfc4ca 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/SensitivityAnalysisExperimentTab.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/SensitivityAnalysisExperimentTab.java @@ -5,12 +5,14 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; +import org.eclipse.core.runtime.IAdaptable; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.resource.LocalResourceManager; import org.eclipse.jface.viewers.ISelectionProvider; import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.ScrolledComposite; import org.eclipse.swt.events.DisposeEvent; @@ -19,10 +21,19 @@ import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeItem; import org.eclipse.ui.IWorkbenchSite; +import org.simantics.browsing.ui.BuiltinKeys; +import org.simantics.browsing.ui.Column; +import org.simantics.browsing.ui.Column.Align; +import org.simantics.browsing.ui.NodeContext; +import org.simantics.browsing.ui.common.ColumnKeys; +import org.simantics.browsing.ui.common.NodeContextBuilder.MapNodeContext; import org.simantics.browsing.ui.swt.SingleSelectionInputSource; import org.simantics.browsing.ui.swt.widgets.Button; import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite; @@ -130,20 +141,56 @@ public class SensitivityAnalysisExperimentTab extends LabelPropertyTabContributo // (Ontology-based) GraphExplorer displaying range axis and variables mapped to those axis explorer = new AxisAndVariablesExplorerComposite(ArrayMap.keys( - "displaySelectors", "displayFilter").values(false, false), site, content, support, SWT.FULL_SELECTION | SWT.BORDER | SWT.SINGLE); + "displaySelectors", "displayFilter", "treeView").values(false, false, true), site, content, support, SWT.FULL_SELECTION | SWT.BORDER | SWT.SINGLE); + explorer.setBrowseContexts(SysdynResource.URIs.SensitivityAnalysisExperiment_ParameterBrowseContext); explorer.setInputSource(new SingleSelectionInputSource( Resource.class)); explorer.getExplorer().setAutoExpandLevel(2); // Expand everything in the beginning + explorer.setColumns( new Column[] { new Column(ColumnKeys.SINGLE, Align.LEFT, 0, "", true) }); explorer.finish(); - + + ((Tree)explorer.getExplorerControl()).addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { updateSelection(context); } }); - + /* Listener for displaying information of the first parameter during view initialization + * The view does not have focus, so normal selection listener mechanisms do not work. + * Need to do it the hard way. + */ + Listener listener = new Listener() { + + boolean flag = false; + @Override + public void handleEvent(Event event) { + switch (event.type) { + case SWT.Activate: + case SWT.Show: + case SWT.Paint: + { + if(!flag && ((Tree) event.widget).getItems().length > 0) { + flag = true; + TreeItem item = ((Tree) event.widget).getItems()[0]; + IAdaptable adaptable = (IAdaptable) item.getData(); + MapNodeContext nc = (MapNodeContext) adaptable.getAdapter(NodeContext.class); + parameterSupport.fireInput(context, new StructuredSelection(nc.getConstant(BuiltinKeys.INPUT))); + propertyContainer.setContent(content); + Point size = content.computeSize(SWT.DEFAULT, SWT.DEFAULT); + propertyContainer.setMinSize(size); + } + } + } + } + }; + + Tree tree = explorer.getExplorerControl(); + tree.addListener(SWT.Activate, listener); + tree.addListener(SWT.Show, listener); + tree.addListener(SWT.Paint,listener); + /* End listener for displaying information for first parameter during view initialization*/ explorer.addDisposeListener(new DisposeListener() { -- 2.47.1