KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > preferences > ProjectSelectionDialog


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

11 package org.eclipse.jdt.internal.ui.preferences;
12
13 import java.util.Set JavaDoc;
14
15 import org.eclipse.core.runtime.IStatus;
16
17 import org.eclipse.core.resources.ResourcesPlugin;
18
19 import org.eclipse.swt.SWT;
20 import org.eclipse.swt.events.SelectionEvent;
21 import org.eclipse.swt.events.SelectionListener;
22 import org.eclipse.swt.graphics.Font;
23 import org.eclipse.swt.layout.GridData;
24 import org.eclipse.swt.widgets.Button;
25 import org.eclipse.swt.widgets.Composite;
26 import org.eclipse.swt.widgets.Control;
27 import org.eclipse.swt.widgets.Shell;
28
29 import org.eclipse.jface.dialogs.Dialog;
30 import org.eclipse.jface.dialogs.IDialogSettings;
31 import org.eclipse.jface.viewers.DoubleClickEvent;
32 import org.eclipse.jface.viewers.IDoubleClickListener;
33 import org.eclipse.jface.viewers.ISelectionChangedListener;
34 import org.eclipse.jface.viewers.IStructuredSelection;
35 import org.eclipse.jface.viewers.SelectionChangedEvent;
36 import org.eclipse.jface.viewers.TableViewer;
37 import org.eclipse.jface.viewers.Viewer;
38 import org.eclipse.jface.viewers.ViewerFilter;
39
40 import org.eclipse.ui.dialogs.SelectionStatusDialog;
41
42 import org.eclipse.jdt.core.IJavaModel;
43 import org.eclipse.jdt.core.JavaCore;
44
45 import org.eclipse.jdt.ui.JavaElementComparator;
46 import org.eclipse.jdt.ui.JavaElementLabelProvider;
47 import org.eclipse.jdt.ui.StandardJavaElementContentProvider;
48
49 import org.eclipse.jdt.internal.ui.JavaPlugin;
50 import org.eclipse.jdt.internal.ui.dialogs.StatusInfo;
51
52 public class ProjectSelectionDialog extends SelectionStatusDialog {
53
54     // the visual selection widget group
55
private TableViewer fTableViewer;
56     private Set JavaDoc fProjectsWithSpecifics;
57
58     // sizing constants
59
private final static int SIZING_SELECTION_WIDGET_HEIGHT= 250;
60     private final static int SIZING_SELECTION_WIDGET_WIDTH= 300;
61     
62     private final static String JavaDoc DIALOG_SETTINGS_SHOW_ALL= "ProjectSelectionDialog.show_all"; //$NON-NLS-1$
63

64     private ViewerFilter fFilter;
65
66     public ProjectSelectionDialog(Shell parentShell, Set JavaDoc projectsWithSpecifics) {
67         super(parentShell);
68         setTitle(PreferencesMessages.ProjectSelectionDialog_title);
69         setMessage(PreferencesMessages.ProjectSelectionDialog_desciption);
70         fProjectsWithSpecifics= projectsWithSpecifics;
71         
72         int shellStyle = getShellStyle();
73         setShellStyle(shellStyle | SWT.MAX | SWT.RESIZE);
74         
75         fFilter= new ViewerFilter() {
76             public boolean select(Viewer viewer, Object JavaDoc parentElement, Object JavaDoc element) {
77                 return fProjectsWithSpecifics.contains(element);
78             }
79         };
80         
81     }
82
83     /* (non-Javadoc)
84      * Method declared on Dialog.
85      */

86     protected Control createDialogArea(Composite parent) {
87         // page group
88
Composite composite= (Composite) super.createDialogArea(parent);
89
90         Font font= parent.getFont();
91         composite.setFont(font);
92
93         createMessageArea(composite);
94
95         fTableViewer= new TableViewer(composite, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
96         fTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
97             public void selectionChanged(SelectionChangedEvent event) {
98                 doSelectionChanged(((IStructuredSelection) event.getSelection()).toArray());
99             }
100         });
101         fTableViewer.addDoubleClickListener(new IDoubleClickListener() {
102             public void doubleClick(DoubleClickEvent event) {
103                 okPressed();
104             }
105         });
106         GridData data= new GridData(SWT.FILL, SWT.FILL, true, true);
107         data.heightHint= SIZING_SELECTION_WIDGET_HEIGHT;
108         data.widthHint= SIZING_SELECTION_WIDGET_WIDTH;
109         fTableViewer.getTable().setLayoutData(data);
110
111         fTableViewer.setLabelProvider(new JavaElementLabelProvider());
112         fTableViewer.setContentProvider(new StandardJavaElementContentProvider());
113         fTableViewer.setComparator(new JavaElementComparator());
114         fTableViewer.getControl().setFont(font);
115
116         Button checkbox= new Button(composite, SWT.CHECK);
117         checkbox.setText(PreferencesMessages.ProjectSelectionDialog_filter);
118         checkbox.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, true, false));
119         checkbox.addSelectionListener(new SelectionListener() {
120             public void widgetSelected(SelectionEvent e) {
121                 updateFilter(((Button) e.widget).getSelection());
122             }
123             public void widgetDefaultSelected(SelectionEvent e) {
124                 updateFilter(((Button) e.widget).getSelection());
125             }
126         });
127         IDialogSettings dialogSettings= JavaPlugin.getDefault().getDialogSettings();
128         boolean doFilter= !dialogSettings.getBoolean(DIALOG_SETTINGS_SHOW_ALL) && !fProjectsWithSpecifics.isEmpty();
129         checkbox.setSelection(doFilter);
130         updateFilter(doFilter);
131         
132         IJavaModel input= JavaCore.create(ResourcesPlugin.getWorkspace().getRoot());
133         fTableViewer.setInput(input);
134         
135         doSelectionChanged(new Object JavaDoc[0]);
136         Dialog.applyDialogFont(composite);
137         return composite;
138     }
139     
140     protected void updateFilter(boolean selected) {
141         if (selected) {
142             fTableViewer.addFilter(fFilter);
143         } else {
144             fTableViewer.removeFilter(fFilter);
145         }
146         JavaPlugin.getDefault().getDialogSettings().put(DIALOG_SETTINGS_SHOW_ALL, !selected);
147     }
148
149     private void doSelectionChanged(Object JavaDoc[] objects) {
150         if (objects.length != 1) {
151             updateStatus(new StatusInfo(IStatus.ERROR, "")); //$NON-NLS-1$
152
setSelectionResult(null);
153         } else {
154             updateStatus(new StatusInfo());
155             setSelectionResult(objects);
156         }
157     }
158
159     /* (non-Javadoc)
160      * @see org.eclipse.ui.dialogs.SelectionStatusDialog#computeResult()
161      */

162     protected void computeResult() {
163     }
164 }
165
Popular Tags