1 11 package org.eclipse.jdt.internal.ui.preferences; 12 13 import java.util.Set ; 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 private TableViewer fTableViewer; 56 private Set fProjectsWithSpecifics; 57 58 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 DIALOG_SETTINGS_SHOW_ALL= "ProjectSelectionDialog.show_all"; 64 private ViewerFilter fFilter; 65 66 public ProjectSelectionDialog(Shell parentShell, Set 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 parentElement, Object element) { 77 return fProjectsWithSpecifics.contains(element); 78 } 79 }; 80 81 } 82 83 86 protected Control createDialogArea(Composite parent) { 87 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 [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 [] objects) { 150 if (objects.length != 1) { 151 updateStatus(new StatusInfo(IStatus.ERROR, "")); setSelectionResult(null); 153 } else { 154 updateStatus(new StatusInfo()); 155 setSelectionResult(objects); 156 } 157 } 158 159 162 protected void computeResult() { 163 } 164 } 165 | Popular Tags |