]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.spreadsheet.graph/scl/Spreadsheet/All.scl
aa58a7f73c2f5654dffac51ce7e81accd1eee6be
[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 "File"
7
8
9 effect SpreadsheetTransaction 
10     "spreadsheetTransaction" 
11     "org.simantics.spreadsheet.Transaction"
12
13 importJava "org.simantics.spreadsheet.graph.ExternalRef" where
14     data ExternalRef
15
16 importJava "org.simantics.spreadsheet.common.TableCell" where
17     data TableCell
18
19 importJava "java.util.function.Consumer" where
20     data Consumer
21
22 importJava "org.simantics.spreadsheet.CellEditor" where
23     data CellEditor
24     startTransaction :: CellEditor -> OperationMode -> <Proc> Transaction
25     @JavaName "edit"
26     editProperty_ :: CellEditor -> String -> String -> a -> Binding a -> Maybe Consumer -> <SpreadsheetTransaction> () 
27     @JavaName "edit"
28     editContent :: CellEditor -> String -> Variant -> Maybe Consumer -> <SpreadsheetTransaction> () 
29
30 @inline
31 editProperty :: Serializable a => CellEditor -> String -> String -> a -> Maybe Consumer -> <SpreadsheetTransaction> ()
32 editProperty editor location property value consumer = editProperty_ editor location property value binding consumer
33
34 importJava "org.simantics.spreadsheet.OperationMode" where
35     data OperationMode
36     OPERATION :: OperationMode
37     EDIT_MODE :: OperationMode
38
39 importJava "org.simantics.spreadsheet.Transaction" where
40     data Transaction
41     commit :: Transaction -> <Proc> ()
42
43 importJava "org.simantics.spreadsheet.common.TreeTableCell" where
44     data TreeTableCell
45
46     @JavaName getData
47     getTreeTableCellData :: TreeTableCell -> <Proc> a
48     
49     createTreeTableCell :: String -> a -> Maybe b -> Integer -> Integer -> Integer -> Boolean -> <Proc> TreeTableCell
50
51     createTreeTableCell2 :: String -> a -> Maybe b -> a -> Integer -> Integer -> Boolean -> <Proc> TreeTableCell
52     
53     @JavaName getText
54     treeTableCellText :: TreeTableCell -> <Proc> String
55     @JavaName getFont
56     treeTableCellFont :: TreeTableCell -> <Proc> Maybe IFont
57     @JavaName getRow
58     treeTableCellRow :: TreeTableCell -> <Proc> Integer
59     @JavaName getColumn
60     treeTableCellColumn :: TreeTableCell -> <Proc> Integer
61     
62 importJava "org.simantics.spreadsheet.common.SpreadsheetCell" where
63     data SpreadsheetCell
64
65 importJava "org.simantics.spreadsheet.graph.SCL" where
66     toVariant :: a -> Variant
67     modelsSourceContribution :: Resource -> <ReadGraph> [Variable]
68     modelsSourceContributionLabeler :: Variable -> <ReadGraph> String
69
70 importJava "org.simantics.spreadsheet.graph.SpreadsheetGraphUtils" where
71     @JavaName "fullSynchronization"
72     fullSynchronizeSheet :: Variable -> <ReadGraph> Boolean
73     evaluateAll :: Variable -> <ReadGraph> ()
74     saveInitialCondition :: Variable -> Resource -> String -> <WriteGraph> Resource
75     findCell :: Variable -> String -> <ReadGraph> Maybe Variable
76     invalidateAll :: Variable -> <ReadGraph> ()
77     extRefVariable :: Variable -> <ReadGraph> Variant
78     extRefActiveVariable :: Variable -> <ReadGraph> Variant
79     cellEditor :: Resource -> <ReadGraph> CellEditor
80     syncExec :: CellEditor -> OperationMode -> (<SpreadsheetTransaction, Proc> a) -> <Proc> a
81     cellColumn :: Variable -> <ReadGraph> Integer
82
83 importJava "org.simantics.spreadsheet.Spreadsheets" where
84      cellName :: Integer -> Integer -> String
85
86 importJava "org.simantics.spreadsheet.util.SpreadsheetUtils" where
87     createSheet :: Resource -> String -> <WriteGraph> Resource
88     queryCells :: a -> [TableCell]
89     modifyCells1 :: [TableCell] -> (TableCell -> TableCell) -> [TableCell]
90     modifyCells :: [TableCell] -> [(TableCell -> TableCell)] -> [TableCell]
91     organizeCells :: Integer -> [String] -> [TableCell] -> [TableCell]
92     applyFont :: IFont -> (TableCell -> Boolean) -> TableCell -> TableCell
93     applyAlign :: Integer -> (TableCell -> Boolean) -> TableCell -> TableCell
94     applyForeground :: IColor -> (TableCell -> Boolean) -> TableCell -> TableCell
95     applyBackground :: IColor -> (TableCell -> Boolean) -> TableCell -> TableCell
96     simpleFont :: String -> String -> Integer -> IFont
97     rgbColor :: Integer -> Integer -> Integer -> IColor
98     selectRow :: Integer -> TableCell -> Boolean
99     selectColumn :: Integer -> TableCell -> Boolean
100     setSCLLine :: Resource -> Integer -> String -> <WriteGraph> ()
101     sheetRun :: Resource -> Variable -> <ReadGraph> Variable
102     @JavaName "sheetRun"
103     bookRun :: Resource -> Variable -> <ReadGraph> Variable
104
105 sheetRunDefault :: Resource -> <ReadGraph> Variable
106 sheetRunDefault sheet = sheetRun sheet (resourceVariable sheet)
107
108 importJava "org.simantics.spreadsheet.graph.SpreadsheetSessionManager" where
109     removeSpreadsheetSession :: Variable -> <Proc, WriteGraph> ()
110
111 importJava "org.simantics.spreadsheet.graph.ExcelImport" where
112     importBook :: Resource -> File -> <Proc> ()
113
114 importSpreadsheetBookAction :: Resource -> <Proc> ()
115 importSpreadsheetBookAction res = match fileDialog "foo" [("Excel file", "*.xls"), ("Excel File", "*.xlsx")] with
116   Nothing -> ()
117   Just file -> importBook res file
118
119 createSpreadsheetBookAction :: Resource -> <Proc> ()
120 createSpreadsheetBookAction res = do
121   syncWrite (\() -> createSpreadsheetBookDefault res)
122   ()
123   
124 createSpreadsheetSheetAction :: Resource -> <Proc> ()
125 createSpreadsheetSheetAction res = do
126   syncWrite (\() -> createSpreadsheetDefault res)
127   ()
128
129 createSpreadsheetDefault :: Resource -> <WriteGraph> Resource
130 createSpreadsheetDefault library = createSheet library $ findFreshEscapedName "Sheet" library 
131
132 createSpreadsheetBookDefault :: Resource -> <WriteGraph> Resource
133 createSpreadsheetBookDefault library = createSpreadsheetBook library $ findFreshEscapedName "Book" library 
134
135 createRange :: Resource -> Resource -> String -> String -> <WriteGraph> Resource
136 createRange library type_ name expression = do
137     range = newResource ()
138     claim range L0.InstanceOf type_
139     claimRelatedValue range L0.HasName name
140     createSCLValue range SHEET.ExpressionRange.cells SHEET.SCLValue expression
141     claim range L0.PartOf library
142     range
143
144 createSpreadsheetBook :: Resource -> String -> <WriteGraph> Resource
145 createSpreadsheetBook library name = do
146     markUndoPoint ()
147     book = newResource ()
148     claim book L0.InstanceOf SHEET.Book
149     claimRelatedValue book L0.HasName name
150     claim book L0.PartOf library
151     createSheet book "Sheet"
152     addCommentMetadata ("Created Spreadsheet Book " + name)
153     book
154