Package it.eng.spagobi.analiticalmodel.functionalitytree.presentation

Source Code of it.eng.spagobi.analiticalmodel.functionalitytree.presentation.ObjectsMenuHtmlGenerator

/**

SpagoBI - The Business Intelligence Free Platform

Copyright (C) 2005-2008 Engineering Ingegneria Informatica S.p.A.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

**/
package it.eng.spagobi.analiticalmodel.functionalitytree.presentation;

import it.eng.spago.base.RequestContainer;
import it.eng.spagobi.analiticalmodel.document.bo.BIObject;
import it.eng.spagobi.analiticalmodel.document.service.ExecutionWorkspaceModule;
import it.eng.spagobi.analiticalmodel.functionalitytree.bo.LowFunctionality;
import it.eng.spagobi.analiticalmodel.functionalitytree.service.TreeObjectsModule;
import it.eng.spagobi.commons.constants.ObjectsTreeConstants;
import it.eng.spagobi.commons.utilities.ChannelUtilities;
import it.eng.spagobi.commons.utilities.PortletUtilities;
import it.eng.spagobi.commons.utilities.messages.IMessageBuilder;
import it.eng.spagobi.commons.utilities.messages.MessageBuilderFactory;
import it.eng.spagobi.commons.utilities.urls.IUrlBuilder;
import it.eng.spagobi.commons.utilities.urls.UrlBuilderFactory;
import it.eng.spagobi.utilities.themes.ThemesManager;

import java.util.Iterator;
import java.util.List;

import javax.portlet.PortletURL;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.servlet.http.HttpServletRequest;

import org.safehaus.uuid.UUID;
import org.safehaus.uuid.UUIDGenerator;

public class ObjectsMenuHtmlGenerator implements ITreeHtmlGenerator {

  RenderResponse renderResponse = null;
  RenderRequest renderRequest = null;
  HttpServletRequest httpRequest = null;
  RequestContainer reqCont = null;
  protected IUrlBuilder urlBuilder = null;
  private String baseFolderPath = null;
  int progrJSTree = 0;
  private int dTreeRootId = -100;
  private int dTreeObjects = -1000;
  protected String requestIdentity = null;
 
  protected IMessageBuilder msgBuilder = null;
  protected String _bundle = null;
  private String currTheme="";
 
  /* (non-Javadoc)
   * @see it.eng.spagobi.analiticalmodel.functionalitytree.presentation.ITreeHtmlGenerator#makeAccessibleTree(java.util.List, javax.servlet.http.HttpServletRequest, java.lang.String)
   */
  public StringBuffer makeAccessibleTree(List objectsList,
      HttpServletRequest httpRequest, String initialPath) {
    // TODO Auto-generated method stub
    return null;
  }

  /* (non-Javadoc)
   * @see it.eng.spagobi.analiticalmodel.functionalitytree.presentation.ITreeHtmlGenerator#makeTree(java.util.List, javax.servlet.http.HttpServletRequest, java.lang.String, java.lang.String)
   */
  public StringBuffer makeTree(List objectsList,
      HttpServletRequest httpRequest, String initialPath, String treename) {
    return makeTree(objectsList, httpRequest, initialPath);
  }

