X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.modeling.ui%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fui%2FmodelBrowser2%2Fcontributions%2FIsUserDefinedComponentTest.java;h=2800d4e72130490a311da6f8611e7ceb7791198e;hb=c26409b1caf2f1e560d37c5befd11b442399c3fe;hp=9ed7f1cde030caabb46bb1070b5533ae8472cdc1;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser2/contributions/IsUserDefinedComponentTest.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser2/contributions/IsUserDefinedComponentTest.java index 9ed7f1cde..2800d4e72 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser2/contributions/IsUserDefinedComponentTest.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser2/contributions/IsUserDefinedComponentTest.java @@ -1,68 +1,68 @@ -/******************************************************************************* - * Copyright (c) 2013 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: - * Semantum Oy - initial API and implementation - *******************************************************************************/ -package org.simantics.modeling.ui.modelBrowser2.contributions; - -import org.simantics.browsing.ui.model.tests.Test; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.layer0.variable.Variable; -import org.simantics.structural.stubs.StructuralResource2; - -/** - * @author Tuukka Lehtonen - */ -public enum IsUserDefinedComponentTest implements Test { - - INSTANCE; - - public static IsUserDefinedComponentTest get() { - return INSTANCE; - } - - @Override - public boolean isCompatible(Class contentType) { - return Variable.class.equals(contentType) || - Resource.class.equals(contentType); - } - - @Override - public boolean test(ReadGraph graph, Object content) throws DatabaseException { - if (content instanceof Variable) { - Variable v = (Variable) content; - //System.out.println("Test variable: " + v.getURI(graph)); - StructuralResource2 STR = StructuralResource2.getInstance(graph); - Resource type = v.getPossibleType(graph, STR.Component); - //System.out.println("variable component type: " + NameUtils.getURIOrSafeNameInternal(graph, type)); - return isUserComponentType(graph, type, STR); - } else if (content instanceof Resource) { - Resource r = (Resource) content; - //System.out.println("Test resource: " + NameUtils.getURIOrSafeNameInternal(graph, r)); - StructuralResource2 STR = StructuralResource2.getInstance(graph); - Resource type = graph.getPossibleType(r, STR.Component); - //System.out.println("resource component type: " + NameUtils.getURIOrSafeNameInternal(graph, type)); - return isUserComponentType(graph, type, STR); - } - return false; - } - - private static boolean isUserComponentType(ReadGraph graph, Resource type, StructuralResource2 STR) throws DatabaseException { - if (type == null) - return false; - Resource definedBy = graph.getPossibleObject(type, STR.IsDefinedBy); - if (definedBy != null) - return true; - boolean procedural = graph.isInstanceOf(type, STR.ProceduralComponentType); - return procedural; - } - -} +/******************************************************************************* + * Copyright (c) 2013 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: + * Semantum Oy - initial API and implementation + *******************************************************************************/ +package org.simantics.modeling.ui.modelBrowser2.contributions; + +import org.simantics.browsing.ui.model.tests.Test; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.structural.stubs.StructuralResource2; + +/** + * @author Tuukka Lehtonen + */ +public enum IsUserDefinedComponentTest implements Test { + + INSTANCE; + + public static IsUserDefinedComponentTest get() { + return INSTANCE; + } + + @Override + public boolean isCompatible(Class contentType) { + return Variable.class.equals(contentType) || + Resource.class.equals(contentType); + } + + @Override + public boolean test(ReadGraph graph, Object content) throws DatabaseException { + if (content instanceof Variable) { + Variable v = (Variable) content; + //System.out.println("Test variable: " + v.getURI(graph)); + StructuralResource2 STR = StructuralResource2.getInstance(graph); + Resource type = v.getPossibleType(graph, STR.Component); + //System.out.println("variable component type: " + NameUtils.getURIOrSafeNameInternal(graph, type)); + return isUserComponentType(graph, type, STR); + } else if (content instanceof Resource) { + Resource r = (Resource) content; + //System.out.println("Test resource: " + NameUtils.getURIOrSafeNameInternal(graph, r)); + StructuralResource2 STR = StructuralResource2.getInstance(graph); + Resource type = graph.getPossibleType(r, STR.Component); + //System.out.println("resource component type: " + NameUtils.getURIOrSafeNameInternal(graph, type)); + return isUserComponentType(graph, type, STR); + } + return false; + } + + private static boolean isUserComponentType(ReadGraph graph, Resource type, StructuralResource2 STR) throws DatabaseException { + if (type == null) + return false; + Resource definedBy = graph.getPossibleObject(type, STR.IsDefinedBy); + if (definedBy != null) + return true; + boolean procedural = graph.isInstanceOf(type, STR.ProceduralComponentType); + return procedural; + } + +}