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 (-1 / +10 lines)
Lines 10-16 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.team.tests.ccvs.core;
11
package org.eclipse.team.tests.ccvs.core;
12
12
13
import org.eclipse.team.internal.ccvs.core.*;
13
import java.util.Map;
14
15
import org.eclipse.team.internal.ccvs.core.CVSException;
16
import org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation;
17
import org.eclipse.team.internal.ccvs.core.IUserAuthenticator;
18
import org.eclipse.team.internal.ccvs.core.IUserInfo;
14
19
15
/**
20
/**
16
 * A test authenticator that provide defaults for all methods.
21
 * A test authenticator that provide defaults for all methods.
Lines 40-43 Link Here
40
    public boolean promptForHostKeyChange(ICVSRepositoryLocation location) {
45
    public boolean promptForHostKeyChange(ICVSRepositoryLocation location) {
41
        return false;
46
        return false;
42
    }
47
    }
48
49
	public Map promptForAlternativeRepository(Map alternativeMap) {
50
		return null;
51
	}
43
}
52
}
(-)contexts_Team_CVS.xml (-1 / +4 lines)
Lines 460-468 Link Here
460
    <context id="tag_uncommmited_dialog_context">
460
    <context id="tag_uncommmited_dialog_context">
461
        <description>There are modified resources in the selection and these changes will not be included in the version created by the tag operation. This dialog allows you to decide whether to continue.</description>
461
        <description>There are modified resources in the selection and these changes will not be included in the version created by the tag operation. This dialog allows you to decide whether to continue.</description>
462
    </context>
462
    </context>
463
        <context id="commit_set_dialog_context">
463
    <context id="commit_set_dialog_context">
464
        <description>This dialog allows you to create or edit the name and comment for a CVS change set.</description>
464
        <description>This dialog allows you to create or edit the name and comment for a CVS change set.</description>
465
    </context>
465
    </context>
466
    <context id="alternative_repository_dialog_context">
467
        <description>When the project set contains only partial repository information (not all locations are known) this dialog allows to choose a known repository location or create a new one or at last use a default.</description>
468
    </context>
466
    
469
    
467
 	<!-- ********************************** -->
470
 	<!-- ********************************** -->
468
 	<!-- Preference Pages 					-->
471
 	<!-- Preference Pages 					-->
(-)src/org/eclipse/team/internal/ccvs/core/CVSProjectSetCapability.java (-16 / +169 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 (isAdditionRepositoryInformationRequired(projects, infoMap, alternativeMap)) {
126
			// display the dialog
127
			Map alternativeRespositoriesMap = promptForAdditionRepositoryInformation(alternativeMap);
128
			// replace repository location from a project load info with one from the prompter
129
			if (alternativeRespositoriesMap != null) {
130
				for (Iterator iterator = infoMap.values().iterator(); iterator
131
						.hasNext();) {
132
					LoadInfo loadInfoForProject = (LoadInfo) iterator.next();
133
					ICVSRepositoryLocation selectedAlternativeRepository = (ICVSRepositoryLocation) alternativeRespositoriesMap
134
							.get(loadInfoForProject.repositoryLocation);
135
					// TODO: final modifier removed for LoadInfo.repositoryLocation 
136
					// another solution is to create a copy (clone) of LoadInfo, and replace the whole object
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
		// TODO: final modifier removed in order to replace a repository location before check out
218
		private ICVSRepositoryLocation repositoryLocation;
202
		private final String module;
219
		private final String module;
203
		private final IProject project;
220
		private final IProject project;
204
		private final CVSTag tag;
221
		private final CVSTag tag;
Lines 276-282 Link Here
276
			}
293
			}
277
		}
294
		}
278
		// No existing location was found so add this location to the list of known repositories
295
		// No existing location was found so add this location to the list of known repositories
279
		KnownRepositories.getInstance().addRepository(newLocation, true);
296
		// TODO: commented out (if we add repository here we won't be able to check for alternatives)
297
		// KnownRepositories.getInstance().addRepository(newLocation, true);
280
		return newLocation;
298
		return newLocation;
281
	}
299
	}
282
	
300
	
Lines 578-582 Link Here
578
			return null;
596
			return null;
579
		}
597
		}
580
	}
598
	}
599
	
600
	/**
601
	 * Checks whether a dialog prompting for an addition repository location is
602
	 * required.
603
	 * 
604
	 * @see org.eclipse.team.internal.ccvs.ui.AlternativeRepositoryDialog
605
	 * @see org.eclipse.team.internal.ccvs.ui.AlternativeRepositoryTable
606
	 * 
607
	 * @param projects
608
	 *            an array of project to check out
609
	 * @param infoMap
610
	 *            a mapping of project to project load information
611
	 * @param alternativeMap
612
	 * 
613
	 * Initially it's an empty map. When <code>true</code> is returned the map
614
	 * will contain a mapping of a repository location (<code>ICVSRepositoryLocation</code>)
615
	 * from the project set 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
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
619
	 * still allow user to select a different location. So, the default location
620
	 * is optionally followed by compatible locations found. Finally, the last
621
	 * positions are held by the rest of known locations.
622
	 * 
623
	 * <p>
624
	 * The order in which items are kept in a list also reflects the way a combo
625
	 * box from the Alternative Repository dialog will look like.
626
	 * </p>
627
	 * <p>
628
	 * Structure of the list:
629
	 * <ul>
630
	 * <li>default location form the project set</li>
631
	 * <li>compatible locations (if found) - no particular order here</li>
632
	 * <li>other known locations - no particular order here neither</li>
633
	 * </ul>
634
	 * </p>
635
	 * @return <code>false</code> when the project set file contains all
636
	 *         required information or <code>true</code> when Alternative
637
	 *         Repository dialog needs to be displayed.
638
	 * 
639
	 * 
640
	 */
