Java SWT TableViewer. Only allow Entry as DropTarget - java

I recently added Drag and Drop to my SWT TableViewer. That works well.
I am able to drag one Element from the source TableViewer to the target TableViewer and I can work with that.
Now comes my problem. I only want to be able to drag an element on another element. In other words I only want to be able to drop my element on another element and not in between two rows.
In the picture you can see what I mean. When dragging between two rows the bold line shows up. And I dont want that to happen. It should only highlight rows and the bold line should never appear.
Currently I'm working with validateDrop(...) so the drop doesn't work when I release there, but that's not a clean solution.
I hope you can help me.
Drag and Drop Example:

Assuming you are using a drop target listener that extends ViewerDropAdapter override determineLocation and always return LOCATION_ON:
#Override
protected int determineLocation(DropTargetEvent event)
{
return LOCATION_ON;
}

Related

Jtable losing multiple row selection,when button in one of the column is clicked

I have a very basic problem with jtable. I have a jtable that has multiple columns with one of column having a button. When i click on that button a panel drops, and asks to select an option from given options. When i select that option, value replaces in one of the column.
Now, i want when i select multiple rows, and do the same thing as above, it should replace that column in all the selected rows.
Problem: Currently, my table is losing selection when i am clicking the button in one of the column in jtable after multiple row selection.
I searched google and stackoverflow a lot, but could not find anything meaningful. Anyhelp or sample code is appreciated.
Thanks
If I understood your problem correctly then the solution is fairly simple.
First of all the issue probably occurs because once you click on the button java sets a new focus on the button and therefore clearing the focus on the other rows. That won´t be a problem in a single selection because you still click into the selected row, however doing that with multiple rows in one go won´t work that way.
To solve this you need to save your previous selections in something like an ArrayList and after the whole option thing you can apply the changes to every element in the ArrayList and reload the table.
A cleaner and more intuitive approach though would be to place the button outside of the JTable.

JXTreeTable - Weird cell rendering issue for certain Look and Feels

So here's my problem. I have developed a plugin for intellij which contains a tool window, and a part of it contains a tabbed pane with a JXTreeTable like this
Looks great and works as expected until I start clicking on the rows. I'll explain the issue through screenshots.
Row selected
Move mouse pointer to next row
Select Next row
Repeat above procedure for the next couple of rows and I end with this!
urghh..puke
Now If I move my mouse pointer back up those again, The colors come back like magic!
Continue moving mouse back up along the rows..
Also at any point if my mouse pointer leaves the column..The view is back to normal again (except for the selected row of course)
My Look and Feel is IntelliJ Dark Look and Feel - com.intellij.ide.ui.laf.IntelliJLaf , which I found out using System.out.println(UIManager.getLookAndFeel())
If I change my look and feel programmatically to something else, This issue disappears. But i'm not in a position to alter the default look and feel so I have to fix this issue (or bug?).
I've used a hack to apply a different look and feel just for my JXTreeTable view component, and it worked great until.. I open another project on a new window (this creates a new instance of my tool window for the new project) and the hack this time around works against me, setting the look and feel properly for the new project instance, but resetting the look and feel back to default for my first project instance
Oh and i'm using the DefaultTreeCellRenderer for my treetable.
EDIT: I implemented a custom cell renderer for the treetable, setting it to transparent when not selected (like MadProgrammer suggested), but the issue is still there.
public class CustomCellRenderer extends JLabel
implements TreeCellRenderer {
#Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
if (selected){
setBackground(Color.BLUE);
setForeground(Color.WHITE);
}else{
setForeground(Color.BLACK);
setBackground(Color.WHITE);
setOpaque(false);
}
setText(value != null ? value.toString() : "<null>");
return this;
}
}
There is a slight change in the results now. lol
Compare with 4. above
EDIT 02:
So I decided to completely disable cell selection for my treetable using treeTable.setFocusable(false). Well guess what? Now when I click on a row nothing happens. No cell selections or colour changes. But once I move my mouse pointer to the next row as shown above (step 2), yup same story over again. Looks like it's related to a mouse listener somewhere? idk.. This is driving me nuts. Some help would be highly appreciated!
EDIT 03:
This seems to be the LAF that's giving me trouble
com.intellij.ide.ui.laf.darcula.DarculaLaf
source: https://github.com/JetBrains/intellij-community/blob/master/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/DarculaLaf.java
EDIT 04
So I gave up SwingX and tried to implement a JTreeTable component from scratch, to see if this would fix the issue. I managed to put together an implementation using online source code. The results are interesting.
As you can see the issue is still there but unlike before, it does not propagate from cell to cell. So basically, it only shows on the current selected cell.
Anyway, the implementation I used, contains a MyTreeTable class which extends a JTreeTable class. The complete source code can be found here
If I instantiate JTreeTable instead of MyTreeTable the cell rendering issue disappears, but so does the collapse/expand feature of the JTreeTable. It basically turns into a flat tree. (useless!) So whatever that's causing the issue,
Is in the MyTreeTable class
Provides the collapse/expand behavior
to the tree component
after a bit of debugging I narrowed it down to the following method. If I remove this method from the MyTreeTable class, I can't expand/collapse the treetable, once it's included the cell rendering issue comes back.
public boolean editCellAt(int row, int column, EventObject e){
if(e instanceof MouseEvent){
MouseEvent me = (MouseEvent)e;
// If the modifiers are not 0 (or the left mouse button),
// tree may try and toggle the selection, and table
// will then try and toggle, resulting in the
// selection remaining the same. To avoid this, we
// only dispatch when the modifiers are 0 (or the left mouse
// button).
if(me.getModifiers()==0 ||
me.getModifiers()==InputEvent.BUTTON1_MASK){
for(int counter = getColumnCount()-1; counter>= 0;
counter--){
if(getColumnClass(counter)== TreeTableModel.class){
MouseEvent newME = new MouseEvent
(tree, me.getID(),
me.getWhen(), me.getModifiers(),
me.getX()-getCellRect(0, counter, true).x,
me.getY(), me.getClickCount(),
me.isPopupTrigger());
tree.dispatchEvent(newME);
break;
}
}
}
return false;
}
return super.editCellAt(row, column, e);
}
Anyway, this looks like a bug from the intellij side because it's look and feel specific and exists to some degree in both SwingX and a standard library JTreeTable implementation. So maybe i'm approaching this totally wrong. But still if there is a possible fix, please share your ideas. I need this issue sorted out. thanks

