]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/synchronization/StyleUpdater.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.spreadsheet.graph / src / org / simantics / spreadsheet / graph / synchronization / StyleUpdater.java
index c536ff67e687dad875569c89502e99663c5b4570..de5b47cc829b0edd68a35e3a63958d7f6a19d311 100644 (file)
-package org.simantics.spreadsheet.graph.synchronization;\r
-\r
-import java.util.Collection;\r
-import java.util.Map;\r
-\r
-import org.simantics.databoard.binding.mutable.Variant;\r
-import org.simantics.datatypes.literal.Font;\r
-import org.simantics.datatypes.literal.RGB;\r
-import org.simantics.spreadsheet.graph.SpreadsheetBook;\r
-import org.simantics.spreadsheet.graph.SpreadsheetStyle;\r
-import org.simantics.structural.synchronization.base.CommandBuilder;\r
-import org.simantics.structural.synchronization.base.ModuleUpdateContext;\r
-import org.simantics.structural.synchronization.base.ModuleUpdaterBase;\r
-import org.simantics.structural.synchronization.base.PropertyUpdateRule;\r
-import org.simantics.structural.synchronization.base.Solver;\r
-\r
-public class StyleUpdater extends ModuleUpdaterBase<SheetLineComponent> {\r
-\r
-    private static class ForegroundUpdateRule implements PropertyUpdateRule<SheetLineComponent> {\r
-        @Override\r
-        public String getPropertyName() {\r
-            return "foreground";\r
-        }\r
-        \r
-        @Override\r
-        public void apply(ModuleUpdateContext<SheetLineComponent> context, boolean isCreating, Map<String, Variant> propertyMap, Map<String, Collection<String>> connectionMap, Variant value) {\r
-            StyleCommandBuilder builder = context.getConcreteCommand();\r
-            RGB.Integer color = (RGB.Integer) value.getValue();\r
-            builder.foreground = color;\r
-        }\r
-    }\r
-    \r
-    private static class BackgroundUpdateRule implements PropertyUpdateRule<SheetLineComponent> {\r
-        @Override\r
-        public String getPropertyName() {\r
-            return "background";\r
-        }\r
-\r
-        @Override\r
-        public void apply(ModuleUpdateContext<SheetLineComponent> context, boolean isCreating, Map<String, Variant> propertyMap, Map<String, Collection<String>> connectionMap, Variant value) {\r
-            StyleCommandBuilder builder = context.getConcreteCommand();\r
-            RGB.Integer color = (RGB.Integer) value.getValue();\r
-            builder.background = color;\r
-        }\r
-    }\r
-    \r
-    private static class FontUpdateRule implements PropertyUpdateRule<SheetLineComponent> {\r
-        @Override\r
-        public String getPropertyName() {\r
-            return "font";\r
-        }\r
-\r
-        @Override\r
-        public void apply(ModuleUpdateContext<SheetLineComponent> context, boolean isCreating, Map<String, Variant> propertyMap, Map<String, Collection<String>> connectionMap, Variant value) {\r
-            StyleCommandBuilder builder = context.getConcreteCommand();\r
-            Font font = (Font) value.getValue();\r
-            builder.font = font;\r
-        }\r
-    }\r
-\r
-    private static class AlignUpdateRule implements PropertyUpdateRule<SheetLineComponent> {\r
-        @Override\r
-        public String getPropertyName() {\r
-            return "align";\r
-        }\r
-\r
-        @Override\r
-        public void apply(ModuleUpdateContext<SheetLineComponent> context, boolean isCreating, Map<String, Variant> propertyMap, Map<String, Collection<String>> connectionMap, Variant value) {\r
-            StyleCommandBuilder builder = context.getConcreteCommand();\r
-            int align = (int) value.getValue();\r
-            builder.align = align;\r
-        }\r
-    }\r
-    \r
-    private static class FormatStringUpdateRule implements PropertyUpdateRule<SheetLineComponent> {\r
-        @Override\r
-        public String getPropertyName() {\r
-            return "formatString";\r
-        }\r
-\r
-        @Override\r
-        public void apply(ModuleUpdateContext<SheetLineComponent> context, boolean isCreating, Map<String, Variant> propertyMap, Map<String, Collection<String>> connectionMap, Variant value) {\r
-            StyleCommandBuilder builder = context.getConcreteCommand();\r
-            String formatString = (String) value.getValue();\r
-            builder.formatString = formatString;\r
-        }\r
-    }\r
-\r
-    private static class FormatIndexUpdateRule implements PropertyUpdateRule<SheetLineComponent> {\r
-        @Override\r
-        public String getPropertyName() {\r
-            return "formatIndex";\r
-        }\r
-\r
-        @Override\r
-        public void apply(ModuleUpdateContext<SheetLineComponent> context, boolean isCreating, Map<String, Variant> propertyMap, Map<String, Collection<String>> connectionMap, Variant value) {\r
-            StyleCommandBuilder builder = context.getConcreteCommand();\r
-            int index = (int) value.getValue();\r
-            builder.formatIndex = index;\r
-        }\r
-    }\r
-\r
-    private static class BorderUpdateRule implements PropertyUpdateRule<SheetLineComponent> {\r
-        @Override\r
-        public String getPropertyName() {\r
-            return "border";\r
-        }\r
-\r
-        @Override\r
-        public void apply(ModuleUpdateContext<SheetLineComponent> context, boolean isCreating, Map<String, Variant> propertyMap, Map<String, Collection<String>> connectionMap, Variant value) {\r
-            StyleCommandBuilder builder = context.getConcreteCommand();\r
-            int border = (int) value.getValue();\r
-            builder.border = border;\r
-        }\r
-    }\r
-    \r
-    private static class LockedUpdateRule implements PropertyUpdateRule<SheetLineComponent> {\r
-        @Override\r
-        public String getPropertyName() {\r
-            return "locked";\r
-        }\r
-\r
-        @Override\r
-        public void apply(ModuleUpdateContext<SheetLineComponent> context, boolean isCreating, Map<String, Variant> propertyMap, Map<String, Collection<String>> connectionMap, Variant value) {\r
-            StyleCommandBuilder builder = context.getConcreteCommand();\r
-            boolean locked = (boolean) value.getValue();\r
-            builder.locked = locked;\r
-        }\r
-    }\r
-    \r
-    private static class ColumnSpanUpdateRule implements PropertyUpdateRule<SheetLineComponent> {\r
-        @Override\r
-        public String getPropertyName() {\r
-            return "columnSpan";\r
-        }\r
-\r
-        @Override\r
-        public void apply(ModuleUpdateContext<SheetLineComponent> context, boolean isCreating, Map<String, Variant> propertyMap, Map<String, Collection<String>> connectionMap, Variant value) {\r
-            StyleCommandBuilder builder = context.getConcreteCommand();\r
-            int columnSpan = (int) value.getValue();\r
-            builder.columnSpan = columnSpan;\r
-        }\r
-    }\r
-    \r
-    private static class RowSpanUpdateRule implements PropertyUpdateRule<SheetLineComponent> {\r
-        @Override\r
-        public String getPropertyName() {\r
-            return "rowSpan";\r
-        }\r
-\r
-        @Override\r
-        public void apply(ModuleUpdateContext<SheetLineComponent> context, boolean isCreating, Map<String, Variant> propertyMap, Map<String, Collection<String>> connectionMap, Variant value) {\r
-            StyleCommandBuilder builder = context.getConcreteCommand();\r
-            int rowSpan = (int) value.getValue();\r
-            builder.rowSpan = rowSpan;\r
-        }\r
-    }\r
-\r
-    \r
-    public StyleUpdater(String moduleType) {\r
-        super(moduleType);\r
-        \r
-        addPropertyUpdateRule(new ForegroundUpdateRule());\r
-        addPropertyUpdateRule(new BackgroundUpdateRule());\r
-        addPropertyUpdateRule(new FontUpdateRule());\r
-        addPropertyUpdateRule(new AlignUpdateRule());\r
-        addPropertyUpdateRule(new FormatStringUpdateRule());\r
-        addPropertyUpdateRule(new FormatIndexUpdateRule());\r
-        addPropertyUpdateRule(new BorderUpdateRule());\r
-        addPropertyUpdateRule(new LockedUpdateRule());\r
-        addPropertyUpdateRule(new ColumnSpanUpdateRule());\r
-        addPropertyUpdateRule(new RowSpanUpdateRule());\r
-    }\r
-\r
-    @Override\r
-    public CommandBuilder createAddCommandBuilder(final String name) {\r
-        return new StyleCommandBuilder(name, false);\r
-    }\r
-\r
-    @Override\r
-    public CommandBuilder createUpdateCommandBuilder(String name) {\r
-        return new StyleCommandBuilder(name, true);\r
-    }\r
-    \r
-    private static class StyleCommandBuilder implements CommandBuilder {\r
-\r
-        protected int rowSpan;\r
-        protected int columnSpan;\r
-        protected int border;\r
-        protected boolean locked;\r
-        protected int formatIndex;\r
-        protected String formatString;\r
-        protected org.simantics.datatypes.literal.RGB.Integer background;\r
-        protected org.simantics.datatypes.literal.RGB.Integer foreground;\r
-        protected Font font;\r
-        protected int align;\r
-        \r
-        private boolean update;\r
-        private String name;\r
-        \r
-        public StyleCommandBuilder(String name, boolean update) {\r
-            this.name = name.split("/")[1];\r
-            this.update = update;\r
-        }\r
-        \r
-        @Override\r
-        public void apply(Solver solver) {\r
-            SpreadsheetBook book = solver.getConcreteSolver();\r
-            SpreadsheetStyle style = SpreadsheetStyle.newInstace().name(name).align(align).font(font)\r
-                    .background(background).foreground(foreground).border(border).locked(locked).rowSpan(rowSpan)\r
-                    .columnSpan(columnSpan).formatIndex((short) formatIndex).formatString(formatString).build();\r
-            if (book.getStyle(style.getStyleId()) == null)\r
-                book.addStyle(style);\r
-            \r
-        }\r
-\r
-        @SuppressWarnings("unchecked")\r
-        @Override\r
-        public <T> T getConcrete() {\r
-            return (T) this;\r
-        }\r
-        \r
-        @Override\r
-        public String toString() {\r
-            StringBuilder sb = new StringBuilder();\r
-            sb.append("StyleCommandBuilder for ").append(name).append(" [background=").append(background).append(", foregroung=").append(foreground).append(", font=").append(font).append(", align=").append(align).append("]");\r
-            return sb.toString();\r
-        }\r
-        \r
-    }\r
-    \r
-}\r
+package org.simantics.spreadsheet.graph.synchronization;
+
+import java.util.Collection;
+import java.util.Map;
+
+import org.simantics.databoard.binding.mutable.Variant;
+import org.simantics.datatypes.literal.Font;
+import org.simantics.datatypes.literal.RGB;
+import org.simantics.spreadsheet.graph.SpreadsheetBook;
+import org.simantics.spreadsheet.graph.SpreadsheetStyle;
+import org.simantics.structural.synchronization.base.CommandBuilder;
+import org.simantics.structural.synchronization.base.ModuleUpdateContext;
+import org.simantics.structural.synchronization.base.ModuleUpdaterBase;
+import org.simantics.structural.synchronization.base.PropertyUpdateRule;
+import org.simantics.structural.synchronization.base.Solver;
+
+public class StyleUpdater extends ModuleUpdaterBase<SheetLineComponent> {
+
+    private static class ForegroundUpdateRule implements PropertyUpdateRule<SheetLineComponent> {
+        @Override
+        public String getPropertyName() {
+            return "foreground";
+        }
+        
+        @Override
+        public void apply(ModuleUpdateContext<SheetLineComponent> context, boolean isCreating, Map<String, Variant> propertyMap, Map<String, Collection<String>> connectionMap, Variant value) {
+            StyleCommandBuilder builder = context.getConcreteCommand();
+            RGB.Integer color = (RGB.Integer) value.getValue();
+            builder.foreground = color;
+        }
+    }
+    
+    private static class BackgroundUpdateRule implements PropertyUpdateRule<SheetLineComponent> {
+        @Override
+        public String getPropertyName() {
+            return "background";
+        }
+
+        @Override
+        public void apply(ModuleUpdateContext<SheetLineComponent> context, boolean isCreating, Map<String, Variant> propertyMap, Map<String, Collection<String>> connectionMap, Variant value) {
+            StyleCommandBuilder builder = context.getConcreteCommand();
+            RGB.Integer color = (RGB.Integer) value.getValue();
+            builder.background = color;
+        }
+    }
+    
+    private static class FontUpdateRule implements PropertyUpdateRule<SheetLineComponent> {
+        @Override
+        public String getPropertyName() {
+            return "font";
+        }
+
+        @Override
+        public void apply(ModuleUpdateContext<SheetLineComponent> context, boolean isCreating, Map<String, Variant> propertyMap, Map<String, Collection<String>> connectionMap, Variant value) {
+            StyleCommandBuilder builder = context.getConcreteCommand();
+            Font font = (Font) value.getValue();
+            builder.font = font;
+        }
+    }
+
+    private static class AlignUpdateRule implements PropertyUpdateRule<SheetLineComponent> {
+        @Override
+        public String getPropertyName() {
+            return "align";
+        }
+
+        @Override
+        public void apply(ModuleUpdateContext<SheetLineComponent> context, boolean isCreating, Map<String, Variant> propertyMap, Map<String, Collection<String>> connectionMap, Variant value) {
+            StyleCommandBuilder builder = context.getConcreteCommand();
+            int align = (int) value.getValue();
+            builder.align = align;
+        }
+    }
+    
+    private static class FormatStringUpdateRule implements PropertyUpdateRule<SheetLineComponent> {
+        @Override
+        public String getPropertyName() {
+            return "formatString";
+        }
+
+        @Override
+        public void apply(ModuleUpdateContext<SheetLineComponent> context, boolean isCreating, Map<String, Variant> propertyMap, Map<String, Collection<String>> connectionMap, Variant value) {
+            StyleCommandBuilder builder = context.getConcreteCommand();
+            String formatString = (String) value.getValue();
+            builder.formatString = formatString;
+        }
+    }
+
+    private static class FormatIndexUpdateRule implements PropertyUpdateRule<SheetLineComponent> {
+        @Override
+        public String getPropertyName() {
+            return "formatIndex";
+        }
+
+        @Override
+        public void apply(ModuleUpdateContext<SheetLineComponent> context, boolean isCreating, Map<String, Variant> propertyMap, Map<String, Collection<String>> connectionMap, Variant value) {
+            StyleCommandBuilder builder = context.getConcreteCommand();
+            int index = (int) value.getValue();
+            builder.formatIndex = index;
+        }
+    }
+
+    private static class BorderUpdateRule implements PropertyUpdateRule<SheetLineComponent> {
+        @Override
+        public String getPropertyName() {
+            return "border";
+        }
+
+        @Override
+        public void apply(ModuleUpdateContext<SheetLineComponent> context, boolean isCreating, Map<String, Variant> propertyMap, Map<String, Collection<String>> connectionMap, Variant value) {
+            StyleCommandBuilder builder = context.getConcreteCommand();
+            int border = (int) value.getValue();
+            builder.border = border;
+        }
+    }
+    
+    private static class LockedUpdateRule implements PropertyUpdateRule<SheetLineComponent> {
+        @Override
+        public String getPropertyName() {
+            return "locked";
+        }
+
+        @Override
+        public void apply(ModuleUpdateContext<SheetLineComponent> context, boolean isCreating, Map<String, Variant> propertyMap, Map<String, Collection<String>> connectionMap, Variant value) {
+            StyleCommandBuilder builder = context.getConcreteCommand();
+            boolean locked = (boolean) value.getValue();
+            builder.locked = locked;
+        }
+    }
+    
+    private static class ColumnSpanUpdateRule implements PropertyUpdateRule<SheetLineComponent> {
+        @Override
+        public String getPropertyName() {
+            return "columnSpan";
+        }
+
+        @Override
+        public void apply(ModuleUpdateContext<SheetLineComponent> context, boolean isCreating, Map<String, Variant> propertyMap, Map<String, Collection<String>> connectionMap, Variant value) {
+            StyleCommandBuilder builder = context.getConcreteCommand();
+            int columnSpan = (int) value.getValue();
+            builder.columnSpan = columnSpan;
+        }
+    }
+    
+    private static class RowSpanUpdateRule implements PropertyUpdateRule<SheetLineComponent> {
+        @Override
+        public String getPropertyName() {
+            return "rowSpan";
+        }
+
+        @Override
+        public void apply(ModuleUpdateContext<SheetLineComponent> context, boolean isCreating, Map<String, Variant> propertyMap, Map<String, Collection<String>> connectionMap, Variant value) {
+            StyleCommandBuilder builder = context.getConcreteCommand();
+            int rowSpan = (int) value.getValue();
+            builder.rowSpan = rowSpan;
+        }
+    }
+
+    
+    public StyleUpdater(String moduleType) {
+        super(moduleType);
+        
+        addPropertyUpdateRule(new ForegroundUpdateRule());
+        addPropertyUpdateRule(new BackgroundUpdateRule());
+        addPropertyUpdateRule(new FontUpdateRule());
+        addPropertyUpdateRule(new AlignUpdateRule());
+        addPropertyUpdateRule(new FormatStringUpdateRule());
+        addPropertyUpdateRule(new FormatIndexUpdateRule());
+        addPropertyUpdateRule(new BorderUpdateRule());
+        addPropertyUpdateRule(new LockedUpdateRule());
+        addPropertyUpdateRule(new ColumnSpanUpdateRule());
+        addPropertyUpdateRule(new RowSpanUpdateRule());
+    }
+
+    @Override
+    public CommandBuilder createAddCommandBuilder(final String name) {
+        return new StyleCommandBuilder(name, false);
+    }
+
+    @Override
+    public CommandBuilder createUpdateCommandBuilder(String name) {
+        return new StyleCommandBuilder(name, true);
+    }
+    
+    private static class StyleCommandBuilder implements CommandBuilder {
+
+        protected int rowSpan;
+        protected int columnSpan;
+        protected int border;
+        protected boolean locked;
+        protected int formatIndex;
+        protected String formatString;
+        protected org.simantics.datatypes.literal.RGB.Integer background;
+        protected org.simantics.datatypes.literal.RGB.Integer foreground;
+        protected Font font;
+        protected int align;
+        
+        private boolean update;
+        private String name;
+        
+        public StyleCommandBuilder(String name, boolean update) {
+            this.name = name.split("/")[1];
+            this.update = update;
+        }
+        
+        @Override
+        public void apply(Solver solver) {
+            SpreadsheetBook book = solver.getConcreteSolver();
+            SpreadsheetStyle style = SpreadsheetStyle.newInstace().name(name).align(align).font(font)
+                    .background(background).foreground(foreground).border(border).locked(locked).rowSpan(rowSpan)
+                    .columnSpan(columnSpan).formatIndex((short) formatIndex).formatString(formatString).build();
+            if (book.getStyle(style.getStyleId()) == null)
+                book.addStyle(style);
+            
+        }
+
+        @SuppressWarnings("unchecked")
+        @Override
+        public <T> T getConcrete() {
+            return (T) this;
+        }
+        
+        @Override
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            sb.append("StyleCommandBuilder for ").append(name).append(" [background=").append(background).append(", foregroung=").append(foreground).append(", font=").append(font).append(", align=").append(align).append("]");
+            return sb.toString();
+        }
+        
+    }
+    
+}