Getting the selectionLayer.getSelectedCells() as empty but not always - java

When I select a cell and start typing any value it edits the cell.
But when I am sorting few columns(2 to 3) by default using this code below,
natTable.doCommand(new SortColumnCommand(sortHeaderLayer, i, true, sortColumn.getSortDirection()));
and then select cell and start typing for first time or maybe first few times it edits then it won't.
When I debug the code I found that I was getting the selected Cells as empty after few successful editing, and that happens randomly like sometimes after 1 or 2 or 4 .. successful editing, then the selected Cell becomes empty. The cell is selected and is clearly visible but still we get empty in the code.
ActivateEditorAction.run()
The above code is used for the Action for the cell editing on selection. In the else block of the synchronized block when we are checking for isSelectionAndTypedKeyValidForEditing(), there the selected cells is coming as empty, not always but once it starts coming as empty then it keeps on coming as empty all the time even though selection is visible on the table.
Code for the function isSelectionAndTypedKeyValidForEditing()

There are certain events that cause a selection clearing. By default sorting is causing such an event.
If you are using GlazedLists you should also be aware that there are multiple events that are fired in case of sorting. The GlazedListsEventLayer tries to squash those events to a single event, but for huge lists it can happen that still multiple events are fired if the time frame in which GlazedLists is firing events is longer than the squashing time.
Maybe you are hitting a concurrency issue somewhere. There is not enough information about your NatTable setup and too much custom code that overrides the default configuration.
Apart from this information it seems to be a quite specific issue that depends on your configuration and your custom code. And that seems to be much more complicated than to be solved easily via Stackoverflow. IMHO you need professional support in this area. Some project members offer sponsored support in that area.

Related

JTextPane and undo manager style change

My situation: I have a JTextPane with its own syntax highlighting. I have it set so that when the user stops typing, it updates the style in the text using the setCharacterAttributes() method.
My Issue: When these updates to the style are not performed, the undo manager works as expected. But when I do use it, the undo manager counts those style changes as actual undo-able actions! Meaning hitting Ctrl+z (I have it bound to undo when pressed) it just un-colors the last character i typed. Rather than actually removing/undoing it.
How would I get it so undo-ing and redo-ing only affects text changes and not style/font changes in my StyledDocument?
Thank you.
It sounds like you need to make use of addEdit or the Significant attribute as explained by the UndoManager:
The UndoManager makes use of isSignificant to determine how many edits
should be undone or redone. The UndoManager will undo or redo all
insignificant edits (isSignificant returns false) between the
current edit and the last or next significant edit. addEdit and
replaceEdit can be used to treat multiple edits as a single edit,
returning false from isSignificant allows for treating can be used to
have many smaller edits undone or redone at once. Similar
functionality can also be done using the addEdit method.
Sources:
https://docs.oracle.com/javase/8/docs/api/javax/swing/undo/UndoableEdit.html

ColumnHideCommand makes the table columns to disappear in NatTable, when all table elements are selected

I have a NatTable component with the following layers:
ViewportLayer
SelectionLayer
RowHideShowLayer
ColumnGroupExpandCollapseLayer
ColumnHideShowLayer
DataLayer
I need to show/hide a specific column, when a checkbox selection changes. In order to that, I use the #doCommand() method provided by the NatTable component:
if(selection) {
nattable.doCommand(new ColumnShowCommand(nattable, COLUMN_INDEX));
} else {
nattable.doCommand(new ColumnHideCommand(nattable, COLUMN_INDEX+1));
}
Everything works just fine, excepting the case when ALL the items in the table are selected, and the ColumnHideCommand is executed. On this specific scenario, the whole table content disappears (Screenshot). If there is no selection in the table, or not all the elements are selected, then everything works just fine.
Please let me know if you have any idea what's going on there or if you experienced this kind of issues before. My experience with NatTables is quite limited, so please let me know if you need any additional information. Thank you!
This is a feature of the SelectionLayer to support multi column hide operations based on the column selection. A ColumnHideCommand get consumed and instead a MultiColumnHideCommand is created and executed based on the fully selected columns. The code in charge is located in SelectionLayer#handleColumnHideCommand(ColumnHideCommand). The method is protected, so if you don't need that feature because you only support column hide/show programmatically and not via UI performed by a user, you can override the method to simply perform a super.doCommand(command); without the check for selections.

Refreshing/Updating contents of a JTable from Database, after user interaction

