Reputation: 405
I have one org.eclipse.ui.dialogs.CheckedTreeSelectionDialog like below code.
final CheckedTreeSelectionDialog checkedTreeSelectionDialog = new
CheckedTreeSelectionDialog(new Shell(),new ActionLabelProvider(), new
ActionContentProvider());
ActionLabelProvider implements org.eclipse.jface.viewers.ILabelProvider and ActionContentProvider implements org.eclipse.jface.viewers.ITreeContentProvider
I have some elements initially selected and some are not in the CheckedTreeSelectionDialog
.
When dialog is open, if I check the unchecked element, I want to show one message.
How can I do this?
Upvotes: 2
Views: 618
Reputation: 8849
Create a subclass of CheckedTreeSelectionDialog
and add addCheckStateListener, use the below code.
// When user checks a checkbox in the tree
import org.eclipse.jface.viewers.CheckStateChangedEvent;
import org.eclipse.jface.viewers.CheckboxTreeViewer;
import org.eclipse.jface.viewers.ICheckStateListener;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.dialogs.CheckedTreeSelectionDialog;
public class MyCheckedTreeSelectionDialog extends CheckedTreeSelectionDialog {
public MyCheckedTreeSelectionDialog(Shell parent, ILabelProvider labelProvider, ITreeContentProvider contentProvider) {
super(parent, labelProvider, contentProvider);
}
@Override
protected CheckboxTreeViewer getTreeViewer() {
CheckboxTreeViewer treeViewer = super.getTreeViewer();
treeViewer.addCheckStateListener(new ICheckStateListener() {
public void checkStateChanged(CheckStateChangedEvent event) {
if (event.getChecked()) {
// Given element is checked
} else {
// Given element is un-checked
// Your message here
}
}
});
return treeViewer;
}
}
Upvotes: 1