]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/contribution/LabelDecoratorContributionImpl.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 / LabelDecoratorContributionImpl.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.LabelDecoratorKey;
15 import org.simantics.browsing.ui.NodeContext;
16 import org.simantics.browsing.ui.PrimitiveQueryUpdater;
17 import org.simantics.browsing.ui.content.LabelDecorator;
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 {@link #hasChildren(AsyncReadGraph)}.
25  * 
26  * @author Tuukka Lehtonen
27  */
28 abstract public class LabelDecoratorContributionImpl extends FinalLabelDecoratorContributionImpl {
29
30         public LabelDecoratorContributionImpl(PrimitiveQueryUpdater updater,
31                         NodeContext context, LabelDecoratorKey key) {
32                 super(updater, context, key);
33         }
34
35         @Override
36         protected Procedure<LabelDecorator> createProcedure() {
37                 
38         return new Listener<LabelDecorator>() {
39
40                 boolean executed = false;
41                 boolean disposed = false;
42                 
43             @Override
44             public void execute(LabelDecorator 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("LabelDecoratorContributionImpl.imageQuery failed, see exception for details.", t);
67             }
68
69         };
70                 
71         }
72
73 }