]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.spreadsheet.graph/scl/Spreadsheet/All.scl
SCL API for direct access to SpreadsheetBooks
[simantics/platform.git] / bundles / org.simantics.spreadsheet.graph / scl / Spreadsheet / All.scl
1 include "Simantics/DB"
2 include "Simantics/Ontologies"
3 include "Simantics/SCL"
4 include "Simantics/UI"
5 include "Document/All"
6 include "Spreadsheet/Solver"
7 include "File"
8
9 importJava "org.simantics.spreadsheet.common.TableCell" where
10     data TableCell
11
12 @inline
13 editProperty :: Serializable a => CellEditor -> String -> String -> a -> Maybe Consumer -> <SpreadsheetTransaction> ()
14 editProperty editor location property value consumer = editProperty_ editor location property value binding consumer
15
16 importJava "org.simantics.spreadsheet.common.TreeTableCell" where
17     data TreeTableCell
18
19     @JavaName getData
20     getTreeTableCellData :: TreeTableCell -> <Proc> a
21     
22     createTreeTableCell :: String -> a -> Maybe b -> Integer -> Integer -> Integer -> Boolean -> <Proc> TreeTableCell
23
24     createTreeTableCell2 :: String -> a -> Maybe b -> a -> Integer -> Integer -> Boolean -> <Proc> TreeTableCell
25     
26     @JavaName getText
27     treeTableCellText :: TreeTableCell -> <Proc> String
28     @JavaName getFont
29     treeTableCellFont :: TreeTableCell -> <Proc> Maybe IFont
30     @JavaName getRow
31     treeTableCellRow :: TreeTableCell -> <Proc> Integer
32     @JavaName getColumn
33     treeTableCellColumn :: TreeTableCell -> <Proc> Integer
34
35 importJava "org.simantics.spreadsheet.graph.SCL" where
36     toVariant :: a -> Variant
37     modelsSourceContribution :: Resource -> <ReadGraph> [Variable]
38     modelsSourceContributionLabeler :: Variable -> <ReadGraph> String
39
40 importJava "org.simantics.spreadsheet.graph.SpreadsheetGraphUtils" where
41     @JavaName "fullSynchronization"
42     fullSynchronizeSheet :: Variable -> <ReadGraph> Boolean
43     evaluateAll :: Variable -> <ReadGraph> ()
44     saveInitialCondition :: Variable -> Resource -> String -> <WriteGraph> Resource
45     findCell :: Variable -> String -> <ReadGraph> Maybe Variable
46     invalidateAll :: Variable -> <ReadGraph> ()
47     extRefVariable :: Variable -> <ReadGraph> Variant
48     extRefActiveVariable :: Variable -> <ReadGraph> Variant
49     forRows :: Variable -> String -> Integer -> Integer -> (Variable -> <ReadGraph,Proc> ()) -> <ReadGraph> ()
50     rowCell :: Variable -> Integer -> <ReadGraph> Maybe Variable
51     offsetCell :: Variable -> Integer -> Integer -> <ReadGraph> Maybe Variable
52     cellEditor :: Resource -> <ReadGraph> CellEditor
53     syncExec :: CellEditor -> OperationMode -> (<SpreadsheetTransaction, Proc> a) -> <Proc> a
54     cellColumn :: Variable -> <ReadGraph> Integer
55     spreadsheetBook :: Variable -> <Proc> SpreadsheetBook
56
57 importJava "org.simantics.spreadsheet.util.SpreadsheetUtils" where
58     createSheet :: Resource -> String -> <WriteGraph> Resource
59     queryCells :: a -> [TableCell]
60     modifyCells1 :: [TableCell] -> (TableCell -> TableCell) -> [TableCell]
61     modifyCells :: [TableCell] -> [(TableCell -> TableCell)] -> [TableCell]
62     organizeCells :: Integer -> [String] -> [TableCell] -> [TableCell]
63     applyFont :: IFont -> (TableCell -> Boolean) -> TableCell -> TableCell
64     applyAlign :: Integer -> (TableCell -> Boolean) -> TableCell -> TableCell
65     applyForeground :: IColor -> (TableCell -> Boolean) -> TableCell -> TableCell
66     applyBackground :: IColor -> (TableCell -> Boolean) -> TableCell -> TableCell
67     simpleFont :: String -> String -> Integer -> IFont
68     rgbColor :: Integer -> Integer -> Integer -> IColor
69     selectRow :: Integer -> TableCell -> Boolean
70     selectColumn :: Integer -> TableCell -> Boolean
71     setSCLLine :: Resource -> Integer -> String -> <WriteGraph> ()
72     sheetRun :: Resource -> Variable -> <ReadGraph> Variable
73     @JavaName "sheetRun"
74     bookRun :: Resource -> Variable -> <ReadGraph> Variable
75
76 sheetRunDefault = bookRunDefault
77
78 bookRunDefault :: Resource -> <ReadGraph> Variable
79 bookRunDefault book = bookRun book (resourceVariable book)
80
81 importJava "org.simantics.spreadsheet.graph.ExcelImport" where
82     importBook :: Resource -> File -> <Proc> ()
83
84 importSpreadsheetBookAction :: Resource -> <Proc> ()
85 importSpreadsheetBookAction res = match fileDialog "foo" [("Excel file", "*.xls"), ("Excel File", "*.xlsx")] with
86   Nothing -> ()
87   Just file -> importBook res file
88
89 createSpreadsheetBookAction :: Resource -> <Proc> ()
90 createSpreadsheetBookAction res = do
91   syncWrite (\() -> createSpreadsheetBookDefault res)
92   ()
93   
94 createSpreadsheetSheetAction :: Resource -> <Proc> ()
95 createSpreadsheetSheetAction res = do
96   syncWrite (\() -> createSpreadsheetDefault res)
97   ()
98
99 createSpreadsheetDefault :: Resource -> <WriteGraph> Resource
100 createSpreadsheetDefault library = createSheet library $ findFreshEscapedName "Sheet" library 
101
102 createSpreadsheetBookDefault :: Resource -> <WriteGraph> Resource
103 createSpreadsheetBookDefault library = createSpreadsheetBook library $ findFreshEscapedName "Book" library 
104
105 createRange :: Resource -> Resource -> String -> String -> <WriteGraph> Resource
106 createRange library type_ name expression = do
107     range = newResource ()
108     claim range L0.InstanceOf type_
109     claimRelatedValue range L0.HasName name
110     createSCLValue range SHEET.ExpressionRange.cells SHEET.SCLValue expression
111     claim range L0.PartOf library
112     range
113
114 createSpreadsheetBook :: Resource -> String -> <WriteGraph> Resource
115 createSpreadsheetBook library name = do
116     markUndoPoint ()
117     book = newResource ()
118     claim book L0.InstanceOf SHEET.Book
119     claimRelatedValue book L0.HasName name
120     claim book L0.PartOf library
121     createSheet book "Sheet"
122     addCommentMetadata ("Created Spreadsheet Book " + name)
123     book
124