added layout publishing functionality (to test)
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/vre-management/VREModeler@8677 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
77a14668ae
commit
abb0f1ef3c
|
@ -0,0 +1,69 @@
|
|||
package org.gcube.vremanagement.vremodeler.portallayout;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
||||
import org.gcube.common.core.contexts.GHNContext;
|
||||
import org.gcube.common.core.resources.GCUBEGenericResource;
|
||||
import org.gcube.vremanagement.vremodeler.db.DBInterface;
|
||||
import org.gcube.vremanagement.vremodeler.portallayout.util.AbstractTree;
|
||||
import org.gcube.vremanagement.vremodeler.portallayout.util.TreeLeaf;
|
||||
import org.gcube.vremanagement.vremodeler.portallayout.util.TreeNode;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
public class LayoutCreation {
|
||||
|
||||
private TreeNode layoutTree = new TreeNode("Root");
|
||||
private Document doc;
|
||||
private GCUBEGenericResource resource;
|
||||
private String vreId;
|
||||
private String vreName;
|
||||
|
||||
|
||||
private void publish(Document doc) throws Exception{
|
||||
|
||||
}
|
||||
|
||||
|
||||
public LayoutCreation(String vreId, String vreName){
|
||||
try{
|
||||
this.resource= GHNContext.getImplementation(GCUBEGenericResource.class);
|
||||
this.doc= DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
|
||||
this.vreId= vreId;
|
||||
this.vreName= vreName;
|
||||
}catch(Exception e){e.printStackTrace();}
|
||||
}
|
||||
|
||||
public void createAndPublishLayout() throws Exception{
|
||||
doc.appendChild(layoutTree.createElement(doc));
|
||||
publish(doc);
|
||||
}
|
||||
|
||||
public void createTree(){
|
||||
try {
|
||||
ResultSet selectedPortlet= DBInterface.queryDB("select p.name, p.portletclass, p.parent from VRERELATEDFUNCT as vf,PORTLETRELTOFUNCT as pf, PORTLET as p WHERE vf.VRERELATEDFUNCT=pf.FUNCID and pf.PORTLETNAME=p.NAME and vf.VREID='"+this.vreId+"';");
|
||||
while (selectedPortlet.next()){
|
||||
AbstractTree child= new TreeLeaf(selectedPortlet.getString(1), selectedPortlet.getString(2) );
|
||||
String parent= selectedPortlet.getString(3);
|
||||
while(parent!=null){
|
||||
ResultSet parentPortlet= DBInterface.queryDB("select p.name, p.parent from PORTLET as p WHERE p.name='"+parent+"' ;");
|
||||
AbstractTree tempParent= new TreeNode(parentPortlet.getString(1));
|
||||
tempParent.addPathNode(child);
|
||||
child= tempParent;
|
||||
try{
|
||||
parent= parentPortlet.getString(2);
|
||||
}catch(Exception e){parent=null;}
|
||||
}
|
||||
layoutTree.addPathNode(child);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package org.gcube.vremanagement.vremodeler.portallayout.util;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
public abstract class AbstractTree {
|
||||
|
||||
protected List<AbstractTree> childs;
|
||||
|
||||
protected String nodeName;
|
||||
|
||||
protected String portletClass;
|
||||
|
||||
public abstract boolean isLeaf();
|
||||
|
||||
public abstract void addPathNode(AbstractTree node);
|
||||
|
||||
public abstract String getPortletClass();
|
||||
|
||||
public boolean equals(Object o){
|
||||
AbstractTree n= (AbstractTree) o;
|
||||
return (this.nodeName.compareTo(n.getNodeName())==0);
|
||||
}
|
||||
|
||||
public String getNodeName() {
|
||||
return this.nodeName;
|
||||
}
|
||||
|
||||
public abstract Element createElement(Document doc);
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package org.gcube.vremanagement.vremodeler.portallayout.util;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
public class TreeLeaf extends AbstractTree{
|
||||
|
||||
private String nodeName;
|
||||
private String portletClass;
|
||||
public TreeLeaf(String name, String portletClass){
|
||||
this.nodeName= name;
|
||||
this.portletClass= portletClass;
|
||||
}
|
||||
|
||||
|
||||
public String getPortletClass(){
|
||||
return this.portletClass;
|
||||
}
|
||||
|
||||
public boolean isLeaf(){
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPathNode(AbstractTree node) {}
|
||||
|
||||
|
||||
public Element createElement(Document doc){
|
||||
Element row =doc.createElement("row");
|
||||
row.setAttribute("can-modify", "false");
|
||||
row.setAttribute("label", "");
|
||||
row.setAttribute("required-role", "");
|
||||
row.setAttribute("style", "");
|
||||
row.setAttribute("visible", "true");
|
||||
row.setAttribute("width", "");
|
||||
Element frame = doc.createElement("frame");
|
||||
frame.setAttribute("can-modify", "false");
|
||||
frame.setAttribute("inner-padding", "");
|
||||
frame.setAttribute("label", "");
|
||||
frame.setAttribute("outer-padding", "");
|
||||
frame.setAttribute("required-role", "");
|
||||
frame.setAttribute("style", "");
|
||||
frame.setAttribute("transparent", "true");
|
||||
frame.setAttribute("visible", "true");
|
||||
frame.setAttribute("width", "");
|
||||
Element portlet= doc.createElement("portletClass");
|
||||
portlet.setTextContent(this.getPortletClass());
|
||||
frame.appendChild(portlet);
|
||||
row.appendChild(frame);
|
||||
return row;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
package org.gcube.vremanagement.vremodeler.portallayout.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
public class TreeNode extends AbstractTree{
|
||||
|
||||
|
||||
public TreeNode(String name){
|
||||
this.nodeName= name;
|
||||
this.childs= new ArrayList<AbstractTree>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPathNode(AbstractTree node){
|
||||
if (node.isLeaf()){
|
||||
this.childs.add(node);
|
||||
} else {
|
||||
if (!this.childs.contains(node)) this.childs.add(node);
|
||||
else this.childs.get((this.childs.indexOf(node))).addPathNode(node.childs.get(0));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPortletClass() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLeaf() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Element createElement(Document doc) {
|
||||
Element subRoot;
|
||||
if(this.childs.get(0).isLeaf()){
|
||||
subRoot= doc.createElement("table");
|
||||
subRoot.setAttribute("can-modify", "false");
|
||||
subRoot.setAttribute("label", "");
|
||||
subRoot.setAttribute("required-role", "");
|
||||
subRoot.setAttribute("style", "");
|
||||
subRoot.setAttribute("visible", "true");
|
||||
subRoot.setAttribute("width", "");
|
||||
}else{
|
||||
subRoot= doc.createElement("tabbed-pane");
|
||||
subRoot.setAttribute("can-modify", "false");
|
||||
subRoot.setAttribute("label", "");
|
||||
subRoot.setAttribute("required-role", "");
|
||||
subRoot.setAttribute("style", "sub-menu");
|
||||
subRoot.setAttribute("visible", "true");
|
||||
subRoot.setAttribute("width", "");
|
||||
}
|
||||
|
||||
for (AbstractTree t:this.childs){
|
||||
subRoot.appendChild(t.createElement(doc));
|
||||
}
|
||||
|
||||
Element tab= doc.createElement("tab");
|
||||
tab.setAttribute("align", "left");
|
||||
tab.setAttribute("can-modify", "false");
|
||||
tab.setAttribute("label", "");
|
||||
tab.setAttribute("order", "50");
|
||||
tab.setAttribute("outline", "true");
|
||||
tab.setAttribute("required-role", "");
|
||||
tab.setAttribute("style", "");
|
||||
tab.setAttribute("visible", "true");
|
||||
tab.setAttribute("width", "");
|
||||
if (this.getNodeName().compareTo("Root")!=0){
|
||||
Element title= doc.createElement("title");
|
||||
title.setAttribute("lang", "en");
|
||||
title.setTextContent(this.getNodeName());
|
||||
tab.appendChild(title);
|
||||
}
|
||||
tab.appendChild(subRoot);
|
||||
|
||||
return tab;
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue