Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2000, 2009 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 Philippe Ombredanne - bug 84808 /
 
 package org.eclipse.team.internal.ccvs.ui.wizards;
 
 import java.io.File;
 import java.util.*;
 import java.util.List;
 
 import  org.eclipse.swt.SWT;
 import  org.eclipse.swt.events.*;
 import  org.eclipse.swt.layout.GridData;
 import  org.eclipse.swt.widgets.*;

Author(s):
Administrator To change the template for this generated type comment go to Window>Preferences>Java>Code Generation>Code and Comments
 
 public class CheckoutAsLocationSelectionPage extends CVSWizardPage {
 
 	public static final String NAME = "CheckoutAsLocationSelectionPage"//$NON-NLS-1$
 	
 	private Button browseButton;
 	private Combo locationPathField;
 	private Label locationLabel;
 	private boolean useDefaults = true;
 	private String targetLocation;
 	
 	// constants
 	private static final int SIZING_TEXT_FIELD_WIDTH = 250;
     private static final int COMBO_HISTORY_LENGTH = 5;
 	
     // store id constants
     private static final String STORE_PREVIOUS_LOCATIONS =
         "CheckoutAsLocationSelectionPage.STORE_PREVIOUS_LOCATIONS";//$NON-NLS-1$
     

Parameters:
pageName
title
titleImage
description
 
 	public CheckoutAsLocationSelectionPage(ImageDescriptor titleImageICVSRemoteFolder[] remoteFolders) {
 		this. = remoteFolders;
 	}

Returns:
 
 	private boolean isSingleFolder() {
 		return . == 1;
 	}

Parameters:
string
 
 	public void setProject(IProject project) {
 		 = project;
 	}

Parameters:
string
 
 	public void setProjectName(String string) {
 		if (string == null || string.equals(".")) return//$NON-NLS-1$
 		if ( != null && .getName().equals(string)) return;
 		setProject(ResourcesPlugin.getWorkspace().getRoot().getProject(string));
 	}
 	
 	private IProject getSingleProject() {
 		if ( == null) {
 		}
 		return ;
	}
	/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
	 */
	public void createControl(Composite parent) {
		Composite compositecreateComposite(parent, 1, false);
		setControl(composite);
		// required in order to use setButtonLayoutData
		final Button useDefaultsButton =
			new Button(composite, SWT.CHECK | SWT.RIGHT);
		useDefaultsButton.setSelection(this.);
        initializeValues();
		SelectionListener listener = new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				 = useDefaultsButton.getSelection();
			}
		};
		useDefaultsButton.addSelectionListener(listener);
        Dialog.applyDialogFont(parent);
	}

Creates the project location specification controls.

Parameters:
projectGroup the parent composite
enabled - sets the initial enabled state of the widgets
Returns:
the parent of the widgets created
	private Composite createUserSpecifiedProjectLocationGroup(Composite parentboolean enabled) {
		// This group needs 3 columns
		Composite projectGroup = createComposite(parent, 3, true);
		// location label
		 = new Label(projectGroup, SWT.NONE);
		if (isSingleFolder()) {
else {
		}
		.setEnabled(enabled);
		// project location entry field
		 = new Combo(projectGroup, SWT.DROP_DOWN);
		GridData data = new GridData(GridData.FILL_HORIZONTAL);
		data.widthHint = ;
		.setLayoutData(data);
		.setEnabled(enabled);
		// browse button
		this. = new Button(projectGroup, SWT.PUSH);
		this..addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent event) {
			}
		});
		this..setEnabled(enabled);
		// Set the initial value first before listener
		// to avoid handling an event during the creation.
		.addModifyListener(new ModifyListener() {
			public void modifyText(ModifyEvent e) {
			}
		});
		return projectGroup;
	}

    
Initializes states of the controls.
    private void initializeValues() {
        // Set remembered values
        IDialogSettings settings = getDialogSettings();
        if (settings != null) {
            String[] previouseLocations = settings.getArray();
            if (previouseLocations != null) {
                for (int i = 0; i < previouseLocations.lengthi++) {
                    if(isSingleFolder())
                        .add(new Path(previouseLocations[i]).append(getSingleProject().getName()).toOSString());
                    else
                        .add(previouseLocations[i]);
                }
            }
        }
    }
    
    
