/******************************************************************************* * Copyright (c) 2007, 2010 Association for Decentralized Information Management * in Industry THTH ry. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ package org.simantics.diagram.symbolcontribution; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Comparator; import org.simantics.diagram.symbollibrary.ISymbolGroup; import org.simantics.diagram.symbollibrary.ISymbolItem; import org.simantics.utils.strings.AlphanumComparator; /** * @author Hannu Niemistö */ public class CompositeSymbolGroup extends ModifiableSymbolGroup { Collection groups = new ArrayList(4); public CompositeSymbolGroup(Object identification, String name, String description) { super(identification, name, description); } public void add(ISymbolGroup group) { groups.add(group); } public Collection getGroups() { return groups; } @Override public ISymbolItem[] getItems() { ArrayList items = new ArrayList(); for(ISymbolGroup group : groups) for(ISymbolItem item : group.getItems()) items.add(new GroupProxySymbolItem(item, this)); Collections.sort(items, new Comparator() { @Override public int compare(ISymbolItem o1, ISymbolItem o2) { return AlphanumComparator.COMPARATOR.compare(o1.getName(),o2.getName()); } }); return items.toArray(new ISymbolItem[items.size()]); } @Override public String toString() { return super.toString() + "[composed group count=" + groups.size() + "]"; } }