use of com.vaadin.ui.JavaScriptFunction in project VaadinUtils by rlsutton1.
the class JSCallWithReturnValue method call.
void call(final JavaScriptCallback<JsonArray> callback) {
final Stopwatch timer = Stopwatch.createStarted();
final ScheduledFuture<?> future = createTimeoutHook();
JavaScript.getCurrent().addFunction(hookName, new JavaScriptFunction() {
private static final long serialVersionUID = 1L;
boolean done = false;
@Override
public void call(JsonArray arguments) {
try {
if (timer.elapsed(TimeUnit.MILLISECONDS) > EXPECTED_RESPONSE_TIME_MS) {
logger.warn(jsToExecute + "\n\nResponded after {}ms", timer.elapsed(TimeUnit.MILLISECONDS));
}
logger.debug("Handling response for " + hookName);
if (!done) {
done = true;
callback.callback(arguments);
} else {
logger.warn("This appears to have been a duplicate callback, ignoring it!");
}
} catch (Exception e) {
logger.error(e, e);
logger.error(trace, trace);
} finally {
future.cancel(false);
removeHooks(hookName, errorHookName);
}
}
});
final String wrappedJs = wrapJSInTryCatch(jsToExecute);
setupErrorHook(future);
JavaScript.getCurrent().execute(wrappedJs);
}
use of com.vaadin.ui.JavaScriptFunction in project VaadinUtils by rlsutton1.
the class JSCallWithReturnValue method callBlind.
void callBlind(final JavaScriptCallback<Void> javaScriptCallback) {
final Stopwatch timer = Stopwatch.createStarted();
final ScheduledFuture<?> future = createTimeoutHook();
JavaScript.getCurrent().addFunction(hookName, new JavaScriptFunction() {
boolean done = false;
private static final long serialVersionUID = 1L;
@Override
public void call(JsonArray arguments) {
logger.debug("Handling response for " + hookName);
if (!done) {
done = true;
javaScriptCallback.callback(null);
} else {
logger.warn("This appears to have been a duplicate callback, ignoring it!");
}
future.cancel(false);
removeHooks(hookName, errorHookName);
if (timer.elapsed(TimeUnit.MILLISECONDS) > EXPECTED_RESPONSE_TIME_MS) {
logger.warn(jsToExecute + "\n\nResponded after {}ms", timer.elapsed(TimeUnit.MILLISECONDS));
}
}
});
setupErrorHook(future);
JavaScript.getCurrent().execute(wrapJSInTryCatchBlind(jsToExecute));
}
use of com.vaadin.ui.JavaScriptFunction in project VaadinUtils by rlsutton1.
the class JSCallWithReturnValue method setupErrorHook.
private void setupErrorHook(final ScheduledFuture<?> future) {
trace = new JavaScriptException("Java Script Invoked From Here, JS:" + jsToExecute);
JavaScript.getCurrent().addFunction(errorHookName, new JavaScriptFunction() {
private static final long serialVersionUID = 1L;
@Override
public void call(JsonArray arguments) {
try {
String value = arguments.getString(0);
logger.error(jsToExecute + " -> resulted in the error: " + value, trace);
Exception ex = new JavaScriptException(trace.getMessage() + " , JS Cause: " + value, trace);
ErrorWindow.showErrorWindow(ex);
} catch (Exception e) {
ErrorWindow.showErrorWindow(trace);
} finally {
future.cancel(false);
JavaScript.getCurrent().removeFunction(hookName);
JavaScript.getCurrent().removeFunction(errorHookName);
}
}
});
}
use of com.vaadin.ui.JavaScriptFunction in project VaadinUtils by rlsutton1.
the class JasperReportLayout method initScreen.
protected void initScreen(SplitPanel panel) {
this.setSizeFull();
splitPanel = panel;
this.addComponent(splitPanel.getComponent());
splitPanel.setFirstComponent((AbstractComponent) getOptionsPanel());
splash = new VerticalLayout();
splash.setMargin(true);
Label titleLabel = new Label("<h1>" + reportProperties.getReportTitle() + "</h1>");
titleLabel.setContentMode(ContentMode.HTML);
splash.addComponent(titleLabel);
Label splashLabel = new Label("<font size='4' >Set the desired filters and click a print button to generate a report</font>");
splashLabel.setContentMode(ContentMode.HTML);
splitPanel.setSecondComponent(splash);
// generate the report immediately if there are no visible filters
if (!builder.hasFilters()) {
splashLabel = new Label("<font size='4' >Please wait whilst we generate your report</font>");
splashLabel.setContentMode(ContentMode.HTML);
// disable the buttons and any filters
printButton.setEnabled(false);
exportButton.setEnabled(false);
showButton.setEnabled(false);
for (ExpanderComponent componet : components) {
componet.getComponent().setEnabled(false);
}
// what follows is a horrible hack...
// if we create the progress dialog at the same time as the popup
// report window the progress dialog will be behind the popup report
// window.
// so I've created a refresher, and 1 seconds after the popup report
// window opens we kick of the report generation which creates the
// progress dialog then, which allows it to be in front.
UI.getCurrent().setPollInterval(500);
UI.getCurrent().addPollListener(new PollListener() {
private static final long serialVersionUID = 1L;
@Override
public void poll(PollEvent event) {
try {
UI.getCurrent().setPollInterval(-1);
UI.getCurrent().removePollListener(this);
generateReport(reportProperties.getDefaultFormat(), JasperReportLayout.this.builder.getReportParameters());
} catch (Exception e) {
logger.catching(e);
Notification.show("Error", e.getMessage(), Type.ERROR_MESSAGE);
}
}
});
}
splash.addComponent(splashLabel);
JavaScript.getCurrent().addFunction("au.com.noojee.reportDrillDown", new JavaScriptFunction() {
// expected syntax of a call to this javascript hook method
//
// window.parent.au.com.noojee.reportDrillDown(
// {
// 'reportFileName':
// 'CallDetailsPerTeamAgentPerHour_CallDetails.jasper',
// 'reportTitle': 'Call Details Per Team Agent Per Hour'
// },
// {
// 'ReportParameterStartDate'='$P{StartDate}',
// 'ReportParameterEndDate'='$P{EndDate}',
// 'ReportParameterExtension'='$F{loginid}',
// 'ReportParameterTeamId'='$P{TeamId}',
// 'ReportParameterHour'='$F{Day}.toString()'
// }
//
// );
private static final long serialVersionUID = 1L;
@Override
public void call(JsonArray arguments) {
try {
JsonObject args = arguments.getObject(0);
String subReportFileName = args.getString("ReportFileName");
String subTitle = args.getString("ReportTitle");
JsonObject params = arguments.getObject(1);
List<ReportParameter<?>> subFilters = new LinkedList<>();
boolean insitue = false;
String[] itr = params.keys();
for (String key : itr) {
if (key.equalsIgnoreCase("ReportParameterInsitue")) {
insitue = true;
} else {
subFilters.add(new ReportParameterConstant<>(key, params.getString(key), key, params.getString(key)));
}
}
if (!insitue) {
new JasperReportPopUp(new ChildJasperReportProperties(reportProperties, subTitle, subReportFileName, subFilters));
} else {
generateReport(OutputFormat.HTML, subFilters);
}
} catch (Exception e) {
logger.error(arguments.toString());
logger.error(e, e);
}
}
});
}
Aggregations