X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.modeling.ui%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fui%2FmodelBrowser%2Fmodel%2FComponentType.java;h=419268d860af7eb1f4f0ffc1b4cd9f934174a39d;hb=627664d06302d454ea3b3fe14d13bb5ab739d666;hp=21869f15d0251820613e70540932fd556a45de87;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser/model/ComponentType.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser/model/ComponentType.java index 21869f15d..419268d86 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser/model/ComponentType.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser/model/ComponentType.java @@ -1,148 +1,148 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 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: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.modeling.ui.modelBrowser.model; - -import java.util.ArrayList; -import java.util.Collection; - -import org.eclipse.jface.resource.ImageDescriptor; -import org.simantics.browsing.ui.common.node.IModifiable; -import org.simantics.browsing.ui.content.Labeler.Modifier; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.Session; -import org.simantics.db.WriteGraph; -import org.simantics.db.common.request.WriteRequest; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.request.Read; -import org.simantics.layer0.Layer0; -import org.simantics.modeling.ModelingResources; -import org.simantics.modeling.ui.Activator; -import org.simantics.structural.stubs.StructuralResource2; - -@Deprecated -public class ComponentType extends Node implements IModifiable { - - final static boolean showFolders = true; - - Resource content; - Resource instance; - - public ComponentType(ReadGraph g, Resource resource) throws DatabaseException { - this(g, resource, null); - } - - public ComponentType(ReadGraph g, Resource resource, Resource instance) throws DatabaseException { - super(resource); - StructuralResource2 sr = StructuralResource2.getInstance(g); - this.content = g.getPossibleObject(resource, sr.IsDefinedBy); - this.instance = instance; - } - - @Override - public Collection getChildren(ReadGraph g) throws DatabaseException { - Collection ret = new ArrayList(3); - ret.add(new Interface(resource, instance, false)); - if(content != null) { - ret.add(new Decorator(g.adapt(content, INode.class)) { - @Override - public String getLabel(ReadGraph g) { - return "Content"; - } - }); - } - for(Resource symbol : g.getObjects(resource, ModelingResources.getInstance(g).ComponentTypeToSymbol)) - ret.add(new Symbol(symbol)); - if(!showFolders) { - ArrayList flatten = new ArrayList(); - for(INode n : ret) - flatten.addAll(n.getChildren(g)); - return flatten; - } - return ret; - } - - @Override - public ImageDescriptor getImage(ReadGraph g) { - return Activator.COMPONENT_TYPE_ICON; - } - - @Override - public String getLabel(ReadGraph g) throws DatabaseException { - Layer0 b = Layer0.getInstance(g); - return g.getPossibleRelatedValue(resource, b.HasName); - } - - @Override - public boolean equals(Object obj) { - if(this == obj) - return true; - if(obj == null) - return false; - if(!getClass().equals(obj.getClass())) - return false; - ComponentType other = (ComponentType)obj; - return resource.equals(other.resource) - && content.equals(other.content) - && (instance == null ? other.instance == null : instance.equals(other.instance)); - } - - @Override - public int hashCode() { - return ((getClass().hashCode()*31 + (instance == null ? 0 : instance.hashCode()))*31 - + content.hashCode())*31 + resource.hashCode(); - } - - @Override - public Modifier getModifier(final Session session, String columnId) { - return new Modifier() { - - @Override - public String getValue() { - Read request = - new Read() { - - @Override - public String perform(ReadGraph graph) throws DatabaseException { - Layer0 b = Layer0.getInstance(graph); - String name = graph.getPossibleRelatedValue(resource, b.HasName); - return name != null ? name : ""; - } - - }; - try { - return session.syncRequest(request); - } catch (DatabaseException e) { - e.printStackTrace(); - return ""; - } - } - - @Override - public String isValid(String label) { - return null; - } - - @Override - public void modify(final String label) { - session.asyncRequest(new WriteRequest() { - @Override - public void perform(WriteGraph graph) throws DatabaseException { - Layer0 b = Layer0.getInstance(graph); - graph.claimLiteral(resource, b.HasName, label); - } - }); - } - - }; - } -} +/******************************************************************************* + * Copyright (c) 2007, 2010 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: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.modeling.ui.modelBrowser.model; + +import java.util.ArrayList; +import java.util.Collection; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.simantics.browsing.ui.common.node.IModifiable; +import org.simantics.browsing.ui.content.Labeler.Modifier; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.request.Read; +import org.simantics.layer0.Layer0; +import org.simantics.modeling.ModelingResources; +import org.simantics.modeling.ui.Activator; +import org.simantics.structural.stubs.StructuralResource2; + +@Deprecated +public class ComponentType extends Node implements IModifiable { + + final static boolean showFolders = true; + + Resource content; + Resource instance; + + public ComponentType(ReadGraph g, Resource resource) throws DatabaseException { + this(g, resource, null); + } + + public ComponentType(ReadGraph g, Resource resource, Resource instance) throws DatabaseException { + super(resource); + StructuralResource2 sr = StructuralResource2.getInstance(g); + this.content = g.getPossibleObject(resource, sr.IsDefinedBy); + this.instance = instance; + } + + @Override + public Collection getChildren(ReadGraph g) throws DatabaseException { + Collection ret = new ArrayList(3); + ret.add(new Interface(resource, instance, false)); + if(content != null) { + ret.add(new Decorator(g.adapt(content, INode.class)) { + @Override + public String getLabel(ReadGraph g) { + return "Content"; + } + }); + } + for(Resource symbol : g.getObjects(resource, ModelingResources.getInstance(g).ComponentTypeToSymbol)) + ret.add(new Symbol(symbol)); + if(!showFolders) { + ArrayList flatten = new ArrayList(); + for(INode n : ret) + flatten.addAll(n.getChildren(g)); + return flatten; + } + return ret; + } + + @Override + public ImageDescriptor getImage(ReadGraph g) { + return Activator.COMPONENT_TYPE_ICON; + } + + @Override + public String getLabel(ReadGraph g) throws DatabaseException { + Layer0 b = Layer0.getInstance(g); + return g.getPossibleRelatedValue(resource, b.HasName); + } + + @Override + public boolean equals(Object obj) { + if(this == obj) + return true; + if(obj == null) + return false; + if(!getClass().equals(obj.getClass())) + return false; + ComponentType other = (ComponentType)obj; + return resource.equals(other.resource) + && content.equals(other.content) + && (instance == null ? other.instance == null : instance.equals(other.instance)); + } + + @Override + public int hashCode() { + return ((getClass().hashCode()*31 + (instance == null ? 0 : instance.hashCode()))*31 + + content.hashCode())*31 + resource.hashCode(); + } + + @Override + public Modifier getModifier(final Session session, String columnId) { + return new Modifier() { + + @Override + public String getValue() { + Read request = + new Read() { + + @Override + public String perform(ReadGraph graph) throws DatabaseException { + Layer0 b = Layer0.getInstance(graph); + String name = graph.getPossibleRelatedValue(resource, b.HasName); + return name != null ? name : ""; + } + + }; + try { + return session.syncRequest(request); + } catch (DatabaseException e) { + e.printStackTrace(); + return ""; + } + } + + @Override + public String isValid(String label) { + return null; + } + + @Override + public void modify(final String label) { + session.asyncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Layer0 b = Layer0.getInstance(graph); + graph.claimLiteral(resource, b.HasName, label); + } + }); + } + + }; + } +}