  private void makeConfigurationDtree(StringBuffer htmlStream) {
    htmlStream.append("<SCRIPT>\n");
    htmlStream.append("    function dTree(objName) {\n");
    htmlStream.append("      this.config = {\n");
    htmlStream.append("        target      : null,\n");
    htmlStream.append("        folderLinks    : true,\n");
    htmlStream.append("        useSelection  : true,\n");
    htmlStream.append("        useCookies    : true,\n");
    htmlStream.append("        useLines    : true,\n");
    htmlStream.append("        useIcons    : true,\n");
    htmlStream.append("        useStatusText  : true,\n");
    htmlStream.append("        closeSameLevel  : false,\n");
    htmlStream.append("        inOrder      : false\n");
    htmlStream.append("      }\n");
    htmlStream.append("      this.icon = {\n");
    htmlStream.append("        root    : '"+PortletUtilities.createPortletURLForResource(httpRequest, "/img/treebase.gif")+"',\n");
    htmlStream.append("        folder    : '"+PortletUtilities.createPortletURLForResource(httpRequest, "/img/treefolder.gif")+"',\n");
    htmlStream.append("        folderOpen  : '"+PortletUtilities.createPortletURLForResource(httpRequest, "/img/treefolderopen.gif")+"',\n");
    htmlStream.append("        node    : '"+PortletUtilities.createPortletURLForResource(httpRequest, "/img/treepage.gif")+"',\n");
    htmlStream.append("        empty    : '"+PortletUtilities.createPortletURLForResource(httpRequest, "/img/treeempty.gif")+"',\n");
    htmlStream.append("        line    : '"+PortletUtilities.createPortletURLForResource(httpRequest, "/img/treeline.gif")+"',\n");
    htmlStream.append("        join    : '"+PortletUtilities.createPortletURLForResource(httpRequest, "/img/treejoin.gif")+"',\n");
    htmlStream.append("        joinBottom  : '"+PortletUtilities.createPortletURLForResource(httpRequest, "/img/treejoinbottom.gif")+"',\n");
    htmlStream.append("        plus    : '"+PortletUtilities.createPortletURLForResource(httpRequest, "/img/treeplus.gif")+"',\n");
    htmlStream.append("        plusBottom  : '"+PortletUtilities.createPortletURLForResource(httpRequest, "/img/treeplusbottom.gif")+"',\n");
    htmlStream.append("        minus    : '"+PortletUtilities.createPortletURLForResource(httpRequest, "/img/treeminus.gif")+"',\n");
    htmlStream.append("        minusBottom  : '"+PortletUtilities.createPortletURLForResource(httpRequest, "/img/treeminusbottom.gif")+"',\n");
    htmlStream.append("        nlPlus    : '"+PortletUtilities.createPortletURLForResource(httpRequest, "/img/treenolines_plus.gif")+"',\n");
    htmlStream.append("        nlMinus    : '"+PortletUtilities.createPortletURLForResource(httpRequest, "/img/treenolines_minus.gif")+"'\n");
    htmlStream.append("      };\n");
    htmlStream.append("      this.obj = objName;\n");
    htmlStream.append("      this.aNodes = [];\n");
    htmlStream.append("      this.aIndent = [];\n");
    htmlStream.append("      this.root = new Node(-1);\n");
    htmlStream.append("      this.selectedNode = null;\n");
    htmlStream.append("      this.selectedFound = false;\n");
    htmlStream.append("      this.completed = false;\n");
    htmlStream.append("    };\n");   
    htmlStream.append("</SCRIPT>\n");
  }
 
  /* (non-Javadoc)
   * @see it.eng.spagobi.analiticalmodel.functionalitytree.presentation.ITreeHtmlGenerator#makeTree(java.util.List, javax.servlet.http.HttpServletRequest, java.lang.String)
   */
  public StringBuffer makeTree(List objectsList, HttpServletRequest httpReq, String initialPath) {
   
    // identity string for object of the page
   
    msgBuilder = MessageBuilderFactory.getMessageBuilder();
    if (_bundle == null)
      _bundle = "messages";
   
      UUIDGenerator uuidGen  = UUIDGenerator.getInstance();
      UUID uuid = uuidGen.generateTimeBasedUUID();
      requestIdentity = uuid.toString();
      requestIdentity = requestIdentity.replaceAll("-", "");
    httpRequest = httpReq;
    baseFolderPath = initialPath;
    urlBuilder = UrlBuilderFactory.getUrlBuilder();
    reqCont = ChannelUtilities.getRequestContainer(httpRequest);
    renderResponse =(RenderResponse)httpRequest.getAttribute("javax.portlet.response");
    renderRequest = (RenderRequest)httpRequest.getAttribute("javax.portlet.request")
    StringBuffer htmlStream = new StringBuffer();
      currTheme=ThemesManager.getCurrentTheme(reqCont);
      if(currTheme==null)currTheme=ThemesManager.getDefaultTheme();
   
    htmlStream.append("<LINK rel='StyleSheet' href='"+urlBuilder.getResourceLinkByTheme(httpRequest, "/css/dtree.css", currTheme )+"' type='text/css' />");
   
   
    makeConfigurationDtree(htmlStream);
   
    //String nameTree = PortletUtilities.getMessage("tree.objectstree.name" ,"messages");
    String nameTree = msgBuilder.getMessage("tree.objectstree.name" ,_bundle, httpRequest);   
   
    htmlStream.append("<SCRIPT language='JavaScript' src='"+renderResponse.encodeURL(renderRequest.getContextPath() + "/js/dtree.js" )+"'></SCRIPT>");
    htmlStream.append("<div id='divmenu' style='position:absolute;left:0;top:0;display:none;width:80px;height:120px;background-color:#FFFFCC;border-color:black;border-style:solid;border-weight:1;' onmouseout='hideMenu();' >");
    htmlStream.append("    menu");
    htmlStream.append("</div>");
    htmlStream.append("<table width='100%'>");
    htmlStream.append("  <tr height='1px'>");
    htmlStream.append("    <td width='10px'>&nbsp;</td>");
    htmlStream.append("    <td>&nbsp;</td>");
    htmlStream.append("  </tr>");
    htmlStream.append("  <tr>");
    htmlStream.append("    <td>&nbsp;</td>");
    htmlStream.append("    <td id='treeMenuObjTd" + requestIdentity + "' name='treeMenuObjTd" + requestIdentity + "'>&nbsp;</td>");
    htmlStream.append("      <script language=\"JavaScript1.2\">\n");
       htmlStream.append("        var nameTree = 'treeExecObj';\n");
    /*String context=httpRequest.getContextPath();
    if (!(context.charAt(context.length() - 1) == '/')) {
      context += '/';
    }    */  
       htmlStream.append("        treeExecObj = new dTree('treeExecObj');\n");
       htmlStream.append("            treeExecObj.add(" + dTreeRootId + ",-1,'"+nameTree+"');\n");
       Iterator it = objectsList.iterator();
       while (it.hasNext()) {
         LowFunctionality folder = (LowFunctionality) it.next();
         if (initialPath != null) {
           if (initialPath.equalsIgnoreCase(folder.getPath())) addItemForJSTree(htmlStream, folder, true);
           else addItemForJSTree(htmlStream, folder, false);
         } else {
           if (folder.getParentId() == null) addItemForJSTree(htmlStream, folder, true);
           else addItemForJSTree(htmlStream, folder, false);
         }
       }
      //htmlStream.append("        document.write(treeExecObj);\n");
       htmlStream.append("        document.getElementById('treeMenuObjTd" + requestIdentity + "').innerHTML = treeExecObj;\n");
      makeJSFunctionForMenu(htmlStream)
    htmlStream.append("      </script>\n");
    htmlStream.append("  </tr>");
    htmlStream.append("</table>");
    htmlStream.append("<br/>");
    return htmlStream;
  }

