blob: 52191239a40c7c7f8ac6bfdda3e5986e92c497b8 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
package org.eclipse.team.internal.ui.jobs;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.team.core.synchronize.SyncInfo;
import org.eclipse.team.internal.ui.IPreferenceIds;
import org.eclipse.team.internal.ui.Policy;
import org.eclipse.team.internal.ui.TeamUIPlugin;
import org.eclipse.team.internal.ui.synchronize.IRefreshEvent;
import org.eclipse.team.internal.ui.synchronize.IRefreshSubscriberListener;
import org.eclipse.team.internal.ui.synchronize.RefreshCompleteDialog;
import org.eclipse.team.ui.TeamUI;
import org.eclipse.team.ui.synchronize.ISynchronizeManager;
import org.eclipse.team.ui.synchronize.ISynchronizeParticipant;
import org.eclipse.team.ui.synchronize.ISynchronizeView;
import org.eclipse.team.ui.synchronize.subscriber.SubscriberParticipant;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.progress.UIJob;
public class RefreshUserNotificationPolicy implements IRefreshSubscriberListener {
private SubscriberParticipant participant;
private boolean addIfNeeded;
public RefreshUserNotificationPolicy(SubscriberParticipant participant, boolean addIfNeeded) {
this.participant = participant;
this.addIfNeeded = addIfNeeded;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.team.internal.ui.jobs.IRefreshSubscriberListener#refreshStarted(org.eclipse.team.internal.ui.jobs.IRefreshEvent)
*/
public void refreshStarted(IRefreshEvent event) {
}
/*
* (non-Javadoc)
*
* @see org.eclipse.team.internal.ui.jobs.IRefreshSubscriberListener#refreshDone(org.eclipse.team.internal.ui.jobs.IRefreshEvent)
*/
public void refreshDone(IRefreshEvent event) {
if(event.getSubscriber() != participant.getSubscriberSyncInfoCollector().getSubscriber()) return;
int type = event.getRefreshType();
boolean promptWithChanges = TeamUIPlugin.getPlugin().getPreferenceStore().getBoolean(IPreferenceIds.SYNCVIEW_VIEW_PROMPT_WITH_CHANGES);
boolean promptWhenNoChanges = TeamUIPlugin.getPlugin().getPreferenceStore().getBoolean(IPreferenceIds.SYNCVIEW_VIEW_PROMPT_WHEN_NO_CHANGES);
boolean promptWithChangesBkg = TeamUIPlugin.getPlugin().getPreferenceStore().getBoolean(IPreferenceIds.SYNCVIEW_VIEW_BKG_PROMPT_WITH_CHANGES);
boolean promptWhenNoChangesBkg = TeamUIPlugin.getPlugin().getPreferenceStore().getBoolean(IPreferenceIds.SYNCVIEW_VIEW_BKG_PROMPT_WHEN_NO_CHANGES);
boolean shouldPrompt = false;
SyncInfo[] infos = event.getChanges();
if (type == IRefreshEvent.USER_REFRESH) {
if (promptWhenNoChanges && infos.length == 0) {
shouldPrompt = true;
} else if (promptWithChanges && infos.length > 0) {
shouldPrompt = true;
}
} else {
if (promptWhenNoChangesBkg && infos.length == 0) {
shouldPrompt = true;
} else if (promptWithChangesBkg && infos.length > 0) {
shouldPrompt = true;
}
}
// If there are interesting changes, ensure the sync view is showing them
// Also, add the participant to the sync view only if changes have been found.
if (infos.length > 0) {
participant.setMode(SubscriberParticipant.INCOMING_MODE);
final ISynchronizeManager manager = TeamUI.getSynchronizeManager();
if (addIfNeeded) {
manager.addSynchronizeParticipants(new ISynchronizeParticipant[]{participant});
TeamUIPlugin.getStandardDisplay().asyncExec(new Runnable() {
public void run() {
ISynchronizeView view = manager.showSynchronizeViewInActivePage(null);
if (view != null) {
view.display(participant);
}
}
});
}
}
// Prompt user if preferences are set for this type of refresh.
if (shouldPrompt) {
notifyIfNeededModal(event);
}
RefreshSubscriberJob.removeRefreshListener(this);
}
private void notifyIfNeededModal(final IRefreshEvent event) {
TeamUIPlugin.getStandardDisplay().asyncExec(new Runnable() {
public void run() {
RefreshCompleteDialog d = new RefreshCompleteDialog(new Shell(TeamUIPlugin.getStandardDisplay()), event, participant);
d.setBlockOnOpen(false);
d.open();
}
});
}
private void notifyIfNeededNonModal(final IRefreshEvent event) {
String message = Policy.bind("RefreshUserNotificationPolicy.0", event.getSubscriber().getName()); //$NON-NLS-1$
PlatformUI.getWorkbench().getProgressService().requestInUI(new UIJob(message) {
public IStatus runInUIThread(IProgressMonitor monitor) {
RefreshCompleteDialog d = new RefreshCompleteDialog(new Shell(TeamUIPlugin.getStandardDisplay()), event, participant);
d.setBlockOnOpen(false);
d.open();
return Status.OK_STATUS;
}
}, message);
}
}
|