X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.modeling.ui%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fui%2Fproperty%2FModelPropertyTester.java;h=a03d7dd62c972926a4b25b27729b55ab7db170a4;hb=55d1e6f63df516019032ebf0c1e9c8c0495a619d;hp=5a4d485aa008691a85f5bd832e3d21a5b5517c0d;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/property/ModelPropertyTester.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/property/ModelPropertyTester.java index 5a4d485aa..a03d7dd62 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/property/ModelPropertyTester.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/property/ModelPropertyTester.java @@ -1,82 +1,82 @@ -/******************************************************************************* - * Copyright (c) 2007, 2012 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.modeling.ui.property; - -import java.util.Collection; - -import org.eclipse.core.expressions.PropertyTester; -import org.simantics.DatabaseJob; -import org.simantics.Simantics; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.Session; -import org.simantics.db.common.request.UniqueRead; -import org.simantics.db.common.utils.RequestUtil; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.layer0.request.ActiveModels; -import org.simantics.scl.reflection.OntologyVersions; -import org.simantics.ui.SimanticsUI; -import org.simantics.utils.ui.ErrorLogger; - -/** - * @author Tuukka Lehtonen - */ -public class ModelPropertyTester extends PropertyTester { - - /** - * Tests if the received object within the model browser tree node is an - * instance of the class specified as the argument. - */ - private static final String HAS_ACTIVE_MODELS_OF_TYPE = "hasActiveModelsOfType"; - - @Override - public boolean test(final Object receiver, final String property, final Object[] args, final Object expectedValue) { - try { - if (HAS_ACTIVE_MODELS_OF_TYPE.equals(property)) { - if (args.length == 0) - return false; - - Session session = Simantics.peekSession(); - final Resource project = Simantics.peekProjectResource(); - if (session != null && project != null) { - if (DatabaseJob.inProgress()) - return false; - - return RequestUtil.trySyncRequest( - session, - SimanticsUI.UI_THREAD_REQUEST_START_TIMEOUT, - SimanticsUI.UI_THREAD_REQUEST_EXECUTION_TIMEOUT, - false, - new UniqueRead() { - @Override - public Boolean perform(ReadGraph graph) - throws DatabaseException { - Resource type = graph.getPossibleResource( OntologyVersions.getInstance().currentVersion((String) args[0]) ); - if (type == null) - return false; - - Collection activeModels = graph.syncRequest(new ActiveModels(project)); - for (Resource activeModel : activeModels) - if (graph.isInstanceOf(activeModel, type)) - return true; - return false; - } - }); - } - } - } catch (DatabaseException | InterruptedException e) { - ErrorLogger.defaultLogError(e); - } - return false; - } - -} +/******************************************************************************* + * Copyright (c) 2007, 2012 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.modeling.ui.property; + +import java.util.Collection; + +import org.eclipse.core.expressions.PropertyTester; +import org.simantics.DatabaseJob; +import org.simantics.Simantics; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.common.request.UniqueRead; +import org.simantics.db.common.utils.RequestUtil; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.request.ActiveModels; +import org.simantics.scl.reflection.OntologyVersions; +import org.simantics.ui.SimanticsUI; +import org.simantics.utils.ui.ErrorLogger; + +/** + * @author Tuukka Lehtonen + */ +public class ModelPropertyTester extends PropertyTester { + + /** + * Tests if the received object within the model browser tree node is an + * instance of the class specified as the argument. + */ + private static final String HAS_ACTIVE_MODELS_OF_TYPE = "hasActiveModelsOfType"; + + @Override + public boolean test(final Object receiver, final String property, final Object[] args, final Object expectedValue) { + try { + if (HAS_ACTIVE_MODELS_OF_TYPE.equals(property)) { + if (args.length == 0) + return false; + + Session session = Simantics.peekSession(); + final Resource project = Simantics.peekProjectResource(); + if (session != null && project != null) { + if (DatabaseJob.inProgress()) + return false; + + return RequestUtil.trySyncRequest( + session, + SimanticsUI.UI_THREAD_REQUEST_START_TIMEOUT, + SimanticsUI.UI_THREAD_REQUEST_EXECUTION_TIMEOUT, + false, + new UniqueRead() { + @Override + public Boolean perform(ReadGraph graph) + throws DatabaseException { + Resource type = graph.getPossibleResource( OntologyVersions.getInstance().currentVersion((String) args[0]) ); + if (type == null) + return false; + + Collection activeModels = graph.syncRequest(new ActiveModels(project)); + for (Resource activeModel : activeModels) + if (graph.isInstanceOf(activeModel, type)) + return true; + return false; + } + }); + } + } + } catch (DatabaseException | InterruptedException e) { + ErrorLogger.defaultLogError(e); + } + return false; + } + +}