]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/contribution/FinalImagerContributionImpl.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 / FinalImagerContributionImpl.java
index aa3f203be2656f92ada49966c966b509dc3ed057..b4d233e0882289b59862157d11f872871376e52f 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.browsing.ui.graph.impl.contribution;\r
-\r
-import java.util.Collections;\r
-import java.util.Map;\r
-\r
-import org.eclipse.jface.resource.ImageDescriptor;\r
-import org.simantics.browsing.ui.BuiltinKeys;\r
-import org.simantics.browsing.ui.BuiltinKeys.ImagerKey;\r
-import org.simantics.browsing.ui.DataSource;\r
-import org.simantics.browsing.ui.NodeContext;\r
-import org.simantics.browsing.ui.PrimitiveQueryUpdater;\r
-import org.simantics.browsing.ui.content.Imager;\r
-import org.simantics.browsing.ui.graph.impl.request.ResourceQuery;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.exception.PendingVariableException;\r
-import org.simantics.db.procedure.Listener;\r
-import org.simantics.db.procedure.Procedure;\r
-import org.simantics.utils.ui.ErrorLogger;\r
-\r
-public abstract class FinalImagerContributionImpl implements Imager {\r
-\r
-    private final static Map<String, ImageDescriptor>         PENDING = Collections.emptyMap();\r
-\r
-    protected final PrimitiveQueryUpdater                     updater;\r
-    private final ResourceQuery<Map<String, ImageDescriptor>> imagerQuery;\r
-    \r
-    protected final NodeContext                                 context;\r
-    private final BuiltinKeys.ImagerKey                       key;\r
-\r
-    protected Map<String, ImageDescriptor>                      content = null;\r
-\r
-    public Object getIdentity(ImagerKey key) {\r
-        return key;\r
-    }\r
-\r
-    public FinalImagerContributionImpl(final PrimitiveQueryUpdater updater, final NodeContext context, final ImagerKey key) {\r
-\r
-        this.updater = updater;\r
-        this.context = context;\r
-        this.key = key;\r
-\r
-        imagerQuery = new ResourceQuery<Map<String, ImageDescriptor>>(getIdentity(key), context) {\r
-\r
-            @Override\r
-            public Map<String, ImageDescriptor> perform(ReadGraph graph) throws DatabaseException {\r
-                try {\r
-                    return getDescriptors(graph, context);\r
-                } catch (PendingVariableException e) {\r
-                    return PENDING;\r
-                } catch (DatabaseException e) {\r
-                    throw e;\r
-                } catch (Throwable t) {\r
-                    ErrorLogger.defaultLogError("LazyGraphLabeler.labelQuery produced unexpected exception.", t);\r
-                    return null;\r
-                }\r
-            }\r
-\r
-            @Override\r
-            public String toString() {\r
-                return FinalImagerContributionImpl.this + " with context " + context;\r
-            }\r
-\r
-        };\r
-\r
-    }\r
-\r
-    protected Procedure<Map<String, ImageDescriptor>> createProcedure() {\r
-\r
-        return new Procedure<Map<String, ImageDescriptor>>() {\r
-\r
-            @Override\r
-            public void execute(Map<String, ImageDescriptor> result) {\r
-                replaceResult(result);\r
-            }\r
-\r
-            @Override\r
-            public void exception(Throwable t) {\r
-                ErrorLogger.defaultLogError("FinalImagerContributionImpl.imagerQuery failed, see exception for details.", t);\r
-            }\r
-\r
-        };\r
-\r
-    }\r
-\r
-    protected void replaceResult(Map<String, ImageDescriptor> desc) {\r
-        content = desc;\r
-        updater.scheduleReplace(context, key, this);\r
-    }\r
-\r
-    @SuppressWarnings("unchecked")\r
-    @Override\r
-    public ImageDescriptor getImage(String key) {\r
-       \r
-        if (content == null) {\r
-\r
-            content = PENDING;\r
-\r
-            final DataSource<ReadGraph> source = updater.getDataSource(ReadGraph.class);\r
-            assert(source != null);\r
-\r
-            final Procedure<Map<String, ImageDescriptor>> procedure = createProcedure();\r
-            source.schedule(graph -> {\r
-                if(procedure instanceof Listener<?>)\r
-                    graph.asyncRequest(imagerQuery, (Listener<Map<String, ImageDescriptor>>)procedure);\r
-                else\r
-                    graph.asyncRequest(imagerQuery, procedure);\r
-            });\r
-\r
-            return null;\r
-\r
-        }\r
-\r
-        ImageDescriptor descriptor = content.get(key);\r
-        return descriptor;\r
-    }\r
-\r
-    // OVERRIDE\r
-\r
-    public abstract Map<String, ImageDescriptor> getDescriptors(ReadGraph graph, NodeContext context) throws DatabaseException;\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.browsing.ui.graph.impl.contribution;
+
+import java.util.Collections;
+import java.util.Map;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.simantics.browsing.ui.BuiltinKeys;
+import org.simantics.browsing.ui.BuiltinKeys.ImagerKey;
+import org.simantics.browsing.ui.DataSource;
+import org.simantics.browsing.ui.NodeContext;
+import org.simantics.browsing.ui.PrimitiveQueryUpdater;
+import org.simantics.browsing.ui.content.Imager;
+import org.simantics.browsing.ui.graph.impl.request.ResourceQuery;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.exception.PendingVariableException;
+import org.simantics.db.procedure.Listener;
+import org.simantics.db.procedure.Procedure;
+import org.simantics.utils.ui.ErrorLogger;
+
+public abstract class FinalImagerContributionImpl implements Imager {
+
+    private final static Map<String, ImageDescriptor>         PENDING = Collections.emptyMap();
+
+    protected final PrimitiveQueryUpdater                     updater;
+    private final ResourceQuery<Map<String, ImageDescriptor>> imagerQuery;
+    
+    protected final NodeContext                                 context;
+    private final BuiltinKeys.ImagerKey                       key;
+
+    protected Map<String, ImageDescriptor>                      content = null;
+
+    public Object getIdentity(ImagerKey key) {
+        return key;
+    }
+
+    public FinalImagerContributionImpl(final PrimitiveQueryUpdater updater, final NodeContext context, final ImagerKey key) {
+
+        this.updater = updater;
+        this.context = context;
+        this.key = key;
+
+        imagerQuery = new ResourceQuery<Map<String, ImageDescriptor>>(getIdentity(key), context) {
+
+            @Override
+            public Map<String, ImageDescriptor> perform(ReadGraph graph) throws DatabaseException {
+                try {
+                    return getDescriptors(graph, context);
+                } catch (PendingVariableException e) {
+                    return PENDING;
+                } catch (DatabaseException e) {
+                    throw e;
+                } catch (Throwable t) {
+                    ErrorLogger.defaultLogError("LazyGraphLabeler.labelQuery produced unexpected exception.", t);
+                    return null;
+                }
+            }
+
+            @Override
+            public String toString() {
+                return FinalImagerContributionImpl.this + " with context " + context;
+            }
+
+        };
+
+    }
+
+    protected Procedure<Map<String, ImageDescriptor>> createProcedure() {
+
+        return new Procedure<Map<String, ImageDescriptor>>() {
+
+            @Override
+            public void execute(Map<String, ImageDescriptor> result) {
+                replaceResult(result);
+            }
+
+            @Override
+            public void exception(Throwable t) {
+                ErrorLogger.defaultLogError("FinalImagerContributionImpl.imagerQuery failed, see exception for details.", t);
+            }
+
+        };
+
+    }
+
+    protected void replaceResult(Map<String, ImageDescriptor> desc) {
+        content = desc;
+        updater.scheduleReplace(context, key, this);
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public ImageDescriptor getImage(String key) {
+       
+        if (content == null) {
+
+            content = PENDING;
+
+            final DataSource<ReadGraph> source = updater.getDataSource(ReadGraph.class);
+            assert(source != null);
+
+            final Procedure<Map<String, ImageDescriptor>> procedure = createProcedure();
+            source.schedule(graph -> {
+                if(procedure instanceof Listener<?>)
+                    graph.asyncRequest(imagerQuery, (Listener<Map<String, ImageDescriptor>>)procedure);
+                else
+                    graph.asyncRequest(imagerQuery, procedure);
+            });
+
+            return null;
+
+        }
+
+        ImageDescriptor descriptor = content.get(key);
+        return descriptor;
+    }
+
+    // OVERRIDE
+
+    public abstract Map<String, ImageDescriptor> getDescriptors(ReadGraph graph, NodeContext context) throws DatabaseException;
+
+}