1 /*******************************************************************************
2 * Copyright (c) 2013 Association for Decentralized Information Management in
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 * Semantum Oy - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.modeling.template2d.ui.adapters;
14 import org.simantics.browsing.ui.model.tests.Test;
15 import org.simantics.db.ReadGraph;
16 import org.simantics.db.Resource;
17 import org.simantics.db.exception.DatabaseException;
18 import org.simantics.db.layer0.request.PossibleModel;
19 import org.simantics.db.layer0.variable.Variable;
20 import org.simantics.db.layer0.variable.Variables;
23 * @author Tuukka Lehtonen
25 public enum IsInModelTest implements Test {
29 public static IsInModelTest get() {
34 public boolean isCompatible(Class<?> contentType) {
35 return Variable.class.equals(contentType) ||
36 Resource.class.equals(contentType);
40 public boolean test(ReadGraph graph, Object content) throws DatabaseException {
41 if (content instanceof Variable) {
42 Variable v = (Variable) content;
43 //System.out.println("Test variable: " + v.getURI(graph));
44 Resource model = Variables.getPossibleModel(graph, v);
45 //System.out.println("variable model: " + NameUtils.getURIOrSafeNameInternal(graph, model));
47 } else if (content instanceof Resource) {
48 Resource r = (Resource) content;
49 //System.out.println("Test resource: " + NameUtils.getURIOrSafeNameInternal(graph, r));
50 Resource model = graph.syncRequest(new PossibleModel(r));
51 //System.out.println("resource model: " + NameUtils.getURIOrSafeNameInternal(graph, model));