641
	private static boolean isAdditionRepositoryInformationRequired(
642
			IProject[] projects, final Map infoMap, Map alternativeMap) {
643
		
644
		List confirmedProjectsList = Arrays.asList(projects);
645
		
646
		if (infoMap == null)
647
			return false;
648
649
		Set projectSetRepositoryLocations = new HashSet();
650
		for (Iterator iterator = infoMap.keySet().iterator(); iterator
651
				.hasNext();) {
652
			IProject project = (IProject) iterator.next();
653
			if (confirmedProjectsList.contains(project)) {
654
				LoadInfo loadInfo = (LoadInfo) infoMap.get(project);
655
				projectSetRepositoryLocations.add(loadInfo.repositoryLocation);
656
			}
657
		}
658
		
659
		// none of projects from project sets is confirmed to overwrite
660
		if (projectSetRepositoryLocations.isEmpty()) {
661
			return false;
662
		}
663
		
664
		List knownRepositories = Arrays.asList(KnownRepositories.getInstance()
665
				.getRepositories());
666
667
		if (knownRepositories.isEmpty()) {
668
			// there are no known repositories so use repository location from
669
			// the project set
670
			for (Iterator iterator = projectSetRepositoryLocations.iterator(); iterator
671
					.hasNext();) {
672
				ICVSRepositoryLocation projectSetRepositoryLocation = (ICVSRepositoryLocation) iterator
673
						.next();
674
				ArrayList alternativeList = new ArrayList(1);
675
				alternativeList.add(projectSetRepositoryLocation);
676
				alternativeMap.put(projectSetRepositoryLocation,
677
						alternativeList);
678
			}
679
		} else if (!knownRepositories.containsAll(projectSetRepositoryLocations)) {
680
			// not all repositories from the project set are known
581
681
682
			for (Iterator iterator = projectSetRepositoryLocations.iterator(); iterator
683
					.hasNext();) {
684
				ICVSRepositoryLocation projectSetRepositoryLocation = (ICVSRepositoryLocation) iterator
685
						.next();
686
687
				ArrayList alternativeList = new ArrayList();
688
				for (Iterator iterator2 = knownRepositories.iterator(); iterator2
689
						.hasNext();) {
690
					ICVSRepositoryLocation knownRepositoryLocation = (ICVSRepositoryLocation) iterator2
691
							.next();
692
					if (isCompatible(knownRepositoryLocation,
693
							projectSetRepositoryLocation)) {
694
						// compatible repositories first
695
						alternativeList.add(0, knownRepositoryLocation);
696
					} else {
697
						alternativeList.add(knownRepositoryLocation);
698
					}
699
				}
700
701
				// Always put the repository location from the project set
702
				// at the beginning (as default). There is a chance that this
703
				// repository is known.
704
				alternativeList.add(0, projectSetRepositoryLocation);
705
706
				alternativeMap.put(projectSetRepositoryLocation,
707
						alternativeList);
708
			}
709
		} // else { all repositories are known, we don't need to prompt for
710
			// additional information }
711
		
712
		return !alternativeMap.isEmpty();
713
	}
