KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > search > PluginSearchResultPage


1 /*******************************************************************************
2  * Copyright (c) 2005, 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.pde.internal.ui.search;
12
13 import org.eclipse.jface.action.IMenuManager;
14 import org.eclipse.jface.action.Separator;
15 import org.eclipse.jface.viewers.ILabelProvider;
16 import org.eclipse.jface.viewers.IStructuredSelection;
17 import org.eclipse.jface.viewers.LabelProvider;
18 import org.eclipse.jface.viewers.ViewerComparator;
19 import org.eclipse.pde.core.plugin.IPluginBase;
20 import org.eclipse.pde.core.plugin.IPluginExtension;
21 import org.eclipse.pde.core.plugin.IPluginExtensionPoint;
22 import org.eclipse.pde.core.plugin.IPluginImport;
23 import org.eclipse.pde.internal.ui.PDEPlugin;
24 import org.eclipse.pde.internal.ui.views.plugins.ImportActionGroup;
25 import org.eclipse.pde.internal.ui.views.plugins.JavaSearchActionGroup;
26 import org.eclipse.search.ui.text.Match;
27 import org.eclipse.swt.graphics.Image;
28 import org.eclipse.ui.PartInitException;
29 import org.eclipse.ui.actions.ActionContext;
30
31
32 public class PluginSearchResultPage extends AbstractSearchResultPage {
33
34     class SearchLabelProvider extends LabelProvider {
35         /* (non-Javadoc)
36          * @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object)
37          */

38         public Image getImage(Object JavaDoc element) {
39             return PDEPlugin.getDefault().getLabelProvider().getImage(element);
40         }
41         
42         /* (non-Javadoc)
43          * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
44          */

45         public String JavaDoc getText(Object JavaDoc object) {
46             if (object instanceof IPluginBase)
47                 return ((IPluginBase)object).getId();
48             
49             if (object instanceof IPluginImport) {
50                 IPluginImport dep = (IPluginImport)object;
51                 return dep.getId()
52                     + " - " //$NON-NLS-1$
53
+ dep.getPluginBase().getId();
54             }
55             
56             if (object instanceof IPluginExtension) {
57                 IPluginExtension extension = (IPluginExtension)object;
58                 return extension.getPoint() + " - " + extension.getPluginBase().getId(); //$NON-NLS-1$
59
}
60             
61             if (object instanceof IPluginExtensionPoint)
62                 return ((IPluginExtensionPoint)object).getFullId();
63
64             return PDEPlugin.getDefault().getLabelProvider().getText(object);
65         }
66     }
67     
68     public PluginSearchResultPage() {
69         super();
70         PDEPlugin.getDefault().getLabelProvider().connect(this);
71     }
72     /* (non-Javadoc)
73      * @see org.eclipse.search.ui.text.AbstractTextSearchViewPage#fillContextMenu(org.eclipse.jface.action.IMenuManager)
74      */

75     protected void fillContextMenu(IMenuManager mgr) {
76         super.fillContextMenu(mgr);
77         mgr.add(new Separator());
78         IStructuredSelection selection = (IStructuredSelection)getViewer().getSelection();
79         ActionContext context = new ActionContext(selection);
80         PluginSearchActionGroup actionGroup = new PluginSearchActionGroup();
81         actionGroup.setContext(context);
82         actionGroup.fillContextMenu(mgr);
83         if (ImportActionGroup.canImport(selection)) {
84             mgr.add(new Separator());
85             ImportActionGroup importActionGroup = new ImportActionGroup();
86             importActionGroup.setContext(context);
87             importActionGroup.fillContextMenu(mgr);
88         }
89         mgr.add(new Separator());
90         
91         JavaSearchActionGroup jsActionGroup = new JavaSearchActionGroup();
92         jsActionGroup.setContext(new ActionContext(selection));
93         jsActionGroup.fillContextMenu(mgr);
94     }
95
96     /* (non-Javadoc)
97      * @see org.eclipse.pde.internal.ui.search.AbstractSearchResultPage#createLabelProvider()
98      */

99     protected ILabelProvider createLabelProvider() {
100         return new SearchLabelProvider();
101     }
102
103     /* (non-Javadoc)
104      * @see org.eclipse.pde.internal.ui.search.AbstractSearchResultPage#createViewerSorter()
105      */

106     protected ViewerComparator createViewerComparator() {
107         return new ViewerComparator();
108     }
109     
110     /* (non-Javadoc)
111      * @see org.eclipse.search.ui.text.AbstractTextSearchViewPage#showMatch(org.eclipse.search.ui.text.Match, int, int, boolean)
112      */

113     protected void showMatch(Match match, int currentOffset, int currentLength,
114             boolean activate) throws PartInitException {
115         ManifestEditorOpener.open(match, activate);
116     }
117
118     /* (non-Javadoc)
119      * @see org.eclipse.search.ui.text.AbstractTextSearchViewPage#dispose()
120      */

121     public void dispose() {
122         PDEPlugin.getDefault().getLabelProvider().disconnect(this);
123         super.dispose();
124     }
125
126 }
127
Popular Tags