
eu.agrosense.spi.activity.Model Maven / Gradle / Ivy
The newest version!
/**
* Copyright (C) 2008-2013 LimeTri. All rights reserved.
*
* AgroSense is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* There are special exceptions to the terms and conditions of the GPLv3 as it
* is applied to this software, see the FLOSS License Exception
* .
*
* AgroSense is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* AgroSense. If not, see .
*/
package eu.agrosense.spi.activity;
import eu.agrosense.api.session.Connections;
import eu.agrosense.shared.model.ModelConstants;
import eu.agrosense.shared.model.PM;
import org.opendolphin.core.PresentationModel;
import org.opendolphin.core.client.ClientAttribute;
/**
* Helper class for presentation models
*
*
*
* @author Timon Veenstra
*/
public class Model {
/**
* Useful in bindings when you are not certain the attribute already exists:
*
* JFXBinder.bind(Field.PROP_NAME).of(Model.withAt(model,
* Field.PROP_NAME)).to(AbstractNode.PROP_NAME).of(this);
*
*
* @param model
* @param attributeKey
* @return
*/
public static PresentationModel withAt(PresentationModel model, String attributeKey) {
// Validate.notNull(model);
// Validate.notNull(attributeKey);
if (model.getAt(attributeKey) == null){
//FIXME when value already exist on server side risk of clearing, perhaps fix/catch on server side
ClientAttribute attribute = new ClientAttribute(attributeKey, "");
String uri = PM.getURIString(model);
if (uri != null) attribute.setQualifier(ModelConstants.qualify(uri, attributeKey));
Connections.get().getClientDolphin().addAttributeToModel(model, attribute);
}
return model;
}
/**
*
* @param model
* @param attributeKeys
* @return
*/
public static PresentationModel withAt(PresentationModel model, String... attributeKeys) {
PresentationModel result = model;
for (String att:attributeKeys){
result = Model.withAt(model, att);
}
return result;
}
public static void setValue(PresentationModel model, String propertyName, Object value) {
// ensure the attribute exists first, then set the value:
withAt(model, propertyName).getAt(propertyName).setValue(value);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy