]> gerrit.simantics Code Review - simantics/platform.git/blob
fc9c80650c6d9513fd680d0795db1449274cc076
[simantics/platform.git] /
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.diagram.symbolcontribution;
13
14 import java.util.ArrayList;
15 import java.util.Collection;
16 import java.util.Collections;
17 import java.util.Comparator;
18
19 import org.simantics.diagram.symbollibrary.ISymbolGroup;
20 import org.simantics.diagram.symbollibrary.ISymbolItem;
21
22 /**
23  * @author Hannu Niemistö
24  */
25 public class CompositeSymbolGroup extends ModifiableSymbolGroup {
26
27     Collection<ISymbolGroup> groups = new ArrayList<ISymbolGroup>(4);
28
29     public CompositeSymbolGroup(Object identification, String name, String description) {
30         super(identification, name, description);
31     }
32
33     public void add(ISymbolGroup group) {
34         groups.add(group);
35     }
36
37     public Collection<ISymbolGroup> getGroups() {
38         return groups;
39     }
40
41     @Override
42     public ISymbolItem[] getItems() {
43         ArrayList<ISymbolItem> items = new ArrayList<ISymbolItem>();
44         for(ISymbolGroup group : groups)
45             for(ISymbolItem item : group.getItems())
46                 items.add(new GroupProxySymbolItem(item,  this));
47         Collections.sort(items, new Comparator<ISymbolItem>() {
48             @Override
49             public int compare(ISymbolItem o1, ISymbolItem o2) {
50                 return o1.getName().compareTo(o2.getName());
51             }
52         });
53         return items.toArray(new ISymbolItem[items.size()]);
54     }
55
56     @Override
57     public String toString() {
58         return super.toString() + "[composed group count=" + groups.size() + "]";
59     }
60
61 }