upload tizen1.0 source
[sdk/ide/product.git] / org.eclipse.cdt.ui / src / org / eclipse / cdt / internal / ui / search / actions / FindDeclarationsProjectAction.java
1 /*******************************************************************************
2  * Copyright (c) 2005, 2008 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.cdt.internal.ui.search.actions;
12
13 import org.eclipse.cdt.core.model.CoreModel;
14 import org.eclipse.cdt.core.model.ICElement;
15 import org.eclipse.cdt.core.model.ICProject;
16 import org.eclipse.cdt.internal.ui.editor.CEditor;
17 import org.eclipse.cdt.internal.ui.search.CSearchMessages;
18 import org.eclipse.cdt.internal.ui.search.PDOMSearchQuery;
19 import org.eclipse.core.resources.IResource;
20 import org.eclipse.jface.viewers.ISelection;
21 import org.eclipse.jface.viewers.IStructuredSelection;
22 import org.eclipse.ui.IWorkbenchSite;
23
24 public class FindDeclarationsProjectAction extends FindAction {
25
26         public FindDeclarationsProjectAction(CEditor editor, String label, String tooltip){
27                 super(editor);
28                 setText(label); 
29                 setToolTipText(tooltip); 
30         }
31         
32         public FindDeclarationsProjectAction(CEditor editor){
33                 this(editor,
34                         CSearchMessages.CSearch_FindDeclarationsProjectAction_label, 
35                         CSearchMessages.CSearch_FindDeclarationsProjectAction_tooltip); 
36         }
37         
38         public FindDeclarationsProjectAction(IWorkbenchSite site){
39                 this(site,
40                         CSearchMessages.CSearch_FindDeclarationsProjectAction_label, 
41                         CSearchMessages.CSearch_FindDeclarationsProjectAction_tooltip); 
42         }
43
44         public FindDeclarationsProjectAction(IWorkbenchSite site, String label, String tooltip) {
45                 super(site);
46                 setText(label);
47                 setToolTipText(tooltip);
48         }
49
50         @Override
51         protected ICElement[] getScope() {
52                 ICProject project = null;
53                 if (fEditor != null) {
54                         project = fEditor.getInputCElement().getCProject();                      
55                 } else if (fSite != null){
56                         ISelection selection = getSelection();
57                         if (selection instanceof IStructuredSelection) {
58                                 Object element = ((IStructuredSelection)selection).getFirstElement();
59                                 if (element instanceof IResource)
60                                         project = CoreModel.getDefault().create(((IResource)element).getProject());
61                                 else if (element instanceof ICElement)
62                                         project = ((ICElement)element).getCProject();
63                         }
64                 }
65                 
66                 return project != null ? new ICElement[] { project } : null;
67         }
68
69         @Override
70         protected String getScopeDescription() {
71                 return CSearchMessages.ProjectScope; 
72         }
73
74         @Override
75         protected int getLimitTo() {
76                 return PDOMSearchQuery.FIND_DECLARATIONS_DEFINITIONS;
77         }
78
79 }