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

Collapse All | Expand All

(-)src/org/eclipse/team/tests/ccvs/core/TestsUserAuthenticator.java (+6 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.team.tests.ccvs.core;
11
package org.eclipse.team.tests.ccvs.core;
12
12
13
import java.util.Map;
14
13
import org.eclipse.team.internal.ccvs.core.*;
15
import org.eclipse.team.internal.ccvs.core.*;
14
16
15
/**
17
/**
Lines 40-43 Link Here
40
    public boolean promptForHostKeyChange(ICVSRepositoryLocation location) {
42
    public boolean promptForHostKeyChange(ICVSRepositoryLocation location) {
41
        return false;
43
        return false;
42
    }
44
    }
45
46
	public Object promptForAlternativeRepository(Map alternativeMap) {
47
		return null;
48
	}
43
}
49
}
(-)src/org/eclipse/team/internal/ccvs/core/CVSProjectSetCapability.java (-16 / +137 lines)
Lines 14-27 Link Here
14
14
15
import java.io.File;
15
import java.io.File;
16
import java.net.URI;
16
import java.net.URI;
17
import java.util.ArrayList;
17
import java.util.*;
18
import java.util.Collection;
19
import java.util.HashMap;
20
import java.util.HashSet;
21
import java.util.List;
22
import java.util.Map;
23
import java.util.Set;
24
import java.util.StringTokenizer;
25
18
26
import org.eclipse.core.resources.*;
19
import org.eclipse.core.resources.*;
27
import org.eclipse.core.runtime.*;
20
import org.eclipse.core.runtime.*;
Lines 122-134 Link Here
122
115
123
		// Confirm the projects to be loaded
116
		// Confirm the projects to be loaded
124
		Map infoMap = new HashMap(referenceStrings.length);
117
		Map infoMap = new HashMap(referenceStrings.length);
125
		IProject[] projects = asProjects(referenceStrings, infoMap);
118
 		IProject[] projects = asProjects(referenceStrings, infoMap);
126
		projects = confirmOverwrite(context, projects);
119
		
127
		if (projects == null)
120
 		projects = confirmOverwrite(context, projects);
128
			throw new OperationCanceledException();
121
 		if (projects == null)
122
 			return new IProject[0];
123
124
 		Map alternativeMap = new HashMap();
125
		if (isAlternativeRepositoryNeeded(projects, infoMap, alternativeMap)) {
126
			Object alternativeRespositoriesMap = promptForAlternativeRespository(alternativeMap);
127
			// replace repositoryLocations in infoMap to the ones from prompter
128
			if (alternativeRespositoriesMap != null) {
129
				for (Iterator iterator = infoMap.values().iterator(); iterator
130
						.hasNext();) {
131
					LoadInfo loadInfoForProject = (LoadInfo) iterator.next();
132
					ICVSRepositoryLocation selectedAlternativeRepository = (ICVSRepositoryLocation) ((Map) alternativeRespositoriesMap)
133
							.get(loadInfoForProject.repositoryLocation
134
									.getLocation(false));
135
					// TODO: final modifier removed for repositoryLocation :/
136
					// (create a copy of LoadInfo?)
137
					loadInfoForProject.repositoryLocation = selectedAlternativeRepository;
138
				}
139
			} else {
140
				// operation canceled
141
				return new IProject[0];
142
			}
143
		}
144
		
145
 		// Load the projects
146
 		return checkout(projects, infoMap, monitor);
129
147
130
		// Load the projects
131
		return checkout(projects, infoMap, monitor);
132
	}
148
	}
133
149
134
	/**
150
	/**
Lines 198-204 Link Here
198
	 * Internal class for adding projects to the workspace 
214
	 * Internal class for adding projects to the workspace 
199
	 */
215
	 */
200
	class LoadInfo {
216
	class LoadInfo {
201
		private final ICVSRepositoryLocation repositoryLocation;
217
		private ICVSRepositoryLocation repositoryLocation;
202
		private final String module;
218
		private final String module;
203
		private final IProject project;
219
		private final IProject project;
204
		private final CVSTag tag;
220
		private final CVSTag tag;
Lines 276-282 Link Here
276
			}
292
			}
277
		}
293
		}
278
		// No existing location was found so add this location to the list of known repositories
294
		// No existing location was found so add this location to the list of known repositories
279
		KnownRepositories.getInstance().addRepository(newLocation, true);
295
		// TODO: commented out (if we add repository here we won't be able to check for alternatives)
296
		// KnownRepositories.getInstance().addRepository(newLocation, true);
280
		return newLocation;
297
		return newLocation;
281
	}
298
	}
282
	
299
	
Lines 578-582 Link Here
578
			return null;
