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.Simantics;
17 import org.simantics.db.ReadGraph;
18 import org.simantics.db.Resource;
19 import org.simantics.db.Session;
20 import org.simantics.db.common.request.UniqueRead;
21 import org.simantics.db.common.utils.RequestUtil;
22 import org.simantics.db.exception.DatabaseException;
23 import org.simantics.modeling.ModelingResources;
24 import org.simantics.ui.SimanticsUI;
25 import org.simantics.ui.utils.ResourceAdaptionUtils;
28 * An Eclipse property tester for normal elements.
30 * @author Tuukka Lehtonen
32 public class ElementPropertyTester extends PropertyTester {
35 * Tests if the received element resource is mapped to a counterpart.
36 * Default expected value is true.
38 private static final String MAPPED = "mapped";
41 public boolean test(Object receiver, final String property, final Object[] args, final Object expectedValue) {
42 final Resource resource = ResourceAdaptionUtils.toSingleResource(receiver);
46 Session session = Simantics.peekSession();
50 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 g) throws DatabaseException {
62 return Boolean.valueOf(doTest(g, resource, property, args, expectedValue));
65 } catch (DatabaseException | InterruptedException e) {
66 // Purposefully not logging these exceptions, there might be way too
67 // many even under normal circumstances.
68 // TODO: add debug tracing options controlling the printing of these exceptions
73 private boolean doTest(ReadGraph graph, Resource resource, String property, Object[] args, Object expectedValue) throws DatabaseException {
74 if (MAPPED.equals(property)) {
75 return graph.hasStatement(resource, ModelingResources.getInstance(graph).ElementToComponent);