GWT: Export a CellTable to an image or pdf file - gwt

I have a CellTable showing data that is plotted in a GFlot SimplePlot.
An export of the plot is possible with GFlots integrated function:
exportImage = plot.getImage();
Now I would like to export the CellTable too, to show the corresponding data to the plot.
Is this possible in some way with GWT on the client-side? It needn't to be the CellTable itself, just the data it shows would suffice.

I think You can use flash4j library:
package com.emitrom.flash4j.demo.client;
import com.emitrom.flash4j.clientio.client.ClientIO;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.RootPanel;
public class ClientIOExample implements EntryPoint {
#Override
public void onModuleLoad() {
// initialize the ClientIO module
ClientIO.init();
Button b = new Button("Click Me");
b.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
// create a PDF File
PDF pdf = new PDF();
pdf.addPage();
pdf.setTextStyle(new RGBColor(0x000000));
pdf.setFont(new CoreFont(), 10);
pdf.addText("");
ClientIO.saveFile(pdf.save(), "file.pdf");
}
});
RootPanel.get().add(b);
}
}
You can see more detailed information a link

Related

Custom Button in MessageDialog

I want to add my custom button with AjaxEventBehavior to MessageDialog , i can add simple custom button without AjaxEventBehavior by extending DialogButton class, but this will be useless button with out listener, anyone no how to do it?
here is my code:
import com.googlecode.wicket.jquery.ui.widget.dialog.MessageDialog;
import org.apache.wicket.ajax.AjaxRequestTarget;
import
org.apache.wicket.core.request.handler.IPartialPageRequestHandler;
import org.apache.wicket.model.Model;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
public class TipOfTheDayDialog extends MessageDialog {
private static final Logger log =
LoggerFactory.getLogger(TipOfTheDayDialog.class);
Model<String> model = null;
List<DialogButton> dialogButtons =null;
public TipOfTheDayDialog(String id, Model<String> model,List<DialogButton> dialogButtons) {
super(id, Model.of("Совет дня"), model, dialogButtons);
this.model = model;
}
#Override
public void onClose(IPartialPageRequestHandler handler, DialogButton button) {}
#Override
public void onClick(AjaxRequestTarget target, DialogButton button)
{
if(!button.getName().equals("next")){
super.close(target,button);
this.close(target, button);
}else {
model.setObject("another message");
target.add(this);
}
}
}
I have decided to override method onclick instead of adding button with its own listener, but now i have another problem, i can't change message of dialog without it's closing , when i change message by this line of the code: model.setObject("another message"); and then add it to the target by this code : target.add(this); dialog window closes, how to fix it?

How to create a javafx 2.0 application MDI