595
			return null;
579
		}
596
		}
580
	}
597
	}
598
	
599
	private static boolean isAlternativeRepositoryNeeded(
600
			IProject[] projects, final Map infoMap, Map alternativeMap) {
601
		
602
		List confirmedProjectsList = Arrays.asList(projects);
603
		
604
		if (infoMap == null)
605
			return false;
606
607
		Set projectSetRepositories = new HashSet();
608
		for (Iterator iterator = infoMap.keySet().iterator(); iterator
609
				.hasNext();) {
610
			IProject project = (IProject) iterator.next();
611
			if (confirmedProjectsList.contains(project)) {
612
				LoadInfo loadInfo = (LoadInfo) infoMap.get(project);
613
				projectSetRepositories.add(loadInfo.repositoryLocation);
614
			}
615
		}
616
		
617
		// none of projects from project sets is confirmed to overwrite
618
		if (projectSetRepositories.isEmpty()) {
619
			return false;
620
		}
621
		
622
		List knownRepositories = Arrays.asList(KnownRepositories.getInstance()
623
				.getRepositories());
624
625
		if (knownRepositories.isEmpty()) {
626
			// there are no known repositories so use repository location from
627
			// the project set
628
			for (Iterator iterator = projectSetRepositories.iterator(); iterator
629
					.hasNext();) {
630
				ICVSRepositoryLocation projectSetRepositoryLocation = (ICVSRepositoryLocation) iterator
631
						.next();
632
				ArrayList alternativeList = new ArrayList(1);
633
				alternativeList.add(projectSetRepositoryLocation);
634
				alternativeMap.put(projectSetRepositoryLocation,
635
						alternativeList);
636
			}
637
		} else if (!knownRepositories.containsAll(projectSetRepositories)) {
638
			// not all repositories from the project set are known
581
639
640
			for (Iterator iterator = projectSetRepositories.iterator(); iterator
641
					.hasNext();) {
642
				ICVSRepositoryLocation projectSetRepositoryLocation = (ICVSRepositoryLocation) iterator
643
						.next();
644
645
				if (knownRepositories.contains(projectSetRepositoryLocation)) {
646
					// hey, we know you
647
					ArrayList alternativeList = new ArrayList(1);
648
					alternativeList.add(projectSetRepositoryLocation);
649
					alternativeMap.put(projectSetRepositoryLocation,
650
							alternativeList);
651
				} else {
652
					ArrayList alternativeList = new ArrayList();
653
					boolean compatibleFound = false;
654
					for (Iterator iterator2 = knownRepositories.iterator(); iterator2
655
							.hasNext();) {
656
						ICVSRepositoryLocation knownRepositoryLocation = (ICVSRepositoryLocation) iterator2
657
								.next();
658
						if (isCompatible(knownRepositoryLocation,
659
								projectSetRepositoryLocation)) {
660
							// compatible repositories first
661
							alternativeList.add(0, knownRepositoryLocation);
662
							compatibleFound = true;
663
						} else {
664
							alternativeList.add(knownRepositoryLocation);
665
						}
666
667
						// if no compatible repository found add the one from
668
						// the project set at the beginning
669
					}
670
					
671
					if (!compatibleFound)
672
						alternativeList.add(0, projectSetRepositoryLocation);
673
674
					alternativeMap.put(projectSetRepositoryLocation,
675
							alternativeList);
676
				}
677
			}
678
		}
679
		
680
		return !alternativeMap.isEmpty();
681
	}
682
	
683
	/**
684
	 * Same test as in org.eclipse.team.internal.ccvs.ui.CVSProjectPropertiesPage
685
	 * 
686
	 * @see org.eclipse.team.internal.ccvs.ui.CVSProjectPropertiesPage#isCompatible
687
	 * 
688
	 * @param location A location from known repositories collection
689
	 * @param oldLocation A location to check c
690
	 * @return Are given locations compatible
691
	 */
692
	private static boolean isCompatible(ICVSRepositoryLocation location, ICVSRepositoryLocation oldLocation) {
693
		if (!location.getHost().equals(oldLocation.getHost())) return false;
694
		if (!location.getRootDirectory().equals(oldLocation.getRootDirectory())) return false;
695
		if (location.equals(oldLocation)) return false;
696
		return true;
697
	}
698
	
699
	private Object promptForAlternativeRespository(Map alternativeMap) {
700
		IUserAuthenticator prompter = CVSRepositoryLocation.getAuthenticator();
701
		return prompter.promptForAlternativeRepository(alternativeMap);
702
	}
582
}
703
}
(-)src/org/eclipse/team/internal/ccvs/core/IUserAuthenticator.java (+14 lines)
Lines 11-16 Link Here
11
 *******************************************************************************/
