KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > ui > synchronize > ParticipantPageDialog


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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.ui.synchronize;
12
13 import org.eclipse.compare.CompareUI;
14 import org.eclipse.jface.dialogs.Dialog;
15 import org.eclipse.jface.dialogs.IDialogConstants;
16 import org.eclipse.swt.SWT;
17 import org.eclipse.swt.widgets.*;
18 import org.eclipse.team.internal.ui.TeamUIMessages;
19 import org.eclipse.team.ui.*;
20
21 /**
22  * A dialog that displays the option of adding the participant to the {@link org.eclipse.team.ui.synchronize.ISynchronizeManager}
23  * when the dialog is closed. This can be useful for showing changes for a participant modally and allowing the
24  * user to decide if the participant shown should be made available non-modally.
25  *
26  * @see SaveablePartAdapter
27  * @see ISynchronizeParticipant
28  * @since 3.0
29  * @deprecated Clients should use {@link ParticipantPageCompareEditorInput}
30  * and {@link CompareUI#openCompareDialog(org.eclipse.compare.CompareEditorInput)}
31  */

32 public class ParticipantPageDialog extends SaveablePartDialog {
33         
34     private ISynchronizeParticipant participant;
35     private Button rememberParticipantButton;
36
37     /**
38      * Creates a dialog with the given participant and input. The input is not created until the dialog
39      * is opened.
40      *
41      * @param shell the parent shell or <code>null</code> to create a top level shell.
42      * @param input the compare input to show in the dialog
43      * @param participant the given participant
44      */

45     public ParticipantPageDialog(Shell shell, SaveablePartAdapter input, ISynchronizeParticipant participant) {
46         super(shell, input);
47         this.participant = participant;
48     }
49     
50     /* (non-Javadoc)
51      * Method declared on Dialog.
52      */

53     protected Control createDialogArea(Composite parent2) {
54         Composite parent = (Composite) super.createDialogArea(parent2);
55         if (isOfferToRememberParticipant() && participant != null && ! particantRegisteredWithSynchronizeManager(participant)) {
56             rememberParticipantButton = new Button(parent, SWT.CHECK);
57             rememberParticipantButton.setText(TeamUIMessages.ParticipantCompareDialog_1);
58         }
59         Dialog.applyDialogFont(parent2);
60         return parent;
61     }
62     
63     /* (non-Javadoc)
64      * @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int)
65      */

66     protected void buttonPressed(int buttonId) {
67         if(buttonId == IDialogConstants.OK_ID && isRememberParticipant()) {
68             rememberParticipant();
69         }
70         super.buttonPressed(buttonId);
71     }
72     
73     private boolean isRememberParticipant() {
74         return getParticipant() != null && rememberParticipantButton != null && rememberParticipantButton.getSelection();
75     }
76     
77     private boolean particantRegisteredWithSynchronizeManager(ISynchronizeParticipant participant) {
78         return TeamUI.getSynchronizeManager().get(participant.getId(), participant.getSecondaryId()) != null;
79     }
80     
81     private void rememberParticipant() {
82         if(getParticipant() != null) {
83             ISynchronizeManager mgr = TeamUI.getSynchronizeManager();
84             ISynchronizeView view = mgr.showSynchronizeViewInActivePage();
85             mgr.addSynchronizeParticipants(new ISynchronizeParticipant[] {getParticipant()});
86             view.display(participant);
87         }
88     }
89     
90     /**
91      * Returns the participant showing in this dialog.
92      *
93      * @return the participant showing in this dialog.
94      */

95     protected ISynchronizeParticipant getParticipant() {
96         return participant;
97     }
98     
99     /**
100      * Return whether the ability to remember the participant in the synchronize
101      * view should be presented to the user. By default, <code>true</code> is
102      * returned. Subclasses may override.
103      * @return whether the ability to remember the participant in the synchronize
104      * view should be presented to the user
105      * @since 3.2
106      */

107     protected boolean isOfferToRememberParticipant() {
108         return true;
109     }
110 }
111
Popular Tags