]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.spreadsheet.ui/src/org/simantics/spreadsheet/ui/editor/SpreadsheetSelectionProcessor.java
Adopt spreadsheet changes made in Balas development
[simantics/platform.git] / bundles / org.simantics.spreadsheet.ui / src / org / simantics / spreadsheet / ui / editor / SpreadsheetSelectionProcessor.java
1 package org.simantics.spreadsheet.ui.editor;
2
3 import java.util.ArrayList;
4 import java.util.Collection;
5 import java.util.Collections;
6 import java.util.Iterator;
7
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.Spreadsheets;
15 import org.simantics.spreadsheet.resource.SpreadsheetResource;
16 import org.simantics.spreadsheet.ui.TableSelection;
17 import org.simantics.spreadsheet.ui.editor.NoCellTab.NoCellInput;
18
19 /**
20  * @author Tuukka Lehtonen
21  */
22 public class SpreadsheetSelectionProcessor implements SelectionProcessor<Collection<?>, ReadGraph> {
23
24     @Override
25     public Collection<?> process(Collection<?> selection, ReadGraph graph) {
26         try {
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();
31                 it.next();
32                 final TableSelection sel = (TableSelection)it.next();
33                 int row = sel.getRows()[0];
34                 int column = sel.getColumns()[0];
35                 String location = Spreadsheets.cellName(row, column);
36                 ArrayList<ComparableTabContributor> result = new ArrayList<ComparableTabContributor>(); 
37                 final Variable cell = variable.getPossibleChild(graph, location);
38                 if(cell != null) {
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"));
48 //                              } else {
49 //                                      
50 //                              }
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"));
57 //                              }
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"));
64                         } else {
65                                 return Collections.emptyList();
66                         }
67                 } else {
68                         result.add(new ComparableTabContributor(new NoCellTab(), 3, new NoCellInput(variable, location), "Configuration"));
69                 }
70                 return result;
71         } catch (Throwable t) {
72                 t.printStackTrace();
73                 return Collections.emptyList();
74         }
75     }
76
77 }