I have a button that decorates user ClickHandler with my one which controls button state -> makes it disabled on click preventing multiple clicks. When user clicks on it - corresponding DialogBox is opened and button becomes disabled. Here is my button:
public class MyButton extends Button {
private boolean isButtonClicked = false;
private ClickHandler clickHandler;
public MyButton(String html) {
this(html, null);
}
public MyButton(String html, final ClickHandler handler) {
super(html);
addClickHandler(handler);
}
public HandlerRegistration addClickHandler(final ClickHandler handler) {
clickHandler = handler;
ClickHandler ch = new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
if(!isButtonClicked) {
isButtonClicked = true;
setEnabled(false);
clickHandler.onClick(event); //Here is a click handler initiated on fly
}
}
};
return super.addClickHandler(ch);
}
}
And this is how it is used:
public TestClass {
protected OneClickButton button = new OneClickButton("Test Button);
//...
button.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
SomeDialogWindow dialog = new SomeDialogWindow(/*args*/);
dialog.center();
}
});
}
When I click on a button it becomes disabled and dialog appears. But when I close the dialog, my button remains disabled. How to set button enable back on dialog close? What event and where should I handle on order to achieve this?
If your SomeDialogWindow extendes DIalogBox..you can do this
dialog.addCloseHandler(new CloseHandler<PopupPanel>() {
public void onClose(com.google.gwt.event.logical.shared.CloseEvent<PopupPanel> event) {
yourbutton.setEnabled(true);
};
});
Related
I've tried to add a method inside MyUi.java class in vaadin, but all I get are errors. So, is it actually possible to do so? The reason why I ask is this: basically MyUi.java class has a button which when clicked opens up another window (the code for this other window sits in a different class). This button is removed (button.setVisible(false);) when clicked and I added a addCloseListener to the new window so that when that window is closed it fires an event and calls a function which will allow me to re-display the button. This function needs to sit inside the MyUi class as I can't figure out how to access the button which currently sits inside MyUi class from a different class.
Some code to make things a little clearer: MyUi.java contains the button
public class MyUI extends UI {
#Override
protected void init(VaadinRequest vaadinRequest) {
final VerticalLayout layout = new VerticalLayout();
final NewWindow newWindow = new NewWindow();
final UploaderComponent uploaderComponent = new UploaderComponent();
//final TextField name = new TextField();
// name.setCaption("Type your name here:");
final Button button = new Button("Click Me");
button.addClickListener(new Button.ClickListener()
{
#Override
public void buttonClick(ClickEvent event)
{
//button.setVisible(false);
// TODO Auto-generated method stub
getUI().addWindow(newWindow.getWindow());
newWindow.getWindow().setContent(uploaderComponent.formLayout);
}
});
layout.addComponents(button );
layout.setMargin(true);
layout.setSpacing(true);
setContent(layout);
public void testMethod(){//produces errors
}
}
}
And the window class:
public class NewWindow
{
//public static final Sizeable.Unit PIXELS;
Window window = new Window();
public NewWindow(){
window.setStyleName("wrappingWindow");
window.setWidth("620px");
window.center();
window.addCloseListener(new CloseListener()
{
#Override
public void windowClose(CloseEvent e)
{
System.out.println("window closed");
}
});
}
public Window getWindow(){
return window;
}
}
Hj. I have a combobox in Javafx.
Initially, I am in AVAILABLE. Then I press the combobox to choose 'AUXUALY' state, it will pop up a dialog to confirm 'AUXUALY' or not. The issue happens when I cancel the pop-up, I can not catch event click to 'AUXUALY' in the next click.
Looking to the attached image, it seems we are still in 'AUXUALY' state because I can see a rectangle covering the 'AUXUALY' button. I can catch event only if I select the LOGOUT state.
Is there anyone here suggest me to overcome this problem?
class MyCombobox extends Combox{
this.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) { // can not catch event here after canceling the dialog
if change = 'AVAILABLE' then
if change = 'AUXUALY' then PopUp.getinstance().showDialog();
if change = 'LOGOUT' then
}
}
class PopUp extends Window{
btOk.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent t) {
...
}
btCancel.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent t) {
hide();
}
public void showDialog(){
this.show();
}
}
I have a checkbox button based on which I want to set a variable as true or false. But I don't know how to handle the event. Here's my code:
Boolean check = false;
Button checkBox = new Button(composite,SWT.CHECK);
checkBox.setText("CheckBox");
checkBox.addSelectionListener(new SelectionAdapter() {
#Override
public void widgetSelected(SelectionEvent event) {
if (event.detail == SWT.CHECK) {
// Now what should I do here to get
// Whether it is a checked event or unchecked event.
}
}
});
To validate selection use getSource() method of event to get object(Button) and check is it selected:
checkBox.addSelectionListener(new SelectionAdapter() {
#Override
public void widgetSelected(SelectionEvent event) {
Button btn = (Button) event.getSource();
System.out.println(btn.getSelection());
}
});
I have a MenuItem that has a ScheduledCommand attached. When the user clicks on the menu, a new PopupPanel appears that has autoHide enabled. Now when the user clicks on the MenuItem while the popup is open, the panel gets closed, but immediately opens again as the PopupPanel's close event fires as a click event on the menu item. Can somebody tell me how can I prevent the PopupPanel from opening in this case?
My code is something like this:
#UiField
protected MenuItem menuItem;
....
menuItem.setScheduledCommand(new ScheduledCommand() {
#Override
public void execute() {
PopupPanel window = new PopupPanel();
window.init();
window.addCloseHandler(new CloseHandler<PopupPanel>() {
#Override
public void onClose(final CloseEvent<PopupPanel> event) {
// TODO Maybe something here?
}
});
window.show();
}
});
Create a single instance for the popup and use PopupPanel#isShowing method to hide or show the popup.
public class MyMenuClass{
private PopupPanel window;
....
....
menuItem.setScheduledCommand(new ScheduledCommand() {
#Override
public void execute() {
if(window==null){
window = new PopupPanel(true);
window.add(new Label("Hello close me!!!"));
}
if(window.isShowing()){
window.hide();
}else{
window.show();
}
}
}
OK, I managed to do this by checking whether the last hovered element on the Menubar was the menuItem that opens the window. To do this, I had to subclass the default MenuBar class and exposing the getSelectedItem() method (it was protected by default, why?)
#UiField
MyMenuBar myMenuBar;
....
menuItem.setScheduledCommand(new ScheduledCommand() {
#Override
public void execute() {
if (!wasHoveredWhenClosed) {
window.init();
window.addCloseHandler(new CloseHandler<PopupPanel>() {
#Override
public void onClose(final CloseEvent<PopupPanel> event) {
wasHoveredWhenClosed = myMenuBar.getSelectedItem() != menuItem;
}
});
window.show();
} else {
wasHoveredWhenClosed = false;
}
}
});
I've one Label in my custom FlowPanel which implements HasDoubleClickHandlers.
final Label label = new Label("Click here to write");
label.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
clicked();
}
});
final CustomFlowPanel customFlowPanel=new CustomFlowPanel();
customFlowPanel.addDoubleClickHandler(new DoubleClickHandler() {
#Override
public void onDoubleClick(DoubleClickEvent event) {
if (event.getSource() instanceof FlowPanel) {
doubleClicked();
}
}
});
custoFlowPanel.add(label);
The problem is when i double click to the label doubleClicked() should not execute.
How to prevent executing doubleClicked() when label is double clicked?
Thanks in advance!!!
You could just check the DoubleClickEvent if the label was clicked and if not you call doubleClicked().
customFlowPanel.addDoubleClickHandler(new DoubleClickHandler() {
#Override
public void onDoubleClick(DoubleClickEvent event) {
Element clicked = event.getNativeEvent();
if (!clicked.Equals(label.getElement())
{
doubleClicked();
}
}
});
I haven't tried it yet, but try adding a double click handler on the label and use Event.stopPropagation() on it. This prevents the event from being propagated to the parent.