1 11 package org.eclipse.team.internal.ui.mapping; 12 13 import java.lang.reflect.InvocationTargetException ; 14 import java.util.Collections ; 15 16 import org.eclipse.core.commands.*; 17 import org.eclipse.core.runtime.CoreException; 18 import org.eclipse.core.runtime.IProgressMonitor; 19 import org.eclipse.jface.operation.IRunnableWithProgress; 20 import org.eclipse.jface.viewers.IStructuredSelection; 21 import org.eclipse.swt.widgets.Event; 22 import org.eclipse.team.core.diff.*; 23 import org.eclipse.team.internal.ui.Utils; 24 import org.eclipse.team.ui.mapping.SaveableComparison; 25 import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration; 26 import org.eclipse.team.ui.synchronize.ModelParticipantAction; 27 import org.eclipse.ui.PlatformUI; 28 29 32 public class MergeIncomingChangesAction extends ModelParticipantAction implements IHandlerListener { 33 34 IHandler handler; 35 36 public MergeIncomingChangesAction(ISynchronizePageConfiguration configuration) { 37 super(null, configuration); 38 handler = (IHandler)configuration.getProperty("org.eclipse.team.ui.mergeAll"); if (handler == null) 41 handler = new MergeAllActionHandler(configuration); 42 handler.addHandlerListener(this); 43 } 44 45 public void runWithEvent(Event event) { 46 if (handler == null || !handler.isEnabled()) 47 return; 48 try { 49 handleTargetSaveableChange(); 50 } catch (InvocationTargetException e) { 51 handle(e); 52 return; 53 } catch (InterruptedException e) { 54 return; 56 } 57 try { 58 handler.execute(new ExecutionEvent(null, Collections.EMPTY_MAP, event, null)); 59 } catch (ExecutionException e) { 60 handle(e); 61 } 62 } 63 64 private void handle(Throwable throwable) { 65 if (throwable instanceof ExecutionException) { 66 ExecutionException ee = (ExecutionException) throwable; 67 if (ee.getCause() != null) { 68 throwable = ee.getCause(); 69 } 70 } 71 Utils.handle(throwable); 72 } 73 74 77 protected boolean isEnabledForSelection(IStructuredSelection selection) { 78 return handler.isEnabled(); 79 } 80 81 84 protected FastDiffFilter getDiffFilter() { 85 return new FastDiffFilter() { 86 public boolean select(IDiff node) { 87 if (node instanceof IThreeWayDiff) { 88 IThreeWayDiff twd = (IThreeWayDiff) node; 89 if (twd.getDirection() == IThreeWayDiff.CONFLICTING || twd.getDirection() == IThreeWayDiff.INCOMING) { 90 return true; 91 } 92 } 93 return false; 94 } 95 }; 96 } 97 98 protected void handleTargetSaveableChange() throws InvocationTargetException , InterruptedException { 99 final SaveableComparison currentBuffer = getActiveSaveable(); 100 if (currentBuffer != null && currentBuffer.isDirty()) { 101 PlatformUI.getWorkbench().getProgressService().run(true, true, new IRunnableWithProgress() { 102 public void run(IProgressMonitor monitor) throws InvocationTargetException , 103 InterruptedException { 104 try { 105 handleTargetSaveableChange(getConfiguration().getSite().getShell(), null, currentBuffer, true, monitor); 106 } catch (CoreException e) { 107 throw new InvocationTargetException (e); 108 } 109 } 110 }); 111 } 112 setActiveSaveable(null); 113 } 114 115 public void dispose() { 116 handler.dispose(); 117 } 118 119 122 public void handlerChanged(HandlerEvent handlerEvent) { 123 setEnabled(handler.isEnabled()); 124 } 125 126 } 127 | Popular Tags |