1 11 package org.eclipse.team.internal.ccvs.ui.repo; 12 13 import java.lang.reflect.InvocationTargetException ; 14 import java.util.ArrayList ; 15 import java.util.List ; 16 17 import org.eclipse.core.runtime.IProgressMonitor; 18 import org.eclipse.core.runtime.IStatus; 19 import org.eclipse.jface.dialogs.*; 20 import org.eclipse.jface.operation.IRunnableWithProgress; 21 import org.eclipse.jface.resource.ImageDescriptor; 22 import org.eclipse.jface.window.Window; 23 import org.eclipse.jface.wizard.Wizard; 24 import org.eclipse.jface.wizard.WizardDialog; 25 import org.eclipse.osgi.util.NLS; 26 import org.eclipse.swt.widgets.Shell; 27 import org.eclipse.team.core.TeamException; 28 import org.eclipse.team.internal.ccvs.core.*; 29 import org.eclipse.team.internal.ccvs.ui.*; 30 import org.eclipse.team.internal.ccvs.ui.Policy; 31 32 35 public class RefreshRemoteProjectWizard extends Wizard { 36 37 private final static int INITIAL_WIDTH = 300; 39 private final static int INITIAL_HEIGHT = 350; 40 41 private ICVSRepositoryLocation root; 42 private ICVSRemoteResource[] rootFolders; 43 private RefreshRemoteProjectSelectionPage projectSelectionPage; 44 private IDialogSettings settings; 45 46 public static boolean execute(Shell shell, final ICVSRepositoryLocation root) { 47 final ICVSRemoteResource[][] rootFolders = new ICVSRemoteResource[1][0]; 48 rootFolders[0] = null; 49 try { 50 new ProgressMonitorDialog(shell).run(true, true, new IRunnableWithProgress() { 51 public void run(IProgressMonitor monitor) throws InvocationTargetException , InterruptedException { 52 try { 53 rootFolders[0] = CVSUIPlugin.getPlugin().getRepositoryManager().getFoldersForTag(root, CVSTag.DEFAULT, monitor); 54 } catch (CVSException e) { 55 throw new InvocationTargetException (e); 56 } 57 } 58 }); 59 } catch (InvocationTargetException e) { 60 CVSUIPlugin.openError(shell, null, null, e); 61 return false; 62 } catch (InterruptedException e) { 63 return false; 64 } 65 RefreshRemoteProjectWizard wizard = new RefreshRemoteProjectWizard(root, rootFolders[0]); 66 WizardDialog dialog = new WizardDialog(shell, wizard); 67 71 dialog.setMinimumPageSize(INITIAL_WIDTH, INITIAL_HEIGHT); 72 return (dialog.open() == Window.OK); 73 } 74 75 public RefreshRemoteProjectWizard(ICVSRepositoryLocation root, ICVSRemoteResource[] rootFolders) { 76 this.root = root; 77 this.rootFolders = rootFolders; 78 IDialogSettings workbenchSettings = CVSUIPlugin.getPlugin().getDialogSettings(); 79 this.settings = workbenchSettings.getSection("RefreshRemoteProjectWizard"); if (settings == null) { 81 this.settings = workbenchSettings.addNewSection("RefreshRemoteProjectWizard"); } 83 setWindowTitle(CVSUIMessages.RefreshRemoteProjectWizard_title); 84 } 85 86 89 public void addPages() { 90 setNeedsProgressMonitor(true); 91 ImageDescriptor substImage = CVSUIPlugin.getPlugin().getImageDescriptor(ICVSUIConstants.IMG_WIZBAN_NEW_LOCATION); 92 projectSelectionPage = new RefreshRemoteProjectSelectionPage( 93 "ProjectSelectionPage", CVSUIMessages.RefreshRemoteProjectSelectionPage_pageTitle, 95 substImage, 96 CVSUIMessages.RefreshRemoteProjectSelectionPage_pageDescription, 97 settings, root, rootFolders); 98 addPage(projectSelectionPage); 99 } 100 101 104 public boolean performFinish() { 105 final ICVSRemoteResource[] selectedFolders = projectSelectionPage.getSelectedRemoteProject(); 106 try { 107 getContainer().run(true, true, new IRunnableWithProgress() { 108 public void run(IProgressMonitor monitor) throws InvocationTargetException , InterruptedException { 109 final RepositoryManager manager = CVSUIPlugin.getPlugin().getRepositoryManager(); 110 manager.run(new IRunnableWithProgress() { 112 public void run(IProgressMonitor monitor) throws InvocationTargetException ,InterruptedException { 113 monitor.beginTask(null, 100); 114 ICVSRemoteResource[] failedFolders = internalRefresh(manager, selectedFolders, false , Policy.subMonitorFor(monitor, 80)); 115 if (failedFolders.length > 0) { 116 if (promptForDeepRefresh(failedFolders)) 118 internalRefresh(manager, failedFolders, true , Policy.subMonitorFor(monitor, 20)); 119 } 120 monitor.done(); 121 } 122 }, monitor); 123 } 124 }); 125 return true; 126 } catch (InvocationTargetException e) { 127 CVSUIPlugin.openError(getShell(), null, null ,e); 128 } catch (InterruptedException e) { 129 } 130 return false; 131 } 132 133 136 private ICVSRemoteResource[] internalRefresh(final RepositoryManager manager, final ICVSRemoteResource[] selectedFolders, final boolean recurse, IProgressMonitor monitor) throws InvocationTargetException { 137 List failedFolders = new ArrayList (); 138 monitor.beginTask(null, 100 * selectedFolders.length); 139 for (int i = 0; i < selectedFolders.length; i++) { 140 try { 141 ICVSRemoteResource resource = selectedFolders[i]; 142 if (resource instanceof ICVSFolder) { 143 CVSTag[] tags = manager.refreshDefinedTags((ICVSFolder)resource, recurse, true , Policy.subMonitorFor(monitor, 100)); 144 if (tags.length == 0) { 145 failedFolders.add(resource); 146 } 147 } 148 } catch (TeamException e) { 149 CVSUIPlugin.log(IStatus.ERROR, NLS.bind("An error occurred while fetching the tags for {0}", selectedFolders[i].getName()), e); } 151 } 152 return (ICVSRemoteResource[]) failedFolders.toArray(new ICVSRemoteResource[failedFolders.size()]); 153 } 154 155 private boolean promptForDeepRefresh(final ICVSRemoteResource[] folders) { 156 final boolean[] prompt = new boolean[] { false }; 157 getShell().getDisplay().syncExec(new Runnable () { 158 public void run() { 159 MessageDialog dialog = new MessageDialog(getShell(), CVSUIMessages.RefreshRemoteProjectWizard_0, null, 160 getNoTagsMessage(folders), 161 MessageDialog.INFORMATION, 162 new String [] { 163 CVSUIMessages.RefreshRemoteProjectWizard_1, 164 CVSUIMessages.RefreshRemoteProjectWizard_2 165 }, 1); 166 int code = dialog.open(); 167 if (code == 0) { 168 prompt[0] = true; 169 } 170 171 } 172 }); 173 return prompt[0]; 174 } 175 176 private String getNoTagsMessage(ICVSRemoteResource[] folders) { 177 if (folders.length == 1) { 178 return NLS.bind(CVSUIMessages.RefreshRemoteProjectWizard_3, new String [] { folders[0].getRepositoryRelativePath() }); 179 } 180 return NLS.bind(CVSUIMessages.RefreshRemoteProjectWizard_4, new String [] { Integer.toString(folders.length) }); 181 } 182 } 183 | Popular Tags |