-/*******************************************************************************\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.modeling.ui.modelBrowser.model;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Collection;\r
-import java.util.Collections;\r
-import java.util.List;\r
-import java.util.function.Supplier;\r
-\r
-import org.eclipse.jface.resource.ImageDescriptor;\r
-import org.simantics.browsing.ui.NodeContext;\r
-import org.simantics.browsing.ui.common.node.DeleteException;\r
-import org.simantics.browsing.ui.common.node.IModifiable;\r
-import org.simantics.browsing.ui.common.node.IRefreshable;\r
-import org.simantics.browsing.ui.content.Labeler.Modifier;\r
-import org.simantics.browsing.ui.graph.impl.LabelModifier;\r
-import org.simantics.browsing.ui.graph.impl.LabelerUtil;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.Session;\r
-import org.simantics.db.Statement;\r
-import org.simantics.db.common.ResourceArray;\r
-import org.simantics.db.common.request.ReadRequest;\r
-import org.simantics.db.common.request.ResourceRead;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.procedure.Listener;\r
-import org.simantics.db.request.Read;\r
-import org.simantics.document.DocumentResource;\r
-import org.simantics.modeling.ui.Activator;\r
-import org.simantics.simulation.ontology.SimulationResource;\r
-import org.simantics.utils.ui.ErrorLogger;\r
-\r
-@Deprecated\r
-public class Experiment extends Node implements INode2, IPathNode, IRefreshable, IModifiable, IDisposable {\r
-\r
- private static final String PENDING = "pending...";\r
-\r
- private static final Supplier<Boolean> DEFAULT_IS_DISPOSED = () -> false;\r
-\r
- Supplier<Boolean> isDisposed = DEFAULT_IS_DISPOSED;\r
-\r
- ResourceArray model;\r
- Session session;\r
- String name = PENDING;\r
- Collection<Object> children = Collections.emptyList();\r
- Runnable nameUpdater;\r
- Runnable childrenUpdater;\r
-\r
- public Experiment(ReadGraph graph, Resource experiment) {\r
- super(experiment);\r
- this.session = graph.getSession();\r
- }\r
-\r
- @Override\r
- public int getCategory(Runnable updater, NodeContext context) {\r
- return 0;\r
- }\r
-\r
- @Override\r
- public Collection<?> getChildren(final Runnable updater, NodeContext context) {\r
- childrenUpdater = updater;\r
-\r
- if (children != Collections.emptyList())\r
- return children;\r
-\r
- session.asyncRequest(new ReadRequest() {\r
- @Override\r
- public void run(ReadGraph graph) throws DatabaseException {\r
- List<Object> result = new ArrayList<Object>();\r
- try {\r
- for (Statement factory : findReportFactories(graph)) {\r
- result.add(new ReportFactory(graph, factory));\r
- }\r
- children = result;\r
- } catch (DatabaseException e) {\r
- children = result;\r
- }\r
- updater.run();\r
- }\r
- });\r
- return children;\r
- }\r
-\r
- @Override\r
- public ImageDescriptor getImage(Runnable updater, NodeContext context) {\r
- return Activator.EXPERIMENT_ICON;\r
- }\r
-\r
- @Override\r
- public String getLabel(ReadGraph graph) throws DatabaseException {\r
- String name = LabelerUtil.safeStringRepresentation(graph, resource);\r
- Resource initialState = graph.getPossibleObject(resource, SimulationResource.getInstance(graph).HasInitialState);\r
- if (initialState != null)\r
- name += " (" + LabelerUtil.safeStringRepresentation(graph, initialState) + ")";\r
- return name;\r
- }\r
-\r
- Read<String> labelRequest(Resource resource) {\r
- return new ResourceRead<String>(resource) {\r
- @Override\r
- public String perform(ReadGraph graph) throws DatabaseException {\r
- return getLabel(graph);\r
- }\r
- };\r
- }\r
-\r
- private class NameListener implements Listener<String> {\r
- private final Object identity;\r
- private final Resource resource;\r
-\r
- public NameListener(Object identity, Resource resource) {\r
- assert identity != null;\r
- assert resource != null;\r
- this.identity = identity;\r
- this.resource = resource;\r
- }\r
-\r
- @Override\r
- public int hashCode() {\r
- return identity.hashCode() + 31 * resource.hashCode();\r
- }\r
-\r
- @Override\r
- public boolean equals(Object obj) {\r
- if (this == obj)\r
- return true;\r
- if (obj == null)\r
- return false;\r
- if (getClass() != obj.getClass())\r
- return false;\r
- NameListener other = (NameListener) obj;\r
- return identity.equals(other.identity) && resource.equals(other.resource);\r
- }\r
-\r
- @Override\r
- public void exception(Throwable t) {\r
- ErrorLogger.defaultLogError(t);\r
- }\r
- @Override\r
- public boolean isDisposed() {\r
- return isDisposed.get();\r
- }\r
- @Override\r
- public void execute(String result) {\r
- name = result;\r
- nameUpdater.run();\r
- }\r
- }\r
-\r
- @Override\r
- public String getLabel(final Runnable updater, NodeContext context) {\r
- nameUpdater = updater;\r
- if (name != PENDING)\r
- return name;\r
-\r
- session.asyncRequest(labelRequest(resource), new NameListener(nameUpdater, resource));\r
- return name;\r
- }\r
-\r
- @Override\r
- public Modifier getModifier(String columnId) {\r
- return new LabelModifier(session, resource) {\r
- @Override\r
- public void run(DatabaseException ex) {\r
- if (ex == null) {\r
- refreshName();\r
- } else {\r
- super.run(ex);\r
- }\r
- }\r
- };\r
- }\r
-\r
- @Override\r
- public boolean hasChildren(Runnable updater, NodeContext context) {\r
- return getChildren(updater, context).size() > 0;\r
- }\r
-\r
- @SuppressWarnings("rawtypes")\r
- @Override\r
- public Object getAdapter(Class adapter) {\r
- return super.getAdapter(adapter);\r
- }\r
-\r
- @Override\r
- public void refresh() {\r
- refreshName();\r
- refreshChildren();\r
- }\r
-\r
- public void refreshName() {\r
- this.name = PENDING;\r
- if (nameUpdater != null)\r
- nameUpdater.run();\r
- }\r
-\r
- public void refreshChildren() {\r
- this.children = Collections.emptyList();\r
- if (childrenUpdater != null)\r
- childrenUpdater.run();\r
- }\r
-\r
- Collection<Statement> findReportFactories(ReadGraph g) throws DatabaseException {\r
- DocumentResource DOC = DocumentResource.getInstance(g);\r
- return g.getStatements(resource, DOC.HasReportFactory);\r
- }\r
-\r
- @Override\r
- public void handleDelete() throws DeleteException {\r
- }\r
-\r
- @Override\r
- public void setPath(ResourceArray path) {\r
- this.model = path;\r
- }\r
-\r
- @Override\r
- public ResourceArray getPath() {\r
- return model;\r
- }\r
-\r
- public Resource getModel() {\r
- return model.size() == 0 ? null : model.resources[0];\r
- }\r
-\r
- @Override\r
- public void setDisposedCallable(Supplier<Boolean> isDisposed) {\r
- this.isDisposed = isDisposed;\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.modeling.ui.modelBrowser.model;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.function.Supplier;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.simantics.browsing.ui.NodeContext;
+import org.simantics.browsing.ui.common.node.DeleteException;
+import org.simantics.browsing.ui.common.node.IModifiable;
+import org.simantics.browsing.ui.common.node.IRefreshable;
+import org.simantics.browsing.ui.content.Labeler.Modifier;
+import org.simantics.browsing.ui.graph.impl.LabelModifier;
+import org.simantics.browsing.ui.graph.impl.LabelerUtil;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.Session;
+import org.simantics.db.Statement;
+import org.simantics.db.common.ResourceArray;
+import org.simantics.db.common.request.ReadRequest;
+import org.simantics.db.common.request.ResourceRead;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.procedure.Listener;
+import org.simantics.db.request.Read;
+import org.simantics.document.DocumentResource;
+import org.simantics.modeling.ui.Activator;
+import org.simantics.simulation.ontology.SimulationResource;
+import org.simantics.utils.ui.ErrorLogger;
+
+@Deprecated
+public class Experiment extends Node implements INode2, IPathNode, IRefreshable, IModifiable, IDisposable {
+
+ private static final String PENDING = "pending...";
+
+ private static final Supplier<Boolean> DEFAULT_IS_DISPOSED = () -> false;
+
+ Supplier<Boolean> isDisposed = DEFAULT_IS_DISPOSED;
+
+ ResourceArray model;
+ Session session;
+ String name = PENDING;
+ Collection<Object> children = Collections.emptyList();
+ Runnable nameUpdater;
+ Runnable childrenUpdater;
+
+ public Experiment(ReadGraph graph, Resource experiment) {
+ super(experiment);
+ this.session = graph.getSession();
+ }
+
+ @Override
+ public int getCategory(Runnable updater, NodeContext context) {
+ return 0;
+ }
+
+ @Override
+ public Collection<?> getChildren(final Runnable updater, NodeContext context) {
+ childrenUpdater = updater;
+
+ if (children != Collections.emptyList())
+ return children;
+
+ session.asyncRequest(new ReadRequest() {
+ @Override
+ public void run(ReadGraph graph) throws DatabaseException {
+ List<Object> result = new ArrayList<Object>();
+ try {
+ for (Statement factory : findReportFactories(graph)) {
+ result.add(new ReportFactory(graph, factory));
+ }
+ children = result;
+ } catch (DatabaseException e) {
+ children = result;
+ }
+ updater.run();
+ }
+ });
+ return children;
+ }
+
+ @Override
+ public ImageDescriptor getImage(Runnable updater, NodeContext context) {
+ return Activator.EXPERIMENT_ICON;
+ }
+
+ @Override
+ public String getLabel(ReadGraph graph) throws DatabaseException {
+ String name = LabelerUtil.safeStringRepresentation(graph, resource);
+ Resource initialState = graph.getPossibleObject(resource, SimulationResource.getInstance(graph).HasInitialState);
+ if (initialState != null)
+ name += " (" + LabelerUtil.safeStringRepresentation(graph, initialState) + ")";
+ return name;
+ }
+
+ Read<String> labelRequest(Resource resource) {
+ return new ResourceRead<String>(resource) {
+ @Override
+ public String perform(ReadGraph graph) throws DatabaseException {
+ return getLabel(graph);
+ }
+ };
+ }
+
+ private class NameListener implements Listener<String> {
+ private final Object identity;
+ private final Resource resource;
+
+ public NameListener(Object identity, Resource resource) {
+ assert identity != null;
+ assert resource != null;
+ this.identity = identity;
+ this.resource = resource;
+ }
+
+ @Override
+ public int hashCode() {
+ return identity.hashCode() + 31 * resource.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ NameListener other = (NameListener) obj;
+ return identity.equals(other.identity) && resource.equals(other.resource);
+ }
+
+ @Override
+ public void exception(Throwable t) {
+ ErrorLogger.defaultLogError(t);
+ }
+ @Override
+ public boolean isDisposed() {
+ return isDisposed.get();
+ }
+ @Override
+ public void execute(String result) {
+ name = result;
+ nameUpdater.run();
+ }
+ }
+
+ @Override
+ public String getLabel(final Runnable updater, NodeContext context) {
+ nameUpdater = updater;
+ if (name != PENDING)
+ return name;
+
+ session.asyncRequest(labelRequest(resource), new NameListener(nameUpdater, resource));
+ return name;
+ }
+
+ @Override
+ public Modifier getModifier(String columnId) {
+ return new LabelModifier(session, resource) {
+ @Override
+ public void accept(DatabaseException ex) {
+ if (ex == null) {
+ refreshName();
+ } else {
+ super.accept(ex);
+ }
+ }
+ };
+ }
+
+ @Override
+ public boolean hasChildren(Runnable updater, NodeContext context) {
+ return getChildren(updater, context).size() > 0;
+ }
+
+ @SuppressWarnings("rawtypes")
+ @Override
+ public Object getAdapter(Class adapter) {
+ return super.getAdapter(adapter);
+ }
+
+ @Override
+ public void refresh() {
+ refreshName();
+ refreshChildren();
+ }
+
+ public void refreshName() {
+ this.name = PENDING;
+ if (nameUpdater != null)
+ nameUpdater.run();
+ }
+
+ public void refreshChildren() {
+ this.children = Collections.emptyList();
+ if (childrenUpdater != null)
+ childrenUpdater.run();
+ }
+
+ Collection<Statement> findReportFactories(ReadGraph g) throws DatabaseException {
+ DocumentResource DOC = DocumentResource.getInstance(g);
+ return g.getStatements(resource, DOC.HasReportFactory);
+ }
+
+ @Override
+ public void handleDelete() throws DeleteException {
+ }
+
+ @Override
+ public void setPath(ResourceArray path) {
+ this.model = path;
+ }
+
+ @Override
+ public ResourceArray getPath() {
+ return model;
+ }
+
+ public Resource getModel() {
+ return model.size() == 0 ? null : model.resources[0];
+ }
+
+ @Override
+ public void setDisposedCallable(Supplier<Boolean> isDisposed) {
+ this.isDisposed = isDisposed;
+ }
+
}
\ No newline at end of file