1 11 package org.eclipse.team.internal.ui.mapping; 12 13 import java.lang.reflect.InvocationTargetException ; 14 import java.util.*; 15 16 import org.eclipse.core.resources.IResource; 17 import org.eclipse.core.resources.mapping.ResourceTraversal; 18 import org.eclipse.core.runtime.CoreException; 19 import org.eclipse.core.runtime.IProgressMonitor; 20 import org.eclipse.jface.dialogs.MessageDialogWithToggle; 21 import org.eclipse.jface.operation.IRunnableWithProgress; 22 import org.eclipse.jface.preference.IPreferenceStore; 23 import org.eclipse.jface.viewers.IStructuredSelection; 24 import org.eclipse.jface.window.Window; 25 import org.eclipse.team.core.diff.IDiff; 26 import org.eclipse.team.core.mapping.provider.ResourceDiffTree; 27 import org.eclipse.team.internal.ui.*; 28 import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration; 29 import org.eclipse.ui.PlatformUI; 30 31 34 public class RemoveFromViewAction extends ResourceModelParticipantAction { 35 36 public RemoveFromViewAction(ISynchronizePageConfiguration configuration) { 37 super(null, configuration); 38 Utils.initAction(this, "action.removeFromView."); } 40 41 44 public void run() { 45 if (confirmRemove()) { 46 try { 47 PlatformUI.getWorkbench().getProgressService().run(true, true, new IRunnableWithProgress() { 48 public void run(IProgressMonitor monitor) throws InvocationTargetException , 49 InterruptedException { 50 try { 51 performRemove(monitor); 52 } catch (CoreException e) { 53 throw new InvocationTargetException (e); 54 } 55 } 56 }); 57 } catch (InvocationTargetException e) { 58 Utils.handle(e); 59 } catch (InterruptedException e) { 60 } 62 } 63 } 64 65 private void performRemove(IProgressMonitor monitor) throws CoreException { 66 IResource[] resources = getVisibleResources(monitor); 67 if (resources.length == 0) 68 return; 69 ResourceDiffTree tree = (ResourceDiffTree)getSynchronizationContext().getDiffTree(); 70 try { 71 tree.beginInput(); 72 for (int i = 0; i < resources.length; i++) { 73 IResource resource = resources[i]; 74 tree.remove(resource); 75 } 76 } finally { 77 tree.endInput(monitor); 78 } 79 } 80 81 private IResource[] getVisibleResources(IProgressMonitor monitor) throws CoreException { 82 ResourceTraversal[] traversals = getResourceTraversals(getStructuredSelection(), monitor); 83 IDiff[] diffs = getSynchronizationContext().getDiffTree().getDiffs(traversals); 84 List result = new ArrayList(); 85 for (int i = 0; i < diffs.length; i++) { 86 IDiff diff = diffs[i]; 87 if (isVisible(diff)) { 88 result.add(ResourceDiffTree.getResourceFor(diff)); 89 } 90 } 91 return (IResource[]) result.toArray(new IResource[result.size()]); 92 } 93 94 private boolean confirmRemove() { 95 IPreferenceStore store = TeamUIPlugin.getPlugin().getPreferenceStore(); 96 if (store.getBoolean(IPreferenceIds.SYNCVIEW_REMOVE_FROM_VIEW_NO_PROMPT)) { 97 return true; 98 } else { 99 MessageDialogWithToggle dialog = MessageDialogWithToggle.openOkCancelConfirm( 100 getConfiguration().getSite().getShell(), 101 TeamUIMessages.RemoveFromView_warningTitle, 102 TeamUIMessages.RemoveFromView_warningMessage, 103 TeamUIMessages.RemoveFromView_warningDontShow, 104 false, 105 null, 106 null); 107 store.setValue(IPreferenceIds.SYNCVIEW_REMOVE_FROM_VIEW_NO_PROMPT, dialog.getToggleState()); 108 return dialog.getReturnCode() == Window.OK; 109 } 110 } 111 112 115 protected boolean isEnabledForSelection(IStructuredSelection selection) { 116 if (selection.isEmpty()) 118 return false; 119 for (Iterator iter = selection.iterator(); iter.hasNext();) { 120 Object element = iter.next(); 121 if (Utils.getResource(element) == null) { 122 return false; 123 } 124 } 125 return true; 126 } 127 } 128 | Popular Tags |