directoryTree.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent evt) {
buttonSetFilter.setEnabled(true);
TreeItem item = (TreeItem) evt.item;
FileFilter currentItemFilter = (FileFilter) item.getData(FILTER_KEY);
if (currentItemFilter != null) {
buttonRemoveFilter.setEnabled(true);
}
else {
buttonRemoveFilter.setEnabled(false);
}
}
});
// buttons next to the tree
Composite compositeButtons = new Composite(c, SWT.NONE);
GridLayout compositeButtonsLayout = new GridLayout();
compositeButtonsLayout.makeColumnsEqualWidth = true;
GridData compositeButtonsData = new GridData();
compositeButtonsData.grabExcessVerticalSpace = true;
compositeButtonsData.verticalAlignment = SWT.FILL;
compositeButtons.setLayoutData(compositeButtonsData);
compositeButtons.setLayout(compositeButtonsLayout);
// add filter button
buttonSetFilter = new Button(compositeButtons, SWT.PUSH | SWT.CENTER);
GridData buttonSetFilterData = new GridData();
buttonSetFilterData.widthHint = UISettings.BUTTON_WIDTH;
buttonSetFilter.setLayoutData(buttonSetFilterData);
buttonSetFilter.setText("Set Filter...");
buttonSetFilter.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent evt) {
TreeItem[] selectedItems = directoryTree.getSelection();
if (selectedItems.length > 0) {
TreeItem selectedItem = selectedItems[0];
FileFilter currentItemFilter = (FileFilter) selectedItem.getData(FILTER_KEY);
FileFilterPage dialog = new FileFilterPage(m_parent.getShell(), currentItemFilter);
dialog.show();
FileFilter newfilter = dialog.getFileFilter();
if (newfilter != null) {
selectedItem.setData(FILTER_KEY, newfilter);
treeItemsWithFilter.add(selectedItem);
File file = (File) selectedItem.getData();
itemsMap.put(file.getPath(), newfilter);