Lines 26-37
Link Here
|
26 |
import org.eclipse.core.runtime.IProgressMonitor; |
26 |
import org.eclipse.core.runtime.IProgressMonitor; |
27 |
import org.eclipse.core.runtime.NullProgressMonitor; |
27 |
import org.eclipse.core.runtime.NullProgressMonitor; |
28 |
|
28 |
|
|
|
29 |
import org.eclipse.jface.action.Action; |
29 |
import org.eclipse.jface.action.IAction; |
30 |
import org.eclipse.jface.action.IAction; |
30 |
import org.eclipse.jface.action.IMenuListener; |
31 |
import org.eclipse.jface.action.IMenuListener; |
31 |
import org.eclipse.jface.action.IMenuManager; |
32 |
import org.eclipse.jface.action.IMenuManager; |
32 |
import org.eclipse.jface.action.IToolBarManager; |
33 |
import org.eclipse.jface.action.IToolBarManager; |
33 |
import org.eclipse.jface.action.MenuManager; |
34 |
import org.eclipse.jface.action.MenuManager; |
34 |
import org.eclipse.jface.action.Separator; |
35 |
import org.eclipse.jface.action.Separator; |
|
|
36 |
import org.eclipse.jface.commands.ActionHandler; |
35 |
import org.eclipse.jface.resource.ColorRegistry; |
37 |
import org.eclipse.jface.resource.ColorRegistry; |
36 |
import org.eclipse.jface.resource.JFaceResources; |
38 |
import org.eclipse.jface.resource.JFaceResources; |
37 |
import org.eclipse.jface.util.IPropertyChangeListener; |
39 |
import org.eclipse.jface.util.IPropertyChangeListener; |
Lines 48-57
Link Here
|
48 |
import org.eclipse.ui.IActionBars; |
50 |
import org.eclipse.ui.IActionBars; |
49 |
import org.eclipse.ui.IPartListener2; |
51 |
import org.eclipse.ui.IPartListener2; |
50 |
import org.eclipse.ui.ISelectionListener; |
52 |
import org.eclipse.ui.ISelectionListener; |
|
|
53 |
import org.eclipse.ui.IWorkbenchCommandConstants; |
51 |
import org.eclipse.ui.IWorkbenchPart; |
54 |
import org.eclipse.ui.IWorkbenchPart; |
52 |
import org.eclipse.ui.IWorkbenchPartReference; |
55 |
import org.eclipse.ui.IWorkbenchPartReference; |
53 |
import org.eclipse.ui.PlatformUI; |
56 |
import org.eclipse.ui.PlatformUI; |
54 |
import org.eclipse.ui.actions.ActionFactory; |
57 |
import org.eclipse.ui.actions.ActionFactory; |
|
|
58 |
import org.eclipse.ui.handlers.IHandlerService; |
55 |
import org.eclipse.ui.part.ViewPart; |
59 |
import org.eclipse.ui.part.ViewPart; |
56 |
|
60 |
|
57 |
import org.eclipse.ui.texteditor.ITextEditorActionConstants; |
61 |
import org.eclipse.ui.texteditor.ITextEditorActionConstants; |
Lines 67-72
Link Here
|
67 |
import org.eclipse.jdt.ui.JavaElementLabels; |
71 |
import org.eclipse.jdt.ui.JavaElementLabels; |
68 |
import org.eclipse.jdt.ui.actions.SelectionDispatchAction; |
72 |
import org.eclipse.jdt.ui.actions.SelectionDispatchAction; |
69 |
|
73 |
|
|
|
74 |
import org.eclipse.jdt.internal.ui.JavaPluginImages; |
70 |
import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor; |
75 |
import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor; |
71 |
import org.eclipse.jdt.internal.ui.text.JavaHeuristicScanner; |
76 |
import org.eclipse.jdt.internal.ui.text.JavaHeuristicScanner; |
72 |
import org.eclipse.jdt.internal.ui.text.Symbols; |
77 |
import org.eclipse.jdt.internal.ui.text.Symbols; |
Lines 250-255
Link Here
|
250 |
fGotoInputAction.setEnabled(false); |
255 |
fGotoInputAction.setEnabled(false); |
251 |
fCopyToClipboardAction= new CopyToClipboardAction(getViewSite()); |
256 |
fCopyToClipboardAction= new CopyToClipboardAction(getViewSite()); |
252 |
|
257 |
|
|
|
258 |
fToggleLinkAction= new LinkAction(); |
259 |
fToggleLinkAction.setActionDefinitionId(IWorkbenchCommandConstants.NAVIGATE_TOGGLE_LINK_WITH_EDITOR); |
260 |
|
253 |
ISelectionProvider provider= getSelectionProvider(); |
261 |
ISelectionProvider provider= getSelectionProvider(); |
254 |
if (provider != null) |
262 |
if (provider != null) |
255 |
provider.addSelectionChangedListener(fCopyToClipboardAction); |
263 |
provider.addSelectionChangedListener(fCopyToClipboardAction); |
Lines 331-336
Link Here
|
331 |
action= getSelectAllAction(); |
339 |
action= getSelectAllAction(); |
332 |
if (action != null) |
340 |
if (action != null) |
333 |
actionBars.setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(), action); |
341 |
actionBars.setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(), action); |
|
|
342 |
|
343 |
IHandlerService handlerService= (IHandlerService) getSite().getService(IHandlerService.class); |
344 |
handlerService.activateHandler(IWorkbenchCommandConstants.NAVIGATE_TOGGLE_LINK_WITH_EDITOR, new ActionHandler(fToggleLinkAction)); |
334 |
} |
345 |
} |
335 |
|
346 |
|
336 |
/** |
347 |
/** |
Lines 341-346
Link Here
|
341 |
* @param tbm the tool bar manager |
352 |
* @param tbm the tool bar manager |
342 |
*/ |
353 |
*/ |
343 |
protected void fillToolBar(IToolBarManager tbm) { |
354 |
protected void fillToolBar(IToolBarManager tbm) { |
|
|
355 |
tbm.add(fToggleLinkAction); |
344 |
tbm.add(fGotoInputAction); |
356 |
tbm.add(fGotoInputAction); |
345 |
} |
357 |
} |
346 |
|
358 |
|
Lines 405-419
Link Here
|
405 |
* Sets whether this info view reacts to selection |
417 |
* Sets whether this info view reacts to selection |
406 |
* changes in the workbench. |
418 |
* changes in the workbench. |
407 |
* |
419 |
* |
408 |
* @param enabled if true then the input is set on selection changes |
420 |
* @param enabled if <code>true</code> then the input is set on selection changes |
409 |
*/ |
421 |
*/ |
410 |
protected void setLinkingEnabled(boolean enabled) { |
422 |
protected void setLinkingEnabled(boolean enabled) { |
411 |
fLinking= enabled; |
423 |
fLinking= enabled; |
412 |
|
424 |
|
413 |
if (fLinking && fLastSelectionProvider != null) { |
425 |
if (fLinking && fLastSelectionProvider != null) { |
414 |
computeAndSetInput(fLastSelectionProvider); |
426 |
//compute the current selection |
|
|
427 |
ISelection selection= fLastSelectionProvider.getSite().getSelectionProvider().getSelection(); |
428 |
if (!selection.isEmpty()) { |
429 |
IJavaElement je= findSelectedJavaElement(null, selection); |
430 |
if (selection instanceof IStructuredSelection && !isValidViewInput(je)) { |
431 |
//while re-enabling if the selection is invalid then clear the view |
432 |
doSetInput(null); |
433 |
fCurrentViewInput= null; |
434 |
} else { |
435 |
computeAndSetInput(fLastSelectionProvider); |
436 |
} |
437 |
} else { |
438 |
//while re-enabling if the selection is empty use the previously computed input to set the view content |
439 |
setInput(fCurrentViewInput); |
440 |
} |
415 |
} |
441 |
} |
416 |
} |
442 |
} |
|
|
443 |
|
444 |
/** |
445 |
* Finds whether the given Java element is a valid input for the current view. |
446 |
* |
447 |
* @param je the Java element whose validity has to be checked |
448 |
* @return <code>true</code> if the Java element can be a valid input to the view, |
449 |
* <code>false</code> otherwise |
450 |
* @since 3.9 |
451 |
*/ |
452 |
protected abstract boolean isValidViewInput(IJavaElement je); |
417 |
|
453 |
|
418 |
/** |
454 |
/** |
419 |
* Returns whether this info view reacts to selection |
455 |
* Returns whether this info view reacts to selection |
Lines 434-441
Link Here
|
434 |
|
470 |
|
435 |
fLastSelectionProvider= part; |
471 |
fLastSelectionProvider= part; |
436 |
|
472 |
|
437 |
if (fLinking) |
473 |
if (fLinking) { |
438 |
computeAndSetInput(part); |
474 |
computeAndSetInput(part); |
|
|
475 |
|
476 |
String iconName= SYNCED_GIF; |
477 |
//find the current structured selection |
478 |
if (!selection.isEmpty()) { |
479 |
IJavaElement je= findSelectedJavaElement(part, selection); |
480 |
//if there is an existing valid view input and the current selection is invalid, then update the icon |
481 |
if (getInput() != null |
482 |
&& selection instanceof IStructuredSelection |
483 |
&& !isValidViewInput(je)) { |
484 |
//Testcase : Select a valid Java file in the Package explorer view and then select a Java project |
485 |
if (isValidViewInput(fCurrentViewInput) && fCurrentViewInput.exists()) { |
486 |
iconName= SYNC_BROKEN_GIF; |
487 |
} |
488 |
} |
489 |
} |
490 |
//if the selection is empty and the view input element does not exist. Testcase :Select a Java file in Package explorer view and then delete it. |
491 |
else if (fCurrentViewInput != null && !fCurrentViewInput.exists()) { |
492 |
iconName= SYNC_BROKEN_GIF; |
493 |
} |
494 |
JavaPluginImages.setLocalImageDescriptors(fToggleLinkAction, iconName); |
495 |
} |
439 |
} |
496 |
} |
440 |
|
497 |
|
441 |
/** |
498 |
/** |
Lines 471-477
Link Here
|
471 |
IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput()); |
528 |
IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput()); |
472 |
ISelection methodSelection = guessMethodNamePosition(document, (ITextSelection)selection); |
529 |
ISelection methodSelection = guessMethodNamePosition(document, (ITextSelection)selection); |
473 |
// if an enclosing method call could not be found |
530 |
// if an enclosing method call could not be found |
474 |
if (methodSelection == null) |
531 |
if (methodSelection == null) |
475 |
return null; |
532 |
return null; |
476 |
// call this method recursively with the new selection |
533 |
// call this method recursively with the new selection |
477 |
return findSelectedJavaElement(part, methodSelection); |
534 |
return findSelectedJavaElement(part, methodSelection); |
Lines 771-774
Link Here
|
771 |
setContentDescription(description); |
828 |
setContentDescription(description); |
772 |
setTitleToolTip(toolTip); |
829 |
setTitleToolTip(toolTip); |
773 |
} |
830 |
} |
|
|
831 |
|
832 |
/** |
833 |
* Action to enable and disable link with selection. |
834 |
* |
835 |
* @since 3.4 |
836 |
*/ |
837 |
protected LinkAction fToggleLinkAction; |
838 |
|
839 |
/** |
840 |
* Name of the link with selection icon when the view and selection is in sync. |
841 |
* |
842 |
* @since 3.9 |
843 |
*/ |
844 |
private static final String SYNCED_GIF= "synced.gif"; //$NON-NLS-1$ |
845 |
|
846 |
/** |
847 |
* Name of the link with selection icon when the view and selection is out of sync. |
848 |
* |
849 |
* @since 3.9 |
850 |
*/ |
851 |
private static final String SYNC_BROKEN_GIF= "sync_broken.gif"; //$NON-NLS-1$ |
852 |
|
853 |
/** |
854 |
* Action to toggle linking with selection. |
855 |
* |
856 |
* @since 3.4 |
857 |
*/ |
858 |
private class LinkAction extends Action { |
859 |
|
860 |
|
861 |
public LinkAction() { |
862 |
super(InfoViewMessages.JavadocView_action_toogleLinking_text, SWT.TOGGLE); |
863 |
setToolTipText(InfoViewMessages.JavadocView_action_toggleLinking_toolTipText); |
864 |
JavaPluginImages.setLocalImageDescriptors(this, SYNCED_GIF); |
865 |
setChecked(fLinking); |
866 |
} |
867 |
|
868 |
/* (non-Javadoc) |
869 |
* @see org.eclipse.jface.action.Action#run() |
870 |
*/ |
871 |
@Override |
872 |
public void run() { |
873 |
setLinkingEnabled(!fLinking); |
874 |
JavaPluginImages.setLocalImageDescriptors(fToggleLinkAction, SYNCED_GIF); |
875 |
} |
876 |
} |
774 |
} |
877 |
} |