+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.g2d.diagram;\r
+\r
+import java.util.Comparator;\r
+import java.util.List;\r
+\r
+import org.simantics.g2d.diagram.impl.Diagram;\r
+import org.simantics.g2d.diagram.participant.ZOrderHandler;\r
+import org.simantics.g2d.element.IElement;\r
+import org.simantics.utils.datastructures.hints.IHintContext;\r
+\r
+/**\r
+ * Diagram is a flat ordered composition of elements.\r
+ * <p>\r
+ * Diagram may only be accessed from canvas thread.\r
+ * <p>\r
+ * Diagram variables are persistent.\r
+ * <p>\r
+ * Elements are ordered according to their z-value\r
+ * \r
+ * @see Diagram Default implementation\r
+ * @see IElement\r
+ * @see ZOrderHandler\r
+ * @author Toni Kalajainen\r
+ */\r
+public interface IDiagram extends IHintContext {\r
+\r
+ public interface CompositionVetoListener {\r
+ /**\r
+ * Invoked before an element is actually added on to a diagram. This\r
+ * provides the possibility to veto the addition by returning\r
+ * <code>false</code>.\r
+ * \r
+ * @param d the diagram to be changed\r
+ * @param e the element to be added\r
+ * @return <code>true</code> to allow the addition or <code>false</code>\r
+ * to veto the addition\r
+ */\r
+ boolean beforeElementAdded(IDiagram d, IElement e);\r
+\r
+ /**\r
+ * Invoked before an element is actually removed from a diagram. This\r
+ * provides the possibility to veto the addition by returning\r
+ * <code>false</code>.\r
+ * \r
+ * @param d the diagram to be changed\r
+ * @param e the element to be removed\r
+ * @return <code>true</code> to allow the removal or <code>false</code>\r
+ * to veto the removal\r
+ */\r
+ boolean beforeElementRemoved(IDiagram d, IElement e);\r
+ }\r
+\r
+ public interface CompositionListener {\r
+ /**\r
+ * @param d\r
+ * @param e\r
+ */\r
+ void onElementAdded(IDiagram d, IElement e);\r
+\r
+ /**\r
+ * @param d\r
+ * @param e\r
+ */\r
+ void onElementRemoved(IDiagram d, IElement e);\r
+ }\r
+\r
+ /**\r
+ * Add a composition listener that can veto element addition/removal\r
+ * @param listener\r
+ */\r
+ void addCompositionVetoListener(CompositionVetoListener listener);\r
+ /**\r
+ * Remove composition veto listener\r
+ * @param listener\r
+ */\r
+ void removeCompositionVetoListener(CompositionVetoListener listener);\r
+\r
+ /**\r
+ * Add a composition listener that notifies about element composition\r
+ * @param listener\r
+ */\r
+ void addCompositionListener(CompositionListener listener);\r
+ /**\r
+ * Remove composition listener\r
+ * @param listener\r
+ */\r
+ void removeCompositionListener(CompositionListener listener);\r
+\r
+ /**\r
+ * Get diagram class\r
+ * @return diagram class\r
+ */\r
+ DiagramClass getDiagramClass();\r
+\r
+ /**\r
+ * Get a snapshot of elements. The list is z-ordered, where\r
+ * top most elements are at the end of the list.\r
+ * @return a snapshot of elements\r
+ */\r
+ List<IElement> getSnapshot();\r
+\r
+ /**\r
+ * Get z-ordered list of the elements. The return value is not intended for\r
+ * direct modification.\r
+ * \r
+ * @return\r
+ */\r
+ List<IElement> getElements();\r
+\r
+ /**\r
+ * Reorder the contained diagram elements using the specified comparator.\r
+ * \r
+ * @param comparator\r
+ */\r
+ void sort(Comparator<IElement> comparator);\r
+\r
+ /**\r
+ * Add an element to the diagram.\r
+ * \r
+ * @param element the element to add\r
+ * @return element of class\r
+ */\r
+ void addElement(IElement element);\r
+\r
+ /**\r
+ * Checks if a diagram contains an element.\r
+ * @return true if diagram contains the element.\r
+ */\r
+ boolean containsElement(IElement element);\r
+\r
+ /**\r
+ * Remove an element from the diagram\r
+ * @param element element to remove\r
+ */\r
+ void removeElement(IElement element);\r
+\r
+ /**\r
+ * Destroy the diagram from the world permanently.\r
+ * Destroys all contained elements as well.\r
+ */\r
+ void destroy();\r
+ void dispose();\r
+\r
+ // Z-Order\r
+ boolean bringUp(IElement e);\r
+ boolean sendDown(IElement e);\r
+ boolean bringToTop(IElement e);\r
+ boolean sendToBottom(IElement e);\r
+\r
+ /**\r
+ * @param e\r
+ * @param position\r
+ * @return <code>true</code> if the position changed\r
+ */\r
+ boolean moveTo(IElement e, int position);\r
+\r
+}\r