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