Opening Toolkit Window near Button
This is very small guide to help you alter Button so it sends actual click location to server.
I wrote small example on topic to forum but it got lost during hsqldb-crash.
By default clickable Button sends boolean variable "state" = "true" to server. First thing you need it to send "clientY" and "clientX" instead of "state".
Alter com.itmill.toolkit.terminal.gwt.client.ui.IButton#IButton()s anonymous ClickListener? to:
IButton.this.setFocus(true); Event e = DOM.eventGetCurrentEvent(); int clientX = DOM.eventGetClientX(e); int clientY = DOM.eventGetClientY(e); client.updateVariable(id, "clientX", clientX, false); client.updateVariable(id, "clientY", clientY, true);
Now, clicking Button in UI sends click location to server. Now IButton's server side component needs few alterations (com.itmill.toolkit.ui.Button).
Let's edit Button#paintContent(PaintTarget? target) first so it really adds those clientX and clientY variables:
public void paintContent(PaintTarget target) throws PaintException {
super.paintContent(target);
- if (isSwitchMode()) {
- target.addAttribute("type", "switch");
- }
boolean state;
try {
state = ((Boolean) getValue()).booleanValue();
} catch (final NullPointerException e) {
state = false;
}
- target.addVariable(this, "state", state);
+ if (isSwitchMode()) {
+ target.addAttribute("type", "switch");
+ target.addVariable(this, "state", state);
+ } else {
+ target.addVariable(this, "clientX",-1);
+ target.addVariable(this, "clientY",-1);
+ }
}
Change Button#changeVariables
@@ -159,26 +162,23 @@
final Boolean newValue = (Boolean) variables.get("state");
final Boolean oldValue = (Boolean) getValue();
- if (isSwitchMode()) {
+ // For switch button, the event is only sent if the
+ // switch state is changed
+ if (newValue != null && !newValue.equals(oldValue) && !isReadOnly()) {
+ setValue(newValue);
+ fireClick();
+ }
- // For switch button, the event is only sent if the
- // switch state is changed
- if (newValue != null && !newValue.equals(oldValue)
- && !isReadOnly()) {
- setValue(newValue);
- fireClick();
- }
- } else {
+ } else if (!isReadOnly() && variables.containsKey("clientX")) {
+ // Only send click event if the button is pushed
+ final Integer clientX = (Integer) variables.get("clientX");
+ final Integer clientY = (Integer) variables.get("clientY");
+ final Boolean oldValue = (Boolean) getValue();
+ fireClick(clientX, clientY);
- // Only send click event if the button is pushed
- if (newValue.booleanValue()) {
- fireClick();
- }
-
- // If the button is true for some reason, release it
- if (oldValue.booleanValue()) {
- setValue(new Boolean(false));
- }
+ // If the button is true for some reason, release it
+ if (oldValue.booleanValue()) {
+ setValue(new Boolean(false));
}
}
}
And finally alter ClickEvent? so listener can get Events location:
@@ -262,7 +262,8 @@
* @since 3.0
*/
public class ClickEvent extends Component.Event {
-
+ private int clientX = -1;
+ private int clientY = -1;
/**
* Serial generated by eclipse.
*/
@@ -278,6 +279,12 @@
super(source);
}
+ public ClickEvent(Component source, int positionX, int positionY) {
+ this(source);
+ clientX = positionX;
+ clientY = positionY;
+ }
+
/**
* Gets the Button where the event occurred.
*
@@ -286,6 +293,14 @@
public Button getButton() {
return (Button) getSource();
}
+
+ public int getClientX() {
+ return clientX;
+ }
+
+ public int getClientY() {
+ return clientY;
+ }
}
/**
@@ -333,5 +348,7 @@
protected void fireClick() {
fireEvent(new Button.ClickEvent(this));
}
-
+ protected void fireClick(int clientX, int clientY) {
+ fireEvent(new Button.ClickEvent(this,clientX,clientY));
+ }
}
Attachments
- Button.diff (3.6 kB) - added by Mauno Haukila 2 months ago.
- IButton.diff (1.2 kB) - added by Mauno Haukila 2 months ago.
-
TicketButtonClickPosition.java
(1.1 kB) - added by Mauno Haukila
2 months ago.
Test application
