I'm using GXT's Info class inside my GWT app to display messages or notifications. To make the message a little bit sticky, i implemented my own version of Info class: I created an InfoConfig
instance and set the number of milliseconds: config.display(int milliseconds);
The problem is sometimes i don't need the Info to be "sticky" so i need to hide it when i do something else: i tried to call the hide()
method but it's not working!
My implementation of Info class:
public class StickyInfo extends Info {
private static StickyInfo info = new StickyInfo();
public StickyInfo() {
super();
}
@Override
protected void onShowInfo() {
super.onShowInfo();
}
/**
* Show the message with a title for 20sec (default duration)
*
* @param title
* the title of the message.
* @param message
* the message to display.
*/
public void show(String title, String message) {
show(title, message, 20000); // for 20sec
}
/**
* Show the message with no title for 20sec (default duration)
*
* @param message
* the message to display.
*/
public void show(String message) {
show(null, message, 20000); // for 20sec
}
/**
* Show the message for the specified number of milliseconds.
*
* @param title
* the title of the message.
* @param message
* the message to display.
* @param milliseconds
* the number of milliseconds to display the message.
*/
public void show(String title, String message, int milliseconds) {
// Configuration
InfoConfig config = new DefaultInfoConfig(title, message);
config.setDisplay(milliseconds);
// Formatting
info.setStyleName("background-color:#f9ff4f;text-align:center;"
+ "border:0x solid black; padding: 3px; font-size:11px;font-weight: bold;");
info.show(config);
// Position
// Point p = info.position();
// p.setY(p.getY() + 400);
// p.setX(0);
info.setPagePosition(info.position().getX(), 55);
}
/**
* Show the message in the given position for the number of milliseconds.
*
* @param title
* the title of the message.
* @param message
* the message to display.
* @param milliseconds
* the number of milliseconds to display the message.
*/
public void show(String title, String message, int milliseconds, int pX,
int pY) {
// Configuration
InfoConfig config = new DefaultInfoConfig(title, message);
config.setDisplay(milliseconds);
// Formatting
info.setStyleName("background-color:#f9ff4f;text-align:center;"
+ "border:0x solid black; padding: 3px; font-size:11px;font-weight: bold;");
info.show(config);
// Position
// Point p = info.position();
// p.setY(p.getY() + 400);
// p.setX(0);
info.setPagePosition(pX, pY);
}
Any pointers? Thanks.
As user2043260 mentioned, i tried to override the hide()
method with following:
@Override
public void hide() {
if (info.getParent != null) {
info.removeFromParent();
}
}
And it works fine :) ! Thanks for the reminder ;)