714
	
715
	/**
716
	 * Same test as in org.eclipse.team.internal.ccvs.ui.CVSProjectPropertiesPage
717
	 * 
718
	 * @see org.eclipse.team.internal.ccvs.ui.CVSProjectPropertiesPage#isCompatible
719
	 * 
720
	 * @param location A location from known repositories collection
721
	 * @param oldLocation A location to check c
722
	 * @return Are given locations compatible
723
	 */
724
	public static boolean isCompatible(ICVSRepositoryLocation location, ICVSRepositoryLocation oldLocation) {
725
		if (!location.getHost().equals(oldLocation.getHost())) return false;
726
		if (!location.getRootDirectory().equals(oldLocation.getRootDirectory())) return false;
727
		if (location.equals(oldLocation)) return false;
728
		return true;
729
	}
730
	
731
	private Map promptForAdditionRepositoryInformation(Map alternativeMap) {
732
		IUserAuthenticator authenticator = CVSRepositoryLocation.getAuthenticator();
733
		return authenticator.promptForAlternativeRepository(alternativeMap);
734
	}
582
}
735
}
(-)src/org/eclipse/team/internal/ccvs/core/IUserAuthenticator.java (+19 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
	 * If the project set contains only partial repository information (some of
138
	 * location are unknown) we will display a dialog to associate each project
139
	 * set repository with a known repository location or create a new one or at
140
	 * last use the default locations.
141
	 * 
142
	 * @param alternativeMap
143
	 *            a map of CVS repository locations form the project set (as
144
	 *            keys) and a list of suggested alternative CVS repository
145
	 *            locations (as values)
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
148
	 *         (as values) or <code>null</code> if the operation is to be
149
	 *         canceled
150
	 */
151
	public abstract Map promptForAlternativeRepository(Map alternativeMap);
133
}
152
}
(-)src/org/eclipse/team/internal/ccvs/ui/IHelpContextIds.java (+1 lines)
Lines 33-38 Link Here
33
	public static final String KEYBOARD_INTERACTIVE_DIALOG = PREFIX + "keyboard_interactive_dialog_context"; //$NON-NLS-1$
33
	public static final String KEYBOARD_INTERACTIVE_DIALOG = PREFIX + "keyboard_interactive_dialog_context"; //$NON-NLS-1$
34
	public static final String COMMIT_SET_DIALOG = PREFIX + "commit_set_dialog_context"; //$NON-NLS-1$
34
	public static final String COMMIT_SET_DIALOG = PREFIX + "commit_set_dialog_context"; //$NON-NLS-1$
35
    public static final String TAG_UNCOMMITED_PROMPT = PREFIX + "tag_uncommmited_dialog_context"; //$NON-NLS-1$
35
    public static final String TAG_UNCOMMITED_PROMPT = PREFIX + "tag_uncommmited_dialog_context"; //$NON-NLS-1$
36
    public static final String ALTERNATIVE_REPOSITORY_DIALOG = PREFIX + "alternative_repository_dialog_context"; //$NON-NLS-1$
36
	
37
	
37
	// Different uses of the TagSelectionDialog
38
	// Different uses of the TagSelectionDialog
38
	public static final String REPLACE_TAG_SELECTION_DIALOG = PREFIX + "replace_tag_selection_dialog_context"; //$NON-NLS-1$
