From eb67052eccd9492b4ea18c08524b083c0eef3bfe Mon Sep 17 00:00:00 2001 From: luukkainen Date: Mon, 26 Apr 2010 14:48:42 +0000 Subject: [PATCH] Interop common plug-in Integration to Apros Model Browser git-svn-id: https://www.simantics.org/svn/simantics/interoperability/trunk@15560 ac1ea38d-2e2b-0410-8846-a27921b304fc --- org.simantics.interop/.classpath | 7 ++ org.simantics.interop/.project | 28 +++++ .../.settings/org.eclipse.jdt.core.prefs | 8 ++ org.simantics.interop/META-INF/MANIFEST.MF | 18 +++ org.simantics.interop/build.properties | 5 + org.simantics.interop/plugin.xml | 25 ++++ .../src/org/simantics/interop/Activator.java | 50 ++++++++ .../interop/browsing/ImportNode.java | 107 ++++++++++++++++++ .../interop/handlers/Contributor1.java | 36 ++++++ .../interop/handlers/EvaluatorFactory1.java | 30 +++++ .../interop/stubs/InteropResource.java | 69 +++++++++++ 11 files changed, 383 insertions(+) create mode 100644 org.simantics.interop/.classpath create mode 100644 org.simantics.interop/.project create mode 100644 org.simantics.interop/.settings/org.eclipse.jdt.core.prefs create mode 100644 org.simantics.interop/META-INF/MANIFEST.MF create mode 100644 org.simantics.interop/build.properties create mode 100644 org.simantics.interop/plugin.xml create mode 100644 org.simantics.interop/src/org/simantics/interop/Activator.java create mode 100644 org.simantics.interop/src/org/simantics/interop/browsing/ImportNode.java create mode 100644 org.simantics.interop/src/org/simantics/interop/handlers/Contributor1.java create mode 100644 org.simantics.interop/src/org/simantics/interop/handlers/EvaluatorFactory1.java create mode 100644 org.simantics.interop/src/org/simantics/interop/stubs/InteropResource.java diff --git a/org.simantics.interop/.classpath b/org.simantics.interop/.classpath new file mode 100644 index 0000000..8a8f166 --- /dev/null +++ b/org.simantics.interop/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/org.simantics.interop/.project b/org.simantics.interop/.project new file mode 100644 index 0000000..4bf9b0a --- /dev/null +++ b/org.simantics.interop/.project @@ -0,0 +1,28 @@ + + + org.simantics.interop + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/org.simantics.interop/.settings/org.eclipse.jdt.core.prefs b/org.simantics.interop/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..c485159 --- /dev/null +++ b/org.simantics.interop/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +#Mon Apr 26 14:43:33 EEST 2010 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/org.simantics.interop/META-INF/MANIFEST.MF b/org.simantics.interop/META-INF/MANIFEST.MF new file mode 100644 index 0000000..99a5c99 --- /dev/null +++ b/org.simantics.interop/META-INF/MANIFEST.MF @@ -0,0 +1,18 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Interop +Bundle-SymbolicName: org.simantics.interop;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Activator: org.simantics.interop.Activator +Bundle-Vendor: VTT +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + org.simantics.db;bundle-version="0.8.0", + org.simantics.db.common;bundle-version="0.8.0", + org.simantics.browsing.ui;bundle-version="0.9.0", + org.simantics.browsing.ui.common;bundle-version="0.9.0", + org.simantics.modeling.ui;bundle-version="1.0.0", + org.simantics.ui;bundle-version="1.0.0", + org.simantics.layer0.utils;bundle-version="0.8.0" +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Bundle-ActivationPolicy: lazy diff --git a/org.simantics.interop/build.properties b/org.simantics.interop/build.properties new file mode 100644 index 0000000..6f20375 --- /dev/null +++ b/org.simantics.interop/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/org.simantics.interop/plugin.xml b/org.simantics.interop/plugin.xml new file mode 100644 index 0000000..a745faf --- /dev/null +++ b/org.simantics.interop/plugin.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + diff --git a/org.simantics.interop/src/org/simantics/interop/Activator.java b/org.simantics.interop/src/org/simantics/interop/Activator.java new file mode 100644 index 0000000..4f5160f --- /dev/null +++ b/org.simantics.interop/src/org/simantics/interop/Activator.java @@ -0,0 +1,50 @@ +package org.simantics.interop; + +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class Activator extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "org.simantics.interop"; + + // The shared instance + private static Activator plugin; + + /** + * The constructor + */ + public Activator() { + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + */ + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } + +} diff --git a/org.simantics.interop/src/org/simantics/interop/browsing/ImportNode.java b/org.simantics.interop/src/org/simantics/interop/browsing/ImportNode.java new file mode 100644 index 0000000..a8f8338 --- /dev/null +++ b/org.simantics.interop/src/org/simantics/interop/browsing/ImportNode.java @@ -0,0 +1,107 @@ +package org.simantics.interop.browsing; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.ISelection; +import org.simantics.browsing.ui.content.Labeler.Modifier; +import org.simantics.db.Builtins; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.interop.stubs.InteropResource; +import org.simantics.modeling.ui.modelBrowser.model.INode; + +public class ImportNode implements INode { + + private Resource project; + + public ImportNode(Resource project) { + this.project = project; + } + + @Override + public Object getAdapter(Class adapter) { + return null; + } + + @Override + public int getCategory(ReadGraph graph) throws DatabaseException { + return 0; + } + + + @Override + public ImageDescriptor getImage(ReadGraph graph) throws DatabaseException { + return null; + } + + @Override + public String getLabel(ReadGraph graph) throws DatabaseException { + return "Imports"; + } + + @Override + public Modifier getModifier(Session session, String columnId) { + // TODO Auto-generated method stub + return null; + } + + @Override + public void handleDelete(WriteGraph graph) throws DatabaseException { + // TODO Auto-generated method stub + + } + + @Override + public void handleDrop(Session session, ISelection selection) { + // TODO Auto-generated method stub + + } + + @Override + public boolean hasChildren(ReadGraph graph) throws DatabaseException { + return getChildren(graph).size() > 0; + } + + @Override + public Collection getChildren(ReadGraph graph) throws DatabaseException { + List nodes = new ArrayList(); + Builtins b = graph.getBuiltins(); + InteropResource i = InteropResource.getInstance(graph); + Collection models = graph.getObjects(project, b.ConsistsOf); + for (Resource m : models) { + Collection objs = graph.getObjects(m, b.ConsistsOf); + for (Resource o : objs) { + if (graph.isInstanceOf(o, i.ImportLibrary)) { + INode node = graph.adapt(o, INode.class); + nodes.add(node); + } + } + } + return nodes; + +// ComosResource c = ComosResource.getInstance(graph); +// Collection models = graph.getObjects(project, b.ConsistsOf); +// Collection comosImports = new ArrayList(); +// for (Resource m : models) { +// Collection objs = graph.getObjects(m, b.ConsistsOf); +// for (Resource o : objs) { +// if (graph.isInstanceOf(o, c.ComosImportLibrary)) { +// String icon_db_path = ComosGraphTools.getIconPath(o, graph); +// if (icon_db_path == null) +// continue; +// ComosIconReader iconReader = new ComosIconReader(icon_db_path); +// comosImports.add(new ComosGraphNode(o, iconReader)); +// } +// } +// } +// return comosImports; + } + + +} diff --git a/org.simantics.interop/src/org/simantics/interop/handlers/Contributor1.java b/org.simantics.interop/src/org/simantics/interop/handlers/Contributor1.java new file mode 100644 index 0000000..26d63a6 --- /dev/null +++ b/org.simantics.interop/src/org/simantics/interop/handlers/Contributor1.java @@ -0,0 +1,36 @@ +package org.simantics.interop.handlers; + +import java.util.ArrayList; +import java.util.Collection; + +import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.interop.browsing.ImportNode; +import org.simantics.layer0.utils.direct.GraphUtils; +import org.simantics.modeling.ui.modelBrowser.model.INode; + +public class Contributor1 extends ViewpointContributor { + + + public Contributor1() { + super(); + } + @Override + public Collection getContribution(ReadGraph graph, Resource input) + throws DatabaseException { + Collection nodes = new ArrayList(); + System.out.println("Contributor 1 " + input + " " + GraphUtils.getReadableName(graph, input)); + nodes.add(new ImportNode(input)); + return nodes; + } + + @Override + public String getViewpointId() { + return "Standard"; + } + + + +} diff --git a/org.simantics.interop/src/org/simantics/interop/handlers/EvaluatorFactory1.java b/org.simantics.interop/src/org/simantics/interop/handlers/EvaluatorFactory1.java new file mode 100644 index 0000000..5178c20 --- /dev/null +++ b/org.simantics.interop/src/org/simantics/interop/handlers/EvaluatorFactory1.java @@ -0,0 +1,30 @@ +package org.simantics.interop.handlers; + +import java.util.Collection; + +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.jface.resource.LocalResourceManager; +import org.eclipse.swt.widgets.Display; +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.ui.SimanticsUI; + +public class EvaluatorFactory1 implements EvaluatorFactory { + + public EvaluatorFactory1() { + // TODO Auto-generated constructor stub + } + + @Override + public Evaluator create(Collection browseContexts) { + return ModelEvaluators.createNodeEvaluator(SimanticsUI.getSession(), new LocalResourceManager(JFaceResources.getResources(Display.getDefault()))); + } + + @Override + public Class getClazz() { + return INode.class; + } + +} diff --git a/org.simantics.interop/src/org/simantics/interop/stubs/InteropResource.java b/org.simantics.interop/src/org/simantics/interop/stubs/InteropResource.java new file mode 100644 index 0000000..bfa3c47 --- /dev/null +++ b/org.simantics.interop/src/org/simantics/interop/stubs/InteropResource.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * 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.interop.stubs; + + +import org.simantics.db.Resource; +import org.simantics.db.ReadGraph; +import org.simantics.db.request.Read; +import org.simantics.db.Session; +import org.simantics.db.exception.DatabaseException; + +public class InteropResource { + + public final Resource ImportLibrary; + public final Resource InteropFeature; + + public static class URIs { + public static final String ImportLibrary = "http://www.simantics.org/Interoperability-1.0/Types/ImportLibrary"; + public static final String InteropFeature = "http://www.simantics.org/Interoperability-1.0/InteropFeature"; + } + + public static Resource getResourceOrNull(ReadGraph graph, String uri) { + try { + return graph.getResource(uri); + } catch(DatabaseException e) { + System.err.println(e.getMessage()); + return null; + } + } + + public InteropResource(ReadGraph graph) { + ImportLibrary = getResourceOrNull(graph, URIs.ImportLibrary); + InteropFeature = getResourceOrNull(graph, URIs.InteropFeature); + } + + public static InteropResource getInstance(ReadGraph graph) { + Session session = graph.getSession(); + InteropResource ret = session.peekService(InteropResource.class); + if(ret == null) { + ret = new InteropResource(graph); + session.registerService(InteropResource.class, ret); + } + return ret; + } + + public static InteropResource getInstance(Session session) throws DatabaseException { + InteropResource ret = session.peekService(InteropResource.class); + if(ret == null) { + ret = session.syncRequest(new Read() { + public InteropResource perform(ReadGraph graph) throws DatabaseException { + return new InteropResource(graph); + } + }); + session.registerService(InteropResource.class, ret); + } + return ret; + } + +} + -- 2.47.0