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;
 
 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 CVSProjectPropertiesPage extends CVSPropertiesPage {
 
 	private static final int TABLE_HEIGHT_HINT = 150;
 	
 	// Widgets
 	Text methodText;
 	Text userText;
 	Text hostText;
 	Text pathText;
 	Text moduleText;
 	Text portText;
 	Text tagText;
 	private Button fetchButton;
 	private Button watchEditButton;
 	
 	private boolean fetch;
 	private boolean watchEdit;
 
 	public static boolean isCompatible(ICVSRepositoryLocation location,
 			ICVSRepositoryLocation oldLocation) {
 		return CVSRepositoryLocationMatcher.isCompatible(locationoldLocation,
 				false);
 	}
 	
 	private class RepositorySelectionDialog extends Dialog {
 		
 		Button okButton;
 		boolean showCompatible = true;
 		
 		public RepositorySelectionDialog(Shell shellICVSRepositoryLocation oldLocation) {
 			super(shell);
 			initialize(oldLocation);
 		}
 		private void initialize(ICVSRepositoryLocation oldLocation) {
 			List locations = new ArrayList();
 			for (int i = 0; i < .i++) {
 				if (isCompatible(locationoldLocation)) {
 					locations.add(location);
 				}
 			}
 		}
 		protected void createButtonsForButtonBar(Composite parent) {
 			// create OK and Cancel buttons by default
 			.setEnabled(false);
		}
		protected Control createDialogArea(Composite parent) {
			Composite composite = (Composite) super.createDialogArea(parent);
			Table table = new Table(composite, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
			GridData data = new GridData(GridData.FILL_HORIZONTAL);
			data.heightHint = ;
			table.setLayoutData(data);
			 = new TableViewer(table);
				public Object[] getElements(Object inputElement) {
else {
						return ;
					}
				}
			});
				public void selectionChanged(SelectionChangedEvent event) {
					if (selection.isEmpty()) {
						.setEnabled(false);
else {
						.setEnabled(true);
					}
				}
			});
				public void doubleClick(DoubleClickEvent event) {
				}
			});
			final Button compatibleButton = createCheckBox(composite.); 
			compatibleButton.setSelection();
			compatibleButton.addSelectionListener(new SelectionAdapter() {
				public void widgetSelected(SelectionEvent e) {
					 = compatibleButton.getSelection();
				}
			});
			Dialog.applyDialogFont(parent);
			return composite;
		}
		protected void cancelPressed() {
		}
		}
	}
	/*
	 * @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 = 2;
		composite.setLayout(layout);
		 = createReadOnlyText(composite"", 1); //$NON-NLS-1$
		 = createReadOnlyText(composite"", 1); //$NON-NLS-1$
		 = createReadOnlyText(composite"", 1); //$NON-NLS-1$
		label = createLabel(composite., 1); 
		 = createReadOnlyText(composite"", 1); //$NON-NLS-1$
		 = createReadOnlyText(composite"", 1); //$NON-NLS-1$
		 = createReadOnlyText(composite"", 1); //$NON-NLS-1$
		label = createLabel(composite., 1); 
		 = createReadOnlyText(composite"", 1); //$NON-NLS-1$
		createLabel(composite"", 1); //$NON-NLS-1$
		// Should absent directories be fetched on update
		.addListener(SWT.Selection, new Listener() {
			public void handleEvent(Event event) {
				 = .getSelection();
			}
		});
		// Should the project be configured for watch/edit
		.addListener(SWT.Selection, new Listener() {
			public void handleEvent(Event event) {
				 = .getSelection();
			}
		});
		createLabel(composite"", 1); //$NON-NLS-1$
		createLabel(composite"", 1); //$NON-NLS-1$
		createLabel(composite"", 1); //$NON-NLS-1$
		createLabel(composite"", 1); //$NON-NLS-1$
		label = new Label(composite, SWT.WRAP);
		GridData data = new GridData(GridData.FILL_HORIZONTAL);
		data.widthHint = 200;
		data.horizontalSpan = 2;
		label.setLayoutData(data);
		Button changeButton = new Button(composite, SWT.PUSH);
		changeButton.addListener(SWT.Selection, new Listener() {
			public void handleEvent(Event e) {
				dialog.open();
				ICVSRepositoryLocation location = dialog.getLocation();
				if (location == nullreturn;
				 = location;
			}
		});
        Dialog.applyDialogFont(parent);
		return composite;
	}
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;
	}
Utility method that creates a text instance and sets the default layout data.

Parameters:
parent the parent for the new label
text the text for the new text
Returns:
the new text
	protected Text createReadOnlyText(Composite parentString textint span) {
		Text txt = new Text(parent, SWT.LEFT | SWT.READ_ONLY);
		txt.setText(text);
		txt.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
		GridData data = new GridData();
		data.horizontalSpan = span;
		data.horizontalAlignment = GridData.FILL;
		txt.setLayoutData(data);
		return txt;
	}
Creates a new checkbox instance and sets the default layout data.

Parameters:
group the composite in which to create the checkbox
label the string to set into the checkbox
Returns:
the new checkbox
 
	protected Button createCheckBox(Composite groupString label) {
		Button button = new Button(group, SWT.CHECK | SWT.LEFT);
		button.setText(label);
		GridData data = new GridData();
		data.horizontalSpan = 2;
		button.setLayoutData(data);
		return button;
	}
Initializes the page
	private void initialize() {
		// Get the project that is the source of this property page
		 = null;
		IAdaptable element = getElement();
		if (element instanceof IProject) {
			 = (IProject)element;
else {
			Object adapter = element.getAdapter(IProject.class);
			if (adapter instanceof IProject) {
				 = (IProject)adapter;
			}
		}
		// Do some pre-checks to ensure we're in a good state
		 = (CVSTeamProvider)RepositoryProvider.getProvider(, CVSProviderPlugin.getTypeId());
		if ( == nullreturn;
		try {
catch (TeamException e) {
		}
	}
Set the initial values of the widgets
	private void initializeValues(ICVSRepositoryLocation location) {
		if ( == nullreturn;
		ICVSFolder folder = cvsRoot.getLocalRoot();
		try {
			if (!folder.isCVSFolder()) return;
			.setText(location.getMethod().getName());
			 = location.getUserInfo(true);
			.setText(location.getHost());
			int port = location.getPort();
                .setText(.); 
else {
				.setText("" + port); //$NON-NLS-1$
			}
			.setText(location.getRootDirectory());
			FolderSyncInfo syncInfo = folder.getFolderSyncInfo();
			if (syncInfo == nullreturn;
			String label = syncInfo.getRepository();
				label = NLS.bind(.new String[] { label }); 
			}
			.setText(label);
			.setSelection();
catch (TeamException e) {
		}
	}
	private void initializeTag() {
		 = (CVSTeamProvider)RepositoryProvider.getProvider(, CVSProviderPlugin.getTypeId());
		if ( == nullreturn;
		try {
			ICVSFolder local = CVSWorkspaceRoot.getCVSFolderFor();
			CVSTag tag = local.getFolderSyncInfo().getTag();
			.setText(getTagLabel(tag));
catch (TeamException e) {
		}
	}
	/*
	 * @see PreferencesPage#performOk
	 */
	public boolean performOk() {
		final boolean[] changeReadOnly = { false };
		try {
				changeReadOnly[0] = true;
			}
catch (CVSException e) {
		}
		if ( == null && !changeReadOnly[0]) {
			return true;
		}
		try {
			if ( != null && !isCompatible()) {
					return false;
				}
			}
					try {
						(( == null)?0:100) + (changeReadOnly[0]?100:0));
						if ( != null)
						if (changeReadOnly[0])
catch (TeamException e) {
					}
				}
			});
			 = null;
			if (changeReadOnly[0]) {
			}
catch (InvocationTargetException e) {
catch (InterruptedException e) {
			return false;
		}
		return true;
	}

Parameters:
watchEdit
	protected void setReadOnly(final boolean watchEditfinal IProgressMonitor monitorthrows CVSException {
		monitor.beginTask(null, 512);
		String taskName = watchEdit?
		monitor.subTask(taskName);
		ICVSFolder root = CVSWorkspaceRoot.getCVSFolderFor();
			public void visitFile(ICVSFile filethrows CVSException {
				// only change managed, unmodified files
				if (file.isManaged() && !file.isModified(null))
					file.setReadOnly(watchEdit);
				monitor.worked(1);
			}
			public void visitFolder(ICVSFolder folderthrows CVSException {
				folder.acceptChildren(this);
			}
		});
		monitor.done();
	}
Shows the given errors to the user.
	protected void handle(Throwable t) {
		CVSUIPlugin.openError(getShell(), nullnullt);
	}
New to GrepCode? Check out our FAQ X