1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.ui.workbench.editor;
14 import java.util.Arrays;
15 import java.util.Collection;
16 import java.util.Collections;
19 public class EditorAdapterDescriptorImpl implements EditorAdapterDescriptor {
21 private final String id;
23 private final String groupId;
25 private final EditorAdapter adapter;
28 * Null if there is no context limitation
30 private final String[] inContexts;
32 public EditorAdapterDescriptorImpl(String id, String groupId, EditorAdapter adapter, String[] inContexts) {
34 if (groupId != null && groupId.isEmpty())
36 this.groupId = groupId;
37 this.adapter = adapter;
38 if (inContexts != null && inContexts.length == 0)
40 this.inContexts = inContexts;
44 public String getId() {
49 public String getGroupId() {
54 public EditorAdapter getAdapter() {
59 public Collection<String> getInContexts() {
60 if (inContexts == null)
61 return Collections.emptyList();
62 return Arrays.asList(inContexts);
66 public boolean isActive(Collection<?> activeContextIds) {
67 // null indicates perpetually active
68 if (inContexts == null)
71 for (Object o : inContexts)
72 if (activeContextIds.contains(o))
78 public String toString() {
79 StringBuilder sb = new StringBuilder();
80 sb.append(EditorAdapterDescriptorImpl.class.getSimpleName()).append(" id=").append(id).append(" gId=").append(groupId);