Lines 12-24
Link Here
|
12 |
|
12 |
|
13 |
import java.util.*; |
13 |
import java.util.*; |
14 |
|
14 |
|
|
|
15 |
import org.eclipse.core.resources.IFile; |
16 |
import org.eclipse.core.resources.IResource; |
15 |
import org.eclipse.core.runtime.*; |
17 |
import org.eclipse.core.runtime.*; |
16 |
import org.eclipse.jface.action.IMenuManager; |
18 |
import org.eclipse.jface.action.IMenuManager; |
17 |
import org.eclipse.jface.action.IToolBarManager; |
19 |
import org.eclipse.jface.action.IToolBarManager; |
|
|
20 |
import org.eclipse.jface.commands.ActionHandler; |
18 |
import org.eclipse.jface.dialogs.*; |
21 |
import org.eclipse.jface.dialogs.*; |
19 |
import org.eclipse.jface.util.IPropertyChangeListener; |
22 |
import org.eclipse.jface.util.IPropertyChangeListener; |
20 |
import org.eclipse.jface.util.PropertyChangeEvent; |
23 |
import org.eclipse.jface.util.PropertyChangeEvent; |
21 |
import org.eclipse.jface.viewers.IBasicPropertyConstants; |
24 |
import org.eclipse.jface.viewers.*; |
22 |
import org.eclipse.osgi.util.NLS; |
25 |
import org.eclipse.osgi.util.NLS; |
23 |
import org.eclipse.swt.widgets.Composite; |
26 |
import org.eclipse.swt.widgets.Composite; |
24 |
import org.eclipse.swt.widgets.Display; |
27 |
import org.eclipse.swt.widgets.Display; |
Lines 29-41
Link Here
|
29 |
import org.eclipse.team.ui.synchronize.*; |
32 |
import org.eclipse.team.ui.synchronize.*; |
30 |
import org.eclipse.ui.*; |
33 |
import org.eclipse.ui.*; |
31 |
import org.eclipse.ui.actions.ActionFactory; |
34 |
import org.eclipse.ui.actions.ActionFactory; |
|
|
35 |
import org.eclipse.ui.handlers.IHandlerService; |
36 |
import org.eclipse.ui.ide.IDE; |
32 |
import org.eclipse.ui.part.*; |
37 |
import org.eclipse.ui.part.*; |
33 |
import org.eclipse.ui.progress.IWorkbenchSiteProgressService; |
38 |
import org.eclipse.ui.progress.IWorkbenchSiteProgressService; |
34 |
|
39 |
|
35 |
/** |
40 |
/** |
36 |
* Implements a Synchronize View that contains multiple synchronize participants. |
41 |
* Implements a Synchronize View that contains multiple synchronize participants. |
37 |
*/ |
42 |
*/ |
38 |
public class SynchronizeView extends PageBookView implements ISynchronizeView, ISynchronizeParticipantListener, IPropertyChangeListener, ISaveablesSource, ISaveablePart { |
43 |
public class SynchronizeView extends PageBookView implements ISynchronizeView, ISynchronizeParticipantListener, IPropertyChangeListener, ISaveablesSource, ISaveablePart, IShowInTarget { |
39 |
|
44 |
|
40 |
/** |
45 |
/** |
41 |
* Suggested maximum length of participant names when shown in certain menus and dialog. |
46 |
* Suggested maximum length of participant names when shown in certain menus and dialog. |
Lines 77-87
Link Here
|
77 |
*/ |
82 |
*/ |
78 |
private RemoveSynchronizeParticipantAction fRemoveAllAction; |
83 |
private RemoveSynchronizeParticipantAction fRemoveAllAction; |
79 |
|
84 |
|
|
|
85 |
private ToggleLinkingAction fToggleLinkingAction; |
86 |
private boolean fLinkingEnabled; |
87 |
private OpenAndLinkWithEditorHelper fOpenAndLinkWithEditorHelper; |
88 |
|
80 |
/** |
89 |
/** |
81 |
* Preference key to save |
90 |
* Preference key to save |
82 |
*/ |
91 |
*/ |
83 |
private static final String KEY_LAST_ACTIVE_PARTICIPANT_ID = "lastactiveparticipant_id"; //$NON-NLS-1$ |
92 |
private static final String KEY_LAST_ACTIVE_PARTICIPANT_ID = "lastactiveparticipant_id"; //$NON-NLS-1$ |
84 |
private static final String KEY_LAST_ACTIVE_PARTICIPANT_SECONDARY_ID = "lastactiveparticipant_sec_id"; //$NON-NLS-1$ |
93 |
private static final String KEY_LAST_ACTIVE_PARTICIPANT_SECONDARY_ID = "lastactiveparticipant_sec_id"; //$NON-NLS-1$ |
|
|
94 |
private static final String KEY_LINK_WITH_EDITOR = "linkWithEditor"; //$NON-NLS-1$ |
85 |
private static final String KEY_SETTINGS_SECTION= "SynchronizeViewSettings"; //$NON-NLS-1$ |
95 |
private static final String KEY_SETTINGS_SECTION= "SynchronizeViewSettings"; //$NON-NLS-1$ |
86 |
|
96 |
|
87 |
|
97 |
|
Lines 356-361
Link Here
|
356 |
protected void createActions() { |
366 |
protected void createActions() { |
357 |
fPageDropDown = new SynchronizePageDropDownAction(this); |
367 |
fPageDropDown = new SynchronizePageDropDownAction(this); |
358 |
fPinAction = new PinParticipantAction(); |
368 |
fPinAction = new PinParticipantAction(); |
|
|
369 |
fToggleLinkingAction = new ToggleLinkingAction(this); |
359 |
fRemoveCurrentAction = new RemoveSynchronizeParticipantAction(this, false); |
370 |
fRemoveCurrentAction = new RemoveSynchronizeParticipantAction(this, false); |
360 |
fRemoveAllAction = new RemoveSynchronizeParticipantAction(this, true); |
371 |
fRemoveAllAction = new RemoveSynchronizeParticipantAction(this, true); |
361 |
updateActionEnablements(); |
372 |
updateActionEnablements(); |
Lines 365-370
Link Here
|
365 |
if (fPinAction != null) { |
376 |
if (fPinAction != null) { |
366 |
fPinAction.setParticipant(activeParticipantRef); |
377 |
fPinAction.setParticipant(activeParticipantRef); |
367 |
} |
378 |
} |
|
|
379 |
if (fToggleLinkingAction != null) { |
380 |
fToggleLinkingAction.setEnabled(getParticipant() != null); |
381 |
} |
368 |
if (fRemoveAllAction != null) { |
382 |
if (fRemoveAllAction != null) { |
369 |
fRemoveAllAction.setEnabled(getParticipant() != null); |
383 |
fRemoveAllAction.setEnabled(getParticipant() != null); |
370 |
} |
384 |
} |
Lines 384-391
Link Here
|
384 |
mgr.add(fPinAction); |
398 |
mgr.add(fPinAction); |
385 |
IMenuManager menu = bars.getMenuManager(); |
399 |
IMenuManager menu = bars.getMenuManager(); |
386 |
menu.add(fPinAction); |
400 |
menu.add(fPinAction); |
|
|
401 |
menu.add(fToggleLinkingAction); |
387 |
menu.add(fRemoveCurrentAction); |
402 |
menu.add(fRemoveCurrentAction); |
388 |
menu.add(fRemoveAllAction); |
403 |
menu.add(fRemoveAllAction); |
|
|
404 |
|
405 |
IHandlerService handlerService= (IHandlerService) this.getViewSite().getService(IHandlerService.class); |
406 |
handlerService.activateHandler(IWorkbenchCommandConstants.NAVIGATE_TOGGLE_LINK_WITH_EDITOR, new ActionHandler(fToggleLinkingAction)); |
389 |
} |
407 |
} |
390 |
|
408 |
|
391 |
/* (non-Javadoc) |
409 |
/* (non-Javadoc) |
Lines 396-406
Link Here
|
396 |
if (part != null) { |
414 |
if (part != null) { |
397 |
partActivated(part); |
415 |
partActivated(part); |
398 |
fPageDropDown.update(); |
416 |
fPageDropDown.update(); |
|
|
417 |
createOpenAndLinkWithEditorHelper(getViewer()); |
399 |
rememberCurrentParticipant(); |
418 |
rememberCurrentParticipant(); |
400 |
PlatformUI.getWorkbench().getHelpSystem().setHelp(getPageBook().getParent(), participant.getHelpContextId()); |
419 |
PlatformUI.getWorkbench().getHelpSystem().setHelp(getPageBook().getParent(), participant.getHelpContextId()); |
401 |
} |
420 |
} |
402 |
} |
421 |
} |
403 |
|
422 |
|
|
|
423 |
private void createOpenAndLinkWithEditorHelper(StructuredViewer viewer) { |
424 |
if (fOpenAndLinkWithEditorHelper != null) |
425 |
fOpenAndLinkWithEditorHelper.dispose(); |
426 |
fOpenAndLinkWithEditorHelper= new OpenAndLinkWithEditorHelper(viewer) { |
427 |
protected void activate(ISelection selection) { |
428 |
try { |
429 |
final Object selectedElement = getSingleElement(selection); |
430 |
if (isOpenInEditor(selectedElement) != null) |
431 |
if (selectedElement instanceof IFile) |
432 |
openInEditor((IFile) selectedElement, true); |
433 |
} catch (PartInitException ex) { |
434 |
// ignore if no editor input can be found |
435 |
} |
436 |
} |
437 |
|
438 |
protected void linkToEditor(ISelection selection) { |
439 |
SynchronizeView.this.linkToEditor(selection); |
440 |
} |
441 |
|
442 |
protected void open(ISelection selection, boolean activate) { |
443 |
// TODO: implement, bug 291211 |
444 |
} |
445 |
}; |
446 |
fOpenAndLinkWithEditorHelper.setLinkWithEditor(isLinkingEnabled()); |
447 |
setLinkingEnabled(isLinkingEnabled()); |
448 |
} |
449 |
|
404 |
/* (non-Javadoc) |
450 |
/* (non-Javadoc) |
405 |
* @see org.eclipse.ui.part.PageBookView#getBootstrapPart() |
451 |
* @see org.eclipse.ui.part.PageBookView#getBootstrapPart() |
406 |
*/ |
452 |
*/ |
Lines 437-442
Link Here
|
437 |
*/ |
483 |
*/ |
438 |
public void createPartControl(Composite parent) { |
484 |
public void createPartControl(Composite parent) { |
439 |
super.createPartControl(parent); |
485 |
super.createPartControl(parent); |
|
|
486 |
restoreLinkingEnabled(); |
440 |
createActions(); |
487 |
createActions(); |
441 |
configureToolBar(getViewSite().getActionBars()); |
488 |
configureToolBar(getViewSite().getActionBars()); |
442 |
updateForExistingParticipants(); |
489 |
updateForExistingParticipants(); |
Lines 683-686
Link Here
|
683 |
new String[] { description, syncMode })); |
730 |
new String[] { description, syncMode })); |
684 |
} |
731 |
} |
685 |
} |
732 |
} |
686 |
} |
733 |
|
|
|
734 |
// copy-pasted from org.eclipse.jdt.internal.ui.packageview.PackageExplorerPart and modified |
735 |
|
736 |
private IPartListener2 fLinkWithEditorListener= new IPartListener2() { |
737 |
public void partVisible(IWorkbenchPartReference partRef) {} |
738 |
public void partBroughtToTop(IWorkbenchPartReference partRef) {} |
739 |
public void partClosed(IWorkbenchPartReference partRef) {} |
740 |
public void partDeactivated(IWorkbenchPartReference partRef) {} |
741 |
public void partHidden(IWorkbenchPartReference partRef) {} |
742 |
public void partOpened(IWorkbenchPartReference partRef) {} |
743 |
public void partInputChanged(IWorkbenchPartReference partRef) { |
744 |
if (partRef instanceof IEditorReference) { |
745 |
editorActivated(((IEditorReference) partRef).getEditor(true)); |
746 |
} |
747 |
} |
748 |
|
749 |
public void partActivated(IWorkbenchPartReference partRef) { |
750 |
if (partRef instanceof IEditorReference) { |
751 |
editorActivated(((IEditorReference) partRef).getEditor(true)); |
752 |
} |
753 |
} |
754 |
|
755 |
}; |
756 |
|
757 |
public boolean isLinkingEnabled() { |
758 |
return fLinkingEnabled; |
759 |
} |
760 |
|
761 |
public void setLinkingEnabled(boolean enabled) { |
762 |
fLinkingEnabled= enabled; |
763 |
IDialogSettings dialogSettings = getDialogSettings(); |
764 |
dialogSettings.put(KEY_LINK_WITH_EDITOR, fLinkingEnabled); |
765 |
|
766 |
IWorkbenchPage page= getSite().getPage(); |
767 |
if (enabled) { |
768 |
page.addPartListener(fLinkWithEditorListener); |
769 |
|
770 |
IEditorPart editor = page.getActiveEditor(); |
771 |
if (editor != null) |
772 |
editorActivated(editor); |
773 |
} else { |
774 |
page.removePartListener(fLinkWithEditorListener); |
775 |
} |
776 |
fOpenAndLinkWithEditorHelper.setLinkWithEditor(enabled); |
777 |
|
778 |
} |
779 |
|
780 |
private void restoreLinkingEnabled() { |
781 |
fLinkingEnabled = getDialogSettings().getBoolean(KEY_LINK_WITH_EDITOR); |
782 |
} |
783 |
|
784 |
/** |
785 |
* Links to editor (if option enabled) |
786 |
* @param selection the selection |
787 |
*/ |
788 |
private void linkToEditor(ISelection selection) { |
789 |
Object obj = getSingleElement(selection); |
790 |
if (obj != null) { |
791 |
IEditorPart part = isOpenInEditor(obj); |
792 |
if (part != null) { |
793 |
IWorkbenchPage page= getSite().getPage(); |
794 |
page.bringToTop(part); |
795 |
} |
796 |
} |
797 |
} |
798 |
|
799 |
/** |
800 |
* An editor has been activated. Set the selection in this Packages Viewer |
801 |
* to be the editor's input, if linking is enabled. |
802 |
* @param editor the activated editor |
803 |
*/ |
804 |
private void editorActivated(IEditorPart editor) { |
805 |
if (!isLinkingEnabled()) |
806 |
return; |
807 |
|
808 |
IEditorInput editorInput= editor.getEditorInput(); |
809 |
if (editorInput == null) |
810 |
return; |
811 |
Object input= getInputFromEditor(editorInput); |
812 |
if (input == null) |
813 |
return; |
814 |
if (!inputIsSelected(editorInput)) |
815 |
showInput(input); |
816 |
else |
817 |
getViewer().getTree().showSelection(); |
818 |
} |
819 |
|
820 |
boolean showInput(Object input) { |
821 |
Object element = input; |
822 |
if (element != null) { |
823 |
ISelection newSelection = new StructuredSelection(element); |
824 |
if (getViewer().getSelection().equals(newSelection)) { |
825 |
getViewer().reveal(element); |
826 |
} else { |
827 |
getViewer().setSelection(newSelection, true); |
828 |
|
829 |
while (element != null && getViewer().getSelection().isEmpty()) { |
830 |
// Try to select parent in case element is filtered |
831 |
element = getParent(element); |
832 |
if (element != null) { |
833 |
newSelection = new StructuredSelection(element); |
834 |
getViewer().setSelection(newSelection, true); |
835 |
} else { |
836 |
// Failed to find parent to select |
837 |
return false; |
838 |
} |
839 |
} |
840 |
} |
841 |
return true; |
842 |
} |
843 |
return false; |
844 |
} |
845 |
|
846 |
/** |
847 |
* Returns the element's parent. |
848 |
* @param element the element |
849 |
* |
850 |
* @return the parent or <code>null</code> if there's no parent |
851 |
*/ |
852 |
private Object getParent(Object element) { |
853 |
if (element instanceof IResource) |
854 |
return ((IResource)element).getParent(); |
855 |
return null; |
856 |
} |
857 |
|
858 |
private TreeViewer getViewer() { |
859 |
IPage currentPage = getCurrentPage(); |
860 |
if (currentPage instanceof ISynchronizePage) { |
861 |
return (TreeViewer) ((ISynchronizePage)currentPage).getViewer(); |
862 |
} |
863 |
// TODO: nobody is expecting null! |
864 |
return null; |
865 |
} |
866 |
|
867 |
private boolean inputIsSelected(IEditorInput input) { |
868 |
IStructuredSelection selection= (IStructuredSelection) getViewer().getSelection(); |
869 |
if (selection.size() != 1) |
870 |
return false; |
871 |
IEditorInput selectionAsInput= getEditorInput(selection.getFirstElement()); |
872 |
return input.equals(selectionAsInput); |
873 |
} |
874 |
|
875 |
private static IEditorInput getEditorInput(Object input) { |
876 |
IResource[] resources = Utils.getContributedResources(new Object[] { input }); |
877 |
if (resources.length > 0) |
878 |
input = resources[0]; |
879 |
if (input instanceof IFile) |
880 |
return new FileEditorInput((IFile) input); |
881 |
return null; |
882 |
} |
883 |
|
884 |
private Object getInputFromEditor(IEditorInput editorInput) { |
885 |
Object input= editorInput.getAdapter(IFile.class); |
886 |
if (input == null && editorInput instanceof IStorageEditorInput) { |
887 |
try { |
888 |
input= ((IStorageEditorInput) editorInput).getStorage(); |
889 |
} catch (CoreException e) { |
890 |
// ignore |
891 |
} |
892 |
} |
893 |
return input; |
894 |
} |
895 |
|
896 |
// copy-pasted from org.eclipse.jdt.internal.ui.javaeditor.EditorUtility and modified |
897 |
|
898 |
private static IEditorPart isOpenInEditor(Object inputElement) { |
899 |
IEditorInput input= getEditorInput(inputElement); |
900 |
|
901 |
if (input != null) { |
902 |
IWorkbenchPage p= TeamUIPlugin.getActivePage(); |
903 |
if (p != null) { |
904 |
return p.findEditor(input); |
905 |
} |
906 |
} |
907 |
return null; |
908 |
} |
909 |
|
910 |
private static IEditorPart openInEditor(IFile file, boolean activate) throws PartInitException { |
911 |
if (file == null) |
912 |
throwPartInitException(TeamUIMessages.SynchronizeView_fileMustNotBeNull); |
913 |
|
914 |
IWorkbenchPage p = TeamUIPlugin.getActivePage(); |
915 |
if (p == null) |
916 |
throwPartInitException(TeamUIMessages.SynchronizeView_noActiveWorkbenchPage); |
917 |
|
918 |
IEditorPart editorPart = IDE.openEditor(p, file, activate); |
919 |
return editorPart; |
920 |
} |
921 |
|
922 |
private static void throwPartInitException(String message) throws PartInitException { |
923 |
IStatus status = new Status(IStatus.ERROR, TeamUIPlugin.ID, IStatus.OK, message, null); |
924 |
throw new PartInitException(status); |
925 |
} |
926 |
|
927 |
// copy-pasted from org.eclipse.jdt.internal.ui.util.SelectionUtil and modified |
928 |
|
929 |
/** |
930 |
* Returns the selected element if the selection consists of a single |
931 |
* element only. |
932 |
* |
933 |
* @param s the selection |
934 |
* @return the selected first element or null |
935 |
*/ |
936 |
private static Object getSingleElement(ISelection s) { |
937 |
if (!(s instanceof IStructuredSelection)) |
938 |
return null; |
939 |
IStructuredSelection selection = (IStructuredSelection) s; |
940 |
if (selection.size() != 1) |
941 |
return null; |
942 |
|
943 |
return selection.getFirstElement(); |
944 |
} |
945 |
|
946 |
/* (non-Javadoc) |
947 |
* @see org.eclipse.ui.part.IShowInTarget#show(org.eclipse.ui.part.ShowInContext) |
948 |
*/ |
949 |
public boolean show(ShowInContext context) { |
950 |
Object selection = getSingleElement(context.getSelection()); |
951 |
if (selection != null) { |
952 |
// If can show the selection, do it. |
953 |
// Otherwise, fall through and attempt to show the input |
954 |
if (showInput(selection)) |
955 |
return true; |
956 |
} |
957 |
Object input = context.getInput(); |
958 |
if (input != null) { |
959 |
if (input instanceof IEditorInput) { |
960 |
return showInput(getInputFromEditor((IEditorInput) input)); |
961 |
} |
962 |
return showInput(input); |
963 |
} |
964 |
return false; |
965 |
} |
966 |
} |