KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ant > internal > ui > preferences > AntPropertiesFileSelectionDialog


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ant.internal.ui.preferences;
12
13 import java.util.List JavaDoc;
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 JavaDoc DIALOG_SETTING= "AntPropertiesFileSelectionDialog.showAll"; //$NON-NLS-1$
41

42     public AntPropertiesFileSelectionDialog(Shell parent, ILabelProvider labelProvider, ITreeContentProvider contentProvider, List JavaDoc propertyFiles) {
43         super(parent, labelProvider, contentProvider);
44         
45         setTitle(AntPreferencesMessages.getString("AntPropertiesFileSelectionDialog.12")); //$NON-NLS-1$
46
setMessage(AntPreferencesMessages.getString("AntPropertiesFileSelectionDialog.13")); //$NON-NLS-1$
47
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 JavaDoc[] selection) {
54                 if (selection.length == 0) {
55                     return new Status(IStatus.ERROR, AntUIPlugin.getUniqueIdentifier(), 0, "", null); //$NON-NLS-1$
56
}
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); //$NON-NLS-1$
60
}
61                 }
62                 return new Status(IStatus.OK, AntUIPlugin.getUniqueIdentifier(), 0, "", null); //$NON-NLS-1$
63
}
64         };
65         setValidator(validator);
66     }
67     
68     /* (non-Javadoc)
69      * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
70      */

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")); //$NON-NLS-1$
76

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     /* (non-Javadoc)
104      * @see org.eclipse.jface.window.Window#close()
105      */

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