--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2018 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:
+ * Semantum Oy - initial API and implementation
+ *******************************************************************************/
+package org.simantics.db.layer0.variable;
+
+import org.simantics.db.ReadGraph;
+
+/**
+ * Allows attaching a variable under another one to create custom hierarchies
+ * from existing variables.
+ *
+ * @author Antti Villberg
+ * @since 1.36.0
+ */
+public interface ProxyVariableSupport {
+
+ Variable attachTo(ReadGraph graph, Variable parent);
+ Variable attachToRenamed(ReadGraph graph, Variable parent, String name);
+
+}
import org.simantics.db.ReadGraph;
import org.simantics.db.exception.DatabaseException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class ProxyVariables {
-
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(ProxyVariables.class);
+
+ public static Variable tryToOwn(ReadGraph graph, Variable parent, Variable variable) {
+ if (variable instanceof ProxyVariableSupport) {
+ ProxyVariableSupport pvs = (ProxyVariableSupport) variable;
+ return pvs.attachTo(graph, parent);
+ }
+ return null;
+ }
+
+ public static Variable tryToOwnRenamed(ReadGraph graph, Variable parent, Variable variable, String name) {
+ if (variable instanceof ProxyVariableSupport) {
+ ProxyVariableSupport pvs = (ProxyVariableSupport) variable;
+ return pvs.attachToRenamed(graph, parent, name);
+ }
+ return null;
+ }
+
public static Variable inputVariable(ReadGraph graph, Variable context) throws DatabaseException {
Variable session = graph.syncRequest(new ProxySessionRequest(context));
if(session == null) return null;
return input;
}
} catch (Throwable t) {
- t.printStackTrace();
+ LOGGER.error("proxySessionVariable failed", t);
return null;
}
}
} catch (Throwable t) {
- t.printStackTrace();
+ LOGGER.error("proxyVariableBase failed", t);
return null;
}
}
} catch (Throwable t) {
- t.printStackTrace();
+ LOGGER.error("proxyVariableRoot failed", t);
return null;
}
return proxyVariableRoot(graph, variable) != null;
}
-
}
import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener;
import org.simantics.db.exception.AssumptionException;
import org.simantics.db.exception.DatabaseException;
-import org.simantics.db.exception.VariableException;
import org.simantics.db.layer0.exception.InvalidVariableException;
import org.simantics.db.layer0.function.All;
import org.simantics.db.layer0.request.ClassificationsRequest;
import org.simantics.layer0.Layer0;
import org.simantics.simulator.variable.exceptions.NodeManagerException;
-public class StandardGraphChildVariable extends AbstractChildVariable {
+public class StandardGraphChildVariable extends AbstractChildVariable implements ProxyVariableSupport {
/*
* Extension points
public Resource getPossiblePredicateResource(ReadGraph graph) throws DatabaseException {
return null;
}
-
+
+ @Override
+ public Variable attachTo(ReadGraph graph, Variable parent) {
+ return new StandardGraphChildVariable(parent, node, resource);
+ }
+
+ @Override
+ public Variable attachToRenamed(ReadGraph graph, Variable parent, String name) {
+ return new StandardGraphChildVariable(parent, node, resource) {
+ @Override
+ public String getName(ReadGraph graph) throws DatabaseException {
+ return name;
+ }
+ };
+ }
+
}