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%2FL0StringModifier.java;h=43dca273040169fdc903f9c76033a5a1a6272fff;hp=23c19b87d614965e5d6403c49530b082ca89ed2c;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/modifiers/L0StringModifier.java b/bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/modifiers/L0StringModifier.java index 23c19b87d..43dca2730 100644 --- a/bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/modifiers/L0StringModifier.java +++ b/bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/modifiers/L0StringModifier.java @@ -1,97 +1,97 @@ -/******************************************************************************* - * 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.ErrorLogger; -import org.simantics.browsing.ui.content.Labeler.Modifier; -import org.simantics.db.ReadGraph; -import org.simantics.db.RequestProcessor; -import org.simantics.db.Resource; -import org.simantics.db.Statement; -import org.simantics.db.WriteGraph; -import org.simantics.db.common.primitiverequest.PossibleAdapter; -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.util.Layer0Utils; -import org.simantics.db.request.Read; -import org.simantics.layer0.Layer0; - -public class L0StringModifier implements Modifier { - - private final RequestProcessor processor; - private final Resource subject; - private final Resource propertyRelation; - private final Resource literal; - - public L0StringModifier(RequestProcessor processor, Resource subject, Resource propertyRelation, Resource literal) { - this.processor = processor; - this.subject = subject; - this.propertyRelation = propertyRelation; - this.literal = literal; - } - - @Override - public String getValue() { - try { - return processor.syncRequest(new PossibleAdapter(literal, String.class)); - } catch (DatabaseException e) { - ErrorLogger.defaultLogError(e); - return null; - } - } - - @Override - public String isValid(final String label) { - try { - return processor.syncRequest(new Read() { - @Override - public String perform(ReadGraph graph) throws DatabaseException { - StringModifier modifier = graph.adapt(literal, StringModifier.class); - return modifier.isValid(label); - } - }); - } catch (DatabaseException e) { - ErrorLogger.defaultLogError(e); - return e.getMessage(); - } - } - - @Override - public void modify(final String label) { - try { - processor.syncRequest(new WriteRequest() { - @Override - public void perform(WriteGraph graph) throws DatabaseException { - Layer0Utils.addCommentMetadata(graph, "Modify string"); - graph.markUndoPoint(); - Statement stm = graph.getPossibleStatement(subject, propertyRelation); - if (stm.isAsserted(subject)) { - Layer0 L0 = Layer0.getInstance(graph); - Resource newLiteral = graph.newResource(); - for (Resource iof : graph.getObjects(literal, L0.InstanceOf)) - graph.claim(newLiteral, L0.InstanceOf, null, iof); - graph.claim(subject, propertyRelation, newLiteral); - StringModifier modifier = graph.adapt(newLiteral, StringModifier.class); - modifier.modify(graph, label); - } else { - StringModifier modifier = graph.adapt(literal, StringModifier.class); - modifier.modify(graph, label); - } - } - }); - } catch (DatabaseException e) { - 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.ErrorLogger; +import org.simantics.browsing.ui.content.Labeler.Modifier; +import org.simantics.db.ReadGraph; +import org.simantics.db.RequestProcessor; +import org.simantics.db.Resource; +import org.simantics.db.Statement; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.primitiverequest.PossibleAdapter; +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.util.Layer0Utils; +import org.simantics.db.request.Read; +import org.simantics.layer0.Layer0; + +public class L0StringModifier implements Modifier { + + private final RequestProcessor processor; + private final Resource subject; + private final Resource propertyRelation; + private final Resource literal; + + public L0StringModifier(RequestProcessor processor, Resource subject, Resource propertyRelation, Resource literal) { + this.processor = processor; + this.subject = subject; + this.propertyRelation = propertyRelation; + this.literal = literal; + } + + @Override + public String getValue() { + try { + return processor.syncRequest(new PossibleAdapter(literal, String.class)); + } catch (DatabaseException e) { + ErrorLogger.defaultLogError(e); + return null; + } + } + + @Override + public String isValid(final String label) { + try { + return processor.syncRequest(new Read() { + @Override + public String perform(ReadGraph graph) throws DatabaseException { + StringModifier modifier = graph.adapt(literal, StringModifier.class); + return modifier.isValid(label); + } + }); + } catch (DatabaseException e) { + ErrorLogger.defaultLogError(e); + return e.getMessage(); + } + } + + @Override + public void modify(final String label) { + try { + processor.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Layer0Utils.addCommentMetadata(graph, "Modify string"); + graph.markUndoPoint(); + Statement stm = graph.getPossibleStatement(subject, propertyRelation); + if (stm.isAsserted(subject)) { + Layer0 L0 = Layer0.getInstance(graph); + Resource newLiteral = graph.newResource(); + for (Resource iof : graph.getObjects(literal, L0.InstanceOf)) + graph.claim(newLiteral, L0.InstanceOf, null, iof); + graph.claim(subject, propertyRelation, newLiteral); + StringModifier modifier = graph.adapt(newLiteral, StringModifier.class); + modifier.modify(graph, label); + } else { + StringModifier modifier = graph.adapt(literal, StringModifier.class); + modifier.modify(graph, label); + } + } + }); + } catch (DatabaseException e) { + ErrorLogger.defaultLogError(e); + } + } + +}