View | Details | Raw Unified | Return to bug 393143 | Differences between
and this patch

Collapse All | Expand All

(-)a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/infoviews/AbstractInfoView.java (-4 / +107 lines)
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
}
(-)a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/infoviews/JavadocView.java (-39 / +6 lines)
Lines 48-54 Link Here
48
import org.eclipse.jface.action.IMenuManager;
48
import org.eclipse.jface.action.IMenuManager;
49
import org.eclipse.jface.action.IToolBarManager;
49
import org.eclipse.jface.action.IToolBarManager;
50
import org.eclipse.jface.action.Separator;
50
import org.eclipse.jface.action.Separator;
51
import org.eclipse.jface.commands.ActionHandler;
52
import org.eclipse.jface.dialogs.MessageDialogWithToggle;
51
import org.eclipse.jface.dialogs.MessageDialogWithToggle;
53
import org.eclipse.jface.internal.text.html.BrowserInput;
52
import org.eclipse.jface.internal.text.html.BrowserInput;
54
import org.eclipse.jface.internal.text.html.HTMLPrinter;
53
import org.eclipse.jface.internal.text.html.HTMLPrinter;
Lines 91-97 Link Here
91
import org.eclipse.ui.PartInitException;
90
import org.eclipse.ui.PartInitException;
92
import org.eclipse.ui.PlatformUI;
91
import org.eclipse.ui.PlatformUI;
93
import org.eclipse.ui.actions.ActionFactory;
92
import org.eclipse.ui.actions.ActionFactory;
94
import org.eclipse.ui.handlers.IHandlerService;
95
93
96
import org.eclipse.ui.texteditor.AbstractDecoratedTextEditor;
94
import org.eclipse.ui.texteditor.AbstractDecoratedTextEditor;
97
import org.eclipse.ui.texteditor.IAbstractTextEditorHelpContextIds;
95
import org.eclipse.ui.texteditor.IAbstractTextEditorHelpContextIds;
Lines 302-330 Link Here
302
	}
300
	}
303
301
304
	/**
302
	/**
305
	 * Action to toggle linking with selection.
306
	 *
307
	 * @since 3.4
308
	 */
309
	private class LinkAction extends Action {
310
311
		public LinkAction() {
312
			super(InfoViewMessages.JavadocView_action_toogleLinking_text, SWT.TOGGLE);
313
			setToolTipText(InfoViewMessages.JavadocView_action_toggleLinking_toolTipText);
314
			JavaPluginImages.setLocalImageDescriptors(this, "synced.gif"); //$NON-NLS-1$
315
			setChecked(isLinkingEnabled());
316
		}
317
318
		/* (non-Javadoc)
319
		 * @see org.eclipse.jface.action.Action#run()
320
		 */
321
		@Override
322
		public void run() {
323
			setLinkingEnabled(!isLinkingEnabled());
324
		}
325
	}
326
327
	/**
328
	 * Action to open the selection in an external browser. If the selection is a java element its
303
	 * Action to open the selection in an external browser. If the selection is a java element its
329
	 * corresponding javadoc is shown if possible. If it is an URL the URL's content is shown.
304
	 * corresponding javadoc is shown if possible. If it is an URL the URL's content is shown.
330
	 * 
305
	 * 
Lines 459-471 Link Here
459
	private ForthAction fForthAction;
434
	private ForthAction fForthAction;
460
435
461
	/**
436
	/**
462
	 * Action to enable and disable link with selection.
437
	 * Action to open the attached Javadoc.
463
	 * @since 3.4
464
	 */
465
	private LinkAction fToggleLinkAction;
466
467
	/**
468
	 * Action to open the attached Javadoc. 
469
	 * @since 3.4
438
	 * @since 3.4
470
	 */
439
	 */
471
	private OpenInBrowserAction fOpenBrowserAction;
440
	private OpenInBrowserAction fOpenBrowserAction;
Lines 721-729 Link Here
721
		fForthAction= new ForthAction();
