]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.charts/src/org/simantics/charts/editor/ChartKeys.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.charts / src / org / simantics / charts / editor / ChartKeys.java
diff --git a/bundles/org.simantics.charts/src/org/simantics/charts/editor/ChartKeys.java b/bundles/org.simantics.charts/src/org/simantics/charts/editor/ChartKeys.java
new file mode 100644 (file)
index 0000000..ed5926c
--- /dev/null
@@ -0,0 +1,72 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 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.charts.editor;\r
+\r
+import org.simantics.databoard.util.ObjectUtils;\r
+import org.simantics.db.Resource;\r
+import org.simantics.utils.datastructures.hints.HintContext;\r
+\r
+/**\r
+ * @author Tuukka Lehtonen\r
+ */\r
+public class ChartKeys {\r
+\r
+    /**\r
+     * //@deprecated use {@link #chartSourceKey(Resource)} with model resource as argument instead\r
+     */\r
+    //@Deprecated\r
+    //public static final Key KEY_ACTIVE_CHART_SOURCE = new HintContext.KeyOf(ChartData.class, "CHART_DATA");\r
+\r
+    public static ChartSourceKey chartSourceKey(Resource model) {\r
+        return new ChartSourceKey(model);\r
+    }\r
+\r
+    /**\r
+     * For having multiple different chart data sources. The sources are\r
+     * identified by resources.\r
+     */\r
+    public static class ChartSourceKey extends HintContext.KeyOf {\r
+\r
+        private final Resource source;\r
+\r
+        public ChartSourceKey(Resource source) {\r
+            super(ChartData.class, "CHART_DATA(" + source.getResourceId() + ")");\r
+            this.source = source;\r
+        }\r
+\r
+        public Resource getResource() {\r
+            return source;\r
+        }\r
+\r
+        @Override\r
+        public int hashCode() {\r
+            return source != null ? source.hashCode() : 0;\r
+        }\r
+\r
+        @Override\r
+        public boolean equals(Object obj) {\r
+            if (this == obj)\r
+                return true;\r
+            if (!(obj instanceof ChartSourceKey))\r
+                return false;\r
+            ChartSourceKey other = (ChartSourceKey) obj;\r
+            return ObjectUtils.objectEquals(source, other.source);\r
+        }\r
+\r
+        @Override\r
+        public String toString() {\r
+            return getClass().getSimpleName() + "[" + source + "]";\r
+        }\r
+\r
+    }\r
+\r
+}\r