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