How to hide selection checkbox in grid? - java

I have a TreeGrid with selection appearence set to checkbox.
TreeGrid resultGrid = new TreeGrid();
resultGrid.setSelectionAppearance(SelectionAppearance.CHECKBOX);
I want some records to be drawn without these checkboxes(in case record is disabled).
I found property showDisabledSelectionCheckbox, which description says:
Should tree nodes show a disabled checkbox instead of a blank space when selectionAppearance:"checkbox" is set on the treegrid, and a node can't be selected?
How I can make the node "unselectable" except setting :
node.setEnabled(false);
And how this property(showDisabledSelectionCheckbox) works?

I would start here. It looks like you can override canEditCell() on the ListGrid itself to keep someone from interacting with the checkbox. I haven't been able to find a method to hide the checkbox completely, however.
Perhaps setting the showDisabledSelectionCheckbox property to false in conjunction with overriding canEditCell() will get you where you're looking to go.

TreeGrid has selection property that can be set via
resultGrid.setSelectionProperty(propertyName);
So setting this property on TreeNodes will define if nodes could be selected.
By default one can just use "canSelect" property.
So this line of code will disable selection of the particular node.
treeNode.setAttribute("canSelect", false);
And if selection appearance is set to SelectionAppearance.CHECKBOX, checkboxes won't be drawn near nodes which couldn't be selected.
This is the only way I've found.

Related

Editor for both CheckBox and Text in a single column in Tree Table using NatTable

I am trying to recreate this "TreeGridWithCheckBoxFieldsExample" from the natTableExamples, and I wanted the first column editable, not only the Checkbox but also the Text it contains.
But when I register for TextCellEditor I am not able to set the CheckBox value by clicking it, if I click on CheckBox it goes to edit mode for the text beside it because of the MouseEditAction() in the below code.
uiBindingRegistry.registerFirstSingleClickBinding(
new CellPainterMouseEventMatcher(
GridRegion.BODY,
MouseEventMatcher.LEFT_BUTTON,
checkBoxPainter),
new MouseEditAction());
But if I remove it I won't be able to select the CheckBox, and because of DefaultBooleanDisplayConverter in the below code, the text after editing is not getting edited because the dataValue it gets is of boolean type .
configRegistry.registerConfigAttribute(
CellConfigAttributes.DISPLAY_CONVERTER,
new DefaultBooleanDisplayConverter(),
DisplayMode.NORMAL,
TreeLayer.TREE_COLUMN_CELL);
Thanks.
This is afaik not supported out of the box. Converters and editors are registered per column/cell. Mixing two editors and converters in one column/cell for two different properties of one row object is nothing to achieve easily. You will need to implement custom mechanisms to achieve that.

If item is selected in ListView JavaFx

If I have a list and a button . And I want that button disabled until an item from that list has been selected , what is the best method to use?
ListView has a property named selectionModel which holds a MultipleSelectionModel object. This selection model has properties/lists that represents what items are selected, if any. There are two modes to this selection model:
SINGLE: Only one item can be selected at a time.
MULTIPLE: Any number of items can be selected at a time.
It might matter what selection mode you're using, but I'm not positive. For single-selection, I'd observe the selectedItem or selectedIndex property. For multi-selection, I'd observe the selectedItems or selectedIndices ObservableList. (Note: While I'm not positive, I'd expect either method to work regardless of the selection mode)
// single selection mode
button.disableProperty()
.bind(listView.getSelectionModel().selectedItemProperty().isNull());
// multiple selection mode
button.disableProperty()
.bind(Bindings.isEmpty(listView.getSelectionModel().getSelectedItems()));
The first option uses the isNull method of the selectedItem property. The method returns a BooleanBinding which binds the disable property of the Button.
The second option uses Bindings.isEmpty which creates a BooleanBinding that will be true when the ObservableList is empty. Like the first option, the disable property is bound to this BooleanBinding.
Use isNull to create a BooleanBinding based on the selectedItem property of the selection model. Use this to bind the disable property of the button:
button.disableProperty().bind(listView.getSelectionModel().selectedItemProperty().isNull());

Packing tree columns on property sheet entry change

We have an RCP app which uses a Tree and its corresponding TreeViewer. This tree uses an ObservableMapLabelProvider which provides the label text and an ObservableListTreeContentProvider for the content. We're using org.eclipse.jface.databinding-1.5.0-SDK-3.7.2.
We supply an array of IObservableMap using EMFObservables.observeMaps(contentProvider.getKnownElements(), new EStructuralFeature[]) to construct the ObservableMapLabelProvider.
We have an implementation of IPropertySourceProvider which seems to be used for populating the property view by overriding getPropertySource(Object).
Now I can see that when I modify the property sheet entry for a label, IPropertySource#setPropertyValue(Object, Object) is invoked. I want to add a change listener to our ObservableMapLabelProvider or IObservableMap to ensure that the tree columns get packed once the label text is modified. I tried adding change map listener to each element of IObservableMap but it doesn't seem to work.
Any suggestions/pointers on where should I be adding the change listener to pack tree columns once label text is changed on the property sheet?
The Properties view part is implemented by the PropertySheet class, and it's worth reading its Javadoc. PropertySheet is a type of PageBookView, a view that shows one of many managed pages. The Properties view's current page shows the properties of the current selection.
So you could try obtaining the tree viewer from the current page from the Properties view part (based on its view ID, org.eclipse.ui.views.PropertySheet) via getCurrentPage().getControl(), and then perform whatever column voodoo is required.
Alternatively you could provide your own IPropertySheetPage that behaves how you want.

How to make nodes in a chart focus traversable?

I'm on javafx-8 and java8, trying to make an interactive chart.
So far I've implemented all the mouse actions (highlight on mouse over, drag&drop to change values etc), but I'm not able to implement any keyboard interactions (basically changing its value with arrow keys) because the nodes (i.e. pic below) in a chart cannot gain focus.
When I try to set the focusTraversable property is fails with exception
java.lang.RuntimeException: StackPane.focusTraversable : A bound value cannot be set.
I have tried setting it on the chart but it doesn't get propagated to the data points (nodes). Can someone please point me the right way? thanks!
The binding of the symbol's focusTraversal is used in accessibility - the snippet from LineChart.createSymbol(..):
symbol.focusTraversableProperty().bind(Platform.accessibilityActiveProperty());
As long as you can live without following accessibility constraints, you might get away (untested for side-effects!) by simply unbinding before setting it to true, something like:
Node node = data.getNode();
node.focusTraversableProperty().unbind();
node.setFocusTraversable(true);

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