1 11 package org.eclipse.team.internal.ui.mapping; 12 13 import org.eclipse.core.commands.ExecutionEvent; 14 import org.eclipse.core.commands.ExecutionException; 15 import org.eclipse.core.resources.IResource; 16 import org.eclipse.core.resources.mapping.ResourceMapping; 17 import org.eclipse.core.runtime.IPath; 18 import org.eclipse.core.runtime.IProgressMonitor; 19 import org.eclipse.jface.dialogs.MessageDialog; 20 import org.eclipse.osgi.util.NLS; 21 import org.eclipse.team.core.diff.*; 22 import org.eclipse.team.core.mapping.*; 23 import org.eclipse.team.internal.ui.*; 24 import org.eclipse.team.internal.ui.synchronize.SynchronizeView; 25 import org.eclipse.team.ui.mapping.*; 26 import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration; 27 import org.eclipse.ui.ide.IDE; 28 29 public class MergeAllActionHandler extends MergeActionHandler implements IDiffChangeListener { 30 31 private MergeAllOperation operation; 32 33 public MergeAllActionHandler(ISynchronizePageConfiguration configuration) { 34 super(configuration); 35 getContext().getDiffTree().addDiffChangeListener(this); 36 } 37 38 41 protected synchronized SynchronizationOperation getOperation() { 42 if (operation == null) { 43 operation = createOperation(); 44 } 45 return operation; 46 } 47 48 protected MergeAllOperation createOperation() { 49 return new MergeAllOperation(getJobName(), getConfiguration(), getMappings(), getContext()); 50 } 51 52 private IMergeContext getContext() { 53 return ((IMergeContext)getConfiguration().getProperty(ITeamContentProviderManager.P_SYNCHRONIZATION_CONTEXT)); 54 } 55 56 private ResourceMapping[] getMappings() { 57 return ((ISynchronizationScope)getConfiguration().getProperty(ITeamContentProviderManager.P_SYNCHRONIZATION_SCOPE)).getMappings(); 58 } 59 60 63 public void diffsChanged(IDiffChangeEvent event, IProgressMonitor monitor) { 64 synchronized (this) { 65 operation = null; 66 } 67 setEnabled(event.getTree().countFor(IThreeWayDiff.INCOMING, IThreeWayDiff.DIRECTION_MASK) > 0 68 || event.getTree().countFor(IThreeWayDiff.CONFLICTING, IThreeWayDiff.DIRECTION_MASK) > 0); 69 } 70 71 74 public void propertyChanged(IDiffTree tree, int property, IPath[] paths) { 75 } 77 78 81 public void dispose() { 82 getContext().getDiffTree().removeDiffChangeListener(this); 83 super.dispose(); 84 } 85 86 public Object execute(ExecutionEvent event) throws ExecutionException { 87 if (saveDirtyEditors() && promptToUpdate()) 88 return super.execute(event); 89 return null; 90 } 91 92 98 public final boolean saveDirtyEditors() { 99 if(needsToSaveDirtyEditors()) { 100 if(!saveAllEditors(getTargetResources(), confirmSaveOfDirtyEditor())) { 101 return false; 102 } 103 } 104 return true; 105 } 106 107 private IResource[] getTargetResources() { 108 return getContext().getDiffTree().getAffectedResources(); 109 } 110 111 120 public final boolean saveAllEditors(IResource[] resources, boolean confirm) { 121 return IDE.saveAllEditors(resources, confirm); 122 } 123 124 130 protected boolean needsToSaveDirtyEditors() { 131 return true; 132 } 133 134 140 protected boolean confirmSaveOfDirtyEditor() { 141 return true; 142 } 143 144 protected String getJobName() { 145 String name = getConfiguration().getParticipant().getName(); 146 return NLS.bind(TeamUIMessages.MergeAllActionHandler_0, Utils.shortenText(SynchronizeView.MAX_NAME_LENGTH, name)); 147 } 148 149 protected boolean promptToUpdate() { 150 final IResourceDiffTree tree = getContext().getDiffTree(); 151 if (tree.isEmpty()) { 152 return false; 153 } 154 final long count = tree.countFor(IThreeWayDiff.INCOMING, IThreeWayDiff.DIRECTION_MASK) + tree.countFor(IThreeWayDiff.CONFLICTING, IThreeWayDiff.DIRECTION_MASK); 155 if (count == 0) 156 return false; 157 final boolean[] result = new boolean[] {true}; 158 TeamUIPlugin.getStandardDisplay().syncExec(new Runnable () { 159 public void run() { 160 String sizeString = Long.toString(count); 161 String message = tree.size() > 1 ? NLS.bind(TeamUIMessages.MergeAllActionHandler_1, new String [] { sizeString }) : 162 NLS.bind(TeamUIMessages.MergeAllActionHandler_2, new String [] { sizeString }); 163 result[0] = MessageDialog.openQuestion(getConfiguration().getSite().getShell(), 164 NLS.bind(TeamUIMessages.MergeAllActionHandler_3, new String [] { sizeString }), message); 165 } 166 }); 167 return result[0]; 168 } 169 } 170 | Popular Tags |