changeset 29:bba8fd97e549

Export and Diagrammoptions integrated into GUI gnv/trunk@133 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Fri, 25 Sep 2009 07:28:49 +0000
parents d93ea867406b
children 07e9c137a2f1
files gnv/Changelog gnv/src/main/java/de/intevation/gnv/action/ChangeOptionsAction.java gnv/src/main/java/de/intevation/gnv/action/DoExportAction.java gnv/src/main/java/de/intevation/gnv/action/DoOutputAction.java gnv/src/main/java/de/intevation/gnv/action/sessionmodel/DefaultSessionModel.java gnv/src/main/java/de/intevation/gnv/action/sessionmodel/DiagrammOptions.java gnv/src/main/java/de/intevation/gnv/action/sessionmodel/SessionModel.java gnv/src/main/resources/applicationMessages.properties gnv/src/main/webapp/WEB-INF/config/struts-config.xml gnv/src/main/webapp/WEB-INF/jsp/includes/display_diagramm_adons_inc.jsp gnv/src/main/webapp/WEB-INF/jsp/includes/display_diagramm_inc.jsp gnv/src/main/webapp/WEB-INF/jsp/includes/display_diagramm_options_inc.jsp gnv/src/main/webapp/WEB-INF/jsp/includes/display_diagramm_statistics_inc.jsp
diffstat 13 files changed, 315 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/gnv/Changelog	Thu Sep 24 12:43:46 2009 +0000
+++ b/gnv/Changelog	Fri Sep 25 07:28:49 2009 +0000
@@ -1,3 +1,33 @@
+2009-09-25  Tim Englich  <tim.englich@intevation.de>
+
+    * src/main/java/de/intevation/gnv/action/DoOutputAction.java Edited:
+      Some Refactoring work done.
+      Logging Integrated. Extract Method for setting Responseheader Informations.
+      
+    * src/main/java/de/intevation/gnv/action/DoExportAction.java Added:
+      Action for performing the Exports eg. CSV and Chart 
+    * src/main/java/de/intevation/gnv/action/ChangeOptionsAction.java Added:
+      Action for do the Bussinesslogic for storing the Diagrammoptions that were
+      changed by the User. 
+    * src/main/java/de/intevation/gnv/action/sessionmodel/DefaultSessionModel.java Edited, 
+    * src/main/java/de/intevation/gnv/action/sessionmodel/SessionModel.java Edited:
+      Added Accessmethod for the Diagrammoptions.
+       
+    * src/main/java/de/intevation/gnv/action/sessionmodel/DiagrammOptions.java Added:
+      Bean for the Representation of Diagrammoptions
+       
+    * src/main/resources/applicationMessages.properties Edited:
+      Added som GUI Lables.
+       
+    * src/main/webapp/WEB-INF/jsp/includes/display_diagramm_inc.jsp Edited,  
+      src/main/webapp/WEB-INF/jsp/includes/display_diagramm_statistics_inc.jsp Add,
+      src/main/webapp/WEB-INF/jsp/includes/display_diagramm_options_inc.jsp Add,
+      src/main/webapp/WEB-INF/jsp/includes/display_diagramm_adons_inc.jsp Add:
+     Added the GUI for the Statistics and Diagramoptions and tge Export.
+     
+    * src/main/webapp/WEB-INF/config/struts-config.xml Edited:
+      Added Actions for Performing Exports and Changing Diagramoptions. 
+      
 2009-09-24  Tim Englich  <tim.englich@intevation.de>
     * src/main/webapp/scripts/gnviewer.js Edited:
       Removed unused Methods from File.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gnv/src/main/java/de/intevation/gnv/action/ChangeOptionsAction.java	Fri Sep 25 07:28:49 2009 +0000