11
 *******************************************************************************/
12
package org.eclipse.team.internal.ccvs.core;
12
package org.eclipse.team.internal.ccvs.core;
13
13
14
import java.util.Map;
15
14
/**
16
/**
15
 * IUserAuthenticators are used to ensure that the user
17
 * IUserAuthenticators are used to ensure that the user
16
 * is validated for access to a given repository.  The
18
 * is validated for access to a given repository.  The
Lines 130-133 Link Here
130
     * @return true if new host key should be accepted
132
     * @return true if new host key should be accepted
131
     */
133
     */
132
    public boolean promptForHostKeyChange(ICVSRepositoryLocation location);
134
    public boolean promptForHostKeyChange(ICVSRepositoryLocation location);
135
    
136
    /**
137
	 * @param alternativeMap
138
	 *            a map of CVS repository locations form the project set (as
139
	 *            keys) and a list of suggested alternative CVS repository
140
	 *            locations (as values)
141
	 * @return a map of CVS repository locations from the project set (as keys)
142
	 *         and confirmed CVS repository locations to be used during checkout
143
	 *         (as values) or <code>null</code> if the operation is to be
144
	 *         canceled
145
	 */
146
	public abstract Object promptForAlternativeRepository(Map alternativeMap);
133
}
147
}
(-)src/org/eclipse/team/internal/ccvs/ui/CVSUIMessages.java (+15 lines)
Lines 336-341 Link Here
336
	public static String CommitWizardFileTypePage_0;
336
	public static String CommitWizardFileTypePage_0;
337
	public static String CommitWizardFileTypePage_2;
337
	public static String CommitWizardFileTypePage_2;
338
	public static String CommitWizardFileTypePage_3;
338
	public static String CommitWizardFileTypePage_3;
339
	
340
	public static String AlternativeRepositoryWizard_title;
341
	public static String AlternativeRepositoryWizard_message;
342
	public static String AlternativeRepositoryWizard_createLocation;
343
	public static String AlternativeRepositoryWizard_createLocationTooltip;
344
	public static String AlternativeRepositoryWizard_column0;
345
	public static String AlternativeRepositoryWizard_column1;
339
346
340
	public static String CommitSyncAction_questionRelease;
347
	public static String CommitSyncAction_questionRelease;
341
	public static String CommitSyncAction_titleRelease;
348
	public static String CommitSyncAction_titleRelease;
Lines 493-498 Link Here
493
	public static String NewLocationWizard_validationFailedText;
500
	public static String NewLocationWizard_validationFailedText;
494
	public static String NewLocationWizard_validationFailedTitle;
501
	public static String NewLocationWizard_validationFailedTitle;
495
	public static String NewLocationWizard_exception;
502
	public static String NewLocationWizard_exception;
503
	
504
	public static String AlternativeLocationWizard_title;
505
	public static String AlternativeLocationWizard_heading;
506
	public static String AlternativeLocationWizard_description;
507
	public static String AlternativeLocationWizard_validationFailedText;
508
	public static String AlternativeLocationWizard_validationFailedTitle;
509
	public static String AlternativeLocationWizard_exception;
510
496
511
497
	public static String OpenLogEntryAction_deletedTitle;
512
	public static String OpenLogEntryAction_deletedTitle;
498
	public static String OpenLogEntryAction_deleted;
513
	public static String OpenLogEntryAction_deleted;
(-)src/org/eclipse/team/internal/ccvs/ui/WorkbenchUserAuthenticator.java (+30 lines)
Lines 11-16 Link Here
11
 *******************************************************************************/
11
 *******************************************************************************/
12
package org.eclipse.team.internal.ccvs.ui;
12
package org.eclipse.team.internal.ccvs.ui;
13
13
14
import java.util.Map;
15
14
import org.eclipse.core.runtime.OperationCanceledException;
16
import org.eclipse.core.runtime.OperationCanceledException;
15
import org.eclipse.jface.dialogs.*;
17
import org.eclipse.jface.dialogs.*;
16
import org.eclipse.jface.window.Window;
18
import org.eclipse.jface.window.Window;
Lines 321-324 Link Here
321
        }
323
        }
322
        return openConfirm[0];
324
        return openConfirm[0];
323
    }
325
    }
326
    
327
	/*
328
	 * (non-Javadoc)
329
	 * 
330
	 * @see org.eclipse.team.internal.ccvs.core.IUserAuthenticator#promptForAlternativeRepository(java.util.Map)
331
	 */
