View | Details | Raw Unified | Return to bug 159258 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/team/internal/ccvs/ui/wizards/AlternativeLocationWizard.java (-8 / +5 lines)
Lines 102-115 Link Here
102
	 * Creates the wizard pages
102
	 * Creates the wizard pages
103
	 */
103
	 */
104
	public void addPages() {
104
	public void addPages() {
105
		mainPage = new AlternativeConfigurationWizardMainPage("repositoryPage1", CVSUIMessages.AlternativeLocationWizard_heading, CVSUIPlugin.getPlugin().getImageDescriptor(ICVSUIConstants.IMG_WIZBAN_NEW_LOCATION)); //$NON-NLS-1$ 
105
		super.addPages();
106
		if (properties != null) {
106
	}
107
			mainPage.setProperties(properties);
107
	
108
		}
108
	protected ConfigurationWizardMainPage createMainPage() {
109
		mainPage.setShowValidate(true);
109
		return new AlternativeConfigurationWizardMainPage("repositoryPage1", CVSUIMessages.AlternativeLocationWizard_heading, CVSUIPlugin.getPlugin().getImageDescriptor(ICVSUIConstants.IMG_WIZBAN_NEW_LOCATION)); //$NON-NLS-1$
110
		mainPage.setDescription(CVSUIMessages.AlternativeLocationWizard_description); 
111
		mainPage.setDialogSettings(getDialogSettings());
112
		addPage(mainPage);
113
	}
110
	}
114
	
111
	
