This commit is contained in:
Francesco Mangiacrapa 2022-07-06 17:47:39 +02:00
parent c1337ab37a
commit 935e0035f1
3 changed files with 130 additions and 39 deletions

View File

@ -738,7 +738,7 @@ public class GeoPortalDataEntryApp implements EntryPoint {
}
TreeItem newSubTree = cloneSubTreeItems(selectedItem);
inorder(newSubTree);
postOrderVisit(newSubTree);
geoNaMainForm.getTreeItemPanel().addChild(selectedItem.getParentItem(), newSubTree);
break;
}
@ -1087,36 +1087,26 @@ public class GeoPortalDataEntryApp implements EntryPoint {
});
}
// Function to print the inorder traversal
// Function to print the postorder traversal
// of the n-ary tree
public void inorder(TreeItem root) {
GWT.log("inorder called");
public void postOrderVisit(TreeItem root) {
// GWT.log("postOrderVisit called");
if (root == null) {
GWT.log("inorder returns, node is null");
// GWT.log("postOrderVisit returns, node is null");
return;
}
GWT.log("inorder called on: " + root.getText());
// GWT.log("postOrderVisit called on: " + root.getText());
// Total children count
int total = root.getChildCount();
for (int i = 0; i < total; i++) {
inorder(root.getChild(i));
postOrderVisit(root.getChild(i));
}
// TreeItem parent = null;
// try {
// // Print the current node's data
// if(root.getParentItem()!=null) {
// parent = root.getParentItem();
// }
// }catch (Exception e) {
// GWT.log("error: "+e.getMessage());
// }
//
String parentText = root.getParentItem()!=null?root.getParentItem().getText():null;
GWT.log("InorderVisit: " + root.getText() + " with parent: "+parentText);
String parentText = root.getParentItem() != null ? root.getParentItem().getText() : null;
GWT.log("PostOrderVisit: " + root.getText() + " with parent: " + parentText);
}
private TreeItem cloneSubTreeItems(TreeItem root) {
@ -1140,10 +1130,10 @@ public class GeoPortalDataEntryApp implements EntryPoint {
// geoNaMainForm.getTreeItemPanel().createAndAddChild(theRootNode.getParentTreeItem(), newNodeFormCard,
// canBeDuplicated, true, theRootNode.getJsonSectionFullPath());
TreeItem newTreeItem = new TreeItem(new NodeItem(root.getParentItem(), newNodeFormCard, canBeDuplicated, true, theRootNode.getJsonSectionFullPath()));
String parentText = root.getParentItem()!=null?root.getParentItem().getText():null;
GWT.log("newTreeItem created: " + newTreeItem.getText() + ", parent is: "+parentText);
TreeItem newTreeItem = new TreeItem(new NodeItem(root.getParentItem(), newNodeFormCard, canBeDuplicated, true,
theRootNode.getJsonSectionFullPath()));
String parentText = root.getParentItem() != null ? root.getParentItem().getText() : null;
GWT.log("newTreeItem created: " + newTreeItem.getText() + ", parent is: " + parentText);
// Total children count
int total = root.getChildCount();

View File

@ -15,6 +15,7 @@
.tree-panel {
padding: 5px;
border: 1px solid #e7e7e7;
min-width: 280px;
}
.tree-panel ul {
@ -28,7 +29,14 @@
.w80 {
width: 80%;
}
.ml5{
.section-toolbar {
width: 100%;
text-align: center;
padding-bottom: 5px;
}
.section-toolbar a {
margin-left: 5px;
}
</ui:style>
@ -37,13 +45,14 @@
<g:HTMLPanel addStyleNames="{style.tree-panel}">
<b:NavList visible=" false " ui:field="navbarTree">
<b:NavHeader>Sections</b:NavHeader>
<b:Button text="Duplicate" addStyleNames="{style.ml5}" ui:field="duplicateSelected"
<g:HTMLPanel addStyleNames="{style.section-toolbar}">
<b:Button text="Duplicate" ui:field="duplicateSelected"
icon="COPY">
</b:Button>
<b:Button text="Delete" addStyleNames="{style.ml5}" ui:field="removeSelected"
<b:Button text="Delete" ui:field="removeSelected"
icon="TRASH">
Delete</b:Button>
</g:HTMLPanel>
</b:NavList>
<g:ScrollPanel ui:field="treePanel">
</g:ScrollPanel>
@ -51,8 +60,7 @@
<g:ScrollPanel ui:field="inputPanel"
addStyleNames="{style.w80}"></g:ScrollPanel>
</g:HTMLPanel>
<!-- <b:TabPanel ui:field="mainTabPanel" tabPosition="left">
</b:TabPanel> -->
<!-- <b:TabPanel ui:field="mainTabPanel" tabPosition="left"> </b:TabPanel> -->
<b:AlertBlock type="DEFAULT" visible="false"
close="false" ui:field="alertFormAction"></b:AlertBlock>
<b:FormActions ui:field="formActions" visible="false">

View File

@ -0,0 +1,93 @@
package org.gcube.portlets.user.geoportaldataentry.shared;
import java.util.ArrayList;
import java.util.List;
/**
* The Class TNode.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Jul 6, 2022
* @param <T> the generic type
*/
public class TNode<T> {
private T data;
private List<TNode<T>> children;
private TNode<T> parent;
/**
* Instantiates a new node.
*
* @param data the data
*/
public TNode(T data) {
this.data = data;
this.children = new ArrayList<TNode<T>>();
}
/**
* Instantiates a new node.
*
* @param node the node
*/
public TNode(TNode<T> node) {
this.data = (T) node.getData();
children = new ArrayList<TNode<T>>();
}
/**
* Adds the child.
*
* @param child the child
*/
public void addChild(TNode<T> child) {
child.setParent(this);
children.add(child);
}
/**
* Gets the data.
*
* @return the data
*/
public T getData() {
return this.data;
}
/**
* Sets the data.
*
* @param data the new data
*/
public void setData(T data) {
this.data = data;
}
/**
* Gets the parent.
*
* @return the parent
*/
public TNode<T> getParent() {
return this.parent;
}
/**
* Sets the parent.
*
* @param parent the new parent
*/
public void setParent(TNode<T> parent) {
this.parent = parent;
}
/**
* Gets the children.
*
* @return the children
*/
public List<TNode<T>> getChildren() {
return this.children;
}
}