使用eclipse jface FilteredTree
//org.eclipse.ui.dialogs.FilteredTree
Code
public class XXXPage extends WizardPage {
// gui
private FilteredTree projectList;
public void createControl(Composite parent) {
// create the composite to hold the widgets
Composite composite = new Composite(parent, SWT.NULL);
// create the desired layout for this wizard page
GridLayout layout = new GridLayout();
layout.numColumns = MAX_COLUMN;
composite.setLayout(layout);
// create the list of bug reports
projectList = new FilteredTree(composite, SWT.SINGLE | SWT.BORDER, new PatternFilter());
//projectList.setLayoutData(GridDataFactory.swtDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).hint(
// SWT.DEFAULT, 200).create());
GridData gridData = new GridData(GridData.FILL_BOTH);
gridData.widthHint = 80;
gridData.heightHint = 160;
gridData.verticalSpan = VERT_SPAN;
projectList.setLayoutData(gridData);
final TreeViewer projectViewer = projectList.getViewer();
projectViewer.setLabelProvider(new LabelProvider());
projectViewer.setContentProvider(new ITreeContentProvider() {
public Object[] getChildren(Object parentElement) {
//if (parentElement instanceof Collection) {
// return ((Collection<?>) parentElement).toArray();
//}
if(parentElement instanceof XXX){
;
return node.getChildren().toArray();
}
return null;
}
public Object getParent(Object element) {
if(element instanceof XXX){
return node.getParent();
}
return null;
}
public boolean hasChildren(Object element) {
if(element instanceof XXX){
return (node.getChildren().size()>0);
}
return false;
}
public Object[] getElements(Object inputElement) {
//return getChildren(inputElement);
if(inputElement instanceof Collection ){
return ((Collection<?>) inputElement).toArray();
}
return null;
}
public void dispose() {
}
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
});
projectViewer.addOpenListener(new IOpenListener() {
public void open(OpenEvent event) {
if (getWizard().canFinish()) {
if (getWizard().performFinish()) {
((WizardDialog) getContainer()).close();
}
}
}
});
projectViewer.addPostSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
// Initialize a variable with the no error status
Status status = new Status(IStatus.OK, DevTrackCorePlugin.PLUGIN_ID , 0, "", null);
if (projectViewer.getSelection().isEmpty()) {
}
// Show the most serious error
applyToStatusLine(status);
isPageComplete();
}
});
// set the composite as the control for this page
setControl(composite);
isPageComplete();
}
}
public class XXXPage extends WizardPage {
// gui
private FilteredTree projectList;
public void createControl(Composite parent) {
// create the composite to hold the widgets
Composite composite = new Composite(parent, SWT.NULL);
// create the desired layout for this wizard page
GridLayout layout = new GridLayout();
layout.numColumns = MAX_COLUMN;
composite.setLayout(layout);
// create the list of bug reports
projectList = new FilteredTree(composite, SWT.SINGLE | SWT.BORDER, new PatternFilter());
//projectList.setLayoutData(GridDataFactory.swtDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).hint(
// SWT.DEFAULT, 200).create());
GridData gridData = new GridData(GridData.FILL_BOTH);
gridData.widthHint = 80;
gridData.heightHint = 160;
gridData.verticalSpan = VERT_SPAN;
projectList.setLayoutData(gridData);
final TreeViewer projectViewer = projectList.getViewer();
projectViewer.setLabelProvider(new LabelProvider());
projectViewer.setContentProvider(new ITreeContentProvider() {
public Object[] getChildren(Object parentElement) {
//if (parentElement instanceof Collection) {
// return ((Collection<?>) parentElement).toArray();
//}
if(parentElement instanceof XXX){
;
return node.getChildren().toArray();
}
return null;
}
public Object getParent(Object element) {
if(element instanceof XXX){
return node.getParent();
}
return null;
}
public boolean hasChildren(Object element) {
if(element instanceof XXX){
return (node.getChildren().size()>0);
}
return false;
}
public Object[] getElements(Object inputElement) {
//return getChildren(inputElement);
if(inputElement instanceof Collection ){
return ((Collection<?>) inputElement).toArray();
}
return null;
}
public void dispose() {
}
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
});
projectViewer.addOpenListener(new IOpenListener() {
public void open(OpenEvent event) {
if (getWizard().canFinish()) {
if (getWizard().performFinish()) {
((WizardDialog) getContainer()).close();
}
}
}
});
projectViewer.addPostSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
// Initialize a variable with the no error status
Status status = new Status(IStatus.OK, DevTrackCorePlugin.PLUGIN_ID , 0, "", null);
if (projectViewer.getSelection().isEmpty()) {
}
// Show the most serious error
applyToStatusLine(status);
isPageComplete();
}
});
// set the composite as the control for this page
setControl(composite);
isPageComplete();
}
}