]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.utils.datastructures/src/org/simantics/utils/datastructures/hints/HintStackTest.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.utils.datastructures / src / org / simantics / utils / datastructures / hints / HintStackTest.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 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 /*\r
13  *\r
14  * @author Toni Kalajainen\r
15  */\r
16 package org.simantics.utils.datastructures.hints;\r
17 \r
18 import org.simantics.utils.datastructures.hints.IHintContext.Key;\r
19 import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;\r
20 \r
21 public class HintStackTest {\r
22 \r
23         public static final Key KEY = new KeyOf(Double.class);\r
24         \r
25         /**\r
26          * @param args\r
27          */\r
28         public static void main(String[] args) {\r
29                 IHintStack stack = new HintStack();\r
30                 stack.addHintListener(new IHintListener() {\r
31                         @Override\r
32                         public void hintChanged(IHintObservable sender, Key key,\r
33                                         Object oldValue, Object newValue) {\r
34                                 System.out.println("Hint changed: "+key+"="+newValue+" (was "+oldValue+")");\r
35                         }\r
36 \r
37                         @Override\r
38                         public void hintRemoved(IHintObservable sender, Key key,\r
39                                         Object oldValue) {\r
40                                 System.out.println("Hint removed: "+key+" (was "+oldValue+")");\r
41                         }});\r
42                 IHintContext c1 = new HintContext();\r
43                 IHintContext c2 = new HintContext();\r
44                 \r
45                 c1.setHint(KEY, 1.0);\r
46                 c2.setHint(KEY, 2.0);\r
47                 \r
48                 // KEY added\r
49                 stack.addHintContext(c1, 0);\r
50                 // KEY overridden\r
51                 stack.addHintContext(c2, 1);\r
52                 \r
53                 // underlying removed, do not do anything\r
54                 stack.removeHintContext(c1);\r
55                 \r
56                 // add over prev value, override\r
57                 stack.addHintContext(c1, 2);\r
58                 \r
59                 // should not do anything, is overridden\r
60                 c2.setHint(KEY, 3.0);\r
61                 \r
62                 // changed. overrides c2\r
63                 c1.setHint(KEY, 4.0);\r
64                 \r
65                 // removed. c2's value 3 becomes effective\r
66                 c1.removeHint(KEY);\r
67         }\r
68 \r
69 }\r