1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.g2d.diagram;
14 import java.util.Comparator;
15 import java.util.List;
17 import org.simantics.g2d.diagram.impl.Diagram;
18 import org.simantics.g2d.diagram.participant.ZOrderHandler;
19 import org.simantics.g2d.element.IElement;
20 import org.simantics.utils.datastructures.hints.IHintContext;
23 * Diagram is a flat ordered composition of elements.
25 * Diagram may only be accessed from canvas thread.
27 * Diagram variables are persistent.
29 * Elements are ordered according to their z-value
31 * @see Diagram Default implementation
34 * @author Toni Kalajainen
36 public interface IDiagram extends IHintContext {
38 public interface CompositionVetoListener {
40 * Invoked before an element is actually added on to a diagram. This
41 * provides the possibility to veto the addition by returning
44 * @param d the diagram to be changed
45 * @param e the element to be added
46 * @return <code>true</code> to allow the addition or <code>false</code>
47 * to veto the addition
49 boolean beforeElementAdded(IDiagram d, IElement e);
52 * Invoked before an element is actually removed from a diagram. This
53 * provides the possibility to veto the addition by returning
56 * @param d the diagram to be changed
57 * @param e the element to be removed
58 * @return <code>true</code> to allow the removal or <code>false</code>
61 boolean beforeElementRemoved(IDiagram d, IElement e);
64 public interface CompositionListener {
69 void onElementAdded(IDiagram d, IElement e);
75 void onElementRemoved(IDiagram d, IElement e);
79 * Add a composition listener that can veto element addition/removal
82 void addCompositionVetoListener(CompositionVetoListener listener);
84 * Remove composition veto listener
87 void removeCompositionVetoListener(CompositionVetoListener listener);
90 * Add a composition listener that notifies about element composition
93 void addCompositionListener(CompositionListener listener);
95 * Remove composition listener
98 void removeCompositionListener(CompositionListener listener);
102 * @return diagram class
104 DiagramClass getDiagramClass();
107 * Get a snapshot of elements. The list is z-ordered, where
108 * top most elements are at the end of the list.
109 * @return a snapshot of elements
111 List<IElement> getSnapshot();
114 * Get z-ordered list of the elements. The return value is not intended for
115 * direct modification.
119 List<IElement> getElements();
122 * Reorder the contained diagram elements using the specified comparator.
126 void sort(Comparator<IElement> comparator);
129 * Add an element to the diagram.
131 * @param element the element to add
132 * @return element of class
134 void addElement(IElement element);
137 * Checks if a diagram contains an element.
138 * @return true if diagram contains the element.
140 boolean containsElement(IElement element);
143 * Remove an element from the diagram
144 * @param element element to remove
146 void removeElement(IElement element);
149 * Destroy the diagram from the world permanently.
150 * Destroys all contained elements as well.
156 boolean bringUp(IElement e);
157 boolean sendDown(IElement e);
158 boolean bringToTop(IElement e);
159 boolean sendToBottom(IElement e);
164 * @return <code>true</code> if the position changed
166 boolean moveTo(IElement e, int position);