1 11 package org.eclipse.team.internal.ui.synchronize; 12 13 import java.util.ArrayList ; 14 import java.util.Arrays ; 15 import java.util.List ; 16 17 import org.eclipse.core.resources.IResource; 18 import org.eclipse.core.runtime.IStatus; 19 import org.eclipse.jface.dialogs.MessageDialog; 20 import org.eclipse.osgi.util.NLS; 21 import org.eclipse.team.core.synchronize.SyncInfo; 22 import org.eclipse.team.internal.ui.*; 23 import org.eclipse.team.internal.ui.synchronize.actions.OpenInCompareAction; 24 import org.eclipse.team.ui.TeamUI; 25 import org.eclipse.team.ui.synchronize.*; 26 import org.eclipse.ui.actions.ActionFactory; 27 28 31 public class RefreshUserNotificationPolicy implements IRefreshSubscriberListener { 32 33 private ISynchronizeParticipant participant; 34 35 public RefreshUserNotificationPolicy(ISynchronizeParticipant participant) { 36 this.participant = participant; 37 } 38 39 43 public void refreshStarted(final IRefreshEvent event) { 44 TeamUIPlugin.getStandardDisplay().asyncExec(new Runnable () { 45 public void run() { 46 if (event.getRefreshType() == IRefreshEvent.USER_REFRESH && event.getParticipant() == participant) { 47 ISynchronizeView view = TeamUI.getSynchronizeManager().showSynchronizeViewInActivePage(); 48 if (view != null) { 49 view.display(participant); 50 } 51 } 52 } 53 }); 54 } 55 56 60 public ActionFactory.IWorkbenchAction refreshDone(final IRefreshEvent event) { 61 if (event.getParticipant() != participant) return null; 63 int severity = event.getStatus().getSeverity(); 65 if(severity == IStatus.CANCEL || severity == IStatus.ERROR) return null; 66 return new WorkbenchAction() { 68 public void run() { 69 boolean prompt = (event.getStatus().getCode() == IRefreshEvent.STATUS_NO_CHANGES); 70 71 prompt = handleRefreshDone(event, prompt); 72 73 if (prompt) { 75 notifyIfNeededModal(event); 76 } 77 setToolTipText(getToolTipText()); 78 if (event.isLink()) { 79 ISynchronizeView view = TeamUI.getSynchronizeManager().showSynchronizeViewInActivePage(); 81 if (view != null) { 82 view.display(participant); 83 } 84 } 85 } 86 87 public String getToolTipText() { 88 boolean prompt = (event.getStatus().getCode() == IRefreshEvent.STATUS_NO_CHANGES); 89 if(prompt) { 90 return TeamUIMessages.RefreshSubscriberJob_2a; 91 } else { 92 return NLS.bind(TeamUIMessages.RefreshSubscriberJob_2b, new String [] { Utils.shortenText(SynchronizeView.MAX_NAME_LENGTH, participant.getName()) }); 93 } 94 } 95 }; 96 } 97 98 private void notifyIfNeededModal(final IRefreshEvent event) { 99 TeamUIPlugin.getStandardDisplay().asyncExec(new Runnable () { 100 public void run() { 101 String title = (event.getRefreshType() == IRefreshEvent.SCHEDULED_REFRESH ? 102 NLS.bind(TeamUIMessages.RefreshCompleteDialog_4a, new String [] { Utils.getTypeName(participant) }) : 103 NLS.bind(TeamUIMessages.RefreshCompleteDialog_4, new String [] { Utils.getTypeName(participant) }) 104 ); 105 MessageDialog.openInformation(Utils.getShell(null), title, event.getStatus().getMessage()); 106 } 107 }); 108 } 109 110 protected boolean handleRefreshDone(final IRefreshEvent event, boolean prompt) { 111 if (participant instanceof SubscriberParticipant) { 112 SubscriberParticipant sp = (SubscriberParticipant) participant; 113 SyncInfo[] infos = ((RefreshChangeListener)event.getChangeDescription()).getChanges(); 114 List selectedResources = new ArrayList (); 115 selectedResources.addAll(Arrays.asList(((RefreshChangeListener)event.getChangeDescription()).getResources())); 116 for (int i = 0; i < infos.length; i++) { 117 selectedResources.add(infos[i].getLocal()); 118 } 119 IResource[] resources = (IResource[]) selectedResources.toArray(new IResource[selectedResources.size()]); 120 121 if (resources.length == 1 && resources[0].getType() == IResource.FILE) { 123 IResource file = resources[0]; 124 SyncInfo info = sp.getSubscriberSyncInfoCollector().getSyncInfoSet().getSyncInfo(file); 125 if(info != null) { 126 OpenInCompareAction.openCompareEditor(participant, info, null); 127 prompt = false; 128 } 129 } 130 } 131 return prompt; 133 } 134 } 135 | Popular Tags |