X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.browsing.ui.model%2Fsrc%2Forg%2Fsimantics%2Fbrowsing%2Fui%2Fmodel%2Fmodifiers%2FStringPropertyModifierRule.java;h=78afae84c95a80e6f83e2dd3c8ceb917e41e81e6;hp=530c97ea8d9e76d293cb451a22f309e3aada3f29;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/modifiers/StringPropertyModifierRule.java b/bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/modifiers/StringPropertyModifierRule.java index 530c97ea8..78afae84c 100644 --- a/bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/modifiers/StringPropertyModifierRule.java +++ b/bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/modifiers/StringPropertyModifierRule.java @@ -1,91 +1,91 @@ -/******************************************************************************* - * Copyright (c) 2007, 2011 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.browsing.ui.model.modifiers; - -import org.simantics.browsing.ui.common.ColumnKeys; -import org.simantics.browsing.ui.common.ErrorLogger; -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.Statement; -import org.simantics.db.WriteGraph; -import org.simantics.db.common.request.WriteRequest; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.layer0.adapter.StringModifier; -import org.simantics.db.layer0.adapter.StringModifierFactory; -import org.simantics.db.layer0.util.Layer0Utils; - -/** - * @author Tuukka Lehtonen - */ -public class StringPropertyModifierRule implements ModifierRule { - - private Resource propertyRelation; - - public StringPropertyModifierRule(ReadGraph graph, String propertyRelationURI) throws DatabaseException { - this.propertyRelation = graph.getResource(propertyRelationURI); - } - - @Override - public boolean isCompatible(Class contentType) { - return contentType.equals(Resource.class); - } - - @Override - public Modifier getModifier(ReadGraph graph, Object content, - String columnKey) throws DatabaseException { - if(!ColumnKeys.SINGLE.equals(columnKey)) - return null; - if(!(content instanceof Resource)) - return null; - - Resource resource = (Resource)content; - final Statement nameStm = graph.getPossibleStatement(resource, propertyRelation); - if (nameStm == null) - return null; - - StringModifierFactory smf = graph.getPossibleAdapter(resource, StringModifierFactory.class); - if (smf != null) { - final StringModifier sm = smf.createModifier(graph, propertyRelation, nameStm.getObject()); - if (sm != null) - return modifierFor(graph.getSession(), sm, nameStm.getObject()); - } - - return new L0StringModifier(graph.getSession(), resource, propertyRelation, nameStm.getObject()); - } - - private Modifier modifierFor(final Session session, final StringModifier sm, final Resource valueResource) { - return new Modifier() { - @Override - public String getValue() { - return sm.getValue(); - } - @Override - public String isValid(String label) { - return sm.isValid(label); - } - @Override - public void modify(final String label) { - session.asyncRequest(new WriteRequest() { - @Override - public void perform(WriteGraph graph) throws DatabaseException { - Layer0Utils.addCommentMetadata(graph, "Modify string"); - graph.markUndoPoint(); - sm.modify(graph, label); - } - }, e -> { if (e != null) ErrorLogger.defaultLogError(e); }); - } - }; - } - -} +/******************************************************************************* + * Copyright (c) 2007, 2011 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.browsing.ui.model.modifiers; + +import org.simantics.browsing.ui.common.ColumnKeys; +import org.simantics.browsing.ui.common.ErrorLogger; +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.Statement; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.adapter.StringModifier; +import org.simantics.db.layer0.adapter.StringModifierFactory; +import org.simantics.db.layer0.util.Layer0Utils; + +/** + * @author Tuukka Lehtonen + */ +public class StringPropertyModifierRule implements ModifierRule { + + private Resource propertyRelation; + + public StringPropertyModifierRule(ReadGraph graph, String propertyRelationURI) throws DatabaseException { + this.propertyRelation = graph.getResource(propertyRelationURI); + } + + @Override + public boolean isCompatible(Class contentType) { + return contentType.equals(Resource.class); + } + + @Override + public Modifier getModifier(ReadGraph graph, Object content, + String columnKey) throws DatabaseException { + if(!ColumnKeys.SINGLE.equals(columnKey)) + return null; + if(!(content instanceof Resource)) + return null; + + Resource resource = (Resource)content; + final Statement nameStm = graph.getPossibleStatement(resource, propertyRelation); + if (nameStm == null) + return null; + + StringModifierFactory smf = graph.getPossibleAdapter(resource, StringModifierFactory.class); + if (smf != null) { + final StringModifier sm = smf.createModifier(graph, propertyRelation, nameStm.getObject()); + if (sm != null) + return modifierFor(graph.getSession(), sm, nameStm.getObject()); + } + + return new L0StringModifier(graph.getSession(), resource, propertyRelation, nameStm.getObject()); + } + + private Modifier modifierFor(final Session session, final StringModifier sm, final Resource valueResource) { + return new Modifier() { + @Override + public String getValue() { + return sm.getValue(); + } + @Override + public String isValid(String label) { + return sm.isValid(label); + } + @Override + public void modify(final String label) { + session.asyncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Layer0Utils.addCommentMetadata(graph, "Modify string"); + graph.markUndoPoint(); + sm.modify(graph, label); + } + }, e -> { if (e != null) ErrorLogger.defaultLogError(e); }); + } + }; + } + +}