How to implement something kinda internal frame in JavaFx 2.0 specifically?
My attempt is as so..
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class Main extends Application {
ConnectDb connection;
public static void main(String[] args) {
Application.launch(args);
}
#Override
public void start(Stage stage) throws Exception {
final Stage stage1 = new Stage();
StackPane pane = new StackPane();
Button btn = new Button("Click Me");
btn.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
connection = new ConnectDb();
try {
connection.start(stage1);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Fire some thing..");
}
});
pane.getChildren().add(btn);
stage.setScene(new Scene(pane ,200, 300));
stage.show();
}
}
ConnectDb.java
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class ConnectDb extends Application {
#Override
public void start(Stage stage) throws Exception {
StackPane pane = new StackPane();
Button btn = new Button("Click On Button which is me");
btn.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
System.out.println("Something here..");
}
});
pane.getChildren().add(btn);
stage.setScene(new Scene(pane ,200, 300));
stage.show();
}
}
First of all, for your approach, you don't really need to (and therefore should not) extend ConnectDb from Application as you just use the start method to create new stages. You just need one Application class (in your case Main). You could just as well create the new stage/scene in your first event handler.
Secondly, there is no real MDI support in JavaFX 2.1. Right now, you can just have multiple Stages (which is the equivalent to having multiple windows/frames). But you cannot have something like an internal frame in a desktop pane.
I guess you could take the following actions:
Just use multiple Stages (windows) with the drawback that they will float quite uninspiredly on your desktop
Use Swing as a container (with JDesktopPane and JInternalFrame) and integrate JavaFX (here's a nice How-To)
Implement your own framework that emulates MDI behavior
Find a framework that provides MDI behavior
Wait for a future release of JavaFX that hopefully provides MDI support (as far as I know, there's a change request pending...)
Create parent AncorPane.
Add several children AnchorPanes to it. They will serve as internal frames. Add different content to these.
Set children AnchorPanes invisible.
Add buttons to hide, resize or close children AnchorPanes. When needed, call function to set all children AnchorPanes invisible, except for one.

windowbuilder tutorial not functioning

I am trying to do a tutorial that allows one to Add and Remove stocks and witness their price and change. This tutorial demonstrates how to use the GUI builder, GWT Designer, to create and design a Stock Watcher application based on the GWT tutorial.
http://code.google.com/webtoolkit/tools/gwtdesigner/tutorials/stockwatcher.html#design_ui
So far I have SW.java:
package edu.gatech.client;
import java.util.ArrayList;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.event.dom.client.KeyPressHandler;
import com.google.gwt.event.dom.client.KeyPressEvent;
/**
* Entry point classes define <code>onModuleLoad()</code>.
*/
public class SW implements EntryPoint {
private RootPanel rootPanel;
private FlexTable stocksFlexTable;
private HorizontalPanel addPanel;
private VerticalPanel mainWindow;
private TextBox newSymbolTextBox;
private Button addButton;
private Label lastUpdatedLabel;
private ArrayList <String> stocks = new ArrayList<String>(); //Add this line
public void onModuleLoad() {
rootPanel = RootPanel.get();
mainWindow = new VerticalPanel();
rootPanel.add(mainWindow, 10, 10);
mainWindow.setSize("267px", "175px");
FlexTable stocksFlexTable = new FlexTable();
//Add these lines
stocksFlexTable.setText(0, 0, "Symbol");
stocksFlexTable.setText(0, 1, "Price");
stocksFlexTable.setText(0, 2, "Change");
stocksFlexTable.setText(0, 3, "Remove");
mainWindow.add(stocksFlexTable);
addPanel = new HorizontalPanel();
rootPanel.add(addPanel, 10, 200);
addPanel.setSize("267px", "68px");
newSymbolTextBox = new TextBox();
newSymbolTextBox.addKeyPressHandler(new KeyPressHandler() {
public void onKeyPress(KeyPressEvent event) {
if (event.getCharCode() == KeyCodes.KEY_ENTER){
addStock();
}
}
});
addPanel.add(newSymbolTextBox);
newSymbolTextBox.setWidth("211px");
addButton = new Button("Add");
addButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
addStock();
}
});
addPanel.add(addButton);
lastUpdatedLabel = new Label("New Label");
rootPanel.add(lastUpdatedLabel, 48, 274);
}
private void addStock() {
final String symbol = newSymbolTextBox.getText().toUpperCase().trim();
newSymbolTextBox.setFocus(true);
// Stock code must be between 1 and 10 chars that are numbers, letters, or dots.
if (!symbol.matches("^[0-9A-Z\\.]{1,10}$")) {
Window.alert("'" + symbol + "' is not a valid symbol.");
newSymbolTextBox.selectAll();
return;
}
newSymbolTextBox.setText("");
// don't add the stock if it's already in the watch list
if (stocks.contains(symbol))
return;
// add the stock to the list
int row = stocksFlexTable.getRowCount();
stocks.add(symbol);
stocksFlexTable.setText(row, 0, symbol);
// add button to remove this stock from the list
Button removeStock = new Button("x");
removeStock.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
int removedIndex = stocks.indexOf(symbol);
stocks.remove(removedIndex);
stocksFlexTable.removeRow(removedIndex + 1);
}
});
stocksFlexTable.setWidget(row, 3, removeStock);
}
}
When I run the web application, I cannot Add a stock. The program does, however, distinguish between bad stock names and acceptable ones. Instead I get an "uncaught exception escaped" error and the program doesn't really do anything. How do I troubleshoot this?
Use the debugger and single step through the code. Set a breakpoint on addStock's first line and find which line crashes. Once you find which line you then instrument the line to find out what aspect is causing the problem - assuming you can't deduce the problem by looking at the line.

GWT/JAVA - Getting an AJAX call into a dialog box

