]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.diagram/src/org/simantics/diagram/participant/ContextState.java
Some enhancements to GraphLayer-related utilities for Diagram layers
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / participant / ContextState.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2013 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.diagram.participant;
13
14 import java.util.Collection;
15 import java.util.Collections;
16
17 /**
18  * @author Tuukka Lehtonen
19  */
20 public class ContextState {
21
22     private Collection<String> contexts;
23     private boolean            contextsSet;
24
25     public ContextState() {
26         this.contexts = Collections.emptyList();
27         this.contextsSet = false;
28     }
29
30     public ContextState(String context) {
31         this.contexts = Collections.singleton(context);
32         this.contextsSet = true;
33     }
34
35     public ContextState(Collection<String> contexts) {
36         setContexts(contexts);
37     }
38
39     void setContexts(Collection<String> contexts) {
40         if (contextsSet)
41             throw new IllegalStateException("contexts can only be set once");
42         this.contexts = Collections.unmodifiableCollection(contexts);
43         this.contextsSet = true;
44     }
45
46     Collection<String> getContexts() {
47         return contexts;
48     }
49
50     boolean contextsAreSet() {
51         return contextsSet;
52     }
53     
54     @Override
55     public String toString() {
56         return "ContextState : " + getContexts().toString();
57     }
58
59 }