KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > search > internal > ui > text > SearchAgainConfirmationDialog


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.search.internal.ui.text;
12
13 import java.util.List JavaDoc;
14
15 import org.eclipse.swt.SWT;
16 import org.eclipse.swt.graphics.Image;
17 import org.eclipse.swt.layout.GridData;
18 import org.eclipse.swt.widgets.Composite;
19 import org.eclipse.swt.widgets.Control;
20 import org.eclipse.swt.widgets.Label;
21 import org.eclipse.swt.widgets.Shell;
22
23 import org.eclipse.jface.dialogs.Dialog;
24 import org.eclipse.jface.viewers.ArrayContentProvider;
25 import org.eclipse.jface.viewers.ILabelProvider;
26 import org.eclipse.jface.viewers.LabelProvider;
27 import org.eclipse.jface.viewers.TableViewer;
28
29 import org.eclipse.search.internal.ui.SearchMessages;
30
31 /**
32  * Dialog telling the user that files are out of sync or matches
33  * are stale and asks for confirmation to refresh/search again
34  * @since 3.0
35  */

36
37 public class SearchAgainConfirmationDialog extends Dialog {
38     private List JavaDoc fOutOfSync;
39     private List JavaDoc fOutOfDate;
40     private ILabelProvider fLabelProvider;
41     
42     private class ProxyLabelProvider extends LabelProvider {
43         
44         
45         /* (non-Javadoc)
46          * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)
47          */

48         public Image getImage(Object JavaDoc element) {
49             if (fLabelProvider != null)
50                 return fLabelProvider.getImage(element);
51             return null;
52         }
53         
54         /* (non-Javadoc)
55          * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
56          */

57         public String JavaDoc getText(Object JavaDoc element) {
58             if (fLabelProvider != null)
59                 return fLabelProvider.getText(element);
60             return null;
61         }
62         
63     }
64     
65     public SearchAgainConfirmationDialog(Shell shell, ILabelProvider labelProvider, List JavaDoc outOfSync, List JavaDoc outOfDate) {
66         super(shell);
67         fOutOfSync= outOfSync;
68         fOutOfDate= outOfDate;
69         fLabelProvider= labelProvider;
70         setShellStyle(getShellStyle() | SWT.RESIZE);
71     }
72     
73     /* (non-Javadoc)
74      * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
75      */

76     protected Control createDialogArea(Composite parent) {
77         Composite result= (Composite) super.createDialogArea(parent);
78         
79         if (fOutOfSync.size() > 0) {
80             createLabel(result, SearchMessages.SearchAgainConfirmationDialog_outofsync_message);
81             
82             createLabel(result, SearchMessages.SearchAgainConfirmationDialog_outofsync_label);
83             createTableViewer(fOutOfSync, result);
84         } else {
85             createLabel(result, SearchMessages.SearchAgainConfirmationDialog_stale_message);
86         }
87         
88         createLabel(result, SearchMessages.SearchAgainConfirmationDialog_stale_label);
89         createTableViewer(fOutOfDate, result);
90         return result;
91     }
92     
93     private void createLabel(Composite parent, String JavaDoc text) {
94         Label message= new Label(parent, SWT.WRAP);
95         GridData gd= new GridData(GridData.FILL_HORIZONTAL);
96         gd.widthHint= convertWidthInCharsToPixels(70);
97         message.setLayoutData(gd);
98         message.setText(text);
99     }
100     
101     private TableViewer createTableViewer(List JavaDoc input, Composite result) {
102         TableViewer viewer= new TableViewer(result);
103         viewer.setContentProvider(new ArrayContentProvider());
104         viewer.setLabelProvider(new ProxyLabelProvider());
105         viewer.setInput(input);
106         GridData gd= new GridData(GridData.FILL_BOTH);
107         gd.widthHint= convertWidthInCharsToPixels(70);
108         gd.heightHint= convertHeightInCharsToPixels(5);
109         viewer.getControl().setLayoutData(gd);
110         return viewer;
111     }
112     
113     protected void configureShell(Shell shell) {
114         super.configureShell(shell);
115         shell.setText(SearchMessages.SearchAgainConfirmationDialog_title);
116     }
117     
118 }
119
Popular Tags