use of org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode in project scout.rt by eclipse.
the class JsonOutlineTable method tableRowToJson.
@Override
protected JSONObject tableRowToJson(ITableRow row) {
JSONObject json = super.tableRowToJson(row);
ITreeNode treeNode = m_page.getTreeNodeFor(row);
JsonOutline<IOutline> jsonOutline = getGlobalAdapter(m_page.getOutline());
String nodeId = jsonOutline.getOrCreateNodeId(treeNode);
putProperty(json, "nodeId", nodeId);
return json;
}
use of org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode in project scout.rt by eclipse.
the class TreeContextMenu method calculateEnableState.
/**
* @param ownerSelection
*/
protected void calculateEnableState(Collection<? extends ITreeNode> ownerSelection) {
boolean enabled = true;
for (ITreeNode node : ownerSelection) {
if (!node.isEnabled()) {
enabled = false;
break;
}
}
final boolean inheritedEnability = enabled;
acceptVisitor(new IActionVisitor() {
@Override
public int visit(IAction action) {
if (action instanceof IMenu) {
IMenu menu = (IMenu) action;
if (!menu.hasChildActions() && menu.isInheritAccessibility()) {
menu.setEnabledInheritAccessibility(inheritedEnability);
}
}
return CONTINUE;
}
});
}
use of org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode 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.client.ui.basic.tree.ITreeNode 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.client.ui.basic.tree.ITreeNode in project scout.rt by eclipse.
the class AbstractComposerField method execMarkSaved.
@Override
protected void execMarkSaved() {
try {
m_tree.setTreeChanging(true);
//
ITreeVisitor v = new ITreeVisitor() {
@Override
public boolean visit(ITreeNode node) {
if (!node.isStatusNonchanged()) {
node.setStatusInternal(ITreeNode.STATUS_NON_CHANGED);
m_tree.updateNode(node);
}
return true;
}
};
m_tree.visitNode(m_tree.getRootNode(), v);
m_tree.clearDeletedNodes();
updateInitialValue();
} finally {
m_tree.setTreeChanging(false);
}
}
Aggregations