690
		fForthAction= new ForthAction();
722
		fForthAction.setActionDefinitionId(IWorkbenchCommandConstants.NAVIGATE_FORWARD);
691
		fForthAction.setActionDefinitionId(IWorkbenchCommandConstants.NAVIGATE_FORWARD);
723
692
724
		fToggleLinkAction= new LinkAction();
725
		fToggleLinkAction.setActionDefinitionId(IWorkbenchCommandConstants.NAVIGATE_TOGGLE_LINK_WITH_EDITOR);
726
727
		fInputSelectionProvider= new SimpleSelectionProvider();
693
		fInputSelectionProvider= new SimpleSelectionProvider();
728
		fOpenBrowserAction= new OpenInBrowserAction(getSite());
694
		fOpenBrowserAction= new OpenInBrowserAction(getSite());
729
		fOpenBrowserAction.setSpecialSelectionProvider(fInputSelectionProvider);
695
		fOpenBrowserAction.setSpecialSelectionProvider(fInputSelectionProvider);
Lines 759-766 Link Here
759
			}
725
			}
760
		});
726
		});
761
727
762
		IHandlerService handlerService= (IHandlerService) getSite().getService(IHandlerService.class);
763
		handlerService.activateHandler(IWorkbenchCommandConstants.NAVIGATE_TOGGLE_LINK_WITH_EDITOR, new ActionHandler(fToggleLinkAction));
764
	}
728
	}
765
729
766
	/* (non-Javadoc)
730
	/* (non-Javadoc)
Lines 773-779 Link Here
773
		tbm.add(fForthAction);
737
		tbm.add(fForthAction);
774
		tbm.add(new Separator());
738
		tbm.add(new Separator());
775
739
776
		tbm.add(fToggleLinkAction);
777
		super.fillToolBar(tbm);
740
		super.fillToolBar(tbm);
778
		tbm.add(fOpenBrowserAction);
741
		tbm.add(fOpenBrowserAction);
779
	}
742
	}
Lines 1242-1248 Link Here
1242
	@Override
1205
	@Override
1243
	protected IJavaElement findSelectedJavaElement(IWorkbenchPart part, ISelection selection) {
1206
	protected IJavaElement findSelectedJavaElement(IWorkbenchPart part, ISelection selection) {
1244
		IJavaElement element= super.findSelectedJavaElement(part, selection);
1207
		IJavaElement element= super.findSelectedJavaElement(part, selection);
1245
		try {			
1208
		try {
1246
			//update the Javadoc view when package.html is selected in project explorer view
1209
			//update the Javadoc view when package.html is selected in project explorer view
1247
			if (element == null && selection instanceof IStructuredSelection) {
1210
			if (element == null && selection instanceof IStructuredSelection) {
1248
				Object selectedElement= ((IStructuredSelection) selection).getFirstElement();
1211
				Object selectedElement= ((IStructuredSelection) selection).getFirstElement();
Lines 1532-1535 Link Here
1532
		}));
1495
		}));
1533
	}
1496
	}
1534
1497
1498
	@Override
1499
	protected boolean isValidViewInput(IJavaElement je) {
1500
		return !(je == null || (je.getElementType() == IJavaElement.JAVA_MODEL || je.getElementType() == IJavaElement.JAVA_PROJECT || je.getElementType() == IJavaElement.PACKAGE_FRAGMENT_ROOT));
1501
	}
1535
}
1502
}
(-)a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/infoviews/SourceView.java (-1 / +7 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
2
 * Copyright (c) 2000, 2013 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 541-544 Link Here
541
	protected String getHelpContextId() {
541
	protected String getHelpContextId() {
542
		return IJavaHelpContextIds.SOURCE_VIEW;
542
		return IJavaHelpContextIds.SOURCE_VIEW;
543
	}
543
	}
544
545
	@Override
546
	protected boolean isValidViewInput(IJavaElement je) {
547
		return (je instanceof ISourceReference);
548
	}
549
544
}
550
}

Return to bug 393143