From: lempinen Date: Tue, 14 Dec 2010 13:04:22 +0000 (+0000) Subject: Enumeration tab updated to use graph explorer X-Git-Tag: 2011-04-05-db-merge-trunk~49 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=b42ca13d487ce45121bfdfcec0d33859aac4cfaa;p=simantics%2Fsysdyn.git Enumeration tab updated to use graph explorer git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@19150 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn.ui/plugin.xml b/org.simantics.sysdyn.ui/plugin.xml index c9117399..af4921f5 100644 --- a/org.simantics.sysdyn.ui/plugin.xml +++ b/org.simantics.sysdyn.ui/plugin.xml @@ -47,13 +47,6 @@ id="org.simantics.sysdyn.ui.category" name="System Dynamics"> - - + + + + @@ -701,6 +701,13 @@ preference="2.0"> + + + + diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EnumerationTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EnumerationTab.java index 0e43aba7..d006e9c2 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EnumerationTab.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EnumerationTab.java @@ -1,34 +1,26 @@ package org.simantics.sysdyn.ui.properties; -import java.util.ArrayList; -import java.util.List; - import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.TableEditor; -import org.eclipse.swt.events.FocusAdapter; -import org.eclipse.swt.events.FocusEvent; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.TableItem; -import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.Tree; import org.eclipse.ui.IWorkbenchSite; import org.simantics.browsing.ui.swt.PropertyTabContributorImpl; +import org.simantics.browsing.ui.swt.SingleSelectionInputSource; import org.simantics.browsing.ui.swt.widgets.Button; +import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite; import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory; import org.simantics.browsing.ui.swt.widgets.Table; import org.simantics.browsing.ui.swt.widgets.TrackedText; -import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl; import org.simantics.browsing.ui.swt.widgets.impl.Widget; import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; -import org.simantics.databoard.Bindings; import org.simantics.db.Builtins; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; @@ -44,11 +36,15 @@ import org.simantics.sysdyn.SysdynResource; import org.simantics.sysdyn.ui.properties.widgets.factories.VariableNamePropertyModifier; import org.simantics.sysdyn.ui.properties.widgets.factories.VariableNameValidator; import org.simantics.ui.SimanticsUI; -import org.simantics.utils.datastructures.Pair; +import org.simantics.ui.utils.AdaptionUtils; +import org.simantics.utils.datastructures.ArrayMap; import org.simantics.utils.ui.ISelectionUtils; public class EnumerationTab extends PropertyTabContributorImpl { + GraphExplorerComposite indexExplorer; + + Table table; @Override public void createControls(Composite body, IWorkbenchSite site, @@ -65,6 +61,29 @@ public class EnumerationTab extends PropertyTabContributorImpl { GridDataFactory.fillDefaults().grab(true, false).span(2,1).applyTo(nameText.getWidget()); + + + indexExplorer = new GraphExplorerComposite(ArrayMap.keys( + "displaySelectors", "displayFilter").values(false, false), site, container, support, SWT.FULL_SELECTION | SWT.BORDER | SWT.MULTI); + + indexExplorer + .setBrowseContexts("http://www.simantics.org/Sysdyn-1.0/EnumerationIndexes"); + indexExplorer.setInputSource(new SingleSelectionInputSource( + Resource.class)); + + indexExplorer.finish(); + + GridDataFactory.fillDefaults().grab(true, true).span(2, 1).applyTo( + indexExplorer); + + Control c = indexExplorer.getExplorerControl(); + if (c instanceof Tree) + ((Tree) c).setLinesVisible(true); + + + /* + + table = new Table(container, support, SWT.BORDER); table.setItemFactory(new ReadFactoryImpl>>() { @@ -161,6 +180,11 @@ public class EnumerationTab extends PropertyTabContributorImpl { } }); + + + + */ + Button add = new Button(container, support, SWT.None); add.setText("Add index"); @@ -251,24 +275,26 @@ public class EnumerationTab extends PropertyTabContributorImpl { @Override public void widgetSelected(SelectionEvent e) { - TableItem[] items = table.getWidget().getSelection(); - final ArrayList resources = new ArrayList(); - for(int i = 0; i < items.length; i++) { - if(items[i].getData() instanceof Resource) - resources.add((Resource)items[i].getData()); - } + ISelectionProvider selectionProvider = (ISelectionProvider)indexExplorer.getAdapter(ISelectionProvider.class); + final IStructuredSelection selection = (IStructuredSelection)selectionProvider.getSelection(); + try { SimanticsUI.getSession().syncRequest(new WriteRequest() { @Override public void perform(WriteGraph graph) throws DatabaseException { - for(Resource r : resources) + for(Object o : selection.toList()) { + Resource r = AdaptionUtils.adaptToSingle(o, Resource.class); + if(r == null) + continue; OrderedSetUtils.remove(graph, enumerationIndexes, r); + } } }); } catch (DatabaseException e1) { e1.printStackTrace(); } + } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/EnumerationIndexLabeler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/EnumerationIndexLabeler.java new file mode 100644 index 00000000..a740831f --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/EnumerationIndexLabeler.java @@ -0,0 +1,20 @@ +package org.simantics.sysdyn.ui.properties.widgets.arrays; + +import org.simantics.browsing.ui.graph.contributor.labeler.LabelerContributor; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; + +public class EnumerationIndexLabeler extends LabelerContributor{ + + @Override + public String getLabel(ReadGraph graph, EnumerationIndexNode index) throws DatabaseException { + Resource r = index.data; + if(r == null) return "Null resource"; + String name = graph.getPossibleRelatedValue(r, Layer0.getInstance(graph).HasName); + return name == null ? "No name" : name; + } + + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/EnumerationIndexNode.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/EnumerationIndexNode.java new file mode 100644 index 00000000..94909cda --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/EnumerationIndexNode.java @@ -0,0 +1,72 @@ +package org.simantics.sysdyn.ui.properties.widgets.arrays; + +import org.simantics.browsing.ui.common.node.AbstractNode; +import org.simantics.browsing.ui.common.node.IModifiableNode; +import org.simantics.browsing.ui.content.Labeler.Modifier; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.request.Read; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.ui.utils.VariableNameUtils; +import org.simantics.ui.SimanticsUI; + +public class EnumerationIndexNode extends AbstractNode implements IModifiableNode { + + public EnumerationIndexNode(Resource resource) { + super(resource); + } + + @Override + public Modifier getModifier(String columnId) { + Modifier modifier = new Modifier() { + + @Override + public String getValue() { + Read request = + new Read() { + + @Override + public String perform(ReadGraph graph) throws DatabaseException { + String name = graph.getPossibleRelatedValue(data, Layer0.getInstance(graph).HasName); + return name != null ? name : ""; + } + + }; + try { + return SimanticsUI.getSession().syncRequest(request); + } catch (DatabaseException e) { + e.printStackTrace(); + return ""; + } + } + + @Override + public String isValid(String label) { + if(!VariableNameUtils.isValid(label)) + return "Not valid"; + return null; + } + + @Override + public void modify(final String label) { + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + graph.claimLiteral(data, Layer0.getInstance(graph).HasName, label); + } + }); + } + + }; + + return modifier; + + + + + } + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/EnumerationIndexes.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/EnumerationIndexes.java new file mode 100644 index 00000000..fcf13e91 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/EnumerationIndexes.java @@ -0,0 +1,40 @@ +package org.simantics.sysdyn.ui.properties.widgets.arrays; + +import java.util.ArrayList; +import java.util.Collection; + +import org.simantics.browsing.ui.common.node.AbstractNode; +import org.simantics.browsing.ui.graph.impl.contributor.viewpoint.ViewpointContributorImpl; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.utils.OrderedSetUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.sysdyn.SysdynResource; + +public class EnumerationIndexes extends ViewpointContributorImpl { + + @Override + public Collection getContribution(ReadGraph graph, Resource input) + throws DatabaseException { + if(input == null) + return null; + SysdynResource sr = SysdynResource.getInstance(graph); + if(!graph.isInstanceOf(input, sr.Enumeration)) + return null; + Resource enumerationIndexList = graph.getPossibleObject(input, sr.HasEnumerationIndexes); + if(enumerationIndexList == null) + return null; + ArrayList> result = new ArrayList>(); + for(Resource r : OrderedSetUtils.toList(graph, enumerationIndexList)) { + result.add(new EnumerationIndexNode(r)); + } + return result; + } + + @Override + public String getViewpointId() { + return "Enumeration indexes"; + } + + +}