]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.diagram/src/org/simantics/diagram/participant/ContextState.java
Merge commit 'bd5bc6e45f700e755b61bd112631796631330ecb'
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / participant / ContextState.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2013 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.diagram.participant;\r
13 \r
14 import java.util.Collection;\r
15 import java.util.Collections;\r
16 \r
17 /**\r
18  * @author Tuukka Lehtonen\r
19  */\r
20 public class ContextState {\r
21 \r
22     private Collection<String> contexts;\r
23     private boolean            contextsSet;\r
24 \r
25     public ContextState() {\r
26         this.contexts = Collections.emptyList();\r
27         this.contextsSet = false;\r
28     }\r
29 \r
30     public ContextState(String context) {\r
31         this.contexts = Collections.singleton(context);\r
32         this.contextsSet = true;\r
33     }\r
34 \r
35     public ContextState(Collection<String> contexts) {\r
36         setContexts(contexts);\r
37     }\r
38 \r
39     void setContexts(Collection<String> contexts) {\r
40         if (contextsSet)\r
41             throw new IllegalStateException("contexts can only be set once");\r
42         this.contexts = Collections.unmodifiableCollection(contexts);\r
43         this.contextsSet = true;\r
44     }\r
45 \r
46     Collection<String> getContexts() {\r
47         return contexts;\r
48     }\r
49 \r
50     boolean contextsAreSet() {\r
51         return contextsSet;\r
52     }\r
53     \r
54     @Override\r
55     public String toString() {\r
56         return "ContextState : " + getContexts().toString();\r
57     }\r
58 \r
59 }\r