package org.simantics.sysdyn.ui.properties;\r
\r
+import java.util.ArrayList;\r
+\r
+import org.eclipse.jface.viewers.ArrayContentProvider;\r
+import org.eclipse.jface.viewers.TableViewerColumn;\r
import org.eclipse.swt.SWT;\r
import org.eclipse.swt.widgets.Composite;\r
import org.eclipse.ui.IWorkbenchSite;\r
import org.simantics.browsing.ui.swt.PropertyTabContributorImpl;\r
import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
+import org.simantics.db.Builtins;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.request.ObjectsWithType;\r
+import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.management.ISessionContext;\r
+import org.simantics.structural.stubs.StructuralResource2;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.ui.properties.widgets.ReferenceRowEditingSupport;\r
import org.simantics.sysdyn.ui.properties.widgets.ReferenceTable;\r
+import org.simantics.sysdyn.ui.properties.widgets.ReferenceRow;\r
+import org.simantics.sysdyn.ui.properties.widgets.RowProvider;\r
+import org.simantics.sysdyn.ui.properties.widgets.ReferenceRowLabelProvider;\r
\r
public class ModuleInputTab extends PropertyTabContributorImpl {\r
\r
+ public static final String FIRSTCOLUMN = "FIRST COLUMN";\r
+ public static final String SECONDCOLUMN = "SECOND COLUMN";\r
+ \r
@Override\r
public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) {\r
- new ReferenceTable(body, support, SWT.NONE);\r
+ ReferenceTable referenceTable = new ReferenceTable(body, support, SWT.NONE);\r
+ \r
+ String[] titles = { FIRSTCOLUMN, SECONDCOLUMN};\r
+ int[] bounds = { 100, 100, 100, 100 };\r
+ for (int i = 0; i < titles.length; i++) {\r
+ TableViewerColumn column = new TableViewerColumn(referenceTable.getTableViewer(), SWT.NONE);\r
+ column.getColumn().setText(titles[i]);\r
+ column.getColumn().setWidth(bounds[i]);\r
+ column.getColumn().setResizable(true);\r
+ column.getColumn().setMoveable(false);\r
+ // enable editing support\r
+ column.setEditingSupport(new ReferenceRowEditingSupport(referenceTable.getTableViewer(), i));\r
+ }\r
+ referenceTable.setContentProvider (new ArrayContentProvider());\r
+ referenceTable.setLabelProvider (new ReferenceRowLabelProvider());\r
+ \r
+ RowProvider rp = new RowProvider() {\r
+ \r
+ @Override\r
+ public ArrayList<ReferenceRow> getRows(ReadGraph graph, Resource module) throws DatabaseException {\r
+ Builtins b = graph.getBuiltins();\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ StructuralResource2 sr2 = StructuralResource2.getInstance(graph);\r
+ ArrayList<ReferenceRow> result = new ArrayList<ReferenceRow>();\r
+ Resource instanceOf = graph.getSingleObject(module, b.InstanceOf);\r
+ Resource configuration = graph.getSingleObject(instanceOf, sr2.IsDefinedBy);\r
+ for(Resource input : graph.syncRequest(new ObjectsWithType(configuration, b.ConsistsOf, sr.Input))) {\r
+ Resource dependency = null;\r
+ for(Resource dep : graph.getObjects(module, sr.IsHeadOf)) {\r
+ Resource refersTo = graph.getPossibleObject(dep, sr.RefersTo);\r
+ if(refersTo != null && refersTo.equals(input)) {\r
+ dependency = dep;\r
+ break;\r
+ }\r
+ }\r
+ ReferenceRow rr = new ReferenceRow(module, dependency, input); \r
+ result.add(rr);\r
+ }\r
+ return result;\r
+ }\r
+ };\r
+ referenceTable.setRowProvider(rp);\r
}\r
\r
}\r
--- /dev/null
+package org.simantics.sysdyn.ui.properties.widgets;\r
+\r
+import org.simantics.databoard.binding.java.StringBindingDefault;\r
+import org.simantics.db.Builtins;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.request.Read;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.ui.SimanticsUI;\r
+\r
+public class ReferenceRow {\r
+\r
+ Resource input, module, dependency;\r
+ String name;\r
+\r
+ public ReferenceRow(Resource module, Resource dependency, Resource input) {\r
+ this.module = module;\r
+ this.input = input;\r
+ this.dependency = dependency;\r
+ }\r
+\r
+\r
+ public Resource getModule() {\r
+ return this.module;\r
+ }\r
+\r
+ public Resource getInput() {\r
+ return this.input;\r
+ }\r
+\r
+ public Resource getDependency() {\r
+ return this.dependency;\r
+ }\r
+\r
+ public String getName() {\r
+ String name = null;\r
+ try {\r
+ name = SimanticsUI.getSession().syncRequest(new Read<String>() {\r
+\r
+ @Override\r
+ public String perform(ReadGraph graph) throws DatabaseException {\r
+ return (String)graph.getRelatedValue(input, graph.getBuiltins().HasName);\r
+ }\r
+ });\r
+ } catch (DatabaseException e) {\r
+ e.printStackTrace();\r
+ }\r
+ return name;\r
+ }\r
+\r
+ public String getOutputName() {\r
+ if(dependency == null) return "";\r
+\r
+ String outputName = null;\r
+ try {\r
+ outputName = SimanticsUI.getSession().syncRequest(new Read<String>() {\r
+\r
+ @Override\r
+ public String perform(ReadGraph graph) throws DatabaseException {\r
+ Builtins b = graph.getBuiltins();\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ Resource output = graph.getPossibleObject(dependency, sr.HasTail);\r
+ return (String)graph.getRelatedValue(output, b.HasName, StringBindingDefault.INSTANCE);\r
+ }\r
+ });\r
+ } catch (DatabaseException e) {\r
+ e.printStackTrace();\r
+ }\r
+ return outputName;\r
+ }\r
+\r
+ public void setRefersTo(final Resource dependency) {\r
+ if(dependency != null && dependency.equals(this.dependency)) return;\r
+ SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
+ @Override\r
+ public void perform(WriteGraph graph) throws DatabaseException {\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ if(getDependency() != null && graph.hasStatement(getDependency(), sr.RefersTo))\r
+ graph.deny(getDependency(), sr.RefersTo);\r
+ setDependency(null);\r
+ if(dependency != null) {\r
+ setDependency(dependency);\r
+ graph.claim(getDependency(), SysdynResource.getInstance(graph).RefersTo, input);\r
+ }\r
+ }\r
+ });\r
+ }\r
+ \r
+ private void setDependency(Resource dependency) {\r
+ this.dependency = dependency;\r
+ }\r
+}\r
+\r
--- /dev/null
+package org.simantics.sysdyn.ui.properties.widgets;\r
+\r
+import java.util.HashMap;\r
+\r
+import org.eclipse.jface.viewers.CellEditor;\r
+import org.eclipse.jface.viewers.ComboBoxCellEditor;\r
+import org.eclipse.jface.viewers.EditingSupport;\r
+import org.eclipse.jface.viewers.TableViewer;\r
+import org.eclipse.jface.viewers.TextCellEditor;\r
+import org.eclipse.swt.SWT;\r
+import org.simantics.db.Builtins;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.request.ObjectsWithType;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.request.Read;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.ui.SimanticsUI;\r
+\r
+public class ReferenceRowEditingSupport extends EditingSupport {\r
+ private CellEditor editor;\r
+ private int column;\r
+ private HashMap<String, Resource> optionResources;\r
+ private String[] options;\r
+ private TableViewer tableViewer;\r
+\r
+ public ReferenceRowEditingSupport(TableViewer viewer, int column) {\r
+ super(viewer);\r
+ this.tableViewer = (TableViewer)viewer;\r
+ this.column = column;\r
+ }\r
+\r
+ @Override\r
+ protected boolean canEdit(Object element) {\r
+ switch (this.column) {\r
+ case 0: return false;\r
+ default: return true;\r
+ }\r
+ }\r
+\r
+ \r
+ @Override\r
+ protected CellEditor getCellEditor(Object element) {\r
+ // Create the correct editor based on the column index\r
+ switch (column) {\r
+ case 0: \r
+ editor = new TextCellEditor(this.tableViewer.getTable());\r
+ case 1:\r
+ ReferenceRow row = (ReferenceRow)element;\r
+ final Resource module = row.getModule();\r
+ final Resource inputVariable = row.getInput();\r
+\r
+ optionResources = new HashMap<String, Resource>();\r
+ try {\r
+ optionResources = SimanticsUI.getSession().syncRequest(new Read<HashMap<String, Resource>>() {\r
+\r
+ @Override\r
+ public HashMap<String, Resource> perform(ReadGraph graph) throws DatabaseException {\r
+ Builtins b = graph.getBuiltins();\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ HashMap<String, Resource> result = new HashMap<String, Resource>();\r
+ for(Resource dependency : graph.syncRequest(new ObjectsWithType(module, sr.IsHeadOf, sr.Dependency))) {\r
+ if(graph.getPossibleObject(dependency, sr.RefersTo) == null ||\r
+ graph.getPossibleObject(dependency, sr.RefersTo).equals(inputVariable)) {\r
+ Resource output = graph.getSingleObject(dependency, sr.HasTail);\r
+ result.put((String)graph.getRelatedValue(output, b.HasName), dependency);\r
+ }\r
+ }\r
+ return result;\r
+ }\r
+ });\r
+ } catch (DatabaseException e) {\r
+ e.printStackTrace();\r
+ }\r
+\r
+ options = optionResources.keySet().toArray(new String[optionResources.keySet().size() + 1]);\r
+ options[optionResources.keySet().size()] = "";\r
+ ComboBoxCellEditor ceditor = new ComboBoxCellEditor(this.tableViewer.getTable(), options, SWT.READ_ONLY);\r
+ ceditor.setActivationStyle(1);\r
+ editor = ceditor;\r
+ break;\r
+ default:\r
+ editor = null;\r
+ }\r
+\r
+ return editor;\r
+ }\r
+\r
+ @Override\r
+ protected Object getValue(Object element) {\r
+ ReferenceRow referenceRow = (ReferenceRow) element;\r
+\r
+ switch (this.column) {\r
+ case 0:\r
+ return referenceRow.getName();\r
+ case 1:\r
+ String refersToName = referenceRow.getOutputName();\r
+ if (refersToName == null) return options.length - 1;\r
+ for(int i = 0; i < options.length ; i++) {\r
+ if(refersToName.equals(options[i])) return i;\r
+ }\r
+ return options[options.length - 1];\r
+ default:\r
+ break;\r
+ }\r
+ return null;\r
+ }\r
+\r
+ @Override\r
+ protected void setValue(Object element, Object value) {\r
+ ReferenceRow referenceRow = (ReferenceRow) element;\r
+ String valueString = String.valueOf(value);\r
+ switch (this.column) {\r
+ case 0:\r
+ break;\r
+ case 1:\r
+ referenceRow.setRefersTo(optionResources.get(options[Integer.parseInt(valueString)]));\r
+ break;\r
+ default:\r
+ break;\r
+ }\r
+\r
+ getViewer().update(element, null);\r
+ }\r
+\r
+}\r
package org.simantics.sysdyn.ui.properties.widgets;\r
\r
import java.util.ArrayList;\r
-import java.util.HashMap;\r
-import java.util.List;\r
-\r
import org.eclipse.jface.layout.GridDataFactory;\r
import org.eclipse.jface.layout.GridLayoutFactory;\r
-import org.eclipse.jface.viewers.ArrayContentProvider;\r
-import org.eclipse.jface.viewers.CellEditor;\r
-import org.eclipse.jface.viewers.ColumnViewer;\r
-import org.eclipse.jface.viewers.ComboBoxCellEditor;\r
-import org.eclipse.jface.viewers.EditingSupport;\r
+import org.eclipse.jface.viewers.IBaseLabelProvider;\r
+import org.eclipse.jface.viewers.IContentProvider;\r
import org.eclipse.jface.viewers.ISelection;\r
-import org.eclipse.jface.viewers.ITableLabelProvider;\r
-import org.eclipse.jface.viewers.LabelProvider;\r
import org.eclipse.jface.viewers.TableViewer;\r
-import org.eclipse.jface.viewers.TableViewerColumn;\r
-import org.eclipse.jface.viewers.TextCellEditor;\r
import org.eclipse.jface.viewers.Viewer;\r
import org.eclipse.jface.viewers.ViewerComparator;\r
import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.graphics.Image;\r
import org.eclipse.swt.widgets.Composite;\r
import org.eclipse.swt.widgets.Table;\r
import org.simantics.browsing.ui.swt.widgets.impl.Widget;\r
import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
-import org.simantics.databoard.binding.java.StringBindingDefault;\r
-import org.simantics.db.Builtins;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
-import org.simantics.db.WriteGraph;\r
-import org.simantics.db.common.request.ObjectsWithType;\r
-import org.simantics.db.common.request.WriteRequest;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.management.ISessionContext;\r
+import org.simantics.db.procedure.Listener;\r
import org.simantics.db.request.Read;\r
-import org.simantics.structural.stubs.StructuralResource2;\r
-import org.simantics.sysdyn.SysdynResource;\r
import org.simantics.ui.SimanticsUI;\r
import org.simantics.utils.ui.ISelectionUtils;\r
\r
public class ReferenceTable implements Widget{\r
\r
- private Table table;\r
private TableViewer tableViewer;\r
- private List<ReferenceRow> references;\r
- public static final String FIRSTCOLUMN = "FIRST COLUMN";\r
- public static final String SECONDCOLUMN = "SECOND COLUMN";\r
- public static final String[] PROPS = { FIRSTCOLUMN, SECONDCOLUMN };\r
+ private RowProvider rowProvider;\r
\r
+ public static final String FIRSTCOLUMN = "Inputs";\r
+ public static final String SECONDCOLUMN = "Outputs";\r
+ \r
public ReferenceTable(Composite parent, WidgetSupport support, int style) {\r
support.register(this);\r
\r
GridLayoutFactory.fillDefaults().applyTo(base);\r
GridDataFactory.fillDefaults().grab(true, true).applyTo(base);\r
\r
- table = new Table(base, SWT.BORDER|SWT.SINGLE|SWT.FULL_SELECTION);\r
+ Table table = new Table(base, SWT.BORDER|SWT.SINGLE|SWT.FULL_SELECTION);\r
GridDataFactory.fillDefaults().grab(true, true).applyTo(table);\r
table.setHeaderVisible (true);\r
table.setLinesVisible(true);\r
table.getVerticalBar().setVisible(true);\r
\r
- // Create the viewer and connect it to the view\r
tableViewer = new TableViewer (table);\r
-\r
- String[] titles = { FIRSTCOLUMN, SECONDCOLUMN};\r
- int[] bounds = { 100, 100, 100, 100 };\r
- for (int i = 0; i < titles.length; i++) {\r
- TableViewerColumn column = new TableViewerColumn(tableViewer, SWT.NONE);\r
- column.getColumn().setText(titles[i]);\r
- column.getColumn().setWidth(bounds[i]);\r
- column.getColumn().setResizable(true);\r
- column.getColumn().setMoveable(false);\r
- // enable editing support\r
- column.setEditingSupport(new ReferenceRowEditingSupport(tableViewer, i));\r
- }\r
-\r
- tableViewer.setContentProvider (new ArrayContentProvider());\r
- tableViewer.setLabelProvider (new ReferenceRowLabelProvider());\r
tableViewer.setComparator(new ReferenceRowComparator());\r
+ }\r
\r
- references = new ArrayList<ReferenceRow>(); \r
- tableViewer.setInput(references);\r
+ public TableViewer getTableViewer() {\r
+ return this.tableViewer;\r
+ }\r
+\r
+ public void setRowProvider(RowProvider rowProvider) {\r
+ this.rowProvider = rowProvider;\r
+ }\r
+ \r
+ public void setContentProvider(IContentProvider provider) {\r
+ tableViewer.setContentProvider(provider);\r
+ }\r
+ \r
+ public void setLabelProvider(IBaseLabelProvider labelProvider) {\r
+ tableViewer.setLabelProvider(labelProvider);\r
}\r
\r
@Override\r
public void setInput(ISessionContext context, Object input) {\r
final Resource module = ISelectionUtils.filterSingleSelection((ISelection)input, Resource.class);\r
- ArrayList<ReferenceRow> referenceRows = null;\r
- try {\r
- referenceRows = SimanticsUI.getSession().syncRequest(new Read<ArrayList<ReferenceRow>>() {\r
-\r
- @Override\r
- public ArrayList<ReferenceRow> perform(ReadGraph graph) throws DatabaseException {\r
- Builtins b = graph.getBuiltins();\r
- SysdynResource sr = SysdynResource.getInstance(graph);\r
- StructuralResource2 sr2 = StructuralResource2.getInstance(graph);\r
- ArrayList<ReferenceRow> result = new ArrayList<ReferenceRow>();\r
- Resource instanceOf = graph.getSingleObject(module, b.InstanceOf);\r
- Resource configuration = graph.getSingleObject(instanceOf, sr2.IsDefinedBy);\r
- for(Resource input : graph.syncRequest(new ObjectsWithType(configuration, b.ConsistsOf, sr.Input))) {\r
- Resource dependency = null;\r
- for(Resource dep : graph.getObjects(module, sr.IsHeadOf)) {\r
- Resource refersTo = graph.getPossibleObject(dep, sr.RefersTo);\r
- if(refersTo != null && refersTo.equals(input)) {\r
- dependency = dep;\r
- break;\r
- }\r
- }\r
- ReferenceRow rr = new ReferenceRow(module, dependency, input); \r
- result.add(rr);\r
- }\r
- return result;\r
- }\r
- });\r
- } catch (DatabaseException e) {\r
- e.printStackTrace();\r
- }\r
- tableViewer.setInput(referenceRows);\r
- }\r
-\r
- public class ReferenceRow {\r
-\r
- Resource input, module, dependency;\r
- String name;\r
-\r
- public ReferenceRow(Resource module, Resource dependency, Resource input) {\r
- this.module = module;\r
- this.input = input;\r
- this.dependency = dependency;\r
- }\r
-\r
-\r
- public Resource getModule() {\r
- return this.module;\r
- }\r
-\r
- public Resource getInput() {\r
- return this.input;\r
- }\r
-\r
- public Resource getDependency() {\r
- return this.dependency;\r
- }\r
-\r
- public String getName() {\r
- String name = null;\r
+ if(this.rowProvider != null) {\r
try {\r
- name = SimanticsUI.getSession().syncRequest(new Read<String>() {\r
+ SimanticsUI.getSession().syncRequest(new Read<ArrayList<ReferenceRow>>() {\r
\r
@Override\r
- public String perform(ReadGraph graph) throws DatabaseException {\r
- return (String)graph.getRelatedValue(input, graph.getBuiltins().HasName);\r
+ public ArrayList<ReferenceRow> perform(ReadGraph graph) throws DatabaseException {\r
+ return rowProvider.getRows(graph, module);\r
}\r
- });\r
- } catch (DatabaseException e) {\r
- e.printStackTrace();\r
- }\r
- return name;\r
- }\r
-\r
- public String getOutputName() {\r
- if(dependency == null) return "";\r
+ } , new Listener<ArrayList<ReferenceRow>>() {\r
\r
- String outputName = null;\r
- try {\r
- outputName = SimanticsUI.getSession().syncRequest(new Read<String>() {\r
+ @Override\r
+ public boolean isDisposed() {\r
+ if(tableViewer != null && tableViewer.getTable() != null)\r
+ return getTableViewer().getTable().isDisposed();\r
+ else\r
+ return true;\r
+ }\r
\r
@Override\r
- public String perform(ReadGraph graph) throws DatabaseException {\r
- Builtins b = graph.getBuiltins();\r
- SysdynResource sr = SysdynResource.getInstance(graph);\r
- Resource output = graph.getPossibleObject(dependency, sr.HasTail);\r
- return (String)graph.getRelatedValue(output, b.HasName, StringBindingDefault.INSTANCE);\r
+ public void execute(final ArrayList<ReferenceRow> result) {\r
+ if(!isDisposed())\r
+ getTableViewer().getTable().getDisplay().asyncExec(new Runnable() {\r
+ \r
+ @Override\r
+ public void run() {\r
+ if(!isDisposed())\r
+ getTableViewer().setInput(result);\r
+ }\r
+ });\r
}\r
- });\r
- } catch (DatabaseException e) {\r
- e.printStackTrace();\r
- }\r
- return outputName;\r
- }\r
\r
- private void setRefersTo(final Resource dependency) {\r
- System.out.println("DEPENDENCY: " + dependency + " (" + getDependency() + ")");\r
- if(dependency != null && dependency.equals(this.dependency)) return;\r
- SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
- @Override\r
- public void perform(WriteGraph graph) throws DatabaseException {\r
- SysdynResource sr = SysdynResource.getInstance(graph);\r
- if(getDependency() != null && graph.hasStatement(getDependency(), sr.RefersTo))\r
- graph.deny(getDependency(), sr.RefersTo);\r
- setDependency(null);\r
- if(dependency != null) {\r
- setDependency(dependency);\r
- graph.claim(getDependency(), SysdynResource.getInstance(graph).RefersTo, input);\r
+ @Override\r
+ public void exception(Throwable t) {\r
}\r
}\r
- });\r
- }\r
- \r
- private void setDependency(Resource dependency) {\r
- this.dependency = dependency;\r
- }\r
- }\r
-\r
- private class ReferenceRowLabelProvider extends LabelProvider implements ITableLabelProvider {\r
-\r
- @Override\r
- public Image getColumnImage(Object element, int columnIndex) {\r
- return null;\r
- }\r
-\r
- @Override\r
- public String getColumnText(Object element, int columnIndex) {\r
- ReferenceRow referenceRow = (ReferenceRow) element;\r
- switch (columnIndex) {\r
- case 0:\r
- return referenceRow.getName();\r
- case 1:\r
- return referenceRow.getOutputName();\r
- default:\r
- throw new RuntimeException("Should not happen");\r
+ );\r
+ } catch (DatabaseException e) {\r
+ e.printStackTrace();\r
}\r
}\r
-\r
}\r
\r
private class ReferenceRowComparator extends ViewerComparator {\r
@Override\r
public int compare(Viewer viewer, Object e1, Object e2) {\r
- return 0;\r
+ ReferenceRow rr1 = (ReferenceRow)e1;\r
+ ReferenceRow rr2 = (ReferenceRow)e2;\r
+ return rr1.getName().compareTo(rr2.getName());\r
}\r
}\r
\r
- public class ReferenceRowEditingSupport extends EditingSupport {\r
- private CellEditor editor;\r
- private int column;\r
- private HashMap<String, Resource> optionResources;\r
- private String[] options;\r
-\r
- public ReferenceRowEditingSupport(ColumnViewer viewer, int column) {\r
- super(viewer);\r
- this.column = column;\r
- }\r
-\r
- @Override\r
- protected boolean canEdit(Object element) {\r
- switch (this.column) {\r
- case 0: return false;\r
- default: return true;\r
- }\r
- }\r
-\r
- @Override\r
- protected CellEditor getCellEditor(Object element) {\r
- // Create the correct editor based on the column index\r
- switch (column) {\r
- case 0: \r
- editor = new TextCellEditor(table);\r
- case 1:\r
- ReferenceRow row = (ReferenceRow)element;\r
- final Resource module = row.getModule();\r
- final Resource inputVariable = row.getInput();\r
-\r
- optionResources = new HashMap<String, Resource>();\r
- try {\r
- optionResources = SimanticsUI.getSession().syncRequest(new Read<HashMap<String, Resource>>() {\r
-\r
- @Override\r
- public HashMap<String, Resource> perform(ReadGraph graph) throws DatabaseException {\r
- Builtins b = graph.getBuiltins();\r
- SysdynResource sr = SysdynResource.getInstance(graph);\r
- HashMap<String, Resource> result = new HashMap<String, Resource>();\r
- for(Resource dependency : graph.syncRequest(new ObjectsWithType(module, sr.IsHeadOf, sr.Dependency))) {\r
- if(graph.getPossibleObject(dependency, sr.RefersTo) == null ||\r
- graph.getPossibleObject(dependency, sr.RefersTo).equals(inputVariable)) {\r
- Resource output = graph.getSingleObject(dependency, sr.HasTail);\r
- result.put((String)graph.getRelatedValue(output, b.HasName), dependency);\r
- }\r
- }\r
- return result;\r
- }\r
- });\r
- } catch (DatabaseException e) {\r
- e.printStackTrace();\r
- }\r
-\r
- options = optionResources.keySet().toArray(new String[optionResources.keySet().size() + 1]);\r
- options[optionResources.keySet().size()] = "";\r
- editor = new ComboBoxCellEditor(table, options, SWT.READ_ONLY);\r
- break;\r
- default:\r
- editor = null;\r
- }\r
-\r
- return editor;\r
- }\r
-\r
- @Override\r
- protected Object getValue(Object element) {\r
- ReferenceRow referenceRow = (ReferenceRow) element;\r
-\r
- switch (this.column) {\r
- case 0:\r
- return referenceRow.getName();\r
- case 1:\r
- String refersToName = referenceRow.getOutputName();\r
- if (refersToName == null) return options.length - 1;\r
- for(int i = 0; i < options.length ; i++) {\r
- if(refersToName.equals(options[i])) return i;\r
- }\r
- return options[options.length - 1];\r
- default:\r
- break;\r
- }\r
- return null;\r
- }\r
-\r
- @Override\r
- protected void setValue(Object element, Object value) {\r
- ReferenceRow referenceRow = (ReferenceRow) element;\r
- String valueString = String.valueOf(value);\r
- switch (this.column) {\r
- case 0:\r
- break;\r
- case 1:\r
- referenceRow.setRefersTo(optionResources.get(options[Integer.parseInt(valueString)]));\r
- break;\r
- default:\r
- break;\r
- }\r
-\r
- getViewer().update(element, null);\r
- }\r
-\r
- }\r
-\r
}\r