1 11 package org.eclipse.ltk.internal.ui.refactoring.actions; 12 13 import java.lang.reflect.InvocationTargetException ; 14 15 import org.eclipse.team.core.diff.IThreeWayDiff; 16 import org.eclipse.team.core.mapping.IMergeContext; 17 import org.eclipse.team.core.mapping.ISynchronizationContext; 18 19 import org.eclipse.core.runtime.Assert; 20 import org.eclipse.core.runtime.IProgressMonitor; 21 import org.eclipse.core.runtime.SubProgressMonitor; 22 23 import org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy; 24 25 import org.eclipse.ltk.internal.core.refactoring.history.RefactoringHistoryService; 26 import org.eclipse.ltk.internal.ui.refactoring.RefactoringUIPlugin; 27 import org.eclipse.ltk.internal.ui.refactoring.model.ModelMessages; 28 import org.eclipse.ltk.internal.ui.refactoring.model.RefactoringDescriptorSynchronizationProxy; 29 30 import org.eclipse.jface.action.Action; 31 import org.eclipse.jface.operation.IRunnableWithProgress; 32 33 import org.eclipse.ui.PlatformUI; 34 35 40 public final class RejectRefactoringsAction extends Action { 41 42 43 private final ISynchronizationContext fContext; 44 45 46 private RefactoringDescriptorProxy[] fProxies= null; 47 48 54 public RejectRefactoringsAction(final ISynchronizationContext context) { 55 Assert.isNotNull(context); 56 fContext= context; 57 setText(ModelMessages.RejectRefactoringsAction_title); 58 setToolTipText(ModelMessages.RejectRefactoringsAction_tool_tip); 59 setDescription(ModelMessages.RejectRefactoringsAction_description); 60 } 61 62 65 public boolean isEnabled() { 66 if (fProxies != null && fProxies.length > 0 && fContext instanceof IMergeContext) { 67 for (int index= 0; index < fProxies.length; index++) { 68 if (fProxies[index] instanceof RefactoringDescriptorSynchronizationProxy) { 69 final RefactoringDescriptorSynchronizationProxy proxy= (RefactoringDescriptorSynchronizationProxy) fProxies[index]; 70 if (proxy.getDirection() == IThreeWayDiff.INCOMING) 71 return true; 72 } 73 } 74 } 75 return false; 76 } 77 78 81 public void run() { 82 if (fProxies != null) { 83 try { 84 PlatformUI.getWorkbench().getProgressService().run(true, true, new IRunnableWithProgress() { 85 86 public final void run(final IProgressMonitor monitor) throws InvocationTargetException , InterruptedException { 87 try { 88 monitor.beginTask("", fProxies.length + 100); final RefactoringHistoryService service= RefactoringHistoryService.getInstance(); 90 for (int index= 0; index < fProxies.length; index++) 91 service.addRefactoringDescriptor(fProxies[index], new SubProgressMonitor(monitor, 1)); 92 } finally { 93 monitor.done(); 94 } 95 } 96 }); 97 } catch (InvocationTargetException exception) { 98 RefactoringUIPlugin.log(exception); 99 } catch (InterruptedException exception) { 100 } 102 } 103 } 104 105 111 public void setRefactoringDescriptors(final RefactoringDescriptorProxy[] proxies) { 112 Assert.isNotNull(proxies); 113 fProxies= proxies; 114 } 115 } | Popular Tags |