332
	public Object promptForAlternativeRepository(final Map alternativeMap) {
333
334
		final Object[] result = new Object[1];
335
		Display display = Display.getCurrent();
336
		if (display != null) {
337
			result[0] = openAlternativeRepositoryDialog(alternativeMap);
338
		} else {
339
			// sync exec in default thread
340
			Display.getDefault().syncExec(new Runnable() {
341
				public void run() {
342
					result[0] = openAlternativeRepositoryDialog(alternativeMap);
343
				}
344
			});
345
		}
346
		return result[0];
347
	}
348
	
349
	private Object openAlternativeRepositoryDialog(Map alternativeMap) {
350
		AlternativeRepositoryDialog dialog = new AlternativeRepositoryDialog(null, alternativeMap);
351
		int result = dialog.open();
352
		return result==1?null:dialog.getSelected();
353
	}
324
}
354
}
(-)src/org/eclipse/team/internal/ccvs/ui/messages.properties (+14 lines)
Lines 285-290 Link Here
285
CommitWizardFileTypePage_2=Unknown new files detected.
285
CommitWizardFileTypePage_2=Unknown new files detected.
286
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.
286
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.
287
287
288
AlternativeRepositoryWizard_title=Select alternative repository
289
AlternativeRepositoryWizard_message=Select an alternative repository or create new based on a existing one
290
AlternativeRepositoryWizard_createLocation=Create Location
291
AlternativeRepositoryWizard_createLocationTooltip=Creates Location from a selected alternative repository
292
AlternativeRepositoryWizard_column0=Repository Location from the project set
293
AlternativeRepositoryWizard_column1=Alternative Repository Location
294
288
CommitSyncAction_questionRelease=You have changes that conflict with the server. Release those changes?
295
CommitSyncAction_questionRelease=You have changes that conflict with the server. Release those changes?
289
CommitSyncAction_titleRelease=Confirm Overwrite
296
CommitSyncAction_titleRelease=Confirm Overwrite
290
CommitSyncAction_releaseAll=Release all changes, overriding any conflicting changes on the server.
297
CommitSyncAction_releaseAll=Release all changes, overriding any conflicting changes on the server.
Lines 449-454 Link Here
449
NewLocationWizard_validationFailedTitle=Unable to Validate
456
NewLocationWizard_validationFailedTitle=Unable to Validate
450
NewLocationWizard_exception=Unable to create repository location
457
NewLocationWizard_exception=Unable to create repository location
451
458
459
AlternativeLocationWizard_title=Configure CVS Repository
460
AlternativeLocationWizard_heading=Configure an alternative CVS Repository
461
AlternativeLocationWizard_description=Configure an alternative CVS Repository
462
AlternativeLocationWizard_validationFailedText=Error validating location: "{0}"\n\nUse location anyway?
463
AlternativeLocationWizard_validationFailedTitle=Unable to Validate
464
AlternativeLocationWizard_exception=Unable to create repository location
465
452
OpenLogEntryAction_deletedTitle=Resource is Deleted
466
OpenLogEntryAction_deletedTitle=Resource is Deleted
453
OpenLogEntryAction_deleted=The selected revision represents a deletion. It cannot be opened.
467
OpenLogEntryAction_deleted=The selected revision represents a deletion. It cannot be opened.
454
468
(-)src/org/eclipse/team/internal/ccvs/ui/wizards/NewLocationWizard.java (-2 / +2 lines)
Lines 32-39 Link Here
32
32
33
public class NewLocationWizard extends Wizard implements IWorkbenchWizard {
33
public class NewLocationWizard extends Wizard implements IWorkbenchWizard {
34
	
34
	
35
	private ConfigurationWizardMainPage mainPage;
35
	protected ConfigurationWizardMainPage mainPage;
36
	private Properties properties = null;
36
	protected Properties properties = null;
37
	private boolean switchPerspectives = true;
37
	private boolean switchPerspectives = true;
38
	
38
	
39
	/**
39
	/**
(-)src/org/eclipse/team/internal/ccvs/ui/AlternativeRepositoryTable.java (+290 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.ICVSRepositoryLocation;
25
import org.eclipse.team.internal.ccvs.core.connection.CVSRepositoryLocation;
26
import org.eclipse.team.internal.ui.SWTUtils;
27
28
29
public class AlternativeRepositoryTable implements ICellModifier, 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 String location;
55
		public List alternativeList;
56
		public int selected;
57
58
		public Item(String 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.compareTo(((Item) o).location);
71
		}
72
	}
73
    
74
    public static class RepositoryLocationItem extends Item {
75
		public RepositoryLocationItem(CVSRepositoryLocation repo,
76
				List repositoryLocation) {
77
			super(repo.getLocation(), repositoryLocation);
78
		}
79
	}
80
    
81
    protected static final String ITEM = "item"; //$NON-NLS-1$
82
    protected static final String PROPERTY_ALTERNATIVE_LIST = "alternativeList"; //$NON-NLS-1$
83
84
    private final TableViewer fTableViewer;
85
    private final List fItems;
86
87
	private CellEditor[] cellEditors;
88
89
	private TextCellEditor dummyAlternativeRepositoryEditor;
90
	
91
	private final Table table;
92
    
93
	public AlternativeRepositoryTable(final Composite composite, List items) {
94
95
		fItems = items;
96
97
		/**
98
		 * Create a table.
99
		 */
100
		table = new Table(composite, SWT.V_SCROLL | SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
101
		table.setLayoutData(SWTUtils.createHVFillGridData());
102
		table.setLinesVisible(true);
103
		table.setHeaderVisible(true);
104
		table.addListener(SWT.MeasureItem, new Listener() {
105
			public void handleEvent(Event event) {
106
//				int clientWidth = table.getClientArea().width;
107
				event.height = event.gc.getFontMetrics().getHeight() + 5;
108
//				event.width = clientWidth * 2;
109
			}
110
		});
111
		
112
		/**
113
		 * The 'Project Set repository location' column
114
		 */
115
		final TableColumn projectSetRepositoryColumn = new TableColumn(table, SWT.NONE, 0);
116
		projectSetRepositoryColumn.setText(CVSUIMessages.AlternativeRepositoryWizard_column0);
117
		
118
		/**
119
		 * The 'Alternative repository locations' column
120
		 */
121
		final TableColumn alternativeRepositoryColums = new TableColumn(table, SWT.NONE, 1);
122
		alternativeRepositoryColums.setText(CVSUIMessages.AlternativeRepositoryWizard_column1); 
123
		
124
		composite.addControlListener(new ControlAdapter() {
125
			public void controlResized(ControlEvent e) {
126
				Rectangle area = composite.getClientArea();
127
				Point size = table.computeSize(SWT.DEFAULT, SWT.DEFAULT);
128
				ScrollBar vBar = table.getVerticalBar();
129
				int width = area.width - table.computeTrim(0,0,0,0).width - vBar.getSize().x;
130
				if (size.y > area.height + table.getHeaderHeight()) {
131
					// Subtract the scrollbar width from the total column width
132
					// if a vertical scrollbar will be required
133
					Point vBarSize = vBar.getSize();
134
					width -= vBarSize.x;
135
				}
136
				Point oldSize = table.getSize();
137
				if (oldSize.x > area.width) {
138
					// table is getting smaller so make the columns 
139
					// smaller first and then resize the table to
140
					// match the client area width
141
					projectSetRepositoryColumn.setWidth(width/2);
142
					alternativeRepositoryColums.setWidth(width - projectSetRepositoryColumn.getWidth());
143
					table.setSize(area.width, area.height);
144
				} else {
145
					// table is getting bigger so make the table 
146
					// bigger first and then make the columns wider
147
					// to match the client area width
148
					table.setSize(area.width, area.height);
149
					projectSetRepositoryColumn.setWidth(width/2);
150
					alternativeRepositoryColums.setWidth(width - projectSetRepositoryColumn.getWidth());
151
				}
152
			}
153
		});
154
		
155
		/**
156
		 * Create a viewer for the table.
157
		 */
158
		fTableViewer = new TableViewer(table);
159
		fTableViewer.setContentProvider(this);
160
		fTableViewer.setLabelProvider(this);
161
		fTableViewer.setComparator(new AlternativeRepositoryComparator());
162
		
163
		/**
164
		 * Add a cell editor in the 'Alternative repository locations' column
165
		 */
166
		new TableEditor(table);
167
		
168
		cellEditors = new CellEditor[2];
169
		cellEditors[0] = null;
170
		// to enable cell editing, create a dummy cell editor
171
		cellEditors[1] = dummyAlternativeRepositoryEditor = new TextCellEditor(table, SWT.READ_ONLY);
172
		
173
	    fTableViewer.setCellEditors(cellEditors);
174
	    fTableViewer.setColumnProperties(new String [] { ITEM, PROPERTY_ALTERNATIVE_LIST });
175
		fTableViewer.setCellModifier(this);
176
		fTableViewer.setInput(fItems);
177
	}
178
	
179
180
    public Object getValue(Object element, String property) {
181
    	
182
        final Item item = (Item)element;
183
        
184
        if (PROPERTY_ALTERNATIVE_LIST.equals(property)) {
185
        	return new Integer(item.selected);
186
        }
187
        return null;
188
    }
189
190
    public boolean canModify(Object element, String property) {
191
    	// set the correct cell editor for this element
192
		cellEditors[1] = getCellEditor(element);
193
		// only allow modification for editable elements
194
    	return PROPERTY_ALTERNATIVE_LIST.equals(property);
195
    }
196
197
    private CellEditor getCellEditor(Object element) {
198
    	
199
		if (element instanceof RepositoryLocationItem) {
200
201
			// create combo-box list of alternative repositories
202
			List alternativeList = ((RepositoryLocationItem) element).alternativeList;
203
			String[] alternativeNames = new String[alternativeList.size()];
204
			int i = 0;
205
			for (Iterator iterator = alternativeList.iterator(); iterator.hasNext();) {
206
				CVSRepositoryLocation repo = (CVSRepositoryLocation) iterator.next();
207
				alternativeNames[i++] = repo.getLocation();
208
			}
209
			return new ComboBoxCellEditor(table, alternativeNames,
210
					SWT.READ_ONLY);
211
		}
212
		return dummyAlternativeRepositoryEditor;
213
	}
214
215
216
	public void modify(Object element, String property, Object value) {
217
		
218
        final IStructuredSelection selection = (IStructuredSelection)fTableViewer.getSelection();
219
        final Item item = (Item)selection.getFirstElement();
220
        if (item == null)
221
            return;
222
223
        final int comboIndex = ((Integer)value).intValue();
224
        
225
        if (PROPERTY_ALTERNATIVE_LIST.equals(property)) {
226
        	item.selected = comboIndex;
227
        }
228
        fTableViewer.refresh(item);
229
    }
230
231
    public Image getColumnImage(Object element, int columnIndex) {
232
    	return null;
233
    }
234
235
    public String getColumnText(Object element, int columnIndex) {
236
237
        final Item item = (Item) element;
238
        
239
        if (columnIndex == 0) { 
240
        	return item.location;
241
        }
242
        
243
        if (columnIndex == 1) {
244
        	return ((CVSRepositoryLocation) item.alternativeList
245
					.get(item.selected)).getLocation();
246
        }
247
    	return null;
248
    }
249
250
    public void addListener(ILabelProviderListener listener) {}
251
252
    public void dispose() {}
253
254
    public boolean isLabelProperty(Object element, String property) {
255
        return false;
256
    }
257
258
    public void removeListener(ILabelProviderListener listener) {}
259
260
    public Object[] getElements(Object inputElement) {	
261
    	return ((Collection)inputElement).toArray();
262
    }
263
264
    public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
265
    
266
    public IStructuredSelection getSelection() {
267
        return (IStructuredSelection)fTableViewer.getSelection();
268
    }
269
    
270
    public TableViewer getViewer() {
271
        return fTableViewer;
272
    }
273
274
    public CVSRepositoryLocation getSelectedAlternativeRepository() {
275
		RepositoryLocationItem firstElement = (RepositoryLocationItem) getSelection()
276
				.getFirstElement();
277
		return (CVSRepositoryLocation) firstElement.alternativeList
278
				.get(firstElement.selected);
279
	} 
280
    
281
	public void addAlternativeRepositoryToSelection(
282
			ICVSRepositoryLocation location) {
283
		RepositoryLocationItem firstElement = (RepositoryLocationItem) getSelection()
284
				.getFirstElement();
285
		// put new alternative repository at first position
286
		firstElement.alternativeList.add(0, location);
287
		firstElement.selected = 0;
288
		fTableViewer.refresh(firstElement);
289
	}
290
}
(-)src/org/eclipse/team/internal/ccvs/ui/AlternativeRepositoryDialog.java (+162 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.*;
14
import java.util.List;
15
16
import org.eclipse.jface.dialogs.Dialog;
17
import org.eclipse.jface.dialogs.TitleAreaDialog;
18
import org.eclipse.jface.viewers.*;
19
import org.eclipse.jface.wizard.WizardDialog;
20
import org.eclipse.swt.SWT;
21
import org.eclipse.swt.graphics.Image;
22
import org.eclipse.swt.graphics.Point;
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
30
public class AlternativeRepositoryDialog extends TitleAreaDialog {
31
32
	private List fAlternatives;
33
	private Image dlgTitleImage;
34
	private final static String windowTitle = CVSUIMessages.AlternativeRepositoryWizard_title;
35
	private final static String title = CVSUIMessages.AlternativeRepositoryWizard_title;
36
	private final static String message = CVSUIMessages.AlternativeRepositoryWizard_message;
37
	
38
	/**
39
	 * Creates a new AlternativeRepositoryDialog.
40
	 * 
41
	 * @param parentShell  the parent shell
42
	 * @param alternativesMap  the default user name
43
	 * @param message  a message to display to the user
44
	 */
45
	public AlternativeRepositoryDialog(Shell parentShell, Map alternativesMap) {
46
		super(parentShell);
47
        setShellStyle(getShellStyle() | SWT.RESIZE);
48
        fAlternatives = new ArrayList();
49
        for (Iterator iterator = alternativesMap.entrySet().iterator(); iterator.hasNext();) {
50
			Map.Entry entry = (Map.Entry) iterator.next();
51
			fAlternatives
52
					.add(new AlternativeRepositoryTable.RepositoryLocationItem(
53
							(CVSRepositoryLocation) entry.getKey(),
54
							(List) entry.getValue())); 
55
		}
56
	}
57
	
58
    /* (non-Javadoc)
59
     * @see org.eclipse.jface.dialogs.TitleAreaDialog#createContents(org.eclipse.swt.widgets.Composite)
60
     */
61
    protected Control createContents(Composite parent) {
62
        Control contents = super.createContents(parent);
63
        setTitle(title);
64
        setMessage(message);
65
        dlgTitleImage = CVSUIPlugin.getPlugin().getImageDescriptor(
66
				ICVSUIConstants.IMG_WIZBAN_NEW_LOCATION).createImage();
67
        setTitleImage(dlgTitleImage);
68
        return contents;
69
    }
70
    
71
    public boolean close() {
72
        if (dlgTitleImage != null) {
73
			dlgTitleImage.dispose();
74
		}
75
        return super.close();
76
    }
77
	
78
	/*
79
	 * (non-Javadoc) Method declared in Window.
80
	 */
81
	protected void configureShell(Shell shell) {
82
		super.configureShell(shell);
83
		if (windowTitle != null) {
84
			shell.setText(windowTitle);
85
		}
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(1, false));
96
		
97
		// TODO: help
98
        
99
        GridData childData = new GridData(GridData.FILL_BOTH);
100
		composite.setLayoutData(childData);
101
		
102
        final AlternativeRepositoryTable table = new AlternativeRepositoryTable(composite, fAlternatives);
103
        
104
        final Button createLocationButton = new Button(composite, SWT.PUSH);
105
		createLocationButton.setText(CVSUIMessages.AlternativeRepositoryWizard_createLocation);
106
		createLocationButton.setToolTipText(CVSUIMessages.AlternativeRepositoryWizard_createLocationTooltip);
107
		createLocationButton.addListener(SWT.Selection, new Listener() {
108
			public void handleEvent(Event event) {
109
				
110
				CVSRepositoryLocation selectedAlternativeRepository = table.getSelectedAlternativeRepository();
111
				
112
				Properties properties = new Properties();
113
				properties.put("connection", selectedAlternativeRepository.getMethod()); //$NON-NLS-1$
114
				properties.put("user", selectedAlternativeRepository.getUsername()); //$NON-NLS-1$
115
				//TODO: 
116
//				properties.put("password", ""); //$NON-NLS-1$
117
				properties.put("host", selectedAlternativeRepository.getHost()); //$NON-NLS-1$
118
				int port = selectedAlternativeRepository.getPort();
119
				if (port != ICVSRepositoryLocation.USE_DEFAULT_PORT)
120
					properties.put("port", String.valueOf(port)); //$NON-NLS-1$
121
				properties.put("root", selectedAlternativeRepository.getRootDirectory()); //$NON-NLS-1$
122
				
123
				AlternativeLocationWizard wizard = new AlternativeLocationWizard(properties);
124
				wizard.setSwitchPerspectives(false);
125
				WizardDialog dialog = new WizardDialog(getShell(), wizard);
126
				dialog.open();
127
				
128
				ICVSRepositoryLocation location = wizard.getLocation();
129
				if (location != null)
130
					table.addAlternativeRepositoryToSelection(location);
131
			}
132
		});
133
		createLocationButton.setEnabled(table.getSelection().getFirstElement() != null);
134
		
135
        table.getViewer().addSelectionChangedListener(
136
				new ISelectionChangedListener() {
137
					public void selectionChanged(SelectionChangedEvent event) {
138
						IStructuredSelection sel = (IStructuredSelection) event
139
								.getSelection();
140
						Object firstElement = sel.getFirstElement();
141
						createLocationButton.setEnabled(firstElement != null);
142
					}
143
				});
144
		
145
        return composite;
146
	}
147
	
148
	protected Point getInitialSize() {
149
		//TODO: read/write using memento
150
		return new Point(600, 500);
151
	}
152
	
153
	public Map getSelected() {
154
		Map map = new HashMap();
155
		for (Iterator iterator = fAlternatives.iterator(); iterator.hasNext();) {
156
			AlternativeRepositoryTable.RepositoryLocationItem rli = (AlternativeRepositoryTable.RepositoryLocationItem) iterator
157
					.next();
158
			map.put(rli.location, rli.alternativeList.get(rli.selected));
159
		}
160
		return map;
161
	}
162
}
(-)src/org/eclipse/team/internal/ccvs/ui/wizards/AlternativeLocationWizard.java (+114 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.wizards;
12
13
import java.lang.reflect.InvocationTargetException;
14
import java.util.Properties;
15
16
import org.eclipse.core.runtime.IProgressMonitor;
17
import org.eclipse.core.runtime.IStatus;
18
import org.eclipse.jface.dialogs.MessageDialog;
19
import org.eclipse.jface.operation.IRunnableWithProgress;
20
import org.eclipse.osgi.util.NLS;
21
import org.eclipse.team.core.TeamException;
22
import org.eclipse.team.internal.ccvs.core.CVSException;
23
import org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation;
24
import org.eclipse.team.internal.ccvs.core.util.KnownRepositories;
25
import org.eclipse.team.internal.ccvs.ui.*;
26
27
public class AlternativeLocationWizard extends NewLocationWizard {
28
29
	private ICVSRepositoryLocation location;
30
	
31
	public boolean performFinish() {
32
		final ICVSRepositoryLocation[] location = new ICVSRepositoryLocation[] { null };
33
		boolean useLocation = true;
34
		try {
35
			// Create a handle to a repository location
36
			location[0] = mainPage.getLocation();
37
			// Add the location quitely so we can validate
38
			location[0] = KnownRepositories.getInstance().addRepository(location[0], false /* don't tell anybody */);
39
			
40
			if (mainPage.getValidate()) {
41
				try {
42
					getContainer().run(true, true, new IRunnableWithProgress() {
43
						public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
44
							try {
45
								location[0].validateConnection(monitor);
46
							} catch (TeamException e) {
47
								throw new InvocationTargetException(e);
48
							}
49
						}
50
					});
51
				} catch (InterruptedException e) {
52
					// Cancelled by user. Fall through to dispose of location
53
				} catch (InvocationTargetException e) {
54
					Throwable t = e.getTargetException();
55
					if (t instanceof TeamException) {
56
						throw (TeamException)t;
57
					} else if (t instanceof Exception) {
58
						throw CVSException.wrapException((Exception)t);
59
					} else {
60
						throw CVSException.wrapException(e);
61
					}
62
				}
63
			} 
64
		} catch (TeamException e) {
65
			if (location[0] == null) {
66
				// Exception creating the root, we cannot continue
67
				CVSUIPlugin.openError(getContainer().getShell(), CVSUIMessages.AlternativeLocationWizard_exception, null, e); 
68
				return false;
69
			} else {
70
				// Exception validating. We can continue if the user wishes.
71
				IStatus error = e.getStatus();
72
				if (error.isMultiStatus() && error.getChildren().length == 1) {
73
					error = error.getChildren()[0];
74
				}
75
					
76
				if (error.isMultiStatus()) {
77
					CVSUIPlugin.openError(getContainer().getShell(), CVSUIMessages.AlternativeLocationWizard_validationFailedTitle, null, e); 
78
				} else {
79
					useLocation = MessageDialog.openQuestion(getContainer().getShell(),
80
						CVSUIMessages.AlternativeLocationWizard_validationFailedTitle, 
81
						NLS.bind(CVSUIMessages.AlternativeLocationWizard_validationFailedText, (new Object[] {error.getMessage()}))); 
82
				}
83
			}
84
		}
85
86
		KnownRepositories.getInstance().disposeRepository(location[0]);
87
		
88
		this.location = useLocation ? location[0] : null;
89
		return true;
90
	}
91
	
92
	public AlternativeLocationWizard(Properties initialProperties) {
93
		super(initialProperties);
94
	}
95
	
96
	/**
97
	 * Creates the wizard pages
98
	 */
99
	public void addPages() {
100
		mainPage = new ConfigurationWizardMainPage("repositoryPage1", CVSUIMessages.AlternativeLocationWizard_heading, CVSUIPlugin.getPlugin().getImageDescriptor(ICVSUIConstants.IMG_WIZBAN_NEW_LOCATION)); //$NON-NLS-1$ 
101
		if (properties != null) {
102
			mainPage.setProperties(properties);
103
		}
104
		mainPage.setShowValidate(true);
105
		mainPage.setDescription(CVSUIMessages.AlternativeLocationWizard_description); 
106
		mainPage.setDialogSettings(getDialogSettings());
107
		addPage(mainPage);
108
	}
109
	
110
	public ICVSRepositoryLocation getLocation() {
111
		return location;
112
	}
113
114
}

Return to bug 159258