]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/IDiagram.java
Merge "Databoard and SCL enchancements."
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / diagram / IDiagram.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.g2d.diagram;\r
13 \r
14 import java.util.Comparator;\r
15 import java.util.List;\r
16 \r
17 import org.simantics.g2d.diagram.impl.Diagram;\r
18 import org.simantics.g2d.diagram.participant.ZOrderHandler;\r
19 import org.simantics.g2d.element.IElement;\r
20 import org.simantics.utils.datastructures.hints.IHintContext;\r
21 \r
22 /**\r
23  * Diagram is a flat ordered composition of elements.\r
24  * <p>\r
25  * Diagram may only be accessed from canvas thread.\r
26  * <p>\r
27  * Diagram variables are persistent.\r
28  * <p>\r
29  * Elements are ordered according to their z-value\r
30  * \r
31  * @see Diagram Default implementation\r
32  * @see IElement\r
33  * @see ZOrderHandler\r
34  * @author Toni Kalajainen\r
35  */\r
36 public interface IDiagram extends IHintContext {\r
37 \r
38     public interface CompositionVetoListener {\r
39         /**\r
40          * Invoked before an element is actually added on to a diagram. This\r
41          * provides the possibility to veto the addition by returning\r
42          * <code>false</code>.\r
43          * \r
44          * @param d the diagram to be changed\r
45          * @param e the element to be added\r
46          * @return <code>true</code> to allow the addition or <code>false</code>\r
47          *         to veto the addition\r
48          */\r
49         boolean beforeElementAdded(IDiagram d, IElement e);\r
50 \r
51         /**\r
52          * Invoked before an element is actually removed from a diagram. This\r
53          * provides the possibility to veto the addition by returning\r
54          * <code>false</code>.\r
55          * \r
56          * @param d the diagram to be changed\r
57          * @param e the element to be removed\r
58          * @return <code>true</code> to allow the removal or <code>false</code>\r
59          *         to veto the removal\r
60          */\r
61         boolean beforeElementRemoved(IDiagram d, IElement e);\r
62     }\r
63 \r
64     public interface CompositionListener {\r
65         /**\r
66          * @param d\r
67          * @param e\r
68          */\r
69         void onElementAdded(IDiagram d, IElement e);\r
70 \r
71         /**\r
72          * @param d\r
73          * @param e\r
74          */\r
75         void onElementRemoved(IDiagram d, IElement e);\r
76     }\r
77 \r
78     /**\r
79      * Add a composition listener that can veto element addition/removal\r
80      * @param listener\r
81      */\r
82     void addCompositionVetoListener(CompositionVetoListener listener);\r
83     /**\r
84      * Remove composition veto listener\r
85      * @param listener\r
86      */\r
87     void removeCompositionVetoListener(CompositionVetoListener listener);\r
88 \r
89     /**\r
90      * Add a composition listener that notifies about element composition\r
91      * @param listener\r
92      */\r
93     void addCompositionListener(CompositionListener listener);\r
94     /**\r
95      * Remove composition listener\r
96      * @param listener\r
97      */\r
98     void removeCompositionListener(CompositionListener listener);\r
99 \r
100     /**\r
101      * Get diagram class\r
102      * @return diagram class\r
103      */\r
104     DiagramClass getDiagramClass();\r
105 \r
106     /**\r
107      * Get a snapshot of elements. The list is z-ordered, where\r
108      * top most elements are at the end of the list.\r
109      * @return a snapshot of elements\r
110      */\r
111     List<IElement> getSnapshot();\r
112 \r
113     /**\r
114      * Get z-ordered list of the elements. The return value is not intended for\r
115      * direct modification.\r
116      * \r
117      * @return\r
118      */\r
119     List<IElement> getElements();\r
120 \r
121     /**\r
122      * Reorder the contained diagram elements using the specified comparator.\r
123      * \r
124      * @param comparator\r
125      */\r
126     void sort(Comparator<IElement> comparator);\r
127 \r
128     /**\r
129      * Add an element to the diagram.\r
130      * \r
131      * @param element the element to add\r
132      * @return element of class\r
133      */\r
134     void addElement(IElement element);\r
135 \r
136     /**\r
137      * Checks if a diagram contains an element.\r
138      * @return true if diagram contains the element.\r
139      */\r
140     boolean containsElement(IElement element);\r
141 \r
142     /**\r
143      * Remove an element from the diagram\r
144      * @param element element to remove\r
145      */\r
146     void removeElement(IElement element);\r
147 \r
148     /**\r
149      * Destroy the diagram from the world permanently.\r
150      * Destroys all contained elements as well.\r
151      */\r
152     void destroy();\r
153     void dispose();\r
154 \r
155     // Z-Order\r
156     boolean bringUp(IElement e);\r
157     boolean sendDown(IElement e);\r
158     boolean bringToTop(IElement e);\r
159     boolean sendToBottom(IElement e);\r
160 \r
161     /**\r
162      * @param e\r
163      * @param position\r
164      * @return <code>true</code> if the position changed\r
165      */\r
166     boolean moveTo(IElement e, int position);\r
167 \r
168 }\r