KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ui > mapping > ModelParticipantPageDialog


1 /*******************************************************************************
2  * Copyright (c) 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.mapping;
12
13 import java.lang.reflect.InvocationTargetException JavaDoc;
14
15 import org.eclipse.compare.CompareConfiguration;
16 import org.eclipse.jface.dialogs.IDialogConstants;
17 import org.eclipse.jface.dialogs.ProgressMonitorDialog;
18 import org.eclipse.jface.operation.IRunnableContext;
19 import org.eclipse.jface.operation.IRunnableWithProgress;
20 import org.eclipse.swt.widgets.*;
21 import org.eclipse.team.core.mapping.IMergeContext;
22 import org.eclipse.team.core.mapping.ISynchronizationContext;
23 import org.eclipse.team.internal.ui.TeamUIMessages;
24 import org.eclipse.team.ui.SaveablePartAdapter;
25 import org.eclipse.team.ui.synchronize.*;
26
27 public final class ModelParticipantPageDialog extends ParticipantPageDialog {
28     
29     /*
30      * Ids for custom buttons when previewing a merge/replace
31      */

32     private static final int DONE_ID = IDialogConstants.CLIENT_ID + 1;
33     private static final int REPLACE_ID = IDialogConstants.CLIENT_ID + 2;
34
35     private final ModelSynchronizeParticipant participant;
36     private Button doneButton;
37     private Button replaceButton;
38
39     public ModelParticipantPageDialog(Shell shell, ModelSynchronizeParticipant participant, CompareConfiguration cc, ISynchronizePageConfiguration pc) {
40         super(shell, createInput(shell, participant, cc, pc), participant);
41         this.participant = participant;
42         pc.setRunnableContext(new IRunnableContext() {
43             public void run(boolean fork, boolean cancelable,
44                     IRunnableWithProgress runnable) throws InvocationTargetException JavaDoc,
45                     InterruptedException JavaDoc {
46                 ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
47                 dialog.run(fork, cancelable, runnable);
48             }
49         });
50     }
51
52     private static SaveablePartAdapter createInput(Shell shell, ModelSynchronizeParticipant participant, CompareConfiguration cc, ISynchronizePageConfiguration pc) {
53         ParticipantPageSaveablePart input = new ParticipantPageSaveablePart(shell, cc, pc, participant);
54         return input;
55     }
56
57     /* (non-Javadoc)
58      * @see org.eclipse.team.ui.SaveablePartDialog#close()
59      */

60     public boolean close() {
61         boolean close = super.close();
62         if (close) {
63             getInput().dispose();
64         }
65         return close;
66     }
67     
68     /* (non-Javadoc)
69      * @see org.eclipse.team.ui.synchronize.ParticipantPageDialog#isOfferToRememberParticipant()
70      */

71     protected boolean isOfferToRememberParticipant() {
72         if (isReplace())
73             return false;
74         return super.isOfferToRememberParticipant();
75     }
76
77     private boolean isReplace() {
78         return ((IMergeContext)participant.getContext()).getMergeType() == ISynchronizationContext.TWO_WAY;
79     }
80
81     /* (non-Javadoc)
82      * @see org.eclipse.team.ui.SaveablePartDialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
83      */

84     protected void createButtonsForButtonBar(Composite parent) {
85         boolean isReplace = isReplace();
86         isReplace = false; // TODO: Disbled for now
87
if (isReplace) {
88             replaceButton = createButton(parent, REPLACE_ID, TeamUIMessages.ModelParticipantPageDialog_0, true);
89             replaceButton.setEnabled(true);
90         }
91         doneButton = createButton(parent, DONE_ID, TeamUIMessages.ResourceMappingMergeOperation_2, !isReplace);
92         doneButton.setEnabled(true);
93         // Don't call super because we don't want the OK button to appear
94
}
95
96     /* (non-Javadoc)
97      * @see org.eclipse.team.ui.synchronize.ParticipantPageDialog#buttonPressed(int)
98      */

99     protected void buttonPressed(int buttonId) {
100         if (buttonId == DONE_ID) {
101             super.buttonPressed(IDialogConstants.OK_ID);
102         } else if (buttonId == REPLACE_ID) {
103             // TODO: Disabled for now
104
// try {
105
// // Do this inline so we don't have to manage disposing of the context
106
// PlatformUI.getWorkbench().getProgressService().run(true, true, new IRunnableWithProgress() {
107
// public void run(IProgressMonitor monitor) throws InvocationTargetException,
108
// InterruptedException {
109
// try {
110
//
111
// ModelParticipantPageDialog.this.operation.performMerge(monitor);
112
// } catch (CoreException e) {
113
// throw new InvocationTargetException(e);
114
// }
115
// }
116
// });
117
// } catch (InvocationTargetException e) {
118
// Throwable t = e.getTargetException();
119
// IStatus status;
120
// if (t instanceof CoreException) {
121
// CoreException ce = (CoreException) t;
122
// status = ce.getStatus();
123
// } else {
124
// status = new Status(IStatus.ERROR, TeamUIPlugin.ID, 0, TeamUIMessages.internal, t);
125
// TeamUIPlugin.log(status);
126
// }
127
// ErrorDialog.openError(getShell(), null, null, status);
128
// return;
129
// } catch (InterruptedException e) {
130
// // Operation was cancelled. Leave the dialog open
131
// return;
132
// }
133
super.buttonPressed(IDialogConstants.OK_ID);
134         } else {
135             super.buttonPressed(buttonId);
136         }
137     }
138 }
Popular Tags