use of org.eclipse.scout.rt.shared.data.model.IDataModelAttributeOp in project scout.rt by eclipse.
the class AbstractDataModelOperatorField method setAttribute.
public void setAttribute(IDataModelAttribute attribute) {
IDataModelAttributeOp oldOp = getValue();
((DataModelOperatorLookupCall) getLookupCall()).setAttribute(attribute);
IDataModelAttributeOp newOp = null;
if (attribute != null) {
setView(true, true, false);
HashSet<IDataModelAttributeOp> tmp = new HashSet<IDataModelAttributeOp>();
List<IDataModelAttributeOp> ops = attribute.getOperators();
tmp.addAll(ops);
if (tmp.contains(oldOp)) {
newOp = oldOp;
} else {
newOp = CollectionUtility.firstElement(ops);
}
} else {
setView(false, false, false);
}
setValue(newOp);
}
use of org.eclipse.scout.rt.shared.data.model.IDataModelAttributeOp in project scout.rt by eclipse.
the class AbstractComposerField method loadXMLRec.
private void loadXMLRec(Element x, ITreeNode parent) {
// build tree
for (Element xmlElem : XmlUtility.getChildElements(x)) {
if ("attribute".equals(xmlElem.getTagName())) {
String id = xmlElem.getAttribute("id");
IDataModelAttributeOp op;
Integer aggregationType = 0;
try {
int operator = DataModelConstants.OPERATOR_EQ;
String opAttribName = "op";
if (xmlElem.hasAttribute(opAttribName)) {
operator = Integer.parseInt(xmlElem.getAttribute(opAttribName));
}
op = DataModelAttributeOp.create(operator);
String aggregTypeName = "aggregationType";
if (xmlElem.hasAttribute(aggregTypeName)) {
aggregationType = Integer.parseInt(xmlElem.getAttribute(aggregTypeName));
}
if (aggregationType == 0) {
aggregationType = null;
}
} catch (Exception e) {
LOG.warn("read op", e);
continue;
}
ArrayList<Object> valueList = new ArrayList<Object>();
try {
for (int i = 1; i <= 5; i++) {
String valueName = (i == 1 ? "value" : "value" + i);
if (xmlElem.hasAttribute(valueName)) {
valueList.add(XmlUtility.getObjectAttribute(xmlElem, valueName));
}
}
} catch (Exception e) {
LOG.warn("read value for attribute {}", id, e);
continue;
}
ArrayList<String> displayValueList = new ArrayList<String>();
for (int i = 1; i <= 5; i++) {
String displayValueName = (i == 1 ? "displayValue" : "displayValue" + i);
if (xmlElem.hasAttribute(displayValueName)) {
String val = null;
if (xmlElem.hasAttribute(displayValueName)) {
val = xmlElem.getAttribute(displayValueName);
}
displayValueList.add(val);
}
}
// find definition
AttributePath attPath = DataModelUtility.externalIdToAttributePath(getDataModel(), id);
IDataModelAttribute foundAtt = (attPath != null ? attPath.getAttribute() : null);
if (foundAtt == null) {
LOG.warn("cannot find attribute with id={}", id);
continue;
}
ITreeNode node = addAttributeNode(parent, foundAtt, aggregationType, op, valueList, displayValueList);
if (node != null) {
// add children recursive
loadXMLRec(xmlElem, node);
}
} else if ("entity".equals(xmlElem.getTagName())) {
String id = xmlElem.getAttribute("id");
boolean negated = Boolean.parseBoolean(xmlElem.getAttribute("negated"));
String text = null;
if (xmlElem.hasAttribute("displayValues")) {
text = xmlElem.getAttribute("displayValues");
}
// find definition
EntityPath entityPath = DataModelUtility.externalIdToEntityPath(getDataModel(), id);
IDataModelEntity foundEntity = (entityPath != null ? entityPath.lastElement() : null);
if (foundEntity == null) {
LOG.warn("cannot find entity with id={}", id);
continue;
}
ITreeNode node = addEntityNode(parent, foundEntity, negated, null, text != null ? Collections.singletonList(text) : null);
if (node != null) {
// add children recursive
loadXMLRec(xmlElem, node);
}
} else if ("or".equals(xmlElem.getTagName())) {
boolean beginning = Boolean.parseBoolean(xmlElem.getAttribute("begin"));
boolean negated = Boolean.parseBoolean(xmlElem.getAttribute("negated"));
ITreeNode node = null;
if (beginning) {
node = addEitherNode(parent, negated);
} else {
// find last EitherOrNode
EitherOrNode orNode = null;
for (ITreeNode n : parent.getChildNodes()) {
if (n instanceof EitherOrNode && ((EitherOrNode) n).isEndOfEitherOr()) {
orNode = (EitherOrNode) n;
}
}
if (orNode != null) {
node = addAdditionalOrNode(orNode, negated);
}
}
if (node != null) {
// add children recursive
loadXMLRec(xmlElem, node);
}
}
}
}
use of org.eclipse.scout.rt.shared.data.model.IDataModelAttributeOp in project scout.rt by eclipse.
the class AbstractComposerField method storeXMLRec.
private void storeXMLRec(Element x, ITreeNode parent) {
for (ITreeNode node : parent.getChildNodes()) {
if (node instanceof EntityNode) {
EntityNode entityNode = (EntityNode) node;
Element xEntity = x.getOwnerDocument().createElement("entity");
xEntity.setAttribute("id", DataModelUtility.entityPathToExternalId(getDataModel(), interceptResolveEntityPath(entityNode)));
xEntity.setAttribute("negated", (entityNode.isNegative() ? "true" : "false"));
List<String> texts = entityNode.getTexts();
xEntity.setAttribute("displayValues", CollectionUtility.hasElements(texts) ? StringUtility.emptyIfNull(CollectionUtility.firstElement(texts)) : null);
x.appendChild(xEntity);
// recursion
storeXMLRec(xEntity, node);
} else if (node instanceof AttributeNode) {
AttributeNode attNode = (AttributeNode) node;
Element xAtt = x.getOwnerDocument().createElement("attribute");
xAtt.setAttribute("id", DataModelUtility.attributePathToExternalId(getDataModel(), interceptResolveAttributePath(attNode)));
IDataModelAttributeOp op = attNode.getOp();
try {
xAtt.setAttribute("op", op.getOperator() + "");
if (attNode.getAggregationType() != null) {
xAtt.setAttribute("aggregationType", attNode.getAggregationType() + "");
}
} catch (Exception e) {
LOG.warn("write op {}", op, e);
}
List<String> texts = attNode.getTexts();
if (CollectionUtility.hasElements(texts)) {
Iterator<String> it = texts.iterator();
xAtt.setAttribute("displayValue", StringUtility.emptyIfNull(it.next()));
int i = 2;
while (it.hasNext()) {
xAtt.setAttribute(("displayValue" + i), StringUtility.emptyIfNull(it.next()));
i++;
}
}
List<Object> values = attNode.getValues();
if (values != null) {
int i = 0;
for (Object value : values) {
String valueName = (i == 0 ? "value" : "value" + (i + 1));
try {
XmlUtility.setObjectAttribute(xAtt, valueName, value);
} catch (Exception e) {
LOG.warn("write value[{}] for attribute {}: {}", i, attNode.getAttribute(), value, e);
}
i++;
}
}
x.appendChild(xAtt);
} else if (node instanceof EitherOrNode) {
EitherOrNode orNode = (EitherOrNode) node;
Element xOr = x.getOwnerDocument().createElement("or");
xOr.setAttribute("begin", "" + orNode.isBeginOfEitherOr());
xOr.setAttribute("negated", (orNode.isNegative() ? "true" : "false"));
x.appendChild(xOr);
// recursion
storeXMLRec(xOr, node);
}
}
}
use of org.eclipse.scout.rt.shared.data.model.IDataModelAttributeOp in project scout.rt by eclipse.
the class DataModelOperatorLookupCall method execCreateLookupRows.
@Override
protected List<ILookupRow<IDataModelAttributeOp>> execCreateLookupRows() {
List<ILookupRow<IDataModelAttributeOp>> result = new ArrayList<ILookupRow<IDataModelAttributeOp>>();
List<IDataModelAttributeOp> ops = null;
if (m_attribute != null) {
ops = m_attribute.getOperators();
}
if (ops != null) {
for (IDataModelAttributeOp op : ops) {
String text = op.getShortText();
if (text != null && text.indexOf("{0}") >= 0) {
text = text.replace("{0}", "n");
}
if (text != null && text.indexOf("{1}") >= 0) {
text = text.replace("{1}", "m");
}
result.add(new LookupRow<IDataModelAttributeOp>(op, text));
}
}
return result;
}
use of org.eclipse.scout.rt.shared.data.model.IDataModelAttributeOp in project scout.rt by eclipse.
the class ComposerAttributeForm method activateValueField.
/**
* activate value field function
*/
private void activateValueField() {
IDataModelAttribute att = getAttributeField().getCheckedKey();
IDataModelAttributeOp op = getOperatorField().getCheckedKey();
List<Object> newValues = getSelectedValues();
//
if (att == null) {
getValueField().clearSelectionContext();
} else {
getValueField().setSelectionContext(att, op, newValues);
}
}
Aggregations