Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

TUTORIALVaadin lets you build secure, UX-first PWAs entirely in Java.
Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
retrieve the current view from navigator? by Martin Vyšný, 1 month ago
How get reference to main window
Hi I've decided to develop my first component form eclipse plugin .Code is litte bit changed to handle my own message. Question is how to get refernce to mainWindow I want to add new window after click. All info i have found is linked to Application not the widget.
public class Box extends AbstractComponent {
private String message;
private int clicks = 0;
public Box(String m){
this.message = m;
}
@Override
public void paintContent(PaintTarget target) throws PaintException {
super.paintContent(target);
// Paint any component specific content by setting attributes
// These attributes can be read in updateFromUIDL in the widget.
target.addAttribute("clicks", clicks);
target.addAttribute("message", message);
// We could also set variables in which values can be returned
// but declaring variables here is not required
}
@Override
public void changeVariables(Object source, Map<String, Object> variables) {
super.changeVariables(source, variables);
if (variables.containsKey("click")) {
clicks++;
message += "<br/>" + variables.get("click");
requestRepaint();
}
}
}
public class VBox extends Widget implements Paintable, ClickHandler {
public static final String CLASSNAME = "v-box";
public static final String CLICK_EVENT_IDENTIFIER = "click";
protected String paintableId;
protected ApplicationConnection client;
public VBox() {
setElement(Document.get().createDivElement());
setStyleName(CLASSNAME);
sinkEvents(Event.ONCLICK);
addDomHandler(this, ClickEvent.getType());
}
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
if (client.updateComponent(this, uidl, true)) {
return;
}
this.client = client;
paintableId = uidl.getId();
int clicks = uidl.getIntAttribute("clicks");
String message = uidl.getStringAttribute("message");
getElement().setInnerHTML("After <b>"+clicks+"</b> mouse clicks:\n" + message);
}
public void onClick(ClickEvent event) {
String button = "left click";
client.updateVariable(paintableId, CLICK_EVENT_IDENTIFIER, button, true);
}
}
public class El_6Application extends Application {
private static final long serialVersionUID = -7939428060094466420L;
@Override
public void init() {
Window mainWindow = new Window("MyAppt");
setTheme("el_6theme");
setMainWindow(mainWindow);
mainWindow.setImmediate(true);
Box a = new Box("message");
mainWindow.addComponent(a);
}
}
Last updated on May, 24th 2012
Ok i found the solution :P:
public class Box extends AbstractComponent {
[b]Window myWindow; // The window to be opened[/b]
private String message;
private int clicks = 0;
public Box(String m){
this.message = m;
}
@Override
public void paintContent(PaintTarget target) throws PaintException {
super.paintContent(target);
target.addAttribute("clicks", clicks);
target.addAttribute("message", message);
// We could also set variables in which values can be returned
// but declaring variables here is not required
}
@Override
public void changeVariables(Object source, Map<String, Object> variables) {
super.changeVariables(source, variables);
// Variables set by the widget are returned in the "variables" map.
if (variables.containsKey("click")) {
[b]myWindow = new Window("A subwindow");
getWindow().addWindow(myWindow);[/b]
clicks++;
message += "<br/>" + variables.get("click");
requestRepaint();
}
}
}
Last updated on May, 24th 2012
You cannot reply to this thread.