ItEr43S10SoporteImpresionMultiplesPaxinasItEr42S15: Added modal window with print configuration properties.

This commit is contained in:
Lorenzo Tilve 2010-01-14 00:05:04 +01:00 committed by Javier Moran Rua
parent 0ee3146bd0
commit cdc8306f48
10 changed files with 265 additions and 23 deletions

View file

@ -20,6 +20,8 @@
package org.zkoss.ganttz;
import static org.zkoss.ganttz.i18n.I18nHelper._;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
@ -48,6 +50,13 @@ import org.zkoss.ganttz.timetracker.zoom.IDetailItemModificator;
import org.zkoss.ganttz.timetracker.zoom.TimeTrackerState;
import org.zkoss.ganttz.util.Interval;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zul.Button;
import org.zkoss.zul.Radiogroup;
import org.zkoss.zul.Window;
public class FunctionalityExposedForExtensions<T> implements IContext<T> {
@ -373,7 +382,41 @@ public class FunctionalityExposedForExtensions<T> implements IContext<T> {
if (!isPrintEnabled()) {
throw new UnsupportedOperationException("print is not supported");
}
configuration.print();
final Window printProperties = (Window) Executions.createComponents(
"/planner/print_configuration.zul", planner, null);
Button printButton = new Button(_("Print"));
printButton.addEventListener(Events.ON_CLICK, new EventListener() {
@Override
public void onEvent(Event event) throws Exception {
Radiogroup layout = (Radiogroup) printProperties
.getFellow("print_layout");
HashMap<String, String> parameters = new HashMap<String, String>();
if (layout.getSelectedIndex() == 2) {
parameters.put("extension", ".png");
}
configuration.print(parameters);
}
});
printButton.setParent(printProperties);
Button cancelPrint = new Button(_("Cancel"));
printButton.addEventListener(Events.ON_CLICK, new EventListener() {
@Override
public void onEvent(Event event) throws Exception {
// get Print properties and params
printProperties.setVisible(false);
}
});
cancelPrint.setParent(printProperties);
try {
printProperties.doModal();
} catch (Exception e) {
e.printStackTrace();
}
}
}

View file

@ -50,10 +50,10 @@ import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.HtmlMacroComponent;
import org.zkoss.zk.ui.util.Clients;
import org.zkoss.zul.Button;
import org.zkoss.zul.ListModel;
import org.zkoss.zul.Separator;
import org.zkoss.zul.SimpleListModel;
import org.zkoss.zul.api.Button;
public class Planner extends HtmlMacroComponent {
@ -144,6 +144,7 @@ public class Planner extends HtmlMacroComponent {
}
public void setZoomLevel(final ZoomLevel zoomLevel) {
if (ganttPanel == null) {
return;
}

View file

@ -24,6 +24,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.Validate;
import org.zkoss.ganttz.data.constraint.Constraint;
@ -44,6 +45,8 @@ public class PlannerConfiguration<T> implements IDisabilityConfiguration {
public interface IPrintAction {
public void doPrint();
public void doPrint(Map<String, String> parameters);
}
public interface IReloadChartListener {
@ -310,4 +313,11 @@ public class PlannerConfiguration<T> implements IDisabilityConfiguration {
printAction.doPrint();
}
public void print(Map<String, String> parameters) {
if (!isPrintEnabled()) {
throw new UnsupportedOperationException("print not supported");
}
printAction.doPrint(parameters);
}
}

View file

@ -439,6 +439,12 @@ public abstract class CompanyPlanningModel implements ICompanyPlanningModel {
public void doPrint() {
CutyPrint.print();
}
@Override
public void doPrint(Map<String, String> parameters) {
CutyPrint.print(parameters);
}
});
}

View file

@ -246,6 +246,12 @@ public abstract class OrderPlanningModel implements IOrderPlanningModel {
public void doPrint() {
CutyPrint.print(order);
}
@Override
public void doPrint(Map<String, String> parameters) {
CutyPrint.print(order, parameters);
}
});
}

