1 package org.simantics.spreadsheet.ui.editor;
3 import java.util.ArrayList;
4 import java.util.Collection;
5 import java.util.Collections;
6 import java.util.Iterator;
8 import org.simantics.db.ReadGraph;
9 import org.simantics.db.Resource;
10 import org.simantics.db.layer0.variable.Variable;
11 import org.simantics.db.layer0.variable.Variables;
12 import org.simantics.selectionview.ComparableTabContributor;
13 import org.simantics.selectionview.SelectionProcessor;
14 import org.simantics.spreadsheet.resource.SpreadsheetResource;
15 import org.simantics.spreadsheet.ui.TableSelection;
16 import org.simantics.spreadsheet.ui.editor.NoCellTab.NoCellInput;
17 import org.simantics.spreadsheet.util.SpreadsheetUtils;
20 * @author Tuukka Lehtonen
22 public class SpreadsheetSelectionProcessor implements SelectionProcessor<Collection<?>, ReadGraph> {
25 public Collection<?> process(Collection<?> selection, ReadGraph graph) {
27 if(selection == null) return Collections.emptyList();
28 if(selection.size() != 3) return Collections.emptyList();
29 Iterator<?> it = selection.iterator();
30 final Variable variable = (Variable)it.next();
32 final TableSelection sel = (TableSelection)it.next();
33 int row = sel.getRows()[0];
34 int column = sel.getColumns()[0];
35 String location = SpreadsheetUtils.cellName(row, column);
36 ArrayList<ComparableTabContributor> result = new ArrayList<ComparableTabContributor>();
37 final Variable cell = variable.getPossibleChild(graph, location);
39 SpreadsheetResource sr = SpreadsheetResource.getInstance(graph);
40 //result.add(new ComparableTabContributor(new SheetTab(), 2, variable, "Sheet"));
41 final Resource type = cell.getPossiblePropertyValue(graph, Variables.TYPE);
42 if(sr.TextCell.equals(type)) {
43 result.add(new ComparableTabContributor(new TextCellTab(), 3, cell, "Configuration"));
44 // if(sr.ExpressionRealization.equals(type)) {
45 // Variable expression = cell.getPossibleProperty(graph, "Expression");
46 // if(expression != null) {
47 // result.add(new ComparableTabContributor(new ExpressionCellTab(), 3, cell, "Configuration"));
51 // } else if(sr.CommandRealization.equals(type)) {
52 // result.add(new ComparableTabContributor(new CommandCellTab(), 3, cell, "Configuration"));
53 // } else if(sr.TextRealization.equals(type)) {
54 // result.add(new ComparableTabContributor(new TextCellTab(), 3, cell, "Configuration"));
55 // } else if(sr.MatrixRealization.equals(type)) {
56 // result.add(new ComparableTabContributor(new MatrixCellTab(), 3, cell, "Configuration"));
58 // System.out.println("cell type = " + type);
59 // final String content = cell.getPossiblePropertyValue(graph, "Content");
60 // if(content != null) {
61 // final Variable contentVariable = Variables.getVariable(graph, content);
62 // if(variable == null) return Collections.emptyList();
63 // return Collections.singleton(new ComparableTabContributor(new SpreadsheetTab(), 3, contentVariable, "Configuration"));
65 return Collections.emptyList();
68 result.add(new ComparableTabContributor(new NoCellTab(), 3, new NoCellInput(variable, location), "Configuration"));
71 } catch (Throwable t) {
73 return Collections.emptyList();