]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
PropertyPage for changing default colors of diagram elements. Currently only Dependen...
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 25 Oct 2013 08:57:16 +0000 (08:57 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 25 Oct 2013 08:57:16 +0000 (08:57 +0000)
refs #4481

git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@28120 ac1ea38d-2e2b-0410-8846-a27921b304fc

14 files changed:
org.simantics.modelica/src/org/simantics/modelica/data/SimulationResult.java
org.simantics.sysdyn.ontology/graph.tg
org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph
org.simantics.sysdyn.ontology/src/org/simantics/sysdyn/SysdynResource.java
org.simantics.sysdyn.ui/plugin.xml
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/SysdynElementFactory.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/connections/DependencyConnectionFactory.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/SysdynDiagramPreferencePage.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/SysdynDiagramPreferences.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/SysdynDiagramPreferencesInitializer.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/SysdynDiagramPropertyExternalRead.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/SysdynDiagramPropertySubscription.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/SysdynDiagramPropertySupport.java [new file with mode: 0644]
org.simantics.sysdyn.ui/sysdyn.product

index 3f18705800c4bd2e44d965d8f71de4dabbc695b5..315b1fc847a800ad6f4b3e98236356fe46893bf8 100644 (file)
@@ -410,10 +410,10 @@ public class SimulationResult {
      */\r
     public DataSet getDataSet(String name) {\r
         for(DataSet set : variables)\r
-            if(set.name.equals(name))\r
+            if(set.name.equalsIgnoreCase(name))\r
                 return set;\r
         for(DataSet set : initials)\r
-            if(set.name.equals(name))\r
+            if(set.name.equalsIgnoreCase(name))\r
                 return set;\r
         return null;\r
     }\r
index 17eab9a3c4491791d58cd0ddfcbc86aac5f97fc8..5046ca49bfab2b29f943c25b83273bfd92df5760 100644 (file)
Binary files a/org.simantics.sysdyn.ontology/graph.tg and b/org.simantics.sysdyn.ontology/graph.tg differ
index fa30152aac68cf607b3f3d3515c41d6095f14907..c209722f659e1e36c626bf858b3f1061bce04716 100644 (file)
@@ -24,8 +24,8 @@ SYSDYN.ImportedOntologies : PROJ.NamespaceRequirement
         "http://www.simantics.org/Sysdyn-1.1" : L0.URI
         "http://www.simantics.org/Layer0-1.1" : L0.URI
         "http://www.simantics.org/SelectionView-1.2" : L0.URI
-//        "http://www.simantics.org/Documentation-1.1" : L0.URI // Experimental documentation tool
-//        "http://www.simantics.org/DocumentWorkbench-1.0" : L0.URI // Experimental documentation tool
+        //"http://www.semantum.fi/Simupedia-1.0" : L0.URI // Experimental Simupedia
+        //"http://www.semantum.fi/SimupediaWorkbench-1.0" : L0.URI // Experimental Simupedia
                 
 SYSDYN.SharedFunctionOntology <T L0.Ontology
 SYSDYN.SharedModuleOntology <T L0.Ontology      
@@ -426,6 +426,19 @@ SYSDYN.ResultSet <T L0.Entity
 //#####################################################################
 //#####################################################################    
 
+//#####################################################################
+// Defaults
+//#####################################################################
+          //G2D.HasFont _ : G2D.Font
+SYSDYN.DefaultFont : G2D.Font          
+  G2D.HasFontFamily "Tahoma"
+  G2D.HasFontSize 12
+  G2D.HasFontStyle G2D.FontStyle.normal_font_style
+  
+SYSDYN.SysdynSymbol <T DIA.FontProvider <T DIA.ColorProvider
+    @L0.assert G2D.HasFont SYSDYN.DefaultFont
+
+    
 //#####################################################################
 // Component types
 //#####################################################################
@@ -456,7 +469,7 @@ SYSDYN.Top <T SYSDYN.Location
 SYSDYN.Bottom <T SYSDYN.Location
 SYSDYN.Center <T SYSDYN.Location
 
-SYSDYN.ValveSymbol <T DIA.FontProvider <T DIA.ColorProvider
+SYSDYN.ValveSymbol <T SYSDYN.SysdynSymbol
     @MOD.defSymbol "Valve" SYSDYN.Valve
     >-- SYSDYN.ValveSymbol.orientation --> SYSDYN.Orientation <R L0.IsWeaklyRelatedTo : L0.FunctionalRelation
     @L0.assert SYSDYN.ValveSymbol.orientation SYSDYN.Horizontal
@@ -474,7 +487,7 @@ SYSDYN.Auxiliary
     @MOD.connection SYSDYN.Variable.isTailOf
     @MOD.connection SYSDYN.Variable.isHeadOf
 
-SYSDYN.AuxiliarySymbol <T DIA.FontProvider <T DIA.ColorProvider
+SYSDYN.AuxiliarySymbol <T SYSDYN.SysdynSymbol
     @MOD.defSymbol "Auxiliary" SYSDYN.Auxiliary
     L0.IsDependencyOf BasicSymbols
     STR.IsDefinedBy _ : DIA.Composite <R L0.HasNext 
@@ -489,7 +502,7 @@ SYSDYN.Cloud
     @MOD.connection SYSDYN.Variable.isTailOf
     @MOD.connection SYSDYN.Variable.isHeadOf
 
-SYSDYN.CloudSymbol <T DIA.FontProvider <T DIA.ColorProvider
+SYSDYN.CloudSymbol <T SYSDYN.SysdynSymbol
     @MOD.defSymbol "Cloud" SYSDYN.Cloud
     L0.IsDependencyOf BasicSymbols
     STR.IsDefinedBy _ : DIA.Composite <R L0.HasNext 
@@ -504,7 +517,7 @@ SYSDYN.Input
     @MOD.connection SYSDYN.Variable.isTailOf
     @MOD.connection SYSDYN.Variable.isHeadOf
 
-SYSDYN.InputSymbol <T DIA.FontProvider <T DIA.ColorProvider
+SYSDYN.InputSymbol <T SYSDYN.SysdynSymbol
     @MOD.defSymbol "Input" SYSDYN.Input
     L0.IsDependencyOf BasicSymbols
     STR.IsDefinedBy _ : DIA.Composite <R L0.HasNext 
@@ -519,7 +532,7 @@ SYSDYN.Stock <T STR.Component
     @MOD.connection SYSDYN.Variable.isTailOf
     @MOD.connection SYSDYN.Variable.isHeadOf
 
-SYSDYN.StockSymbol <T DIA.FontProvider <T DIA.ColorProvider
+SYSDYN.StockSymbol <T SYSDYN.SysdynSymbol
     @MOD.defSymbol "Stock" SYSDYN.Stock
     L0.IsDependencyOf BasicSymbols
     STR.IsDefinedBy _ : DIA.Composite <R L0.HasNext 
@@ -534,7 +547,7 @@ SYSDYN.Shadow
     @MOD.connection SYSDYN.Variable.isTailOf
     @MOD.connection SYSDYN.Variable.isHeadOf
 
-SYSDYN.ShadowSymbol <T DIA.FontProvider <T DIA.ColorProvider
+SYSDYN.ShadowSymbol <T SYSDYN.SysdynSymbol
     @MOD.defSymbol "Shadow" SYSDYN.Shadow
     L0.IsDependencyOf BasicSymbols
     STR.IsDefinedBy _ : DIA.Composite <R L0.HasNext 
@@ -553,6 +566,7 @@ SYSDYN.ShadowSymbol <T DIA.FontProvider <T DIA.ColorProvider
 SYSDYN.FlowConnection <T DIA.RouteGraphConnection <T DIA.FontProvider <T DIA.ColorProvider
     MOD.DiagramConnectionTypeToConnectionType
         SYSDYN.Flow  
+    @L0.assert G2D.HasFont SYSDYN.DefaultFont     
 
 SYSDYN.DependencyConnection <T DIA.Connection <T DIA.FontProvider <T DIA.ColorProvider
     @L0.singleProperty SYSDYN.Dependency.angle
@@ -561,6 +575,9 @@ SYSDYN.DependencyConnection <T DIA.Connection <T DIA.FontProvider <T DIA.ColorPr
     @L0.assert SYSDYN.Dependency.angle 0.1
     MOD.DiagramConnectionTypeToConnectionType
         SYSDYN.Dependency
+    @L0.assert G2D.HasFont SYSDYN.DefaultFont
+    @L0.assert G2D.HasColor 
+        [0.0,0.0,1.0,1.0] : G2D.Color        
 
 // TODO: Browser URIs
 
index 7786957177e40d62badec76efc9304e3ac7aaab1..08d0361ede24e7c0ca458d2644a60211b2e7588d 100644 (file)
@@ -329,6 +329,7 @@ public class SysdynResource {
     public final Resource ConfigurationDiagram_selection;\r
     public final Resource ConfigurationDiagram_selection_Inverse;\r
     public final Resource ConstantExpression;\r
+    public final Resource DefaultFont;\r
     public final Resource DefaultProfile;\r
     public final Resource DefaultRealization;\r
     public final Resource DelayExpression;\r
@@ -644,6 +645,7 @@ public class SysdynResource {
     public final Resource SysdynModelicaFunction_outputs_Inverse;\r
     public final Resource SysdynModuleLibrary;\r
     public final Resource SysdynOperationBrowser;\r
+    public final Resource SysdynSymbol;\r
     public final Resource SysdynTerminal;\r
     public final Resource Top;\r
     public final Resource UniformDistribution;\r
@@ -1071,6 +1073,7 @@ public class SysdynResource {
         public static final String ConfigurationDiagram_selection = "http://www.simantics.org/Sysdyn-1.1/ConfigurationDiagram/selection";\r
         public static final String ConfigurationDiagram_selection_Inverse = "http://www.simantics.org/Sysdyn-1.1/ConfigurationDiagram/selection/Inverse";\r
         public static final String ConstantExpression = "http://www.simantics.org/Sysdyn-1.1/ConstantExpression";\r
+        public static final String DefaultFont = "http://www.simantics.org/Sysdyn-1.1/DefaultFont";\r
         public static final String DefaultProfile = "http://www.simantics.org/Sysdyn-1.1/DefaultProfile";\r
         public static final String DefaultRealization = "http://www.simantics.org/Sysdyn-1.1/DefaultRealization";\r
         public static final String DelayExpression = "http://www.simantics.org/Sysdyn-1.1/DelayExpression";\r
@@ -1386,6 +1389,7 @@ public class SysdynResource {
         public static final String SysdynModelicaFunction_outputs_Inverse = "http://www.simantics.org/Sysdyn-1.1/SysdynModelicaFunction/outputs/Inverse";\r
         public static final String SysdynModuleLibrary = "http://www.simantics.org/Sysdyn-1.1/SysdynModuleLibrary";\r
         public static final String SysdynOperationBrowser = "http://www.simantics.org/Sysdyn-1.1/SysdynOperationBrowser";\r
+        public static final String SysdynSymbol = "http://www.simantics.org/Sysdyn-1.1/SysdynSymbol";\r
         public static final String SysdynTerminal = "http://www.simantics.org/Sysdyn-1.1/SysdynTerminal";\r
         public static final String Top = "http://www.simantics.org/Sysdyn-1.1/Top";\r
         public static final String UniformDistribution = "http://www.simantics.org/Sysdyn-1.1/UniformDistribution";\r
@@ -1823,6 +1827,7 @@ public class SysdynResource {
         ConfigurationDiagram_selection = getResourceOrNull(graph, URIs.ConfigurationDiagram_selection);\r
         ConfigurationDiagram_selection_Inverse = getResourceOrNull(graph, URIs.ConfigurationDiagram_selection_Inverse);\r
         ConstantExpression = getResourceOrNull(graph, URIs.ConstantExpression);\r
+        DefaultFont = getResourceOrNull(graph, URIs.DefaultFont);\r
         DefaultProfile = getResourceOrNull(graph, URIs.DefaultProfile);\r
         DefaultRealization = getResourceOrNull(graph, URIs.DefaultRealization);\r
         DelayExpression = getResourceOrNull(graph, URIs.DelayExpression);\r
@@ -2138,6 +2143,7 @@ public class SysdynResource {
         SysdynModelicaFunction_outputs_Inverse = getResourceOrNull(graph, URIs.SysdynModelicaFunction_outputs_Inverse);\r
         SysdynModuleLibrary = getResourceOrNull(graph, URIs.SysdynModuleLibrary);\r
         SysdynOperationBrowser = getResourceOrNull(graph, URIs.SysdynOperationBrowser);\r
+        SysdynSymbol = getResourceOrNull(graph, URIs.SysdynSymbol);\r
         SysdynTerminal = getResourceOrNull(graph, URIs.SysdynTerminal);\r
         Top = getResourceOrNull(graph, URIs.Top);\r
         UniformDistribution = getResourceOrNull(graph, URIs.UniformDistribution);\r
index 69b129a7002bcbfb6d210b302e96d1cb04fe71f7..e422b73e14dec79066956b45ece147bee75c001f 100644 (file)
             id="org.simantics.modelica.preferences"\r
             name="Modelica">\r
       </page>\r
+      <page\r
+            class="org.simantics.sysdyn.ui.preferences.SysdynDiagramPreferencePage"\r
+            id="org.simantics.sysdyn.diagram.preferences"\r
+            name="Sysdyn Diagrams">\r
+      </page>      \r
    </extension>\r
    <extension\r
          point="org.eclipse.core.runtime.preferences">\r
       <initializer\r
             class="org.simantics.modelica.preferences.ModelicaPreferenceInitializer">\r
       </initializer>\r
+      <initializer\r
+            class="org.simantics.sysdyn.ui.preferences.SysdynDiagramPreferencesInitializer">\r
+      </initializer>      \r
    </extension>\r
 </plugin>\r
index 4686cc62b177da43ba4cf52d7c86b937d0bd9b36..61415eca862a1f673a9b542e5651f07d1579645a 100644 (file)
@@ -19,6 +19,7 @@ import java.util.Collections;
 \r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
+import org.simantics.db.Statement;\r
 import org.simantics.db.common.utils.OrderedSetUtils;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.exception.ManyObjectsForFunctionalRelationException;\r
@@ -101,9 +102,12 @@ public abstract class SysdynElementFactory extends SyncElementFactory {
                 ElementUtils.setTextFont(e, G2DUtils.getFont(graph, fontResource));\r
         }\r
         if (graph.isInstanceOf(element, dr.ColorProvider)) {\r
-            Resource colorResource = graph.getPossibleObject(element, g2d.HasColor);\r
-            if (colorResource != null)\r
-                ElementUtils.setTextColor(e, G2DUtils.getColor(graph, colorResource));\r
+            Statement colorStatement = graph.getPossibleStatement(element, g2d.HasColor);\r
+            if (colorStatement != null && !colorStatement.isAsserted(element))\r
+                ElementUtils.setTextColor(e, G2DUtils.getColor(graph, colorStatement.getObject()));\r
+            else {\r
+                \r
+            }\r
         }\r
 \r
         Resource component = graph.getPossibleObject(element, mr.ElementToComponent);\r
index fcfb5445929e89de715b49dcb441a5915f28ca5d..b521dd4bb88282e2dc8208e83fa591b419e9232a 100644 (file)
  *******************************************************************************/\r
 package org.simantics.sysdyn.ui.elements.connections;\r
 \r
+import java.awt.Color;\r
 import java.util.HashMap;\r
 import java.util.concurrent.ConcurrentSkipListMap;\r
 import java.util.concurrent.atomic.AtomicInteger;\r
 \r
+import org.eclipse.jface.resource.StringConverter;\r
+import org.eclipse.swt.graphics.RGB;\r
 import org.simantics.databoard.Bindings;\r
 import org.simantics.db.AsyncReadGraph;\r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
+import org.simantics.db.Statement;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.procedure.AsyncMultiProcedure;\r
 import org.simantics.db.procedure.AsyncProcedure;\r
@@ -36,6 +40,8 @@ import org.simantics.g2d.element.IElement;
 import org.simantics.g2d.element.handler.impl.StaticObjectAdapter;\r
 import org.simantics.layer0.Layer0;\r
 import org.simantics.sysdyn.ui.editor.routing.DependencyRouter;\r
+import org.simantics.sysdyn.ui.preferences.SysdynDiagramPreferences;\r
+import org.simantics.sysdyn.ui.preferences.SysdynDiagramPropertyExternalRead;\r
 import org.simantics.utils.datastructures.Pair;\r
 \r
 /**\r
@@ -92,12 +98,22 @@ public class DependencyConnectionFactory extends ElementFactoryAdapter {
         });\r
         \r
         // Find possible color\r
-        graph.forPossibleObject(elementResource, G2D.HasColor, new SyncProcedure<Resource>() {\r
+        graph.forPossibleStatement(elementResource, G2D.HasColor, new SyncProcedure<Statement>() {\r
 \r
             @Override\r
-            public void execute(ReadGraph graph, Resource result) throws DatabaseException {\r
-                if(result != null) {\r
-                    element.setHint(ElementHints.KEY_TEXT_COLOR, G2DUtils.getColor(graph, result));\r
+            public void execute(ReadGraph graph, Statement result) throws DatabaseException {\r
+                if(result != null && !result.isAsserted(elementResource)) {\r
+                    element.setHint(ElementHints.KEY_TEXT_COLOR, G2DUtils.getColor(graph, result.getObject()));\r
+                } else {\r
+                    String color = graph.syncRequest(new SysdynDiagramPropertyExternalRead(new Pair<Resource, String>(elementResource, SysdynDiagramPreferences.ARROW_COLOR)));\r
+                    if(color != null) {\r
+                        RGB rgb = StringConverter.asRGB(color, null);\r
+                        if(rgb != null) {\r
+                            Color c = new Color(rgb.red, rgb.green, rgb.blue);\r
+                            element.setHint(ElementHints.KEY_TEXT_COLOR, c);\r
+                        }\r
+                    }\r
+\r
                 }\r
             }\r
 \r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/SysdynDiagramPreferencePage.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/SysdynDiagramPreferencePage.java
new file mode 100644 (file)
index 0000000..ce357b7
--- /dev/null
@@ -0,0 +1,89 @@
+/*******************************************************************************\r
+ * Copyright (c) 2013 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     Semantum Oy\r
+ *******************************************************************************/\r
+\r
+package org.simantics.sysdyn.ui.preferences;\r
+\r
+import org.eclipse.jface.preference.ColorFieldEditor;\r
+import org.eclipse.jface.preference.FieldEditorPreferencePage;\r
+import org.eclipse.ui.IEditorPart;\r
+import org.eclipse.ui.IWorkbench;\r
+import org.eclipse.ui.IWorkbenchPage;\r
+import org.eclipse.ui.IWorkbenchPreferencePage;\r
+import org.eclipse.ui.IWorkbenchWindow;\r
+import org.eclipse.ui.PlatformUI;\r
+import org.simantics.g2d.diagram.DiagramUtils;\r
+import org.simantics.g2d.diagram.IDiagram;\r
+import org.simantics.modeling.ui.diagramEditor.DiagramEditor;\r
+import org.simantics.sysdyn.ui.Activator;\r
+\r
+/**\r
+ * \r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
+public class SysdynDiagramPreferencePage extends FieldEditorPreferencePage implements\r
+IWorkbenchPreferencePage {\r
+\r
+    public SysdynDiagramPreferencePage() {\r
+        super(GRID);\r
+        setDescription("System dynamics diagram preferences");\r
+    }\r
+\r
+    @Override\r
+    public void init(IWorkbench workbench) {\r
+        setPreferenceStore(Activator.getDefault().getPreferenceStore());\r
+    }\r
+\r
+    @Override\r
+    protected void createFieldEditors() {\r
+        addField(new ColorFieldEditor(SysdynDiagramPreferences.ARROW_COLOR, "&Dependency", getFieldEditorParent()));\r
+        addField(new ColorFieldEditor(SysdynDiagramPreferences.FLOW_COLOR, "&Flow", getFieldEditorParent()));\r
+        addField(new ColorFieldEditor(SysdynDiagramPreferences.AUXILIARY_COLOR, "&Auxiliary", getFieldEditorParent()));\r
+        addField(new ColorFieldEditor(SysdynDiagramPreferences.STOCK_COLOR, "&Stock", getFieldEditorParent()));\r
+        addField(new ColorFieldEditor(SysdynDiagramPreferences.VALVE_COLOR, "&Valve", getFieldEditorParent()));\r
+        addField(new ColorFieldEditor(SysdynDiagramPreferences.CLOUD_COLOR, "&Cloud", getFieldEditorParent()));\r
+    }\r
+\r
+    @Override\r
+    public boolean performOk() {\r
+        IEditorPart editor = null;\r
+        IWorkbench workbench = PlatformUI.getWorkbench();\r
+        IWorkbenchWindow[] windows = workbench.getWorkbenchWindows();\r
+        // To ask for the active window doesn't work, so browse through all\r
+        // windows and when an active editor is found, use that\r
+        for (IWorkbenchWindow window : windows) {\r
+            IWorkbenchPage page = window.getActivePage();\r
+            if (page != null) {\r
+                editor = (IEditorPart)page.getActiveEditor();\r
+                if (editor != null)\r
+                    break;\r
+            }\r
+        }\r
+        if (editor != null) {\r
+            if (editor instanceof DiagramEditor) {\r
+                DiagramEditor diagramEditor = (DiagramEditor) editor;\r
+                IDiagram o = (IDiagram) diagramEditor.getViewer().getAdapter(IDiagram.class);\r
+//                ICanvasContext o = (ICanvasContext) diagramEditor.getViewer().getAdapter(ICanvasContext.class);\r
+                if(o != null) {\r
+                    DiagramUtils.invalidate(o);\r
+                    DiagramUtils.validateAndFix(o, o.getElements());\r
+                    \r
+//                    o.getContentContext().setDirty();\r
+                }\r
+            }\r
+        }\r
+\r
+\r
+        return super.performOk();\r
+    }\r
+\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/SysdynDiagramPreferences.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/SysdynDiagramPreferences.java
new file mode 100644 (file)
index 0000000..5ab40e6
--- /dev/null
@@ -0,0 +1,29 @@
+/*******************************************************************************\r
+ * Copyright (c) 2013 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     Semantum Oy\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.ui.preferences;\r
+\r
+/**\r
+ * \r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
+public class SysdynDiagramPreferences {\r
+\r
+    public static String ARROW_COLOR = "Arrow color";\r
+    public static String FLOW_COLOR = "Flow color";\r
+    public static String AUXILIARY_COLOR = "Auxiliary color";\r
+    public static String CLOUD_COLOR = "Cloud color";\r
+    public static String STOCK_COLOR = "Stock color";\r
+    public static String VALVE_COLOR = "Valve color";\r
+\r
+    \r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/SysdynDiagramPreferencesInitializer.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/SysdynDiagramPreferencesInitializer.java
new file mode 100644 (file)
index 0000000..0539888
--- /dev/null
@@ -0,0 +1,39 @@
+/*******************************************************************************\r
+ * Copyright (c) 2013 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     Semantum Oy\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.ui.preferences;\r
+\r
+import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;\r
+import org.eclipse.jface.preference.IPreferenceStore;\r
+import org.eclipse.jface.resource.StringConverter;\r
+import org.eclipse.swt.graphics.RGB;\r
+import org.simantics.sysdyn.ui.Activator;\r
+\r
+/**\r
+ * \r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
+public class SysdynDiagramPreferencesInitializer extends AbstractPreferenceInitializer {  \r
+\r
+    @Override  \r
+    public void initializeDefaultPreferences() {\r
+        IPreferenceStore store = Activator.getDefault().getPreferenceStore();\r
+        store.setDefault(SysdynDiagramPreferences.ARROW_COLOR, StringConverter.asString(new RGB(0, 0, 255)));\r
+        store.setDefault(SysdynDiagramPreferences.FLOW_COLOR, StringConverter.asString(new RGB(0, 0, 0)));\r
+        store.setDefault(SysdynDiagramPreferences.AUXILIARY_COLOR, StringConverter.asString(new RGB(0, 0, 0)));\r
+        store.setDefault(SysdynDiagramPreferences.STOCK_COLOR, StringConverter.asString(new RGB(0, 0, 0)));\r
+        store.setDefault(SysdynDiagramPreferences.VALVE_COLOR, StringConverter.asString(new RGB(0, 0, 0)));\r
+        store.setDefault(SysdynDiagramPreferences.CLOUD_COLOR, StringConverter.asString(new RGB(0, 0, 0)));\r
+    }  \r
+\r
+\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/SysdynDiagramPropertyExternalRead.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/SysdynDiagramPropertyExternalRead.java
new file mode 100644 (file)
index 0000000..4d76f61
--- /dev/null
@@ -0,0 +1,48 @@
+/*******************************************************************************\r
+ * Copyright (c) 2013 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     Semantum Oy\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.ui.preferences;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.request.ParametrizedPrimitiveRead;\r
+import org.simantics.db.procedure.Listener;\r
+import org.simantics.sysdyn.ui.Activator;\r
+import org.simantics.utils.datastructures.Pair;\r
+\r
+/**\r
+ * \r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
+public class SysdynDiagramPropertyExternalRead extends ParametrizedPrimitiveRead<Pair<Resource, String>, String> {\r
+\r
+    private SysdynDiagramPropertySubscription subscription;\r
+\r
+    public SysdynDiagramPropertyExternalRead(Pair<Resource, String> input) {\r
+        super(input);\r
+    }\r
+\r
+    @Override\r
+    public void register(ReadGraph graph, Listener<String> procedure) {\r
+        subscription = new SysdynDiagramPropertySubscription(procedure, parameter.second);\r
+        SysdynDiagramPropertySupport.INSTANCE.register(subscription);\r
+        procedure.execute(Activator.getDefault().getPreferenceStore().getString(parameter.second));\r
+    }\r
+    \r
+    @Override\r
+    public void unregistered() {\r
+        if(subscription != null) {\r
+            SysdynDiagramPropertySupport.INSTANCE.unregister(subscription);\r
+            subscription = null;\r
+        }\r
+    }\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/SysdynDiagramPropertySubscription.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/SysdynDiagramPropertySubscription.java
new file mode 100644 (file)
index 0000000..286572c
--- /dev/null
@@ -0,0 +1,38 @@
+/*******************************************************************************\r
+ * Copyright (c) 2013 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     Semantum Oy\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.ui.preferences;\r
+\r
+import org.simantics.db.procedure.Listener;\r
+\r
+/**\r
+ * \r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
+public class SysdynDiagramPropertySubscription {\r
+    \r
+    private Listener<String> listener;\r
+    private String propertyName;\r
+    \r
+    public SysdynDiagramPropertySubscription(Listener<String> listener, String propertyName) {\r
+        this.listener = listener;\r
+        this.propertyName = propertyName;\r
+    }\r
+\r
+    public Listener<String> getListener() {\r
+        return listener;\r
+    }\r
+    \r
+    public String getPropertyName() {\r
+        return propertyName;\r
+    }\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/SysdynDiagramPropertySupport.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/SysdynDiagramPropertySupport.java
new file mode 100644 (file)
index 0000000..1e5d5b5
--- /dev/null
@@ -0,0 +1,101 @@
+/*******************************************************************************\r
+ * Copyright (c) 2013 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     Semantum Oy\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.ui.preferences;\r
+\r
+import gnu.trove.set.hash.THashSet;\r
+\r
+import java.util.HashSet;\r
+import java.util.Set;\r
+\r
+import org.eclipse.jface.resource.StringConverter;\r
+import org.eclipse.jface.util.IPropertyChangeListener;\r
+import org.eclipse.jface.util.PropertyChangeEvent;\r
+import org.eclipse.swt.graphics.RGB;\r
+import org.simantics.sysdyn.ui.Activator;\r
+\r
+/**\r
+ * \r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
+public class SysdynDiagramPropertySupport {\r
+    \r
+    public static SysdynDiagramPropertySupport INSTANCE = new SysdynDiagramPropertySupport();\r
+    \r
+    private Set<String> diagramProperties;\r
+    private THashSet<SysdynDiagramPropertySubscription> subscriptions = new THashSet<SysdynDiagramPropertySubscription>();\r
+    private SysdynDiagramPropertySubscription[] subscriptionSnapshot = null;\r
+    \r
+    private void add(String property) {\r
+        diagramProperties.add(property);\r
+    }\r
+    \r
+    public SysdynDiagramPropertySupport() {\r
+        diagramProperties = new HashSet<String>();\r
+        add(SysdynDiagramPreferences.ARROW_COLOR);\r
+        add(SysdynDiagramPreferences.AUXILIARY_COLOR);\r
+        add(SysdynDiagramPreferences.CLOUD_COLOR);\r
+        add(SysdynDiagramPreferences.FLOW_COLOR);\r
+        add(SysdynDiagramPreferences.STOCK_COLOR);\r
+        add(SysdynDiagramPreferences.VALVE_COLOR);\r
+        \r
+        Activator.getDefault().getPreferenceStore().addPropertyChangeListener(new IPropertyChangeListener() {\r
+            @Override\r
+            public void propertyChange(PropertyChangeEvent event) {\r
+                String propertyName = event.getProperty();\r
+                if(diagramProperties.contains(propertyName)){\r
+                    for(SysdynDiagramPropertySubscription subscription : getSubscriptionSnapshot()) {\r
+                        if(propertyName.equals(subscription.getPropertyName())) {\r
+                            Object newValue = event.getNewValue();\r
+                            String result = newValue.toString();\r
+                            if(newValue instanceof RGB) \r
+                                result = StringConverter.asString((RGB)newValue);\r
+                            subscription.getListener().execute(result);\r
+                        }\r
+                    }\r
+                }\r
+            }\r
+        });\r
+    }\r
+\r
+    public void register(SysdynDiagramPropertySubscription subscription) {\r
+        assert subscription != null;\r
+        synchronized (subscriptions) {\r
+            subscriptions.add(subscription);\r
+            subscriptionSnapshot = null;\r
+        }\r
+    }\r
+\r
+    public void unregister(SysdynDiagramPropertySubscription subscription) {\r
+        assert subscription != null;\r
+        synchronized (subscriptions) {\r
+            subscriptions.remove(subscription);\r
+            subscriptionSnapshot = null;\r
+        }\r
+\r
+    }\r
+    \r
+    public SysdynDiagramPropertySubscription[] getSubscriptionSnapshot() {\r
+        SysdynDiagramPropertySubscription[] snapshot = subscriptionSnapshot;\r
+        if (snapshot == null) {\r
+            synchronized (subscriptions) {\r
+                snapshot = subscriptionSnapshot;\r
+                if (snapshot == null) {\r
+                    snapshot = subscriptionSnapshot = \r
+                            subscriptions.toArray(new SysdynDiagramPropertySubscription[subscriptions.size()]);\r
+                }\r
+            }\r
+        }\r
+        return snapshot;\r
+    }    \r
+\r
+}\r
index 921a8d4c3232ee6bf0d0ecdbeb515726974a7cf7..d65c835ebf54dea85d0151608cb9d51fc1eff4b5 100644 (file)
@@ -14,7 +14,8 @@
 \r
    <launcherArgs>\r
       <programArgs>-fixerrors\r
---launcher.XXMaxPermSize 192m</programArgs>\r
+--launcher.XXMaxPermSize 192m\r
+-data @noDefault</programArgs>\r
       <vmArgs>-ea  -Xmx768M -XX:MaxPermSize=192m -Xshare:off</vmArgs>\r
       <vmArgsMac>-XstartOnFirstThread -Dorg.eclipse.swt.internal.carbon.smallFonts</vmArgsMac>\r
    </launcherArgs>\r
@@ -30,7 +31,6 @@
       </win>\r
    </launcher>\r
 \r
-\r
    <vm>\r
       <windows include="true">org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6</windows>\r
    </vm>\r