39
	public static final String REPLACE_TAG_SELECTION_DIALOG = PREFIX + "replace_tag_selection_dialog_context"; //$NON-NLS-1$
(-)src/org/eclipse/team/internal/ccvs/ui/CVSUIMessages.java (+19 lines)
Lines 348-353 Link Here
348
	public static String CommitWizardFileTypePage_0;
348
	public static String CommitWizardFileTypePage_0;
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
	
352
	public static String AlternativeRepositoryWizard_title;
353
	public static String AlternativeRepositoryWizard_message;
354
	public static String AlternativeRepositoryWizard_createLocation;
355
	public static String AlternativeRepositoryWizard_createLocationTooltip;
356
	public static String AlternativeRepositoryWizard_column0;
357
	public static String AlternativeRepositoryWizard_column1;
358
	public static String AlternativeRepositoryWizard_showConnection;
359
	public static String AlternativeRepositoryWizardDialog_finish;
360
	
351
361
352
	public static String CommitSyncAction_questionRelease;
362
	public static String CommitSyncAction_questionRelease;
353
	public static String CommitSyncAction_titleRelease;
363
	public static String CommitSyncAction_titleRelease;
Lines 503-508 Link Here
503
	public static String NewLocationWizard_validationFailedText;
513
	public static String NewLocationWizard_validationFailedText;
504
	public static String NewLocationWizard_validationFailedTitle;
514
	public static String NewLocationWizard_validationFailedTitle;
505
	public static String NewLocationWizard_exception;
515
	public static String NewLocationWizard_exception;
516
	
517
	public static String AlternativeLocationWizard_title;
518
	public static String AlternativeLocationWizard_heading;
519
	public static String AlternativeLocationWizard_description;
520
	public static String AlternativeLocationWizard_validationFailedText;
521
	public static String AlternativeLocationWizard_validationFailedTitle;
522
	public static String AlternativeLocationWizard_exception;
523
	
524
	public static String AlternativeConfigurationWizardMainPage_0;
506
525
507
	public static String OpenLogEntryAction_deletedTitle;
526
	public static String OpenLogEntryAction_deletedTitle;
508
	public static String OpenLogEntryAction_deleted;
527
	public static String OpenLogEntryAction_deleted;
(-)src/org/eclipse/team/internal/ccvs/ui/WorkbenchUserAuthenticator.java (+38 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 Map promptForAlternativeRepository(final Map alternativeMap) {
333
		final Map[] result = new Map[1];
334
		Display display = Display.getCurrent();
335
		if (display != null) {
336
			result[0] = openAlternativeRepositoryDialog(alternativeMap);
337
		} else {
338
			// sync exec in default thread
339
			Display.getDefault().syncExec(new Runnable() {
340
				public void run() {
341
					result[0] = openAlternativeRepositoryDialog(alternativeMap);
342
				}
343
			});
344
		}
345
		return result[0];
346
	}
347
	
348
	/**
349
	 * Opens the Alternative Repository Selection dialog.
350
	 * 
351
	 * @param alternativeMap
352
	 * @return a map with selected repositories to use or <code>null</code>
353
	 *         when canceled.
354
	 */
355
	private Map openAlternativeRepositoryDialog(Map alternativeMap) {
356
		AlternativeRepositoryDialog dialog = new AlternativeRepositoryDialog(
357
				null, alternativeMap);
358
		int result = dialog.open();
359
		return result == IDialogConstants.CANCEL_ID ? null : dialog
360
				.getSelected();
361
	}
324
}
362
}
(-)src/org/eclipse/team/internal/ccvs/ui/messages.properties (+18 lines)
Lines 289-294 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
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.
294
AlternativeRepositoryWizard_createLocation=Create Location
295
AlternativeRepositoryWizard_createLocationTooltip=Creates Location from a selected alternative repository
296
AlternativeRepositoryWizard_column0=Project set repository information
297
AlternativeRepositoryWizard_column1=Repository Location
298
AlternativeRepositoryWizard_showConnection=Show connection method
299
AlternativeRepositoryWizardDialog_finish=Create
300
292
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?
293
CommitSyncAction_titleRelease=Confirm Overwrite
302
CommitSyncAction_titleRelease=Confirm Overwrite
294
CommitSyncAction_releaseAll=Release all changes, overriding any conflicting changes on the server.
303
CommitSyncAction_releaseAll=Release all changes, overriding any conflicting changes on the server.
Lines 453-458 Link Here
453
NewLocationWizard_validationFailedTitle=Unable to Validate
462
NewLocationWizard_validationFailedTitle=Unable to Validate
454
NewLocationWizard_exception=Unable to create repository location
463
NewLocationWizard_exception=Unable to create repository location
455
464
465
AlternativeLocationWizard_title=Configure CVS Repository
466
AlternativeLocationWizard_heading=Configure an alternative CVS Repository
467
AlternativeLocationWizard_description=Configure an alternative CVS Repository
468
AlternativeLocationWizard_validationFailedText=Error validating location: "{0}"\n\nUse location anyway?
469
AlternativeLocationWizard_validationFailedTitle=Unable to Validate
470
AlternativeLocationWizard_exception=Unable to create repository location
471
472
AlternativeConfigurationWizardMainPage_0=Location already exists. Close this dialog and select the location from a combo box.
473
456
OpenLogEntryAction_deletedTitle=Resource is Deleted
474
OpenLogEntryAction_deletedTitle=Resource is Deleted
457
OpenLogEntryAction_deleted=The selected revision represents a deletion. It cannot be opened.
475
OpenLogEntryAction_deleted=The selected revision represents a deletion. It cannot be opened.
458
476
(-)src/org/eclipse/team/internal/ccvs/ui/wizards/ConfigurationWizardMainPage.java (-1 / +1 lines)
Lines 524-530 Link Here
524
	 * Validates the contents of the editable fields and set page completion 
