-/*******************************************************************************\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;\r
-\r
-import java.util.Collections;\r
-import java.util.Map;\r
-\r
-import org.simantics.browsing.ui.BuiltinKeys.LabelerKey;\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.common.labelers.LabelerContent;\r
-import org.simantics.browsing.ui.common.labelers.LabelerStub;\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.procedure.Listener;\r
-import org.simantics.utils.ui.ErrorLogger;\r
-\r
-public abstract class LazyGraphLabeler extends LabelerStub {\r
-\r
- protected final PrimitiveQueryUpdater updater;\r
- private final ResourceQuery<LabelerContent> labelQuery;\r
- private final Listener<LabelerContent> procedure;\r
-\r
- public Object getIdentity(LabelerKey key) {\r
- return key;\r
- }\r
-\r
- public LazyGraphLabeler(final PrimitiveQueryUpdater updater, final NodeContext context, final LabelerKey key) {\r
- this.updater = updater;\r
-\r
- labelQuery = new ResourceQuery<LabelerContent>(getIdentity(key), context) {\r
-\r
- @Override\r
- public LabelerContent perform(ReadGraph graph) throws DatabaseException {\r
- try {\r
- int cat = category(graph);\r
- Map<String, String> lbls = labels(graph);\r
- // Make sure that null is not returned.\r
- if (lbls == null)\r
- throw new NullPointerException("LazyGraphLabeler.labels is not allowed to return null, but " + LazyGraphLabeler.this.getClass() + " just did it");\r
- return new LabelerContent(cat, lbls);\r
- } catch (DatabaseException e) {\r
- throw e;\r
- } catch (Throwable t) {\r
- ErrorLogger.defaultLogError("LazyGraphLabeler.labelQuery produced unexpected exception.", t);\r
- return LabelerContent.NO_CONTENT;\r
- }\r
- }\r
-\r
- @Override\r
- public String toString() {\r
- return LazyGraphLabeler.this + " with context " + context;\r
- }\r
-\r
- };\r
-\r
- procedure = new Listener<LabelerContent>() {\r
-\r
- @Override\r
- public void execute(LabelerContent result) {\r
- setContent(result);\r
- updater.scheduleReplace(context, key, LazyGraphLabeler.this);\r
- }\r
-\r
- @Override\r
- public boolean isDisposed() {\r
- return updater.isDisposed();\r
- }\r
-\r
- @Override\r
- public void exception(Throwable t) {\r
- System.err.println("LazyGraphLabeler2: ");\r
- t.printStackTrace();\r
- }\r
-\r
- };\r
- }\r
-\r
- @Override\r
- public Map<String, String> getLabels() {\r
-\r
- if (content == LabelerContent.NO_CONTENT) {\r
-\r
- final DataSource<ReadGraph> source = updater.getDataSource(ReadGraph.class);\r
- assert(source != null);\r
- source.schedule(graph -> graph.asyncRequest(labelQuery, procedure));\r
-\r
- }\r
-\r
- if(content == null) return Collections.emptyMap();\r
-\r
- return content.labels;\r
-\r
- }\r
-\r
- // OVERRIDE\r
-\r
- public abstract Map<String, String> labels(ReadGraph graph) throws DatabaseException;\r
-\r
- public int category(ReadGraph graph) throws DatabaseException {\r
-\r
- if(content == null) return 0;\r
-\r
- return content.category;\r
-\r
- }\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;
+
+import java.util.Collections;
+import java.util.Map;
+
+import org.simantics.browsing.ui.BuiltinKeys.LabelerKey;
+import org.simantics.browsing.ui.DataSource;
+import org.simantics.browsing.ui.NodeContext;
+import org.simantics.browsing.ui.PrimitiveQueryUpdater;
+import org.simantics.browsing.ui.common.labelers.LabelerContent;
+import org.simantics.browsing.ui.common.labelers.LabelerStub;
+import org.simantics.browsing.ui.graph.impl.request.ResourceQuery;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.procedure.Listener;
+import org.simantics.utils.ui.ErrorLogger;
+
+public abstract class LazyGraphLabeler extends LabelerStub {
+
+ protected final PrimitiveQueryUpdater updater;
+ private final ResourceQuery<LabelerContent> labelQuery;
+ private final Listener<LabelerContent> procedure;
+
+ public Object getIdentity(LabelerKey key) {
+ return key;
+ }
+
+ public LazyGraphLabeler(final PrimitiveQueryUpdater updater, final NodeContext context, final LabelerKey key) {
+ this.updater = updater;
+
+ labelQuery = new ResourceQuery<LabelerContent>(getIdentity(key), context) {
+
+ @Override
+ public LabelerContent perform(ReadGraph graph) throws DatabaseException {
+ try {
+ int cat = category(graph);
+ Map<String, String> lbls = labels(graph);
+ // Make sure that null is not returned.
+ if (lbls == null)
+ throw new NullPointerException("LazyGraphLabeler.labels is not allowed to return null, but " + LazyGraphLabeler.this.getClass() + " just did it");
+ return new LabelerContent(cat, lbls);
+ } catch (DatabaseException e) {
+ throw e;
+ } catch (Throwable t) {
+ ErrorLogger.defaultLogError("LazyGraphLabeler.labelQuery produced unexpected exception.", t);
+ return LabelerContent.NO_CONTENT;
+ }
+ }
+
+ @Override
+ public String toString() {
+ return LazyGraphLabeler.this + " with context " + context;
+ }
+
+ };
+
+ procedure = new Listener<LabelerContent>() {
+
+ @Override
+ public void execute(LabelerContent result) {
+ setContent(result);
+ updater.scheduleReplace(context, key, LazyGraphLabeler.this);
+ }
+
+ @Override
+ public boolean isDisposed() {
+ return updater.isDisposed();
+ }
+
+ @Override
+ public void exception(Throwable t) {
+ System.err.println("LazyGraphLabeler2: ");
+ t.printStackTrace();
+ }
+
+ };
+ }
+
+ @Override
+ public Map<String, String> getLabels() {
+
+ if (content == LabelerContent.NO_CONTENT) {
+
+ final DataSource<ReadGraph> source = updater.getDataSource(ReadGraph.class);
+ assert(source != null);
+ source.schedule(graph -> graph.asyncRequest(labelQuery, procedure));
+
+ }
+
+ if(content == null) return Collections.emptyMap();
+
+ return content.labels;
+
+ }
+
+ // OVERRIDE
+
+ public abstract Map<String, String> labels(ReadGraph graph) throws DatabaseException;
+
+ public int category(ReadGraph graph) throws DatabaseException {
+
+ if(content == null) return 0;
+
+ return content.category;
+
+ }
+
+}