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.diagram.symbolcontribution;
14 import java.util.ArrayList;
15 import java.util.Collection;
16 import java.util.Collections;
17 import java.util.Comparator;
19 import org.simantics.diagram.symbollibrary.ISymbolGroup;
20 import org.simantics.diagram.symbollibrary.ISymbolItem;
21 import org.simantics.utils.strings.AlphanumComparator;
24 * @author Hannu Niemistö
26 public class CompositeSymbolGroup extends ModifiableSymbolGroup {
28 Collection<ISymbolGroup> groups = new ArrayList<ISymbolGroup>(4);
30 public CompositeSymbolGroup(Object identification, String name, String description) {
31 super(identification, name, description);
34 public void add(ISymbolGroup group) {
38 public Collection<ISymbolGroup> getGroups() {
43 public ISymbolItem[] getItems() {
44 ArrayList<ISymbolItem> items = new ArrayList<ISymbolItem>();
45 for(ISymbolGroup group : groups)
46 for(ISymbolItem item : group.getItems())
47 items.add(new GroupProxySymbolItem(item, this));
48 Collections.sort(items, new Comparator<ISymbolItem>() {
50 public int compare(ISymbolItem o1, ISymbolItem o2) {
51 return AlphanumComparator.COMPARATOR.compare(o1.getName(),o2.getName());
54 return items.toArray(new ISymbolItem[items.size()]);
58 public String toString() {
59 return super.toString() + "[composed group count=" + groups.size() + "]";