From 0ffcb1180dcccf28e66a391338885be224ba1c47 Mon Sep 17 00:00:00 2001 From: Antti Villberg Date: Sun, 18 Aug 2019 12:09:15 +0300 Subject: [PATCH] Playground for Antti. These shall be smuggled into master in small pieces. Change-Id: I91e16a145d59c785fb421418dc7e5b5487c6fb13 --- .../swt/widgets/GraphExplorerComposite.java | 4 + .../META-INF/MANIFEST.MF | 4 +- .../db/common/SimanticsInternal.java | 157 +++++++++++++++++ .../request/RuntimeEnvironmentRequest.java | 153 ++++++++++++++++ .../db/common/utils/CommonDBUtils.java | 34 +++- .../db/common/validation/L0Validations.java | 49 +++--- .../scl/Simantics/Layer0.scl | 9 + .../scl/Simantics/Validation.scl | 3 + .../db/layer0/internal/SimanticsInternal.java | 136 +------------- .../db/layer0/request/PropertyInfo.java | 10 +- .../layer0/request/PropertyInfoRequest.java | 6 +- .../simantics/db/layer0/util/Layer0Utils.java | 42 +++-- .../db/layer0/validation/ValidationUtils.java | 9 +- .../db/layer0/variable/ResourceX.java | 33 ++++ .../StandardGraphPropertyVariable.java | 2 +- .../layer0/variable/VariableOrResource.java | 23 +++ .../db/layer0/variable/VariableX.java | 31 ++++ .../META-INF/MANIFEST.MF | 6 +- .../db/management/SessionContext.java | 33 +--- .../internal/SessionManagerProvider.java | 15 +- .../META-INF/MANIFEST.MF | 8 +- .../services/adaption/AdapterRegistry2.java | 6 +- .../reflection/ReflectionAdapter2.java | 57 +++--- .../graph/Documentation.pgraph | 59 +++++++ .../scl/Document/All.scl | 9 +- .../document/server/IEventCommand.java | 7 +- .../document/server/bean/Command.java | 4 + .../document/server/client/WidgetData.java | 6 +- .../document/server/client/WidgetManager.java | 4 +- .../document/swt/core/SWTDocument.java | 10 +- .../document/swt/core/SWTDocumentClient.java | 42 ++++- .../simantics/document/swt/core/SWTViews.java | 24 +++ .../swt/core/base/AbstractEventCommand.java | 7 +- .../swt/core/base/PostEventCommand.java | 29 ++- .../swt/core/base/PropertyWidgetManager.java | 32 +++- .../core/widget/ButtonSelectionListener.java | 54 ++++-- .../swt/core/widget/ButtonWidget.java | 43 ++--- .../swt/core/widget/CommandEventWidget.java | 16 +- .../document/swt/core/widget/Explorer.java | 82 ++++++++- .../swt/core/widget/ExplorerListener.java | 60 +++++++ .../swt/core/widget/FillComposite.java | 5 - .../swt/core/widget/GridComposite.java | 2 +- .../graph/Components.pgraph | 5 + .../META-INF/MANIFEST.MF | 4 +- .../org.simantics.issues.common/adapters.xml | 5 + .../issues/common/AllActiveIssues.java | 29 +-- .../issues/common/AllVisibleIssues.java | 89 ++-------- .../issues/common/BatchValidations.java | 166 ++++++++++++++++++ .../issues/common/ConstraintIssueSource.java | 116 ++++++++++++ .../org/simantics/issues/common/Messages.java | 32 ++++ .../issues/common/ModelVisibleIssues.java | 119 +++++++++++++ .../issues/common/RunActiveValidations.java | 133 ++++++++++++++ .../issues/common/messages.properties | 18 ++ .../graph/Issue.pgraph | 14 +- .../graph/Layer0Sources.pgraph | 18 ++ .../scl/Simantics/IssueUI.scl | 5 + .../ui/handler/ConfigureIssueSources.java | 93 +++------- .../ui/handler/RunActiveValidations.java | 21 ++- .../META-INF/MANIFEST.MF | 4 +- .../org.simantics.layer0/graph/Layer0.pgraph | 4 + .../graph/Layer0Constraints.pgraph | 6 +- .../graph/Layer0Templates.pgraph | 7 + .../graph/Layer0Validations.pgraph | 28 +-- .../graph/ModelingViewpoint.pgraph | 10 ++ .../scl/Simantics/Testing/BrowseContext.scl | 6 + bundles/org.simantics.modeling/adapters.xml | 8 + .../scl/Simantics/Issue.scl | 19 +- .../scl/Simantics/Ontologies.scl | 4 +- .../adapters/SCLCheckedStateRule.java | 59 +++++++ .../modeling/adapters/SCLChildRule.java | 2 +- .../META-INF/MANIFEST.MF | 3 +- .../build.properties | 3 +- .../graph/PlatformUI.pgraph | 3 +- .../graph/ValidationView.pgraph | 70 ++++++++ .../Simantics/PlatformUI.scl} | 48 ++++- .../scl/Simantics/Variables.scl | 13 +- .../org/simantics/scl/db/SCLFunctions.java | 13 ++ .../graph/Structural.pgraph | 6 +- .../org/simantics/structural2/Functions.java | 2 +- .../src/org/simantics/SimanticsPlatform.java | 16 +- 80 files changed, 1992 insertions(+), 534 deletions(-) create mode 100644 bundles/org.simantics.db.common/src/org/simantics/db/common/SimanticsInternal.java create mode 100644 bundles/org.simantics.db.common/src/org/simantics/db/common/request/RuntimeEnvironmentRequest.java create mode 100644 bundles/org.simantics.db.layer0/scl/Simantics/Layer0.scl create mode 100644 bundles/org.simantics.db.layer0/scl/Simantics/Validation.scl create mode 100644 bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ResourceX.java create mode 100644 bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/VariableOrResource.java create mode 100644 bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/VariableX.java create mode 100644 bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/widget/ExplorerListener.java create mode 100644 bundles/org.simantics.issues.common/src/org/simantics/issues/common/BatchValidations.java create mode 100644 bundles/org.simantics.issues.common/src/org/simantics/issues/common/ConstraintIssueSource.java create mode 100644 bundles/org.simantics.issues.common/src/org/simantics/issues/common/Messages.java create mode 100644 bundles/org.simantics.issues.common/src/org/simantics/issues/common/ModelVisibleIssues.java create mode 100644 bundles/org.simantics.issues.common/src/org/simantics/issues/common/RunActiveValidations.java create mode 100644 bundles/org.simantics.issues.common/src/org/simantics/issues/common/messages.properties create mode 100644 bundles/org.simantics.issues.ontology/graph/Layer0Sources.pgraph create mode 100644 bundles/org.simantics.issues.ui/scl/Simantics/IssueUI.scl create mode 100644 bundles/org.simantics.modeling/src/org/simantics/modeling/adapters/SCLCheckedStateRule.java create mode 100644 bundles/org.simantics.platform.ui.ontology/graph/ValidationView.pgraph rename bundles/org.simantics.platform.ui.ontology/{graph/scl/SCLMain.scl => scl/Simantics/PlatformUI.scl} (61%) diff --git a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/widgets/GraphExplorerComposite.java b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/widgets/GraphExplorerComposite.java index 2f52153a1..d27eeaa79 100644 --- a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/widgets/GraphExplorerComposite.java +++ b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/widgets/GraphExplorerComposite.java @@ -427,6 +427,10 @@ public class GraphExplorerComposite extends Composite implements Widget, IAdapta ((Control)explorer.getControl()).addListener(eventType, listener); } + public void removeListenerFromControl(int eventType, Listener listener) { + ((Control)explorer.getControl()).removeListener(eventType, listener); + } + public void finish() { created = true; createControls(site); diff --git a/bundles/org.simantics.db.common/META-INF/MANIFEST.MF b/bundles/org.simantics.db.common/META-INF/MANIFEST.MF index c45b276d7..27e433851 100644 --- a/bundles/org.simantics.db.common/META-INF/MANIFEST.MF +++ b/bundles/org.simantics.db.common/META-INF/MANIFEST.MF @@ -15,7 +15,9 @@ Require-Bundle: org.simantics.db;bundle-version="1.1.0";visibility:=reexport, org.simantics.user.ontology;bundle-version="1.0.0", org.simantics.layer0x.ontology;bundle-version="1.0.0", org.simantics.issues.ontology;bundle-version="1.2.0", - org.slf4j.api + org.slf4j.api, + org.simantics.db.management;bundle-version="1.1.0", + org.simantics.scl.osgi Export-Package: org.simantics.db.common, org.simantics.db.common.adaption, org.simantics.db.common.auth, diff --git a/bundles/org.simantics.db.common/src/org/simantics/db/common/SimanticsInternal.java b/bundles/org.simantics.db.common/src/org/simantics/db/common/SimanticsInternal.java new file mode 100644 index 000000000..e59e36ffa --- /dev/null +++ b/bundles/org.simantics.db.common/src/org/simantics/db/common/SimanticsInternal.java @@ -0,0 +1,157 @@ +/******************************************************************************* + * 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.db.common; + +import java.util.concurrent.TimeUnit; + +import org.simantics.db.Session; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.management.ISessionContext; +import org.simantics.db.management.ISessionContextProvider; +import org.simantics.db.management.ISessionContextProviderSource; +import org.simantics.db.request.ReadInterface; +import org.simantics.db.request.WriteInterface; +import org.simantics.layer0.Layer0; +import org.simantics.operation.Layer0X; +import org.simantics.utils.threads.ThreadUtils; + +/** + * An internal facade for accessing basic Simantics platform services. + * Usable without a graphical UI, i.e. in headless contexts. + * + * Use org.simantics.Simantics instead where ever possible. + */ +public class SimanticsInternal { + + private static ISessionContextProviderSource providerSource = null; + + /** + * Queue execution of a runnable. + * + * @param runnable + */ + public static void async(Runnable runnable) { + ThreadUtils.getBlockingWorkExecutor().execute(runnable); + } + + public static void async(Runnable runnable, int delay, TimeUnit unit) { + ThreadUtils.getTimer().schedule(runnable, delay, unit); + } + + /** + * Queue execution of a non-blocking runnable. Use this method with caution. + * A non-blocking runnable nevers locks anything, No Locks, No semaphores, + * No Object.wait(), No synchronized() {} blocks. + * + * @param runnable a non-blocking runnable + */ + public static void asyncNonblocking(Runnable runnable) { + ThreadUtils.getNonBlockingWorkExecutor().execute(runnable); + } + + /** + * Schedule execution of a non-blocking runnable. Use this method with caution. + * A non-blocking runnable never locks anything, No Locks, No semaphores, + * No Object,wait(), No synchronized() {} blocks. + * + * @param runnable a non-blocking runnable + * @param initialDelay + * @param period + */ + public static void asyncNonblocking(Runnable runnable, int initialDelay, int period) { + ThreadUtils.getNonBlockingWorkExecutor().scheduleAtFixedRate(runnable, initialDelay, period, TimeUnit.MILLISECONDS); + } + + public static synchronized ISessionContext setSessionContext(ISessionContext ctx) { + return getSessionContextProvider().setSessionContext(ctx); + } + + public static void setSessionContextProviderSource(ISessionContextProviderSource source) { + if (source == null) + throw new IllegalArgumentException("null provider source"); + providerSource = source; + } + + public static ISessionContextProviderSource getProviderSource() { + if (providerSource == null) + throw new IllegalStateException( + "providerSource must be initialized by the application before using class Simantics"); + return providerSource; + } + + public static ISessionContextProvider getSessionContextProvider() { + return getProviderSource().getActive(); + } + + /** + * Returns the database session context associated with the currently active + * context. This method should be used to retrieve session contexts only + * when the client is sure that the correct context is active. + * + * @return the session context associated with the currently active context + * or null if the context has no session context + */ + public static ISessionContext getSessionContext() { + ISessionContextProvider provider = getSessionContextProvider(); + return provider != null ? provider.getSessionContext() : null; + } + + /** + * Returns the database Session bound to the currently active context. + * + *

+ * The method always returns a non-null Session or produces an + * IllegalStateException if a Session was not attainable. + *

+ * + * @return the Session bound to the currently active workbench window + * @throws IllegalStateException if no Session was available + */ + public static Session getSession() { + ISessionContext ctx = getSessionContext(); + if (ctx == null) + throw new IllegalStateException("Session unavailable, no database session open"); + return ctx.getSession(); + } + + /** + * Returns the database Session bound to the currently active context. + * Differently from {@link #getSession()}, this method returns + * null if there is no current Session available. + * + * @see #getSession() + * @return the Session bound to the currently active context or + * null + */ + public static Session peekSession() { + ISessionContext ctx = getSessionContext(); + return ctx == null ? null : ctx.peekSession(); + } + + public static Layer0 getLayer0() throws DatabaseException { + return Layer0.getInstance(getSession()); + } + + public static Layer0X getLayer0X() throws DatabaseException { + return Layer0X.getInstance(getSession()); + } + + + public static T sync(ReadInterface r) throws DatabaseException { + return getSession().sync(r); + } + + public static T sync(WriteInterface r) throws DatabaseException { + return getSession().sync(r); + } + +} diff --git a/bundles/org.simantics.db.common/src/org/simantics/db/common/request/RuntimeEnvironmentRequest.java b/bundles/org.simantics.db.common/src/org/simantics/db/common/request/RuntimeEnvironmentRequest.java new file mode 100644 index 000000000..24a5c10c9 --- /dev/null +++ b/bundles/org.simantics.db.common/src/org/simantics/db/common/request/RuntimeEnvironmentRequest.java @@ -0,0 +1,153 @@ +package org.simantics.db.common.request; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.SimanticsInternal; +import org.simantics.db.common.utils.CommonDBUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.procedure.Listener; +import org.simantics.db.request.Read; +import org.simantics.scl.compiler.environment.specification.EnvironmentSpecification; +import org.simantics.scl.compiler.module.repository.ImportFailureException; +import org.simantics.scl.compiler.module.repository.UpdateListener; +import org.simantics.scl.compiler.runtime.RuntimeEnvironment; +import org.simantics.scl.osgi.SCLOsgi; +import org.simantics.scl.runtime.SCLContext; + +/** + * Finds the runtime environment of a model or other index root. + * + * @author Hannu Niemistö + * @author Antti Villberg + */ +public class RuntimeEnvironmentRequest extends UnaryRead { + + public RuntimeEnvironmentRequest(Resource parameter) { + super(parameter); + } + + protected void fillEnvironmentSpecification(EnvironmentSpecification environmentSpecification) { + } + + static class UpdateListenerImpl extends UpdateListener { + + final EnvironmentSpecification environmentSpecification; + final Listener callback; + + UpdateListenerImpl(EnvironmentSpecification environmentSpecification, Listener callback) { + this.environmentSpecification = environmentSpecification; + this.callback = callback; + } + + @Override + public void notifyAboutUpdate() { + if(callback.isDisposed()) { + stopListening(); + return; + } + getRuntimeEnvironment(environmentSpecification, callback, this); + } + }; + + public static void getRuntimeEnvironment(EnvironmentSpecification environmentSpecification, Listener callback, UpdateListenerImpl listener) { + + try { + + SCLContext context = SCLContext.getCurrent(); + + RuntimeEnvironment env; + Object graph = context.get("graph"); + if(graph == null) + try { + env = SimanticsInternal.getSession().syncRequest(new Read() { + @Override + public RuntimeEnvironment perform(ReadGraph graph) throws DatabaseException { + + SCLContext sclContext = SCLContext.getCurrent(); + Object oldGraph = sclContext.get("graph"); + try { + sclContext.put("graph", graph); + return SCLOsgi.MODULE_REPOSITORY.createRuntimeEnvironment( + environmentSpecification, + callback.getClass().getClassLoader(), listener); + } catch (ImportFailureException e) { + throw new DatabaseException(e); + } catch (Throwable t) { + throw new DatabaseException(t); + } finally { + sclContext.put("graph", oldGraph); + } + } + }); + } catch (DatabaseException e) { + callback.exception(e); + return; + } + else + env = SCLOsgi.MODULE_REPOSITORY.createRuntimeEnvironment( + environmentSpecification, + callback.getClass().getClassLoader(), listener); + callback.execute(env); + } catch (ImportFailureException e) { + callback.exception(new DatabaseException(e)); + } + + } + + @Override + public RuntimeEnvironment perform(ReadGraph graph) + throws DatabaseException { + final EnvironmentSpecification environmentSpecification = EnvironmentSpecification.of( + "Builtin", "", + "StandardLibrary", "", + "Simantics/All", ""); + fillEnvironmentSpecification(environmentSpecification); + + Resource mainModule = CommonDBUtils.getPossibleChild(graph, parameter, "SCLMain"); + String mainModuleUri; + if(mainModule != null) { + mainModuleUri = graph.getURI(mainModule); + environmentSpecification.importModule(mainModuleUri, ""); + } + else + mainModuleUri = graph.getURI(parameter) + "/#"; // Add something dummy to the model uri that cannot be in a real URI + + return graph.syncRequest(new ParametrizedPrimitiveRead(mainModuleUri) { + + UpdateListenerImpl sclListener; + + @Override + public void register(ReadGraph graph, Listener procedure) { + + SCLContext context = SCLContext.getCurrent(); + Object oldGraph = context.put("graph", graph); + try { + + if(procedure.isDisposed()) { + getRuntimeEnvironment(environmentSpecification, procedure, null); + } else { + sclListener = new UpdateListenerImpl(environmentSpecification, procedure); + sclListener.notifyAboutUpdate(); + } + + } finally { + context.put("graph", oldGraph); + } + + } + + @Override + public void unregistered() { + if(sclListener != null) + sclListener.stopListening(); + } + + }); + } + + @Override + public int hashCode() { + return 31*getClass().hashCode() + super.hashCode(); + } + +} diff --git a/bundles/org.simantics.db.common/src/org/simantics/db/common/utils/CommonDBUtils.java b/bundles/org.simantics.db.common/src/org/simantics/db/common/utils/CommonDBUtils.java index a07d42519..dcd3939a4 100644 --- a/bundles/org.simantics.db.common/src/org/simantics/db/common/utils/CommonDBUtils.java +++ b/bundles/org.simantics.db.common/src/org/simantics/db/common/utils/CommonDBUtils.java @@ -4,7 +4,6 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Set; @@ -16,8 +15,10 @@ import org.simantics.db.WriteGraph; import org.simantics.db.common.procedure.adapter.DirectStatementProcedure; import org.simantics.db.common.request.IsParent; import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.common.request.PossibleChild; import org.simantics.db.common.request.PossibleObjectWithType; import org.simantics.db.common.request.PossibleOwner; +import org.simantics.db.common.request.RuntimeEnvironmentRequest; import org.simantics.db.exception.DatabaseException; import org.simantics.db.exception.InvalidResourceReferenceException; import org.simantics.db.service.ClusterUID; @@ -26,6 +27,10 @@ import org.simantics.db.service.DirectQuerySupport; import org.simantics.db.service.SerialisationSupport; import org.simantics.db.service.XSupport; import org.simantics.layer0.Layer0; +import org.simantics.scl.compiler.environment.Environments; +import org.simantics.scl.compiler.runtime.RuntimeEnvironment; +import org.simantics.scl.compiler.top.SCLExpressionCompilationException; +import org.simantics.scl.compiler.types.Type; import org.simantics.utils.datastructures.collections.CollectionUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -313,5 +318,32 @@ public class CommonDBUtils { return xs.isClusterLoaded(clusterUID); } + public static Type getSCLType(ReadGraph graph, RuntimeEnvironment runtimeEnvironment, String typeText) throws DatabaseException { + try { + return Environments.getType(runtimeEnvironment.getEnvironment(), typeText); + } catch (SCLExpressionCompilationException e) { + throw new DatabaseException(e); + } + } + + public static Type getSCLType(ReadGraph graph, Resource resource, String typeText) throws DatabaseException { + try { + RuntimeEnvironment runtimeEnvironment = graph.syncRequest(new RuntimeEnvironmentRequest(resource)); + return Environments.getType(runtimeEnvironment.getEnvironment(), typeText); + } catch (SCLExpressionCompilationException e) { + throw new DatabaseException(e); + } + } + + public static Resource getPossibleChild(ReadGraph graph, Resource resource, String name) throws DatabaseException { + return graph.sync(new PossibleChild(resource, name)); + } + + public static Resource getPossibleChild(ReadGraph graph, Resource resource, Resource type, String name) throws DatabaseException { + Resource child = graph.sync(new PossibleChild(resource, name)); + if(child == null) return null; + if(!graph.isInstanceOf(child, type)) return null; + return child; + } } diff --git a/bundles/org.simantics.db.common/src/org/simantics/db/common/validation/L0Validations.java b/bundles/org.simantics.db.common/src/org/simantics/db/common/validation/L0Validations.java index a1ed10e77..99ef91b7a 100644 --- a/bundles/org.simantics.db.common/src/org/simantics/db/common/validation/L0Validations.java +++ b/bundles/org.simantics.db.common/src/org/simantics/db/common/validation/L0Validations.java @@ -3,41 +3,50 @@ package org.simantics.db.common.validation; import org.simantics.databoard.Bindings; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; +import org.simantics.db.common.utils.CommonDBUtils; import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; import org.simantics.layer0.Layer0; +import org.simantics.scl.compiler.types.Type; public class L0Validations { public static String checkValueType(ReadGraph graph, Resource subject, Resource predicate) throws DatabaseException { + if (subject == null) return null; if (predicate == null) return null; Layer0 L0 = Layer0.getInstance(graph); - if(graph.isSubrelationOf(predicate, L0.HasProperty)) { + if(graph.isSubrelationOf(predicate, L0.HasProperty)) { Resource object = graph.getPossibleObject(subject, predicate); if(object == null) return null; - String valueType = graph.getPossibleRelatedValue(predicate, L0.RequiresValueType, Bindings.STRING); - if(valueType != null) { - String valueType2 = graph.getPossibleRelatedValue(object, L0.HasValueType, Bindings.STRING); - if(!valueType.equals(valueType2)) { - StringBuilder sb = new StringBuilder() - .append("The value type ") - .append(valueType) - .append(" of predicate ") - .append(NameUtils.getSafeName(graph, predicate, true)) - .append(" does not match the value type ") - .append(valueType2) - .append(" of object ") - .append(NameUtils.getSafeName(graph, object, true)) - .append("."); - return sb.toString(); - } - } - } - return null; + String valueTypeText = graph.getPossibleRelatedValue(predicate, L0.RequiresValueType, Bindings.STRING); + if(valueTypeText != null) { + Type valueType = CommonDBUtils.getSCLType(graph, subject, valueTypeText); + String valueTypeText2 = graph.getPossibleRelatedValue(object, L0.HasValueType, Bindings.STRING); + if(valueTypeText2 != null) { + Type valueType2 = CommonDBUtils.getSCLType(graph, subject, valueTypeText2); + if(!valueType.equals(valueType2)) { + StringBuilder sb = new StringBuilder() + .append("The value type ") + .append(valueType) + .append(" of predicate ") + .append(NameUtils.getSafeName(graph, predicate, true)) + .append(" does not match the value type ") + .append(valueType2) + .append(" of object ") + .append(NameUtils.getSafeName(graph, object, true)) + .append("."); + return sb.toString(); + } + } + } + } + + return null; + } } diff --git a/bundles/org.simantics.db.layer0/scl/Simantics/Layer0.scl b/bundles/org.simantics.db.layer0/scl/Simantics/Layer0.scl new file mode 100644 index 000000000..0b034a14d --- /dev/null +++ b/bundles/org.simantics.db.layer0/scl/Simantics/Layer0.scl @@ -0,0 +1,9 @@ +include "Simantics/DB" +include "Simantics/Issue" + +importJava "org.simantics.db.layer0.function.All" where + uriValidator :: Resource -> [Issue] + valueValidator :: Resource -> [Issue] + relationValidator :: Resource -> [Issue] + propertyValidator :: Resource -> [Issue] + clusterValidator :: Resource -> [Issue] \ No newline at end of file diff --git a/bundles/org.simantics.db.layer0/scl/Simantics/Validation.scl b/bundles/org.simantics.db.layer0/scl/Simantics/Validation.scl new file mode 100644 index 000000000..0a62e0b8e --- /dev/null +++ b/bundles/org.simantics.db.layer0/scl/Simantics/Validation.scl @@ -0,0 +1,3 @@ +import "Simantics/DB" +import "Simantics/Issue" + diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/internal/SimanticsInternal.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/internal/SimanticsInternal.java index 8ae309e68..6ad324c28 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/internal/SimanticsInternal.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/internal/SimanticsInternal.java @@ -12,22 +12,12 @@ package org.simantics.db.layer0.internal; import java.io.File; -import java.util.concurrent.TimeUnit; import org.eclipse.core.runtime.Platform; import org.simantics.db.Resource; -import org.simantics.db.Session; -import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.util.SimanticsClipboard; import org.simantics.db.layer0.util.SimanticsKeys; import org.simantics.db.management.ISessionContext; -import org.simantics.db.management.ISessionContextProvider; -import org.simantics.db.management.ISessionContextProviderSource; -import org.simantics.db.request.ReadInterface; -import org.simantics.db.request.WriteInterface; -import org.simantics.layer0.Layer0; -import org.simantics.operation.Layer0X; -import org.simantics.utils.threads.ThreadUtils; /** * An internal facade for accessing basic Simantics platform services. @@ -35,112 +25,7 @@ import org.simantics.utils.threads.ThreadUtils; * * Use org.simantics.Simantics instead where ever possible. */ -public class SimanticsInternal { - - private static ISessionContextProviderSource providerSource = null; - - /** - * Queue execution of a runnable. - * - * @param runnable - */ - public static void async(Runnable runnable) { - ThreadUtils.getBlockingWorkExecutor().execute(runnable); - } - - public static void async(Runnable runnable, int delay, TimeUnit unit) { - ThreadUtils.getTimer().schedule(runnable, delay, unit); - } - - /** - * Queue execution of a non-blocking runnable. Use this method with caution. - * A non-blocking runnable nevers locks anything, No Locks, No semaphores, - * No Object.wait(), No synchronized() {} blocks. - * - * @param runnable a non-blocking runnable - */ - public static void asyncNonblocking(Runnable runnable) { - ThreadUtils.getNonBlockingWorkExecutor().execute(runnable); - } - - /** - * Schedule execution of a non-blocking runnable. Use this method with caution. - * A non-blocking runnable never locks anything, No Locks, No semaphores, - * No Object,wait(), No synchronized() {} blocks. - * - * @param runnable a non-blocking runnable - * @param initialDelay - * @param period - */ - public static void asyncNonblocking(Runnable runnable, int initialDelay, int period) { - ThreadUtils.getNonBlockingWorkExecutor().scheduleAtFixedRate(runnable, initialDelay, period, TimeUnit.MILLISECONDS); - } - - public static synchronized ISessionContext setSessionContext(ISessionContext ctx) { - return getSessionContextProvider().setSessionContext(ctx); - } - - public static void setSessionContextProviderSource(ISessionContextProviderSource source) { - if (source == null) - throw new IllegalArgumentException("null provider source"); - providerSource = source; - } - - public static ISessionContextProviderSource getProviderSource() { - if (providerSource == null) - throw new IllegalStateException( - "providerSource must be initialized by the application before using class Simantics"); - return providerSource; - } - - public static ISessionContextProvider getSessionContextProvider() { - return getProviderSource().getActive(); - } - - /** - * Returns the database session context associated with the currently active - * context. This method should be used to retrieve session contexts only - * when the client is sure that the correct context is active. - * - * @return the session context associated with the currently active context - * or null if the context has no session context - */ - public static ISessionContext getSessionContext() { - ISessionContextProvider provider = getSessionContextProvider(); - return provider != null ? provider.getSessionContext() : null; - } - - /** - * Returns the database Session bound to the currently active context. - * - *

- * The method always returns a non-null Session or produces an - * IllegalStateException if a Session was not attainable. - *

- * - * @return the Session bound to the currently active workbench window - * @throws IllegalStateException if no Session was available - */ - public static Session getSession() { - ISessionContext ctx = getSessionContext(); - if (ctx == null) - throw new IllegalStateException("Session unavailable, no database session open"); - return ctx.getSession(); - } - - /** - * Returns the database Session bound to the currently active context. - * Differently from {@link #getSession()}, this method returns - * null if there is no current Session available. - * - * @see #getSession() - * @return the Session bound to the currently active context or - * null - */ - public static Session peekSession() { - ISessionContext ctx = getSessionContext(); - return ctx == null ? null : ctx.peekSession(); - } +public class SimanticsInternal extends org.simantics.db.common.SimanticsInternal { /** * @return the currently open and active project as an IProject @@ -163,7 +48,7 @@ public class SimanticsInternal { ISessionContext ctx = getSessionContext(); return ctx != null ? (Resource) ctx.getHint(SimanticsKeys.KEY_PROJECT) : null; } - + private static SimanticsClipboard clipboard = SimanticsClipboard.EMPTY; /** @@ -179,23 +64,6 @@ public class SimanticsInternal { return clipboard; } - public static Layer0 getLayer0() throws DatabaseException { - return Layer0.getInstance(getSession()); - } - - public static Layer0X getLayer0X() throws DatabaseException { - return Layer0X.getInstance(getSession()); - } - - - public static T sync(ReadInterface r) throws DatabaseException { - return getSession().sync(r); - } - - public static T sync(WriteInterface r) throws DatabaseException { - return getSession().sync(r); - } - public static File getTemporaryDirectory() { File workspace = Platform.getLocation().toFile(); File temp = new File(workspace, "tempFiles"); diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/PropertyInfo.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/PropertyInfo.java index f3753ce80..a219a4ed1 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/PropertyInfo.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/PropertyInfo.java @@ -20,6 +20,7 @@ public class PropertyInfo { public final Resource predicate; public final String name; public final boolean isHasProperty; + public final boolean isFunctional; public final Set classifications; public final VariableBuilder builder; public final Resource literalRange; @@ -30,9 +31,10 @@ public class PropertyInfo { public final Map> subliteralPredicates; public final ValueAccessor valueAccessor; public final boolean hasEnumerationRange; - public PropertyInfo(Resource predicate, String name, boolean isHasProperty, Set classifications, VariableBuilder builder, Resource literalRange, Datatype requiredDatatype, String definedUnit, String requiredValueType, Binding defaultBinding, Map> subliteralPredicates, ValueAccessor valueAccessor, boolean hasEnumerationRange) { + public PropertyInfo(Resource predicate, String name, boolean isFunctional, boolean isHasProperty, Set classifications, VariableBuilder builder, Resource literalRange, Datatype requiredDatatype, String definedUnit, String requiredValueType, Binding defaultBinding, Map> subliteralPredicates, ValueAccessor valueAccessor, boolean hasEnumerationRange) { this.predicate = predicate; this.name = name; + this.isFunctional = isFunctional; this.isHasProperty = isHasProperty; this.classifications = classifications; this.builder = builder; @@ -45,7 +47,7 @@ public class PropertyInfo { this.valueAccessor = valueAccessor; this.hasEnumerationRange = hasEnumerationRange; } - public static PropertyInfo make(ReadGraph graph, Resource predicate, String name, boolean isHasProperty, Set classifications, VariableBuilder builder, Resource literalRange, Datatype requiredDatatype, String definedUnit, String requiredValueType, Map> subliteralPredicates, ValueAccessor valueAccessor, boolean hasEnumerationRange) throws DatabaseException { + public static PropertyInfo make(ReadGraph graph, Resource predicate, String name, boolean isFunctional, boolean isHasProperty, Set classifications, VariableBuilder builder, Resource literalRange, Datatype requiredDatatype, String definedUnit, String requiredValueType, Map> subliteralPredicates, ValueAccessor valueAccessor, boolean hasEnumerationRange) throws DatabaseException { Layer0 L0 = Layer0.getInstance(graph); if(literalRange != null) { @@ -58,7 +60,7 @@ public class PropertyInfo { Binding defaultBinding = requiredDatatype != null ? Bindings.getBinding(requiredDatatype) : null; - return new PropertyInfo(predicate, name, isHasProperty, classifications, builder, literalRange, requiredDatatype, definedUnit, requiredValueType, defaultBinding, subliteralPredicates, valueAccessor, hasEnumerationRange); + return new PropertyInfo(predicate, name, isFunctional, isHasProperty, classifications, builder, literalRange, requiredDatatype, definedUnit, requiredValueType, defaultBinding, subliteralPredicates, valueAccessor, hasEnumerationRange); } public boolean hasClassification(String classification) { @@ -75,6 +77,8 @@ public class PropertyInfo { .append(requiredValueType) .append(", predicate=") .append(predicate) + .append(", isFunctional=") + .append(isFunctional) .append(", isHasProperty=") .append(isHasProperty) .append(", hasEnumerationRange=") diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/PropertyInfoRequest.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/PropertyInfoRequest.java index 2a181674c..90e63e29f 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/PropertyInfoRequest.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/PropertyInfoRequest.java @@ -41,6 +41,8 @@ final public class PropertyInfoRequest extends ResourceRead { String name = graph.getPossibleRelatedValue(resource, L0.HasName, Bindings.STRING); if(name != null) name = name.intern(); + boolean isFunctional = graph.isInstanceOf(resource, L0.FunctionalRelation); + Set classifications = graph.sync(new ClassificationsRequest(graph.getPrincipalTypes(resource))); VariableBuilder variableBuilder = graph.getPossibleAdapter(resource, VariableBuilder.class); @@ -88,13 +90,13 @@ final public class PropertyInfoRequest extends ResourceRead { } } - return PropertyInfo.make(graph, resource, name, isHasProperty, classifications, variableBuilder, literalRange, requiredDataType, definedUnit, requiredValueType, map, accessor, hasEnumerationRange); + return PropertyInfo.make(graph, resource, name, isFunctional, isHasProperty, classifications, variableBuilder, literalRange, requiredDataType, definedUnit, requiredValueType, map, accessor, hasEnumerationRange); } } } - return PropertyInfo.make(graph, resource, name, isHasProperty, classifications, variableBuilder, literalRange, requiredDataType, definedUnit, requiredValueType, Collections.>emptyMap(), accessor, hasEnumerationRange); + return PropertyInfo.make(graph, resource, name, isFunctional, isHasProperty, classifications, variableBuilder, literalRange, requiredDataType, definedUnit, requiredValueType, Collections.>emptyMap(), accessor, hasEnumerationRange); } diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/Layer0Utils.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/Layer0Utils.java index 62c7093da..7c7412d18 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/Layer0Utils.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/Layer0Utils.java @@ -74,6 +74,7 @@ import org.simantics.db.common.request.ObjectsWithType; import org.simantics.db.common.request.PossibleChild; import org.simantics.db.common.request.PossibleIndexRoot; import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.common.utils.CommonDBUtils; import org.simantics.db.common.utils.NameUtils; import org.simantics.db.event.ChangeListener; import org.simantics.db.exception.CancelTransactionException; @@ -353,13 +354,9 @@ public class Layer0Utils { throw new IllegalArgumentException("Unable to convert datatype into SCL type: " + type); } - + @Deprecated public static Type getSCLType(ReadGraph graph, RuntimeEnvironment runtimeEnvironment, String typeText) throws DatabaseException { - try { - return Environments.getType(runtimeEnvironment.getEnvironment(), typeText); - } catch (SCLExpressionCompilationException e) { - throw new DatabaseException(e); - } + return CommonDBUtils.getSCLType(graph, runtimeEnvironment, typeText); } public static Type getSCLType(ReadGraph graph, Variable property) throws DatabaseException { @@ -646,15 +643,14 @@ public class Layer0Utils { return graph.getPossibleResource(graph.getURI(root) + suffix); } + @Deprecated public static Resource getPossibleChild(ReadGraph graph, Resource resource, String name) throws DatabaseException { - return graph.sync(new PossibleChild(resource, name)); + return CommonDBUtils.getPossibleChild(graph, resource, name); } + @Deprecated public static Resource getPossibleChild(ReadGraph graph, Resource resource, Resource type, String name) throws DatabaseException { - Resource child = graph.sync(new PossibleChild(resource, name)); - if(child == null) return null; - if(!graph.isInstanceOf(child, type)) return null; - return child; + return CommonDBUtils.getPossibleChild(graph, resource, type, name); } public static RelationContext relationContext(ReadGraph graph, Resource subject, Resource predicate) throws DatabaseException { @@ -1385,7 +1381,31 @@ public class Layer0Utils { } return result; } + + public static Resource possibleObjectForType(ReadGraph graph, Resource type, Resource relation) throws DatabaseException { + PropertyInfo pi = graph.syncRequest(new PropertyInfoRequest(relation)); + return possibleObjectForType(graph, type, relation, pi.isFunctional); + } + public static Resource possibleObjectForType(ReadGraph graph, Resource type, Resource relation, boolean functional) throws DatabaseException { + if(functional) { + Layer0 L0 = Layer0.getInstance(graph); + Resource result = graph.getPossibleObject(type, relation); + if(result != null) return result; + for(Resource su : graph.getObjects(L0.Inherits, type)) { + Resource r = possibleObjectForType(graph, su, relation); + if(r != null) { + if(result != null) return null; + result = r; + } + } + return result; + } else { + throw new UnsupportedOperationException("asd"); + } + } + + public static Resource getPossiblePredicateByNameFromType(ReadGraph graph, Resource type, String name) throws DatabaseException { Map domain = getDomainOf(graph, type); return domain.get(name); diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/validation/ValidationUtils.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/validation/ValidationUtils.java index 673eeaee5..47c829cd8 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/validation/ValidationUtils.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/validation/ValidationUtils.java @@ -1,7 +1,6 @@ package org.simantics.db.layer0.validation; -import gnu.trove.set.hash.THashSet; - +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; @@ -18,6 +17,8 @@ import org.simantics.db.layer0.util.DomainProcessor3; import org.simantics.db.layer0.util.ModelTransferableGraphSourceRequest; import org.simantics.layer0.Layer0; +import gnu.trove.set.hash.THashSet; + public class ValidationUtils { /** @@ -62,7 +63,7 @@ public class ValidationUtils { return validateConstraints(graph, r, null); } - public static Set validateConstraintsForDomain(ReadGraph graph, Resource r) throws DatabaseException { + public static List validateConstraintsForDomain(ReadGraph graph, Resource r) throws DatabaseException { Set result = null; DomainProcessor3 dp = ModelTransferableGraphSourceRequest.getDomainOnly(graph, null, r); @@ -75,7 +76,7 @@ public class ValidationUtils { } } - return result != null ? result : Collections.emptySet(); + return result != null ? new ArrayList(result) : Collections.emptyList(); } } diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ResourceX.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ResourceX.java new file mode 100644 index 000000000..db3bd01c9 --- /dev/null +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ResourceX.java @@ -0,0 +1,33 @@ +package org.simantics.db.layer0.variable; + +import org.simantics.db.Resource; + +public class ResourceX implements VariableOrResource { + + public final Resource value; + + public ResourceX(Resource value) { + this.value = value; + } + + @Override + public String toString() { + return "ResourceX " + value; + } + + @Override + public boolean equals(Object obj) { + if(this == obj) + return true; + if(obj == null || obj.getClass() != getClass()) + return false; + ResourceX other = (ResourceX)obj; + return value == null ? other.value == null : value.equals(other.value); + } + + @Override + public int hashCode() { + return 31 * (value == null ? 0 : value.hashCode()) + 13532; + } + +} diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardGraphPropertyVariable.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardGraphPropertyVariable.java index ed58556c7..7927614cd 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardGraphPropertyVariable.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardGraphPropertyVariable.java @@ -38,7 +38,7 @@ public class StandardGraphPropertyVariable extends AbstractPropertyVariable { private static final Logger LOGGER = LoggerFactory.getLogger(StandardGraphPropertyVariable.class); protected static final PropertyInfo NO_PROPERTY = new PropertyInfo(null, null, - false, Collections. emptySet(), null, null, null, null, null, null, + false, false, Collections. emptySet(), null, null, null, null, null, null, Collections.> emptyMap(), null, false); diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/VariableOrResource.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/VariableOrResource.java new file mode 100644 index 000000000..cdcfd8b09 --- /dev/null +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/VariableOrResource.java @@ -0,0 +1,23 @@ +package org.simantics.db.layer0.variable; + +import org.simantics.db.Resource; + +public interface VariableOrResource { + + public static VariableOrResource make(Resource value) { + return new ResourceX(value); + } + + public static VariableOrResource make(Variable value) { + return new VariableX(value); + } + + public static VariableOrResource make(Object value) { + if(value instanceof Resource) + return make((Resource)value); + if(value instanceof Variable) + return make((Variable)value); + throw new IllegalArgumentException("VariableOrResource acccepts only Variable or Resource, got " + value + " with class " + value.getClass().getName()); + } + +} diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/VariableX.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/VariableX.java new file mode 100644 index 000000000..24d775a5d --- /dev/null +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/VariableX.java @@ -0,0 +1,31 @@ +package org.simantics.db.layer0.variable; + +public class VariableX implements VariableOrResource { + + public final Variable value; + + public VariableX(Variable value) { + this.value = value; + } + + @Override + public String toString() { + return "VariableX " + value; + } + + @Override + public boolean equals(Object obj) { + if(this == obj) + return true; + if(obj == null || obj.getClass() != getClass()) + return false; + VariableX other = (VariableX)obj; + return value == null ? other.value == null : value.equals(other.value); + } + + @Override + public int hashCode() { + return 31 * (value == null ? 0 : value.hashCode()) + 13532; + } + +} diff --git a/bundles/org.simantics.db.management/META-INF/MANIFEST.MF b/bundles/org.simantics.db.management/META-INF/MANIFEST.MF index ecf2439e8..75fdb8b6f 100644 --- a/bundles/org.simantics.db.management/META-INF/MANIFEST.MF +++ b/bundles/org.simantics.db.management/META-INF/MANIFEST.MF @@ -5,9 +5,9 @@ Bundle-SymbolicName: org.simantics.db.management Bundle-Version: 1.1.0.qualifier Bundle-Activator: org.simantics.db.management.internal.Activator Bundle-Vendor: VTT Technical Research Centre of Finland -Require-Bundle: org.simantics.db.services;bundle-version="0.8.0", - org.simantics.db.procore;bundle-version="0.8.0", - org.eclipse.core.runtime;bundle-version="3.5.0" +Require-Bundle: org.eclipse.core.runtime;bundle-version="3.5.0", + org.simantics.utils;bundle-version="1.1.0", + org.simantics.layer0;bundle-version="1.1.0" Bundle-ActivationPolicy: lazy Export-Package: org.simantics.db.management, org.simantics.db.management.discovery diff --git a/bundles/org.simantics.db.management/src/org/simantics/db/management/SessionContext.java b/bundles/org.simantics.db.management/src/org/simantics/db/management/SessionContext.java index dae8bea75..79df14026 100644 --- a/bundles/org.simantics.db.management/src/org/simantics/db/management/SessionContext.java +++ b/bundles/org.simantics.db.management/src/org/simantics/db/management/SessionContext.java @@ -16,19 +16,14 @@ import java.util.Arrays; import java.util.UUID; import java.util.concurrent.TimeoutException; -import org.eclipse.core.runtime.IStatus; import org.simantics.db.Disposable; import org.simantics.db.ReadGraph; import org.simantics.db.Session; import org.simantics.db.VirtualGraph; -import org.simantics.db.common.processor.MergingDelayedWriteProcessor; -import org.simantics.db.common.processor.MergingGraphRequestProcessor; -import org.simantics.db.common.request.ReadRequest; import org.simantics.db.exception.DatabaseException; -import org.simantics.db.management.internal.Activator; +import org.simantics.db.request.Read; import org.simantics.db.service.LifecycleSupport; import org.simantics.db.service.VirtualGraphSupport; -import org.simantics.db.services.GlobalServiceInitializer; import org.simantics.layer0.Layer0; import org.simantics.utils.datastructures.disposable.DisposeState; import org.simantics.utils.datastructures.disposable.IDisposable; @@ -52,10 +47,6 @@ public class SessionContext extends HintContext implements ISessionContext, Disp private Session session; - private boolean servicesRegistered = false; - - private IStatus servicesRegisteredStatus = null; - public static SessionContext create(Session session, boolean initialize) throws DatabaseException { return new SessionContext(session, initialize); } @@ -67,33 +58,19 @@ public class SessionContext extends HintContext implements ISessionContext, Disp } private void initializeSession(Session s) throws DatabaseException { - s.registerService(MergingGraphRequestProcessor.class, new MergingGraphRequestProcessor("SessionService", s, 20)); - s.registerService(MergingDelayedWriteProcessor.class, new MergingDelayedWriteProcessor(s, 20)); s.registerService(VirtualGraph.class, s.getService(VirtualGraphSupport.class).getMemoryPersistent(UUID.randomUUID().toString())); // Builtins needs to be initialized for the new session before // anything useful can be done with it. - s.syncRequest(new ReadRequest() { + s.syncRequest(new Read() { @Override - public void run(ReadGraph g) { + public Object perform(ReadGraph g) { // Registers Builtins with the ServiceLocator of the Graph's session. Layer0.getInstance(g); + return null; } }); - } - - public void registerServices() { - if (servicesRegistered) - return; - - // Register any services available for the SessionLocator of the new - // Session. - servicesRegisteredStatus = new GlobalServiceInitializer().initialize(session); - if (!servicesRegisteredStatus.isOK()) { - Activator.getDefault().getLog().log(servicesRegisteredStatus); - } - - servicesRegistered = true; + } // @Override diff --git a/bundles/org.simantics.db.management/src/org/simantics/db/management/internal/SessionManagerProvider.java b/bundles/org.simantics.db.management/src/org/simantics/db/management/internal/SessionManagerProvider.java index 81967124d..8691c0a03 100644 --- a/bundles/org.simantics.db.management/src/org/simantics/db/management/internal/SessionManagerProvider.java +++ b/bundles/org.simantics.db.management/src/org/simantics/db/management/internal/SessionManagerProvider.java @@ -11,7 +11,6 @@ *******************************************************************************/ package org.simantics.db.management.internal; -import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.util.Properties; @@ -21,8 +20,6 @@ import org.osgi.framework.Bundle; import org.simantics.db.SessionManager; import org.simantics.utils.FileUtils; -import fi.vtt.simantics.procore.SessionManagerSource; - /** * Complete hack for the time being. Simply provides the SessionManager behind * procore's SessionManagerSource with proper initialization. @@ -40,12 +37,12 @@ public final class SessionManagerProvider { return provider; } - public SessionManager getSessionManager() throws IOException { - if (sessionManager == null) { - sessionManager = SessionManagerSource.getSessionManager(loadProperties()); - } - return sessionManager; - } +// public SessionManager getSessionManager() throws IOException { +// if (sessionManager == null) { +// sessionManager = SessionManagerSource.getSessionManager(loadProperties()); +// } +// return sessionManager; +// } private Properties loadProperties() { Bundle procore = Platform.getBundle("org.simantics.db.procore"); diff --git a/bundles/org.simantics.db.services/META-INF/MANIFEST.MF b/bundles/org.simantics.db.services/META-INF/MANIFEST.MF index 7403f3d70..bb78bf41e 100644 --- a/bundles/org.simantics.db.services/META-INF/MANIFEST.MF +++ b/bundles/org.simantics.db.services/META-INF/MANIFEST.MF @@ -6,9 +6,13 @@ Bundle-Version: 1.1.0.qualifier Bundle-Vendor: VTT Technical Research Centre of Finland Require-Bundle: org.eclipse.core.runtime, gnu.trove3, - org.simantics.layer0.utils;bundle-version="1.1.0", org.simantics.layer0x.ontology;bundle-version="1.0.0", - org.slf4j.api;bundle-version="1.7.25" + org.slf4j.api;bundle-version="1.7.25", + org.simantics.utils;bundle-version="1.1.0", + org.simantics.db;bundle-version="1.1.0", + org.simantics.scl.reflection, + org.simantics.db.common;bundle-version="1.1.0", + org.simantics.layer0.utils Export-Package: org.simantics.db.services, org.simantics.db.services.activation, org.simantics.db.services.adaption diff --git a/bundles/org.simantics.db.services/src/org/simantics/db/services/adaption/AdapterRegistry2.java b/bundles/org.simantics.db.services/src/org/simantics/db/services/adaption/AdapterRegistry2.java index 578b42a61..fe9bab552 100644 --- a/bundles/org.simantics.db.services/src/org/simantics/db/services/adaption/AdapterRegistry2.java +++ b/bundles/org.simantics.db.services/src/org/simantics/db/services/adaption/AdapterRegistry2.java @@ -36,6 +36,7 @@ import org.simantics.db.adaption.AdapterInstaller; import org.simantics.db.adaption.AdaptionService; import org.simantics.db.common.request.ReadRequest; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.request.Read; import org.simantics.db.services.adaption.reflection.AdaptingDynamicAdapter2; import org.simantics.db.services.adaption.reflection.AtMostOneRelatedResource2; import org.simantics.db.services.adaption.reflection.ConstantAdapter; @@ -337,9 +338,9 @@ public class AdapterRegistry2 { } public void updateAdaptionService(Session s, final AdaptionService service) throws DatabaseException { - s.syncRequest(new ReadRequest() { + s.syncRequest(new Read() { @Override - public void run(ReadGraph g) { + public Object perform(ReadGraph g) { for(AdapterInstaller t : installerSources.keySet()) { try { t.install(g, service); @@ -347,6 +348,7 @@ public class AdapterRegistry2 { AdapterRegistry2.this.handleException(e, t); } } + return null; } }); } diff --git a/bundles/org.simantics.db.services/src/org/simantics/db/services/adaption/reflection/ReflectionAdapter2.java b/bundles/org.simantics.db.services/src/org/simantics/db/services/adaption/reflection/ReflectionAdapter2.java index 187fc5219..870b17e78 100644 --- a/bundles/org.simantics.db.services/src/org/simantics/db/services/adaption/reflection/ReflectionAdapter2.java +++ b/bundles/org.simantics.db.services/src/org/simantics/db/services/adaption/reflection/ReflectionAdapter2.java @@ -18,9 +18,9 @@ import java.util.Arrays; import org.simantics.db.AsyncReadGraph; import org.simantics.db.Resource; import org.simantics.db.adaption.Adapter; -import org.simantics.db.common.request.AsyncReadRequest; import org.simantics.db.exception.DatabaseException; import org.simantics.db.procedure.AsyncProcedure; +import org.simantics.db.request.AsyncRead; public class ReflectionAdapter2 implements Adapter { @@ -78,35 +78,36 @@ public class ReflectionAdapter2 implements Adapter { } else { - g.asyncRequest(new AsyncReadRequest() { - + g.asyncRequest(new AsyncRead() { + @Override - public void run(AsyncReadGraph graph) { - + public void perform(AsyncReadGraph graph, AsyncProcedure p) { + Object[] args = new Object[parameters.length]; try { - for(int i=0;i implements Adapter { return "ReflectionAdapter$1" + constructor + "$" + Arrays.toString(parameters); } - }); + }, procedure); } diff --git a/bundles/org.simantics.document.base.ontology/graph/Documentation.pgraph b/bundles/org.simantics.document.base.ontology/graph/Documentation.pgraph index 4845558ea..56b2695d8 100644 --- a/bundles/org.simantics.document.base.ontology/graph/Documentation.pgraph +++ b/bundles/org.simantics.document.base.ontology/graph/Documentation.pgraph @@ -100,6 +100,65 @@ Documentation.child10 : L0.Template Documentation.Relations.parent %connection %connection : STR.Connection +Documentation.child1_ : L0.Template + @template %parent %child + _ : STR.Connection + Documentation.Relations.part1.Inverse %parent + Documentation.Relations.parent.Inverse %child + +Documentation.child2_ : L0.Template + @template %parent %child + _ : STR.Connection + Documentation.Relations.part2.Inverse %parent + Documentation.Relations.parent.Inverse %child + +Documentation.child3_ : L0.Template + @template %parent %child + _ : STR.Connection + Documentation.Relations.part3.Inverse %parent + Documentation.Relations.parent.Inverse %child + +Documentation.child4_ : L0.Template + @template %parent %child + _ : STR.Connection + Documentation.Relations.part4.Inverse %parent + Documentation.Relations.parent.Inverse %child + +Documentation.child5_ : L0.Template + @template %parent %child + _ : STR.Connection + Documentation.Relations.part5.Inverse %parent + Documentation.Relations.parent.Inverse %child + +Documentation.child6_ : L0.Template + @template %parent %child + _ : STR.Connection + Documentation.Relations.part6.Inverse %parent + Documentation.Relations.parent.Inverse %child + +Documentation.child7_ : L0.Template + @template %parent %child + _ : STR.Connection + Documentation.Relations.part7.Inverse %parent + Documentation.Relations.parent.Inverse %child + +Documentation.child8_ : L0.Template + @template %parent %child + _ : STR.Connection + Documentation.Relations.part8.Inverse %parent + Documentation.Relations.parent.Inverse %child + +Documentation.child9_ : L0.Template + @template %parent %child + _ : STR.Connection + Documentation.Relations.part9.Inverse %parent + Documentation.Relations.parent.Inverse %child + +Documentation.child10_ : L0.Template + @template %parent %child + _ : STR.Connection + Documentation.Relations.part10.Inverse %parent + Documentation.Relations.parent.Inverse %child Documentation.singleData : L0.Template @template %commandEvent %defVar %dataSource %eventSource %eventRelation %sourceName %targetName %DataSourceConn %DataTargetConn %EventConn diff --git a/bundles/org.simantics.document.server/scl/Document/All.scl b/bundles/org.simantics.document.server/scl/Document/All.scl index a90a24bcb..d676e2a3b 100644 --- a/bundles/org.simantics.document.server/scl/Document/All.scl +++ b/bundles/org.simantics.document.server/scl/Document/All.scl @@ -122,9 +122,9 @@ importJava "org.simantics.document.server.Functions" where readEventHandler :: Variable -> (Variable -> (String -> Maybe String) -> String) -> AbstractEventHandler eventHandler :: ((String -> Maybe String) -> String) -> AbstractEventHandler - readEventHandler2 :: (CommandContext -> Maybe CommandResult) -> AbstractEventHandler - writeEventHandler2 :: (CommandContext -> Maybe CommandResult) -> AbstractEventHandler - eventHandler2 :: (CommandContext -> Maybe CommandResult) -> AbstractEventHandler + readEventHandler2 :: (CommandContext -> Maybe CommandResult) -> AbstractEventHandler + writeEventHandler2 :: (CommandContext -> Maybe CommandResult) -> AbstractEventHandler + eventHandler2 :: (CommandContext -> Maybe CommandResult) -> AbstractEventHandler responseHandler :: Variable -> String -> AbstractEventHandler @@ -147,6 +147,9 @@ importJava "org.simantics.document.server.Functions" where compileDocumentSCLHandlerValueExpression :: Variable -> String primitiveProperties :: DocumentProperties + +contextVariable :: Variable -> Variable +contextVariable var = propertyValue (variableParent var) "input" propertyValueCached :: Serializable a => Typeable a => Variable -> String -> a propertyValueCached var prop = propertyValueCached_ var prop binding diff --git a/bundles/org.simantics.document.server/src/org/simantics/document/server/IEventCommand.java b/bundles/org.simantics.document.server/src/org/simantics/document/server/IEventCommand.java index b971fef4c..5a024ec39 100644 --- a/bundles/org.simantics.document.server/src/org/simantics/document/server/IEventCommand.java +++ b/bundles/org.simantics.document.server/src/org/simantics/document/server/IEventCommand.java @@ -1,11 +1,14 @@ package org.simantics.document.server; +import org.simantics.document.server.io.CommandContext; +import org.simantics.document.server.io.CommandContextMutable; + public interface IEventCommand { public void setNext(IEventCommand command); public IEventCommand getNext(); - public void handleCommand(); - public void commandSuccess(); + public CommandContext handleCommand(CommandContextMutable context); + public CommandContext commandSuccess(CommandContextMutable context); public void commandError(String errorMessage); } diff --git a/bundles/org.simantics.document.server/src/org/simantics/document/server/bean/Command.java b/bundles/org.simantics.document.server/src/org/simantics/document/server/bean/Command.java index f47c0c5c3..ddfb6ea9e 100644 --- a/bundles/org.simantics.document.server/src/org/simantics/document/server/bean/Command.java +++ b/bundles/org.simantics.document.server/src/org/simantics/document/server/bean/Command.java @@ -12,6 +12,10 @@ public class Command implements ICommand { public Command() {} + public Command(String command) { + this.command = command; + } + public Command(String targetId, String trigger, String command, CommandContext constants) { this.targetId = targetId; this.trigger = trigger; diff --git a/bundles/org.simantics.document.server/src/org/simantics/document/server/client/WidgetData.java b/bundles/org.simantics.document.server/src/org/simantics/document/server/client/WidgetData.java index 1235d527c..92e8b293d 100644 --- a/bundles/org.simantics.document.server/src/org/simantics/document/server/client/WidgetData.java +++ b/bundles/org.simantics.document.server/src/org/simantics/document/server/client/WidgetData.java @@ -5,6 +5,8 @@ import java.util.TreeMap; import org.simantics.document.server.IEventCommand; import org.simantics.document.server.JSONObject; +import org.simantics.document.server.io.CommandContext; +import org.simantics.document.server.io.ICommand; public class WidgetData { @@ -67,12 +69,12 @@ public class WidgetData { } @SuppressWarnings({ "unchecked", "rawtypes" }) - public IEventCommand eventCommand(String command) { + public IEventCommand eventCommand(ICommand command, CommandContext c) { if(object == null) return null; WidgetManager manager = document.getManager(object); if(manager != null) - return manager.eventCommand(document, object, widget, command); + return manager.eventCommand(document, object, widget, command, c); else return null; } diff --git a/bundles/org.simantics.document.server/src/org/simantics/document/server/client/WidgetManager.java b/bundles/org.simantics.document.server/src/org/simantics/document/server/client/WidgetManager.java index 8474bfd15..09338b50d 100644 --- a/bundles/org.simantics.document.server/src/org/simantics/document/server/client/WidgetManager.java +++ b/bundles/org.simantics.document.server/src/org/simantics/document/server/client/WidgetManager.java @@ -4,6 +4,8 @@ import java.util.TreeMap; import org.simantics.document.server.IEventCommand; import org.simantics.document.server.JSONObject; +import org.simantics.document.server.io.CommandContext; +import org.simantics.document.server.io.ICommand; public interface WidgetManager { @@ -13,7 +15,7 @@ public interface WidgetManager { public void updateChildren(D document, JSONObject object, W widget, TreeMap childMap); - public IEventCommand eventCommand(D document, JSONObject object, W widget, String command); + public IEventCommand eventCommand(D document, JSONObject object, W widget, ICommand command, CommandContext context); public String getProperty(D document, JSONObject object, W widget, String property); diff --git a/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/SWTDocument.java b/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/SWTDocument.java index 41183050f..e0db02e8b 100644 --- a/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/SWTDocument.java +++ b/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/SWTDocument.java @@ -1,6 +1,7 @@ package org.simantics.document.swt.core; import java.util.Collections; +import java.util.List; import java.util.Map; import org.eclipse.jface.viewers.ISelectionProvider; @@ -8,8 +9,12 @@ import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Font; import org.eclipse.ui.IWorkbenchSite; import org.simantics.document.server.client.Document; -import org.simantics.document.server.handler.AbstractEventHandler; +import org.simantics.document.server.client.WidgetData; +import org.simantics.document.server.io.AbstractEventHandler; import org.simantics.document.server.io.CommandContext; +import org.simantics.document.server.io.CommandContextMutable; +import org.simantics.document.server.io.ICommand; +import org.simantics.utils.datastructures.Pair; public interface SWTDocument extends Document { @@ -19,7 +24,8 @@ public interface SWTDocument extends Document { ISelectionProvider getSelectionProvider(); Color getColor(org.simantics.datatypes.literal.RGB.Integer bean); Font getFont(org.simantics.datatypes.literal.Font bean); - void post(AbstractEventHandler handler, CommandContext parameters); + void post(AbstractEventHandler handler, CommandContextMutable context); + CommandContext handleCommands(List> data, CommandContextMutable context, Object component); void layout(); void displayError(String error); diff --git a/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/SWTDocumentClient.java b/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/SWTDocumentClient.java index 58c280595..090448db5 100644 --- a/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/SWTDocumentClient.java +++ b/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/SWTDocumentClient.java @@ -1,8 +1,10 @@ package org.simantics.document.swt.core; +import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; import org.eclipse.jface.layout.GridDataFactory; @@ -15,16 +17,21 @@ import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.ui.IWorkbenchSite; import org.simantics.db.common.utils.Logger; +import org.simantics.document.server.IEventCommand; import org.simantics.document.server.JSONObject; import org.simantics.document.server.client.DocumentClient; import org.simantics.document.server.client.WidgetData; import org.simantics.document.server.client.WidgetMapping; -import org.simantics.document.server.handler.AbstractEventHandler; +import org.simantics.document.server.io.AbstractEventHandler; import org.simantics.document.server.io.CommandContext; +import org.simantics.document.server.io.CommandContextMutable; +import org.simantics.document.server.io.ICommand; +import org.simantics.document.server.io.JSONObjectUtils; import org.simantics.document.swt.core.base.WidgetContainer; import org.simantics.document.swt.core.widget.FillComposite; import org.simantics.ui.colors.Colors; import org.simantics.ui.fonts.Fonts; +import org.simantics.utils.datastructures.Pair; import org.simantics.utils.threads.IThreadWorkQueue; import org.simantics.utils.threads.SWTThread; @@ -99,9 +106,10 @@ public class SWTDocumentClient extends DocumentClient implements SWTDocument { } @Override - public void post(final AbstractEventHandler handler, CommandContext parameters) { + public void post(AbstractEventHandler handler, CommandContextMutable parameters) { handler.handle(parameters); } + @Override protected void updateDocument(Collection objects) { @@ -141,6 +149,36 @@ public class SWTDocumentClient extends DocumentClient implements SWTDocument { } + @Override + public CommandContext handleCommands(List> data, CommandContextMutable context, Object component) { + + // Build a linked list of commands + + ArrayList commands = new ArrayList(); + for(Pair pair : data) { + WidgetData d = pair.first; + + ICommand c = pair.second; + IEventCommand p = d.eventCommand(c, null); +// if(component != null && p != null) +// p.setTrigger(component); + if(p != null) { + if(!commands.isEmpty()) + commands.get(commands.size()-1).setNext(p); + commands.add(p); + } + } + + // Execute the first command, the linked list handles the rest of them + if(!commands.isEmpty()) { + try { + commands.get(0).handleCommand(context); + } finally { + } + } + return context; + } + @Override public void layout() { requireLayout = true; diff --git a/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/SWTViews.java b/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/SWTViews.java index 468bf7bda..9b81f9eea 100644 --- a/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/SWTViews.java +++ b/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/SWTViews.java @@ -1,6 +1,9 @@ package org.simantics.document.swt.core; +import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.eclipse.swt.widgets.Composite; @@ -8,8 +11,11 @@ import org.eclipse.swt.widgets.Control; import org.simantics.document.server.JSONObject; import org.simantics.document.server.client.CommandMapping; import org.simantics.document.server.client.CommandMappingImpl; +import org.simantics.document.server.client.Document; +import org.simantics.document.server.client.WidgetData; import org.simantics.document.server.client.WidgetMapping; import org.simantics.document.server.client.WidgetMappingImpl; +import org.simantics.document.server.io.ICommand; import org.simantics.document.swt.core.base.ScrolledCompositeContent; import org.simantics.document.swt.core.widget.BrowserWidget; import org.simantics.document.swt.core.widget.ButtonWidget; @@ -23,6 +29,7 @@ import org.simantics.document.swt.core.widget.LabelWidget; import org.simantics.document.swt.core.widget.SCLTextEditor; import org.simantics.document.swt.core.widget.ScrolledCompositeWidget; import org.simantics.document.swt.core.widget.TrackedTextWidget; +import org.simantics.utils.datastructures.Pair; public class SWTViews { @@ -58,6 +65,7 @@ public class SWTViews { commandMapping = new CommandMappingImpl(); commandMapping.register("Button", new ButtonWidget.ButtonCommandManager()); + commandMapping.register("Explorer", new Explorer.ExplorerCommandManager()); } @@ -65,6 +73,22 @@ public class SWTViews { } + public static List> getTriggeredCommands(Document document, Collection commands, String trigger) { + // Nulls should not get this far + assert(commands != null); + List> data = new ArrayList>(); + for(ICommand c : commands) { + if(c.getCommand() == null || c.getTargetId() == null || c.getTrigger() == null) + continue; + if(trigger.equals(c.getTrigger())) { + WidgetData wd = document.getWidgetData().get(c.getTargetId()); + if(wd != null) + data.add(new Pair(wd, c)); + } + } + return data; + } + public static void notifyScrolledComposite(Control c) { if(c instanceof ScrolledCompositeContent) { ScrolledCompositeContent content = (ScrolledCompositeContent)c; diff --git a/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/base/AbstractEventCommand.java b/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/base/AbstractEventCommand.java index 3bd0364e7..57a2fbbe8 100644 --- a/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/base/AbstractEventCommand.java +++ b/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/base/AbstractEventCommand.java @@ -1,6 +1,8 @@ package org.simantics.document.swt.core.base; import org.simantics.document.server.IEventCommand; +import org.simantics.document.server.io.CommandContext; +import org.simantics.document.server.io.CommandContextMutable; import org.simantics.document.swt.core.SWTDocument; public abstract class AbstractEventCommand implements IEventCommand { @@ -23,9 +25,10 @@ public abstract class AbstractEventCommand implements IEventCommand { } @Override - public void commandSuccess() { + public CommandContext commandSuccess(CommandContextMutable context) { if(next != null) - next.handleCommand(); + return next.handleCommand(context); + return context; } @Override diff --git a/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/base/PostEventCommand.java b/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/base/PostEventCommand.java index ff6d4fd13..2537f9de9 100644 --- a/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/base/PostEventCommand.java +++ b/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/base/PostEventCommand.java @@ -1,40 +1,37 @@ package org.simantics.document.swt.core.base; -import java.util.Map; - -import org.simantics.document.server.handler.AbstractEventHandler; +import org.simantics.document.server.io.AbstractEventHandler; import org.simantics.document.server.io.CommandContext; -import org.simantics.document.server.io.CommandContextImpl; +import org.simantics.document.server.io.CommandContextMutable; import org.simantics.document.swt.core.SWTDocument; public class PostEventCommand extends AbstractEventCommand { private AbstractEventHandler handler; - private CommandContextImpl parameters; + private CommandContextMutable context; - public PostEventCommand(SWTDocument document, AbstractEventHandler handler, Map parameters) { - this(document, handler, parameters, null); + public PostEventCommand(SWTDocument document, AbstractEventHandler handler, CommandContextMutable context) { + this(document, handler, context, null); } - public PostEventCommand(SWTDocument document, AbstractEventHandler handler, Map parameters, PostEventCommand next) { + public PostEventCommand(SWTDocument document, AbstractEventHandler handler, CommandContextMutable context, PostEventCommand next) { super(document); this.handler = handler; - this.parameters = new CommandContextImpl(); - for(Map.Entry entry : parameters.entrySet()) { - this.parameters.putString(entry.getKey(), entry.getValue()); - } + this.context = context; this.next = next; } @Override - public void handleCommand() { - document.post(handler, parameters); + public CommandContext handleCommand(CommandContextMutable context) { + document.post(handler, context); + return context; } @Override - public void commandSuccess() { + public CommandContext commandSuccess(CommandContextMutable context) { if(next != null) - next.handleCommand(); + return next.handleCommand(context); + return context; } @Override diff --git a/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/base/PropertyWidgetManager.java b/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/base/PropertyWidgetManager.java index 1c3297061..c8593c604 100644 --- a/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/base/PropertyWidgetManager.java +++ b/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/base/PropertyWidgetManager.java @@ -1,9 +1,23 @@ package org.simantics.document.swt.core.base; +import java.awt.Component; +import java.util.Collection; +import java.util.List; +import java.util.Map; + import org.simantics.document.server.IEventCommand; import org.simantics.document.server.JSONObject; +import org.simantics.document.server.client.Document; +import org.simantics.document.server.client.WidgetData; import org.simantics.document.server.client.WidgetManager; +import org.simantics.document.server.io.CommandContext; +import org.simantics.document.server.io.CommandContextImpl; +import org.simantics.document.server.io.CommandContextMutable; +import org.simantics.document.server.io.ICommand; +import org.simantics.document.server.io.JSONObjectUtils; import org.simantics.document.swt.core.SWTDocument; +import org.simantics.document.swt.core.SWTViews; +import org.simantics.utils.datastructures.Pair; public abstract class PropertyWidgetManager implements WidgetManager { @@ -13,8 +27,24 @@ public abstract class PropertyWidgetManager implements WidgetManager commands = JSONObjectUtils.getCommands(wd.object); + + if(context == null) context = new CommandContextImpl(); + context.putValue("event", event); + + List> data = SWTViews.getTriggeredCommands(document, commands, "eventOut"); + + return document.handleCommands(data, context, wd.widget); + + } + } diff --git a/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/widget/ButtonSelectionListener.java b/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/widget/ButtonSelectionListener.java index 303460dea..2f9a33bfa 100644 --- a/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/widget/ButtonSelectionListener.java +++ b/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/widget/ButtonSelectionListener.java @@ -1,19 +1,25 @@ package org.simantics.document.swt.core.widget; -import java.util.ArrayList; -import java.util.LinkedHashMap; +import java.util.List; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; -import org.simantics.document.server.IEventCommand; import org.simantics.document.server.client.WidgetData; +import org.simantics.document.server.io.CommandContext; +import org.simantics.document.server.io.CommandContextImpl; +import org.simantics.document.server.io.CommandContextMutable; +import org.simantics.document.server.io.ICommand; import org.simantics.document.swt.core.SWTDocument; +import org.simantics.document.swt.core.base.PropertyWidgetManager; +import org.simantics.utils.datastructures.Pair; public class ButtonSelectionListener implements SelectionListener { - private LinkedHashMap data; + private WidgetData wd; + private List> data; - public ButtonSelectionListener(LinkedHashMap data) { + public ButtonSelectionListener(WidgetData wd, List> data) { + this.wd = wd; this.data = data; } @@ -24,27 +30,37 @@ public class ButtonSelectionListener implements SelectionListener { @Override public void widgetDefaultSelected(SelectionEvent e) { - SWTDocument document = null; - // Build a linked list of commands - ArrayList commands = new ArrayList(); - for(WidgetData d : data.keySet()) { - document = (SWTDocument)d.document; // assume that all widgets are from the same document - IEventCommand p = d.eventCommand(data.get(d)); - if(p != null) { - if(!commands.isEmpty()) - commands.get(commands.size()-1).setNext(p); - commands.add(p); +// SWTDocument document = null; +// // Build a linked list of commands +// ArrayList commands = new ArrayList(); +// for(WidgetData d : data.keySet()) { +// document = (SWTDocument)d.document; // assume that all widgets are from the same document +// IEventCommand p = d.eventCommand(data.get(d)); +// if(p != null) { +// if(!commands.isEmpty()) +// commands.get(commands.size()-1).setNext(p); +// commands.add(p); +// } + + CommandContextMutable context = new CommandContextImpl(); + context.putValue("event", "onPress"); + + if(!data.isEmpty()) { + ((SWTDocument)wd.document).handleCommands(data, context, e.widget); } - } + + CommandContext ret = PropertyWidgetManager.sendEvent((SWTDocument)wd.document, wd, "onPress", e.widget, context); + +// } // empty errors // if(document != null) // document.displayError(""); // Execute the first command, the linked list handles the rest of them - if(!commands.isEmpty()) - commands.get(0).handleCommand(); - +// if(!commands.isEmpty()) +// commands.get(0).handleCommand(); +// } } \ No newline at end of file diff --git a/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/widget/ButtonWidget.java b/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/widget/ButtonWidget.java index 384ef88cd..0142fdf6b 100644 --- a/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/widget/ButtonWidget.java +++ b/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/widget/ButtonWidget.java @@ -1,11 +1,9 @@ package org.simantics.document.swt.core.widget; +import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.HashSet; -import java.util.LinkedHashMap; import java.util.List; -import java.util.Map; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionListener; @@ -17,11 +15,18 @@ import org.simantics.document.server.bean.Command; import org.simantics.document.server.client.CommandManager; import org.simantics.document.server.client.WidgetData; import org.simantics.document.server.handler.AbstractEventHandler; -import org.simantics.document.server.handler.EventHandler; +import org.simantics.document.server.io.CommandContext; +import org.simantics.document.server.io.CommandContextImpl; +import org.simantics.document.server.io.CommandContextMutable; +import org.simantics.document.server.io.ICommand; +import org.simantics.document.server.io.JSONObjectUtils; import org.simantics.document.swt.core.SWTDocument; +import org.simantics.document.swt.core.SWTViews; import org.simantics.document.swt.core.base.LeafWidgetManager; import org.simantics.document.swt.core.base.PostEventCommand; import org.simantics.document.swt.core.base.WidgetContainer; +import org.simantics.utils.datastructures.Pair; +import org.simantics.utils.ui.SWTUtils; public class ButtonWidget extends LeafWidgetManager