Lines 1-5
Link Here
|
1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2000, 2011 IBM Corporation and others. |
2 |
* Copyright (c) 2000, 2016 IBM Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
Lines 11-16
Link Here
|
11 |
package org.eclipse.jdt.ui.actions; |
11 |
package org.eclipse.jdt.ui.actions; |
12 |
|
12 |
|
13 |
import java.lang.reflect.InvocationTargetException; |
13 |
import java.lang.reflect.InvocationTargetException; |
|
|
14 |
import java.util.ArrayList; |
15 |
import java.util.Iterator; |
14 |
|
16 |
|
15 |
import org.eclipse.core.runtime.IAdaptable; |
17 |
import org.eclipse.core.runtime.IAdaptable; |
16 |
import org.eclipse.core.runtime.IStatus; |
18 |
import org.eclipse.core.runtime.IStatus; |
Lines 98-104
Link Here
|
98 |
*/ |
100 |
*/ |
99 |
abstract Class<?>[] getValidTypes(); |
101 |
abstract Class<?>[] getValidTypes(); |
100 |
|
102 |
|
101 |
private boolean canOperateOn(IStructuredSelection sel) { |
103 |
boolean canOperateOn(IStructuredSelection sel) { |
102 |
return sel != null && !sel.isEmpty() && canOperateOn(getJavaElement(sel, true)); |
104 |
return sel != null && !sel.isEmpty() && canOperateOn(getJavaElement(sel, true)); |
103 |
} |
105 |
} |
104 |
|
106 |
|
Lines 139-144
Link Here
|
139 |
} |
141 |
} |
140 |
} |
142 |
} |
141 |
|
143 |
|
|
|
144 |
IJavaElement getJavaElement(Object firstElement, boolean silent) { |
145 |
IJavaElement elem= null; |
146 |
if (firstElement instanceof IJavaElement) |
147 |
elem= (IJavaElement) firstElement; |
148 |
else if (firstElement instanceof IAdaptable) |
149 |
elem= ((IAdaptable) firstElement).getAdapter(IJavaElement.class); |
150 |
if (elem != null) { |
151 |
return getTypeIfPossible(elem, silent); |
152 |
} |
153 |
|
154 |
return null; |
155 |
} |
156 |
|
142 |
IJavaElement getJavaElement(IStructuredSelection selection, boolean silent) { |
157 |
IJavaElement getJavaElement(IStructuredSelection selection, boolean silent) { |
143 |
if (selection.size() == 1) { |
158 |
if (selection.size() == 1) { |
144 |
Object firstElement= selection.getFirstElement(); |
159 |
Object firstElement= selection.getFirstElement(); |
Lines 153-158
Link Here
|
153 |
|
168 |
|
154 |
} |
169 |
} |
155 |
return null; |
170 |
return null; |
|
|
171 |
} |
172 |
|
173 |
ArrayList<IJavaElement> getMultipleJavaElement(IStructuredSelection selection, boolean silent) { |
174 |
ArrayList<IJavaElement> javaElementList = new ArrayList<>(); |
175 |
for (Iterator<?> iter= selection.iterator(); iter.hasNext();) { |
176 |
Object firstElement= iter.next(); |
177 |
IJavaElement elem= null; |
178 |
if (firstElement instanceof IJavaElement) |
179 |
elem= (IJavaElement) firstElement; |
180 |
else if (firstElement instanceof IAdaptable) |
181 |
elem= ((IAdaptable) firstElement).getAdapter(IJavaElement.class); |
182 |
if (elem != null) { |
183 |
javaElementList.add(getTypeIfPossible(elem, silent)); |
184 |
} |
185 |
} |
186 |
return javaElementList; |
156 |
} |
187 |
} |
157 |
|
188 |
|
158 |
private void showOperationUnavailableDialog() { |
189 |
private void showOperationUnavailableDialog() { |
Lines 201-215
Link Here
|
201 |
*/ |
232 |
*/ |
202 |
@Override |
233 |
@Override |
203 |
public void run(IStructuredSelection selection) { |
234 |
public void run(IStructuredSelection selection) { |
204 |
IJavaElement element= getJavaElement(selection, false); |
235 |
if (selection.size() == 1) { |
205 |
if (element == null || !element.exists()) { |
236 |
IJavaElement element= getJavaElement(selection, false); |
206 |
showOperationUnavailableDialog(); |
237 |
if (element == null || !element.exists()) { |
207 |
return; |
238 |
showOperationUnavailableDialog(); |
|
|
239 |
return; |
240 |
} |
241 |
else if (element == RETURN_WITHOUT_BEEP) |
242 |
return; |
243 |
|
244 |
run(element); |
208 |
} |
245 |
} |
209 |
else if (element == RETURN_WITHOUT_BEEP) |
246 |
else { |
210 |
return; |
247 |
ArrayList<IJavaElement> elementList = getMultipleJavaElement(selection, false); |
211 |
|
248 |
for (Iterator iterator= elementList.iterator(); iterator.hasNext();) { |
212 |
run(element); |
249 |
IJavaElement element= (IJavaElement) iterator.next(); |
|
|
250 |
if (element == null || !element.exists()) { |
251 |
showOperationUnavailableDialog(); |
252 |
return; |
253 |
} |
254 |
else if (!ActionUtil.isProcessable(getShell(), element)) |
255 |
return; |
256 |
else if (element == RETURN_WITHOUT_BEEP) |
257 |
return; |
258 |
} |
259 |
run(elementList); |
260 |
} |
213 |
} |
261 |
} |
214 |
|
262 |
|
215 |
/* |
263 |
/* |
Lines 275-282
Link Here
|
275 |
// cancelled |
323 |
// cancelled |
276 |
} |
324 |
} |
277 |
} |
325 |
} |
|
|
326 |
|
327 |
/** |
328 |
* Executes this action for the given java element List. |
329 |
* @param element The java element in Lists to be found. |
330 |
* @since 3.12 |
331 |
*/ |
332 |
public void run(ArrayList<IJavaElement> element) { |
333 |
// will return true except for debugging purposes. |
334 |
try { |
335 |
performNewSearch(element); |
336 |
} catch (JavaModelException ex) { |
337 |
ExceptionHandler.handle(ex, getShell(), SearchMessages.Search_Error_search_notsuccessful_title, SearchMessages.Search_Error_search_notsuccessful_message); |
338 |
} catch (InterruptedException e) { |
339 |
// cancelled |
340 |
} |
341 |
} |
278 |
|
342 |
|
279 |
private void performNewSearch(IJavaElement element) throws JavaModelException, InterruptedException { |
343 |
private void performNewSearch(IJavaElement element) throws JavaModelException, InterruptedException { |
|
|
344 |
JavaSearchQuery query= new JavaSearchQuery(createQuery(element)); |
345 |
if (query.canRunInBackground()) { |
346 |
/* |
347 |
* This indirection with Object as parameter is needed to prevent the loading |
348 |
* of the Search plug-in: the VM verifies the method call and hence loads the |
349 |
* types used in the method signature, eventually triggering the loading of |
350 |
* a plug-in (in this case ISearchQuery results in Search plug-in being loaded). |
351 |
*/ |
352 |
SearchUtil.runQueryInBackground(query); |
353 |
} else { |
354 |
IProgressService progressService= PlatformUI.getWorkbench().getProgressService(); |
355 |
/* |
356 |
* This indirection with Object as parameter is needed to prevent the loading |
357 |
* of the Search plug-in: the VM verifies the method call and hence loads the |
358 |
* types used in the method signature, eventually triggering the loading of |
359 |
* a plug-in (in this case it would be ISearchQuery). |
360 |
*/ |
361 |
IStatus status= SearchUtil.runQueryInForeground(progressService, query); |
362 |
if (status.matches(IStatus.ERROR | IStatus.INFO | IStatus.WARNING)) { |
363 |
ErrorDialog.openError(getShell(), SearchMessages.Search_Error_search_title, SearchMessages.Search_Error_search_message, status); |
364 |
} |
365 |
} |
366 |
} |
367 |
|
368 |
private void performNewSearch(ArrayList<IJavaElement> element) throws JavaModelException, InterruptedException { |
280 |
JavaSearchQuery query= new JavaSearchQuery(createQuery(element)); |
369 |
JavaSearchQuery query= new JavaSearchQuery(createQuery(element)); |
281 |
if (query.canRunInBackground()) { |
370 |
if (query.canRunInBackground()) { |
282 |
/* |
371 |
/* |
Lines 316-322
Link Here
|
316 |
String description= factory.getWorkspaceScopeDescription(true); |
405 |
String description= factory.getWorkspaceScopeDescription(true); |
317 |
return new ElementQuerySpecification(element, getLimitTo(), scope, description); |
406 |
return new ElementQuerySpecification(element, getLimitTo(), scope, description); |
318 |
} |
407 |
} |
319 |
|
408 |
|
|
|
409 |
/** |
410 |
* Creates a query for the given element. Subclasses reimplement this method. |
411 |
* |
412 |
* @param elementList the elements to create a query for |
413 |
* |
414 |
* @return returns the query |
415 |
* @throws JavaModelException thrown when accessing the element failed |
416 |
* @throws InterruptedException thrown when the user interrupted the query selection |
417 |
*/ |
418 |
QuerySpecification createQuery(ArrayList<IJavaElement> elementList) throws JavaModelException, InterruptedException { |
419 |
IJavaElement element = elementList.get(0); |
420 |
JavaSearchScopeFactory factory= JavaSearchScopeFactory.getInstance(); |
421 |
IJavaSearchScope scope= factory.createWorkspaceScope(true); |
422 |
String description= factory.getWorkspaceScopeDescription(true); |
423 |
return new ElementQuerySpecification(element, getLimitTo(), scope, description); |
424 |
} |
320 |
abstract int getLimitTo(); |
425 |
abstract int getLimitTo(); |
321 |
|
426 |
|
322 |
IType getType(IJavaElement element) { |
427 |
IType getType(IJavaElement element) { |