]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/DiagramClass.java
G2DParentNode handles "undefined" child bounds separately
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / diagram / DiagramClass.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.g2d.diagram;
13
14 import java.util.ArrayList;
15 import java.util.Collection;
16
17 import org.simantics.g2d.diagram.handler.DiagramHandler;
18 import org.simantics.g2d.diagram.handler.impl.DataElementMapImpl;
19 import org.simantics.g2d.diagram.handler.impl.LockingTransactionContext;
20 import org.simantics.g2d.diagram.handler.impl.PickContextImpl;
21 import org.simantics.g2d.diagram.handler.impl.TopologyImpl;
22 import org.simantics.g2d.diagram.impl.AbstractHandlerClass;
23
24 /**
25  * DiagramClass is a compilation of DiagramHandlers
26  * 
27  * @See {@link DiagramHandler}
28  * @author Toni Kalajainen
29  */
30 public final class DiagramClass extends AbstractHandlerClass<DiagramHandler> {
31
32     private static final long serialVersionUID = 1541784948072436274L;
33
34     /**
35      * Compile new Diagram class from a set of contributions
36      * @param contributions
37      * @return
38      */
39     public static DiagramClass compile(Collection<DiagramHandler> contributions)
40     {
41         return new DiagramClass(contributions);
42     }
43
44     /**
45      * Compile new Diagram class from a set of contributions
46      * @param contributions
47      * @return
48      */
49     public static DiagramClass compile(DiagramHandler... contributions)
50     {
51         ArrayList<DiagramHandler> al = new ArrayList<DiagramHandler>(contributions.length);
52         for (DiagramHandler eh : contributions)
53             al.add(eh);
54         return new DiagramClass(al);
55     }
56
57     DiagramClass(Collection<DiagramHandler> contributions) {
58         super(contributions);
59     }
60
61     public static final DiagramClass DEFAULT =
62         DiagramClass.compile(
63                 new PickContextImpl(),
64                 new LockingTransactionContext(),
65                 new TopologyImpl(),
66                 //ConnectionValidator.INSTANCE,
67                 new DataElementMapImpl()
68         );
69
70     public DiagramClass newClassWith(DiagramHandler... addedHandlers) {
71         Collection<DiagramHandler> newHandlers = new ArrayList<DiagramHandler>(getAll());
72         for (DiagramHandler h : addedHandlers)
73             newHandlers.add(h);
74         return DiagramClass.compile(newHandlers);
75     }
76
77     public DiagramClass newClassWith(Collection<DiagramHandler> addedHandlers) {
78         Collection<DiagramHandler> newHandlers = new ArrayList<DiagramHandler>(getAll());
79         newHandlers.addAll(addedHandlers);
80         return DiagramClass.compile(newHandlers);
81     }
82
83 }