  private void addItemForJSTree(StringBuffer htmlStream, LowFunctionality folder, boolean isRoot) {
   
    String nameLabel = folder.getName();
    //String name = PortletUtilities.getMessage(nameLabel, "messages");
    String name = msgBuilder.getMessage(nameLabel, _bundle, httpRequest);

    Integer idFolder = folder.getId();
    Integer parentId = folder.getParentId();
    String imgFolder = PortletUtilities.createPortletURLForResource(httpRequest, "/img/treefolder.gif");
    String imgFolderOp = PortletUtilities.createPortletURLForResource(httpRequest, "/img/treefolderopen.gif");
    if (isRoot) {
      htmlStream.append("  treeExecObj.add(" + idFolder + ", " + dTreeRootId + ",'" + name + "', '', '', '', '', '', 'true');\n");
    } else {
      htmlStream.append("  treeExecObj.add(" + idFolder + ", " + parentId + ",'" + name + "', '', '', '', '" + imgFolder + "', '" + imgFolderOp + "', '', '');\n");
    }
    List objects = folder.getBiObjects();
    for (Iterator it = objects.iterator(); it.hasNext(); ) {
      BIObject obj = (BIObject) it.next();
      //insert the correct image for each BI Object type
      String biObjType = obj.getBiObjectTypeCode();
      String imgUrl = "/img/objecticon_"+ biObjType+ ".png";
      String userIcon = PortletUtilities.createPortletURLForResource(httpRequest, imgUrl);
      //String userIconTest = PortletUtilities.createPortletURLForResource(httpRequest, "/img/objecticontest.gif");
      PortletURL execUrl = renderResponse.createActionURL();
      execUrl.setParameter(ObjectsTreeConstants.PAGE, ExecutionWorkspaceModule.MODULE_PAGE);
      execUrl.setParameter(ObjectsTreeConstants.OBJECT_LABEL, obj.getLabel());
      execUrl.setParameter(TreeObjectsModule.PATH_SUBTREE, baseFolderPath);
      htmlStream.append("  treeExecObj.add(" + dTreeObjects-- + ", " + idFolder + ",'" + obj.getName() + "', '" + execUrl.toString() + "', '', '', '" + userIcon + "', '', '', '' );\n");
    }
  }
 
  private void makeJSFunctionForMenu(StringBuffer htmlStream) {
    htmlStream.append("    function linkEmpty() {\n");
    htmlStream.append("    }\n");
  }
 
}
TOP

Related Classes of it.eng.spagobi.analiticalmodel.functionalitytree.presentation.ObjectsMenuHtmlGenerator

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.