]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/DisposableListener.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / adapter / DisposableListener.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.diagram.adapter;
13
14 import org.simantics.db.common.procedure.adapter.ListenerSupport;
15 import org.simantics.db.procedure.Listener;
16
17 /**
18  * @author Tuukka Lehtonen
19  *
20  * @param <T>
21  */
22 public abstract class DisposableListener<T> implements Listener<T> {
23
24     private final ListenerSupport support;
25     private boolean               disposed = false;
26
27     public DisposableListener(ListenerSupport support) {
28         this.support = support;
29     }
30
31     /**
32      * Forcefully and irreversibly dispose this listener.
33      */
34     public void disposeListener() {
35         disposed = true;
36     }
37
38     @Override
39     public void exception(Throwable t) {
40         support.exception(t);
41     }
42
43     @Override
44     public boolean isDisposed() {
45         return disposed || support.isDisposed();
46     }
47
48 }