Is there a way to set the value in a ComboBoxCellEditor other then when the focus is lost on the cell? I'm using it in each cell of a column in a TreeViewer and the only time that the setValue method is called is when focus is lost on the cell. So when a user makes a selection and doesn't click off of the cell the value is never set to the new selection. I've tried adding listeners on the ComboBoxCellEditor and on the control of the ComboBoxCellEditor but nothing seems to pick up the selection event.
I figured out that I needed to cast the control to a CCombo in order to add the correct type of listener to the ComboBoxCellEditor. Here's what I did:
CCombo combo = (CCombo) cellEditor.getControl();
combo.addSelectionListener(new SelectionListener()
{
#Override
public void widgetSelected(SelectionEvent paramSelectionEvent)
{
//selection code here...
}
#Override
public void
widgetDefaultSelected(SelectionEvent paramSelectionEvent)
{
//do nothing here...
}
});
Related
I have a SWT Table with check boxes enable on the rows to allow TableItems to be selected. I currently have a listener on there
myTable.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event selectionEvent) {}});
This listener fires both when a check box for a row is checked and when a row is highlighted / selected, I haven't been able to find a way to separate these actions. Am I using the wrong listener or is there a way to do this?
Thanks for any help.
You can check within the Listener if it's a checkbox event or a selection event:
myTable.addListener(SWT.Selection, new Listener()
{
public void handleEvent(Event e)
{
if(e.detail == SWT.CHECK)
{
// Checkbox
}
else
{
// Selection
}
}
});
I am very new to SWT. Started working on it today actually. I have a table of type CheckboxTableViewer. What i want to be able to do is whenever the user selects the row (i.e clicks anywhere on the row) I want the check box to be checked (ticked). Currently I have a listener on the CheckboxTableViewer as follows:
diagnosesTableViewer.addCheckStateListener(new ICheckStateListener() {
#Override
public void checkStateChanged(CheckStateChangedEvent event) {
Nomenclature changedStateNomenclature = (Nomenclature) event
.getElement();
if (event.getChecked()) {
selectedNomenclatures.add(changedStateNomenclature);
} else {
selectedNomenclatures.remove(changedStateNomenclature);
}
}
});
I am able to select the row by checking on the checkbox. But i want to select the check box even when the user selects the row by clicking anywhere on that row on any column (not just the checkbox).
I guess that logic would go somewhere in the addSelectionChangedListener for the addSelectionChangedListener. But I am not sure how to go about it. Can anyone help me with this?
Use this code: Add selection listener to the table. ctv is the instance of of your CheckboxTableViewer.
Also I assumed CheckboxTableViewer allow only single selection not multi.
ctv.getTable().addSelectionListener(new SelectionAdapter() {
#Override
public void widgetSelected(SelectionEvent e) {
int df = ctv.getTable().getSelectionIndex();
ctv.setChecked(ctv.getElementAt(df), !ctv.getChecked(ctv.getElementAt(df)));
}
});
Currently every header contains the name of the column and ocassionally a combo box below it. Whenever the combo box is clicked the jtable automatically sort. Is there a simple way to disable sorting for just the combo box clicks while preserving the rest of the header to sort on click.
I have been suggested JXTable but am fearful that it will cause more problems than it would fix.
Any help is appreciated.
Try something like:
public class SortFilterTableHeaderUI extends BasicTableHeaderUI {
private Component filteredComponent;
#Override
protected MouseInputListener createMouseInputListener() {
return new MouseInputHandler() {
#Override
public void mouseClicked(MouseEvent e) {
if (!filteredComponent.contains(e.getPoint()))
super.mouseClicked(e);
}
};
}
}
Other option is override JTAbleHeader.columnAtPoint(Point point) and return -1 if the combo contains the point.
I have 2 comboboxes and a spinner, that work like this: if the selected item of the first combo is changed, the second combo keeps its selected item but re-calls the spinner (the spinner is linked only to the second box). My problem is that I can't trigger the stateChange listener of the spinner when I do this.
Here is the code for forcing the second box to reselect its last item when the first one is changed (nothing wrong here, it works just fine):
String orientare = (String) orientareComboBox.getSelectedItem();
orientareComboBox.setSelectedItem(orientare);
This is the code for the second box actionListener:
public void actionPerformed(ActionEvent e) {
JComboBox combo = (JComboBox) e.getSource();
String value = combo.getSelectedItem().toString();
if (value.equalsIgnoreCase("oblica"))
{
unghiSpinner.setEnabled(true);
double unghi = (double) unghiSpinner.getValue();
unghiSpinner.setValue(new Double(unghi));
}
}
And the spinner's Listener:
public void stateChanged(ChangeEvent e)
{
if (unghiSpinner.isEnabled())
{
// do something
}
}
I do not know what command I should use for unghiSpinner to trigger its listener, because setValue() can't do it.
I don't see you changing the value of your JSpinner in the code above. It appears that all you do is set the spinner's value to the same value that it held previously, and that shouldn't trigger the listener. To trigger a change listener to fire you must change the state of the observed entity.
I have a button that updates data to a grid.I want to display a message box when grid is updated.So I wanted to invoke that in a selection change listener.Is that possible.Any other suggestions??
If you want to show a MessageBox when the Grid is updated. Then you can add StoreListener on the Grid's Store.
Example
grid.getStore().addStoreListener(new StoreListener<ModelData>() {
#Override
public void storeUpdate(StoreEvent<ModelData> se) {
MessageBox.alert(...);
}
});