From 68c3d5a59d0543b3583e590f5a8d00716216dee0 Mon Sep 17 00:00:00 2001 From: luukkainen Date: Thu, 1 Sep 2011 12:13:04 +0000 Subject: [PATCH] Removed os.modelling.ui.modelBrowser.model.INode dependency. git-svn-id: https://www.simantics.org/svn/simantics/interoperability/trunk@22024 ac1ea38d-2e2b-0410-8846-a27921b304fc --- org.simantics.interop/META-INF/MANIFEST.MF | 3 +- .../org/simantics/interop/browsing/INode.java | 29 +++ .../interop/browsing/INodeEvaluators.java | 181 ++++++++++++++++++ .../interop/browsing/ImportNode.java | 2 - .../interop/browsing/ImportNode2.java | 2 - .../interop/browsing/InteropChildRule.java | 2 - .../interop/handlers/Contributor1.java | 3 +- .../interop/handlers/Contributor2.java | 4 +- .../interop/handlers/EvaluatorFactory1.java | 16 +- 9 files changed, 226 insertions(+), 16 deletions(-) create mode 100644 org.simantics.interop/src/org/simantics/interop/browsing/INode.java create mode 100644 org.simantics.interop/src/org/simantics/interop/browsing/INodeEvaluators.java diff --git a/org.simantics.interop/META-INF/MANIFEST.MF b/org.simantics.interop/META-INF/MANIFEST.MF index 4b19fd4..168f429 100644 --- a/org.simantics.interop/META-INF/MANIFEST.MF +++ b/org.simantics.interop/META-INF/MANIFEST.MF @@ -20,7 +20,8 @@ Require-Bundle: org.eclipse.ui, org.simantics.browsing.ui.model;bundle-version="1.0.0" Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-ActivationPolicy: lazy -Export-Package: org.simantics.interop.issues, +Export-Package: org.simantics.interop.browsing, + org.simantics.interop.issues, org.simantics.interop.stubs, org.simantics.interop.test, org.simantics.interop.utils diff --git a/org.simantics.interop/src/org/simantics/interop/browsing/INode.java b/org.simantics.interop/src/org/simantics/interop/browsing/INode.java new file mode 100644 index 0000000..b849a02 --- /dev/null +++ b/org.simantics.interop/src/org/simantics/interop/browsing/INode.java @@ -0,0 +1,29 @@ +package org.simantics.interop.browsing; + +import java.util.Collection; + +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.ISelection; +import org.simantics.browsing.ui.common.node.IDeletable; +import org.simantics.browsing.ui.content.Labeler.Modifier; +import org.simantics.db.ReadGraph; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; + +public interface INode extends IAdaptable { + String getLabel(ReadGraph graph) throws DatabaseException; + int getCategory(ReadGraph graph) throws DatabaseException; + Collection getChildren(ReadGraph graph) throws DatabaseException; + boolean hasChildren(ReadGraph graph) throws DatabaseException; + ImageDescriptor getImage(ReadGraph graph) throws DatabaseException; + void handleDrop(Session session, ISelection selection); + Modifier getModifier(Session session, String columnId); + + /** + * Delete node in the background system. The node is considered deletable + * only if it implements {@link IDeletable}. + */ + void handleDelete(WriteGraph graph) throws DatabaseException; +} diff --git a/org.simantics.interop/src/org/simantics/interop/browsing/INodeEvaluators.java b/org.simantics.interop/src/org/simantics/interop/browsing/INodeEvaluators.java new file mode 100644 index 0000000..e6216ed --- /dev/null +++ b/org.simantics.interop/src/org/simantics/interop/browsing/INodeEvaluators.java @@ -0,0 +1,181 @@ +package org.simantics.interop.browsing; + +import java.util.Collection; +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.DataSource; +import org.simantics.browsing.ui.NodeContext; +import org.simantics.browsing.ui.PrimitiveQueryUpdater; +import org.simantics.browsing.ui.BuiltinKeys.ImagerKey; +import org.simantics.browsing.ui.BuiltinKeys.LabelerKey; +import org.simantics.browsing.ui.BuiltinKeys.ViewpointKey; +import org.simantics.browsing.ui.GraphExplorer.ModificationContext; +import org.simantics.browsing.ui.common.ColumnKeys; +import org.simantics.browsing.ui.common.EvaluatorImpl; +import org.simantics.browsing.ui.common.EvaluatorData.Evaluator; +import org.simantics.browsing.ui.common.comparators.AlphanumericComparatorFactory; +import org.simantics.browsing.ui.common.imagers.ContainerImager; +import org.simantics.browsing.ui.content.Imager; +import org.simantics.browsing.ui.content.ImagerFactory; +import org.simantics.browsing.ui.content.Labeler; +import org.simantics.browsing.ui.content.LabelerFactory; +import org.simantics.browsing.ui.content.Viewpoint; +import org.simantics.browsing.ui.content.ViewpointFactory; +import org.simantics.browsing.ui.graph.impl.LazyGraphLabeler; +import org.simantics.browsing.ui.graph.impl.LazyViewpoint; +import org.simantics.browsing.ui.graph.impl.MissingImageDescriptor; +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.modeling.ui.modelBrowser.model.IChildrenCallback; +import org.simantics.modeling.ui.modelBrowser.model.IDisposable; +import org.simantics.modeling.ui.modelBrowser.model.IUpdateable; +import org.simantics.ui.SimanticsUI; +import org.simantics.utils.datastructures.Callable; +import org.simantics.utils.datastructures.Callback; + + +public class INodeEvaluators { + public static Evaluator createEvaluator() { + Evaluator nodeEvaluator = new EvaluatorImpl(); + + nodeEvaluator.addViewpoint(new NodeViewpointFactory(), 1.0); + nodeEvaluator.addComparator(new AlphanumericComparatorFactory(ColumnKeys.SINGLE), 2.0); + nodeEvaluator.addLabeler(new NodeLabelerFactory(), 1.0); + nodeEvaluator.addImager(new NodeImagerFactory(), 1.0); + + return nodeEvaluator; + } +} + +abstract class BaseViewpointFactory implements ViewpointFactory { + protected abstract class VPB extends LazyViewpoint implements Callable, IChildrenCallback { + public VPB(PrimitiveQueryUpdater updater, NodeContext context, ViewpointKey key) { + super(updater, context, key); + } + + @Override + public String toString() { + return BaseViewpointFactory.this.toString(); + } + + @Override + public Object getIdentity() { + // This is necessary to give graph requests related to this + // LazyViewpoint a unique-enough identity so that they don't collide + // unexpectedly with other users of ModelEvaluators. + // This makes requests created with different concrete classes of + // BaseViewpointFactory unique. + return BaseViewpointFactory.this.getClass(); + } + + @Override + public Boolean call() { + return Boolean.valueOf(updater.isDisposed()); + } + + @Override + public void refreshChildren(Collection newChildren) { + NodeContext[] ncs = toContextsWithInput(newChildren); + setHasChildren(ncs.length > 0); + setChildren(ncs); + updater.scheduleReplace(context, key, this); + } + + @Override + public Boolean hasChildren(ReadGraph graph) throws DatabaseException { + // hasChildren must do the same graph operations as children + // since they both share the same PrimitiveQueryUpdater. + return children(graph).length > 0; + } + }; +} + +class NodeViewpointFactory extends BaseViewpointFactory { + @Override + public String toString() { + return "Standard"; + } + + class VP extends VPB { + public VP(PrimitiveQueryUpdater updater, NodeContext context, ViewpointKey key) { + super(updater, context, key); + } + + @Override + public NodeContext[] children(ReadGraph graph) throws DatabaseException { + INode node = (INode) context.getConstant(BuiltinKeys.INPUT); + if (node instanceof IUpdateable) + ((IUpdateable) node).setChildrenCallback(this); + + Collection children = node.getChildren(graph); + for (Object child : children) { + if (child instanceof IDisposable) + ((IDisposable) child).setDisposedCallable(this); + } + return toContextsWithInput(children); + } + }; + + @Override + public Viewpoint create(PrimitiveQueryUpdater updater, NodeContext context, ViewpointKey key) { + return new VP(updater, context, key); + } +} + +class NodeLabelerFactory implements LabelerFactory { + @Override + public Labeler create(PrimitiveQueryUpdater updater, final NodeContext context, LabelerKey key) { + return new LazyGraphLabeler(updater, context, key) { + @Override + public Object getIdentity(LabelerKey key) { + return NodeLabelerFactory.this.getClass(); + } + + @Override + public Map labels(ReadGraph graph) throws DatabaseException { + return Collections.singletonMap(ColumnKeys.SINGLE, + ((INode) context.getConstant(BuiltinKeys.INPUT)).getLabel(graph)); + } + + @Override + public Modifier getModifier(ModificationContext sourcePart, String key) { + return ((INode) context.getConstant(BuiltinKeys.INPUT)).getModifier(SimanticsUI.getSession(), key); + } + + @Override + public int category(ReadGraph graph) throws DatabaseException { + return ((INode) context.getConstant(BuiltinKeys.INPUT)).getCategory(graph); + } + }; + } +} + +class NodeImagerFactory implements ImagerFactory { + + @Override + public Imager create(final PrimitiveQueryUpdater updater, final NodeContext context, final ImagerKey key) { + final ContainerImager result = new ContainerImager(); + result.setImage(MissingImageDescriptor.getInstance()); + + DataSource source = updater.getDataSource(ReadGraph.class); + + source.schedule(new Callback() { + @Override + public void run(ReadGraph g) { + try { + ImageDescriptor descriptor = ((INode)context.getConstant(BuiltinKeys.INPUT)).getImage(g); + result.setImage(descriptor); + updater.scheduleReplace(context, key, result); + } catch (DatabaseException e) { + e.printStackTrace(); + } + } + }); + + return result; + } + +} \ No newline at end of file diff --git a/org.simantics.interop/src/org/simantics/interop/browsing/ImportNode.java b/org.simantics.interop/src/org/simantics/interop/browsing/ImportNode.java index 496eb9b..af39f89 100644 --- a/org.simantics.interop/src/org/simantics/interop/browsing/ImportNode.java +++ b/org.simantics.interop/src/org/simantics/interop/browsing/ImportNode.java @@ -14,9 +14,7 @@ import org.simantics.db.WriteGraph; import org.simantics.db.exception.DatabaseException; import org.simantics.interop.Activator; import org.simantics.interop.stubs.InteropResource; -import org.simantics.modeling.ui.modelBrowser.model.INode; -@SuppressWarnings("deprecation") public class ImportNode implements INode { //private Resource project; diff --git a/org.simantics.interop/src/org/simantics/interop/browsing/ImportNode2.java b/org.simantics.interop/src/org/simantics/interop/browsing/ImportNode2.java index 54a8ada..f746a9f 100644 --- a/org.simantics.interop/src/org/simantics/interop/browsing/ImportNode2.java +++ b/org.simantics.interop/src/org/simantics/interop/browsing/ImportNode2.java @@ -14,9 +14,7 @@ import org.simantics.db.WriteGraph; import org.simantics.db.exception.DatabaseException; import org.simantics.interop.Activator; import org.simantics.interop.stubs.InteropResource; -import org.simantics.modeling.ui.modelBrowser.model.INode; -@SuppressWarnings("deprecation") public class ImportNode2 implements INode { private Resource project; diff --git a/org.simantics.interop/src/org/simantics/interop/browsing/InteropChildRule.java b/org.simantics.interop/src/org/simantics/interop/browsing/InteropChildRule.java index cf889aa..dacd74d 100644 --- a/org.simantics.interop/src/org/simantics/interop/browsing/InteropChildRule.java +++ b/org.simantics.interop/src/org/simantics/interop/browsing/InteropChildRule.java @@ -9,9 +9,7 @@ import org.simantics.browsing.ui.model.children.ChildRule; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.exception.DatabaseException; -import org.simantics.modeling.ui.modelBrowser.model.INode; -@SuppressWarnings("deprecation") public class InteropChildRule implements ChildRule{ @Override public boolean isCompatible(Class contentType) { diff --git a/org.simantics.interop/src/org/simantics/interop/handlers/Contributor1.java b/org.simantics.interop/src/org/simantics/interop/handlers/Contributor1.java index 7e0344b..1f90997 100644 --- a/org.simantics.interop/src/org/simantics/interop/handlers/Contributor1.java +++ b/org.simantics.interop/src/org/simantics/interop/handlers/Contributor1.java @@ -6,12 +6,11 @@ import java.util.Collection; import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor; import org.simantics.db.ReadGraph; import org.simantics.db.exception.DatabaseException; +import org.simantics.interop.browsing.INode; import org.simantics.interop.browsing.ImportNode; -import org.simantics.modeling.ui.modelBrowser.model.INode; import org.simantics.structural.ui.modelBrowser.nodes.ModelNode; -@SuppressWarnings("deprecation") public class Contributor1 extends ViewpointContributor { diff --git a/org.simantics.interop/src/org/simantics/interop/handlers/Contributor2.java b/org.simantics.interop/src/org/simantics/interop/handlers/Contributor2.java index 8931554..62dd734 100644 --- a/org.simantics.interop/src/org/simantics/interop/handlers/Contributor2.java +++ b/org.simantics.interop/src/org/simantics/interop/handlers/Contributor2.java @@ -7,11 +7,11 @@ import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributo import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.exception.DatabaseException; +import org.simantics.interop.browsing.INode; import org.simantics.interop.browsing.ImportNode2; -import org.simantics.modeling.ui.modelBrowser.model.INode; -@SuppressWarnings("deprecation") + public class Contributor2 extends ViewpointContributor { diff --git a/org.simantics.interop/src/org/simantics/interop/handlers/EvaluatorFactory1.java b/org.simantics.interop/src/org/simantics/interop/handlers/EvaluatorFactory1.java index aa9b72e..1028e36 100644 --- a/org.simantics.interop/src/org/simantics/interop/handlers/EvaluatorFactory1.java +++ b/org.simantics.interop/src/org/simantics/interop/handlers/EvaluatorFactory1.java @@ -4,10 +4,9 @@ import java.util.Collection; import org.simantics.browsing.ui.common.EvaluatorData.Evaluator; import org.simantics.browsing.ui.common.extension.EvaluatorFactory; -import org.simantics.modeling.ui.modelBrowser.ModelEvaluators; -import org.simantics.modeling.ui.modelBrowser.model.INode; +import org.simantics.interop.browsing.INode; +import org.simantics.interop.browsing.INodeEvaluators; -@SuppressWarnings("deprecation") public class EvaluatorFactory1 implements EvaluatorFactory { public EvaluatorFactory1() { @@ -15,12 +14,19 @@ public class EvaluatorFactory1 implements EvaluatorFactory { @Override public Evaluator create(Collection browseContexts) { - return ModelEvaluators.createNodeEvaluator(); + + + return INodeEvaluators.createEvaluator(); } @Override public Class getClazz() { return INode.class; } - + + } + + + + -- 2.47.1