]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/contribution/ImagerContributionImpl.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.browsing.ui.graph.impl / src / org / simantics / browsing / ui / graph / impl / contribution / ImagerContributionImpl.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.browsing.ui.graph.impl.contribution;
13
14 import java.util.Map;
15
16 import org.eclipse.jface.resource.ImageDescriptor;
17 import org.simantics.browsing.ui.BuiltinKeys.ImagerKey;
18 import org.simantics.browsing.ui.NodeContext;
19 import org.simantics.browsing.ui.PrimitiveQueryUpdater;
20 import org.simantics.db.AsyncReadGraph;
21 import org.simantics.db.procedure.Listener;
22 import org.simantics.db.procedure.Procedure;
23 import org.simantics.utils.ui.ErrorLogger;
24
25 /**
26  * Implement {@link #children(AsyncReadGraph)} and {@link #hasChildren(AsyncReadGraph)}.
27  * 
28  * @author Tuukka Lehtonen
29  */
30 @SuppressWarnings("unchecked")
31 public abstract class ImagerContributionImpl extends FinalImagerContributionImpl {
32
33     public ImagerContributionImpl(PrimitiveQueryUpdater updater,
34             NodeContext context, ImagerKey key) {
35         super(updater, context, key);
36     }
37
38     @Override
39     protected Procedure<Map<String, ImageDescriptor>> createProcedure() {
40
41         return new Listener<Map<String, ImageDescriptor>>() {
42
43                 boolean executed = false;
44                 boolean disposed = false;
45
46             @Override
47             public void execute(Map<String, ImageDescriptor> result) {
48                 replaceResult(result);
49                 executed = true;
50             }
51
52             @Override
53             public boolean isDisposed() {
54                 
55                 if(disposed) return true;
56                 
57                 if((updater.isDisposed() || !updater.isShown(context)) && executed) {
58                         content = null;
59                         disposed = true;
60                         return true;
61                 } else {
62                         return false;
63                 }
64                 
65             }
66
67             @Override
68             public void exception(Throwable t) {
69                 ErrorLogger.defaultLogError("ImagerContributionImpl.imagerQuery failed, see exception for details.", t);
70             }
71
72         };
73
74     }
75
76 }