public void treeExpanded(final TreeEvent evt) {
TreeItem item = (TreeItem) evt.item;
TreeItem[] childrens = item.getItems();
for (TreeItem children : childrens) {
if (children.getData(EXPANDED_KEY) == null) {
File file = (File) children.getData();
try {
addChildren(file, children);
}
catch (IOException e) {
ExceptionHandler.reportException(e);
}
children.setData(EXPANDED_KEY, new Object());
}
}
}
});
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);
markItem(selectedItem);
buttonRemoveFilter.setEnabled(true);
}
}
}
});
// remove filter button
buttonRemoveFilter = new Button(compositeButtons, SWT.PUSH | SWT.CENTER);
GridData buttonRemoveFilterData = new GridData();
buttonRemoveFilterData.widthHint = UISettings.BUTTON_WIDTH;
buttonRemoveFilter.setLayoutData(buttonRemoveFilterData);
buttonRemoveFilter.setText("Remove Filter");
buttonRemoveFilter.setEnabled(false);
buttonRemoveFilter.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent evt) {
TreeItem[] selectedItems = directoryTree.getSelection();
if (selectedItems.length > 0) {
TreeItem selectedItem = selectedItems[0];
treeItemsWithFilter.remove(selectedItem);
File file = (File) selectedItem.getData();
itemsMap.remove(file.getPath());
unmarkItem(selectedItem);
}
}
});