ItEr43S10SoporteImpresionMultiplesPaxinasItEr42S15: Adding support for horizontal scaling through CSS autogeneration
This commit is contained in:
parent
6bd8884801
commit
7f35b06128
9 changed files with 383 additions and 99 deletions
|
|
@ -410,7 +410,7 @@ public class FunctionalityExposedForExtensions<T> implements IContext<T> {
|
|||
printButton.addEventListener(Events.ON_CLICK, new EventListener() {
|
||||
@Override
|
||||
public void onEvent(Event event) throws Exception {
|
||||
configuration.print(buildParameters(printProperties));
|
||||
configuration.print(buildParameters(printProperties),planner);
|
||||
}
|
||||
});
|
||||
printButton.setParent(printProperties);
|
||||
|
|
|
|||
|
|
@ -23,10 +23,12 @@ package org.zkoss.ganttz.adapters;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.zkoss.ganttz.Planner;
|
||||
import org.zkoss.ganttz.data.constraint.Constraint;
|
||||
import org.zkoss.ganttz.data.constraint.DateConstraint;
|
||||
import org.zkoss.ganttz.extensions.ICommand;
|
||||
|
|
@ -47,6 +49,8 @@ public class PlannerConfiguration<T> implements IDisabilityConfiguration {
|
|||
public void doPrint();
|
||||
|
||||
public void doPrint(Map<String, String> parameters);
|
||||
|
||||
public void doPrint(HashMap<String, String> parameters, Planner planner);
|
||||
}
|
||||
|
||||
public interface IReloadChartListener {
|
||||
|
|
@ -320,4 +324,11 @@ public class PlannerConfiguration<T> implements IDisabilityConfiguration {
|
|||
printAction.doPrint(parameters);
|
||||
}
|
||||
|
||||
public void print(HashMap<String, String> parameters, Planner planner) {
|
||||
if (!isPrintEnabled()) {
|
||||
throw new UnsupportedOperationException("print not supported");
|
||||
}
|
||||
printAction.doPrint(parameters, planner);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,9 @@ import org.zkoss.ganttz.util.Interval;
|
|||
public abstract class TimeTrackerState {
|
||||
|
||||
protected static final long MILLSECONDS_IN_DAY = 1000 * 60 * 60 * 24;
|
||||
protected static final int NUMBER_OF_ITEMS_MINIMUM = 10;
|
||||
|
||||
// Pending to calculate interval dinamically
|
||||
protected static final int NUMBER_OF_ITEMS_MINIMUM = 4;
|
||||
|
||||
private final IDetailItemModificator firstLevelModificator;
|
||||
|
||||
|
|
|
|||
|
|
@ -445,6 +445,12 @@ public abstract class CompanyPlanningModel implements ICompanyPlanningModel {
|
|||
CutyPrint.print(parameters);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doPrint(HashMap<String, String> parameters,
|
||||
Planner planner) {
|
||||
CutyPrint.print(parameters, planner);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
|
@ -252,6 +253,13 @@ public abstract class OrderPlanningModel implements IOrderPlanningModel {
|
|||
CutyPrint.print(order, parameters);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doPrint(HashMap<String, String> parameters,
|
||||
Planner planner) {
|
||||
CutyPrint.print(order, parameters, planner);
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,13 @@ package org.navalplanner.web.print;
|
|||
|
||||
import static org.zkoss.ganttz.i18n.I18nHelper._;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
|
|
@ -17,9 +23,9 @@ import org.apache.commons.logging.Log;
|
|||
import org.apache.commons.logging.LogFactory;
|
||||
import org.navalplanner.business.orders.entities.Order;
|
||||
import org.navalplanner.web.common.entrypoints.URLHandler;
|
||||
import org.zkoss.ganttz.Planner;
|
||||
import org.zkoss.ganttz.servlets.CallbackServlet;
|
||||
import org.zkoss.ganttz.servlets.CallbackServlet.IServletRequestHandler;
|
||||
import org.zkoss.ganttz.timetracker.zoom.ZoomLevel;
|
||||
import org.zkoss.zk.ui.Executions;
|
||||
|
||||
public class CutyPrint {
|
||||
|
|
@ -28,6 +34,9 @@ public class CutyPrint {
|
|||
|
||||
private static final String CUTYCAPT_COMMAND = "/usr/bin/CutyCapt ";
|
||||
|
||||
// Fixed taskdetails width padding left
|
||||
private static int TASKDETAILS_WIDTH = 310;
|
||||
|
||||
public static void print(Order order) {
|
||||
print("/planner/index.zul", entryPointForShowingOrder(order),
|
||||
Collections.<String, String> emptyMap());
|
||||
|
|
@ -38,6 +47,12 @@ public class CutyPrint {
|
|||
parameters);
|
||||
}
|
||||
|
||||
public static void print(Order order, HashMap<String, String> parameters,
|
||||
Planner planner) {
|
||||
print("/planner/index.zul", entryPointForShowingOrder(order),
|
||||
parameters, planner);
|
||||
}
|
||||
|
||||
public static void print() {
|
||||
print("/planner/index.zul", Collections.<String, String> emptyMap(),
|
||||
Collections.<String, String> emptyMap());
|
||||
|
|
@ -48,6 +63,11 @@ public class CutyPrint {
|
|||
parameters);
|
||||
}
|
||||
|
||||
public static void print(HashMap<String, String> parameters, Planner planner) {
|
||||
print("/planner/index.zul", Collections.<String, String> emptyMap(),
|
||||
parameters, planner);
|
||||
}
|
||||
|
||||
private static Map<String, String> entryPointForShowingOrder(Order order) {
|
||||
final Map<String, String> result = new HashMap<String, String>();
|
||||
result.put("order", order.getId() + "");
|
||||
|
|
@ -57,10 +77,39 @@ public class CutyPrint {
|
|||
public static void print(final String forwardURL,
|
||||
final Map<String, String> entryPointsMap,
|
||||
Map<String, String> parameters) {
|
||||
print(forwardURL, entryPointsMap, parameters, null);
|
||||
}
|
||||
|
||||
public static void print(final String forwardURL,
|
||||
final Map<String, String> entryPointsMap,
|
||||
Map<String, String> parameters, Planner planner) {
|
||||
|
||||
HttpServletRequest request = (HttpServletRequest) Executions
|
||||
.getCurrent().getNativeRequest();
|
||||
|
||||
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())
|
||||
+ extension;
|
||||
|
||||
int plannerWidth = 0;
|
||||
if ((planner != null) && (planner.getTimeTracker() != null)) {
|
||||
plannerWidth = planner.getTimeTracker().getHorizontalSize()
|
||||
+ TASKDETAILS_WIDTH;
|
||||
}
|
||||
|
||||
// Generate capture string
|
||||
String captureString = CUTYCAPT_COMMAND;
|
||||
|
||||
String url = CallbackServlet.registerAndCreateURLFor(request,
|
||||
new IServletRequestHandler() {
|
||||
|
||||
|
|
@ -78,22 +127,6 @@ public class CutyPrint {
|
|||
}
|
||||
});
|
||||
|
||||
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())
|
||||
+ extension;
|
||||
|
||||
// Generate capture string
|
||||
String captureString = CUTYCAPT_COMMAND;
|
||||
|
||||
// Add capture destination callback URL
|
||||
captureString += " --url=http://" + request.getLocalName() + ":"
|
||||
+ request.getLocalPort() + url;
|
||||
|
|
@ -103,33 +136,34 @@ public class CutyPrint {
|
|||
for (String key : parameters.keySet()) {
|
||||
captureString += key + "=" + parameters.get(key) + "&";
|
||||
}
|
||||
captureString.substring(0, captureString.length() - 1);
|
||||
captureString = captureString.substring(0,
|
||||
(captureString.length() - 1));
|
||||
}
|
||||
|
||||
// Static width and time delay parameters (FIX)
|
||||
captureString += " --min-width="
|
||||
+ getCanvasWidth(ZoomLevel
|
||||
.getFromString(parameters.get("zoom")));
|
||||
captureString += " --min-width=" + plannerWidth;
|
||||
|
||||
// Static width and time delay parameters (FIX)
|
||||
captureString += " --delay=1000 ";
|
||||
|
||||
String generatedCSSFile = createCSSFile(absolutePath
|
||||
+ "/planner/css/printlabels.css", plannerWidth);
|
||||
|
||||
// Relative user styles
|
||||
captureString += "--user-styles=" + absolutePath
|
||||
+ "/planner/css/print.css";
|
||||
captureString += "--user-styles=" + generatedCSSFile;
|
||||
|
||||
// Destination complete absolute path
|
||||
captureString += " --out=" + absolutePath + filename;
|
||||
|
||||
try {
|
||||
|
||||
// CutyCapt command execution
|
||||
LOG.debug(captureString);
|
||||
|
||||
Process print;
|
||||
Process server = null;
|
||||
|
||||
// Ensure cleanup of unfinished CutyCapt processes
|
||||
Process clean = null;
|
||||
clean = Runtime.getRuntime().exec("killall CutyCapt");
|
||||
// Ensure cleanup of unfinished CutyCapt processes and CSS
|
||||
Runtime.getRuntime().exec("killall CutyCapt");
|
||||
|
||||
// If there is a not real X server environment then use Xvfb
|
||||
if ((System.getenv("DISPLAY") == null)
|
||||
|
|
@ -159,10 +193,36 @@ public class CutyPrint {
|
|||
}
|
||||
}
|
||||
|
||||
private static int getCanvasWidth(ZoomLevel z) {
|
||||
// Calculate based on real planner width
|
||||
int value = 2600;
|
||||
return value;
|
||||
}
|
||||
private static String createCSSFile(String srFile, int width) {
|
||||
File generatedCSS = null;
|
||||
try {
|
||||
generatedCSS = File.createTempFile("print", ".css");
|
||||
|
||||
File f1 = new File(srFile);
|
||||
InputStream in = new FileInputStream(f1);
|
||||
|
||||
// For Overwrite the file.
|
||||
OutputStream out = new FileOutputStream(generatedCSS);
|
||||
|
||||
byte[] buf = new byte[1024];
|
||||
int len;
|
||||
while ((len = in.read(buf)) > 0) {
|
||||
out.write(buf, 0, len);
|
||||
}
|
||||
String body = "body { width: " + width + "px; } \n";
|
||||
out.write(body.getBytes());
|
||||
in.close();
|
||||
out.close();
|
||||
LOG.debug(_("Generated CSS:") + generatedCSS.getAbsolutePath());
|
||||
} catch (FileNotFoundException ex) {
|
||||
LOG.error(ex.getMessage() + _(" in the specified directory."));
|
||||
System.exit(0);
|
||||
} catch (IOException e) {
|
||||
LOG.error(e.getMessage());
|
||||
}
|
||||
if (generatedCSS != null) {
|
||||
return generatedCSS.getAbsolutePath();
|
||||
} else
|
||||
return srFile;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,68 +6,6 @@
|
|||
* to integrate the custom appearance of the web application.
|
||||
*/
|
||||
|
||||
@media print {
|
||||
|
||||
.mainmenu, .user-area, .help-link {
|
||||
display: none;
|
||||
}
|
||||
|
||||
body .perspectives-column {
|
||||
display: none;
|
||||
}
|
||||
|
||||
body .main-area {
|
||||
margin-left: -90px;
|
||||
margin-top: -28px;
|
||||
}
|
||||
|
||||
.toolbar-box {
|
||||
display: none;
|
||||
height: 0px !important;
|
||||
}
|
||||
|
||||
/* Calculate dynamically */
|
||||
body {
|
||||
width: 2500px;
|
||||
}
|
||||
|
||||
body .z-border-layout {
|
||||
background-color: #FFFFFF;
|
||||
}
|
||||
|
||||
.plannerlayout .leftpanelcontainer,
|
||||
.plannerlayout .rightpanellayout .z-center-body {
|
||||
overflow: hidden !important;
|
||||
}
|
||||
|
||||
body {
|
||||
width: 2500px;
|
||||
}
|
||||
|
||||
/* ----- 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;
|
||||
}
|
||||
|
||||
} /* --- End print media ----*/
|
||||
|
||||
|
||||
/* ----- Predefined Height dependent styles ----- */
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
|
||||
/* Print CSS used for CutyCapt capture requests */
|
||||
|
||||
.mainmenu, .user-area, .help-link {
|
||||
display: none;
|
||||
body .mainmenu, body .user-area, body .help-link {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
body .perspectives-column {
|
||||
|
|
@ -79,3 +78,167 @@ a.ruta, .toolbar-box {
|
|||
display: inline !important;
|
||||
}
|
||||
|
||||
|
||||
@media screen {
|
||||
|
||||
body .mainmenu, body .user-area, body .help-link {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
body .perspectives-column {
|
||||
display: none;
|
||||
}
|
||||
|
||||
body .main-area {
|
||||
margin-left: -90px;
|
||||
margin-top: -28px;
|
||||
}
|
||||
|
||||
.toolbar-box {
|
||||
display: none;
|
||||
height: 0px !important;
|
||||
}
|
||||
|
||||
|
||||
body .z-border-layout {
|
||||
background-color: #FFFFFF;
|
||||
}
|
||||
|
||||
.plannerlayout .leftpanelcontainer,
|
||||
.plannerlayout .rightpanellayout .z-center-body {
|
||||
overflow: hidden !important;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@media print {
|
||||
|
||||
body .mainmenu, body .user-area, body .help-link {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
body .perspectives-column {
|
||||
display: none;
|
||||
}
|
||||
|
||||
body .main-area {
|
||||
margin-left: -90px;
|
||||
margin-top: -28px;
|
||||
}
|
||||
|
||||
.toolbar-box {
|
||||
display: none;
|
||||
height: 0px !important;
|
||||
}
|
||||
|
||||
|
||||
body .z-border-layout {
|
||||
background-color: #FFFFFF;
|
||||
}
|
||||
|
||||
.plannerlayout .leftpanelcontainer,
|
||||
.plannerlayout .rightpanellayout .z-center-body {
|
||||
overflow: hidden !important;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,96 @@
|
|||
/* optional */
|
||||
.task-labels {
|
||||
display: inline !important;
|
||||
}
|
||||
|
||||
.task-resources {
|
||||
display: inline !important;
|
||||
}
|
||||
|
||||
/****
|
||||
Redundant, but @import or passing several
|
||||
CSS files does not work with CutyCapt
|
||||
--- print.css ----
|
||||
*******/
|
||||
|
||||
/* ------ Hide non printable elements ------ */
|
||||
body div.scheduling-graphics {
|
||||
height: 0px !important;
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
body .perspectives-column {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
body .mainmenu, body .user-area, body .help-link {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
body .footer {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
/* ------ Remove scrolls ------ */
|
||||
.leftpanelcontainer {
|
||||
overflow: hidden !important;
|
||||
}
|
||||
|
||||
.rightpanellayout .z-center-body {
|
||||
overflow: hidden !important;
|
||||
}
|
||||
|
||||
#ganttpanel_scroller_x, #ganttpanel_scroller_y {
|
||||
overflow: hidden !important;
|
||||
}
|
||||
|
||||
.main-area, .orderslayout-area, .orderelements-tab, #timetrackedtable,
|
||||
.plannerlayout .taskspanelgap #timetracker, .leftpanelcontainer {
|
||||
overflow: hidden !important;
|
||||
}
|
||||
|
||||
/* ------ Reposition main-area ------ */
|
||||
body .main-area {
|
||||
margin-left: 0;
|
||||
margin-top: -32px;
|
||||
}
|
||||
|
||||
/* ------ Hide possible Javascript execution exceptions ------ */
|
||||
#zk_err_1 {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* Hack for hiding breadcrumbs part in printed diagrams */
|
||||
a.ruta,
|
||||
.ruta tr td,
|
||||
.ruta tr td+td,
|
||||
.ruta tr td+td+td {
|
||||
display:none;
|
||||
}
|
||||
|
||||
.ruta tr td+td+td+td+td+td {
|
||||
font-size: 20px;
|
||||
display: inline !important;
|
||||
}
|
||||
|
||||
/* ------ Dynamically set heights ------ */
|
||||
body {
|
||||
width: 5000px;
|
||||
}
|
||||
|
||||
body div.main-layout {
|
||||
height: 1100px !important;
|
||||
}
|
||||
|
||||
body div.plannerlayout {
|
||||
height: 1090px !important;
|
||||
}
|
||||
|
||||
body div#timetracker {
|
||||
height: 1030px !important;
|
||||
}
|
||||
|
||||
body div#scroll_container {
|
||||
height: 1010px !important;
|
||||
}
|
||||
|
||||
Loading…
Add table
Reference in a new issue