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 *******************************************************************************/
14 * @author Toni Kalajainen
16 package org.simantics.utils.datastructures.prioritystack;
18 import org.simantics.utils.threads.IThreadWorkQueue;
22 * Stack of interactor layers
23 * @param <E> type of stack items
25 public interface IPriorityStack<E> {
28 * Put an item to the stack
29 * to the top of the stack.
33 void add(E item, int priority);
36 * Get priority of an item.
37 * Priority affects the event handing, hint overriding and to the paint order of
40 * @param item the item
41 * @return priority of the interactor or <code>null</code> if item does not exist
43 Integer getPriority(E item);
48 * @return true if was found and removed
50 boolean remove(E item);
53 * Checks whether an item is in the stack
55 * @return true if stack contains the specified item
57 boolean contains(E item);
60 * Get all items by class. All items assignable to the specified class are
65 * @return all items assignable to the specified class
67 <R extends E> R[] getItemsByClass(Class<R> clazz);
70 * Get a single item by class. (Convenience method)
74 * @return a single item of the specified class
75 * @throws RuntimeException if single item was not found or if multiple
76 * matching items were found
78 <R extends E> R getSingleItem(Class<R> clazz);
81 * Get a snapshot of all the items
82 * @return ordered list of items. The highest priority item is the last element.
91 void addStackListener(IThreadWorkQueue thread, IPriorityStackListener<E> listener);
98 void removeStackListener(IThreadWorkQueue thread, IPriorityStackListener<E> listener);
104 void addStackListener(IPriorityStackListener<E> listener);
110 void removeStackListener(IPriorityStackListener<E> listener);