View file

@ -27,15 +27,24 @@ public class CutyPrint {
private static final String CUTYCAPT_COMMAND = "/usr/bin/CutyCapt ";
// Calculate dynamically width and delay parameters
private static final String CUTYCAPT_PARAMETERS = " --min-width=2500 --delay=1000 ";
public static void print() {
print("/planner/index.zul", Collections.<String, String> emptyMap());
public static void print(Order order) {
print("/planner/index.zul", entryPointForShowingOrder(order),
Collections.<String, String> emptyMap());
}
public static void print(Order order) {
print("/planner/index.zul", entryPointForShowingOrder(order));
public static void print(Order order, Map<String, String> parameters) {
print("/planner/index.zul", entryPointForShowingOrder(order),
parameters);
}
public static void print() {
print("/planner/index.zul", Collections.<String, String> emptyMap(),
Collections.<String, String> emptyMap());
}
public static void print(Map<String, String> parameters) {
print("/planner/index.zul", Collections.<String, String> emptyMap(),
parameters);
}
private static Map<String, String> entryPointForShowingOrder(Order order) {
@ -45,7 +54,8 @@ public class CutyPrint {
}
public static void print(final String forwardURL,
final Map<String, String> entryPointsMap) {
final Map<String, String> entryPointsMap,
Map<String, String> parameters) {
HttpServletRequest request = (HttpServletRequest) Executions
.getCurrent().getNativeRequest();
@ -61,31 +71,53 @@ public class CutyPrint {
URLHandler.setupEntryPointsForThisRequest(request,
entryPointsMap);
// Pending to forward and process additional parameters
// as show labels or resources
// as show labels, resources, zoom or expand all
request.getRequestDispatcher(forwardURL).forward(
request, response);
}
});
String CUTYCAPT_URL = "--url=http://" + request.getLocalName() + ":"
+ request.getLocalPort() + url;
String captureString = CUTYCAPT_COMMAND + CUTYCAPT_URL;
captureString += CUTYCAPT_PARAMETERS;
String extension = ".pdf";
if (((parameters.get("extension") != null) && !(parameters
.get("extension").equals("")))) {
extension = parameters.get("extension");
}
// Calculate application path and destination file relative route
String absolutePath = request.getSession().getServletContext()
.getRealPath("/");
String filename = "/print/"
+ new SimpleDateFormat("yyyyMMddHHmmss").format(new Date())
+ ".pdf";
captureString += "--out=" + absolutePath + filename;
+ extension;
// Generate capture string
String captureString = CUTYCAPT_COMMAND;
// Add capture destination callback URL
captureString += " --url=http://" + request.getLocalName() + ":"
+ request.getLocalPort() + url;
// Static width and time delay parameters (FIX)
captureString += " --min-width=2600 --delay=1000 ";
// Relative user styles
captureString += "--user-styles=" + absolutePath
+ "/planner/css/print.css";
// Destination complete absolute path
captureString += " --out=" + absolutePath + filename;
try {
// CutyCapt command execution
// If there is a not real X server environment, use framebuffer
LOG.debug(captureString);
Process print;
Process server = null;
// Ensure cleanup of unfinished CutyCapt processes
Process clean = null;
clean = Runtime.getRuntime().exec("killall CutyCapt");
// If there is a not real X server environment then use Xvfb
if ((System.getenv("DISPLAY") == null)
|| (System.getenv("DISPLAY").equals(""))) {
String[] serverEnvironment = { "PATH=$PATH" };
@ -104,7 +136,7 @@ public class CutyPrint {
server.destroy();
}
Executions.getCurrent().sendRedirect(filename, "_blank");
} catch (InterruptedException e) {
} catch (Exception e) {
LOG.error(_("Could open generated PDF"), e);
}
@ -113,5 +145,4 @@ public class CutyPrint {
}
}
}

View file

@ -20,6 +20,19 @@
margin-left: -90px;
}
body .main-area {
margin-left: -90px;
}
.toolbar-box {
display: none;
height: 0px !important;
}
.plannerlayout_center {
margin-top: -25px;
}
/* Calculate dynamically */
body {
width: 2500px;
@ -77,7 +90,6 @@
width: 300px;
}
.plannerlayout #watermark,
.plannerlayout #watermark .timetracker_column_even {
height: 99999px !important;
@ -1165,7 +1177,7 @@ tr.z-tree-row-seld, tr.z-list-item-seld,
min-width: 30px;
}
.function {
min-width: 90px;
}

