// Create FilterCombo component and attach listener
Label assetTypeFilterLabel = new Label(topLevel, SWT.NONE);
assetTypeFilterLabel.setText(WizardMessages.getString(RESOURCE_PREFIX +
"assetTypeFilter.label"));
ComboViewer filterCombo = new ComboViewer(topLevel, SWT.READ_ONLY);
filterCombo.setContentProvider(new EncodingCollectionContentProvider(true));
filterCombo.setLabelProvider(new EncodingCollectionExtensionLabelProvider("image"));
filterCombo.setInput(ImageEncoding.COLLECTION);
filterCombo.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
Object selectedEncoding = selection.getFirstElement();
if (selectedEncoding instanceof EncodingCollection) {
setFilter(new EncodingCollectionViewerFilter(
(EncodingCollection) selectedEncoding));
} else {
setFilter(new EncodingViewerFilter(
(Encoding) selectedEncoding));
}
}
});
GridData gd2 = new GridData(GridData.FILL_HORIZONTAL);
filterCombo.getControl().setLayoutData(gd2);
// Add label for tree viewer
Label componentLabel = new Label(topLevel, SWT.NONE);
componentLabel.setText(WizardMessages.getString(RESOURCE_PREFIX +
"tree.label"));
// Create Composite which contains tree viewer and preview
Composite treeAndPreviewComposite = new Composite(topLevel, SWT.NONE);
GridLayout grid = new GridLayout();
grid.numColumns = 2;
grid.makeColumnsEqualWidth = true;
grid.horizontalSpacing = DEFAULT_COMPONENT_SPACING;
treeAndPreviewComposite.setLayout(grid);
GridData gd3 = new GridData();
gd3.grabExcessHorizontalSpace = true;
gd3.grabExcessVerticalSpace = true;
gd3.horizontalAlignment = GridData.FILL;
gd3.verticalAlignment = GridData.FILL;
gd3.horizontalSpan = 2;
treeAndPreviewComposite.setLayoutData(gd3);
// Create and add the tree viewer
treeViewer = createCheckboxTreeViewer(treeAndPreviewComposite,
SWT.BORDER);
// Create a Composite with a StackLayout for displaying changing previews.
// Some event handlers need access to stackComposite for creating new
// previews.
stackComposite = new Composite(treeAndPreviewComposite, SWT.NONE);
GridData gd4 = new GridData();
gd4.verticalAlignment = GridData.FILL;
gd4.horizontalAlignment = GridData.FILL;
gd4.grabExcessVerticalSpace = true;
gd4.grabExcessHorizontalSpace = true;
gd4.heightHint = PREVIEW_HEIGHT_HINT;
gd4.horizontalSpan = 1;
stackComposite.setLayoutData(gd4);
stack = new StackLayout();
stackComposite.setLayout(stack);
// Create the initial unavailable preview.
unavailablePreview = new UnavailablePreview(stackComposite, SWT.NONE);
// Note: It is unclear why the StackLayout must access the Preview's
// group here rather than just the preview. There may be a bug with
// SWT groups/composites/stacklayouts. Within the Preview class,
// delegating setVisible(boolean) to the Preview's group results
// in no widget being displayed, as does delegating all Composite
// methods to the Preview's group.
stack.topControl = unavailablePreview.getGroup();
stackComposite.layout();
// Create a composite with a RowLayout to contain the
// "Select All" and "Deselect All" buttons.
Composite buttonComposite = new Composite(topLevel, SWT.NONE);
RowLayout rowLayout = new RowLayout();
rowLayout.spacing = HORIZONTAL_BUTTON_GAP;
buttonComposite.setLayout(rowLayout);
// Create the "Select All" button.
selectAllButton = new Button(buttonComposite, SWT.PUSH);
selectAllButton.setText(WizardMessages.getString(RESOURCE_PREFIX +
"button.selectAll.label"));
// Add the button's listener
selectAllButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
BusyIndicator.showWhile(Display.getCurrent(), new Runnable() {
public void run() {
treeViewer.expandToLevel(contentProvider.
getActualRoot(),
CheckboxTreeViewer.ALL_LEVELS);
treeViewer.setSubtreeChecked(contentProvider.
getActualRoot(), true);
updateButtons();
}
});
}
});
// The "Select All" button is initially disabled.
selectAllButton.setEnabled(false);
// Create the "Select All" button.
deselectAllButton = new Button(buttonComposite, SWT.PUSH);
deselectAllButton.setText(WizardMessages.getString(RESOURCE_PREFIX +
"button.deselectAll.label"));
deselectAllButton.setEnabled(false);
// Add the button's listener
deselectAllButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
BusyIndicator.showWhile(Display.getCurrent(), new Runnable() {
public void run() {
treeViewer.setSubtreeChecked(contentProvider.
getActualRoot(), false);
updateButtons();
}
});
}
});
setErrorMessage(null);
setMessage(null);
setControl(topLevel);
filterCombo.getCombo().select(0);
setFilter(new EncodingCollectionViewerFilter(ImageEncoding.COLLECTION));
}