]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.ui/src/org/simantics/ui/workbench/editor/EditorAdapterDescriptorImpl.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.ui / src / org / simantics / ui / workbench / editor / EditorAdapterDescriptorImpl.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 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.ui.workbench.editor;
13
14 import java.util.Arrays;
15 import java.util.Collection;
16 import java.util.Collections;
17
18
19 public class EditorAdapterDescriptorImpl implements EditorAdapterDescriptor {
20
21     private final String                id;
22
23     private final String                groupId;
24
25     private final EditorAdapter adapter;
26
27     /**
28      * Null if there is no context limitation
29      */
30     private final String[]              inContexts;
31
32     public EditorAdapterDescriptorImpl(String id, String groupId, EditorAdapter adapter, String[] inContexts) {
33         this.id = id;
34         if (groupId != null && groupId.isEmpty())
35             groupId = null;
36         this.groupId = groupId;
37         this.adapter = adapter;
38         if (inContexts != null && inContexts.length == 0)
39             inContexts = null;
40         this.inContexts = inContexts;
41     }
42
43     @Override
44     public String getId() {
45         return id;
46     }
47
48     @Override
49     public String getGroupId() {
50         return groupId;
51     }
52
53     @Override
54     public EditorAdapter getAdapter() {
55         return adapter;
56     }
57
58     @Override
59     public Collection<String> getInContexts() {
60         if (inContexts == null)
61             return Collections.emptyList();
62         return Arrays.asList(inContexts);
63     }
64
65     @Override
66     public boolean isActive(Collection<?> activeContextIds) {
67         // null indicates perpetually active
68         if (inContexts == null)
69             return true;
70
71         for (Object o : inContexts)
72             if (activeContextIds.contains(o))
73                 return true;
74         return false;
75     }
76     
77     @Override
78     public String toString() {
79         StringBuilder sb = new StringBuilder();
80         sb.append(EditorAdapterDescriptorImpl.class.getSimpleName()).append(" id=").append(id).append(" gId=").append(groupId);
81         return sb.toString();
82     }
83
84 }