I want to be able to add options to a right click menu of the NatTable that when clicked will cause either the row or column headers to be hidden but can be brought back as well.
The common practice is to operate on the corresponding DataLayer and modify the row height. Modifying the IDataProvider is typically not a good practice, as the IDataProvider is responsible for providing the data, not how the data should be rendered. So the following is an example of how to toggle the visibility of the column header layer (supposed that hideHeader is the flag to store the current state).
Button hideButton = new Button(buttonPanel, SWT.PUSH);
hideButton.setText("Hide/Show");
hideButton.addSelectionListener(new SelectionAdapter() {
#Override
public void widgetSelected(SelectionEvent e) {
this.hideHeader = !this.hideHeader;
if (this.hideHeader) {
columnHeaderDataLayer.setDefaultRowHeight(0);
} else {
columnHeaderDataLayer.setDefaultRowHeight(20);
}
natTable.refresh(false);
}
});
I know users who even used that approach to implement some sort of transition by slowly reducing the height to 0.
Alternatively you could use the RowResizeCommand if the column header DataLayer is not known
Button hideButton = new Button(buttonPanel, SWT.PUSH);
hideButton.setText("Hide/Show");
hideButton.addSelectionListener(new SelectionAdapter() {
#Override
public void widgetSelected(SelectionEvent e) {
this.hideHeader = !this.hideHeader;
if (this.hideHeader) {
natTable.doCommand(new RowResizeCommand(natTable, 0, 0));
} else {
natTable.doCommand(new RowResizeCommand(natTable, 0, 20));
}
}
});
I ended up solving this by changing the logic in the getColumnCount() method in my RowHeaderDataProvider to return 0 when flagged to be hidden, or 1 when flagged to be not hidden. Same applies for the getRowCount() in my ColumnHeaderDataProvider.
Related
I'm trying to set a hilite inside the record click handler of the list grid. I have tired the following code,
My hilites are as follows,
public static Hilite[] getWayBillSetHilites() {
return new Hilite[]{
new Hilite() {
{
setFieldNames("RECORD_VIEWED_STATUS");
setCriteria(new Criterion("RECORD_VIEWED_STATUS", OperatorId.EQUALS, "TRUE"));
setCssText(Constant.Css.TEXT_ITALIC_GRAY_32);
setTextColor("font-style:italic;color:#525252;");
setId("0");
}
}
};
}
record click handler of the grid appears as follows,
grid.addRecordClickHandler(new RecordClickHandler() {
#Override
public void onRecordClick(RecordClickEvent recordClickEvent) {
//gridWayBillSetGrid.getHiliteState()
//make RECORD_VIEWED_STATUS value "true"
recordClickEvent.getRecord().setAttribute("RECORD_VIEWED_STATUS", true);
gridWayBillSetGrid.enableHilite("0", true);
}
});
But when I click on the record, the styles are not showing up.
Please be kind to advise on this.
I think it's the wrong use case for hilites. Use getCellCSSText instead.
Try this one (override getCellCSSText method of ListGrid class):
ListGrid grid = new ListGrid(...){
#Override
protected String getCellCSSText(ListGridRecord record, int rowNum, int colNum) {
if("true".equalsIgnoreCase(record.getAttribute("RECORD_VIEWED_STATUS"))){
return "font-style:italic;color:#525252;";
}
return super.getCellCSSText(record, rowNum, colNum);
}
};
we would like to link from a CellTable to a property editor page. We use the SingleSelectionModel to get notified, when a user clicks on an item.
It is initialized like this:
private final SingleSelectionModel<Device> selectionModel = new SingleSelectionModel<Device>();
We then assign the selection change handler:
selectionModel.addSelectionChangeHandler(this);
Our selection change handler looks like this:
#Override
public void onSelectionChange(SelectionChangeEvent event) {
Log.debug("DevicesPresenter: SelectionChangeEvent caught.");
Device selectedDevice = selectionModel.getSelectedObject();
if (selectedDevice != null) {
selectionModel.clear();
if (selectionModel.getSelectedObject() != null){
Log.debug("DevicesPresenter: selected item is " + selectionModel.getSelectedObject());
}
else{
Log.debug("DevicesPresenter: selected item is null");
}
deviceEditorDialog.setCurrentDevice(selectedDevice.getUuid());
// get the container data for this device
clientModelProvider.fetchContainersForDevice(selectedDevice.getUuid());
PlaceRequest request = new PlaceRequest.Builder()
.nameToken(NameTokens.deviceInfo)
.with("uuid", selectedDevice.getUuid())
.build();
Log.debug("Navigating to " + request.toString());
placeManager.revealPlace(request);
}
}
Now there are two issues: There always seem to be two SelectionChangeEvents at once and i really cannot see why. The other thing is: How is the right way do handle selection of items and the related clearing of the selection model? Do we do that the right way?
Thanks!
If you only want to get notified of "clicks" without keeping the "clicked" item selected, use a NoSelectionModel instead; no need to clear the selection model as soon as something is selected.
As for your other issue with being called twice, double-check that you haven't added your selection handler twice (if you can unit-test your DevicesPresenter, introspect the handlers inside the selection model for example)
In your line selectionModel.addSelectionChangeHandler(this); what does this refer?
Here my code how I use SingleSelectionModel
public class MyClass{
private final SingleSelectionModel<CountryDto> selectionModel = new SingleSelectionModel<CountryDto>();
...
public MyClass(){
cellTable.setSelectionModel(selectionModel);
selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
#Override
public void onSelectionChange(SelectionChangeEvent event) {
CountryDto selected = selectionModel
.getSelectedObject();
if (selected != null) {
Window.alert("Selected country "+selected.getTitle());
}
}
});
}
}
I currently have firstGrid that has some records, I have set a warning on removal message so a dialog box pops up when I click the delete button. How do I make it so secondGrid refresh when I confirm the delete on firstGrid?
firstGrid.setWarnOnRemoval(true);
firstGrid.setWarnOnRemovalMessage("Delete?");
SmartGwt doesn't support a customized behavior for this operation. You should program it by yourself.
Just create a new ListGridField and refresh your second grid in the CallBack after the remove operation. Your first approach could be the following:
ListGridField removeListGridField = new ListGridField("removeButton", 20);
removeListGridField.setType(ListGridFieldType.ICON);
removeListGridField.setCellIcon("[SKIN]actions/remove.png");
removeListGridField.setCanEdit(false);
removeListGridField.setCanFilter(false);
removeListGridField.setCanGroupBy(false);
removeListGridField.setCanSort(false);
removeListGridField.setCanDragResize(false);
removeListGridField.setCanFreeze(false);
removeListGridField.setCanHide(false);
removeListGridField.addRecordClickHandler(new RecordClickHandler()
{
#Override
public void onRecordClick(RecordClickEvent event)
{
if (event.getRecord() == null) // local record
{
discardEdits(event.getRecordNum(), 0);
yourGrid.fetchData();
}
else
removeData(event.getRecord(), new DSCallback()
{
#Override
public void execute(DSResponse dsResponse, Object data, DSRequest dsRequest)
{
yourGrid.fetchData();
}
});
}
});
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.
EDIT: This seems to be a bug.
I'm trying to make CellTable work together with AsyncListViewAdapter<T> and SimplePager<T>. The data gets displayed, but when the pager should be 'deaf' (meaning when all existing data are displayed) it still receives clicks and, more importantly, makes the displayed data go away. Instead of my data 'loading' indicator gets displayed, and it keep loading and loading... Obviously nothing gets loaded, as it doesn't even call the onRangeChanged handler.
I went through the code-snippets in this thread, but I can't see anything suspicions on what I've been doing.
Is there some obvious answer to a rookie mistake?
I shrinked my variable names, hopefully it won't wrap too much.
protected class MyAsyncAdapter
extends AsyncListViewAdapter<DTO> {
#Override
protected void onRangeChanged(ListView<DTO> v) {
/*
* doesn't even get called on [go2start/go2end] click :(
*/
Range r = v.getRange();
fetchData(r.getStart(), r.getLength());
}
}
private void addTable() {
// table:
CellTable<DTO> table = new CellTable<DTO>(10);
table.addColumn(new Column<DTO, String>(new TextCell()) {
#Override
public String getValue(DTO myDto) {
return myDto.getName();
}
}, "Name");
// pager:
SimplePager<DTO> pager = new SimplePager<DTO>(table);
table.setPager(pager);
adapter = new MyAsyncAdapter();
adapter.addView(table);
// does not make any difference:
// adapter.updateDataSize(0, false);
// adapter.updateDataSize(10, true);
VerticalPanel vPanel = new VerticalPanel();
vPanel.add(table);
vPanel.add(pager);
RootLayoutPanel.get().add(vPanel);
}
// success-handler of my fetching AsyncCallback
#Override
public void onSuccess(List<DTO> data) {
// AsyncCallback<List<DTO>> has start field
adapter.updateViewData(start, data.size(), data);
if(data.size() < length)
adapter.updateDataSize(start + data.size(), true);
}
Regards
J. Záruba
Apparently because of a bug.