KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > search > internal > ui > ShowSearchesAction


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;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.Arrays JavaDoc;
15 import java.util.Iterator JavaDoc;
16 import java.util.List JavaDoc;
17
18 import org.eclipse.swt.graphics.Image;
19
20 import org.eclipse.jface.action.Action;
21 import org.eclipse.jface.resource.ImageDescriptor;
22 import org.eclipse.jface.viewers.LabelProvider;
23 import org.eclipse.jface.window.Window;
24
25 import org.eclipse.search.internal.ui.util.ListDialog;
26
27 /**
28  * Invoke the resource creation wizard selection Wizard.
29  * This action will retarget to the active view.
30  * @deprecated old search
31  */

32 class ShowSearchesAction extends Action {
33
34     private static final class SearchesLabelProvider extends LabelProvider {
35         
36         private ArrayList JavaDoc fImages= new ArrayList JavaDoc();
37         
38         public String JavaDoc getText(Object JavaDoc element) {
39             if (!(element instanceof ShowSearchAction))
40                 return ""; //$NON-NLS-1$
41
return ((ShowSearchAction)element).getText();
42         }
43         public Image getImage(Object JavaDoc element) {
44             if (!(element instanceof ShowSearchAction))
45                 return null;
46
47             ImageDescriptor imageDescriptor= ((ShowSearchAction)element).getImageDescriptor();
48             if (imageDescriptor == null)
49                 return null;
50             
51             Image image= imageDescriptor.createImage();
52             fImages.add(image);
53
54             return image;
55         }
56         
57         public void dispose() {
58             Iterator JavaDoc iter= fImages.iterator();
59             while (iter.hasNext())
60                 ((Image)iter.next()).dispose();
61             
62             fImages= null;
63         }
64     }
65
66     /**
67      * Create a new instance of this class
68      */

69     public ShowSearchesAction() {
70         super(SearchMessages.ShowOtherSearchesAction_label);
71         setToolTipText(SearchMessages.ShowOtherSearchesAction_tooltip);
72     }
73     /*
74      * Overrides method from Action
75      */

76     public void run() {
77         run(false);
78     }
79      
80     public void run(boolean showAll) {
81         Iterator JavaDoc iter= SearchManager.getDefault().getPreviousSearches().iterator();
82         int cutOffSize;
83         if (showAll)
84             cutOffSize= 0;
85         else
86             cutOffSize= SearchDropDownAction.RESULTS_IN_DROP_DOWN;
87         int size= SearchManager.getDefault().getPreviousSearches().size() - cutOffSize;
88         Search selectedSearch= SearchManager.getDefault().getCurrentSearch();
89         Action selectedAction = null;
90         ArrayList JavaDoc input= new ArrayList JavaDoc(size);
91         int i= 0;
92         while (iter.hasNext()) {
93             Search search= (Search)iter.next();
94             if (i++ < cutOffSize)
95                 continue;
96             Action action= new ShowSearchAction(search);
97             input.add(action);
98             if (selectedSearch == search)
99                 selectedAction= action;
100         }
101
102         // Open a list dialog.
103
String JavaDoc title;
104         String JavaDoc message;
105         if (showAll) {
106             title= SearchMessages.PreviousSearchesDialog_title;
107             message= SearchMessages.PreviousSearchesDialog_message;
108         }
109         else {
110             title= SearchMessages.OtherSearchesDialog_title;
111             message= SearchMessages.OtherSearchesDialog_message;
112         }
113         
114         LabelProvider labelProvider=new SearchesLabelProvider();
115
116         ListDialog dlg= new ListDialog(SearchPlugin.getActiveWorkbenchShell(),input, title, message, new SearchResultContentProvider(), labelProvider);
117         if (selectedAction != null) {
118             Object JavaDoc[] selected= new Object JavaDoc[1];
119             selected[0]= selectedAction;
120             dlg.setInitialSelections(selected);
121         }
122         if (dlg.open() == Window.OK) {
123             List JavaDoc result= Arrays.asList(dlg.getResult());
124             if (result != null && result.size() == 1) {
125                 ((ShowSearchAction)result.get(0)).run();
126             }
127         }
128     }
129 }
130
Popular Tags