1 /*******************************************************************************
2 * Copyright (c) 2007, 2012 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.modeling.ui.property;
14 import java.util.Collection;
16 import org.eclipse.core.expressions.PropertyTester;
17 import org.simantics.DatabaseJob;
18 import org.simantics.Simantics;
19 import org.simantics.db.ReadGraph;
20 import org.simantics.db.Resource;
21 import org.simantics.db.Session;
22 import org.simantics.db.common.request.UniqueRead;
23 import org.simantics.db.common.utils.RequestUtil;
24 import org.simantics.db.exception.DatabaseException;
25 import org.simantics.db.layer0.request.ActiveModels;
26 import org.simantics.scl.reflection.OntologyVersions;
27 import org.simantics.ui.SimanticsUI;
28 import org.simantics.utils.ui.ErrorLogger;
31 * @author Tuukka Lehtonen
33 public class ModelPropertyTester extends PropertyTester {
36 * Tests if the received object within the model browser tree node is an
37 * instance of the class specified as the argument.
39 private static final String HAS_ACTIVE_MODELS_OF_TYPE = "hasActiveModelsOfType";
42 public boolean test(final Object receiver, final String property, final Object[] args, final Object expectedValue) {
44 if (HAS_ACTIVE_MODELS_OF_TYPE.equals(property)) {
48 Session session = Simantics.peekSession();
49 final Resource project = Simantics.peekProjectResource();
50 if (session != null && project != null) {
51 if (DatabaseJob.inProgress())
54 return RequestUtil.trySyncRequest(
56 SimanticsUI.UI_THREAD_REQUEST_START_TIMEOUT,
57 SimanticsUI.UI_THREAD_REQUEST_EXECUTION_TIMEOUT,
59 new UniqueRead<Boolean>() {
61 public Boolean perform(ReadGraph graph)
62 throws DatabaseException {
63 Resource type = graph.getPossibleResource( OntologyVersions.getInstance().currentVersion((String) args[0]) );
67 Collection<Resource> activeModels = graph.syncRequest(new ActiveModels(project));
68 for (Resource activeModel : activeModels)
69 if (graph.isInstanceOf(activeModel, type))
76 } catch (DatabaseException | InterruptedException e) {
77 ErrorLogger.defaultLogError(e);