Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2000, 2007 IBM Corporation and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html Contributors: IBM Corporation - initial API and implementation /
 
 package org.eclipse.team.internal.ccvs.ui.repo;
 
 import java.util.List;
 
 import  org.eclipse.swt.widgets.Shell;
Wizard for refreshing the tags for a CVS repository location
 
 public class RefreshRemoteProjectWizard extends Wizard {
     
     // The initial size of this wizard.
     private final static int INITIAL_WIDTH = 300;
     private final static int INITIAL_HEIGHT = 350;
     
 	
 	public static boolean execute(Shell shellfinal ICVSRepositoryLocation root) {
 		final ICVSRemoteResource[][] rootFolders = new ICVSRemoteResource[1][0];
 		rootFolders[0] = null;
 		try {
 			new ProgressMonitorDialog(shell).run(truetruenew IRunnableWithProgress() {
 				public void run(IProgressMonitor monitorthrows InvocationTargetExceptionInterruptedException {
 					try {
 						rootFolders[0] = CVSUIPlugin.getPlugin().getRepositoryManager().getFoldersForTag(root.monitor);
 					} catch (CVSException e) {
 						throw new InvocationTargetException(e);
 					}
 				}
 			});
 		} catch (InvocationTargetException e) {
 			CVSUIPlugin.openError(shellnullnulle);
 			return false;
 		} catch (InterruptedException e) {
 			return false;
 		}
 		RefreshRemoteProjectWizard wizard = new RefreshRemoteProjectWizard(rootrootFolders[0]);
 		WizardDialog dialog = new WizardDialog(shellwizard);
This is the only place where a size hint > 0 is required. The wizard page should in general have hints of 0 (and grab excessive space).
 
 		return (dialog.open() == .);
 	}
 	
 		this. = root;
 		this. = rootFolders;
 		IDialogSettings workbenchSettings = CVSUIPlugin.getPlugin().getDialogSettings();
 		this. = workbenchSettings.getSection("RefreshRemoteProjectWizard");//$NON-NLS-1$
 		if ( == null) {
 			this. = workbenchSettings.addNewSection("RefreshRemoteProjectWizard");//$NON-NLS-1$
 		}
 	}

See also:
org.eclipse.jface.wizard.IWizard.addPages()
 
 	public void addPages() {
 			"ProjectSelectionPage"//$NON-NLS-1$
 			substImage,
 	}

See also:
org.eclipse.jface.wizard.Wizard.performFinish()
	public boolean performFinish() {
		try {
			getContainer().run(truetruenew IRunnableWithProgress() {
					final RepositoryManager manager = CVSUIPlugin.getPlugin().getRepositoryManager();
					// Run in the manager to avoid multiple repo view updates
					manager.run(new IRunnableWithProgress() {
						    monitor.beginTask(null, 100);
						    ICVSRemoteResource[] failedFolders = internalRefresh(managerselectedFoldersfalse /* recurse */, Policy.subMonitorFor(monitor, 80));
						    if (failedFolders.length > 0) {
						        // Go deep any any failed folders.
						        if (promptForDeepRefresh(failedFolders))
						            internalRefresh(managerfailedFolderstrue /* recurse */, Policy.subMonitorFor(monitor, 20));
						    }
						    monitor.done();
						}
					}, monitor);
				}
			});
			return true;
catch (InvocationTargetException e) {
			CVSUIPlugin.openError(getShell(), nullnull ,e);
catch (InterruptedException e) {
		}
		return false;
	}
	/*
	 * Refresh the tags of the given resources and return those for which no tags were found.
	 */
    private ICVSRemoteResource[] internalRefresh(final RepositoryManager managerfinal ICVSRemoteResource[] selectedFoldersfinal boolean recurseIProgressMonitor monitorthrows InvocationTargetException {
        List failedFolders = new ArrayList();
        monitor.beginTask(null, 100 * selectedFolders.length);
        	for (int i = 0; i < selectedFolders.lengthi++) {
        		try {
					ICVSRemoteResource resource = selectedFolders[i];
					if (resource instanceof ICVSFolder) {
						CVSTag[] tags = manager.refreshDefinedTags((ICVSFolder)resourcerecursetrue /* notify */, Policy.subMonitorFor(monitor, 100));
						if (tags.length == 0) {
						    failedFolders.add(resource);
						}
					}
catch (TeamException e) {
					CVSUIPlugin.log(., NLS.bind("An error occurred while fetching the tags for {0}"selectedFolders[i].getName()), e); //$NON-NLS-1$
				}
        	}
        	return (ICVSRemoteResource[]) failedFolders.toArray(new ICVSRemoteResource[failedFolders.size()]);
    }
    private boolean promptForDeepRefresh(final ICVSRemoteResource[] folders) {
        final boolean[] prompt = new boolean[] { false };
        getShell().getDisplay().syncExec(new Runnable() {
            public void run() {
		        MessageDialog dialog = new MessageDialog(getShell(), .null
		                getNoTagsMessage(folders),
		                .,
		                new String[] {
		            		.
		        		}, 1);
		        int code = dialog.open();
		        if (code == 0) {
		            prompt[0] = true;
		        }
            }
        });
        return prompt[0];
    }
    private String getNoTagsMessage(ICVSRemoteResource[] folders) {
        if (folders.length == 1) {
            return NLS.bind(.new String[] { folders[0].getRepositoryRelativePath() }); 
        }
        return NLS.bind(.new String[] { Integer.toString(folders.length) }); 
    }
New to GrepCode? Check out our FAQ X