I have been researching this for days and have tried everything I have come across, but to no avail. I have built an item checkout system in JAVA using a Derby Embedded Database and everything that I have wanted it to do works great. The only thing I can't get to work is having my table update or refresh the information displayed after the user (A) Adds a new entry in the system due to a customer checking out an item. (B) A customer returns an item and is checked back into the system. (C) The table data is changed/fixed due to a previous user error. Case in point: The user checks out an item using the check out dialogue box, then clicks the check in dialogue box but the new entry just made, does not appear. Closing out of the program and going back into it then shows the new information.
I have a method called loadTable() that makes the DB connection all the way through building the table how I want and returns the table.
So far I have tried:
- Calling the loadTable() on any event (Button pressed, window closed, etc).
setFireTableDataChanged() method.
table.setModel(), here I tried inserting the loadTable().getModel or using a temp table.
jtable.tableChanged(new TableModelEvent(jtable.getModel())).
SwingUtilities.updateComponentTreeUI(yourJScrollPane); Ultimately it gets added to JSP.
table.UpdateUI();.
((DefaultTableModel)table.getModel()).fireTableDataChanged();.
repaint().
revalidate().
So far everything I have tried, does not produce the desired results.
I know you all will want to see code, there's a lot so I don't know what I should start with. This is my first time posting so, have mercy on me if i'm going about this the wrong way. Many thanks in advance!

Tracking data offset of data in a table to retrieve the previous/next subset on table scroll

I am writing a browser based application using GWT and making use of websql (yes, I know it is deprecated). I have created a custom table widget (based on FlexTable) and enabled it to scroll with the help of some CSS trickery. What I am striving to achieve (without much success) is that when the user scrolls to the start/end of the current data in the table, an event is fired and the next subset of X rows is returned from the websql DB and replaces the data currently in the table. In order for this to work, I need to keep track of the data offset in the table widget so that I can pass this to the query and use the limit and offset functions of SQL to return the required data. However, I just cannot seem to get the logic right to implement the data offset tracker within the widget. Another complication is that I need the table to be able to scroll 'into the past' (so to speak), so that it can retrieve data from before the initial start point when the table loads.
I have been at this for a number of days now and just cannot seem to get it right. So I was wondering/hoping that someone might be able to point me in the right direction (PLEASE!).
Thanks in advance
Tim
I am not sure why this is causing a problem.
int page = 0;
// when you hit the bottom
page++;
loadData(page);
// when you hit the top
if (page > 0) {
page--;
loadData(page);
}
Tim I think it is not a good idea controlling the scroll with CSS trickery.
I have done something similar soon and controlling all the logic (pagination, scroll positions,...).
What I suggest to use is a gwt's scrollPanel, a HasData widget (like a cellList) your custom AbstractCell (class which is rendered for each row of your list) and asyncDataProvider ( which gives you the onRangeChange handler for asking to your server when the range data display has changed).
You can force/fire that event when in scrollPanel.addScrollHandler detects you are arriving to the end.
If you want to see all of this in action have a look into (click on source code): http://gwt.googleusercontent.com/samples/Showcase/Showcase.html#!CwCellList
EDIT [according comment below]:
A. If you want to override the data (in the example is X+X+X...) with the new retrieved just maintain always the same range of data displayed [display.setVisibleRange(0, newPageSize);], and start from 0 when you render the new data (on your RangeChange listener).
B. If you need to have control over up and down scrolls instead of taking advantage of the used events internally on the cellList (basically onRangeChange), you can create your custom events and fire them (this option could be easier for your colleagues for understanding everything). And do not worry about controlling up and down scrolls, inside the ShowMorePagerPanel.java you can see a simple example of knowing up and down controls.
Anyway, I did not explain more detailed because I did not see you very convinced to use CellList approach (and I was using my tablet :D ).
If you change your mind, just let me know and I write for you a proper example step by step (this part could be tricky, so if you are lost it is normal ;) ).

JTable Header Focus Query?

This Scenario may sound silly... but this was the observation...
When a mouse click on the the JTable cell...
Cell is gets into the editor mode, while in the editor and a invalid entry is made (JTextFeild Component is installed in each cell), the focus is restricted in the editor mode by returning false instead of super.return stopCellEditing(); while validation and test field is painted red.
In the false mode, if user clicks anywhere on the table or outside the table the focus is not lost, but when the user clicks on the JTable header the focus is lost from the cell... I need to restrict this... How can this be achieved
Thank You in Advance...
just to make sure: the editing is canceled in that case (though not exactly on click but on any mouse gesture which might be interpreted as starting a column move/resize, if I remember correctly), right?
If so, it's
a long standing bug, table silently removes editors on receiving change notifications from the column model
even if fixed, (arguably, of course) not the best user experience to not allow moving out
You might look at #camickr's TablePopupEditor, which uses a modal dialog to edit.
This can actually be possible by disabling
table.getTableHeader().setReorderingAllowed(false);
table.getTableHeader().setResizingAllowed(false);
Currently its working, but don't know under what circumstances it may fail.
Thank You

Categories

Resources