]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.selectionview/src/org/simantics/selectionview/StandardSelectionInput.java
Support labels for property children
[simantics/platform.git] / bundles / org.simantics.selectionview / src / org / simantics / selectionview / StandardSelectionInput.java
1 package org.simantics.selectionview;
2
3 import java.util.ArrayList;
4 import java.util.Collection;
5 import java.util.Collections;
6 import java.util.HashMap;
7 import java.util.Map;
8
9 import org.simantics.ui.selection.WorkbenchSelectionElement;
10
11 final public class StandardSelectionInput implements SelectionInput {
12         
13         private final Collection<WorkbenchSelectionElement> elements;
14         private final Map<String, Object> parameters;
15         
16         public StandardSelectionInput(Collection<WorkbenchSelectionElement> elements, Map<String, Object> parameters) {
17                 this.parameters = new HashMap<String, Object>(parameters);
18                 this.elements = new ArrayList<WorkbenchSelectionElement>(elements);
19         }
20         
21         public StandardSelectionInput(WorkbenchSelectionElement element, Map<String, Object> parameters) {
22                 this.parameters = new HashMap<String, Object>(parameters);
23                 this.elements = Collections.singletonList(element);
24         }
25
26         public StandardSelectionInput(WorkbenchSelectionElement element) {
27                 this.parameters = Collections.emptyMap();
28                 this.elements = Collections.singletonList(element);
29         }
30
31         public Collection<WorkbenchSelectionElement> getElements() {
32                 return elements;
33         }
34         
35         public <T> T getParameter(String key) {
36                 return (T)parameters.get(key);
37         }
38         
39         @Override
40         public int hashCode() {
41                 return elements.hashCode() + 31 * parameters.hashCode();
42         }
43         
44         @Override
45         public boolean equals(Object object) {
46         if (this == object)
47             return true;
48         else if (object == null)
49             return false;
50         else if (!(object instanceof StandardSelectionInput))
51             return false;
52         StandardSelectionInput ssi = (StandardSelectionInput)object;
53         if(!elements.equals(ssi.elements)) return false;
54         return parameters.equals(ssi.parameters);
55         }
56
57         @Override
58         public String toString() {
59                 return "StandardSelectionInput[es=" + elements + ", par=" + parameters + "]";
60         }
61         
62 }