]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.charts/src/org/simantics/charts/editor/ChartKeys.java
Sync git svn branch with SVN repository r33269.
[simantics/platform.git] / bundles / org.simantics.charts / src / org / simantics / charts / editor / ChartKeys.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2011 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.charts.editor;\r
13 \r
14 import org.simantics.databoard.util.ObjectUtils;\r
15 import org.simantics.db.Resource;\r
16 import org.simantics.utils.datastructures.hints.HintContext;\r
17 \r
18 /**\r
19  * @author Tuukka Lehtonen\r
20  */\r
21 public class ChartKeys {\r
22 \r
23     /**\r
24      * //@deprecated use {@link #chartSourceKey(Resource)} with model resource as argument instead\r
25      */\r
26     //@Deprecated\r
27     //public static final Key KEY_ACTIVE_CHART_SOURCE = new HintContext.KeyOf(ChartData.class, "CHART_DATA");\r
28 \r
29     public static ChartSourceKey chartSourceKey(Resource model) {\r
30         return new ChartSourceKey(model);\r
31     }\r
32 \r
33     /**\r
34      * For having multiple different chart data sources. The sources are\r
35      * identified by resources.\r
36      */\r
37     public static class ChartSourceKey extends HintContext.KeyOf {\r
38 \r
39         private final Resource source;\r
40 \r
41         public ChartSourceKey(Resource source) {\r
42             super(ChartData.class, "CHART_DATA(" + source.getResourceId() + ")");\r
43             this.source = source;\r
44         }\r
45 \r
46         public Resource getResource() {\r
47             return source;\r
48         }\r
49 \r
50         @Override\r
51         public int hashCode() {\r
52             return source != null ? source.hashCode() : 0;\r
53         }\r
54 \r
55         @Override\r
56         public boolean equals(Object obj) {\r
57             if (this == obj)\r
58                 return true;\r
59             if (!(obj instanceof ChartSourceKey))\r
60                 return false;\r
61             ChartSourceKey other = (ChartSourceKey) obj;\r
62             return ObjectUtils.objectEquals(source, other.source);\r
63         }\r
64 \r
65         @Override\r
66         public String toString() {\r
67             return getClass().getSimpleName() + "[" + source + "]";\r
68         }\r
69 \r
70     }\r
71 \r
72 }\r