1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 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.diagram.elements;
14 import org.eclipse.core.expressions.PropertyTester;
15 import org.simantics.DatabaseJob;
16 import org.simantics.db.ReadGraph;
17 import org.simantics.db.Resource;
18 import org.simantics.db.Session;
19 import org.simantics.db.common.request.UniqueRead;
20 import org.simantics.db.common.utils.RequestUtil;
21 import org.simantics.db.exception.DatabaseException;
22 import org.simantics.modeling.ModelingResources;
23 import org.simantics.ui.SimanticsUI;
24 import org.simantics.ui.utils.ResourceAdaptionUtils;
27 * An Eclipse property tester for normal elements.
29 * @author Tuukka Lehtonen
31 public class ElementPropertyTester extends PropertyTester {
34 * Tests if the received element resource is mapped to a counterpart.
35 * Default expected value is true.
37 private static final String MAPPED = "mapped";
40 public boolean test(Object receiver, final String property, final Object[] args, final Object expectedValue) {
41 final Resource resource = ResourceAdaptionUtils.toSingleResource(receiver);
45 Session session = SimanticsUI.peekSession();
49 if (DatabaseJob.inProgress())
53 return RequestUtil.trySyncRequest(
55 SimanticsUI.UI_THREAD_REQUEST_START_TIMEOUT,
56 SimanticsUI.UI_THREAD_REQUEST_EXECUTION_TIMEOUT,
58 new UniqueRead<Boolean>() {
60 public Boolean perform(ReadGraph g) throws DatabaseException {
61 return Boolean.valueOf(doTest(g, resource, property, args, expectedValue));
64 } catch (DatabaseException | InterruptedException e) {
65 // Purposefully not logging these exceptions, there might be way too
66 // many even under normal circumstances.
67 // TODO: add debug tracing options controlling the printing of these exceptions
72 private boolean doTest(ReadGraph graph, Resource resource, String property, Object[] args, Object expectedValue) throws DatabaseException {
73 if (MAPPED.equals(property)) {
74 return graph.hasStatement(resource, ModelingResources.getInstance(graph).ElementToComponent);