View file

@ -0,0 +1,53 @@
/* Print CSS used for CutyCapt capture requests */
body {
width: 2600px;
}
/* ----- Height dependent styles ----- */
body div.scheduling-graphics {
height: 0px !important;
display: none;
}
/* Dynamically set heights */
body div.main-layout {
height: 1800px !important;
}
body div.plannerlayout {
height: 1790px !important;
}
body div#timetracker {
height: 1730px !important;
}
body div#scroll_container {
height: 1710px !important;
}
/* Hide possible Javascript execution exceptions */
#zk_err_1 {
display: none;
}
/* Hide more stuff */
a.ruta, .toolbar-box {
display: none;
}
/* Hack for hiding breadcrumbs part in printed diagrams */
.ruta tr td,
.ruta tr td+td,
.ruta tr td+td+td {
display:none;
}
.ruta tr td+td+td+td+td+td {
font-size: 18px;
display: inline !important;
}

View file

@ -0,0 +1,79 @@
<!--
This file is part of ###PROJECT_NAME###
Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e
Desenvolvemento Tecnolóxico de Galicia
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<?page title="${i18n:_('Print configuration')}"?>
<?taglib uri="/WEB-INF/tld/i18n.tld" prefix="i18n"?>
<zk>
<window border="normal" title="${i18n:_('Print configuration')}"
closable="true">
<panel title="${i18n:_('Select print page properties')}"
border="normal" style="margin-bottom:10px;">
<panelchildren>
<groupbox>
<caption label="${i18n:_('Print layout')}" />
<radiogroup id="print_layout"
onCheck="choice.value = self.selectedItem.label">
<radio label="${i18n:_('Portrait')}"
selected="true" />
<radio label="${i18n:_('Landscape')}" disabled="true" />
<radio label="${i18n:_('Single image')}" />
</radiogroup>
</groupbox>
<groupbox visible="false">
<caption label="${i18n:_('Paper size')}" />
<radiogroup id="print_paper_size"
onCheck="choice.value = self.selectedItem.label">
<radio label="${i18n:_('A4')}" selected="true" />
<radio label="${i18n:_('A3')}" disabled="true" />
<radio label="${i18n:_('A2')}" disabled="true" />
<radio label="${i18n:_('A1')}" disabled="true" />
</radiogroup>
</groupbox>
<groupbox>
<caption label="${i18n:_('Zoom level')}" />
<radiogroup id="print_zoom_level"
onCheck="choice.value = self.selectedItem.label">
<radio label="${i18n:_('Year')}" selected="true" />
<radio label="${i18n:_('Quarter')}" />
<radio label="${i18n:_('Month')}" />
<radio label="${i18n:_('Week')}" />
<radio label="${i18n:_('Day')}" />
</radiogroup>
</groupbox>
</panelchildren>
</panel>
<panel title="${i18n:_('Select print visualization options')}"
border="normal" style="margin-bottom:10px;">
<panelchildren>
<vbox>
<checkbox id="print_labels" label="${i18n:_('Show all labels')}" />
<checkbox id="print_resources"
label="${i18n:_('Show all resource assignments')}" />
<checkbox id="print_expanded"
label="${i18n:_('Show expanded tree')}" visible="false" />
<checkbox id="print_shrinked"
label="${i18n:_('Shrink to fit page width')}" checked="true" disabled="true" />
</vbox>
</panelchildren>
</panel>
</window>
</zk>

View file

@ -1 +1,2 @@
*.pdf
*.png