Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2000, 2010 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.*;
 import java.util.List;
 
 import  org.eclipse.swt.SWT;
 import  org.eclipse.swt.events.SelectionAdapter;
 import  org.eclipse.swt.events.SelectionEvent;
 import  org.eclipse.swt.layout.GridData;
 import  org.eclipse.swt.layout.GridLayout;
 import  org.eclipse.swt.widgets.*;
 
 public class CVSRepositoryPropertiesPage extends PropertyPage {
 	private static final String FAKE_PASSWORD = "*********"//$NON-NLS-1$
 	
 	// Widgets
 	Text userText;
 	Text passwordText;
 	Combo methodType;
 	Text hostText;
 	Text pathText;
 	// Port
 	private Text portText;
 	private Button useDefaultPort;
 	private Button useCustomPort;
 	
 	// Caching password
 	private Button allowCachingButton;
 	private boolean allowCaching = false;
 	
 	boolean passwordChanged;
 
 
 	// Label
 	private Button useLocationAsLabel;
 	private Button useCustomLabel;
 	private Text labelText;
 			
 	/*
 	 * @see PreferencesPage#createContents
 	 */
 	protected Control createContents(Composite parent) {
 		
 		Composite composite = new Composite(parent, SWT.NULL);
 		composite.setLayoutData(new GridData(GridData.FILL_BOTH));
 		GridLayout layout = new GridLayout();
 		layout.numColumns = 3;
 		composite.setLayout(layout);
 
 		// Repository Label
 		// create a composite to ensure the radio buttons come in the correct order
 		Composite labelGroup = new Composite(composite, SWT.NONE);
 		GridData data = new GridData();
 		data.horizontalSpan = 3;
 		labelGroup.setLayoutData(data);
 		layout = new GridLayout();
 		layout.numColumns = 3;
 		layout.marginHeight = 0;
 		layout.marginWidth = 0;
 		labelGroup.setLayout(layout);
 		Listener labelListener = new Listener() {
 			public void handleEvent(Event event) {
			}
		};
		.addListener(SWT.Selection, labelListener);
		 = createTextField(labelGroup);
		.addListener(SWT.Modify, labelListener);
		// Add some extra space
		createLabel(composite"", 3); //$NON-NLS-1$
		 = createCombo(composite);
		 = createTextField(composite);
		 = createTextField(composite);
		 = createTextField(composite);
		// Port number
		// create a composite to ensure the radio buttons come in the correct order
		Composite portGroup = new Composite(composite, SWT.NONE);
		data = new GridData();
		data.horizontalSpan = 3;
		portGroup.setLayoutData(data);
		layout = new GridLayout();
		layout.numColumns = 3;
		layout.marginHeight = 0;
		layout.marginWidth = 0;
		portGroup.setLayout(layout);
		 = createTextField(portGroup);
		// Add some extra space
		createLabel(composite"", 3); //$NON-NLS-1$
		 = new Button(composite, SWT.CHECK);
		data = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL);
		data.horizontalSpan = 3;
		.setLayoutData(data);
		.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				 = .getSelection();
			}
		});
		link.setLayoutData(data);
		// Add some extra space
		createLabel(composite"", 3); //$NON-NLS-1$
		Listener connectionInfoChangedListener = new Listener() {
			public void handleEvent(Event event) {
			}
		};
		.addListener(SWT.Modify, new Listener() {
			public void handleEvent(Event event) {
			}
		});
		.addListener(SWT.Modify, connectionInfoChangedListener);
		.addListener(SWT.Modify, connectionInfoChangedListener);
		.addListener(SWT.Modify, connectionInfoChangedListener);
		.addListener(SWT.Modify, connectionInfoChangedListener);
		.addListener(SWT.Selection, connectionInfoChangedListener);
		.addListener(SWT.Modify, connectionInfoChangedListener);
        Dialog.applyDialogFont(parent);
		return composite;
	}

Utility method that creates a combo box

Parameters:
parent the parent for the new label
Returns:
the new widget
	protected Combo createCombo(Composite parent) {
		Combo combo = new Combo(parent, SWT.READ_ONLY);
		GridData data = new GridData(GridData.FILL_HORIZONTAL);
		data.horizontalSpan = 2;
		combo.setLayoutData(data);
		return combo;
	}
Utility method that creates a label instance and sets the default layout data.

