Packing tree columns on property sheet entry change - java

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.

Related

How to change the sorting column dynamically when getting a NotesViewEntryCollection

I have a viewEntryCollection in SSJS from a sorted view displayed in a repeat which is displaying a table on the web page
I now want the viewEntrycollection do be sorted as any of the other sortable columns in the view. (i.e the user click on a columnn in the table and set a viewScope variable that I can use when I get the entrycollection)
I do not want to resort the entrycollection programmatically and I do not want to update the view design. I just want to change which column the collection use for sorting.
Preferably the same way a viewPanel can be set to be resorted based on specified sorted column.
any ideas?
If you have a NotesViewEntryCollection you retrieved that from a NotesView object. To sort that collection, you need to resort the view object after you've opened it using the resortView("colName", sortAsc); method.
That will only work if you enabled the 'click to sort column' option for the column you want to sort on.
If you need more control over how view data is handled (including sorting), have a look at the Domino JNA project and this blog post (disclaimer: I wrote that post).

RCP 3.x editable PropertySheet view

I implemented a custom PropertySheet as described in here.
So I have a main view, which implements the selectionprovider and it works to show the properties in my custom PropertySheet view.
My problem is now, that I want to edit the some properties of the selection in the property view and prevent changing the selection in the main view, if there are unsaved changes in the property view.
What is the best way to solve that problem?
If I implement the ISaveablePart in my custom property view, I can mark it as dirty. How can I prevent to change the selection, if my property view is dirty?
Thanks in advance!
As a view is a non-modal (e.g. non-blocking) UI component, there is no real way to prevent selection changes outside the view. For this reason, the expected way of Properties view to work is to save as soon as possible.
The default, TreeViewer based implementation of EMF models uses a CellEditor to change its values; when the value in a CellEditor changes, the changed values are written back to the original model automatically to avoid the data loss scenarios you have mentioned.
In other words, you have to rely on your data source (e.g. the editor that provides the selection) to store the permanent changes, and the changes can be serialized through that source (editor).

SWT ComboBoxCellEditor editable

I have a TableViewer where the values in one column should typically come from a dynamic list.
I'm currently using org.eclipse.jface.viewers.ComboBoxCellEditor , which is actually a Select-List: it stores the index of the selected value. If I change the underlying list (calling setItems(String[]), it's clumsy to keep the previous selected value... (specially if it's not included in the list anymore!) What I'd wish is actually a cell editor that stores, not the index from the list, but the string (perhaps letting the user edit it freely, perhaps not), where the list is just used as a suggestion at input time - like a "combobox" was supposed to work in the good old days... Is this possible?
I would suggest you to have your CellEditor to mimic the behavior that you are looking for. Extend ComboBoxViewerCellEditor and override doGetValue() method. Add modify listener on Combo control and also filter (which filters list items based on input text) to comboviewer.
You should look at :
org.eclipse.wst.xml.ui.internal.properties.StringComboBoxCellEditor This class comes from WTP project; It's an extended ComboBoxCellEditor that selects and returns Strings.
codemirror.eclipse.ui.xquery.viewers.StringComboBoxCellEditor It's the copy/paste of WTP StringComboBoxCellEditor; it adds the capability to add the item in the combo when it is not found.

How to hide selection checkbox in grid?

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.

JTable that can save to a file

Does anyone know of a JTable based Swing component OR code example that can save to a file? i.e: provides a menu item or button that when clicked on prompts the user for a file location and saves the table's contents to a file (CSV, XLS, TXT, or whatever).
The easy part is looping through the rows and saving to a file. But there also needs to be a UI component ON the table itself that allows the user to initiate the save.
Write your own. All you do is use the table.getModel().getValueAt(...) method and loop through the rows and columns and then write the data to a file.
I have implemented this using the following approach:
Create an Action implementation: DelimitedExportAction. I typically add this action to a JToolBar, JMenuBar or JPopupMenu.
Expose a method void registerTable(JTable tbl). Internally this method adds a FocusListener to the JTable. When a given JTable gains focus set the tableToExport instance variable and enable the action.
When the actionPerformed(ActionEvent) method is called, invoke your export logic if tableToExport != null.
Rather than iterate over the TableModel I recommend iterating over the JTable, and for each row calling getValueAt(int, int) on the underlying TableModel, remembering to convert between view and model row / column indices. This is more intuitive to the end user as it means any sorting and filtering applied to the JTable is preserved during the export. (In my implementation I actually offer users the choice of exporting all data or visible data.)
Define a DelimitedExportFormatter whose role is to convert each object returned by getValueAt(int, int) to a String. Similar to when providing renderers to a JTable this class should permit you to provide a Format for a given Class or specific column, whereby a column specific format takes precedence. The default format applied to all other values should be: value == null ? "" : value.toString().
I allow the action to be configured in different modes (which also governs the action's icon):
Export to file: Launches a file chooser dialog allowing user to specify save destination.
Export to Excel: Saves the exported data as a temporary file and opens it within Excel.
Configurable export: Launches a dialog whereby the user can specify: row delimiter, field delimiter, columns to export, rows to export (all, visible, selected), save destination (Excel / File).
I'm afraid I can't provide the code as it is proprietary but hopefully this will put you on the right track. Good luck!
I recently created a very simple tutorial that exports data from JTable into excel file, using Tab-Separated Values(TSV) format. The application provides an Export button, which then triggers a dialog box (JFileChooser) to assist the user in specifying the file location/destination. I hope this helps somehow.
https://sites.google.com/site/teachmemrxymon/java/export-records-from-jtable-to-ms-excel
I don't know of any JTable-like Swing component that fulfills this exact need.
However, where would you expect the button to be placed on the table? In my opinion you would be better served by either adding the JTable to a JScrollPane and putting your "save" button on the JScrollPane or adding the JScrollPane to a JPanel and putting the "save" button on the JPanel. I don't see the logic behind having a button on the JTable itself.
If you want a menu item, you'd probably want to create the menubar and add the JTable to whatever container is holding the menubar. There's still no adding of a button to the table itself, mind you, but it would be the same thing visually.

Categories

Resources