I can't resize or move elements on Intellij IDEA GUI designer

I just want to drag and drop them like in Netbeans.
is there any way to get functionality of Netbeans or Eclipse in IDEA?
I had the same problem and I have solved it. You need to create a new row before dragging any new elements. In the left side you will see small green boxes for each row. Right click on the last row's green box and then choose "Insert row after this". Then you can drag and drop any new elements into your newly created row.
You can drag and drop components and alter on which part of the layout they appear. You might need to split a column if you want the component on only the half of a parent.
See: https://www.jetbrains.com/idea/help/placing-gui-components-on-a-form.html
But to set some minimum size or set if a component should grow, you need to look into properties panel of a selected component (on the left).
See: https://www.jetbrains.com/idea/help/setting-component-properties.html

JavaFX Table Menu Button list shows text but not graphic

I am working on an application that uses a TableView and has a Table Menu Button to add or remove columns from the list.
Since I wanted my column headers to have tooltips, I had no choice but to create a label and use it in the following manner in :
// Some code here
TableColumn col;
// some code here
col.setGraphic(header_title);
The problem with this is that when the program runs, the table menu button shows a list of empty text:
On the other hand when I do:
// Some code here
TableColumn col;
// some code here
col.setText(rs.getString("column_title"));
col.setGraphic(header_title);
I can see the text on the column menu, but the actual titles are appended to the graphic:
I have tried to look for a way to perform a setContentDisplay(GRAPHIC_ONLY), but this does not seem to exist for TableColumn, and I am not sure how to access the header node in order to set this setting.
Any help would be greatly appreciated.
Just forget about the inbuilt table menu button. It's absolutely minimal and not worth mentioning. If you e. g. want to click away 10 columns you have to click on the button, hide the column, click on the button, hide the column, etc. In other words: It closes as soon as you press a menu item.
You can't even extend it with e. g. a hide all and a show all button. And it's buggy: When the last column gets hidden, the menu button vanishes as well, so you have to restart your application if you want to see anything in your table again.
Just create your own table menu. There are 2 examples on this gist:
example which uses a lookup, i. e. works without reflection
example which uses reflection
Then you can adapt whatever header you want and whatever menu items you want.

GWT CellTable selection and single click on CheckBoxCell

I've got a CellTable wich work with SingleSelectionModel to make single selection and show some information into details panel. Also I've got CheckBoxCell column into this CellTable which work with another MultipleSelectionModel to make mass delete operation.
When I try to click on check box in CheckBoxCell column GWT selects row and after second click on checkbox it change checkbox state. So we should make two clicks, but I need to do it (change checkbox state) by one click.
I tried different ways to fix it:
Change dependsOnSelection and handlesSelection parameters into CheckboxCell
Change SelectionEventManager in CellTable (DefaultSelectionEventManager.createCheckboxManager(), DefaultSelectionEventManager.createCustomManager)
But it doesn't work.
I found similar problems into Internet but all of them work with one MultipleSelectionModel. It's not the same what I want, because there's details panel (So I could make only single selection).
Can anyone help me to figure out how to resolve it?
UPD:
I've just removed SingleSelectionModel and redesigned UI to working with MultipleSelectionModel. It's GWT-hell..
Try to switch your selection models: use the MultiSelectionModel as the CellTable's selection model, so that the checkboxes work as expected (with both dependsOnSelection and handlesSelection set to true), and for the master-detail feature, use a CellPreviewEvent.Handler (or DefaultSelectionEventManager#createCustomManager), and RowStyles and getRowElement+addStyleName/removeStyleName for rendering (RowStyles when the CellTable renders the rows, then getRowElement to dynamically update styling).

Categories

Resources