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
13 package org.simantics.utils.datastructures.context;
\r
15 import java.util.Collection;
\r
17 import org.simantics.utils.threads.IThreadWorkQueue;
\r
20 * Observable container.
\r
22 * TODO: add addAll() method
\r
24 * @see Context for implementation
\r
26 * @author Toni Kalajainen
\r
29 public interface IContext<E> {
\r
32 * Put an item to the context.
\r
38 * Remove an item from the context.
\r
40 * @return true if was found and removed
\r
42 boolean remove(E item);
\r
45 * Checks whether an item is in the context
\r
46 * @param item an item
\r
47 * @return true if context contains an item
\r
49 boolean contains(E item);
\r
52 * Clears all items from the context.
\r
57 * Get all items by class
\r
60 * @return collection
\r
62 <R extends E> Collection<R> getItemsByClass(Class<R> clazz);
\r
65 * Get a single item by class.
\r
66 * (Convenience method)
\r
71 * @throws RuntimeException if single interactor was not found
\r
73 <R extends E> R getSingleItem(Class<R> clazz);
\r
76 * Checks that the context has the item by the class
\r
79 * @return <code>true</code> if contained
\r
81 <R> boolean containsItemByClass(Class<R> clazz);
\r
84 * Get a single item by class.
\r
85 * (Convenience method)
\r
89 * @return the item or <code>null</code>
\r
90 * @throws RuntimeException if more than one items were found
\r
92 <R extends E> R getAtMostOneItemOfClass(Class<R> clazz);
\r
95 * Get a snapshot of all the items
\r
96 * @return ordered list of items. The highest priority item is the last element.
\r
104 void addContextListener(IContextListener<E> listener);
\r
110 void removeContextListener(IContextListener<E> listener);
\r
114 * @param thread thread
\r
117 void addContextListener(IThreadWorkQueue thread, IContextListener<E> listener);
\r
121 * @param thread thread
\r
124 void removeContextListener(IThreadWorkQueue thread, IContextListener<E> listener);
\r