diff options
Diffstat (limited to 'examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/GetSynchronizeOperation.java')
-rw-r--r-- | examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/GetSynchronizeOperation.java | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/GetSynchronizeOperation.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/GetSynchronizeOperation.java new file mode 100644 index 000000000..067861739 --- /dev/null +++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/GetSynchronizeOperation.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.team.examples.filesystem.ui; + +import org.eclipse.compare.structuremergeviewer.IDiffElement; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.team.core.TeamException; +import org.eclipse.team.core.synchronize.SyncInfoSet; +import org.eclipse.team.examples.filesystem.FileSystemProvider; +import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration; + +/** + * Sync view operation for getting file system resources + */ +public class GetSynchronizeOperation extends FileSystemSynchronizeOperation { + + protected GetSynchronizeOperation(ISynchronizePageConfiguration configuration, IDiffElement[] elements) { + super(configuration, elements); + } + + /* (non-Javadoc) + * @see org.eclipse.team.examples.filesystem.ui.FileSystemSynchronizeOperation#promptForConflictHandling(org.eclipse.swt.widgets.Shell, org.eclipse.team.core.synchronize.SyncInfoSet) + */ + protected boolean promptForConflictHandling(Shell shell, SyncInfoSet syncSet) { + // If there is a conflict in the syncSet, we need to prompt the user before proceeding. + if (syncSet.hasConflicts() || syncSet.hasOutgoingChanges()) { + switch (promptForConflicts(shell, syncSet)) { + case 0: + // Yes, synchronize conflicts as well + break; + case 1: + // No, remove outgoing + syncSet.removeConflictingNodes(); + syncSet.removeOutgoingNodes(); + break; + case 2: + default: + // Cancel + return false; + } + } + return true; + } + + /** + * Prompts the user to determine how conflicting changes should be handled. + * Note: This method is designed to be overridden by test cases. + * @return 0 to sync conflicts, 1 to sync all non-conflicts, 2 to cancel + */ + private int promptForConflicts(Shell shell, SyncInfoSet syncSet) { + String[] buttons = new String[] {IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL}; + String title = "Confirm Overwrite"; //$NON-NLS-1$ + String question = "You have changes that conflict with the server. Overwrite those changes?"; //$NON-NLS-1$ + final MessageDialog dialog = new MessageDialog(shell, title, null, question, MessageDialog.QUESTION, buttons, 0); + shell.getDisplay().syncExec(new Runnable() { + public void run() { + dialog.open(); + } + }); + return dialog.getReturnCode(); + } + + /* (non-Javadoc) + * @see org.eclipse.team.examples.filesystem.ui.FileSystemSynchronizeOperation#run(org.eclipse.team.examples.filesystem.FileSystemProvider, org.eclipse.team.core.synchronize.SyncInfoSet, org.eclipse.core.runtime.IProgressMonitor) + */ + protected void run(FileSystemProvider provider, SyncInfoSet set, IProgressMonitor monitor) throws TeamException { + provider.getOperations().get(set.getResources(), IResource.DEPTH_INFINITE, true, monitor); + } + +} |