]> 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
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.browsing.ui.graph.impl / src / org / simantics / browsing / ui / graph / impl / contribution / LabelDecoratorContributionImpl.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.browsing.ui.graph.impl.contribution;\r
13 \r
14 import org.simantics.browsing.ui.BuiltinKeys.LabelDecoratorKey;\r
15 import org.simantics.browsing.ui.NodeContext;\r
16 import org.simantics.browsing.ui.PrimitiveQueryUpdater;\r
17 import org.simantics.browsing.ui.content.LabelDecorator;\r
18 import org.simantics.db.AsyncReadGraph;\r
19 import org.simantics.db.procedure.Listener;\r
20 import org.simantics.db.procedure.Procedure;\r
21 import org.simantics.utils.ui.ErrorLogger;\r
22 \r
23 /**\r
24  * Implement {@link #children(AsyncReadGraph)} and {@link #hasChildren(AsyncReadGraph)}.\r
25  * \r
26  * @author Tuukka Lehtonen\r
27  */\r
28 abstract public class LabelDecoratorContributionImpl extends FinalLabelDecoratorContributionImpl {\r
29 \r
30         public LabelDecoratorContributionImpl(PrimitiveQueryUpdater updater,\r
31                         NodeContext context, LabelDecoratorKey key) {\r
32                 super(updater, context, key);\r
33         }\r
34 \r
35         @Override\r
36         protected Procedure<LabelDecorator> createProcedure() {\r
37                 \r
38         return new Listener<LabelDecorator>() {\r
39 \r
40                 boolean executed = false;\r
41                 boolean disposed = false;\r
42                 \r
43             @Override\r
44             public void execute(LabelDecorator result) {\r
45                 replaceResult(result);\r
46                 executed = true;\r
47             }\r
48 \r
49             @Override\r
50             public boolean isDisposed() {\r
51                 \r
52                 if(disposed) return true;\r
53                 \r
54                 if((updater.isDisposed() || !updater.isShown(context)) && executed) {\r
55                         decorator = FRESH;\r
56                         disposed = true;\r
57                         return true;\r
58                 } else {\r
59                         return false;\r
60                 }\r
61                 \r
62             }\r
63 \r
64             @Override\r
65             public void exception(Throwable t) {\r
66                 ErrorLogger.defaultLogError("LabelDecoratorContributionImpl.imageQuery failed, see exception for details.", t);\r
67             }\r
68 \r
69         };\r
70                 \r
71         }\r
72 \r
73 }\r