From: lempinen Date: Thu, 22 Jul 2010 14:09:03 +0000 (+0000) Subject: Step towards more generic referenceTable that can be used also to specify outputs X-Git-Tag: simantics-1.2.0~165 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=66654511325cb8785a3ac625a518bea4d096e702;p=simantics%2Fsysdyn.git Step towards more generic referenceTable that can be used also to specify outputs git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@16797 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ModuleInputTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ModuleInputTab.java index c4ade2ad..74f4b1dc 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ModuleInputTab.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ModuleInputTab.java @@ -1,18 +1,77 @@ package org.simantics.sysdyn.ui.properties; +import java.util.ArrayList; + +import org.eclipse.jface.viewers.ArrayContentProvider; +import org.eclipse.jface.viewers.TableViewerColumn; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.IWorkbenchSite; import org.simantics.browsing.ui.swt.PropertyTabContributorImpl; import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.db.Builtins; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.exception.DatabaseException; import org.simantics.db.management.ISessionContext; +import org.simantics.structural.stubs.StructuralResource2; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.properties.widgets.ReferenceRowEditingSupport; import org.simantics.sysdyn.ui.properties.widgets.ReferenceTable; +import org.simantics.sysdyn.ui.properties.widgets.ReferenceRow; +import org.simantics.sysdyn.ui.properties.widgets.RowProvider; +import org.simantics.sysdyn.ui.properties.widgets.ReferenceRowLabelProvider; public class ModuleInputTab extends PropertyTabContributorImpl { + public static final String FIRSTCOLUMN = "FIRST COLUMN"; + public static final String SECONDCOLUMN = "SECOND COLUMN"; + @Override public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) { - new ReferenceTable(body, support, SWT.NONE); + ReferenceTable referenceTable = new ReferenceTable(body, support, SWT.NONE); + + String[] titles = { FIRSTCOLUMN, SECONDCOLUMN}; + int[] bounds = { 100, 100, 100, 100 }; + for (int i = 0; i < titles.length; i++) { + TableViewerColumn column = new TableViewerColumn(referenceTable.getTableViewer(), SWT.NONE); + column.getColumn().setText(titles[i]); + column.getColumn().setWidth(bounds[i]); + column.getColumn().setResizable(true); + column.getColumn().setMoveable(false); + // enable editing support + column.setEditingSupport(new ReferenceRowEditingSupport(referenceTable.getTableViewer(), i)); + } + referenceTable.setContentProvider (new ArrayContentProvider()); + referenceTable.setLabelProvider (new ReferenceRowLabelProvider()); + + RowProvider rp = new RowProvider() { + + @Override + public ArrayList getRows(ReadGraph graph, Resource module) throws DatabaseException { + Builtins b = graph.getBuiltins(); + SysdynResource sr = SysdynResource.getInstance(graph); + StructuralResource2 sr2 = StructuralResource2.getInstance(graph); + ArrayList result = new ArrayList(); + Resource instanceOf = graph.getSingleObject(module, b.InstanceOf); + Resource configuration = graph.getSingleObject(instanceOf, sr2.IsDefinedBy); + for(Resource input : graph.syncRequest(new ObjectsWithType(configuration, b.ConsistsOf, sr.Input))) { + Resource dependency = null; + for(Resource dep : graph.getObjects(module, sr.IsHeadOf)) { + Resource refersTo = graph.getPossibleObject(dep, sr.RefersTo); + if(refersTo != null && refersTo.equals(input)) { + dependency = dep; + break; + } + } + ReferenceRow rr = new ReferenceRow(module, dependency, input); + result.add(rr); + } + return result; + } + }; + referenceTable.setRowProvider(rp); } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ReferenceRow.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ReferenceRow.java new file mode 100644 index 00000000..10eba6dd --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ReferenceRow.java @@ -0,0 +1,96 @@ +package org.simantics.sysdyn.ui.properties.widgets; + +import org.simantics.databoard.binding.java.StringBindingDefault; +import org.simantics.db.Builtins; +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.sysdyn.SysdynResource; +import org.simantics.ui.SimanticsUI; + +public class ReferenceRow { + + Resource input, module, dependency; + String name; + + public ReferenceRow(Resource module, Resource dependency, Resource input) { + this.module = module; + this.input = input; + this.dependency = dependency; + } + + + public Resource getModule() { + return this.module; + } + + public Resource getInput() { + return this.input; + } + + public Resource getDependency() { + return this.dependency; + } + + public String getName() { + String name = null; + try { + name = SimanticsUI.getSession().syncRequest(new Read() { + + @Override + public String perform(ReadGraph graph) throws DatabaseException { + return (String)graph.getRelatedValue(input, graph.getBuiltins().HasName); + } + }); + } catch (DatabaseException e) { + e.printStackTrace(); + } + return name; + } + + public String getOutputName() { + if(dependency == null) return ""; + + String outputName = null; + try { + outputName = SimanticsUI.getSession().syncRequest(new Read() { + + @Override + public String perform(ReadGraph graph) throws DatabaseException { + Builtins b = graph.getBuiltins(); + SysdynResource sr = SysdynResource.getInstance(graph); + Resource output = graph.getPossibleObject(dependency, sr.HasTail); + return (String)graph.getRelatedValue(output, b.HasName, StringBindingDefault.INSTANCE); + } + }); + } catch (DatabaseException e) { + e.printStackTrace(); + } + return outputName; + } + + public void setRefersTo(final Resource dependency) { + if(dependency != null && dependency.equals(this.dependency)) return; + SimanticsUI.getSession().asyncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + if(getDependency() != null && graph.hasStatement(getDependency(), sr.RefersTo)) + graph.deny(getDependency(), sr.RefersTo); + setDependency(null); + if(dependency != null) { + setDependency(dependency); + graph.claim(getDependency(), SysdynResource.getInstance(graph).RefersTo, input); + } + } + }); + } + + private void setDependency(Resource dependency) { + this.dependency = dependency; + } +} + diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ReferenceRowEditingSupport.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ReferenceRowEditingSupport.java new file mode 100644 index 00000000..3bb2e686 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ReferenceRowEditingSupport.java @@ -0,0 +1,126 @@ +package org.simantics.sysdyn.ui.properties.widgets; + +import java.util.HashMap; + +import org.eclipse.jface.viewers.CellEditor; +import org.eclipse.jface.viewers.ComboBoxCellEditor; +import org.eclipse.jface.viewers.EditingSupport; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.TextCellEditor; +import org.eclipse.swt.SWT; +import org.simantics.db.Builtins; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.request.Read; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.ui.SimanticsUI; + +public class ReferenceRowEditingSupport extends EditingSupport { + private CellEditor editor; + private int column; + private HashMap optionResources; + private String[] options; + private TableViewer tableViewer; + + public ReferenceRowEditingSupport(TableViewer viewer, int column) { + super(viewer); + this.tableViewer = (TableViewer)viewer; + this.column = column; + } + + @Override + protected boolean canEdit(Object element) { + switch (this.column) { + case 0: return false; + default: return true; + } + } + + + @Override + protected CellEditor getCellEditor(Object element) { + // Create the correct editor based on the column index + switch (column) { + case 0: + editor = new TextCellEditor(this.tableViewer.getTable()); + case 1: + ReferenceRow row = (ReferenceRow)element; + final Resource module = row.getModule(); + final Resource inputVariable = row.getInput(); + + optionResources = new HashMap(); + try { + optionResources = SimanticsUI.getSession().syncRequest(new Read>() { + + @Override + public HashMap perform(ReadGraph graph) throws DatabaseException { + Builtins b = graph.getBuiltins(); + SysdynResource sr = SysdynResource.getInstance(graph); + HashMap result = new HashMap(); + for(Resource dependency : graph.syncRequest(new ObjectsWithType(module, sr.IsHeadOf, sr.Dependency))) { + if(graph.getPossibleObject(dependency, sr.RefersTo) == null || + graph.getPossibleObject(dependency, sr.RefersTo).equals(inputVariable)) { + Resource output = graph.getSingleObject(dependency, sr.HasTail); + result.put((String)graph.getRelatedValue(output, b.HasName), dependency); + } + } + return result; + } + }); + } catch (DatabaseException e) { + e.printStackTrace(); + } + + options = optionResources.keySet().toArray(new String[optionResources.keySet().size() + 1]); + options[optionResources.keySet().size()] = ""; + ComboBoxCellEditor ceditor = new ComboBoxCellEditor(this.tableViewer.getTable(), options, SWT.READ_ONLY); + ceditor.setActivationStyle(1); + editor = ceditor; + break; + default: + editor = null; + } + + return editor; + } + + @Override + protected Object getValue(Object element) { + ReferenceRow referenceRow = (ReferenceRow) element; + + switch (this.column) { + case 0: + return referenceRow.getName(); + case 1: + String refersToName = referenceRow.getOutputName(); + if (refersToName == null) return options.length - 1; + for(int i = 0; i < options.length ; i++) { + if(refersToName.equals(options[i])) return i; + } + return options[options.length - 1]; + default: + break; + } + return null; + } + + @Override + protected void setValue(Object element, Object value) { + ReferenceRow referenceRow = (ReferenceRow) element; + String valueString = String.valueOf(value); + switch (this.column) { + case 0: + break; + case 1: + referenceRow.setRefersTo(optionResources.get(options[Integer.parseInt(valueString)])); + break; + default: + break; + } + + getViewer().update(element, null); + } + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ReferenceRowLabelProvider.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ReferenceRowLabelProvider.java new file mode 100644 index 00000000..a618e427 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ReferenceRowLabelProvider.java @@ -0,0 +1,26 @@ +package org.simantics.sysdyn.ui.properties.widgets; + +import org.eclipse.jface.viewers.ITableLabelProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.swt.graphics.Image; + +public class ReferenceRowLabelProvider extends LabelProvider implements ITableLabelProvider { + + @Override + public Image getColumnImage(Object element, int columnIndex) { + return null; + } + + @Override + public String getColumnText(Object element, int columnIndex) { + ReferenceRow referenceRow = (ReferenceRow) element; + switch (columnIndex) { + case 0: + return referenceRow.getName(); + case 1: + return referenceRow.getOutputName(); + default: + throw new RuntimeException("Should not happen"); + } + } +} \ No newline at end of file diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ReferenceTable.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ReferenceTable.java index 56464118..32bb8339 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ReferenceTable.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ReferenceTable.java @@ -1,54 +1,36 @@ package org.simantics.sysdyn.ui.properties.widgets; import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; -import org.eclipse.jface.viewers.ArrayContentProvider; -import org.eclipse.jface.viewers.CellEditor; -import org.eclipse.jface.viewers.ColumnViewer; -import org.eclipse.jface.viewers.ComboBoxCellEditor; -import org.eclipse.jface.viewers.EditingSupport; +import org.eclipse.jface.viewers.IBaseLabelProvider; +import org.eclipse.jface.viewers.IContentProvider; import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ITableLabelProvider; -import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.viewers.TableViewerColumn; -import org.eclipse.jface.viewers.TextCellEditor; import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.ViewerComparator; import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Image; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Table; import org.simantics.browsing.ui.swt.widgets.impl.Widget; import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; -import org.simantics.databoard.binding.java.StringBindingDefault; -import org.simantics.db.Builtins; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.common.request.ObjectsWithType; -import org.simantics.db.common.request.WriteRequest; import org.simantics.db.exception.DatabaseException; import org.simantics.db.management.ISessionContext; +import org.simantics.db.procedure.Listener; import org.simantics.db.request.Read; -import org.simantics.structural.stubs.StructuralResource2; -import org.simantics.sysdyn.SysdynResource; import org.simantics.ui.SimanticsUI; import org.simantics.utils.ui.ISelectionUtils; public class ReferenceTable implements Widget{ - private Table table; private TableViewer tableViewer; - private List references; - public static final String FIRSTCOLUMN = "FIRST COLUMN"; - public static final String SECONDCOLUMN = "SECOND COLUMN"; - public static final String[] PROPS = { FIRSTCOLUMN, SECONDCOLUMN }; + private RowProvider rowProvider; + public static final String FIRSTCOLUMN = "Inputs"; + public static final String SECONDCOLUMN = "Outputs"; + public ReferenceTable(Composite parent, WidgetSupport support, int style) { support.register(this); @@ -56,285 +38,84 @@ public class ReferenceTable implements Widget{ GridLayoutFactory.fillDefaults().applyTo(base); GridDataFactory.fillDefaults().grab(true, true).applyTo(base); - table = new Table(base, SWT.BORDER|SWT.SINGLE|SWT.FULL_SELECTION); + Table table = new Table(base, SWT.BORDER|SWT.SINGLE|SWT.FULL_SELECTION); GridDataFactory.fillDefaults().grab(true, true).applyTo(table); table.setHeaderVisible (true); table.setLinesVisible(true); table.getVerticalBar().setVisible(true); - // Create the viewer and connect it to the view tableViewer = new TableViewer (table); - - String[] titles = { FIRSTCOLUMN, SECONDCOLUMN}; - int[] bounds = { 100, 100, 100, 100 }; - for (int i = 0; i < titles.length; i++) { - TableViewerColumn column = new TableViewerColumn(tableViewer, SWT.NONE); - column.getColumn().setText(titles[i]); - column.getColumn().setWidth(bounds[i]); - column.getColumn().setResizable(true); - column.getColumn().setMoveable(false); - // enable editing support - column.setEditingSupport(new ReferenceRowEditingSupport(tableViewer, i)); - } - - tableViewer.setContentProvider (new ArrayContentProvider()); - tableViewer.setLabelProvider (new ReferenceRowLabelProvider()); tableViewer.setComparator(new ReferenceRowComparator()); + } - references = new ArrayList(); - tableViewer.setInput(references); + public TableViewer getTableViewer() { + return this.tableViewer; + } + + public void setRowProvider(RowProvider rowProvider) { + this.rowProvider = rowProvider; + } + + public void setContentProvider(IContentProvider provider) { + tableViewer.setContentProvider(provider); + } + + public void setLabelProvider(IBaseLabelProvider labelProvider) { + tableViewer.setLabelProvider(labelProvider); } @Override public void setInput(ISessionContext context, Object input) { final Resource module = ISelectionUtils.filterSingleSelection((ISelection)input, Resource.class); - ArrayList referenceRows = null; - try { - referenceRows = SimanticsUI.getSession().syncRequest(new Read>() { - - @Override - public ArrayList perform(ReadGraph graph) throws DatabaseException { - Builtins b = graph.getBuiltins(); - SysdynResource sr = SysdynResource.getInstance(graph); - StructuralResource2 sr2 = StructuralResource2.getInstance(graph); - ArrayList result = new ArrayList(); - Resource instanceOf = graph.getSingleObject(module, b.InstanceOf); - Resource configuration = graph.getSingleObject(instanceOf, sr2.IsDefinedBy); - for(Resource input : graph.syncRequest(new ObjectsWithType(configuration, b.ConsistsOf, sr.Input))) { - Resource dependency = null; - for(Resource dep : graph.getObjects(module, sr.IsHeadOf)) { - Resource refersTo = graph.getPossibleObject(dep, sr.RefersTo); - if(refersTo != null && refersTo.equals(input)) { - dependency = dep; - break; - } - } - ReferenceRow rr = new ReferenceRow(module, dependency, input); - result.add(rr); - } - return result; - } - }); - } catch (DatabaseException e) { - e.printStackTrace(); - } - tableViewer.setInput(referenceRows); - } - - public class ReferenceRow { - - Resource input, module, dependency; - String name; - - public ReferenceRow(Resource module, Resource dependency, Resource input) { - this.module = module; - this.input = input; - this.dependency = dependency; - } - - - public Resource getModule() { - return this.module; - } - - public Resource getInput() { - return this.input; - } - - public Resource getDependency() { - return this.dependency; - } - - public String getName() { - String name = null; + if(this.rowProvider != null) { try { - name = SimanticsUI.getSession().syncRequest(new Read() { + SimanticsUI.getSession().syncRequest(new Read>() { @Override - public String perform(ReadGraph graph) throws DatabaseException { - return (String)graph.getRelatedValue(input, graph.getBuiltins().HasName); + public ArrayList perform(ReadGraph graph) throws DatabaseException { + return rowProvider.getRows(graph, module); } - }); - } catch (DatabaseException e) { - e.printStackTrace(); - } - return name; - } - - public String getOutputName() { - if(dependency == null) return ""; + } , new Listener>() { - String outputName = null; - try { - outputName = SimanticsUI.getSession().syncRequest(new Read() { + @Override + public boolean isDisposed() { + if(tableViewer != null && tableViewer.getTable() != null) + return getTableViewer().getTable().isDisposed(); + else + return true; + } @Override - public String perform(ReadGraph graph) throws DatabaseException { - Builtins b = graph.getBuiltins(); - SysdynResource sr = SysdynResource.getInstance(graph); - Resource output = graph.getPossibleObject(dependency, sr.HasTail); - return (String)graph.getRelatedValue(output, b.HasName, StringBindingDefault.INSTANCE); + public void execute(final ArrayList result) { + if(!isDisposed()) + getTableViewer().getTable().getDisplay().asyncExec(new Runnable() { + + @Override + public void run() { + if(!isDisposed()) + getTableViewer().setInput(result); + } + }); } - }); - } catch (DatabaseException e) { - e.printStackTrace(); - } - return outputName; - } - private void setRefersTo(final Resource dependency) { - System.out.println("DEPENDENCY: " + dependency + " (" + getDependency() + ")"); - if(dependency != null && dependency.equals(this.dependency)) return; - SimanticsUI.getSession().asyncRequest(new WriteRequest() { - @Override - public void perform(WriteGraph graph) throws DatabaseException { - SysdynResource sr = SysdynResource.getInstance(graph); - if(getDependency() != null && graph.hasStatement(getDependency(), sr.RefersTo)) - graph.deny(getDependency(), sr.RefersTo); - setDependency(null); - if(dependency != null) { - setDependency(dependency); - graph.claim(getDependency(), SysdynResource.getInstance(graph).RefersTo, input); + @Override + public void exception(Throwable t) { } } - }); - } - - private void setDependency(Resource dependency) { - this.dependency = dependency; - } - } - - private class ReferenceRowLabelProvider extends LabelProvider implements ITableLabelProvider { - - @Override - public Image getColumnImage(Object element, int columnIndex) { - return null; - } - - @Override - public String getColumnText(Object element, int columnIndex) { - ReferenceRow referenceRow = (ReferenceRow) element; - switch (columnIndex) { - case 0: - return referenceRow.getName(); - case 1: - return referenceRow.getOutputName(); - default: - throw new RuntimeException("Should not happen"); + ); + } catch (DatabaseException e) { + e.printStackTrace(); } } - } private class ReferenceRowComparator extends ViewerComparator { @Override public int compare(Viewer viewer, Object e1, Object e2) { - return 0; + ReferenceRow rr1 = (ReferenceRow)e1; + ReferenceRow rr2 = (ReferenceRow)e2; + return rr1.getName().compareTo(rr2.getName()); } } - public class ReferenceRowEditingSupport extends EditingSupport { - private CellEditor editor; - private int column; - private HashMap optionResources; - private String[] options; - - public ReferenceRowEditingSupport(ColumnViewer viewer, int column) { - super(viewer); - this.column = column; - } - - @Override - protected boolean canEdit(Object element) { - switch (this.column) { - case 0: return false; - default: return true; - } - } - - @Override - protected CellEditor getCellEditor(Object element) { - // Create the correct editor based on the column index - switch (column) { - case 0: - editor = new TextCellEditor(table); - case 1: - ReferenceRow row = (ReferenceRow)element; - final Resource module = row.getModule(); - final Resource inputVariable = row.getInput(); - - optionResources = new HashMap(); - try { - optionResources = SimanticsUI.getSession().syncRequest(new Read>() { - - @Override - public HashMap perform(ReadGraph graph) throws DatabaseException { - Builtins b = graph.getBuiltins(); - SysdynResource sr = SysdynResource.getInstance(graph); - HashMap result = new HashMap(); - for(Resource dependency : graph.syncRequest(new ObjectsWithType(module, sr.IsHeadOf, sr.Dependency))) { - if(graph.getPossibleObject(dependency, sr.RefersTo) == null || - graph.getPossibleObject(dependency, sr.RefersTo).equals(inputVariable)) { - Resource output = graph.getSingleObject(dependency, sr.HasTail); - result.put((String)graph.getRelatedValue(output, b.HasName), dependency); - } - } - return result; - } - }); - } catch (DatabaseException e) { - e.printStackTrace(); - } - - options = optionResources.keySet().toArray(new String[optionResources.keySet().size() + 1]); - options[optionResources.keySet().size()] = ""; - editor = new ComboBoxCellEditor(table, options, SWT.READ_ONLY); - break; - default: - editor = null; - } - - return editor; - } - - @Override - protected Object getValue(Object element) { - ReferenceRow referenceRow = (ReferenceRow) element; - - switch (this.column) { - case 0: - return referenceRow.getName(); - case 1: - String refersToName = referenceRow.getOutputName(); - if (refersToName == null) return options.length - 1; - for(int i = 0; i < options.length ; i++) { - if(refersToName.equals(options[i])) return i; - } - return options[options.length - 1]; - default: - break; - } - return null; - } - - @Override - protected void setValue(Object element, Object value) { - ReferenceRow referenceRow = (ReferenceRow) element; - String valueString = String.valueOf(value); - switch (this.column) { - case 0: - break; - case 1: - referenceRow.setRefersTo(optionResources.get(options[Integer.parseInt(valueString)])); - break; - default: - break; - } - - getViewer().update(element, null); - } - - } - } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/RowProvider.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/RowProvider.java new file mode 100644 index 00000000..4c1bce70 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/RowProvider.java @@ -0,0 +1,11 @@ +package org.simantics.sysdyn.ui.properties.widgets; + +import java.util.ArrayList; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; + +public abstract class RowProvider { + public abstract ArrayList getRows(ReadGraph graph, Resource module) throws DatabaseException; +}