115
	public ICVSRepositoryLocation getLocation() {
112
	public ICVSRepositoryLocation getLocation() {
(-)src/org/eclipse/team/internal/ccvs/ui/wizards/NewLocationWizard.java (-1 / +6 lines)
Lines 65-71 Link Here
65
	 * Creates the wizard pages
65
	 * Creates the wizard pages
66
	 */
66
	 */
67
	public void addPages() {
67
	public void addPages() {
68
		mainPage = new ConfigurationWizardMainPage("repositoryPage1", CVSUIMessages.NewLocationWizard_heading, CVSUIPlugin.getPlugin().getImageDescriptor(ICVSUIConstants.IMG_WIZBAN_NEW_LOCATION)); //$NON-NLS-1$ 
68
		mainPage = createMainPage();
69
		if (properties != null) {
69
		if (properties != null) {
70
			mainPage.setProperties(properties);
70
			mainPage.setProperties(properties);
71
		}
71
		}
Lines 74-79 Link Here
74
		mainPage.setDialogSettings(getDialogSettings());
74
		mainPage.setDialogSettings(getDialogSettings());
75
		addPage(mainPage);
75
		addPage(mainPage);
76
	}
76
	}
77
	
78
	protected ConfigurationWizardMainPage createMainPage() {
79
		return new ConfigurationWizardMainPage("repositoryPage1", CVSUIMessages.NewLocationWizard_heading, CVSUIPlugin.getPlugin().getImageDescriptor(ICVSUIConstants.IMG_WIZBAN_NEW_LOCATION)); //$NON-NLS-1$ 
80
	}
81
	
77
	/*
82
	/*
78
	 * @see IWizard#performFinish
83
	 * @see IWizard#performFinish
79
	 */
84
	 */
(-)src/org/eclipse/team/internal/ccvs/ui/CVSUIMessages.java (-8 / +8 lines)
Lines 349-362 Link Here
349
	public static String CommitWizardFileTypePage_2;
349
	public static String CommitWizardFileTypePage_2;
350
	public static String CommitWizardFileTypePage_3;
350
	public static String CommitWizardFileTypePage_3;
351
	
351
	
352
	public static String AlternativeRepositoryWizard_title;
352
	public static String ConfigureRepositoryLocationsWizard_title;
353
	public static String AlternativeRepositoryWizard_message;
353
	public static String ConfigureRepositoryLocationsWizard_message;
354
	public static String AlternativeRepositoryWizard_createLocation;
354
	public static String ConfigureRepositoryLocationsWizard_createLocation;
355
	public static String AlternativeRepositoryWizard_createLocationTooltip;
355
	public static String ConfigureRepositoryLocationsWizard_createLocationTooltip;
356
	public static String AlternativeRepositoryWizard_column0;
356
	public static String ConfigureRepositoryLocationsWizard_column0;
357
	public static String AlternativeRepositoryWizard_column1;
357
	public static String ConfigureRepositoryLocationsWizard_column1;
358
	public static String AlternativeRepositoryWizard_showConnection;
358
	public static String ConfigureRepositoryLocationsWizard_showConnection;
359
	public static String AlternativeRepositoryWizardDialog_finish;
359
	public static String ConfigureRepositoryLocationsWizardDialog_finish;
360
	
360
	
361
361
362
	public static String CommitSyncAction_questionRelease;
362
	public static String CommitSyncAction_questionRelease;
(-)src/org/eclipse/team/internal/ccvs/ui/AlternativeRepositoryDialog.java (-231 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.team.internal.ccvs.ui;
12
13
import java.util.Map;
14
import java.util.Properties;
15
16
import org.eclipse.jface.dialogs.*;
17
import org.eclipse.jface.dialogs.Dialog;
18
import org.eclipse.jface.viewers.*;
19
import org.eclipse.jface.wizard.IWizard;
20
import org.eclipse.jface.wizard.WizardDialog;
21
import org.eclipse.swt.SWT;
22
import org.eclipse.swt.graphics.Image;
23
import org.eclipse.swt.layout.GridData;
24
import org.eclipse.swt.layout.GridLayout;
25
import org.eclipse.swt.widgets.*;
26
import org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation;
27
import org.eclipse.team.internal.ccvs.core.connection.CVSRepositoryLocation;
28
import org.eclipse.team.internal.ccvs.ui.wizards.AlternativeLocationWizard;
29
import org.eclipse.ui.PlatformUI;
30
31
public class AlternativeRepositoryDialog extends TitleAreaDialog {
32
33
	private Image dlgTitleImage;
34
	private AlternativeRepositoryTable fAlternativeRepositoryTable;
35
36
	/**
37
	 * Creates a new AlternativeRepositoryDialog.
38
	 * 
39
	 * @param parentShell
40
	 *            the parent shell
41
	 * @param alternativesMap
42
	 *            Map with a repository location (ICVSRepositoryLocation) from
43
	 *            the Team Project Set as a key and list of alternatives found
44
	 *            (also ICVSRepositoryLocation) as a value.
45
	 * @param message
46
	 *            a message to display to the user
47
	 */
48
	public AlternativeRepositoryDialog(Shell parentShell, Map alternativesMap) {
49
		super(parentShell);
50
		setShellStyle(getShellStyle() | SWT.RESIZE);
51
		fAlternativeRepositoryTable = new AlternativeRepositoryTable(
52
				alternativesMap);
53
	}
54
55
	/*
56
	 * (non-Javadoc)
57
	 * 
58
	 * @see org.eclipse.jface.dialogs.TitleAreaDialog#createContents(org.eclipse.swt.widgets.Composite)
59
	 */
60
	protected Control createContents(Composite parent) {
61
		Control contents = super.createContents(parent);
62
		setTitle(CVSUIMessages.AlternativeRepositoryWizard_title);
63
		setMessage(CVSUIMessages.AlternativeRepositoryWizard_message);
64
		dlgTitleImage = CVSUIPlugin.getPlugin().getImageDescriptor(
65
				ICVSUIConstants.IMG_WIZBAN_NEW_LOCATION).createImage();
66
		setTitleImage(dlgTitleImage);
67
		return contents;
68
	}
69
70
	public boolean close() {
71
		if (dlgTitleImage != null) {
72
			dlgTitleImage.dispose();
73
		}
74
		return super.close();
75
	}
76
77
	/*
78
	 * (non-Javadoc) Method declared in Window.
79
	 */
80
	protected void configureShell(Shell shell) {
81
		super.configureShell(shell);
82
		shell.setText(CVSUIMessages.AlternativeRepositoryWizard_title);
83
		// set F1 help
84
		PlatformUI.getWorkbench().getHelpSystem().setHelp(shell,
85
				IHelpContextIds.ALTERNATIVE_REPOSITORY_DIALOG);
86
	}
87
88
	/**
89
	 * @see Dialog#createDialogArea
90
	 */
91
	protected Control createDialogArea(Composite parent) {
92
		initializeDialogUnits(parent);
93
94
		final Composite composite = new Composite(parent, SWT.NONE);
95
		composite.setLayout(new GridLayout(2, false));
96
97
		// TODO: help
98
99
		GridData childData = new GridData(GridData.FILL_BOTH);
100
		composite.setLayoutData(childData);
101
102
		Composite table = fAlternativeRepositoryTable.createControl(composite);
103
		GridData gridData = new GridData(GridData.VERTICAL_ALIGN_FILL);
104
		gridData.horizontalSpan = 2;
105
		gridData.horizontalAlignment = GridData.FILL;
106
		gridData.grabExcessHorizontalSpace = true;
107
		gridData.grabExcessVerticalSpace = true;
108
		table.setLayoutData(gridData);
109
110
		final Button showMethodButton = new Button(composite, SWT.CHECK);
111
		showMethodButton
112
				.setText(CVSUIMessages.AlternativeRepositoryWizard_showConnection);
113
		showMethodButton.addListener(SWT.Selection, new Listener() {
114
			public void handleEvent(Event event) {
115
				fAlternativeRepositoryTable
116
						.setShowConnectionMethod(showMethodButton
117
								.getSelection());
118
			}
119
		});
120
		showMethodButton.setEnabled(fAlternativeRepositoryTable
121
				.noDuplicateRepositoryLocationFound());
122
		showMethodButton.setSelection(!fAlternativeRepositoryTable
123
				.noDuplicateRepositoryLocationFound());
124
		showMethodButton.setLayoutData(new GridData(
125
				GridData.HORIZONTAL_ALIGN_BEGINNING));
126
127
		final Button createLocationButton = new Button(composite, SWT.PUSH);
128
		createLocationButton
129
				.setText(CVSUIMessages.AlternativeRepositoryWizard_createLocation);
130
		createLocationButton
131
				.setToolTipText(CVSUIMessages.AlternativeRepositoryWizard_createLocationTooltip);
132
		createLocationButton.addListener(SWT.Selection, new Listener() {
133
			public void handleEvent(Event event) {
134
135
				CVSRepositoryLocation selectedAlternativeRepository = fAlternativeRepositoryTable
136
						.getSelectedAlternativeRepository();
137
138
				Properties properties = new Properties();
139
				properties
140
						.put(
141
								"connection", selectedAlternativeRepository.getMethod().getName()); //$NON-NLS-1$
142
				properties.put(
143
						"user", selectedAlternativeRepository.getUsername()); //$NON-NLS-1$
144
				// TODO: retrieve password (if available) and use it to prime
145
				// the field
146
				// properties.put("password", ""); //$NON-NLS-1$
147
				properties.put("host", selectedAlternativeRepository.getHost()); //$NON-NLS-1$
148
				int port = selectedAlternativeRepository.getPort();
149
				if (port != ICVSRepositoryLocation.USE_DEFAULT_PORT)
150
					properties.put("port", String.valueOf(port)); //$NON-NLS-1$
151
				properties
152
						.put(
153
								"root", selectedAlternativeRepository.getRootDirectory()); //$NON-NLS-1$
154
155
				AlternativeLocationWizard wizard = new AlternativeLocationWizard(
156
						properties);
157
				wizard.setSwitchPerspectives(false);
158
				WizardDialog dialog = new AlternativeRepositoryWizardDialog(
159
						getShell(), wizard);
160
				dialog.open();
161
162
				ICVSRepositoryLocation location = wizard.getLocation();
163
				if (location != null)
164
					fAlternativeRepositoryTable
165
							.addAlternativeRepositoryToSelection(location);
166
			}
167
		});
168
		createLocationButton.setEnabled(fAlternativeRepositoryTable
169
				.getSelection().getFirstElement() != null);
170
		createLocationButton.setLayoutData(new GridData(
171
				GridData.HORIZONTAL_ALIGN_END));
172
173
		fAlternativeRepositoryTable.getViewer().addSelectionChangedListener(
174
				new ISelectionChangedListener() {
175
					public void selectionChanged(SelectionChangedEvent event) {
176
						IStructuredSelection sel = (IStructuredSelection) event
177
								.getSelection();
178
						Object firstElement = sel.getFirstElement();
179
						createLocationButton.setEnabled(firstElement != null);
180
					}
181
				});
182
183
		return composite;
184
	}
185
186
	public Map getSelected() {
187
		return fAlternativeRepositoryTable.getSelected();
188
	}
189
190
	/*
191
	 * (non-Javadoc)
192
	 * 
193
	 * @see org.eclipse.jface.dialogs.Dialog#getDialogBoundsSettings()
194
	 */
195
	protected IDialogSettings getDialogBoundsSettings() {
196
		String sectionName = getClass().getName() + "_dialogBounds"; //$NON-NLS-1$
197
		IDialogSettings settings = CVSUIPlugin.getPlugin().getDialogSettings();
198
		IDialogSettings section = settings.getSection(sectionName);
199
		if (section == null)
200
			section = settings.addNewSection(sectionName);
201
		return section;
202
	}
203
204
	/*
205
	 * @see org.eclipse.jface.dialogs.Dialog#getDialogBoundsStrategy()
206
	 * @since 3.2
207
	 */
208
	protected int getDialogBoundsStrategy() {
209
		return DIALOG_PERSISTLOCATION | DIALOG_PERSISTSIZE;
210
	}
211
212
	/**
213
	 * This class is made only to change Wizard's default "Finish" button label
214
	 * to "Create".
215
	 */
216
	private class AlternativeRepositoryWizardDialog extends WizardDialog {
217
218
		public AlternativeRepositoryWizardDialog(Shell parentShell,
219
				IWizard newWizard) {
220
			super(parentShell, newWizard);
221
		}
222
223
		protected Button createButton(Composite parent, int id, String label,
224
				boolean defaultButton) {
225
			if (id == IDialogConstants.FINISH_ID)
226
				label = CVSUIMessages.AlternativeRepositoryWizardDialog_finish;
227
			return super.createButton(parent, id, label, defaultButton);
228
		}
229
230
	}
231
}
(-)src/org/eclipse/team/internal/ccvs/ui/WorkbenchUserAuthenticator.java (-3 / +3 lines)
Lines 327-335 Link Here
327
	/*
327
	/*
328
	 * (non-Javadoc)
328
	 * (non-Javadoc)
329
	 * 
329
	 * 
330
	 * @see org.eclipse.team.internal.ccvs.core.IUserAuthenticator#promptForAlternativeRepository(java.util.Map)
330
	 * @see org.eclipse.team.internal.ccvs.core.IUserAuthenticator#promptToConfigureRepositoryLocations(java.util.Map)
331
	 */
331
	 */
332
	public Map promptForAlternativeRepository(final Map alternativeMap) {
332
	public Map promptToConfigureRepositoryLocations(final Map alternativeMap) {
333
		final Map[] result = new Map[1];
333
		final Map[] result = new Map[1];
334
		Display display = Display.getCurrent();
334
		Display display = Display.getCurrent();
335
		if (display != null) {
335
		if (display != null) {
Lines 353-359 Link Here
353
	 *         when canceled.
353
	 *         when canceled.
354
	 */
354
	 */
355
	private Map openAlternativeRepositoryDialog(Map alternativeMap) {
355
	private Map openAlternativeRepositoryDialog(Map alternativeMap) {
356
		AlternativeRepositoryDialog dialog = new AlternativeRepositoryDialog(
356
		ConfigureRepositoryLocationsDialog dialog = new ConfigureRepositoryLocationsDialog(
357
				null, alternativeMap);
357
				null, alternativeMap);
358
		int result = dialog.open();
358
		int result = dialog.open();
359
		return result == IDialogConstants.CANCEL_ID ? null : dialog
359
		return result == IDialogConstants.CANCEL_ID ? null : dialog
(-)src/org/eclipse/team/internal/ccvs/ui/AlternativeRepositoryTable.java (-397 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.team.internal.ccvs.ui;
13
14
import java.util.*;
15
import java.util.List;
16
17
import org.eclipse.jface.viewers.*;
18
import org.eclipse.swt.SWT;
19
import org.eclipse.swt.custom.TableEditor;
20
import org.eclipse.swt.events.ControlAdapter;
21
import org.eclipse.swt.events.ControlEvent;
22
import org.eclipse.swt.graphics.*;
23
import org.eclipse.swt.widgets.*;
24
import org.eclipse.team.internal.ccvs.core.CVSProjectSetCapability;
25
import org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation;
26
import org.eclipse.team.internal.ccvs.core.connection.CVSRepositoryLocation;
27
28
public class AlternativeRepositoryTable implements ICellModifier,
29
		IStructuredContentProvider, ITableLabelProvider {
30
31
	private static final class AlternativeRepositoryComparator extends
32
			ViewerComparator {
33
34
		public AlternativeRepositoryComparator() {
35
		}
36
37
		private int getCategory(Object element) {
38
			if (element instanceof RepositoryLocationItem) {
39
				return 0;
40
			}
41
			return 2;
42
		}
43
44
		public int compare(Viewer viewer, Object e1, Object e2) {
45
			final int compare = getCategory(e1) - getCategory(e2);
46
			if (compare != 0)
47
				return compare;
48
			return super.compare(viewer, ((Item) e1).location,
49
					((Item) e2).location);
50
		}
51
	}
52
53
	public abstract static class Item implements Comparable {
54
		public final ICVSRepositoryLocation location;
55
		public List alternativeList;
56
		public int selected;
57
58
		public Item(ICVSRepositoryLocation name, List alternative) {
59
			this.location = name;
60
			this.alternativeList = alternative;
61
			this.selected = 0;
62
		}
63
64
		/*
65
		 * (non-Javadoc)
66
		 * 
67
		 * @see java.lang.Comparable#compareTo(java.lang.Object)
68
		 */
69
		public int compareTo(Object o) {
70
			return location.getLocation(false).compareTo(
71
					((Item) o).location.getLocation(false));
72
		}
73
	}
74
75
	public static class RepositoryLocationItem extends Item {
76
		public RepositoryLocationItem(
77
				ICVSRepositoryLocation projectSetRepositoryLocation,
78
				List suggestedRepositoryLocations) {
79
			super(projectSetRepositoryLocation, suggestedRepositoryLocations);
80
		}
81
	}
82
83
	protected static final String ITEM = "item"; //$NON-NLS-1$
84
	protected static final String PROPERTY_ALTERNATIVE_LIST = "alternativeList"; //$NON-NLS-1$
85
86
	private TableViewer fTableViewer;
87
88
	private CellEditor[] cellEditors;
89
90
	private TextCellEditor dummyAlternativeRepositoryEditor;
91
92
	private Table table;
93
94
	/**
95
	 * List of <code>AlternativeRepositoryTable.RepositoryLocationItem</code>
96
	 * used as an input to the table.
97
	 */
98
	private List fAlternatives;
99
100
	/**
101
	 * Indicates whether a connection method should be displayed in the first
102
	 * column - project set information.
103
	 */
104
	private boolean fShowConnectionMethod;
105
106
	private boolean fNoDuplicateRepositoryLocationFound;
107
108
	public AlternativeRepositoryTable(Map alternativesMap) {
109
		fAlternatives = new ArrayList();
110
		Set checkSet = new HashSet();
111
		for (Iterator iterator = alternativesMap.entrySet().iterator(); iterator
112
				.hasNext();) {
113
			Map.Entry entry = (Map.Entry) iterator.next();
114
			fAlternatives
115
					.add(new AlternativeRepositoryTable.RepositoryLocationItem(
116
							(ICVSRepositoryLocation) entry.getKey(),
117
							(List) entry.getValue()));
118
			fNoDuplicateRepositoryLocationFound = checkSet
119
					.add(excludeConnectionMethod((ICVSRepositoryLocation) entry
120
							.getKey()));
121
		}
122
		fShowConnectionMethod = !fNoDuplicateRepositoryLocationFound;
123
		// we won't need it anymore
124
		checkSet = null;
125
	}
126
127
	public Composite createControl(final Composite composite) {
128
		/**
129
		 * Create a table.
130
		 */
131
		table = new Table(composite, SWT.V_SCROLL | SWT.BORDER | SWT.MULTI
132
				| SWT.FULL_SELECTION);
133
		// table.setLayoutData(SWTUtils.createHVFillGridData());
134
		table.setLinesVisible(true);
135
		table.setHeaderVisible(true);
136
		table.addListener(SWT.MeasureItem, new Listener() {
137
			public void handleEvent(Event event) {
138
				// int clientWidth = table.getClientArea().width;
139
				event.height = event.gc.getFontMetrics().getHeight() + 5;
140
				// event.width = clientWidth * 2;
141
			}
142
		});
143
144
		/**
145
		 * The 'Project Set repository location' column
146
		 */
147
		final TableColumn projectSetRepositoryColumn = new TableColumn(table,
148
				SWT.NONE, 0);
149
		projectSetRepositoryColumn
150
				.setText(CVSUIMessages.AlternativeRepositoryWizard_column0);
151
152
		/**
153
		 * The 'Alternative repository locations' column
154
		 */
155
		final TableColumn alternativeRepositoryColums = new TableColumn(table,
156
				SWT.NONE, 1);
157
		alternativeRepositoryColums
158
				.setText(CVSUIMessages.AlternativeRepositoryWizard_column1);
159
160
		composite.addControlListener(new ControlAdapter() {
161
			public void controlResized(ControlEvent e) {
162
				Rectangle area = composite.getClientArea();
163
				Point size = table.computeSize(SWT.DEFAULT, SWT.DEFAULT);
164
				ScrollBar vBar = table.getVerticalBar();
165
				int width = area.width - table.computeTrim(0, 0, 0, 0).width
166
						- vBar.getSize().x;
167
				if (size.y > area.height + table.getHeaderHeight()) {
168
					// Subtract the scrollbar width from the total column width
169
					// if a vertical scrollbar will be required
170
					Point vBarSize = vBar.getSize();
171
					width -= vBarSize.x;
172
				}
173
				Point oldSize = table.getSize();
174
				if (oldSize.x > area.width) {
175
					// table is getting smaller so make the columns
176
					// smaller first and then resize the table to
177
					// match the client area width
178
					projectSetRepositoryColumn.setWidth(width / 2);
179
					alternativeRepositoryColums.setWidth(width
180
							- projectSetRepositoryColumn.getWidth());
181
					table.setSize(area.width, area.height);
182
				} else {
183
					// table is getting bigger so make the table
184
					// bigger first and then make the columns wider
185
					// to match the client area width
186
					table.setSize(area.width, area.height);
187
					projectSetRepositoryColumn.setWidth(width / 2);
188
					alternativeRepositoryColums.setWidth(width
189
							- projectSetRepositoryColumn.getWidth());
190
				}
191
			}
192
		});
193
194
		/**
195
		 * Create a viewer for the table.
196
		 */
197
		fTableViewer = new TableViewer(table);
198
		fTableViewer.setContentProvider(this);
199
		fTableViewer.setLabelProvider(this);
200
		fTableViewer.setComparator(new AlternativeRepositoryComparator());
201
202
		/**
203
		 * Add a cell editor in the 'Alternative repository locations' column
204
		 */
205
		new TableEditor(table);
206
207
		cellEditors = new CellEditor[2];
208
		cellEditors[0] = null;
209
		// to enable cell editing, create a dummy cell editor
210
		cellEditors[1] = dummyAlternativeRepositoryEditor = new TextCellEditor(
211
				table, SWT.READ_ONLY);
212
213
		fTableViewer.setCellEditors(cellEditors);
214
		fTableViewer.setColumnProperties(new String[] { ITEM,
215
				PROPERTY_ALTERNATIVE_LIST });
216
		fTableViewer.setCellModifier(this);
217
		fTableViewer.setInput(fAlternatives);
218
219
		return table;
220
	}
221
222
	public Object getValue(Object element, String property) {
223
224
		final Item item = (Item) element;
225
226
		if (PROPERTY_ALTERNATIVE_LIST.equals(property)) {
227
			return new Integer(item.selected);
228
		}
229
		return null;
230
	}
231
232
	public boolean canModify(Object element, String property) {
233
		// set the correct cell editor for this element
234
		cellEditors[1] = getCellEditor(element);
235
		// only allow modification for editable elements
236
		return PROPERTY_ALTERNATIVE_LIST.equals(property);
237
	}
238
239
	private CellEditor getCellEditor(Object element) {
240
241
		if (element instanceof RepositoryLocationItem) {
242
243
			// create combo-box list of alternative repositories
244
			List alternativeList = ((RepositoryLocationItem) element).alternativeList;
245
			String[] alternativeNames = new String[alternativeList.size()];
246
			int i = 0;
247
			for (Iterator iterator = alternativeList.iterator(); iterator
248
					.hasNext();) {
249
				CVSRepositoryLocation repo = (CVSRepositoryLocation) iterator
250
						.next();
251
				alternativeNames[i++] = repo.getLocation();
252
			}
253
			return new ComboBoxCellEditor(table, alternativeNames,
254
					SWT.READ_ONLY);
255
		}
256
		return dummyAlternativeRepositoryEditor;
257
	}
258
259
	public void modify(Object element, String property, Object value) {
260
261
		final IStructuredSelection selection = (IStructuredSelection) fTableViewer
262
				.getSelection();
263
		final Item item = (Item) selection.getFirstElement();
264
		if (item == null)
265
			return;
266
267
		final int comboIndex = ((Integer) value).intValue();
268
269
		if (PROPERTY_ALTERNATIVE_LIST.equals(property)) {
270
			item.selected = comboIndex;
271
		}
272
		fTableViewer.refresh(item);
273
	}
274
275
	public Image getColumnImage(Object element, int columnIndex) {
276
		return null;
277
	}
278
279
	public String getColumnText(Object element, int columnIndex) {
280
		final Item item = (Item) element;
281
282
		switch (columnIndex) {
283
		case 0:
284
			return fShowConnectionMethod ? item.location.getLocation(false)
285
					: excludeConnectionMethod(item.location);
286
		case 1:
287
			return ((CVSRepositoryLocation) item.alternativeList
288
					.get(item.selected)).getLocation();
289
		default:
290
			return null;
291
		}
292
	}
293
294
	public void addListener(ILabelProviderListener listener) {
295
	}
296
297
	public void dispose() {
298
	}
299
300
	public boolean isLabelProperty(Object element, String property) {
301
		return false;
302
	}
303
304
	public void removeListener(ILabelProviderListener listener) {
305
	}
306
307
	public Object[] getElements(Object inputElement) {
308
		return ((Collection) inputElement).toArray();
309
	}
310
311
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
312
	}
313
314
	public IStructuredSelection getSelection() {
315
		return (IStructuredSelection) fTableViewer.getSelection();
316
	}
317
318
	public TableViewer getViewer() {
319
		return fTableViewer;
320
	}
321
322
	/**
323
	 * @return a selected (in a combo box) alternative repository location for
324
	 *         the first selected element
325
	 */
326
	public CVSRepositoryLocation getSelectedAlternativeRepository() {
327
		RepositoryLocationItem firstElement = (RepositoryLocationItem) getSelection()
328
				.getFirstElement();
329
		return (CVSRepositoryLocation) firstElement.alternativeList
330
				.get(firstElement.selected);
331
	}
332
333
	public void addAlternativeRepositoryToSelection(
334
			ICVSRepositoryLocation location) {
335
		// add newly created repository location to all selected elements
336
		for (Iterator iterator = getSelection().iterator(); iterator.hasNext();) {
337
			RepositoryLocationItem selectedItem = (RepositoryLocationItem) iterator
338
					.next();
339
			selectedItem.alternativeList.add(0, location);
340
			selectedItem.selected = 0;
341
			// fTableViewer.refresh(selectedItem);
342
		}
343
344
		// add newly created repository location to not-selected elements
345
		// new location must be compatible with the one from the project set
346
		for (int i = 0; i < fTableViewer.getTable().getItemCount(); i++) {
347
			Object element = fTableViewer.getElementAt(i);
348
			if (!getSelection().toList().contains(element)) {
349
				RepositoryLocationItem locationItem = (RepositoryLocationItem) element;
350
				if (CVSProjectSetCapability.isCompatible(location,
351
						locationItem.location)) {
352
					locationItem.alternativeList.add(location);
353
				}
354
			}
355
		}
356
357
		// update labels because of the first loop - first item changed
358
		fTableViewer.refresh(true);
359
	}
360
361
	/**
362
	 * @return A map with repository location from the project set as a key and
363
	 *         selected repository location from a combo box as value.
364
	 */
365
	public Map getSelected() {
366
		Map map = new HashMap();
367
		for (Iterator iterator = fAlternatives.iterator(); iterator.hasNext();) {
368
			AlternativeRepositoryTable.RepositoryLocationItem rli = (AlternativeRepositoryTable.RepositoryLocationItem) iterator
369
					.next();
370
			map.put(rli.location, rli.alternativeList.get(rli.selected));
371
		}
372
		return map;
373
	}
374
375
	public void setShowConnectionMethod(boolean show) {
376
		fShowConnectionMethod = show;
377
		fTableViewer.refresh(true);
378
	}
379
380
	private String excludeConnectionMethod(ICVSRepositoryLocation location) {
381
		String user = location.getUsername();
382
		String host = location.getHost();
383
		int port = location.getPort();
384
		String root = location.getRootDirectory();
385
386
		return (user != null && !user.equals("") ? (user + CVSRepositoryLocation.HOST_SEPARATOR) //$NON-NLS-1$
387
				: "") + //$NON-NLS-1$ 
388
				host
389
				+ CVSRepositoryLocation.COLON
390
				+ ((port == CVSRepositoryLocation.USE_DEFAULT_PORT) ? "" : (new Integer(port).toString())) + //$NON-NLS-1$ 
391
				root;
392
	}
393
394
	public boolean noDuplicateRepositoryLocationFound() {
395
		return fNoDuplicateRepositoryLocationFound;
396
	}
397
}
(-)src/org/eclipse/team/internal/ccvs/ui/messages.properties (-8 / +8 lines)
Lines 289-302 Link Here
289
CommitWizardFileTypePage_2=Unknown new files detected.
289
CommitWizardFileTypePage_2=Unknown new files detected.
290
CommitWizardFileTypePage_3=New files with the following unknown names or extensions have been detected in the workspace. Please specify whether these files should be stored as text or binary and whether this decision should be remembered.
290
CommitWizardFileTypePage_3=New files with the following unknown names or extensions have been detected in the workspace. Please specify whether these files should be stored as text or binary and whether this decision should be remembered.
291
291
292
AlternativeRepositoryWizard_title=Select alternative repository
292
ConfigureRepositoryLocationsWizard_title=Select alternative repository
293
AlternativeRepositoryWizard_message=The project set only contains partial repository information. Please use the table below to associate each project set repository with a repository location or click OK to use the default locations.
293
ConfigureRepositoryLocationsWizard_message=The project set only contains partial repository information. Please use the table below to associate each project set repository with a repository location or click OK to use the default locations.
294
AlternativeRepositoryWizard_createLocation=Create Location
294
ConfigureRepositoryLocationsWizard_createLocation=Create Location
295
AlternativeRepositoryWizard_createLocationTooltip=Creates Location from a selected alternative repository
295
ConfigureRepositoryLocationsWizard_createLocationTooltip=Creates Location from a selected alternative repository
296
AlternativeRepositoryWizard_column0=Project set repository information
296
ConfigureRepositoryLocationsWizard_column0=Project set repository information
297
AlternativeRepositoryWizard_column1=Repository Location
297
ConfigureRepositoryLocationsWizard_column1=Repository Location
298
AlternativeRepositoryWizard_showConnection=Show connection method
298
ConfigureRepositoryLocationsWizard_showConnection=Show connection method
299
AlternativeRepositoryWizardDialog_finish=Create
299
ConfigureRepositoryLocationsWizardDialog_finish=Create
300
300
301
CommitSyncAction_questionRelease=You have changes that conflict with the server. Release those changes?
301
CommitSyncAction_questionRelease=You have changes that conflict with the server. Release those changes?
302
CommitSyncAction_titleRelease=Confirm Overwrite
302
CommitSyncAction_titleRelease=Confirm Overwrite
(-)src/org/eclipse/team/internal/ccvs/ui/ConfigureRepositoryLocationsTable.java (+397 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.team.internal.ccvs.ui;
13
14
import java.util.*;
15
import java.util.List;
16
17
import org.eclipse.jface.viewers.*;
18
import org.eclipse.swt.SWT;
19
import org.eclipse.swt.custom.TableEditor;
20
import org.eclipse.swt.events.ControlAdapter;
21
import org.eclipse.swt.events.ControlEvent;
22
import org.eclipse.swt.graphics.*;
23
import org.eclipse.swt.widgets.*;
24
import org.eclipse.team.internal.ccvs.core.CVSProjectSetCapability;
25
import org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation;
26
import org.eclipse.team.internal.ccvs.core.connection.CVSRepositoryLocation;
27
28
public class ConfigureRepositoryLocationsTable implements ICellModifier,
29
		IStructuredContentProvider, ITableLabelProvider {
30
31
	private static final class AlternativeRepositoryComparator extends
32
			ViewerComparator {
33
34
		public AlternativeRepositoryComparator() {
35
		}
36
37
		private int getCategory(Object element) {
38
			if (element instanceof RepositoryLocationItem) {
39
				return 0;
40
			}
41
			return 2;
42
		}
43
44
		public int compare(Viewer viewer, Object e1, Object e2) {
45
			final int compare = getCategory(e1) - getCategory(e2);
46
			if (compare != 0)
47
				return compare;
48
			return super.compare(viewer, ((Item) e1).location,
49
					((Item) e2).location);
50
		}
51
	}
52
53
	public abstract static class Item implements Comparable {
54
		public final ICVSRepositoryLocation location;
55
		public List alternativeList;
56
		public int selected;
57
58
		public Item(ICVSRepositoryLocation name, List alternative) {
59
			this.location = name;
60
			this.alternativeList = alternative;
61
			this.selected = 0;
62
		}
63
64
		/*
65
		 * (non-Javadoc)
66
		 * 
67
		 * @see java.lang.Comparable#compareTo(java.lang.Object)
68
		 */
69
		public int compareTo(Object o) {
70
			return location.getLocation(false).compareTo(
71
					((Item) o).location.getLocation(false));
72
		}
73
	}
74
75
	public static class RepositoryLocationItem extends Item {
76
		public RepositoryLocationItem(
77
				ICVSRepositoryLocation projectSetRepositoryLocation,
78
				List suggestedRepositoryLocations) {
79
			super(projectSetRepositoryLocation, suggestedRepositoryLocations);
80
		}
81
	}
82
83
	protected static final String ITEM = "item"; //$NON-NLS-1$
84
	protected static final String PROPERTY_ALTERNATIVE_LIST = "alternativeList"; //$NON-NLS-1$
85
86
	private TableViewer fTableViewer;
87
88
	private CellEditor[] cellEditors;
89
90
	private TextCellEditor dummyAlternativeRepositoryEditor;
91
92
	private Table table;
93
94
	/**
95
	 * List of <code>AlternativeRepositoryTable.RepositoryLocationItem</code>
96
	 * used as an input to the table.
97
	 */
98
	private List fAlternatives;
99
100
	/**
101
	 * Indicates whether a connection method should be displayed in the first
102
	 * column - project set information.
103
	 */
104
	private boolean fShowConnectionMethod;
105
106
	private boolean fNoDuplicateRepositoryLocationFound;
107
108
	public ConfigureRepositoryLocationsTable(Map alternativesMap) {
109
		fAlternatives = new ArrayList();
110
		Set checkSet = new HashSet();
111
		for (Iterator iterator = alternativesMap.entrySet().iterator(); iterator
112
				.hasNext();) {
113
			Map.Entry entry = (Map.Entry) iterator.next();
114
			fAlternatives
115
					.add(new ConfigureRepositoryLocationsTable.RepositoryLocationItem(
116
							(ICVSRepositoryLocation) entry.getKey(),
117
							(List) entry.getValue()));
118
			fNoDuplicateRepositoryLocationFound = checkSet
119
					.add(excludeConnectionMethod((ICVSRepositoryLocation) entry
120
							.getKey()));
121
		}
122
		fShowConnectionMethod = !fNoDuplicateRepositoryLocationFound;
123
		// we won't need it anymore
124
		checkSet = null;
125
	}
126
127
	public Composite createControl(final Composite composite) {
128
		/**
129
		 * Create a table.
130
		 */
131
		table = new Table(composite, SWT.V_SCROLL | SWT.BORDER | SWT.MULTI
132
				| SWT.FULL_SELECTION);
133
		// table.setLayoutData(SWTUtils.createHVFillGridData());
134
		table.setLinesVisible(true);
135
		table.setHeaderVisible(true);
136
		table.addListener(SWT.MeasureItem, new Listener() {
137
			public void handleEvent(Event event) {
138
				// int clientWidth = table.getClientArea().width;
139
				event.height = event.gc.getFontMetrics().getHeight() + 5;
140
				// event.width = clientWidth * 2;
141
			}
142
		});
143
144
		/**
145
		 * The 'Project Set repository location' column
146
		 */
147
		final TableColumn projectSetRepositoryColumn = new TableColumn(table,
148
				SWT.NONE, 0);
149
		projectSetRepositoryColumn
150
				.setText(CVSUIMessages.ConfigureRepositoryLocationsWizard_column0);
151
152
		/**
153
		 * The 'Alternative repository locations' column
154
		 */
155
		final TableColumn alternativeRepositoryColums = new TableColumn(table,
156
				SWT.NONE, 1);
157
		alternativeRepositoryColums
158
				.setText(CVSUIMessages.ConfigureRepositoryLocationsWizard_column1);
159
160
		composite.addControlListener(new ControlAdapter() {
161
			public void controlResized(ControlEvent e) {
162
				Rectangle area = composite.getClientArea();
163
				Point size = table.computeSize(SWT.DEFAULT, SWT.DEFAULT);
164
				ScrollBar vBar = table.getVerticalBar();
165
				int width = area.width - table.computeTrim(0, 0, 0, 0).width
166
						- vBar.getSize().x;
167
				if (size.y > area.height + table.getHeaderHeight()) {
168
					// Subtract the scrollbar width from the total column width
169
					// if a vertical scrollbar will be required
170
					Point vBarSize = vBar.getSize();
171
					width -= vBarSize.x;
172
				}
173
				Point oldSize = table.getSize();
174
				if (oldSize.x > area.width) {
175
					// table is getting smaller so make the columns
176
					// smaller first and then resize the table to
177
					// match the client area width
178
					projectSetRepositoryColumn.setWidth(width / 2);
179
					alternativeRepositoryColums.setWidth(width
180
							- projectSetRepositoryColumn.getWidth());
181
					table.setSize(area.width, area.height);
182
				} else {
183
					// table is getting bigger so make the table
184
					// bigger first and then make the columns wider
185
					// to match the client area width
186
					table.setSize(area.width, area.height);
187
					projectSetRepositoryColumn.setWidth(width / 2);
188
					alternativeRepositoryColums.setWidth(width
189
							- projectSetRepositoryColumn.getWidth());
190
				}
191
			}
192
		});
193
194
		/**
195
		 * Create a viewer for the table.
196
		 */
197
		fTableViewer = new TableViewer(table);
198
		fTableViewer.setContentProvider(this);
199
		fTableViewer.setLabelProvider(this);
200
		fTableViewer.setComparator(new AlternativeRepositoryComparator());
201
202
		/**
203
		 * Add a cell editor in the 'Alternative repository locations' column
204
		 */
205
		new TableEditor(table);
206
207
		cellEditors = new CellEditor[2];
208
		cellEditors[0] = null;
209
		// to enable cell editing, create a dummy cell editor
210
		cellEditors[1] = dummyAlternativeRepositoryEditor = new TextCellEditor(
211
				table, SWT.READ_ONLY);
212
213
		fTableViewer.setCellEditors(cellEditors);
214
		fTableViewer.setColumnProperties(new String[] { ITEM,
215
				PROPERTY_ALTERNATIVE_LIST });
216
		fTableViewer.setCellModifier(this);
217
		fTableViewer.setInput(fAlternatives);
218
219
		return table;
220
	}
221
222
	public Object getValue(Object element, String property) {
223
224
		final Item item = (Item) element;
225
226
		if (PROPERTY_ALTERNATIVE_LIST.equals(property)) {
227
			return new Integer(item.selected);
228
		}
229
		return null;
230
	}
231
232
	public boolean canModify(Object element, String property) {
233
		// set the correct cell editor for this element
234
		cellEditors[1] = getCellEditor(element);
235
		// only allow modification for editable elements
236
		return PROPERTY_ALTERNATIVE_LIST.equals(property);
237
	}
238
239
	private CellEditor getCellEditor(Object element) {
240
241
		if (element instanceof RepositoryLocationItem) {
242
243
			// create combo-box list of alternative repositories
244
			List alternativeList = ((RepositoryLocationItem) element).alternativeList;
245
			String[] alternativeNames = new String[alternativeList.size()];
246
			int i = 0;
247
			for (Iterator iterator = alternativeList.iterator(); iterator
248
					.hasNext();) {
249
				CVSRepositoryLocation repo = (CVSRepositoryLocation) iterator
250
						.next();
251
				alternativeNames[i++] = repo.getLocation();
252
			}
253
			return new ComboBoxCellEditor(table, alternativeNames,
254
					SWT.READ_ONLY);
255
		}
256
		return dummyAlternativeRepositoryEditor;
257
	}
258
259
	public void modify(Object element, String property, Object value) {
260
261
		final IStructuredSelection selection = (IStructuredSelection) fTableViewer
262
				.getSelection();
263
		final Item item = (Item) selection.getFirstElement();
264
		if (item == null)
265
			return;
266
267
		final int comboIndex = ((Integer) value).intValue();
268
269
		if (PROPERTY_ALTERNATIVE_LIST.equals(property)) {
270
			item.selected = comboIndex;
271
		}
272
		fTableViewer.refresh(item);
273
	}
274
275
	public Image getColumnImage(Object element, int columnIndex) {
276
		return null;
277
	}
278
279
	public String getColumnText(Object element, int columnIndex) {
280
		final Item item = (Item) element;
281
282
		switch (columnIndex) {
283
		case 0:
284
			return fShowConnectionMethod ? item.location.getLocation(false)
285
					: excludeConnectionMethod(item.location);
286
		case 1:
287
			return ((CVSRepositoryLocation) item.alternativeList
288
					.get(item.selected)).getLocation();
289
		default:
290
			return null;
291
		}
292
	}
293
294
	public void addListener(ILabelProviderListener listener) {
295
	}
296
297
	public void dispose() {
298
	}
299
300
	public boolean isLabelProperty(Object element, String property) {
301
		return false;
302
	}
303
304
	public void removeListener(ILabelProviderListener listener) {
305
	}
306
307
	public Object[] getElements(Object inputElement) {
308
		return ((Collection) inputElement).toArray();
309
	}
310
311
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
312
	}
313
314
	public IStructuredSelection getSelection() {
315
		return (IStructuredSelection) fTableViewer.getSelection();
316
	}
317
318
	public TableViewer getViewer() {
319
		return fTableViewer;
320
	}
321
322
	/**
323
	 * @return a selected (in a combo box) alternative repository location for
324
	 *         the first selected element
325
	 */
326
	public CVSRepositoryLocation getSelectedAlternativeRepository() {
327
		RepositoryLocationItem firstElement = (RepositoryLocationItem) getSelection()
328
				.getFirstElement();
329
		return (CVSRepositoryLocation) firstElement.alternativeList
330
				.get(firstElement.selected);
331
	}
332
333
	public void addAlternativeRepositoryToSelection(
334
			ICVSRepositoryLocation location) {
335
		// add newly created repository location to all selected elements
336
		for (Iterator iterator = getSelection().iterator(); iterator.hasNext();) {
337
			RepositoryLocationItem selectedItem = (RepositoryLocationItem) iterator
338
					.next();
339
			selectedItem.alternativeList.add(0, location);
340
			selectedItem.selected = 0;
341
			// fTableViewer.refresh(selectedItem);
342
		}
343
344
		// add newly created repository location to not-selected elements
345
		// new location must be compatible with the one from the project set
346
		for (int i = 0; i < fTableViewer.getTable().getItemCount(); i++) {
347
			Object element = fTableViewer.getElementAt(i);
348
			if (!getSelection().toList().contains(element)) {
349
				RepositoryLocationItem locationItem = (RepositoryLocationItem) element;
350
				if (CVSProjectSetCapability.isCompatible(location,
351
						locationItem.location)) {
352
					locationItem.alternativeList.add(location);
353
				}
354
			}
355
		}
356
357
		// update labels because of the first loop - first item changed
358
		fTableViewer.refresh(true);
359
	}
360
361
	/**
362
	 * @return A map with repository location from the project set as a key and
363
	 *         selected repository location from a combo box as value.
364
	 */
365
	public Map getSelected() {
366
		Map map = new HashMap();
367
		for (Iterator iterator = fAlternatives.iterator(); iterator.hasNext();) {
368
			ConfigureRepositoryLocationsTable.RepositoryLocationItem rli = (ConfigureRepositoryLocationsTable.RepositoryLocationItem) iterator
369
					.next();
370
			map.put(rli.location, rli.alternativeList.get(rli.selected));
371
		}
372
		return map;
373
	}
374
375
	public void setShowConnectionMethod(boolean show) {
376
		fShowConnectionMethod = show;
377
		fTableViewer.refresh(true);
378
	}
379
380
	private String excludeConnectionMethod(ICVSRepositoryLocation location) {
381
		String user = location.getUsername();
382
		String host = location.getHost();
383
		int port = location.getPort();
384
		String root = location.getRootDirectory();
385
386
		return (user != null && !user.equals("") ? (user + CVSRepositoryLocation.HOST_SEPARATOR) //$NON-NLS-1$
387
				: "") + //$NON-NLS-1$ 
388
				host
389
				+ CVSRepositoryLocation.COLON
390
				+ ((port == CVSRepositoryLocation.USE_DEFAULT_PORT) ? "" : (new Integer(port).toString())) + //$NON-NLS-1$ 
391
				root;
392
	}
393
394
	public boolean noDuplicateRepositoryLocationFound() {
395
		return fNoDuplicateRepositoryLocationFound;
396
	}
397
}
(-)src/org/eclipse/team/internal/ccvs/ui/ConfigureRepositoryLocationsDialog.java (+229 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.team.internal.ccvs.ui;
12
13
import java.util.Map;
14
import java.util.Properties;
15
16
import org.eclipse.jface.dialogs.*;
17
import org.eclipse.jface.dialogs.Dialog;
18
import org.eclipse.jface.viewers.*;
19
import org.eclipse.jface.wizard.IWizard;
20
import org.eclipse.jface.wizard.WizardDialog;
21
import org.eclipse.swt.SWT;
22
import org.eclipse.swt.graphics.Image;
23
import org.eclipse.swt.layout.GridData;
24
import org.eclipse.swt.layout.GridLayout;
25
import org.eclipse.swt.widgets.*;
26
import org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation;
27
import org.eclipse.team.internal.ccvs.core.connection.CVSRepositoryLocation;
28
import org.eclipse.team.internal.ccvs.ui.wizards.AlternativeLocationWizard;
29
import org.eclipse.ui.PlatformUI;
30
31
public class ConfigureRepositoryLocationsDialog extends TitleAreaDialog {
32
33
	private Image dlgTitleImage;
34
	private ConfigureRepositoryLocationsTable fConfigureRepositoryLocationsTable;
35
36
	/**
37
	 * Creates a new AlternativeRepositoryDialog.
38
	 * 
39
	 * @param parentShell
40
	 *            the parent shell
41
	 * @param alternativesMap
42
	 *            Map with a repository location (ICVSRepositoryLocation) from
43
	 *            the Team Project Set as a key and list of alternatives found
44
	 *            (also ICVSRepositoryLocation) as a value.
45
	 * @param message
46
	 *            a message to display to the user
47
	 */
48
	public ConfigureRepositoryLocationsDialog(Shell parentShell, Map alternativesMap) {
49
		super(parentShell);
50
		setShellStyle(getShellStyle() | SWT.RESIZE);
51
		fConfigureRepositoryLocationsTable = new ConfigureRepositoryLocationsTable(
52
				alternativesMap);
53
	}
54
55
	/*
56
	 * (non-Javadoc)
57
	 * 
58
	 * @see org.eclipse.jface.dialogs.TitleAreaDialog#createContents(org.eclipse.swt.widgets.Composite)
59
	 */
60
	protected Control createContents(Composite parent) {
61
		Control contents = super.createContents(parent);
62
		setTitle(CVSUIMessages.ConfigureRepositoryLocationsWizard_title);
63
		setMessage(CVSUIMessages.ConfigureRepositoryLocationsWizard_message);
64
		dlgTitleImage = CVSUIPlugin.getPlugin().getImageDescriptor(
65
				ICVSUIConstants.IMG_WIZBAN_NEW_LOCATION).createImage();
66
		setTitleImage(dlgTitleImage);
67
		return contents;
68
	}
69
70
	public boolean close() {
71
		if (dlgTitleImage != null) {
72
			dlgTitleImage.dispose();
73
		}
74
		return super.close();
75
	}
76
77
	/*
78
	 * (non-Javadoc) Method declared in Window.
79
	 */
80
	protected void configureShell(Shell shell) {
81
		super.configureShell(shell);
82
		shell.setText(CVSUIMessages.ConfigureRepositoryLocationsWizard_title);
83
		// set F1 help
84
		PlatformUI.getWorkbench().getHelpSystem().setHelp(shell,
85
				IHelpContextIds.ALTERNATIVE_REPOSITORY_DIALOG);
86
	}
87
88
	/**
89
	 * @see Dialog#createDialogArea
90
	 */
91
	protected Control createDialogArea(Composite parent) {
92
		initializeDialogUnits(parent);
93
94
		final Composite composite = new Composite(parent, SWT.NONE);
95
		composite.setLayout(new GridLayout(2, false));
96
97
		GridData childData = new GridData(GridData.FILL_BOTH);
98
		composite.setLayoutData(childData);
99
100
		Composite table = fConfigureRepositoryLocationsTable.createControl(composite);
101
		GridData gridData = new GridData(GridData.VERTICAL_ALIGN_FILL);
102
		gridData.horizontalSpan = 2;
103
		gridData.horizontalAlignment = GridData.FILL;
104
		gridData.grabExcessHorizontalSpace = true;
105
		gridData.grabExcessVerticalSpace = true;
106
		table.setLayoutData(gridData);
107
108
		final Button showMethodButton = new Button(composite, SWT.CHECK);
109
		showMethodButton
110
				.setText(CVSUIMessages.ConfigureRepositoryLocationsWizard_showConnection);
111
		showMethodButton.addListener(SWT.Selection, new Listener() {
112
			public void handleEvent(Event event) {
113
				fConfigureRepositoryLocationsTable
114
						.setShowConnectionMethod(showMethodButton
115
								.getSelection());
116
			}
117
		});
118
		showMethodButton.setEnabled(fConfigureRepositoryLocationsTable
119
				.noDuplicateRepositoryLocationFound());
120
		showMethodButton.setSelection(!fConfigureRepositoryLocationsTable
121
				.noDuplicateRepositoryLocationFound());
122
		showMethodButton.setLayoutData(new GridData(
123
				GridData.HORIZONTAL_ALIGN_BEGINNING));
124
125
		final Button createLocationButton = new Button(composite, SWT.PUSH);
126
		createLocationButton
127
				.setText(CVSUIMessages.ConfigureRepositoryLocationsWizard_createLocation);
128
		createLocationButton
129
				.setToolTipText(CVSUIMessages.ConfigureRepositoryLocationsWizard_createLocationTooltip);
130
		createLocationButton.addListener(SWT.Selection, new Listener() {
131
			public void handleEvent(Event event) {
132
133
				CVSRepositoryLocation selectedAlternativeRepository = fConfigureRepositoryLocationsTable
134
						.getSelectedAlternativeRepository();
135
136
				Properties properties = new Properties();
137
				properties
138
						.put(
139
								"connection", selectedAlternativeRepository.getMethod().getName()); //$NON-NLS-1$
140
				properties.put(
141
						"user", selectedAlternativeRepository.getUsername()); //$NON-NLS-1$
142
				// TODO: retrieve password (if available) and use it to prime
143
				// the field
144
				// properties.put("password", ""); //$NON-NLS-1$
145
				properties.put("host", selectedAlternativeRepository.getHost()); //$NON-NLS-1$
146
				int port = selectedAlternativeRepository.getPort();
147
				if (port != ICVSRepositoryLocation.USE_DEFAULT_PORT)
148
					properties.put("port", String.valueOf(port)); //$NON-NLS-1$
149
				properties
150
						.put(
151
								"root", selectedAlternativeRepository.getRootDirectory()); //$NON-NLS-1$
152
153
				AlternativeLocationWizard wizard = new AlternativeLocationWizard(
154
						properties);
155
				wizard.setSwitchPerspectives(false);
156
				WizardDialog dialog = new ConfigureRepositoryLocationsWizardDialog(
157
						getShell(), wizard);
158
				dialog.open();
159
160
				ICVSRepositoryLocation location = wizard.getLocation();
161
				if (location != null)
162
					fConfigureRepositoryLocationsTable
163
							.addAlternativeRepositoryToSelection(location);
164
			}
165
		});
166
		createLocationButton.setEnabled(fConfigureRepositoryLocationsTable
167
				.getSelection().getFirstElement() != null);
168
		createLocationButton.setLayoutData(new GridData(
169
				GridData.HORIZONTAL_ALIGN_END));
170
171
		fConfigureRepositoryLocationsTable.getViewer().addSelectionChangedListener(
172
				new ISelectionChangedListener() {
173
					public void selectionChanged(SelectionChangedEvent event) {
174
						IStructuredSelection sel = (IStructuredSelection) event
175
								.getSelection();
176
						Object firstElement = sel.getFirstElement();
177
						createLocationButton.setEnabled(firstElement != null);
178
					}
179
				});
180
181
		return composite;
182
	}
183
184
	public Map getSelected() {
185
		return fConfigureRepositoryLocationsTable.getSelected();
186
	}
187
188
	/*
189
	 * (non-Javadoc)
190
	 * 
191
	 * @see org.eclipse.jface.dialogs.Dialog#getDialogBoundsSettings()
192
	 */
193
	protected IDialogSettings getDialogBoundsSettings() {
194
		String sectionName = getClass().getName() + "_dialogBounds"; //$NON-NLS-1$
195
		IDialogSettings settings = CVSUIPlugin.getPlugin().getDialogSettings();
196
		IDialogSettings section = settings.getSection(sectionName);
197
		if (section == null)
198
			section = settings.addNewSection(sectionName);
199
		return section;
200
	}
201
202
	/*
203
	 * @see org.eclipse.jface.dialogs.Dialog#getDialogBoundsStrategy()
204
	 * @since 3.2
205
	 */
206
	protected int getDialogBoundsStrategy() {
207
		return DIALOG_PERSISTLOCATION | DIALOG_PERSISTSIZE;
208
	}
209
	
210
	/**
211
	 * This class is made only to change Wizard's default "Finish" button label
212
	 * to "Create".
213
	 */
214
	private class ConfigureRepositoryLocationsWizardDialog extends WizardDialog {
215
216
		public ConfigureRepositoryLocationsWizardDialog(Shell parentShell,
217
				IWizard newWizard) {
218
			super(parentShell, newWizard);
219
		}
220
221
		protected Button createButton(Composite parent, int id, String label,
222
				boolean defaultButton) {
223
			if (id == IDialogConstants.FINISH_ID)
224
				label = CVSUIMessages.ConfigureRepositoryLocationsWizardDialog_finish;
225
			return super.createButton(parent, id, label, defaultButton);
226
		}
227
228
	}
229
}
(-)src/org/eclipse/team/internal/ccvs/core/CVSProjectSetCapability.java (-26 / +25 lines)
Lines 15-22 Link Here
15
import java.io.File;
15
import java.io.File;
16
import java.net.URI;
16
import java.net.URI;
17
import java.util.*;
17
import java.util.*;
18
18
 import org.eclipse.core.resources.*;
19
import org.eclipse.core.resources.*;
20
import org.eclipse.core.runtime.*;
19
import org.eclipse.core.runtime.*;
21
import org.eclipse.core.runtime.jobs.ISchedulingRule;
20
import org.eclipse.core.runtime.jobs.ISchedulingRule;
22
import org.eclipse.core.runtime.jobs.MultiRule;
21
import org.eclipse.core.runtime.jobs.MultiRule;
Lines 121-128 Link Here
121
 		if (projects == null)
120
 		if (projects == null)
122
 			return new IProject[0];
121
 			return new IProject[0];
123
122
124
 		Map alternativeMap = new HashMap();
123
 		Map alternativeMap = isAdditionRepositoryInformationRequired(projects, infoMap);
125
		if (isAdditionRepositoryInformationRequired(projects, infoMap, alternativeMap)) {
124
		if (!alternativeMap.isEmpty()) {
126
			// display the dialog
125
			// display the dialog
127
			Map alternativeRespositoriesMap = promptForAdditionRepositoryInformation(alternativeMap);
126
			Map alternativeRespositoriesMap = promptForAdditionRepositoryInformation(alternativeMap);
128
			// replace repository location from a project load info with one from the prompter
127
			// replace repository location from a project load info with one from the prompter
Lines 605-618 Link Here
605
	 * @see org.eclipse.team.internal.ccvs.ui.AlternativeRepositoryTable
604
	 * @see org.eclipse.team.internal.ccvs.ui.AlternativeRepositoryTable
606
	 * 
605
	 * 
607
	 * @param projects
606
	 * @param projects
608
	 *            an array of project to check out
607
	 *            an array of project to check out a mapping of project to
609
	 * @param infoMap
608
	 *            project load information
610
	 *            a mapping of project to project load information
609
	 * 
611
	 * @param alternativeMap
610
	 * @return a mapping of project to project load information
612
	 * 
611
	 * 
613
	 * Initially it's an empty map. When <code>true</code> is returned the map
612
	 * 
614
	 * will contain a mapping of a repository location (<code>ICVSRepositoryLocation</code>)
613
	 * When non-empty map is returned it will contain a mapping of a repository
615
	 * from the project set to a list of suggested, known repositories locations (<code>ICVSRepositoryLocation</code>)
614
	 * location (<code>ICVSRepositoryLocation</code>) from the project set
615
	 * to a list of suggested, known repositories locations (<code>ICVSRepositoryLocation</code>)
616
	 * to use. The list contains at least one element - a default location (same
616
	 * to use. The list contains at least one element - a default location (same
617
	 * as in the project set). It's always on the first position in the list.
617
	 * as in the project set). It's always on the first position in the list.
618
	 * It's possible that the repository location is known, but even then we
618
	 * It's possible that the repository location is known, but even then we
Lines 632-650 Link Here
632
	 * <li>other known locations - no particular order here neither</li>
632
	 * <li>other known locations - no particular order here neither</li>
633
	 * </ul>
633
	 * </ul>
634
	 * </p>
634
	 * </p>
635
	 * @return <code>false</code> when the project set file contains all
635
	 * An empty map is returned when the project set file contains all required
636
	 *         required information or <code>true</code> when Alternative
636
	 * information.
637
	 *         Repository dialog needs to be displayed.
638
	 * 
639
	 * 
640
	 */
637
	 */
641
	private static boolean isAdditionRepositoryInformationRequired(
638
	private static Map isAdditionRepositoryInformationRequired(
642
			IProject[] projects, final Map infoMap, Map alternativeMap) {
639
			IProject[] projects, final Map infoMap) {
643
		
640
		
644
		List confirmedProjectsList = Arrays.asList(projects);
641
		List confirmedProjectsList = Arrays.asList(projects);
645
		
642
		
646
		if (infoMap == null)
643
		if (infoMap == null)
647
			return false;
644
			return Collections.EMPTY_MAP;
648
645
649
		Set projectSetRepositoryLocations = new HashSet();
646
		Set projectSetRepositoryLocations = new HashSet();
650
		for (Iterator iterator = infoMap.keySet().iterator(); iterator
647
		for (Iterator iterator = infoMap.keySet().iterator(); iterator
Lines 658-669 Link Here
658
		
655
		
659
		// none of projects from project sets is confirmed to overwrite
656
		// none of projects from project sets is confirmed to overwrite
660
		if (projectSetRepositoryLocations.isEmpty()) {
657
		if (projectSetRepositoryLocations.isEmpty()) {
661
			return false;
658
			return Collections.EMPTY_MAP;
662
		}
659
		}
663
		
660
		
664
		List knownRepositories = Arrays.asList(KnownRepositories.getInstance()
661
		List knownRepositories = Arrays.asList(KnownRepositories.getInstance()
665
				.getRepositories());
662
				.getRepositories());
666
663
		
664
		Map resultMap = new HashMap();
665
		
667
		if (knownRepositories.isEmpty()) {
666
		if (knownRepositories.isEmpty()) {
668
			// there are no known repositories so use repository location from
667
			// there are no known repositories so use repository location from
669
			// the project set
668
			// the project set
Lines 673-679 Link Here
673
						.next();
672
						.next();
674
				ArrayList alternativeList = new ArrayList(1);
673
				ArrayList alternativeList = new ArrayList(1);
675
				alternativeList.add(projectSetRepositoryLocation);
674
				alternativeList.add(projectSetRepositoryLocation);
676
				alternativeMap.put(projectSetRepositoryLocation,
675
				resultMap.put(projectSetRepositoryLocation,
677
						alternativeList);
676
						alternativeList);
678
			}
677
			}
679
		} else if (!knownRepositories.containsAll(projectSetRepositoryLocations)) {
678
		} else if (!knownRepositories.containsAll(projectSetRepositoryLocations)) {
Lines 703-715 Link Here
703
				// repository is known.
702
				// repository is known.
704
				alternativeList.add(0, projectSetRepositoryLocation);
703
				alternativeList.add(0, projectSetRepositoryLocation);
705
704
706
				alternativeMap.put(projectSetRepositoryLocation,
705
				resultMap.put(projectSetRepositoryLocation,
707
						alternativeList);
706
						alternativeList);
708
			}
707
			}
709
		} // else { all repositories are known, we don't need to prompt for
708
		} // else { all repositories are known, we don't need to prompt for
710
			// additional information }
709
			// additional information }
711
		
710
		
712
		return !alternativeMap.isEmpty();
711
		return resultMap;
713
	}
712
	}
714
	
713
	
715
	/**
714
	/**
Lines 730-735 Link Here
730
	
729
	
731
	private Map promptForAdditionRepositoryInformation(Map alternativeMap) {
730
	private Map promptForAdditionRepositoryInformation(Map alternativeMap) {
732
		IUserAuthenticator authenticator = CVSRepositoryLocation.getAuthenticator();
731
		IUserAuthenticator authenticator = CVSRepositoryLocation.getAuthenticator();
733
		return authenticator.promptForAlternativeRepository(alternativeMap);
732
		return authenticator.promptToConfigureRepositoryLocations(alternativeMap);
734
	}
733
	}
735
}
734
}
(-)src/org/eclipse/team/internal/ccvs/core/IUserAuthenticator.java (-3 / +3 lines)
Lines 141-152 Link Here
141
	 * 
141
	 * 
142
	 * @param alternativeMap
142
	 * @param alternativeMap
143
	 *            a map of CVS repository locations form the project set (as
143
	 *            a map of CVS repository locations form the project set (as
144
	 *            keys) and a list of suggested alternative CVS repository
144
	 *            keys) and a list of suggested alternative (known) CVS
145
	 *            locations (as values)
145
	 *            repository locations (as values)
146
	 * @return a map of CVS repository locations from the project set (as keys)
146
	 * @return a map of CVS repository locations from the project set (as keys)
147
	 *         and confirmed CVS repository locations to be used during checkout
147
	 *         and confirmed CVS repository locations to be used during checkout
148
	 *         (as values) or <code>null</code> if the operation is to be
148
	 *         (as values) or <code>null</code> if the operation is to be
149
	 *         canceled
149
	 *         canceled
150
	 */
150
	 */
151
	public abstract Map promptForAlternativeRepository(Map alternativeMap);
151
	public abstract Map promptToConfigureRepositoryLocations(Map alternativeMap);
152
}
152
}
(-)src/org/eclipse/team/tests/ccvs/core/TestsUserAuthenticator.java (-1 / +1 lines)
Lines 46-52 Link Here
46
        return false;
46
        return false;
47
    }
47
    }
48
48
49
	public Map promptForAlternativeRepository(Map alternativeMap) {
49
	public Map promptToConfigureRepositoryLocations(Map alternativeMap) {
50
		return null;
50
		return null;
51
	}
51
	}
52
}
52
}

Return to bug 159258