KickJava   Java API By Example, From Geeks To Geeks.

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


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.core.runtime.*;
16 import org.eclipse.jface.dialogs.ErrorDialog;
17 import org.eclipse.jface.dialogs.IDialogConstants;
18 import org.eclipse.swt.widgets.Composite;
19 import org.eclipse.team.core.mapping.IMergeContext;
20 import org.eclipse.team.core.mapping.ISynchronizationContext;
21 import org.eclipse.team.core.mapping.provider.SynchronizationContext;
22 import org.eclipse.team.internal.ui.Policy;
23 import org.eclipse.team.internal.ui.TeamUIMessages;
24 import org.eclipse.team.ui.mapping.SynchronizationOperation;
25 import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration;
26 import org.eclipse.team.ui.synchronize.ModelMergeOperation;
27
28 public final class MergeAllOperation extends SynchronizationOperation {
29     
30     private final IMergeContext context;
31     private final String JavaDoc jobName;
32
33     public MergeAllOperation(String JavaDoc jobName, ISynchronizePageConfiguration configuration, Object JavaDoc[] elements, IMergeContext context) {
34         super(configuration, elements);
35         this.jobName = jobName;
36         this.context = context;
37     }
38     
39     /* (non-Javadoc)
40      * @see org.eclipse.team.ui.mapping.SynchronizationOperation#execute(org.eclipse.core.runtime.IProgressMonitor)
41      */

42     public void execute(IProgressMonitor monitor) throws InvocationTargetException JavaDoc,
43             InterruptedException JavaDoc {
44         new ModelMergeOperation(getPart(), ((SynchronizationContext)context).getScopeManager()) {
45             public boolean isPreviewRequested() {
46                 return false;
47             }
48             protected void initializeContext(IProgressMonitor monitor) throws CoreException {
49                 monitor.beginTask(null, 10);
50                 monitor.done();
51             }
52             protected ISynchronizationContext getContext() {
53                 return context;
54             }
55             protected void executeMerge(IProgressMonitor monitor) throws CoreException {
56                 monitor.beginTask(null, 100);
57                 if (!hasChangesOfInterest()) {
58                     handleNoChanges();
59                 } else if (isPreviewRequested()) {
60                     handlePreviewRequest();
61                 } else {
62                     IStatus status = ModelMergeOperation.validateMerge(getMergeContext(), Policy.subMonitorFor(monitor, 10));
63                     if (!status.isOK()) {
64                         if (!promptToContinue(status))
65                             return;
66                     }
67                     status = performMerge(Policy.subMonitorFor(monitor, 90));
68                     if (!status.isOK()) {
69                         handleMergeFailure(status);
70                     }
71                 }
72                 monitor.done();
73             }
74             private IMergeContext getMergeContext() {
75                 return (IMergeContext)getContext();
76             }
77             private boolean promptToContinue(final IStatus status) {
78                 final boolean[] result = new boolean[] { false };
79                 Runnable JavaDoc runnable = new Runnable JavaDoc() {
80                     public void run() {
81                         ErrorDialog dialog = new ErrorDialog(getShell(), TeamUIMessages.ModelMergeOperation_0, TeamUIMessages.ModelMergeOperation_1, status, IStatus.ERROR | IStatus.WARNING | IStatus.INFO) {
82                             protected void createButtonsForButtonBar(Composite parent) {
83                                 createButton(parent, IDialogConstants.YES_ID, IDialogConstants.YES_LABEL,
84                                         false);
85                                 createButton(parent, IDialogConstants.NO_ID, IDialogConstants.NO_LABEL,
86                                         true);
87                                 createDetailsButton(parent);
88                             }
89                             /* (non-Javadoc)
90                              * @see org.eclipse.jface.dialogs.ErrorDialog#buttonPressed(int)
91                              */

92                             protected void buttonPressed(int id) {
93                                 if (id == IDialogConstants.YES_ID)
94                                     super.buttonPressed(IDialogConstants.OK_ID);
95                                 else if (id == IDialogConstants.NO_ID)
96                                     super.buttonPressed(IDialogConstants.CANCEL_ID);
97                                 super.buttonPressed(id);
98                             }
99                         };
100                         int code = dialog.open();
101                         result[0] = code == 0;
102                     }
103                 };
104                 getShell().getDisplay().syncExec(runnable);
105                 return (result[0]);
106             }
107         }.run(monitor);
108     }
109
110     /* (non-Javadoc)
111      * @see org.eclipse.team.ui.TeamOperation#canRunAsJob()
112      */

113     protected boolean canRunAsJob() {
114         return true;
115     }
116     
117     /* (non-Javadoc)
118      * @see org.eclipse.team.ui.TeamOperation#getJobName()
119      */

120     protected String JavaDoc getJobName() {;
121         return jobName;
122     }
123 }
Popular Tags