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
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.g2d.diagram;
\r
14 import java.util.Comparator;
\r
15 import java.util.List;
\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
23 * Diagram is a flat ordered composition of elements.
\r
25 * Diagram may only be accessed from canvas thread.
\r
27 * Diagram variables are persistent.
\r
29 * Elements are ordered according to their z-value
\r
31 * @see Diagram Default implementation
\r
33 * @see ZOrderHandler
\r
34 * @author Toni Kalajainen
\r
36 public interface IDiagram extends IHintContext {
\r
38 public interface CompositionVetoListener {
\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
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
49 boolean beforeElementAdded(IDiagram d, IElement e);
\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
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
61 boolean beforeElementRemoved(IDiagram d, IElement e);
\r
64 public interface CompositionListener {
\r
69 void onElementAdded(IDiagram d, IElement e);
\r
75 void onElementRemoved(IDiagram d, IElement e);
\r
79 * Add a composition listener that can veto element addition/removal
\r
82 void addCompositionVetoListener(CompositionVetoListener listener);
\r
84 * Remove composition veto listener
\r
87 void removeCompositionVetoListener(CompositionVetoListener listener);
\r
90 * Add a composition listener that notifies about element composition
\r
93 void addCompositionListener(CompositionListener listener);
\r
95 * Remove composition listener
\r
98 void removeCompositionListener(CompositionListener listener);
\r
101 * Get diagram class
\r
102 * @return diagram class
\r
104 DiagramClass getDiagramClass();
\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
111 List<IElement> getSnapshot();
\r
114 * Get z-ordered list of the elements. The return value is not intended for
\r
115 * direct modification.
\r
119 List<IElement> getElements();
\r
122 * Reorder the contained diagram elements using the specified comparator.
\r
124 * @param comparator
\r
126 void sort(Comparator<IElement> comparator);
\r
129 * Add an element to the diagram.
\r
131 * @param element the element to add
\r
132 * @return element of class
\r
134 void addElement(IElement element);
\r
137 * Checks if a diagram contains an element.
\r
138 * @return true if diagram contains the element.
\r
140 boolean containsElement(IElement element);
\r
143 * Remove an element from the diagram
\r
144 * @param element element to remove
\r
146 void removeElement(IElement element);
\r
149 * Destroy the diagram from the world permanently.
\r
150 * Destroys all contained elements as well.
\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
164 * @return <code>true</code> if the position changed
\r
166 boolean moveTo(IElement e, int position);
\r