Saves the widget values
    private void saveWidgetValues() {
        // Update history
        IDialogSettings settings = getDialogSettings();
        if (settings != null) {
            String[] previouseLocations = settings.getArray();
            if (previouseLocations == nullpreviouseLocations = new String[0];
            if(isSingleFolder())
                previouseLocations = addToHistory(previouseLocationsnew Path(.getText()).removeLastSegments(1).toOSString());
            else
                previouseLocations = addToHistory(previouseLocations.getText());
            settings.put(previouseLocations);
        }
    }

    
Adds an entry to a history, while taking care of duplicate history items and excessively long histories. The assumption is made that all histories should be of length CheckoutAsLocationSelectionPage.COMBO_HISTORY_LENGTH.

Parameters:
history the current history
newEntry the entry to add to the history
Returns:
the history with the new entry appended
    private String[] addToHistory(String[] historyString newEntry) {
        ArrayList l = new ArrayList(Arrays.asList(history));
        addToHistory(lnewEntry);
        String[] r = new String[l.size()];
        l.toArray(r);
        return r;
    }
    
    
Adds an entry to a history, while taking care of duplicate history items and excessively long histories. The assumption is made that all histories should be of length CheckoutAsLocationSelectionPage.COMBO_HISTORY_LENGTH.

Parameters:
history the current history
newEntry the entry to add to the history
    private void addToHistory(List historyString newEntry) {
        history.remove(newEntry);
        history.add(0,newEntry);
    
        // since only one new item was added, we can be over the limit
        // by at most one item
        if (history.size() > )
            history.remove();
    }
    
Check if the entry in the widget location is valid. If it is valid return null. Otherwise return a string that indicates the problem.
		if () {
			return null;
else {
			if (.equals("")) {//$NON-NLS-1$
			}
			else{
				IPath path = new Path("");//$NON-NLS-1$
				}
			}
			if (isSingleFolder()) {
				IStatus locationStatus =
				if (!locationStatus.isOK())
					return locationStatus.getMessage();
else {
				for (int i = 0; i < .i++) {
					IStatus locationStatus = ResourcesPlugin.getWorkspace().validateProjectLocation(
						ResourcesPlugin.getWorkspace().getRoot().getProject(projectName),
						new Path().append(projectName));
					if (!locationStatus.isOK())
						return locationStatus.getMessage();
				}
			}
			return null;
		}
	}

Set the location to the default location if we are set to useDefaults.
	private void setLocationForSelection(boolean changed) {
		if () {
			IPath defaultPath = null;
			if (isSingleFolder()) {
				IProject singleProject = getSingleProject();
				if (singleProject != null) {
					try {
						defaultPath = singleProject.getDescription().getLocation();
catch (CoreException e) {
						// ignore
					}
					if (defaultPath == null) {
						defaultPath = Platform.getLocation().append(singleProject.getName());
					}
				}
else {
				defaultPath = Platform.getLocation();
			}
			if (defaultPath != null) {
				.setText(defaultPath.toOSString());
			}
else if (changed) {
			IPath location = null;
			IProject project = getSingleProject();
			if (project != null) {
				try {
					location = project.getDescription().getLocation();
catch (CoreException e) {
					// ignore the exception
				}
			}
			if (location == null) {
				.setText(""); //$NON-NLS-1$
else {
				if (isSingleFolder()) {
					 = location.toOSString();
else {
				}
			}
		}
	}

Open an appropriate directory browser
		DirectoryDialog dialog = new DirectoryDialog(.getShell());
		if (isSingleFolder()) {
else {
		}
		String dirName = .getText();
		if (!dirName.equals("")) {//$NON-NLS-1$
			File path = new File(dirName);
			if (path.exists())
				dialog.setFilterPath(dirName);
		}
		String selectedDirectory = dialog.open();
		if (selectedDirectory != null) {
			if (isSingleFolder()) {
				.setText(new Path(selectedDirectory).append(getSingleProject().getName()).toOSString());
else {
				.setText(new Path(selectedDirectory).toOSString());
			}
		}
	}

Return the custom location for a single project. In this case, the specified location is used as the location of the project.

Parameters:
project
Returns:
            saveWidgetValues();
            return ;
        }
		return null;
	}

Returns:
	private boolean isCustomLocationSpecified() {
		return !;
	}
New to GrepCode? Check out our FAQ X