X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.browsing.ui.swt%2Fsrc%2Forg%2Fsimantics%2Fbrowsing%2Fui%2Fswt%2Fwidgets%2FVariableStringPropertyFactory.java;h=d98e21952b63ce84783be6f5be8bbfa2fe04d118;hb=70d03af6b040eee42d3461907e9ea2c8ad4cfb77;hp=be8b3827c5c17681b5cc384399feb410384a376e;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/widgets/VariableStringPropertyFactory.java b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/widgets/VariableStringPropertyFactory.java index be8b3827c..d98e21952 100644 --- a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/widgets/VariableStringPropertyFactory.java +++ b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/widgets/VariableStringPropertyFactory.java @@ -1,85 +1,85 @@ -/******************************************************************************* - * Copyright (c) 2007, 2012 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.swt.widgets; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; - -import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl; -import org.simantics.db.ReadGraph; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.layer0.variable.Variable; -import org.simantics.db.layer0.variable.Variables; -import org.simantics.utils.datastructures.Quad; - - -public class VariableStringPropertyFactory extends ReadFactoryImpl { - - final private String format; - final private Collection properties; - - public VariableStringPropertyFactory(String property) { - this.properties = Collections.singleton(property); - this.format = "%1"; - } - - public VariableStringPropertyFactory(String format, String ... properties) { - this.properties = Arrays.asList(properties); - this.format = format; - } - - @Override - public Object getIdentity(Object inputContents) { - return new Quad, Object>((Variable)inputContents, format, properties, getClass()); - } - - public String toString(ReadGraph graph, Variable variable, String property, Object value) throws DatabaseException { -// System.out.println("toString " + value); - if(value == null) { - return "VariableStringPropertyFactory: no value for " + property + " in variable " + variable;//variable.getURI(graph); - } else if(value instanceof Variable) { - String result = ((Variable)value).getPossiblePropertyValue(graph, Variables.NAME); -// System.out.println("toString[Variable] = " + result); - return result; - } else { - return value.toString(); - } - } - - public String toPossibleString(ReadGraph graph, Variable variable, String property, Object value) throws DatabaseException { - if(value == null) return ""; - return toString(graph, variable, property, value); - } - - @Override - public String perform(ReadGraph graph, Variable variable) throws DatabaseException { - - if(variable == null) return ""; - - int index = 1; - String result = format; - for(String property : properties) { -// System.out.println("variablestringpropertyfactory " + property); - Variable target = variable.browsePossible(graph, property); - Object targetValue = target != null ? target.getValue(graph) : null; - String possibleTargetString = toPossibleString(graph, variable, property, targetValue); - result = result.replace("?%" + (index), possibleTargetString); - String targetString = toString(graph, variable, property, targetValue); - result = result.replace("%" + (index), targetString); - index++; - } - return result; - - } - -} +/******************************************************************************* + * Copyright (c) 2007, 2012 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.swt.widgets; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; + +import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl; +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.db.layer0.variable.Variables; +import org.simantics.utils.datastructures.Quad; + + +public class VariableStringPropertyFactory extends ReadFactoryImpl { + + final private String format; + final private Collection properties; + + public VariableStringPropertyFactory(String property) { + this.properties = Collections.singleton(property); + this.format = "%1"; + } + + public VariableStringPropertyFactory(String format, String ... properties) { + this.properties = Arrays.asList(properties); + this.format = format; + } + + @Override + public Object getIdentity(Object inputContents) { + return new Quad, Object>((Variable)inputContents, format, properties, getClass()); + } + + public String toString(ReadGraph graph, Variable variable, String property, Object value) throws DatabaseException { +// System.out.println("toString " + value); + if(value == null) { + return "VariableStringPropertyFactory: no value for " + property + " in variable " + variable;//variable.getURI(graph); + } else if(value instanceof Variable) { + String result = ((Variable)value).getPossiblePropertyValue(graph, Variables.NAME); +// System.out.println("toString[Variable] = " + result); + return result; + } else { + return value.toString(); + } + } + + public String toPossibleString(ReadGraph graph, Variable variable, String property, Object value) throws DatabaseException { + if(value == null) return ""; + return toString(graph, variable, property, value); + } + + @Override + public String perform(ReadGraph graph, Variable variable) throws DatabaseException { + + if(variable == null) return ""; + + int index = 1; + String result = format; + for(String property : properties) { +// System.out.println("variablestringpropertyfactory " + property); + Variable target = variable.browsePossible(graph, property); + Object targetValue = target != null ? target.getValue(graph) : null; + String possibleTargetString = toPossibleString(graph, variable, property, targetValue); + result = result.replace("?%" + (index), possibleTargetString); + String targetString = toString(graph, variable, property, targetValue); + result = result.replace("%" + (index), targetString); + index++; + } + return result; + + } + +}