Parameters:
parent the parent for the new label
text the text for the new label
Returns:
the new label
	protected Label createLabel(Composite parentString textint span) {
		Label label = new Label(parent, SWT.LEFT);
		label.setText(text);
		GridData data = new GridData();
		data.horizontalSpan = span;
		data.horizontalAlignment = GridData.FILL;
		label.setLayoutData(data);
		return label;
	}
Create a text field specific for this application

Parameters:
parent the parent of the new text field
Returns:
the new text field
	protected Text createTextField(Composite parent) {
		Text text = new Text(parent, SWT.SINGLE | SWT.BORDER);
		return layoutTextField(text);
	}
Create a password field specific for this application

Parameters:
parent the parent of the new text field
Returns:
the new text field
	protected Text createPasswordField(Composite parent) {
		Text text = new Text(parent, SWT.SINGLE | SWT.BORDER | SWT.PASSWORD);
		return layoutTextField(text);
	}
Layout a text or password field specific for this application

Parameters:
parent the parent of the new text field
Returns:
the new text field
	protected Text layoutTextField(Text text) {
		GridData data = new GridData(GridData.FILL_HORIZONTAL);
		data.verticalAlignment = GridData.CENTER;
		data.grabExcessVerticalSpace = false;
		data.horizontalSpan = 2;
		text.setLayoutData(data);
		return text;
	}

Utility method to create a radio button

Parameters:
parent the parent of the radio button
label the label of the radio button
span the number of columns to span
Returns:
the created radio button
	protected Button createRadioButton(Composite parentString labelint span) {
		Button button = new Button(parent, SWT.RADIO);
		button.setText(label);
		GridData data = new GridData();
		data.horizontalSpan = span;
		button.setLayoutData(data);
		return button;
	}