524
	 * Validates the contents of the editable fields and set page completion 
525
	 * and error messages appropriately.
525
	 * and error messages appropriately.
526
	 */
526
	 */
527
	private void validateFields() {
527
	protected void validateFields() {
528
		String user = userCombo.getText();
528
		String user = userCombo.getText();
529
		IStatus status = validateUserName(user);
529
		IStatus status = validateUserName(user);
530
		if (!isStatusOK(status)) {
530
		if (!isStatusOK(status)) {
(-)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 INewWizard {
33
public class NewLocationWizard extends Wizard implements INewWizard {
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 (+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 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/AlternativeRepositoryDialog.java (+231 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 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/wizards/AlternativeLocationWizard.java (+158 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.jface.resource.ImageDescriptor;
21
import org.eclipse.osgi.util.NLS;
22
import org.eclipse.team.core.TeamException;
23
import org.eclipse.team.internal.ccvs.core.CVSException;
24
import org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation;
25
import org.eclipse.team.internal.ccvs.core.util.KnownRepositories;
26
import org.eclipse.team.internal.ccvs.ui.*;
27
28
public class AlternativeLocationWizard extends NewLocationWizard {
29
30
	private ICVSRepositoryLocation location;
31
	
32
	public boolean performFinish() {
33
		final ICVSRepositoryLocation[] location = new ICVSRepositoryLocation[] { null };
34
		boolean useLocation = true;
35
		try {
36
			// Create a handle to a repository location
37
			location[0] = mainPage.getLocation();
38
			// Add the location quitely so we can validate
39
			location[0] = KnownRepositories.getInstance().addRepository(location[0], false /* don't tell anybody */);
40
			
41
			if (mainPage.getValidate()) {
42
				try {
43
					getContainer().run(true, true, new IRunnableWithProgress() {
44
						public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
45
							try {
46
								location[0].validateConnection(monitor);
47
							} catch (TeamException e) {
48
								throw new InvocationTargetException(e);
49
							}
50
						}
51
					});
52
				} catch (InterruptedException e) {
53
					// Cancelled by user. Fall through to dispose of location
54
				} catch (InvocationTargetException e) {
55
					Throwable t = e.getTargetException();
56
					if (t instanceof TeamException) {
57
						throw (TeamException)t;
58
					} else if (t instanceof Exception) {
59
						throw CVSException.wrapException((Exception)t);
60
					} else {
61
						throw CVSException.wrapException(e);
62
					}
63
				}
64
			} 
65
		} catch (TeamException e) {
66
			if (location[0] == null) {
67
				// Exception creating the root, we cannot continue
68
				CVSUIPlugin.openError(getContainer().getShell(), CVSUIMessages.AlternativeLocationWizard_exception, null, e); 
69
				return false;
70
			} else {
71
				// Exception validating. We can continue if the user wishes.
72
				IStatus error = e.getStatus();
73
				if (error.isMultiStatus() && error.getChildren().length == 1) {
74
					error = error.getChildren()[0];
75
				}
76
					
77
				if (error.isMultiStatus()) {
78
					CVSUIPlugin.openError(getContainer().getShell(), CVSUIMessages.AlternativeLocationWizard_validationFailedTitle, null, e); 
79
				} else {
80
					useLocation = MessageDialog.openQuestion(getContainer().getShell(),
81
						CVSUIMessages.AlternativeLocationWizard_validationFailedTitle, 
82
						NLS.bind(CVSUIMessages.AlternativeLocationWizard_validationFailedText, (new Object[] {error.getMessage()}))); 
83
				}
84
			}
85
		}
86
		
87
		if (useLocation) {
88
			KnownRepositories.getInstance().addRepository(location[0], true /* let the world know */);
89
		} else {
90
			KnownRepositories.getInstance().disposeRepository(location[0]);
91
		}
92
		
93
		this.location = useLocation ? location[0] : null;
94
		return useLocation;
95
	}
96
	
97
	public AlternativeLocationWizard(Properties initialProperties) {
98
		super(initialProperties);
99
	}
100
	
101
	/**
102
	 * Creates the wizard pages
103
	 */
104
	public void addPages() {
105
		mainPage = new AlternativeConfigurationWizardMainPage("repositoryPage1", CVSUIMessages.AlternativeLocationWizard_heading, CVSUIPlugin.getPlugin().getImageDescriptor(ICVSUIConstants.IMG_WIZBAN_NEW_LOCATION)); //$NON-NLS-1$ 
106
		if (properties != null) {
107
			mainPage.setProperties(properties);
108
		}
109
		mainPage.setShowValidate(true);
110
		mainPage.setDescription(CVSUIMessages.AlternativeLocationWizard_description); 
111
		mainPage.setDialogSettings(getDialogSettings());
112
		addPage(mainPage);
113
	}
114
	
115
	public ICVSRepositoryLocation getLocation() {
116
		return location;
117
	}
118
	
119
	/**
120
	 * Wizard page for entering information about a CVS repository location used
121
	 * while working with Alternative Repository dialog.
122
	 * 
123
	 * <p>
124
	 * Validation works slightly different. When user wants to create a
125
	 * location, which already exists he/she will be informed that the location
126
	 * can be obtained from a combo-box.
127
	 * </p>
128
	 * 
129
	 * TODO: enable to create existing location, instead of displaying an error
130
	 * close the dialog and select the entry with that location in the combo box
131
	 */
132
	private class AlternativeConfigurationWizardMainPage extends
133
			ConfigurationWizardMainPage {
134
135
		public AlternativeConfigurationWizardMainPage(String pageName,
136
				String title, ImageDescriptor titleImage) {
137
			super(pageName, title, titleImage);
138
		}
139
140
		/*
141
		 * (non-Javadoc)
142
		 * 
143
		 * @see org.eclipse.team.internal.ccvs.ui.wizards.ConfigurationWizardMainPage#validateFields()
144
		 */
145
		protected void validateFields() {
146
			super.validateFields();
147
			if (!isPageComplete()
148
					&& getErrorMessage() != null
149
					&& getErrorMessage().equals(
150
							CVSUIMessages.ConfigurationWizardMainPage_0)) {
151
				// add an information that the location already exists and can
152
				// be selected from a combo box
153
				setErrorMessage(CVSUIMessages.AlternativeConfigurationWizardMainPage_0);
154
			}
155
		}
156
	}
157
	
158
}

Return to bug 159258