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