Initializes the page
	private void initialize() {
		 = null;
		IAdaptable element = getElement();
		if (element instanceof ICVSRepositoryLocation) {
else {
			Object adapter = element.getAdapter(ICVSRepositoryLocation.class);
			if (adapter instanceof ICVSRepositoryLocation) {
			}
		}
	}
Set the initial values of the widgets
	private void initializeValues() {
		 = false;
		IConnectionMethod[] methods = CVSRepositoryLocation.getPluggedInConnectionMethods();
		for (int i = 0; i < methods.lengthi++) {
			.add(methods[i].getName());
		}
		.select(.indexOf(method));
		int port = .getPort();
			.setSelection(true);
			.setSelection(false);
			.setEnabled(false);
else {
			.setSelection(false);
			.setSelection(true);
			.setText("" + port); //$NON-NLS-1$
		}
		 = .getSelection();
		// get the repository label
		String label = null;
		label = root.getName();
		.setSelection(label == null);
		.setSelection(!.getSelection());
		if (label == null) {
			label = .getLocation(true);
		}
		.setText(label);
	}
	private boolean performConnectionInfoChanges() {
		// Set the caching mode of the location
			}
		}
		// Don't do anything else if there wasn't a password or connection change
		if (! && !return true;
		try {
			// Check if the password was the only thing to change.
				if () {
					oldLocation.updateCache();
				}
				 = false;
				return true;
			}
			// Otherwise change the connection info and the password
			// This operation is done inside a workspace operation in case the sharing
			// info for existing projects is changed
			if (!(.getHost().equals(.getText()) && .getRootDirectory().equals(.getText()))) {
				// The host or path has changed
				if (!MessageDialog.openConfirm(getShell(), 
					return false;
				}
			}
			final boolean[] result = new boolean[] { false };
			final ProgressMonitorDialog progressMonitorDialog = new ProgressMonitorDialog(getShell());
            progressMonitorDialog.run(falsefalsenew WorkspaceModifyOperation(null) {
					try {
						// Create a new repository location with the new information
						CVSRepositoryLocation newLocation = CVSRepositoryLocation.fromProperties(createProperties());
						try {
							// For each project shared with the old location, set connection info to the new one
							List projects = new ArrayList();
							IProject[] allProjects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
							for (int i = 0; i < allProjects.lengthi++) {
								RepositoryProvider teamProvider = RepositoryProvider.getProvider(allProjects[i], CVSProviderPlugin.getTypeId());
								if (teamProvider != null) {
									CVSTeamProvider cvsProvider = (CVSTeamProvider)teamProvider;
										projects.add(allProjects[i]);
									}
								}
							}
							if (projects.size() > 0) {
								// To do: warn the user
								    progressMonitorDialog.getShell(), 
									(IProject[]) projects.toArray(new IProject[projects.size()]),
									true,
								int r = dialog.open();
								if (r != .) {
									result[0] = false;
									return;
								}
								monitor.beginTask(null, 1000 * projects.size());
								try {
									Iterator it = projects.iterator();
									while (it.hasNext()) {
										IProject project = (IProject)it.next();
										RepositoryProvider teamProvider = RepositoryProvider.getProvider(project, CVSProviderPlugin.getTypeId());
										CVSTeamProvider cvsProvider = (CVSTeamProvider)teamProvider;
										cvsProvider.setRemoteRoot(newLocation, Policy.subMonitorFor(monitor, 1000));
									}
finally {
									monitor.done();
								}
							}
							// Dispose the old repository location
finally {
							// Even if we failed, ensure that the new location appears in the repo view.
							newLocation = (CVSRepositoryLocation)KnownRepositories.getInstance().addRepository(newLocation, !KnownRepositories.getInstance().isKnownRepository(newLocation.getLocation()));
						}
						// Set the location of the page to the new location in case Apply was chosen
						 = newLocation;
						 = false;
catch (TeamException e) {
					}
					result[0] = true;
				}
			});
			return result[0];
catch (InvocationTargetException e) {
catch (InterruptedException e) {
		}
		return false/* we only get here if an exception occurred */
	}
	}
	/*
	 * @see PreferencesPage#performOk
	 */
	public boolean performOk() {
			return true;
		}
		return false;
	}
	/* (non-Javadoc)
	 * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
	 */
	protected void performDefaults() {
	}

Shows the given errors to the user.
	protected void handle(Throwable e) {
		CVSUIPlugin.openError(getShell(), nullnulle);
	}

Updates widget enablements and sets error message if appropriate.
	protected void updateWidgetEnablements() {
		if (.getSelection()) {
			.setEnabled(false);
else {
			.setEnabled(true);
		}
		if (.getSelection()) {
			.setEnabled(false);
else {
			.setEnabled(true);
		}
	}
	private void validateFields() {
		if (.isEnabled()) {
			if (.getText().length() == 0) {
				setValid(false);
				return;
			}
		}
		String user = .getText();
		IStatus status = ConfigurationWizardMainPage.validateUserName(user);
		if (!isStatusOK(status)) {
			return;
		}
		String host = .getText();
		status = ConfigurationWizardMainPage.validateHost(host);
		if (!isStatusOK(status)) {
			return;
		}
		if (.isEnabled()) {
			String port = .getText();
			status = ConfigurationWizardMainPage.validatePort(port);
			if (!isStatusOK(status)) {
				return;
			}
		}
		String pathString = .getText();
		status = ConfigurationWizardMainPage.validatePath(pathString);
		if (!isStatusOK(status)) {
			return;
		}
		try {
			CVSRepositoryLocation l = CVSRepositoryLocation.fromProperties(createProperties());
			if (!l.equals() && KnownRepositories.getInstance().isKnownRepository(l.getLocation())) {
				setValid(false);
				return;
			}
catch (CVSException e) {
			CVSUIPlugin.log(e);
			// Let it pass. Creation should fail
		}
		setValid(true);
	}
	private boolean isStatusOK(IStatus status) {
		if (!status.isOK()) {
			setValid(false);
			return false;
		}
		return true;
	}
	private void recordNewLabel(CVSRepositoryLocation location) {
		String newLabel = getNewLabel(location);
		if (newLabel == null) {
			String oldLabel = getOldLabel(location);
			if (oldLabel == null || oldLabel.equals(location.getLocation())) {
				return;
			}
else if (newLabel.equals(getOldLabel(location))) {
			return;
		}
		CVSUIPlugin.getPlugin().getRepositoryManager().setLabel(locationnewLabel);
	}
		return CVSUIPlugin.getPlugin().getRepositoryManager().getRepositoryRootFor(location).getName();
	}
		String label = null;
		if (.getSelection()) {
			label = .getText();
			if (label.equals(location.getLocation())) {
				label = null;
			}
		}
		return label;
	}
	/* internal use only */ String getNewPassword() {
		return .getText();
	}
		Properties result = new Properties();
		result.setProperty("connection".getText()); //$NON-NLS-1$
		result.setProperty("user".getText()); //$NON-NLS-1$
			result.setProperty("password".getText()); //$NON-NLS-1$
		}
		result.setProperty("host".getText()); //$NON-NLS-1$
		if (.getSelection()) {
			result.setProperty("port".getText()); //$NON-NLS-1$
		}
		result.setProperty("root".getText()); //$NON-NLS-1$
		return result;
	}
New to GrepCode? Check out our FAQ X