1 11 package org.eclipse.team.internal.ccvs.ui.wizards; 12 13 import java.lang.reflect.InvocationTargetException ; 14 import java.util.ArrayList ; 15 import java.util.HashSet ; 16 import java.util.List ; 17 import java.util.Set ; 18 19 import org.eclipse.core.resources.IResource; 20 import org.eclipse.core.resources.mapping.ResourceMapping; 21 import org.eclipse.core.runtime.IStatus; 22 import org.eclipse.jface.resource.ImageDescriptor; 23 import org.eclipse.jface.wizard.Wizard; 24 import org.eclipse.team.internal.ccvs.core.CVSMergeSubscriber; 25 import org.eclipse.team.internal.ccvs.core.CVSTag; 26 import org.eclipse.team.internal.ccvs.core.client.Command; 27 import org.eclipse.team.internal.ccvs.core.client.Update; 28 import org.eclipse.team.internal.ccvs.ui.*; 29 import org.eclipse.team.internal.ccvs.ui.actions.WorkspaceTraversalAction; 30 import org.eclipse.team.internal.ccvs.ui.mappings.ModelMergeOperation; 31 import org.eclipse.team.internal.ccvs.ui.mappings.ModelMergeParticipant; 32 import org.eclipse.team.internal.ccvs.ui.operations.UpdateOperation; 33 import org.eclipse.team.internal.ccvs.ui.subscriber.MergeSynchronizeParticipant; 34 import org.eclipse.team.internal.ccvs.ui.tags.TagSource; 35 import org.eclipse.team.ui.TeamUI; 36 import org.eclipse.team.ui.synchronize.ISynchronizeParticipant; 37 import org.eclipse.ui.IWorkbenchPart; 38 39 public class MergeWizard extends Wizard { 40 MergeWizardPage page; 41 IResource[] resources; 42 private final IWorkbenchPart part; 43 private final ResourceMapping[] mappings; 44 45 public MergeWizard(IWorkbenchPart part, IResource[] resources, ResourceMapping[] mappings) { 46 this.part = part; 47 this.resources = resources; 48 this.mappings = mappings; 49 } 50 51 public void addPages() { 52 setNeedsProgressMonitor(true); 53 TagSource tagSource = TagSource.create(resources); 54 setWindowTitle(CVSUIMessages.MergeWizard_title); 55 ImageDescriptor mergeImage = CVSUIPlugin.getPlugin().getImageDescriptor(ICVSUIConstants.IMG_WIZBAN_MERGE); 56 page = new MergeWizardPage("mergePage", CVSUIMessages.MergeWizard_0, mergeImage, CVSUIMessages.MergeWizard_1, tagSource); addPage(page); 58 } 59 60 public boolean performFinish() { 61 62 CVSTag startTag = page.getStartTag(); 63 CVSTag endTag = page.getEndTag(); 64 65 if (startTag == null || !page.isPreview()) { 66 UpdateOperation op = new UpdateOperation(getPart(), mappings, getLocalOptions(startTag, endTag), null); 68 try { 69 op.run(); 70 } catch (InvocationTargetException e) { 71 CVSUIPlugin.openError(getShell(), null, null, e); 72 } catch (InterruptedException e) { 73 } 75 } else { 76 if (isShowModelSync()) { 77 ModelMergeParticipant participant = ModelMergeParticipant.getMatchingParticipant(mappings, startTag, endTag); 78 if(participant == null) { 79 CVSMergeSubscriber s = new CVSMergeSubscriber(getProjects(resources), startTag, endTag); 80 try { 81 new ModelMergeOperation(getPart(), mappings, s, page.isOnlyPreviewConflicts()).run(); 82 } catch (InvocationTargetException e) { 83 CVSUIPlugin.log(IStatus.ERROR, "Internal error", e.getTargetException()); } catch (InterruptedException e) { 85 } 87 } else { 88 participant.refresh(null, mappings); 89 } 90 } else { 91 try { 93 resources = getAllResources(startTag, endTag); 94 } catch (InvocationTargetException e) { 95 CVSUIPlugin.log(IStatus.ERROR, "An error occurred while detemrining if extra resources should be included in the merge", e.getTargetException()); } 98 MergeSynchronizeParticipant participant = MergeSynchronizeParticipant.getMatchingParticipant(resources, startTag, endTag); 99 if(participant == null) { 100 CVSMergeSubscriber s = new CVSMergeSubscriber(resources, startTag, endTag); 101 participant = new MergeSynchronizeParticipant(s); 102 TeamUI.getSynchronizeManager().addSynchronizeParticipants(new ISynchronizeParticipant[] {participant}); 103 } 104 participant.refresh(resources, null, null, null); 105 106 } 107 } 108 return true; 109 } 110 111 private IResource[] getAllResources(CVSTag startTag, CVSTag endTag) throws InvocationTargetException { 112 if (!WorkspaceTraversalAction.isLogicalModel(mappings)) 114 return resources; 115 CVSMergeSubscriber s = new CVSMergeSubscriber(WorkspaceTraversalAction.getProjects(resources), startTag, endTag); 116 IResource[] allResources = WorkspaceTraversalAction.getResourcesToCompare(mappings, s); 117 s.cancel(); 118 return allResources; 119 } 120 121 public static boolean isShowModelSync() { 122 return CVSUIPlugin.getPlugin().getPreferenceStore().getBoolean(ICVSUIConstants.PREF_ENABLE_MODEL_SYNC); 123 } 124 125 private IResource[] getProjects(IResource[] resources) { 126 Set projects = new HashSet (); 127 for (int i = 0; i < resources.length; i++) { 128 IResource resource = resources[i]; 129 projects.add(resource.getProject()); 130 } 131 return (IResource[]) projects.toArray(new IResource[projects.size()]); 132 } 133 134 private Command.LocalOption[] getLocalOptions(CVSTag startTag, CVSTag endTag) { 135 List options = new ArrayList (); 136 if (startTag != null) { 137 options.add(Command.makeArgumentOption(Update.JOIN, startTag.getName())); 138 } 139 options.add(Command.makeArgumentOption(Update.JOIN, endTag.getName())); 140 return (Command.LocalOption[]) options.toArray(new Command.LocalOption[options.size()]); 141 } 142 143 private IWorkbenchPart getPart() { 144 return part; 145 } 146 } 147 | Popular Tags |