@@ -0,0 +1,71 @@
+/**
+ *
+ */
+package de.intevation.gnv.action;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.log4j.Logger;
+import org.apache.struts.action.ActionForm;
+import org.apache.struts.action.ActionForward;
+import org.apache.struts.action.ActionMapping;
+import org.w3c.dom.Node;
+
+import de.intevation.gnv.action.sessionmodel.SessionModel;
+import de.intevation.gnv.action.sessionmodel.SessionModelFactory;
+import de.intevation.gnv.artifactdatabase.client.ArtifactDatabaseClient;
+import de.intevation.gnv.artifactdatabase.client.ArtifactDatabaseClientFactory;
+import de.intevation.gnv.artifactdatabase.objects.ArtifactDescription;
+import de.intevation.gnv.util.XMLUtils;
+import de.intevation.gnv.util.XSLTransformer;
+
+/**
+ * @author Tim Englich <tim.englich@intevation.de>
+ *
+ */
+public class ChangeOptionsAction extends ArtifactDatabaseActionBase {
+    /**
+     * the logger, used to log exceptions and additonaly information
+     */
+    private static Logger log = Logger.getLogger(ChangeOptionsAction.class);
+    /**
+     * Constructor
+     */
+    public ChangeOptionsAction() {
+        super();
+    }
+
+    @Override
+    public ActionForward execute(ActionMapping mapping, ActionForm form,
+            HttpServletRequest request, HttpServletResponse response)
+            throws Exception {
+        log.debug("NextArtifactStepAction.execute");
+        SessionModel sm = SessionModelFactory.getInstance().getSessionModel(request);
+        ArtifactDescription ad = (ArtifactDescription)sm.getCurrentArtifact();
+        ArtifactDatabaseClient adc = ArtifactDatabaseClientFactory.getInstance().getArtifactDatabaseClient();
+        
+
+        ArtifactDescription artifactDescription = adc.getCurrentStepDescription(sm.getSelectedArtifactFactory(), sm.getCurrentArtifact());
+        
+        Node currentUI = artifactDescription.getCurrentUI();
+        XSLTransformer transformer = new XSLTransformer();
+        String ui = transformer.transform(new XMLUtils().getNodeXPath(currentUI, "dynamic"), "UTF-8", request.getRealPath("WEB-INF/config/templates/describe-ui.xsl"));
+        
+        request.setAttribute("ui", ui);
+        
+        String staticUI = transformer.transform(new XMLUtils().getNodeXPath(currentUI, "static"), "UTF-8", request.getRealPath("WEB-INF/config/templates/describe-ui-static.xsl"));
+        request.setAttribute("staticui", staticUI);
+        
+        request.setAttribute("furthertargets", (ad.getReachableStates() != null && !ad.getReachableStates().isEmpty()));
+        
+        if (ad.getReachableStates() != null && !ad.getReachableStates().isEmpty()){
+        }else{
+            request.setAttribute("diagramm", true);
+        }
+        return super.execute(mapping, form, request, response);
+    }
+    
+    
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gnv/src/main/java/de/intevation/gnv/action/DoExportAction.java	Fri Sep 25 07:28:49 2009 +0000
@@ -0,0 +1,48 @@
+/**
+ *
+ */
+package de.intevation.gnv.action;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.log4j.Logger;
+
+/**
+ * @author Tim Englich <tim.englich@intevation.de>
+ *
+ */
+public class DoExportAction extends DoOutputAction {
+
+    /**
+     * the logger, used to log exceptions and additonaly information
+     */
+    private static Logger log = Logger.getLogger(DoExportAction.class);
+    
+    /**
+     * Constructor
+     */
+    public DoExportAction() {
+        super();
+    }
+
+    @Override
+    protected void setHeaders(String target, String mimeType,
+            HttpServletResponse response, HttpServletRequest request) {
+        log.debug("DoExportAction.setHeaders");
+        super.setHeaders(target, mimeType, response, request);
+        String fileName = "GNVEXPORT_"+System.currentTimeMillis()+".";
+        
+        if (target.equalsIgnoreCase("chart")){
+            fileName = fileName + mimeType.substring(mimeType.indexOf("/")+1);
+        }else if (target.equalsIgnoreCase("CSV")){
+            fileName = fileName +"csv";
+        }else{
+            fileName = fileName +"txt";
+        }
+        log.debug("FileName for Export: "+fileName);
+        response.setHeader("Content-Disposition","attachment;filename="+fileName);
+    }
+
+    
+}
--- a/gnv/src/main/java/de/intevation/gnv/action/DoOutputAction.java	Thu Sep 24 12:43:46 2009 +0000
+++ b/gnv/src/main/java/de/intevation/gnv/action/DoOutputAction.java	Fri Sep 25 07:28:49 2009 +0000
@@ -11,6 +11,7 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.log4j.Logger;
 import org.apache.struts.action.ActionForm;
 import org.apache.struts.action.ActionForward;
 import org.apache.struts.action.ActionMapping;
@@ -30,6 +31,10 @@
 public class DoOutputAction extends ArtifactDatabaseActionBase {
 
     /**
+     * the logger, used to log exceptions and additonaly information
+     */
+    private static Logger log = Logger.getLogger(DoOutputAction.class);
+    /**
      * Constructor
      */
     public DoOutputAction() {
@@ -44,10 +49,14 @@
     public ActionForward execute(ActionMapping mapping, ActionForm form,
             HttpServletRequest request, HttpServletResponse response)
             throws Exception {
+        log.debug("DoOutputAction.execute");
         String target = request.getParameter("target");
         String mimeType = request.getParameter("mimetype");
         
-        // TODO Check if ist is propper;
+        log.debug("Target: "+target);
+        log.debug("MimeType: "+mimeType);
+        
+        // TODO Check if is propper;
         
         SessionModel sm = SessionModelFactory.getInstance().getSessionModel(request);
         ArtifactDescription ad = (ArtifactDescription)sm.getCurrentArtifact();
@@ -66,7 +75,8 @@
         
         ArtifactDatabaseClient adc = ArtifactDatabaseClientFactory.getInstance().getArtifactDatabaseClient();
         
-        response.setContentType(mimeType);
+        this.setHeaders(target, mimeType, response, request);
+        
         OutputStream outputStream = response.getOutputStream();
         adc.doOutput(sm.getSelectedArtifactFactory(), sm.getCurrentArtifact(), outputStream, target, mimeType, ips);
         
@@ -76,5 +86,9 @@
         return super.execute(mapping, form, request, response);
     }
     
+    protected void setHeaders(String target, String mimeType, HttpServletResponse response, HttpServletRequest request){
+        response.setHeader("Content-Type", mimeType);
+    }
+    
 
 }
--- a/gnv/src/main/java/de/intevation/gnv/action/sessionmodel/DefaultSessionModel.java	Thu Sep 24 12:43:46 2009 +0000
+++ b/gnv/src/main/java/de/intevation/gnv/action/sessionmodel/DefaultSessionModel.java	Fri Sep 25 07:28:49 2009 +0000
@@ -15,11 +15,15 @@
 public class DefaultSessionModel implements SessionModel{
 
 
+
+
     private Collection<ArtifactObject> artifactFactories = null;
     
     private ArtifactObject selectedArtifactFactory = null;
     
     private ArtifactObject currentArtifact  =null;
+    
+    private DiagrammOptions diagrammOptions= null;
    
 
     /**
@@ -88,5 +92,13 @@
         this.currentArtifact = artifact;
     }
     
+    public DiagrammOptions getDiagrammOptions() {
+        if (diagrammOptions == null){
+            diagrammOptions = new DiagrammOptions();
+        }
+        return diagrammOptions;
+    }
+    
+    
 
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gnv/src/main/java/de/intevation/gnv/action/sessionmodel/DiagrammOptions.java	Fri Sep 25 07:28:49 2009 +0000
@@ -0,0 +1,55 @@
+/**
+ *
+ */
+package de.intevation.gnv.action.sessionmodel;
+/**
+ * @author Tim Englich <tim.englich@intevation.de>
+ *
+ */
+public class DiagrammOptions {
+
+    
+    public enum mode{
+        Standard,
+        User_Specific
+    }
+    
+    private mode modus = mode.Standard;
+    
+    private int width = 500;
+    /**
+     * Constructor
+     */
+    public DiagrammOptions() {
+        super();
+    }
+    
+    /**
+     * @return
+     */
+    public mode getModus() {
+        return modus;
+    }
+    
+    /**
+     * @param modus
+     */
+    public void setModus(mode modus) {
+        this.modus = modus;
+    }
+    
+    /**
+     * @return
+     */
+    public int getWidth() {
+        return width;
+    }
+    
+    /**
+     * @param width
+     */
+    public void setWidth(int width) {
+        this.width = width;
+    }
+
+}
\ No newline at end of file
--- a/gnv/src/main/java/de/intevation/gnv/action/sessionmodel/SessionModel.java	Thu Sep 24 12:43:46 2009 +0000
+++ b/gnv/src/main/java/de/intevation/gnv/action/sessionmodel/SessionModel.java	Fri Sep 25 07:28:49 2009 +0000
@@ -24,5 +24,7 @@
     ArtifactObject getCurrentArtifact();
     
     void setCurrentArtifact(ArtifactObject artifact);
+    
+    DiagrammOptions getDiagrammOptions();
 
 }
--- a/gnv/src/main/resources/applicationMessages.properties	Thu Sep 24 12:43:46 2009 +0000
+++ b/gnv/src/main/resources/applicationMessages.properties	Fri Sep 25 07:28:49 2009 +0000
@@ -111,6 +111,7 @@
 
 
 # attachedOutputOptions
+gnviewer.output.options.diagramm.alt=Diagramm
 gnviewer.output.options.save.title=Diagramm speichern
 gnviewer.output.options.export.title=Daten exportieren
 gnviewer.diagram.options.ajax.success=Die Werte wurden erfolgreich gesetzt.
--- a/gnv/src/main/webapp/WEB-INF/config/struts-config.xml	Thu Sep 24 12:43:46 2009 +0000
+++ b/gnv/src/main/webapp/WEB-INF/config/struts-config.xml	Fri Sep 25 07:28:49 2009 +0000
@@ -34,6 +34,19 @@
                 scope="request"
                 validate="false">
         </action>
+        <action path="/export" 
+                type="de.intevation.gnv.action.DoExportAction"
+                scope="request"
+                validate="false">
+        </action>
+        <action path="/changeOptions" 
+                type="de.intevation.gnv.action.ChangeOptionsAction"
+                scope="request"
+                validate="false">
+                <forward
+                name="success"
+                path="/WEB-INF/jsp/mainlayout.jsp"/>
+        </action>
        </action-mappings>
        
        <message-resources parameter="applicationMessages" null="false"/>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gnv/src/main/webapp/WEB-INF/jsp/includes/display_diagramm_adons_inc.jsp	Fri Sep 25 07:28:49 2009 +0000
@@ -0,0 +1,4 @@
+<div id="diagramoptions">
+    <jsp:include page="/WEB-INF/jsp/includes/display_diagramm_options_inc.jsp"></jsp:include>
+    <jsp:include page="/WEB-INF/jsp/includes/display_diagramm_statistics_inc.jsp"></jsp:include>
+</div>
\ No newline at end of file
--- a/gnv/src/main/webapp/WEB-INF/jsp/includes/display_diagramm_inc.jsp	Thu Sep 24 12:43:46 2009 +0000
+++ b/gnv/src/main/webapp/WEB-INF/jsp/includes/display_diagramm_inc.jsp	Fri Sep 25 07:28:49 2009 +0000
@@ -1,11 +1,28 @@
+<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
 <%@page import="de.intevation.gnv.action.sessionmodel.SessionModelFactory"%>
 <%Object diagramm = request.getAttribute("diagramm");
 if (diagramm != null){
+    
+    String target = "chart"; 
+    String targetCSV = "csv";
+    boolean supportCSV = true; // TODO get from SessionModel
     String mimeType = "image/png";// TODO: get from SessionModel SessionModelFactory.getInstance().getSessionModel(request).
-    String target = "chart"; // TODO: get from SessionModel
-    %>
+    String mimeTypeCSV = "text/plain";// TODO: get from SessionModel SessionModelFactory.getInstance().getSessionModel(request).
+%>
     
     <div id="diagram">
-        <img src='<%=response.encodeURL("out.do?mimetype="+mimeType+"&target="+target+"&uid="+System.currentTimeMillis())%>' alt='Chart'>
+        <img src='<%=response.encodeURL("out.do?mimetype="+mimeType+"&target="+target+"&uid="+System.currentTimeMillis())%>' alt='<bean:message key="gnviewer.output.options.diagramm.alt"/>'/>
+        <br/>
+        <div id="export">
+            <a href="<%=response.encodeURL("export.do?mimetype="+mimeType+"&target="+target+"&uid="+System.currentTimeMillis())%>" title="<bean:message key="gnviewer.output.options.save.title"/>">
+                <img src="images/diagram_export.png" border="0"/>
+            </a>
+            <%if (supportCSV) { %>
+            <a href="<%=response.encodeURL("export.do?mimetype="+mimeTypeCSV+"&target="+targetCSV+"&uid="+System.currentTimeMillis())%>" title="<bean:message key="gnviewer.output.options.export.title"/>">
+                <img src="images/data_export.png" border="0"/>
+            </a>
+            <%}%>
+        </div>
     </div>
+    <jsp:include page="/WEB-INF/jsp/includes/display_diagramm_adons_inc.jsp"></jsp:include>
 <%}%>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gnv/src/main/webapp/WEB-INF/jsp/includes/display_diagramm_options_inc.jsp	Fri Sep 25 07:28:49 2009 +0000
@@ -0,0 +1,33 @@
+<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
+<%@page import="de.intevation.gnv.action.sessionmodel.DiagrammOptions"%>
+<%@page import="de.intevation.gnv.action.sessionmodel.SessionModelFactory"%>
+<%@page import="de.intevation.gnv.action.sessionmodel.DiagrammOptions.mode"%>
+<%
+  DiagrammOptions diagrammOptions = SessionModelFactory.getInstance().getSessionModel(request).getDiagrammOptions();
+  boolean isStandard = diagrammOptions.getModus() == DiagrammOptions.mode.Standard;
+%>
+
+<div id="diagramOptionsContent">
+    <fieldset>
+        <legend onmousedown="displayDiv('diagramOptionsContent');" class="expandableFieldset">
+           <bean:message key="gnviewer.diagram.options.header.title"/>
+        </legend>
+        <form id="outputOptionsForm" method="post" action="changeOptions.do">
+           <input name="overrideSize" value="false" <%=isStandard ? "checked=\"checked\"" : "" %>onblur="document.forms.outputOptionsForm.submit()" type="radio">
+           <label for="overrideSize">
+                <bean:message key="gnviewer.diagram.options.size.fix"/>
+            </label>
+            <br>
+            <input name="overrideSize" value="true" <%=!isStandard ? "checked=\"checked\"" : "" %> onblur="document.forms.outputOptionsForm.submit()" type="radio">
+            <label for="overrideSize">
+                 <bean:message key="gnviewer.diagram.options.size.relative"/>
+            </label>
+            <label for="overridenWidth">
+                <bean:message key="gnviewer.diagram.options.size.text"/>
+            </label>
+            <input name="overridenWidth" value="<%=diagrammOptions.getWidth()%>" onblur="document.forms.outputOptionsForm.submit()" type="text">
+            <br/>
+            <span style="color: red;"></span>
+        </form>
+    </fieldset>
+</div>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gnv/src/main/webapp/WEB-INF/jsp/includes/display_diagramm_statistics_inc.jsp	Fri Sep 25 07:28:49 2009 +0000
@@ -0,0 +1,10 @@
+<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
+<div id="statistics">
+  <fieldset>
+      <legend class="expandableFieldset">
+            <bean:message key="gnviewer.statistics.header.title"/>
+        </legend>
+        <div id="statisticValues">
+        </div>
+    </fieldset>
+</div>
\ No newline at end of file

http://dive4elements.wald.intevation.org