diff options
author | Tomasz Zarna | 2009-12-15 14:08:21 +0000 |
---|---|---|
committer | Tomasz Zarna | 2009-12-15 14:08:21 +0000 |
commit | fea52a74ae84d9b7040eb49d8664c0ae85161094 (patch) | |
tree | 562a3a08bde919b2cff89cf55f8a99d92665094c /bundles | |
parent | 2cad51d4599dcc09019f63b2b61d39ff2ff07387 (diff) | |
download | eclipse.platform.team-fea52a74ae84d9b7040eb49d8664c0ae85161094.tar.gz eclipse.platform.team-fea52a74ae84d9b7040eb49d8664c0ae85161094.tar.xz eclipse.platform.team-fea52a74ae84d9b7040eb49d8664c0ae85161094.zip |
Initial commit -- 3.6M4 work.
Diffstat (limited to 'bundles')
29 files changed, 1720 insertions, 16 deletions
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/META-INF/MANIFEST.MF b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/META-INF/MANIFEST.MF index 399e23291..da375d8d1 100644 --- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/META-INF/MANIFEST.MF @@ -10,7 +10,7 @@ Export-Package: org.eclipse.compare, org.eclipse.compare.contentmergeviewer, org.eclipse.compare.internal;x-internal:=true, org.eclipse.compare.internal.merge;x-internal:=true, - org.eclipse.compare.internal.patch;x-internal:=true, + org.eclipse.compare.internal.patch;x-friends:="org.eclipse.team.ui", org.eclipse.compare.patch, org.eclipse.compare.structuremergeviewer Require-Bundle: org.eclipse.ui;bundle-version="[3.5.0,4.0.0)", diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/InputPatchPage.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/InputPatchPage.java index 9b51fb3c8..efe7e63e4 100644 --- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/InputPatchPage.java +++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/InputPatchPage.java @@ -71,7 +71,7 @@ import org.eclipse.ui.views.navigator.ResourceComparator; import com.ibm.icu.text.MessageFormat; -/* package */ class InputPatchPage extends WizardPage { +public class InputPatchPage extends WizardPage { // constants protected static final int SIZING_TEXT_FIELD_WIDTH= 250; @@ -124,7 +124,7 @@ import com.ibm.icu.text.MessageFormat; } } - InputPatchPage(PatchWizard pw) { + public InputPatchPage(PatchWizard pw) { super(INPUTPATCHPAGE_NAME, PatchMessages.InputPatchPage_title, null); fPatchWizard= pw; setMessage(PatchMessages.InputPatchPage_message); @@ -206,7 +206,10 @@ import com.ibm.icu.text.MessageFormat; // all of the projects that make up the patch and continue on to final preview page // else go on to target selection page if (patcher.isWorkspacePatch()) { - return fPatchWizard.getPage(PreviewPatchPage2.PREVIEWPATCHPAGE_NAME); + // skip 'Patch Target' page + IWizardPage page = super.getNextPage(); + if (page.getName().equals(PatchTargetPage.PATCHTARGETPAGE_NAME)) + return page.getNextPage(); } return super.getNextPage(); diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatchTargetPage.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatchTargetPage.java index ccca2d32e..8fd95d738 100644 --- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatchTargetPage.java +++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatchTargetPage.java @@ -12,18 +12,31 @@ package org.eclipse.compare.internal.patch; import org.eclipse.compare.internal.ICompareContextIds; import org.eclipse.compare.internal.Utilities; -import org.eclipse.core.resources.*; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.viewers.*; +import org.eclipse.jface.viewers.DoubleClickEvent; +import org.eclipse.jface.viewers.IDoubleClickListener; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.wizard.IWizardPage; import org.eclipse.jface.wizard.WizardPage; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.*; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.Tree; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.model.WorkbenchContentProvider; import org.eclipse.ui.model.WorkbenchLabelProvider; @@ -48,7 +61,7 @@ public class PatchTargetPage extends WizardPage { protected final static String PATCHTARGETPAGE_NAME = "PatchTargetPage"; //$NON-NLS-1$ - PatchTargetPage(WorkspacePatcher patcher) { + public PatchTargetPage(WorkspacePatcher patcher) { super(PATCHTARGETPAGE_NAME, PatchMessages.PatchTargetPage_title, null); setMessage(PatchMessages.PatchTargetPage_message); fPatcher = patcher; diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatchWizard.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatchWizard.java index fa19443a7..9b9773583 100644 --- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatchWizard.java +++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatchWizard.java @@ -40,9 +40,9 @@ public class PatchWizard extends Wizard { private boolean fHasNewDialogSettings; - private InputPatchPage fPatchWizardPage; - private PatchTargetPage fPatchTargetPage; - private PreviewPatchPage2 fPreviewPage2; + protected InputPatchPage fPatchWizardPage; + protected PatchTargetPage fPatchTargetPage; + protected PreviewPatchPage2 fPreviewPage2; private final WorkspacePatcher fPatcher; @@ -86,15 +86,18 @@ public class PatchWizard extends Wizard { } } - WorkspacePatcher getPatcher() { + protected WorkspacePatcher getPatcher() { return fPatcher; } - + + protected IStorage getPatch() { + return patch; + } + IResource getTarget() { return fPatcher.getTarget(); } - /* (non-Javadoc) * Method declared on IWizard. */ diff --git a/bundles/org.eclipse.team.ui/META-INF/MANIFEST.MF b/bundles/org.eclipse.team.ui/META-INF/MANIFEST.MF index a838368a7..45d93b6e9 100644 --- a/bundles/org.eclipse.team.ui/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.team.ui/META-INF/MANIFEST.MF @@ -15,6 +15,7 @@ Export-Package: org.eclipse.team.internal.ui;x-friends:="org.eclipse.team.cvs.ss org.eclipse.team.internal.ui.registry;x-friends:="org.eclipse.team.cvs.ssh,org.eclipse.team.cvs.ssh2,org.eclipse.team.cvs.ui", org.eclipse.team.internal.ui.synchronize;x-friends:="org.eclipse.team.cvs.ssh,org.eclipse.team.cvs.ssh2,org.eclipse.team.cvs.ui", org.eclipse.team.internal.ui.synchronize.actions;x-friends:="org.eclipse.team.cvs.ssh,org.eclipse.team.cvs.ssh2,org.eclipse.team.cvs.ui", + org.eclipse.team.internal.ui.synchronize.patch;x-internal:=true, org.eclipse.team.internal.ui.wizards;x-friends:="org.eclipse.team.cvs.ssh,org.eclipse.team.cvs.ssh2,org.eclipse.team.cvs.ui", org.eclipse.team.ui, org.eclipse.team.ui.history, diff --git a/bundles/org.eclipse.team.ui/plugin.properties b/bundles/org.eclipse.team.ui/plugin.properties index af0be473b..9c059f080 100644 --- a/bundles/org.eclipse.team.ui/plugin.properties +++ b/bundles/org.eclipse.team.ui/plugin.properties @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2000, 2008 IBM Corporation and others. +# Copyright (c) 2000, 2009 IBM Corporation and others. # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Public License v1.0 # which accompanies this distribution, and is available at @@ -78,3 +78,5 @@ CompareWithEachOtherAction.label= &Each Other CompareWithEachOtherAction.tooltip= Compare the Selected Resources ignoresTransferName= Team Ignored Resources Transfer + +PatchModel=Patch Contents diff --git a/bundles/org.eclipse.team.ui/plugin.xml b/bundles/org.eclipse.team.ui/plugin.xml index d58a93d51..54bda73d3 100644 --- a/bundles/org.eclipse.team.ui/plugin.xml +++ b/bundles/org.eclipse.team.ui/plugin.xml @@ -567,4 +567,122 @@ </mapping> </transfer> </extension> + <extension + point="org.eclipse.team.ui.synchronizeWizards"> + <wizard + class="org.eclipse.team.internal.ui.synchronize.patch.ApplyPatchSynchronizationWizard" + description="description" + icon="icons/full/obj/resource_model.gif" + id="org.eclipse.team.ui.applyPatchWizard" + name="Apply Patch"> + </wizard> + </extension> + <extension + point="org.eclipse.team.ui.synchronizeParticipants"> + <participant + class="org.eclipse.team.internal.ui.synchronize.patch.ApplyPatchModelSynchronizeParticipant" + id="org.eclipse.team.ui.applyPatchModelParticipant" + name="Apply Patch Model Synchronize Participant" + persistent="false"> + </participant> + </extension> + <extension + id="patchModel" + name="%PatchModel" + point="org.eclipse.core.resources.modelProviders"> + <modelProvider + class="org.eclipse.team.internal.ui.synchronize.patch.PatchModelProvider"/> + <extends-model id="org.eclipse.core.resources.modelProvider"/> + <enablement> + <instanceof + value="org.eclipse.core.resources.IResource"> + </instanceof> + </enablement> + </extension> + <extension + point="org.eclipse.ui.navigator.navigatorContent"> + <navigatorContent + contentProvider="org.eclipse.team.internal.ui.synchronize.patch.PatchSyncContentProvider" + id="org.eclipse.team.ui.patchSyncNavigatorContent" + labelProvider="org.eclipse.team.internal.ui.synchronize.patch.PatchSyncLabelProvider" + name="Patch" + priority="highest"> + <override + policy="InvokeAlwaysRegardlessOfSuppressedExt" + suppressedExtensionId="org.eclipse.team.ui.resourceContent"> + </override> + <triggerPoints> + <or> + <instanceof + value="org.eclipse.team.core.mapping.ISynchronizationScope"> + </instanceof> + <instanceof + value="org.eclipse.team.core.mapping.ISynchronizationContext"> + </instanceof> + <instanceof + value="org.eclipse.team.internal.ui.synchronize.patch.PatchWorkspace"> + </instanceof> + <instanceof + value="org.eclipse.compare.internal.patch.PatchDiffNode"> + </instanceof> + <instanceof + value="org.eclipse.team.internal.ui.synchronize.patch.PatchModelProvider"> + </instanceof> + </or> + </triggerPoints> + </navigatorContent> + </extension> + <extension + point="org.eclipse.core.runtime.adapters"> + <factory + adaptableType="org.eclipse.compare.internal.patch.PatchProjectDiffNode" + class="org.eclipse.team.internal.ui.synchronize.patch.AdapterFactory"> + <adapter + type="org.eclipse.core.resources.mapping.ResourceMapping"> + </adapter> + <adapter + type="org.eclipse.ui.model.IWorkbenchAdapter"> + </adapter> + </factory> + <factory + adaptableType="org.eclipse.compare.internal.patch.PatchFileDiffNode" + class="org.eclipse.team.internal.ui.synchronize.patch.AdapterFactory"> + <adapter + type="org.eclipse.core.resources.mapping.ResourceMapping"> + </adapter> + <adapter + type="org.eclipse.ui.model.IWorkbenchAdapter"> + </adapter> + </factory> + <factory + adaptableType="org.eclipse.compare.internal.patch.HunkDiffNode" + class="org.eclipse.team.internal.ui.synchronize.patch.AdapterFactory"> + <adapter + type="org.eclipse.core.resources.mapping.ResourceMapping"> + </adapter> + <adapter + type="org.eclipse.ui.model.IWorkbenchAdapter"> + </adapter> + </factory> + <factory + adaptableType="org.eclipse.team.internal.ui.synchronize.patch.PatchWorkspace" + class="org.eclipse.team.internal.ui.synchronize.patch.AdapterFactory"> + <adapter + type="org.eclipse.ui.model.IWorkbenchAdapter"> + </adapter> + </factory> + <factory + adaptableType="org.eclipse.team.internal.ui.synchronize.patch.PatchModelProvider" + class="org.eclipse.team.internal.ui.synchronize.patch.AdapterFactory"> + <!--adapter type="org.eclipse.team.core.mapping.IResourceMappingMerger"/--> + <adapter type="org.eclipse.team.ui.mapping.ISynchronizationCompareAdapter"/> + </factory> + </extension> + <extension + point="org.eclipse.team.ui.teamContentProviders"> + <teamContentProvider + contentExtensionId="org.eclipse.team.ui.patchSyncNavigatorContent" + modelProviderId="org.eclipse.team.ui.patchModel"> + </teamContentProvider> + </extension> </plugin> diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/TeamUIMessages.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/TeamUIMessages.java index e2545dc60..d2fb871f4 100644 --- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/TeamUIMessages.java +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/TeamUIMessages.java @@ -714,6 +714,11 @@ public class TeamUIMessages extends NLS { public static String SelectAncestorDialog_message; public static String SelectAncestorDialog_option; + public static String PatchPreviewModePage_title; + public static String PatchPreviewModePage_description; + public static String PatchPreviewModePage_previewInPatchWizard; + public static String PatchPreviewModePage_previewInSynchronizeView; + public static String NotFound; } diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/messages.properties b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/messages.properties index e0353a660..fc7cad943 100644 --- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/messages.properties +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/messages.properties @@ -570,3 +570,10 @@ SaveablesCompareEditorInput_threeWayTooltip=Three-way compare of ''{1}'' and ''{ SelectAncestorDialog_title=Select Common Ancestor SelectAncestorDialog_message=Which resource would you like to use as the common ancestor in the three-way compare? SelectAncestorDialog_option=''{0}'' +# +# PatchPreviewModePage +# +PatchPreviewModePage_title=Patch Preview Mode +PatchPreviewModePage_description=Choose the way to preview the patch. +PatchPreviewModePage_previewInPatchWizard=Preview in the &Patch Wizard +PatchPreviewModePage_previewInSynchronizeView=Preview in the &synchronize view
\ No newline at end of file diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/AdapterFactory.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/AdapterFactory.java new file mode 100644 index 000000000..aa564bbc1 --- /dev/null +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/AdapterFactory.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.team.internal.ui.synchronize.patch; + +import org.eclipse.compare.internal.patch.*; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.mapping.ResourceMapping; +import org.eclipse.core.runtime.IAdapterFactory; +import org.eclipse.team.ui.mapping.ISynchronizationCompareAdapter; +import org.eclipse.ui.model.IWorkbenchAdapter; + +public class AdapterFactory implements IAdapterFactory { + + private IWorkbenchAdapter modelAdapter = new PatchWorkbenchAdapter(); + private ISynchronizationCompareAdapter compareAdapter; + + public Object getAdapter(Object adaptableObject, Class adapterType) { + if (adapterType == ResourceMapping.class) { + if (adaptableObject instanceof PatchProjectDiffNode) { + return new DiffProjectResourceMapping( + ((PatchProjectDiffNode) adaptableObject).getDiffProject()); + } + if (adaptableObject instanceof PatchFileDiffNode) { + return new FilePatchResourceMapping( + ((PatchFileDiffNode) adaptableObject).getDiffResult()); + } + if (adaptableObject instanceof HunkDiffNode) { + return new HunkResourceMapping(((HunkDiffNode) adaptableObject).getHunkResult()); + } + } + if (adapterType == IWorkbenchAdapter.class) + return modelAdapter; + if (adapterType == ISynchronizationCompareAdapter.class && adaptableObject instanceof PatchModelProvider) { + if (compareAdapter == null) { + compareAdapter = new PatchCompareAdapter(/*(PatchModelProvider)adaptableObject*/); + } + return compareAdapter; + } + return null; + } + + public Class[] getAdapterList() { + return new Class[] { ResourceMapping.class, IWorkbenchAdapter.class, + IResource.class }; + } +} diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/ApplyPatchModelSynchronizeParticipant.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/ApplyPatchModelSynchronizeParticipant.java new file mode 100644 index 000000000..c9f56a38e --- /dev/null +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/ApplyPatchModelSynchronizeParticipant.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * Copyright (c) 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.team.internal.ui.synchronize.patch; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.jface.action.Action; +import org.eclipse.team.core.mapping.provider.SynchronizationContext; +import org.eclipse.team.ui.TeamUI; +import org.eclipse.team.ui.mapping.SynchronizationActionProvider; +import org.eclipse.team.ui.synchronize.*; + +public class ApplyPatchModelSynchronizeParticipant extends + ModelSynchronizeParticipant { + + public static final String ID = "org.eclipse.team.ui.applyPatchModelParticipant"; //$NON-NLS-1$ + + public ApplyPatchModelSynchronizeParticipant(SynchronizationContext context) { + super(context); + init(); + } + + private void init() { + try { + ISynchronizeParticipantDescriptor descriptor = TeamUI + .getSynchronizeManager().getParticipantDescriptor(ID); + setInitializationData(descriptor); + setSecondaryId(Long.toString(System.currentTimeMillis())); + } catch (CoreException e) { + // ignore + } + } + + protected void initializeConfiguration( + final ISynchronizePageConfiguration configuration) { + super.initializeConfiguration(configuration); + configuration + .setSupportedModes(ISynchronizePageConfiguration.INCOMING_MODE + | ISynchronizePageConfiguration.CONFLICTING_MODE); + configuration.setMode(ISynchronizePageConfiguration.INCOMING_MODE); + } + + protected ModelSynchronizeParticipantActionGroup createMergeActionGroup() { + return new ApplyPatchModelSynchronizeParticipantActionGroup(); + } + + public class ApplyPatchModelSynchronizeParticipantActionGroup extends + ModelSynchronizeParticipantActionGroup { + protected void configureMergeAction(String mergeActionId, Action action) { + if (mergeActionId == SynchronizationActionProvider.MERGE_ACTION_ID) { + // Custom label for merge + action.setText("Apply (merge)"); //$NON-NLS-1$ + } else if (mergeActionId == SynchronizationActionProvider.OVERWRITE_ACTION_ID) { + // Custom label for overwrite + action.setText("Apply (overwrite)"); //$NON-NLS-1$ + } else if (mergeActionId == SynchronizationActionProvider.MARK_AS_MERGE_ACTION_ID) { + // Custom label for mark-as-merged + action.setText("Exclude"); //$NON-NLS-1$ + } else { + super.configureMergeAction(mergeActionId, action); + } + } + } +} diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/ApplyPatchSubscriber.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/ApplyPatchSubscriber.java new file mode 100644 index 000000000..7e81fbbf6 --- /dev/null +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/ApplyPatchSubscriber.java @@ -0,0 +1,143 @@ +/******************************************************************************* + * Copyright (c) 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.team.internal.ui.synchronize.patch; + +import java.util.*; + +import org.eclipse.compare.internal.core.patch.*; +import org.eclipse.compare.internal.patch.*; +import org.eclipse.compare.structuremergeviewer.IDiffElement; +import org.eclipse.core.resources.*; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.team.core.TeamException; +import org.eclipse.team.core.subscribers.Subscriber; +import org.eclipse.team.core.synchronize.SyncInfo; +import org.eclipse.team.core.variants.IResourceVariant; +import org.eclipse.team.core.variants.IResourceVariantComparator; +import org.eclipse.team.internal.core.mapping.LocalResourceVariant; + +public class ApplyPatchSubscriber extends Subscriber { + + private WorkspacePatcher patcher; + private IResourceVariantComparator comparator; + + public ApplyPatchSubscriber(WorkspacePatcher patcher) { + this.patcher = patcher; + this.comparator = new PatchedFileVariantComparator(); + getPatcher().refresh(); + PatchWorkspace.create(ResourcesPlugin.getWorkspace().getRoot(), getPatcher()); + } + + public String getName() { + // TODO: change to something like '{0} patch applied' + return "Apply Patch Subscriber"; //$NON-NLS-1$ + } + + public IResourceVariantComparator getResourceComparator() { + return comparator; + } + + public SyncInfo getSyncInfo(IResource resource) throws TeamException { + FilePatch2[] diffs = getPatcher().getDiffs(); + try { + IResourceVariant variant = null; + if (resource.getType() == IResource.FILE) { + for (int i = 0; i < diffs.length; i++) { + if (diffs[i] instanceof FilePatch2) { + DiffProject diffProject = (diffs[i]).getProject(); + IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(diffProject.getName()); + IFile file = project.getFile(diffs[i].getPath(getPatcher().isReversed())); + if (file.equals(resource)) { + // null as 'variant' for deletions + if (diffs[i].getDiffType(patcher.isReversed()) != FilePatch2.DELETION) + variant = new PatchedFileVariant(getPatcher(), diffs[i]); + IResourceVariant base = resource.exists() ? new LocalResourceVariant(resource) : null; + SyncInfo info = new SyncInfo(resource, base, variant, getResourceComparator()); + info.init(); + return info; + } + } + } + } + return null; + } catch (CoreException e) { + throw TeamException.asTeamException(e); + } + } + + public boolean isSupervised(IResource resource) throws TeamException { + // TODO Auto-generated method stub + System.out.println(">> [true] isSupervised: " + resource.getName()); //$NON-NLS-1$ + return true; + } + + public IResource[] members(IResource resource) throws TeamException { + FilePatch2[] diffs = getPatcher().getDiffs(); + try { + if(resource.getType() == IResource.FILE) + // file has no members + return new IResource[0]; + IContainer container = (IContainer) resource; + + // workspace container members + List existingChildren = new ArrayList(Arrays.asList(container.members())); + + // patch members, subscriber location + for (int i = 0; i < diffs.length; i++) { + DiffProject diffProject = diffs[i].getProject(); + IProject project = container.getProject(); + if (project.getName().equals(diffProject.getName())) { + IResource file = project.getFile(diffs[i].getPath(getPatcher().isReversed())); + if (!existingChildren.contains(file)) { + existingChildren.add(file); + } + } + } + return (IResource[]) existingChildren.toArray(new IResource[existingChildren.size()]); + } catch (CoreException e) { + throw TeamException.asTeamException(e); + } + } + + public void refresh(IResource[] resources, int depth, + IProgressMonitor monitor) throws TeamException { + // TODO Auto-generated method stub + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < resources.length; i++) { + sb.append(resources[i].getName()).append(","); //$NON-NLS-1$ + } + System.out + .println(">> [ignored] ApplyPatchSubscriber.refresh: " + sb.toString()); //$NON-NLS-1$ + } + + public IResource[] roots() { + IDiffElement[] children = PatchWorkspace.getInstance().getChildren(); + Set roots = new HashSet(); + for (int i = 0; i < children.length; i++) { + if (getPatcher().isWorkspacePatch()) { + // return array of projects from the patch + DiffProject diffProject = ((PatchProjectDiffNode)children[i]).getDiffProject(); + IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(diffProject.getName()); + roots.add(project); + } else { + FileDiffResult diffResult = ((PatchFileDiffNode)children[i]).getDiffResult(); + IFile file = ((WorkspaceFileDiffResult)diffResult).getTargetFile(); + roots.add(file); + } + } + return (IResource[]) roots.toArray(new IResource[0]); + } + + WorkspacePatcher getPatcher() { + return patcher; + } +} diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/ApplyPatchSubscriberMergeContext.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/ApplyPatchSubscriberMergeContext.java new file mode 100644 index 000000000..628b8d8a3 --- /dev/null +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/ApplyPatchSubscriberMergeContext.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.team.internal.ui.synchronize.patch; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.team.core.diff.IDiff; +import org.eclipse.team.core.mapping.ISynchronizationScopeManager; +import org.eclipse.team.core.subscribers.Subscriber; +import org.eclipse.team.core.subscribers.SubscriberMergeContext; + +class ApplyPatchSubscriberMergeContext extends SubscriberMergeContext { + + protected ApplyPatchSubscriberMergeContext(Subscriber subscriber, + ISynchronizationScopeManager manager) { + super(subscriber, manager); + } + + public static ApplyPatchSubscriberMergeContext createContext( + Subscriber subscriber, ISynchronizationScopeManager manager) { + ApplyPatchSubscriberMergeContext mergeContext = new ApplyPatchSubscriberMergeContext( + subscriber, manager); + // Initialize using the ApplyPatchSubscriber to populate the diff tree. + mergeContext.initialize(); + return mergeContext; + } + + protected void makeInSync(IDiff diff, IProgressMonitor monitor) + throws CoreException { + // TODO Auto-generated method stub + System.out.println(">> [ignore] makeInSync: " + diff.toDiffString()); //$NON-NLS-1$ + } + + public void markAsMerged(IDiff node, boolean inSyncHint, + IProgressMonitor monitor) throws CoreException { + // TODO Auto-generated method stub + System.out + .println(">> [ignore] markAsMerged: " + node.toDiffString() + ", inSyncHint " + inSyncHint); //$NON-NLS-1$ //$NON-NLS-2$ + } + + public void reject(IDiff diff, IProgressMonitor monitor) + throws CoreException { + // TODO Auto-generated method stub + System.out.println(">> [ignore] reject: " + diff.toDiffString()); //$NON-NLS-1$ + } +} diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/ApplyPatchSynchronizationWizard.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/ApplyPatchSynchronizationWizard.java new file mode 100644 index 000000000..4d1a99346 --- /dev/null +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/ApplyPatchSynchronizationWizard.java @@ -0,0 +1,96 @@ +/******************************************************************************* + * Copyright (c) 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.team.internal.ui.synchronize.patch; + +import org.eclipse.compare.CompareConfiguration; +import org.eclipse.compare.internal.patch.*; +import org.eclipse.core.resources.*; +import org.eclipse.core.resources.mapping.ResourceMapping; +import org.eclipse.jface.wizard.IWizardPage; +import org.eclipse.team.core.subscribers.SubscriberMergeContext; +import org.eclipse.team.core.subscribers.SubscriberScopeManager; +import org.eclipse.team.internal.ui.Utils; +import org.eclipse.team.ui.IConfigurationWizard; +import org.eclipse.team.ui.TeamUI; +import org.eclipse.team.ui.synchronize.ISynchronizeParticipant; +import org.eclipse.team.ui.synchronize.ModelSynchronizeParticipant; +import org.eclipse.ui.IWorkbench; + +public class ApplyPatchSynchronizationWizard extends PatchWizard implements + IConfigurationWizard { + + public ApplyPatchSynchronizationWizard() { + // TODO: get selection, available when launched from toolbar or main menu + super((IStorage) null, (IResource) null, new CompareConfiguration()); + } + + private boolean isPreviewInSyncViewSelected() { + return ((PatchPreviewModePage)getPage(PatchPreviewModePage.PATCH_PREVIEW_MODE_PAGE_NAME)).isPreviewInSyncViewSelected(); + } + + public boolean performFinish() { + if (isPreviewInSyncViewSelected()) { + ApplyPatchSubscriber subscriber = new ApplyPatchSubscriber(getPatcher()); + + // Get ResourceMappings for root resources from the patch. + ResourceMapping[] inputMappings = Utils.getResourceMappings(subscriber.roots()); + + // Take the given mappings, consult logical models and construct the complete set of resources to be operated on. + // Use SubscriberResourceMappingContext which uses subscriber to access to the remote state of local resources. + SubscriberScopeManager scopeManager = new SubscriberScopeManager(subscriber.getName(), inputMappings, subscriber, true); + + // Initialize the diff tree. + // TODO: are we going to perform head-less auto-merges? do we need to subclass MergeContext? + SubscriberMergeContext mergeContext = ApplyPatchSubscriberMergeContext.createContext(subscriber, scopeManager); + + // Create the participant and show it. + ModelSynchronizeParticipant participant = new ApplyPatchModelSynchronizeParticipant(mergeContext); + TeamUI.getSynchronizeManager().addSynchronizeParticipants(new ISynchronizeParticipant[]{participant}); + // We don't know in which site to show progress because a participant could actually be shown in multiple sites. + participant.run(null /* no site */); + return true; + } else { + // apply the patch + return super.performFinish(); + // TODO: Next, synchronize the affected files, but only when the wizard has been opened from the sync view. + } + } + + public void init(IWorkbench workbench, IProject project) { + // nothing to do here + } + + public void addPages() { + if (getPatch() == null) + addPage(fPatchWizardPage = new InputPatchPage(this)); + if (getPatch() == null || !getPatcher().isWorkspacePatch()) + addPage(fPatchTargetPage = new PatchTargetPage(getPatcher())); + addPage(new PatchPreviewModePage()); + fPreviewPage2 = new PreviewPatchPage2(getPatcher(), + getCompareConfiguration()); + addPage(fPreviewPage2); + } + + public boolean canFinish() { + IWizardPage currentPage = getContainer().getCurrentPage(); + if (currentPage.getName().equals( + PatchPreviewModePage.PATCH_PREVIEW_MODE_PAGE_NAME) + && isPreviewInSyncViewSelected()) { + return true; + } + return super.canFinish(); + } + + public WorkspacePatcher getPatcher() { + // make the patcher available to other classes in the package + return super.getPatcher(); + } +} diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/DiffProjectResourceMapping.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/DiffProjectResourceMapping.java new file mode 100644 index 000000000..376e9b815 --- /dev/null +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/DiffProjectResourceMapping.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright (c) 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.team.internal.ui.synchronize.patch; + +import org.eclipse.compare.internal.core.patch.*; +import org.eclipse.core.resources.*; +import org.eclipse.core.resources.mapping.*; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; + +public class DiffProjectResourceMapping extends ResourceMapping { + + private final DiffProject object; + + public DiffProjectResourceMapping(DiffProject adaptableObject) { + object = adaptableObject; + } + + public Object getModelObject() { + return object; + } + + public String getModelProviderId() { + return PatchModelProvider.ID; + } + + public IProject[] getProjects() { + IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject( + object.getName()); + return new IProject[] { p }; + } + + public ResourceTraversal[] getTraversals(ResourceMappingContext context, + IProgressMonitor monitor) throws CoreException { + return new ResourceTraversal[] { new ResourceTraversal( + new IResource[] { getResource() }, IResource.DEPTH_INFINITE, + IResource.NONE) }; + } + + private IResource getResource() { + return getProjects()[0]; + } + + public boolean contains(ResourceMapping mapping) { + if (mapping instanceof DiffProjectResourceMapping) { + DiffProject diffProject = (DiffProject) mapping.getModelObject(); + return diffProject.getName().equals(object.getName()); + } else if (mapping instanceof FilePatchResourceMapping) { + FileDiffResult filePatch = (FileDiffResult) mapping + .getModelObject(); + FilePatch2[] filePatches = object.getFileDiffs(); + for (int i = 0; i < filePatches.length; i++) { + if (filePatches[i].getPath(false).equals( + filePatch.getTargetPath())) + return true; + } + } else if (mapping instanceof HunkResourceMapping) { + HunkResult hunk = (HunkResult) mapping.getModelObject(); + DiffProject diffProject = hunk.getHunk().getParent().getProject(); + return diffProject.getName().equals(object.getName()); + } + return super.contains(mapping); + } + +} diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/FilePatchResourceMapping.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/FilePatchResourceMapping.java new file mode 100644 index 000000000..2795d5fa5 --- /dev/null +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/FilePatchResourceMapping.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.team.internal.ui.synchronize.patch; + +import org.eclipse.compare.internal.core.patch.DiffProject; +import org.eclipse.compare.internal.core.patch.FileDiffResult; +import org.eclipse.compare.internal.patch.WorkspaceFileDiffResult; +import org.eclipse.core.resources.*; +import org.eclipse.core.resources.mapping.*; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; + +public class FilePatchResourceMapping extends ResourceMapping { + + private final FileDiffResult object; + + public FilePatchResourceMapping(FileDiffResult fileDiffResult) { + object = fileDiffResult; + } + + public Object getModelObject() { + return object; + } + + public String getModelProviderId() { + return PatchModelProvider.ID; + } + + public IProject[] getProjects() { + DiffProject dp = (DiffProject) object.getDiff().getProject(); + IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject( + dp.getName()); + return new IProject[] { p }; + } + + public ResourceTraversal[] getTraversals(ResourceMappingContext context, + IProgressMonitor monitor) throws CoreException { + return new ResourceTraversal[] { new ResourceTraversal( + new IResource[] { getResource() }, IResource.DEPTH_INFINITE, + IResource.NONE) }; + } + + private IResource getResource() { + return ((WorkspaceFileDiffResult) object).getTargetFile(); + } +} diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/HunkResourceMapping.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/HunkResourceMapping.java new file mode 100644 index 000000000..9bd50fcc7 --- /dev/null +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/HunkResourceMapping.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.team.internal.ui.synchronize.patch; + +import org.eclipse.compare.internal.core.patch.DiffProject; +import org.eclipse.compare.internal.core.patch.HunkResult; +import org.eclipse.core.resources.*; +import org.eclipse.core.resources.mapping.*; +import org.eclipse.core.runtime.*; + +public class HunkResourceMapping extends ResourceMapping { + + private final HunkResult object; + + public HunkResourceMapping(HunkResult hunkResult) { + this.object = hunkResult; + } + + public Object getModelObject() { + return object; + } + + public String getModelProviderId() { + return PatchModelProvider.ID; + } + + public IProject[] getProjects() { + DiffProject dp = (DiffProject) object.getHunk().getParent() + .getProject(); + IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject( + dp.getName()); + return new IProject[] { p }; + } + + private IResource getResource() { + IPath path = object.getHunk().getParent().getPath(false); + return getProjects()[0].getFile(path); + } + + public ResourceTraversal[] getTraversals(ResourceMappingContext context, + IProgressMonitor monitor) throws CoreException { + return new ResourceTraversal[] { new ResourceTraversal( + new IResource[] { getResource() }, IResource.DEPTH_ZERO, + IResource.NONE) }; + } +} diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/PatchCompareAdapter.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/PatchCompareAdapter.java new file mode 100644 index 000000000..50c435bac --- /dev/null +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/PatchCompareAdapter.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.team.internal.ui.synchronize.patch; + +import org.eclipse.compare.structuremergeviewer.ICompareInput; +import org.eclipse.core.resources.mapping.ResourceMapping; +import org.eclipse.team.core.mapping.ISynchronizationContext; +import org.eclipse.team.ui.mapping.SynchronizationCompareAdapter; +import org.eclipse.ui.IMemento; + +public class PatchCompareAdapter extends SynchronizationCompareAdapter { + + public ICompareInput asCompareInput(ISynchronizationContext context, + Object o) { + if (o instanceof ICompareInput) + return (ICompareInput) o; + return super.asCompareInput(context, o); + } + + public void save(ResourceMapping[] mappings, IMemento memento) { + // TODO Auto-generated method stub + + } + + public ResourceMapping[] restore(IMemento memento) { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/PatchModelProvider.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/PatchModelProvider.java new file mode 100644 index 000000000..b662cb78f --- /dev/null +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/PatchModelProvider.java @@ -0,0 +1,105 @@ +/******************************************************************************* + * Copyright (c) 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.team.internal.ui.synchronize.patch; + +import org.eclipse.compare.internal.core.patch.FileDiffResult; +import org.eclipse.compare.internal.patch.*; +import org.eclipse.compare.structuremergeviewer.IDiffElement; +import org.eclipse.core.resources.*; +import org.eclipse.core.resources.mapping.*; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.team.core.subscribers.SubscriberResourceMappingContext; +import org.eclipse.team.internal.core.TeamPlugin; + +public class PatchModelProvider extends ModelProvider { + + public static final String ID = "org.eclipse.team.ui.patchModel"; //$NON-NLS-1$ + private static PatchModelProvider provider; + + public static PatchModelProvider getProvider() { + if (provider == null) { + try { + provider = (PatchModelProvider) ModelProvider + .getModelProviderDescriptor(PatchModelProvider.ID) + .getModelProvider(); + } catch (CoreException e) { + TeamPlugin.log(e); + } + } + return provider; + } + + public ResourceMapping[] getMappings(IResource resource, + ResourceMappingContext context, IProgressMonitor monitor) + throws CoreException { + if (context instanceof SubscriberResourceMappingContext) { + SubscriberResourceMappingContext srmc = (SubscriberResourceMappingContext) context; + if (resource instanceof IProject) { + IProject[] projects = srmc.getProjects(); + for (int i = 0; i < projects.length; i++) { + if (projects[i].equals(resource)) { + IDiffElement object = createModelObject(resource); + if (object != null) + return new ResourceMapping[] { getResourceMapping(object) }; + } + } + } + } + return super.getMappings(resource, context, monitor); + } + + static ResourceMapping getResourceMapping(IDiffElement object) { + if (object instanceof PatchProjectDiffNode) { + return new DiffProjectResourceMapping( + ((PatchProjectDiffNode) object).getDiffProject()); + } else if (object instanceof PatchFileDiffNode) { + return new FilePatchResourceMapping(((PatchFileDiffNode) object) + .getDiffResult()); + } else if (object instanceof HunkDiffNode) { + return new HunkResourceMapping(((HunkDiffNode) object) + .getHunkResult()); + } + return null; + } + + static IDiffElement createModelObject(IResource resource) { + PatchWorkspace pw = PatchWorkspace.getInstance(); + /* pw == null means that we're not applying a patch in the sync view */ + if (pw != null) { + IDiffElement[] children = pw.getChildren(); + + switch (resource.getType()) { + case IResource.PROJECT: { + for (int i = 0; i < children.length; i++) { + if (((PatchProjectDiffNode) children[i]).getDiffProject() + .getName().equals(resource.getName())) + return children[i]; + } + } + case IResource.FILE: { + for (int i = 0; i < children.length; i++) { + IDiffElement[] c = ((PatchProjectDiffNode) children[i]) + .getChildren(); + FileDiffResult diffResult = ((PatchFileDiffNode) c[i]) + .getDiffResult(); + IFile file = ((WorkspaceFileDiffResult) diffResult) + .getTargetFile(); + if (resource.equals(file)) { + return c[i]; + } + } + } + } + } + return null; + } +} diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/PatchPreviewModePage.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/PatchPreviewModePage.java new file mode 100644 index 000000000..7af836caf --- /dev/null +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/PatchPreviewModePage.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * Copyright (c) 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.team.internal.ui.synchronize.patch; + +import org.eclipse.jface.wizard.IWizardPage; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.team.internal.ui.TeamUIMessages; + +public class PatchPreviewModePage extends WizardPage { + + public final static String PATCH_PREVIEW_MODE_PAGE_NAME = "PatchPreviewModePage"; //$NON-NLS-1$ + private Button previewInDialogButton; + private Button previewInSyncViewButton; + + public PatchPreviewModePage() { + super(PATCH_PREVIEW_MODE_PAGE_NAME, + TeamUIMessages.PatchPreviewModePage_title, null); + setDescription(TeamUIMessages.PatchPreviewModePage_description); + } + + public void createControl(Composite parent) { + Composite composite = new Composite(parent, SWT.NULL); + composite.setLayout(new GridLayout()); + composite.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL + | GridData.HORIZONTAL_ALIGN_FILL)); + setControl(composite); + + initializeDialogUnits(parent); + createPreviewOptionArea(composite); + } + + private void createPreviewOptionArea(Composite parent) { + + SelectionAdapter selectionAdapter = new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + setPageComplete(true); // update wizard buttons + } + }; + + GridData gd = new GridData(); + + // 1st row + previewInDialogButton = new Button(parent, SWT.RADIO); + previewInDialogButton + .setText(TeamUIMessages.PatchPreviewModePage_previewInPatchWizard); + previewInDialogButton.setLayoutData(gd); + previewInDialogButton.addSelectionListener(selectionAdapter); + // TODO: enable 'Next' and 'Finish' + + // 2nd row + previewInSyncViewButton = new Button(parent, SWT.RADIO); + previewInSyncViewButton + .setText(TeamUIMessages.PatchPreviewModePage_previewInSynchronizeView); + previewInSyncViewButton.setLayoutData(gd); + previewInSyncViewButton.addSelectionListener(selectionAdapter); + previewInSyncViewButton.setSelection(true); + } + + public IWizardPage getNextPage() { + if (previewInSyncViewButton.getSelection()) + return null; + return super.getNextPage(); + } + + public boolean isPreviewInSyncViewSelected() { + return previewInSyncViewButton.getSelection(); + } + +} diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/PatchSyncContentProvider.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/PatchSyncContentProvider.java new file mode 100644 index 000000000..95890e804 --- /dev/null +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/PatchSyncContentProvider.java @@ -0,0 +1,164 @@ +/******************************************************************************* + * Copyright (c) 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.team.internal.ui.synchronize.patch; + +import java.util.*; + +import org.eclipse.compare.structuremergeviewer.IDiffElement; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.mapping.*; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.team.core.mapping.ISynchronizationContext; +import org.eclipse.team.core.mapping.ISynchronizationScope; +import org.eclipse.team.internal.ui.TeamUIPlugin; +import org.eclipse.team.internal.ui.Utils; +import org.eclipse.team.internal.ui.mapping.SynchronizationResourceMappingContext; +import org.eclipse.team.ui.mapping.SynchronizationContentProvider; +import org.eclipse.ui.navigator.*; + +public class PatchSyncContentProvider extends SynchronizationContentProvider + implements IPipelinedTreeContentProvider { + + private PatchWorkbenchContentProvider delegate; + + public PatchSyncContentProvider() { + super(); + } + + public void init(ICommonContentExtensionSite site) { + super.init(site); + delegate = new PatchWorkbenchContentProvider(/*getPatcher()*/); + // delegate.init(site); + } + + public void dispose() { + super.dispose(); + if (delegate != null) + delegate.dispose(); + } + + protected ITreeContentProvider getDelegateContentProvider() { + return delegate; + } + + protected String getModelProviderId() { + return PatchModelProvider.ID; + } + + protected Object getModelRoot() { + return PatchWorkspace.getInstance(); + } + + /* + * Copied from + * org.eclipse.team.examples.model.ui.mapping.ModelSyncContentProvider + * .getTraversals(ISynchronizationContext, Object) + */ + protected ResourceTraversal[] getTraversals( + ISynchronizationContext context, Object object) { + + ResourceMapping mapping = PatchModelProvider.getResourceMapping((IDiffElement) object); + ResourceMappingContext rmc = new SynchronizationResourceMappingContext( + context); + try { + // XXX: + // Technically speaking, this may end up being too long + // running for this + // (i.e. we may end up hitting the server) but it will do + // for illustration purposes + return mapping + .getTraversals(rmc, new NullProgressMonitor()); + } catch (CoreException e) { + TeamUIPlugin.log(e); + } + return new ResourceTraversal[0]; + } + + protected Object[] getChildrenInContext(ISynchronizationContext context, + Object parent, Object[] children) { + // TODO Auto-generated method stub + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < children.length; i++) { + sb.append(children[i].toString()).append(","); //$NON-NLS-1$ + } + System.out + .println(">> [super] PatchSyncContentProvider.getChildrenInContext: context-> " + context + "parent-> " + parent.toString() + "; children-> " + sb.toString()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + return super.getChildrenInContext(context, parent, children); + } + + public void getPipelinedChildren(Object aParent, Set theCurrentChildren) { + // Nothing to do + } + + public void getPipelinedElements(Object anInput, Set theCurrentElements) { + // Replace any model projects with a DiffProject if the input + // is a synchronization context + if (anInput instanceof ISynchronizationContext) { + List newProjects = new ArrayList(); + for (Iterator iter = theCurrentElements.iterator(); iter.hasNext();) { + Object element = iter.next(); + IResource[] resources = Utils.getContributedResources(new Object[] {element}); + //TODO: what about the rest? + IResource resource = resources[0]; + if (resource instanceof IProject) { + IProject project = (IProject) resource; + IDiffElement diffProject = PatchModelProvider.createModelObject(project/*, getPatcher()*/); + if (diffProject != null) { + iter.remove(); + newProjects.add(diffProject); + } + } + } + theCurrentElements.addAll(newProjects); + } else if (anInput instanceof ISynchronizationScope) { + // When the root is a scope, we should return + // our model provider so all model providers appear + // at the root of the viewer. + theCurrentElements.add(getModelProvider()); + } + } + + public Object getPipelinedParent(Object anObject, Object aSuggestedParent) { + // TODO Auto-generated method stub + System.out + .println(">> [aSuggestedParent] PatchSyncContentProvider.getPipelinedParent: aSuggestedParent-> " + aSuggestedParent); //$NON-NLS-1$ + return aSuggestedParent; + } + + public PipelinedShapeModification interceptAdd( + PipelinedShapeModification anAddModification) { + // TODO Auto-generated method stub + System.out + .println(">> [null] PatchSyncContentProvider.interceptAdd: anAddModification-> " + anAddModification); //$NON-NLS-1$ + return null; + } + + public boolean interceptRefresh( + PipelinedViewerUpdate aRefreshSynchronization) { + // No need to intercept the refresh + return false; + } + + public PipelinedShapeModification interceptRemove( + PipelinedShapeModification aRemoveModification) { + return aRemoveModification; + } + + public boolean interceptUpdate(PipelinedViewerUpdate anUpdateSynchronization) { + // No need to intercept the update + System.out + .println(">> [false] PatchSyncContentProvider.interceptUpdate: anUpdateSynchronization-> " + anUpdateSynchronization); //$NON-NLS-1$ + return false; + } +} diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/PatchSyncLabelProvider.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/PatchSyncLabelProvider.java new file mode 100644 index 000000000..bf1b378ff --- /dev/null +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/PatchSyncLabelProvider.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * Copyright (c) 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.team.internal.ui.synchronize.patch; + +import org.eclipse.compare.structuremergeviewer.Differencer; +import org.eclipse.compare.structuremergeviewer.IDiffElement; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.mapping.ResourceMapping; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.swt.graphics.Image; +import org.eclipse.team.core.diff.IDiff; +import org.eclipse.team.internal.ui.TeamUIPlugin; +import org.eclipse.team.ui.mapping.SynchronizationLabelProvider; +import org.eclipse.ui.navigator.ICommonContentExtensionSite; + +public class PatchSyncLabelProvider extends SynchronizationLabelProvider { + + private PatchWorkbenchLabelProvider delegate; + + public PatchSyncLabelProvider() { + super(); + } + + public void init(ICommonContentExtensionSite site) { + super.init(site); + delegate = new PatchWorkbenchLabelProvider(); + // delegate(site); + } + + public void dispose() { + super.dispose(); + if (delegate != null) + delegate.dispose(); + } + + protected ILabelProvider getDelegateLabelProvider() { + return delegate; + } + + protected IDiff getDiff(Object element) { + ResourceMapping mapping = PatchModelProvider + .getResourceMapping((IDiffElement) element); + if (mapping != null) { + // XXX: getting IResource for patch model object + try { + IResource resource = mapping.getTraversals(null, null)[0] + .getResources()[0]; + return getContext().getDiffTree().getDiff(resource); + } catch (CoreException e) { + TeamUIPlugin.log(e); + } + } + return super.getDiff(element); + } + + protected Image getCompareImage(Image base, int kind) { + /* + * Need to swap left and right for PatchDiffNodes as done in Apply Patch + * wizard. See org.eclipse.compare.structuremergeviewer.DiffTreeViewer. + * DiffViewerLabelProvider.getImage(Object). + */ + switch (kind & Differencer.DIRECTION_MASK) { + case Differencer.LEFT: + kind= (kind &~ Differencer.LEFT) | Differencer.RIGHT; + break; + case Differencer.RIGHT: + kind= (kind &~ Differencer.RIGHT) | Differencer.LEFT; + break; + } + return super.getCompareImage(base, kind); + } + +} diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/PatchWorkbenchAdapter.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/PatchWorkbenchAdapter.java new file mode 100644 index 000000000..d8cc10410 --- /dev/null +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/PatchWorkbenchAdapter.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (c) 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.team.internal.ui.synchronize.patch; + +import org.eclipse.compare.structuremergeviewer.DiffNode; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.graphics.Image; +import org.eclipse.ui.model.IWorkbenchAdapter; + +public class PatchWorkbenchAdapter implements IWorkbenchAdapter { + + public Object[] getChildren(Object o) { + if (o instanceof DiffNode) { + return ((DiffNode) o).getChildren(); + } + return null; + } + + public ImageDescriptor getImageDescriptor(Object object) { + if (object instanceof DiffNode) { + Image image = ((DiffNode) object).getImage(); + return ImageDescriptor.createFromImage(image); + } + return null; + } + + public String getLabel(Object o) { + if (o instanceof DiffNode) { + return ((DiffNode) o).getName(); + } + return null; + } + + public Object getParent(Object o) { + if (o instanceof DiffNode) { + return ((DiffNode) o).getParent(); + } + return null; + } +} diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/PatchWorkbenchContentProvider.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/PatchWorkbenchContentProvider.java new file mode 100644 index 000000000..331381dc3 --- /dev/null +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/PatchWorkbenchContentProvider.java @@ -0,0 +1,104 @@ +/******************************************************************************* + * Copyright (c) 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.team.internal.ui.synchronize.patch; + +import java.util.*; + +import org.eclipse.compare.structuremergeviewer.IDiffElement; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.ui.IMemento; +import org.eclipse.ui.model.BaseWorkbenchContentProvider; +import org.eclipse.ui.navigator.*; + +public class PatchWorkbenchContentProvider extends BaseWorkbenchContentProvider + implements IPipelinedTreeContentProvider { + private boolean isWorkspaceRoot; + + public PatchWorkbenchContentProvider() { + } + + public Object getParent(Object element) { + Object parent = super.getParent(element); + if (isWorkspaceRoot && parent instanceof PatchWorkspace) { + return ((PatchWorkspace) parent).getResource(); + } + return parent; + } + + public void getPipelinedChildren(Object aParent, Set theCurrentChildren) { + // Nothing to do + } + + public void getPipelinedElements(Object anInput, Set theCurrentElements) { + // Replace any model projects with a DiffProject + // TODO: does it ever happen? the provider is use *only* as delegate in + // PatchSyncContentProvider + if (anInput instanceof IWorkspaceRoot) { + List newProjects = new ArrayList(); + for (Iterator iter = theCurrentElements.iterator(); iter.hasNext();) { + Object element = iter.next(); + if (element instanceof IProject) { + IProject project = (IProject) element; + IDiffElement diffProject = PatchModelProvider + .createModelObject(project); + if (diffProject != null) { + iter.remove(); + newProjects.add(diffProject); + } + } + } + theCurrentElements.addAll(newProjects); + } + } + + public Object getPipelinedParent(Object anObject, Object aSuggestedParent) { + return aSuggestedParent; + } + + public PipelinedShapeModification interceptAdd( + PipelinedShapeModification anAddModification) { + // TODO Auto-generated method stub + return null; + } + + public boolean interceptRefresh( + PipelinedViewerUpdate aRefreshSynchronization) { + // No need to intercept the refresh + return false; + } + + public PipelinedShapeModification interceptRemove( + PipelinedShapeModification aRemoveModification) { + // No need to intercept the remove + return aRemoveModification; + } + + public boolean interceptUpdate(PipelinedViewerUpdate anUpdateSynchronization) { + // No need to intercept the update + return false; + } + + public void init(ICommonContentExtensionSite aConfig) { + // TODO Auto-generated method stub + + } + + public void restoreState(IMemento aMemento) { + // TODO Auto-generated method stub + + } + + public void saveState(IMemento aMemento) { + // TODO Auto-generated method stub + + } +} diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/PatchWorkbenchLabelProvider.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/PatchWorkbenchLabelProvider.java new file mode 100644 index 000000000..38f903ee9 --- /dev/null +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/PatchWorkbenchLabelProvider.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.team.internal.ui.synchronize.patch; + +import org.eclipse.compare.structuremergeviewer.DiffNode; +import org.eclipse.ui.IMemento; +import org.eclipse.ui.model.WorkbenchLabelProvider; +import org.eclipse.ui.navigator.ICommonContentExtensionSite; +import org.eclipse.ui.navigator.ICommonLabelProvider; + +public class PatchWorkbenchLabelProvider extends WorkbenchLabelProvider + implements ICommonLabelProvider { + + private ICommonContentExtensionSite extensionSite; + + /* (non-Javadoc) + * @see org.eclipse.ui.navigator.ICommonLabelProvider#init(org.eclipse.ui.navigator.ICommonContentExtensionSite) + */ + public void init(ICommonContentExtensionSite aConfig) { + extensionSite = aConfig; + } + + /* (non-Javadoc) + * @see org.eclipse.ui.navigator.IMementoAware#restoreState(org.eclipse.ui.IMemento) + */ + public void restoreState(IMemento aMemento) { + // Nothing to do + } + + /* (non-Javadoc) + * @see org.eclipse.ui.navigator.IMementoAware#saveState(org.eclipse.ui.IMemento) + */ + public void saveState(IMemento aMemento) { + // Nothing to do + } + + /* (non-Javadoc) + * @see org.eclipse.ui.navigator.IDescriptionProvider#getDescription(java.lang.Object) + */ + public String getDescription(Object anElement) { + if (anElement instanceof DiffNode) { + return ((DiffNode) anElement).getName(); + } + return null; + } + + /** + * Return the extension site for this label provider. + * @return the extension site for this label provider + */ + public ICommonContentExtensionSite getExtensionSite() { + return extensionSite; + } + +} diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/PatchWorkspace.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/PatchWorkspace.java new file mode 100644 index 000000000..11501ad15 --- /dev/null +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/PatchWorkspace.java @@ -0,0 +1,125 @@ +/******************************************************************************* + * Copyright (c) 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.team.internal.ui.synchronize.patch; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.compare.internal.core.patch.*; +import org.eclipse.compare.internal.patch.*; +import org.eclipse.compare.structuremergeviewer.*; +import org.eclipse.core.internal.runtime.AdapterManager; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.runtime.IAdaptable; + +// TODO: extend PatchDiffNode, update navigatorContent triggerPoints when done +public class PatchWorkspace extends DiffNode implements IAdaptable { + + private static PatchWorkspace instance; + private IWorkspaceRoot root; + private WorkspacePatcher patcher; + + private PatchWorkspace(IWorkspaceRoot root, WorkspacePatcher patcher) { + super(null, Differencer.NO_CHANGE); + this.root = root; + this.patcher = patcher; + } + + public static PatchWorkspace getInstance() { + return instance; + } + + // this should be called before any getInstance + // TODO: don't use singleton! + public static Object create(IWorkspaceRoot root, WorkspacePatcher patcher) { + instance = new PatchWorkspace(root, patcher); + return instance; + } + + public WorkspacePatcher getPatcher() { + return patcher; + } + + public IResource getResource() { + return root; + } + + public String getName() { + return "Patch Root Workspace"; //$NON-NLS-1$ + } + + public IDiffContainer getParent() { + return null; + } + + public IDiffElement[] getChildren() { + /* + * Create a complete tree of patch model objects - elements of the + * patch, but return only top-level ones: PatchProjectDiffNode(s) for a + * workspace patch or FileDiffResult(s) otherwise. See + * org.eclipse.compare.internal + * .patch.PatchCompareEditorInput.buildTree() + */ + IDiffElement[] children; + if (getPatcher().isWorkspacePatch()) { + children = processProjects(getPatcher().getDiffProjects()); + } else { + children = processDiffs(getPatcher().getDiffs()); + } + return children; + } + + // see org.eclipse.compare.internal.patch.PatchCompareEditorInput.processDiffs(FilePatch2[]) + private IDiffElement[] processDiffs(FilePatch2[] diffs) { + List result = new ArrayList(); + for (int i = 0; i < diffs.length; i++) { + result.addAll(processDiff(diffs[i], this)); + } + return (IDiffElement[]) result.toArray(new IDiffElement[result.size()]); + } + + // see org.eclipse.compare.internal.patch.PatchCompareEditorInput.processProjects(DiffProject[]) + private IDiffElement[] processProjects(DiffProject[] diffProjects) { + List result = new ArrayList(); + for (int i = 0; i < diffProjects.length; i++) { + PatchProjectDiffNode projectNode = new PatchProjectDiffNode(this, diffProjects[i], getPatcher().getConfiguration()); + result.add(projectNode); + FilePatch2[] diffs = diffProjects[i].getFileDiffs(); + for (int j = 0; j < diffs.length; j++) { + FilePatch2 fileDiff = diffs[j]; + processDiff(fileDiff, projectNode); + } + } + return (IDiffElement[]) result.toArray(new IDiffElement[result.size()]); + } + + // see org.eclipse.compare.internal.patch.PatchCompareEditorInput.processDiff(FilePatch2, DiffNode) + private List/*<IDiffElement>*/ processDiff(FilePatch2 diff, DiffNode parent) { + List result = new ArrayList(); + FileDiffResult diffResult = getPatcher().getDiffResult(diff); + PatchFileDiffNode node = PatchFileDiffNode.createDiffNode(parent, diffResult); + result.add(node); + HunkResult[] hunkResults = diffResult.getHunkResults(); + for (int i = 0; i < hunkResults.length; i++) { + HunkResult hunkResult = hunkResults[i]; + /*HunkDiffNode hunkDiffNode =*/ HunkDiffNode.createDiffNode(node, hunkResult, false, true, false); + // result.add(hunkDiffNode); + } + return result; + } + + // cannot extend PlatformObject (already extends DiffNode) so implement + // IAdaptable + public Object getAdapter(Class adapter) { + return AdapterManager.getDefault().getAdapter(this, adapter); + } +} diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/PatchedFileVariant.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/PatchedFileVariant.java new file mode 100644 index 000000000..50a6d28a7 --- /dev/null +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/PatchedFileVariant.java @@ -0,0 +1,90 @@ +/******************************************************************************* + * Copyright (c) 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.team.internal.ui.synchronize.patch; + +import java.io.InputStream; + +import org.eclipse.compare.internal.core.patch.FileDiffResult; +import org.eclipse.compare.internal.core.patch.FilePatch2; +import org.eclipse.compare.internal.patch.WorkspacePatcher; +import org.eclipse.core.resources.IStorage; +import org.eclipse.core.runtime.*; +import org.eclipse.team.core.TeamException; +import org.eclipse.team.core.variants.IResourceVariant; + +public class PatchedFileVariant implements IResourceVariant { + + private FilePatch2 diff; + private WorkspacePatcher patcher; + + public PatchedFileVariant(WorkspacePatcher patcher, FilePatch2 diff) { + this.diff = diff; + this.patcher = patcher; + } + + public byte[] asBytes() { + // We don't persist the variant between sessions. + return null; + } + + public String getContentIdentifier() { + // TODO: use patch file name (?) + // currently it's displayed as 'Remote File (After Patch)' for the right side :/ + return "(After Patch)"; //$NON-NLS-1$ + } + + public String getName() { + // TODO: is it ever used? + return diff.getPath(patcher.isReversed()).lastSegment() + + "(patched) <IResourceVariant>"; //$NON-NLS-1$ + } + + public IStorage getStorage(IProgressMonitor monitor) throws TeamException { + return new PatchedFileStorage(diff, patcher); + } + + public boolean isContainer() { + return false; + } + + public static class PatchedFileStorage implements IStorage { + private FilePatch2 diff; + private WorkspacePatcher patcher; + + public PatchedFileStorage(FilePatch2 diff, WorkspacePatcher patcher) { + this.diff = diff; + this.patcher = patcher; + } + + public Object getAdapter(Class adapter) { + return null; + } + + public boolean isReadOnly() { + return true; + } + + public String getName() { + // TODO: what is it used for? + return diff.getPath(patcher.isReversed()).lastSegment() + + "(patched) <IStorage>"; //$NON-NLS-1$ + } + + public IPath getFullPath() { + return null; + } + + public InputStream getContents() throws CoreException { + FileDiffResult diffResult = patcher.getDiffResult(diff); + return diffResult.getPatchedContents(); + } + } +} diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/PatchedFileVariantComparator.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/PatchedFileVariantComparator.java new file mode 100644 index 000000000..d88db79f5 --- /dev/null +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/PatchedFileVariantComparator.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright (c) 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.team.internal.ui.synchronize.patch; + +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IStorage; +import org.eclipse.team.core.TeamException; +import org.eclipse.team.core.variants.IResourceVariant; +import org.eclipse.team.core.variants.IResourceVariantComparator; +import org.eclipse.team.internal.ui.TeamUIPlugin; + +public class PatchedFileVariantComparator implements IResourceVariantComparator { + + public boolean compare(IResource local, IResourceVariant remote) { + /* + * Comparing local with base returns true, see + * org.eclipse.team.core.synchronize.SyncInfo.calculateKind() + */ + IStorage s = null; + try { + s = remote.getStorage(null); + } catch (TeamException e) { + TeamUIPlugin.log(e); + } + return local.equals(s); + // return false; + } + + public boolean compare(IResourceVariant base, IResourceVariant remote) { + return false; + } + + public boolean isThreeWay() { + return true; + } +} diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/AbstractSynchronizeLabelProvider.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/AbstractSynchronizeLabelProvider.java index 7d668d17d..680325800 100644 --- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/AbstractSynchronizeLabelProvider.java +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/AbstractSynchronizeLabelProvider.java @@ -119,7 +119,13 @@ public abstract class AbstractSynchronizeLabelProvider implements ILabelProvider return getCompareImage(base, compareKind); } - private Image getCompareImage(Image base, int compareKind) { + /** + * Returns an image showing the specified change kind applied to a given base image. + * + * @nooverride This method is not intended to be re-implemented or extended by clients. + * @noreference This method is not intended to be referenced by clients. + */ + protected Image getCompareImage(Image base, int compareKind) { return getImageManager().getImage(base, compareKind); } |