KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ui > synchronize > RefreshUserNotificationPolicyInModalDialog


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.team.internal.ui.synchronize;
12
13 import org.eclipse.compare.CompareConfiguration;
14 import org.eclipse.core.runtime.IStatus;
15 import org.eclipse.jface.dialogs.MessageDialog;
16 import org.eclipse.swt.widgets.Shell;
17 import org.eclipse.team.internal.ui.TeamUIMessages;
18 import org.eclipse.team.internal.ui.Utils;
19 import org.eclipse.team.ui.TeamUI;
20 import org.eclipse.team.ui.synchronize.*;
21 import org.eclipse.ui.actions.ActionFactory;
22
23 public class RefreshUserNotificationPolicyInModalDialog implements IRefreshSubscriberListener {
24
25     private SubscriberParticipant participant;
26     private ISynchronizePageConfiguration configuration;
27     private Shell shell;
28     private String JavaDoc title;
29
30     public RefreshUserNotificationPolicyInModalDialog(Shell shell, String JavaDoc title, ISynchronizePageConfiguration configuration, SubscriberParticipant participant) {
31         this.title = title;
32         this.configuration = configuration;
33         this.participant = participant;
34         this.shell = shell;
35     }
36
37     public void refreshStarted(IRefreshEvent event) {
38     }
39
40     public ActionFactory.IWorkbenchAction refreshDone(final IRefreshEvent event) {
41         // Ensure that this event was generated for this participant
42
if (event.getParticipant() != participant)
43             return null;
44         // If the event is for a cancelled operation, there's nothing to do
45
int severity = event.getStatus().getSeverity();
46         if(severity == IStatus.CANCEL || severity == IStatus.ERROR)
47             return null;
48         
49         return new WorkbenchAction() {
50             public void run() {
51                     // If there are no changes
52
if (event.getStatus().getCode() == IRefreshEvent.STATUS_NO_CHANGES) {
53                         MessageDialog.openInformation(shell, TeamUIMessages.OpenComparedDialog_noChangeTitle, TeamUIMessages.OpenComparedDialog_noChangesMessage); //
54
return;
55                     }
56                     compareAndOpenDialog(event, participant);
57                     setEnabled(false);
58             }
59             public void dispose() {
60                 if (TeamUI.getSynchronizeManager().get(participant.getId(), participant.getSecondaryId()) == null) {
61                     participant.dispose();
62                 }
63             }
64         };
65     }
66
67     protected void compareAndOpenDialog(final IRefreshEvent event, final SubscriberParticipant participant) {
68         CompareConfiguration cc = new CompareConfiguration();
69         ParticipantPageSaveablePart input = new ParticipantPageSaveablePart(Utils.getShell(null), cc, configuration, participant) {
70             public String JavaDoc getTitle() {
71                 return RefreshUserNotificationPolicyInModalDialog.this.title;
72             }
73         };
74         try {
75             ParticipantPageDialog dialog = new ParticipantPageDialog(shell, input, participant);
76             dialog.setBlockOnOpen(true);
77             dialog.open();
78         } finally {
79             input.dispose();
80         }
81     }
82 }
83
Popular Tags