1 11 package org.eclipse.team.internal.ccvs.ui.actions; 12 13 import java.util.*; 14 15 import org.eclipse.core.internal.resources.mapping.*; 16 import org.eclipse.core.resources.*; 17 import org.eclipse.core.runtime.*; 18 import org.eclipse.osgi.util.NLS; 19 import org.eclipse.swt.widgets.Shell; 20 import org.eclipse.team.core.subscribers.Subscriber; 21 import org.eclipse.team.core.synchronize.FastSyncInfoFilter; 22 import org.eclipse.team.core.synchronize.SyncInfo; 23 import org.eclipse.team.core.synchronize.FastSyncInfoFilter.SyncInfoDirectionFilter; 24 import org.eclipse.team.internal.ccvs.core.CVSProviderPlugin; 25 import org.eclipse.team.internal.ccvs.ui.CVSUIMessages; 26 import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin; 27 import org.eclipse.team.internal.ui.dialogs.*; 28 29 public abstract class UncommittedChangesDialog extends MappingSelectionDialog { 30 31 public static final class UncommittedFilter implements IResourceMappingResourceFilter { 32 public boolean select(IResource resource, 33 ResourceMapping mapping, ResourceTraversal traversal) 34 throws CoreException { 35 SyncInfo info = CVSProviderPlugin.getPlugin().getCVSWorkspaceSubscriber().getSyncInfo(resource); 36 return (info != null && getResourceFilter().select(info)); 37 } 38 } 39 40 public static FastSyncInfoFilter getResourceFilter() { 41 return new SyncInfoDirectionFilter(new int[] { SyncInfo.OUTGOING, SyncInfo.CONFLICTING }); 43 } 44 45 private final ResourceMapping[] allMappings; 46 47 48 public UncommittedChangesDialog(Shell parentShell, String dialogTitle, ResourceMapping[] mappings, IProgressMonitor monitor) { 49 super(parentShell, dialogTitle, getMatchingMappings(mappings, CVSProviderPlugin.getPlugin().getCVSWorkspaceSubscriber(), getResourceFilter(), monitor), new UncommittedFilter()); 50 allMappings = mappings; 51 } 52 53 54 protected String getResourceListMessage(ResourceMapping mapping) { 55 if (mapping == null) { 56 return CVSUIMessages.UncommittedChangesDialog_2; } else { 58 String label = ResourceMappingResourceDisplayArea.getLabel(mapping); 59 if (mapping.getModelObject() instanceof IFile) { 60 return NLS.bind(CVSUIMessages.UncommittedChangesDialog_4, new String [] { label }); } 62 return NLS.bind(CVSUIMessages.UncommittedChangesDialog_3, new String [] { label }); } 64 } 65 66 71 public ResourceMapping[] promptToSelectMappings() { 72 ResourceMapping[] matchingMappings = getMappings(); 73 if (matchingMappings.length > 0) { 74 int code = open(); 75 if (code == OK) { 76 Set result = new HashSet(); 77 result.addAll(Arrays.asList(allMappings)); 78 result.removeAll(Arrays.asList(matchingMappings)); 79 result.addAll(Arrays.asList(getCheckedMappings())); 80 return (ResourceMapping[]) result.toArray(new ResourceMapping[result.size()]); 81 } 82 return new ResourceMapping[0]; 83 } else { 84 return allMappings; 86 } 87 } 88 89 private static ResourceMapping[] getMatchingMappings(ResourceMapping[] mappings, final Subscriber subscriber, final FastSyncInfoFilter resourceFilter, IProgressMonitor monitor) { 90 Set result = new HashSet(); 91 for (int i = 0; i < mappings.length; i++) { 92 ResourceMapping mapping = mappings[i]; 93 if (matchesFilter(mapping, subscriber, resourceFilter, monitor)) { 94 result.add(mapping); 95 } 96 } 97 return (ResourceMapping[]) result.toArray(new ResourceMapping[result.size()]); 98 } 99 100 private static boolean matchesFilter(ResourceMapping mapping, final Subscriber subscriber, final FastSyncInfoFilter resourceFilter, IProgressMonitor monitor) { 101 try { 102 mapping.accept(ResourceMappingContext.LOCAL_CONTEXT, new IResourceVisitor() { 103 public boolean visit(IResource resource) throws CoreException { 104 SyncInfo info = subscriber.getSyncInfo(resource); 105 if (info != null && resourceFilter.select(info)) { 106 throw new CoreException(Status.OK_STATUS); 107 } 108 return true; 109 } 110 }, monitor); 111 } catch (CoreException e) { 112 if (e.getStatus().isOK()) { 113 return true; 114 } 115 CVSUIPlugin.log(e); 116 } 117 return false; 118 } 119 120 121 public ResourceMapping[] getAllMappings() { 122 return allMappings; 123 } 124 125 protected boolean includeCancelButton() { 126 if (super.includeCancelButton()) { 127 return getAllMappings().length > 1; 128 } 129 return false; 130 } 131 132 } 133 | Popular Tags |