How to get current row (element) on TreeEditor Button click event - swt

TreeViewerColumn colEdit= new TreeViewerColumn (viewer, column);
colEdit.setLabelProvider(new ColumnLabelProvider(){
#Override
public void update(ViewerCell cell) {
TreeItem item = (TreeItem) cell.getItem();
Button btnEdit= new Button((Composite) cell.getViewerRow().getControl(),SWT.NONE);
btnEdit.setText("Edit");
TreeEditor editor = new TreeEditor(item.getParent());
editor.grabHorizontal = true;
editor.grabVertical = true;
editor.setEditor(btnEdit, item, cell.getColumnIndex());
editor.layout();
btnEdit.addSelectionListener(new SelectionAdapter() {
#Override
public void widgetSelected(SelectionEvent e) {
// How to get current row element.
TreeItem[] selection = treeViewer.getTree().getSelection(); // (Selection is empty, because click on button and selection not happened)
}
});
}
});
treeViewer.getTree().getSelection(); return empty because Tree Editor with button control added and while button click row selection not happening.
cell.getElement() returning null in handler method.
btnEdit.setData can help me but Is there any way to get current row (element) on which button click event it clicked ??

Related

Swap the type of link depending on model object

I'm at complete loss how to proceed further:
I have panel with a DropDownChoice and a submit button next to it. Depending on the selected value of the DropDownChoice (Obtained upon the firing of a OnChangeAjaxBehavior attached to it, the submit button needs to either replace the whole panel with a different one, OR become an ExternalLink.
Currently, the code looks like that:
public class ReportSelectionPanel extends Panel {
protected OptionItem selectedOption ;
public ReportSelectionPanel(String id) {
super(id);
IModel<List<OptionItem>> choices = new AbstractReadOnlyModel() {
// Create a list of options to be displayed in the DropDownChoice
} ;
final IModel<OptionItem> optionModel =
new PropertyModel<OptionItem>(this,"selectedOption") ;
final DropDownChoice<OptionItem> options =
new DropDownChoice("selectChoice",optionModel,choices) ;
// I don't know what the button should be... Plain Button? A Link?
final Component button = ???
options.add( new OnChangeAjaxBehavior() {
protected void onUpdate(AjaxRequestTarget target) {
if ( selectedOption.getChild() == null ) {
// button becomes an ExternalLink.
// A new window will popup once button is clicked
} else {
// button becomes a Something, and upon clicking,
// this ReportSelectionPanel instance gets replaced by
// an new Panel instance, the type of which is
// selectedOption.getChild()
}
} ) ;
I'm really not quite sure what the commented lines should become to achieve the result. Any suggestions?
Thanks!
Eric
IMHO it's nicer to keep just one button and just react differently depending on the selected option:
final Component button = new AjaxButton("button") {
public void onClick(AjaxRequestTarget target) {
if (selectedOption.getChild() == null) {
PopupSettings popup = new PopupSettings();
popup.setTarget("'" + externalUrl + "'");
target.appendJavascript(popup.getPopupJavaScript());
} else {
ReportSelectionPanel.this.replaceWith(new ReportResultPanel("..."));
}
}
};
// not needed if options and button are inside a form
// options.add( new OnChangeAjaxBehavior() { } ) ;

Close picklist of select item smartgwt

I have the following requirement.
There is a select item which has a pickList which is a ListGrid with check boxes for multiple selection.
Once the user selects the records then user has to manually click on the picklisticon (down arrow just beside (right) to the select item) or he can click anywhere out side of the select item to close the pickList.
Now i want to close this pickList when the mouse moves out of the listGrid (pickList) after user selects the records he wants to.
This is because ,after selecting the records there is a button which user clicks to save the form. With Picklist being closed only when he manually clicks the down arrow or anywhere outside of the select item and then click on the apply button.
Is there any way i can achieve this functionality?
Following is the code
VLayout layout = new VLayout();
final ButtonItem button = new ButtonItem("button","Apply");
button.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
SC.say("You clicked me");
}
});
final ListGrid pickListProperties = new ListGrid();
pickListProperties.setShowHeader(true);
pickListProperties.setCanGroupBy(false);
pickListProperties.setAutoFetchData(true);
pickListProperties.addMouseOutHandler(new MouseOutHandler() {
#Override
public void onMouseOut(MouseOutEvent event) {
GWT.log("Closing the pick list of the select item");
pickListProperties.hide(); // Not sure how to get the arrow down item and fire the click event on this so that pickList is closed.
button.focusInItem();
}
});
ListGridField descrField = new ListGridField("description","Names");
DataSourceTextField dsField = new DataSourceTextField("description","Names");
dsField.setMultiple(true);
DataSource optionalDS = new DataSource();
optionalDS.setDataURL(GWT.getModuleBaseForStaticFiles()+"optional.xml");
optionalDS.setFields(dsField);
final SelectItem selectItem = new SelectItem("Name","Select");
selectItem.setPickListHeight(100);
selectItem.setSelectOnFocus(true);
selectItem.setPickListFields(descrField);
selectItem.setPickListProperties(pickListProperties);
selectItem.setPickListWidth(350);
selectItem.setOptionDataSource(optionalDS);
selectItem.setMultiple(true);
selectItem.setAllowEmptyValue(false);
selectItem.setMultipleAppearance(MultipleAppearance.PICKLIST);
// selectItem.sett trigger
DynamicForm hdf = new DynamicForm();
hdf.setFields(selectItem,button);
layout.addMember(hdf);

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 button click event

i have one window panel in my project.
and i add one button to it.
when i click the button,i want two event to fire.
one event is to hide that window,which i achieve through
Button button = new Button("click");
button.addListener(new ButtonListenerAdapter(){
#Override
public void onClick(Button button, EventObject e) {
hide();
super.onClick(button, e);
}
});
Window.add(button);
and second i want to pop up another window at the same time on the same button click..what to do?
help me out
I think this should solve your problem :
final boolean evenClick = false;
Button button = new Button("click");
button.addListener(new ButtonListenerAdapter(){
#Override
public void onClick(Button button, EventObject e) {
if (!evenClick) {
hide();
super.onClick(button, e);
}
else {
//DO YOUR SECOND CLICK STUFF
}
evenClick = !evenClick;
}
});
Window.add(button);

SWT: show popup menu below toolbar button after clicking on it

I want to show a popup menu below a toolbar button when the user clicks this button. I've read about the SWT.DROP_DOWN style for a ToolItem but this seems very much limited to a simple list of items according to this sample. Instead, I want to show a popup menu with, e.g., checkbox and radio button menu items.
You can make MenuItem with styles SWT.CHECK, SWT.CASCADE, SWT.PUSH, SWT.RADIO, SWT.SEPARATOR
see javadoc..
So you can "hang" swt menu to selection of dropdown on toolbar item like this
public class Test {
private Shell shell;
public Test() {
Display display = new Display();
shell = new Shell(display, SWT.SHELL_TRIM);
shell.setLayout(new FillLayout(SWT.VERTICAL));
shell.setSize(50, 100);
ToolBar toolbar = new ToolBar(shell, SWT.FLAT);
ToolItem itemDrop = new ToolItem(toolbar, SWT.DROP_DOWN);
itemDrop.setText("drop menu");
itemDrop.addSelectionListener(new SelectionAdapter() {
Menu dropMenu = null;
#Override
public void widgetSelected(SelectionEvent e) {
if(dropMenu == null) {
dropMenu = new Menu(shell, SWT.POP_UP);
shell.setMenu(dropMenu);
MenuItem itemCheck = new MenuItem(dropMenu, SWT.CHECK);
itemCheck.setText("checkbox");
MenuItem itemRadio = new MenuItem(dropMenu, SWT.RADIO);
itemRadio.setText("radio1");
MenuItem itemRadio2 = new MenuItem(dropMenu, SWT.RADIO);
itemRadio2.setText("radio2");
}
if (e.detail == SWT.ARROW) {
// Position the menu below and vertically aligned with the the drop down tool button.
final ToolItem toolItem = (ToolItem) e.widget;
final ToolBar toolBar = toolItem.getParent();
Point point = toolBar.toDisplay(new Point(e.x, e.y));
dropMenu.setLocation(point.x, point.y);
dropMenu.setVisible(true);
}
}
});
shell.open();
while(!shell.isDisposed()) {
if(!display.readAndDispatch()) display.sleep();
}
display.dispose();
}
public static void main(String[] args) {
new Test();
}
}