GWT - Using a Checkbox as the header of a DisclosurePanel - gwt

I'm trying to create a DisclosurePanel that uses a Checkbox for a header. However, when I set this up, clicking on the Checkbox only opens and closes the DisclosurePanel; it doesn't check or uncheck the box. Anyone know how to make this happen?

Just add handlers to the open / close events and set the value of the checkbox there:
disclosurePanel.addOpenHandler<DisclosurePanel>(new OpenHandler<DisclosurePanel>() {
#Override
public void onOpen(OpenEvent<DisclosurePanel> event) {
checkbox.setValue(true);
}
));
disclosurePanel.addCloseHandler<DisclosurePanel>(new CloseHandler<DisclosurePanel>() {
#Override
public void onClose(CloseEvent<DisclosurePanel> event) {
checkbox.setValue(false);
}
));

Related

addValueChangeHandler of gxt ComboBox only fired on focus on another field

I have form with several GWT GXT 3 fields, one of which is a combo box.
When the combo box changes it should call a doSomething method.
My problem is that the onValueChange is only fired when I focus on another form field.
I would like that it changed just when I select an item of the combo box.
How can I do it?
This is part of my code.
final ComboBox<DropDownItemDTO> field = new ComboBox<DropDownItemDTO>(storeCombo, propsTitoliRioComboItemDTO.label());
...
field.addValueChangeHandler(new ValueChangeHandler<DropDownItemDTO>() {
#Override
public void onValueChange(ValueChangeEvent<DropDownItemDTO> event) {
if (event.getValue()!=null) {
value.setFieldValue(event.getValue().getValue());
} else {
value.setFieldValue("");
}
doSomething(event.getValue().getValue());
}
});
I ended up using SelectionHandler, which fires right away on selection
field.addSelectionHandler(new SelectionHandler<DropDownItemDTO>() {
#Override
public void onSelection(SelectionEvent<DropDownItemDTO> event) {

GWT - enable button on KeyDownEvent in RichTextArea

I have following handler
textArea.addKeyDownHandler(new KeyDownHandler() {
#Override
public void onKeyDown(KeyDownEvent event) {
//here
}
});
I need to enable save button with id "idsave", but I am not able to refer the button.
I am new to GWT, any help would be appreciated.
Typically, you do not use element ids in GWT. If you created a button, you can simply use it:
private Button saveButton;
...
saveButton = new Button("Save");
textArea.addKeyDownHandler(new KeyDownHandler() {
#Override
public void onKeyDown(KeyDownEvent event) {
saveButton.setEnabled(true);
}
});
If you don't have the reference of the button then try with the id.
// get element by id
Element saveButtonElement = RootPanel.get("idsave").getElement();
// remove disabled attribute to make it enable
saveButtonElement.removeAttribute("disabled");

GXT3 - Editable Grid: display the row to edit in a popup

GXT3 - Grid: Adding a column with a button to modify row in Editable Grid
In the example the line is editable automatically when line is selected.
http://www.sencha.com/examples/#Exam...oweditablegrid
I want the line to be changed when I click on the edit button that would appear in a popup.
TextButtonCell button = new TextButtonCell();
button.addSelectHandler(new SelectHandler() {
#Override
public void onSelect(SelectEvent event) {
Context c = event.getContext();
Info.display("Event", "Call the popup here.");
}
});
nameColumn.setCell(button);
There is a way do get this?
Thanks in advance for your help.
First of all you have yo create a column with TextBoxCell which may you already created.
Then you have to disable default onclick editable behavior of grid.
For that as per Sencha example's file RowEditingGridExample.java you can override onClick event and prevent to fire default code.
public class RowEditingGridExample extends AbstractGridEditingExample {
#Override
protected GridEditing<Plant> createGridEditing(Grid<Plant> editableGrid) {
return new GridRowEditing<Plant>(editableGrid){
#Override
protected void onClick(ClickEvent event) {
}
};
}
}
And when you click on textBoxCell click handler you can start editing manually.
TextButtonCell button = new TextButtonCell();
button.addSelectHandler(new SelectHandler() {
#Override
public void onSelect(SelectEvent event) {
Context c = event.getContext();
//Here you can pass a new GridCell like with proper cell index and row index.
GridCell cell = new GridCell(getRowIndex(), getCellIndex());
editing.startEditng(cell);
}
});
nameColumn.setCell(button);
If you want to appear row editor in separate popup you have to design it manually.

GWT checkbox hides/shows widget

How to add clickHandler to a gwt checkbox, so that when the checkbox is checked, a listbox is shown and when it is unchecked, the listbox disappears?
Following is what I have so far. When I check the checkbox, the list appears, but when I uncheck it, the listbox does not disappear.
VerticalPanel vPanel = new VerticalPanel();
ListBox list = new listBox();
list.setVisible(false);
vPanel.add(list);
.....
.....
checkBox.addClickHandler(new ClickHandler()
{
public void onClick(ClickEvent event)
{
boolean checked =((CheckBox) event.getSource()).isEnabled();
if(checked==true)
{
list.addItem("a");
list.addItem("b");
list.addItem("c");
list.setVisible(true);
}
else if(checked==false)
{
componentList.setVisible(false);
}
}
});
Thanks so much in advance.
A better way to do it is to do the value changed handler. The user can even use the keyboards to check the checkbox!
CheckBox c = new CheckBox();
c.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
#Override
public void onValueChange(ValueChangeEvent<Boolean> event) {
componentList.setVisible(event.getValue());
}
});
}
edit -
You should add the items in the list outside. And, depending on the default checkbox value,(checked or unchecked), set the component visible or hidden outside itself in the start.
enabled != checked! (use isChecked or getValue)
Otherwise, go with Bhat's code and advises.

GWT: context menu in RichTextArea

I'm using a RichTextArea in a GWT app. I want to add a context menu to my RichTextArea:
public class MyRichTextArea extends RichTextArea implements HasContextMenuHandlers {
public HandlerRegistration addContextMenuHandler(ContextMenuHandler h) {
return addDomHandler(h, ContextMenuEvent.getType());
}
}
(...)
myRichTextArea.addContextMenuHandler(new ContextMenuHandler() {
public void onContextMenu(ContextMenuEvent event) {
contextMenu.show();
}
});
This works, however, the context menu only appears when I right-click on the border of the RichTextArea. If I right-click into the RichTextArea, e.g. on the contained text, the browser's default context menu is shown.
How can I display my own context menu?
Prevent default context memu:
myRichTextArea.addDomHandler(new ContextMenuHandler() {
#Override public void onContextMenu(ContextMenuEvent event) {
event.preventDefault();
event.stopPropagation();
// do what you want to do instead
}
}, ContextMenuEvent.getType());
I would go after a method that tells you that the rich text area has the focus, like hasfocus, or maybe better, an event listener (addFocusListener) to tell you when the focus is there on a mouse click for the right mouse button?
Does that make sense?