I'm new to GWT, and having an issue getting the result of an AJAX call to show up in my Dialog box.
I set up my dialog box, Vpanel, and response label here:
VerticalPanel eventDetailWindow = new VerticalPanel();
final DialogBox dialogBox2 = new DialogBox();
dialogBox2.setText("Event Detail");
dialogBox2.setAnimationEnabled(true);
final HTML serverResponse3 = new HTML("<b> ok, this is working</b>");
serverResponse3.addStyleName("detailView");
eventDetailWindow.add(serverResponse3);
eventDetailWindow.addStyleName("detailWindow");
dialogBox2.setWidget(eventDetailWindow);
RootPanel.get("detailWindow").add(eventDetailWindow);
Then, in the onSuccess method I have this:
dialogBox2.setText("Remote Procedure Call");
serverResponse3.setHTML(result);
dialogBox2.center();
closeButton.setFocus(true);
However, when it fires, the response shows up on the page, not in the dialog box and the dialog box is empty. It looks like it's set up the same as the starter project - which works fine..
Can someone help me out...?
Dont use that RootPanel.get("detailWindow").add(eventDetailWindow);
if you want to only add into dialogBox2
use like that:
dialogBox2.setWidget(eventDetailWindow);
and You dont have to add dialogBox2.show(); because dialogBox2.center(); that code will show the dialogBox2 initially.
package com.ex.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
public class Example implements EntryPoint {
public void onModuleLoad() {
VerticalPanel eventDetailWindow = new VerticalPanel();
final DialogBox dialogBox2 = new DialogBox();
dialogBox2.setText("Event Detail");
dialogBox2.setAnimationEnabled(true);
final HTML serverResponse3 = new HTML("<b> ok, this is working</b>");
serverResponse3.addStyleName("detailView");
eventDetailWindow.add(serverResponse3);
eventDetailWindow.addStyleName("detailWindow");
dialogBox2.setWidget(eventDetailWindow);
Button b= new Button("click");
b.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
dialogBox2.setText("Remote Procedure Call");
serverResponse3.setHTML("result");
dialogBox2.center();
}
});
RootPanel.get().add(b);
}
}
You are adding the eventDetailWindow to something on the page and I don't see a call to .show() on the DialogBox. Can you post your full code?

GWT ImageBundle Problem : Image Not Displaying : Code Included

I am having trouble getting images to display when using ImageBundle. I have followed the GWT tutorial as a guide however my images don't display.
I can view the images (from within Eclipse) in my browser fine - so they are definitely there. I am clearly doing something wrong when using the ImageBundle but I'm at a loss to understand what it is I am doing wrong.
The logo.jpg image should simply display itself.
The ajaxLoader.gif should display itself first (in order to cover the RPC which gets the facebook user profile data) and then it would be replaced by the image at the pic_square url.
When I look at the GWT generated html, I find that where the logo.jpg image should be, there is a gif image [http://sandpit1965.appspot.com/sandpit/clear.cache.gif] but I don't understand where this is coming from.
Any help would be appreciated - source code below.
Darren
Image Package Structure
org.redboffin.sandpit.client.icons
|___ SandpitImageBundle.java
|___ ajaxLoader.gif
|___ logo.jpeg
Relevent Classes
package org.redboffin.sandpit.client.facebook;
import org.redboffin.sandpit.client.icons.SandpitImageBundle;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ErrorEvent;
import com.google.gwt.event.dom.client.ErrorHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.AbstractImagePrototype;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DockPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.xml.client.Document;
import com.google.gwt.xml.client.Element;
import com.google.gwt.xml.client.XMLParser;
public class ProfileWidget extends Composite implements RBWidget {
// Data
private String firstName = null;
private String lastName = null;
private String picSquareUrl = null;
// Elements
private Image picSquare = new Image();
private Image logo = new Image();
private Button logoutButton = new Button("Logout");
private DockPanel panel = new DockPanel();
private HTML html = new HTML("Welcome to Sandpit.");
/**
* Create a remote service proxy to talk to the server-side User Data
* service.
*/
private final UserDataServiceAsync userDataService = GWT.create(UserDataService.class);
public ProfileWidget() {
this.rpcWidget = new RPCWidget(this);
this.initProfileImage();
this.initLogoImage();
panel.add(picSquare, DockPanel.WEST);
panel.add(html, DockPanel.CENTER);
VerticalPanel verticalPanel = new VerticalPanel();
verticalPanel.add(logo);
verticalPanel.add(logoutButton);
panel.add(verticalPanel, DockPanel.EAST);
panel.add(rpcWidget, DockPanel.SOUTH);
initWidget(panel);
}
private void initProfileImage() {
// Display ajaxLoader.gif
SandpitImageBundle sib = GWT.create(SandpitImageBundle.class);
AbstractImagePrototype aip = sib.ajaxLoader();
sib.applyTo(this.picSquare);
}
private void initLogoImage() {
// Display logo.jpg
SandpitImageBundle sib = GWT.create(SandpitImageBundle.class);
AbstractImagePrototype aip = sib.logo();
aip.applyTo(this.logo);
}
// Other methods omitted...
}
package org.redboffin.sandpit.client.icons;
import com.google.gwt.user.client.ui.AbstractImagePrototype;
import com.google.gwt.user.client.ui.ImageBundle;
public interface SandpitImageBundle extends ImageBundle {
/**
* Would match the file 'logo.jpg', 'logo.gif', or 'logo.png' located in the
* same package as this type.
*/
public AbstractImagePrototype logo();
/**
* Would match the file 'ajaxLoader.jpg', 'ajaxLoader.gif', or 'ajaxLoader.png' located in the
* same package as this type.
*/
public AbstractImagePrototype ajaxLoader();
}
I don't understand why but this now works and I haven't changed anything.
The image won't be displayed until you "compile" your project and place your generated "war" in your servers public folder. You were simply making a request to a non existing file.