use of org.openforis.collect.designer.component.SchemaTreeModel.SchemaNodeData in project collect by openforis.
the class SchemaVM method openMoveNodePopup.
@Command
public void openMoveNodePopup() {
SchemaNodeData selectedTreeNode = getSelectedTreeNode();
if (selectedTreeNode == null) {
return;
}
SurveyObject selectedItem = selectedTreeNode.getSurveyObject();
if (selectedItem instanceof NodeDefinition) {
NodeDefinition selectedNode = (NodeDefinition) selectedItem;
boolean changeParentNodeAllowed = checkChangeParentNodeAllowed(selectedNode);
if (changeParentNodeAllowed) {
openSelectParentNodePopupForReparent(selectedNode);
}
} else {
// TODO support tab moving
return;
}
}
use of org.openforis.collect.designer.component.SchemaTreeModel.SchemaNodeData in project collect by openforis.
the class SchemaVM method openDuplicateNodePopup.
@Command
public void openDuplicateNodePopup() {
if (!checkCanLeaveForm()) {
return;
}
SchemaNodeData selectedTreeNode = getSelectedTreeNode();
if (selectedTreeNode == null) {
return;
}
SurveyObject selectedItem = selectedTreeNode.getSurveyObject();
if (selectedItem instanceof NodeDefinition) {
openSelectParentNodePopupForDuplicate((NodeDefinition) selectedItem);
}
}
use of org.openforis.collect.designer.component.SchemaTreeModel.SchemaNodeData in project collect by openforis.
the class SchemaVM method updateTreeNodeIcon.
private void updateTreeNodeIcon(SurveyObject item, boolean key, boolean calculated) {
Treeitem treeItem = getTreeItem(item);
if (treeItem != null) {
SchemaNodeData data = treeModel.getNodeData(item);
String icon = getIcon(data, key, calculated);
treeItem.setImage(icon);
}
}
use of org.openforis.collect.designer.component.SchemaTreeModel.SchemaNodeData in project collect by openforis.
the class SchemaVM method openSelectParentNodePopupForReparent.
private void openSelectParentNodePopupForReparent(final NodeDefinition selectedItem) {
UIOptions uiOptions = survey.getUIOptions();
final Set<UITab> assignableTabs = new HashSet<UITab>(uiOptions.getAssignableTabs(editedNodeParentEntity, selectedItem));
final EntityDefinition selectedItemParentDefn = selectedItem.getParentEntityDefinition();
UITab inheritedTab = uiOptions.getAssignedTab(selectedItemParentDefn);
assignableTabs.add(inheritedTab);
Predicate<SurveyObject> includedNodePredicate = new Predicate<SurveyObject>() {
public boolean evaluate(SurveyObject item) {
if (item instanceof UITab) {
return true;
} else if (item instanceof NodeDefinition) {
if (item instanceof EntityDefinition) {
EntityDefinition entityItemDef = (EntityDefinition) item;
if (entityItemDef.isVirtual()) {
return false;
} else if (selectedItem instanceof EntityDefinition && entityItemDef.isDescendantOf((EntityDefinition) selectedItem)) {
return false;
} else {
return true;
}
} else {
return false;
}
} else {
return false;
}
}
};
Predicate<SurveyObject> disabledPredicate = new Predicate<SurveyObject>() {
@Override
public boolean evaluate(SurveyObject item) {
if (item instanceof UITab) {
return survey.isPublished() && !assignableTabs.contains(item);
} else if (item instanceof NodeDefinition) {
NodeDefinition itemNodeDef = (NodeDefinition) item;
if (itemNodeDef.equals(selectedItemParentDefn)) {
return false;
} else if (selectedItem instanceof EntityDefinition && itemNodeDef.isDescendantOf((EntityDefinition) selectedItem)) {
// is descendant of the selected item
return true;
} else if (!survey.isPublished() && itemNodeDef instanceof EntityDefinition && !itemNodeDef.equals(selectedItem)) {
// published
return false;
} else {
return true;
}
} else {
// do not allow selecting non-node definitions
return true;
}
}
};
String nodeName = editedNode instanceof NodeDefinition ? ((NodeDefinition) editedNode).getName() : "";
UITab assignedTab = survey.getUIOptions().getAssignedTab((NodeDefinition) editedNode);
String assignedTabLabel = assignedTab.getLabel(currentLanguageCode);
String title = Labels.getLabel("survey.schema.move_node_popup_title", new String[] { getNodeTypeHeaderLabel(), nodeName, assignedTabLabel });
// calculate parent item (tab or entity)
SchemaTreeNode treeNode = treeModel.getTreeNode(selectedItem);
TreeNode<SchemaNodeData> parentTreeNode = treeNode.getParent();
SurveyObject parentItem = parentTreeNode.getData().getSurveyObject();
final Window popup = SchemaTreePopUpVM.openPopup(title, selectedRootEntity, null, includedNodePredicate, false, true, disabledPredicate, null, parentItem, false);
popup.addEventListener(SchemaTreePopUpVM.NODE_SELECTED_EVENT_NAME, new EventListener<NodeSelectedEvent>() {
public void onEvent(NodeSelectedEvent event) throws Exception {
SurveyObject selectedParent = event.getSelectedItem();
changeEditedNodeParent(selectedParent, false);
refreshNodeForm();
closePopUp(popup);
}
});
}
use of org.openforis.collect.designer.component.SchemaTreeModel.SchemaNodeData in project collect by openforis.
the class SurveyObjectTreeModelCreator method createNode.
public AbstractNode<SchemaNodeData> createNode(SchemaNodeData data, boolean defineEmptyChildrenForLeaves) {
SchemaTreeNode node = null;
SurveyObject surveyObject = data.getSurveyObject();
if (includeNodePredicate == null || includeNodePredicate.evaluate(surveyObject)) {
List<AbstractNode<SchemaNodeData>> childNodes = createChildNodes(surveyObject);
// create result
if (childNodes == null) {
node = new SchemaTreeNode(data);
} else if (childNodes.isEmpty()) {
if (includeEmptyNodes) {
if (defineEmptyChildrenForLeaves) {
node = new SchemaTreeNode(data, Collections.<AbstractNode<SchemaNodeData>>emptyList());
} else {
node = new SchemaTreeNode(data);
}
} else {
node = null;
}
} else {
node = new SchemaTreeNode(data, (List<AbstractNode<SchemaNodeData>>) childNodes);
}
}
if (node != null && disabledNodePredicate != null) {
if (disabledNodePredicate.evaluate(surveyObject)) {
node.setDisabled(true);
}
}
return node;
}
Aggregations