1 11 package org.eclipse.ant.internal.ui.preferences; 12 13 import java.util.List ; 14 import org.eclipse.ant.internal.ui.model.AntUIPlugin; 15 import org.eclipse.core.resources.IFile; 16 import org.eclipse.core.resources.ResourcesPlugin; 17 import org.eclipse.core.runtime.IStatus; 18 import org.eclipse.core.runtime.Status; 19 import org.eclipse.jface.dialogs.IDialogConstants; 20 import org.eclipse.jface.dialogs.IDialogSettings; 21 import org.eclipse.jface.viewers.ILabelProvider; 22 import org.eclipse.jface.viewers.ITreeContentProvider; 23 import org.eclipse.jface.viewers.ViewerFilter; 24 import org.eclipse.swt.SWT; 25 import org.eclipse.swt.events.SelectionAdapter; 26 import org.eclipse.swt.events.SelectionEvent; 27 import org.eclipse.swt.layout.GridData; 28 import org.eclipse.swt.widgets.Button; 29 import org.eclipse.swt.widgets.Composite; 30 import org.eclipse.swt.widgets.Control; 31 import org.eclipse.swt.widgets.Shell; 32 import org.eclipse.ui.dialogs.ElementTreeSelectionDialog; 33 import org.eclipse.ui.dialogs.ISelectionStatusValidator; 34 import org.eclipse.ui.views.navigator.ResourceSorter; 35 36 public class AntPropertiesFileSelectionDialog extends ElementTreeSelectionDialog { 37 38 private ViewerFilter fFilter; 39 private boolean fShowAll= false; 40 private final static String DIALOG_SETTING= "AntPropertiesFileSelectionDialog.showAll"; 42 public AntPropertiesFileSelectionDialog(Shell parent, ILabelProvider labelProvider, ITreeContentProvider contentProvider, List propertyFiles) { 43 super(parent, labelProvider, contentProvider); 44 45 setTitle(AntPreferencesMessages.getString("AntPropertiesFileSelectionDialog.12")); setMessage(AntPreferencesMessages.getString("AntPropertiesFileSelectionDialog.13")); fFilter= new PropertyFileFilter(propertyFiles); 48 49 setInput(ResourcesPlugin.getWorkspace().getRoot()); 50 setSorter(new ResourceSorter(ResourceSorter.NAME)); 51 52 ISelectionStatusValidator validator= new ISelectionStatusValidator() { 53 public IStatus validate(Object [] selection) { 54 if (selection.length == 0) { 55 return new Status(IStatus.ERROR, AntUIPlugin.getUniqueIdentifier(), 0, "", null); } 57 for (int i= 0; i < selection.length; i++) { 58 if (!(selection[i] instanceof IFile)) { 59 return new Status(IStatus.ERROR, AntUIPlugin.getUniqueIdentifier(), 0, "", null); } 61 } 62 return new Status(IStatus.OK, AntUIPlugin.getUniqueIdentifier(), 0, "", null); } 64 }; 65 setValidator(validator); 66 } 67 68 71 protected Control createDialogArea(Composite parent) { 72 73 Composite result= (Composite)super.createDialogArea(parent); 74 final Button button = new Button(result, SWT.CHECK); 75 button.setText(AntPreferencesMessages.getString("AntPropertiesFileSelectionDialog.14")); 77 button.setFont(parent.getFont()); 78 GridData data= new GridData(); 79 data.heightHint = convertVerticalDLUsToPixels(IDialogConstants.BUTTON_HEIGHT); 80 button.setLayoutData(data); 81 IDialogSettings settings= AntUIPlugin.getDefault().getDialogSettings(); 82 fShowAll= settings.getBoolean(DIALOG_SETTING); 83 if (!fShowAll) { 84 getTreeViewer().addFilter(fFilter); 85 button.setSelection(true); 86 } 87 88 button.addSelectionListener(new SelectionAdapter() { 89 public void widgetSelected(SelectionEvent event) { 90 if (button.getSelection()) { 91 fShowAll= false; 92 getTreeViewer().addFilter(fFilter); 93 } else { 94 fShowAll= true; 95 getTreeViewer().removeFilter(fFilter); 96 } 97 } 98 }); 99 applyDialogFont(result); 100 return result; 101 } 102 103 106 public boolean close() { 107 IDialogSettings settings= AntUIPlugin.getDefault().getDialogSettings(); 108 settings.put(DIALOG_SETTING, fShowAll); 109 return super.close(); 110 } 111 } 112 | Popular Tags |