1 11 package org.eclipse.ant.internal.ui.preferences; 12 13 import java.util.List ; 14 15 import org.eclipse.ant.internal.ui.AntUIPlugin; 16 import org.eclipse.core.resources.IFile; 17 import org.eclipse.core.resources.IResource; 18 import org.eclipse.core.resources.ResourcesPlugin; 19 import org.eclipse.core.runtime.IPath; 20 import org.eclipse.core.runtime.IStatus; 21 import org.eclipse.core.runtime.Path; 22 import org.eclipse.core.runtime.Status; 23 import org.eclipse.jface.dialogs.IDialogSettings; 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.widgets.Button; 28 import org.eclipse.swt.widgets.Composite; 29 import org.eclipse.swt.widgets.Control; 30 import org.eclipse.swt.widgets.Shell; 31 import org.eclipse.ui.dialogs.ElementTreeSelectionDialog; 32 import org.eclipse.ui.dialogs.ISelectionStatusValidator; 33 import org.eclipse.ui.model.WorkbenchContentProvider; 34 import org.eclipse.ui.model.WorkbenchLabelProvider; 35 import org.eclipse.ui.views.navigator.ResourceComparator; 36 37 public class FileSelectionDialog extends ElementTreeSelectionDialog { 38 39 private FileFilter fFilter; 40 private String fFilterMessage; 41 private boolean fShowAll= false; 42 private final static String DIALOG_SETTING= "AntPropertiesFileSelectionDialog.showAll"; private final static String LAST_CONTAINER= "AntPropertiesFileSelectionDialog.lastContainer"; 45 public FileSelectionDialog(Shell parent, List files, String title, String message, String filterExtension, String filterMessage) { 46 super(parent, new WorkbenchLabelProvider(), new WorkbenchContentProvider()); 47 48 setTitle(title); 49 setMessage(message); 50 fFilter= new FileFilter(files, filterExtension); 51 fFilterMessage= filterMessage; 52 setInput(ResourcesPlugin.getWorkspace().getRoot()); 53 setComparator(new ResourceComparator(ResourceComparator.NAME)); 54 55 ISelectionStatusValidator validator= new ISelectionStatusValidator() { 56 public IStatus validate(Object [] selection) { 57 if (selection.length == 0) { 58 return new Status(IStatus.ERROR, AntUIPlugin.getUniqueIdentifier(), 0, "", null); } 60 for (int i= 0; i < selection.length; i++) { 61 if (!(selection[i] instanceof IFile)) { 62 return new Status(IStatus.ERROR, AntUIPlugin.getUniqueIdentifier(), 0, "", null); } 64 } 65 return new Status(IStatus.OK, AntUIPlugin.getUniqueIdentifier(), 0, "", null); } 67 }; 68 setValidator(validator); 69 } 70 71 74 protected Control createDialogArea(Composite parent) { 75 76 Composite result= (Composite)super.createDialogArea(parent); 77 final Button button = new Button(result, SWT.CHECK); 78 button.setText(fFilterMessage); 79 button.setFont(parent.getFont()); 80 81 IDialogSettings settings= AntUIPlugin.getDefault().getDialogSettings(); 82 fShowAll= settings.getBoolean(DIALOG_SETTING); 83 84 String lastPath= settings.get(LAST_CONTAINER); 85 if (lastPath != null) { 86 IPath path= Path.fromPortableString(lastPath); 87 IResource resource= ResourcesPlugin.getWorkspace().getRoot().findMember(path); 88 setInitialSelection(resource); 89 } 90 91 fFilter.considerExtension(!fShowAll); 92 getTreeViewer().addFilter(fFilter); 93 if (!fShowAll) { 94 button.setSelection(true); 95 } 96 97 button.addSelectionListener(new SelectionAdapter() { 98 public void widgetSelected(SelectionEvent event) { 99 if (button.getSelection()) { 100 fShowAll= false; 101 } else { 102 fShowAll= true; 103 } 104 fFilter.considerExtension(!fShowAll); 105 getTreeViewer().refresh(); 106 } 107 }); 108 applyDialogFont(result); 109 return result; 110 } 111 112 115 public boolean close() { 116 IDialogSettings settings= AntUIPlugin.getDefault().getDialogSettings(); 117 settings.put(DIALOG_SETTING, fShowAll); 118 119 Object [] result= getResult(); 120 if (result != null && result.length > 0) { 121 settings.put(LAST_CONTAINER, ((IResource)result[0]).getParent().getFullPath().toPortableString()); 122 } 123 return super.close(); 124 } 125 } 126 | Popular Tags |