]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/GroupStyleProfileEntry.java
Set initial priority for GroupStyleProfileEntry
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / adapter / GroupStyleProfileEntry.java
index 32c285721a76b978261a9d69e103184734fcf92d..f38d1971b50a960bb3b80d6b435ffc4d6054e40d 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in 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
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.diagram.adapter;\r
-\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.RequestProcessor;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.common.request.ReadRequest;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.diagram.stubs.DiagramResource;\r
-import org.simantics.scenegraph.profile.EvaluationContext;\r
-import org.simantics.scenegraph.profile.Group;\r
-import org.simantics.scenegraph.profile.ProfileEntry;\r
-import org.simantics.scenegraph.profile.Style;\r
-import org.simantics.utils.ui.ErrorLogger;\r
-\r
-public class GroupStyleProfileEntry implements ProfileEntry {\r
-\r
-    private final Resource entry;\r
-    private boolean        active = false;\r
-\r
-    private Style          style;\r
-    private Group          group;\r
-    private double         priority;\r
-\r
-    public GroupStyleProfileEntry(ReadGraph graph, Resource entry) throws DatabaseException {\r
-        this.entry = entry;\r
-\r
-        DiagramResource dr = DiagramResource.getInstance(graph);\r
-        Resource style = graph.getPossibleObject(entry, dr.ProfileEntry_HasStyle);\r
-        Resource group = graph.getPossibleObject(entry, dr.ProfileEntry_HasGroup);\r
-\r
-        Double priority = graph.getPossibleRelatedValue(entry, dr.ProfileEntry_HasPriority);\r
-        if(priority != null) this.priority = priority;\r
-        else this.priority = 0;\r
-\r
-        GroupStyleProfileEntry.this.style = graph.adapt(style, Style.class);\r
-        GroupStyleProfileEntry.this.group = graph.adapt(group, Group.class);\r
-    }\r
-\r
-    @Override\r
-    public void activate(RequestProcessor processor, final Resource runtimeDiagram, final EvaluationContext observer) {\r
-\r
-        try {\r
-            processor.syncRequest(new ReadRequest() {\r
-\r
-                @Override\r
-                public void run(ReadGraph graph) throws DatabaseException {\r
-\r
-                    GroupStyleProfileEntry.this.style.activate(graph, runtimeDiagram, entry, GroupStyleProfileEntry.this.group, observer);\r
-\r
-                }\r
-\r
-            });\r
-\r
-            active = true;\r
-\r
-        } catch (DatabaseException e) {\r
-            ErrorLogger.defaultLogError(e);\r
-        }\r
-    }\r
-\r
-    @Override\r
-    public void deactivate(Resource diagram, EvaluationContext observer) {\r
-        if (style == null) {\r
-            System.out.println("GroupStyleProfileEntry has null style!");\r
-            return;\r
-        }\r
-\r
-        style.deactivate(diagram, entry, group, observer);\r
-        active = false;\r
-    }\r
-\r
-    @Override\r
-    public void apply(EvaluationContext observer) {\r
-        if (style == null) {\r
-            System.out.println("GroupStyleProfileEntry has null style!");\r
-            return;\r
-        }\r
-        style.apply(entry, group, observer);\r
-    }\r
-\r
-    @Override\r
-    public int hashCode() {\r
-        return entry.hashCode();\r
-    }\r
-\r
-    @Override\r
-    public boolean equals(Object object) {\r
-        if (this == object)\r
-            return true;\r
-        else if (object == null)\r
-            return false;\r
-        else if (GroupStyleProfileEntry.class != object.getClass())\r
-            return false;\r
-        GroupStyleProfileEntry other = (GroupStyleProfileEntry)object;\r
-        return entry.equals(other.entry);\r
-    }\r
-    \r
-    @Override\r
-    public String toString() {\r
-        return "" + style + " applied to " + group;\r
-    }\r
-\r
-    @Override\r
-    public boolean isActive() {\r
-        return active;\r
-    }\r
-    \r
-    @Override\r
-    public double getPriority() {\r
-       return priority;\r
-    }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.diagram.adapter;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.RequestProcessor;
+import org.simantics.db.Resource;
+import org.simantics.db.common.request.ReadRequest;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.diagram.stubs.DiagramResource;
+import org.simantics.scenegraph.profile.EvaluationContext;
+import org.simantics.scenegraph.profile.Group;
+import org.simantics.scenegraph.profile.ProfileEntry;
+import org.simantics.scenegraph.profile.Style;
+import org.simantics.utils.ui.ErrorLogger;
+
+public class GroupStyleProfileEntry implements ProfileEntry {
+
+    private final Resource entry;
+    private boolean        active = false;
+
+    private Style          style;
+    private Group          group;
+    private double         priority;
+
+    public GroupStyleProfileEntry(ReadGraph graph, Resource entry) throws DatabaseException {
+        this.entry = entry;
+
+        DiagramResource dr = DiagramResource.getInstance(graph);
+        Resource style = graph.getPossibleObject(entry, dr.ProfileEntry_HasStyle);
+        Resource group = graph.getPossibleObject(entry, dr.ProfileEntry_HasGroup);
+
+        Double priority = graph.getPossibleRelatedValue(entry, dr.ProfileEntry_HasPriority);
+        if(priority != null) this.priority = priority;
+        else this.priority = 0;
+
+        GroupStyleProfileEntry.this.style = graph.adapt(style, Style.class);
+        GroupStyleProfileEntry.this.style.setPriority(this.priority);
+        GroupStyleProfileEntry.this.group = graph.adapt(group, Group.class);
+    }
+
+    @Override
+    public void activate(RequestProcessor processor, final Resource runtimeDiagram, final EvaluationContext observer) {
+
+        try {
+            processor.syncRequest(new ReadRequest() {
+
+                @Override
+                public void run(ReadGraph graph) throws DatabaseException {
+
+                    GroupStyleProfileEntry.this.style.activate(graph, runtimeDiagram, entry, GroupStyleProfileEntry.this.group, observer);
+
+                }
+
+            });
+
+            active = true;
+
+        } catch (DatabaseException e) {
+            ErrorLogger.defaultLogError(e);
+        }
+    }
+
+    @Override
+    public void deactivate(Resource diagram, EvaluationContext observer) {
+        if (style == null) {
+            System.out.println("GroupStyleProfileEntry has null style!");
+            return;
+        }
+
+        style.deactivate(diagram, entry, group, observer);
+        active = false;
+    }
+
+    @Override
+    public void apply(EvaluationContext observer) {
+        if (style == null) {
+            System.out.println("GroupStyleProfileEntry has null style!");
+            return;
+        }
+        style.apply(entry, group, observer);
+    }
+
+    @Override
+    public int hashCode() {
+        return entry.hashCode();
+    }
+
+    @Override
+    public boolean equals(Object object) {
+        if (this == object)
+            return true;
+        else if (object == null)
+            return false;
+        else if (GroupStyleProfileEntry.class != object.getClass())
+            return false;
+        GroupStyleProfileEntry other = (GroupStyleProfileEntry)object;
+        return entry.equals(other.entry);
+    }
+    
+    @Override
+    public String toString() {
+        return "" + style + " applied to " + group;
+    }
+
+    @Override
+    public boolean isActive() {
+        return active;
+    }
+    
+    @Override
+    public double getPriority() {
+       return priority;
+    }
+
+}