Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 7440a7fcba1c4f86b37fd8cf8b4043c08db07111 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*******************************************************************************
 * Copyright (c) 2007 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 * IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.team.internal.ccvs.ui.wizards;

import java.lang.reflect.InvocationTargetException;
import java.util.Properties;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.osgi.util.NLS;
import org.eclipse.team.core.TeamException;
import org.eclipse.team.internal.ccvs.core.CVSException;
import org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation;
import org.eclipse.team.internal.ccvs.core.util.KnownRepositories;
import org.eclipse.team.internal.ccvs.ui.*;

public class AlternativeLocationWizard extends NewLocationWizard {

	private ICVSRepositoryLocation location;
	
	public boolean performFinish() {
		final ICVSRepositoryLocation[] location = new ICVSRepositoryLocation[] { null };
		boolean useLocation = true;
		try {
			// Create a handle to a repository location
			location[0] = mainPage.getLocation();
			// Add the location quietly so we can validate
			location[0] = KnownRepositories.getInstance().addRepository(location[0], false /* don't tell anybody */);
			
			if (mainPage.getValidate()) {
				try {
					getContainer().run(true, true, new IRunnableWithProgress() {
						public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
							try {
								location[0].validateConnection(monitor);
							} catch (TeamException e) {
								throw new InvocationTargetException(e);
							}
						}
					});
				} catch (InterruptedException e) {
					// Canceled by user. Fall through to dispose of location
				} catch (InvocationTargetException e) {
					Throwable t = e.getTargetException();
					if (t instanceof TeamException) {
						throw (TeamException)t;
					} else if (t instanceof Exception) {
						throw CVSException.wrapException((Exception)t);
					} else {
						throw CVSException.wrapException(e);
					}
				}
			} 
		} catch (TeamException e) {
			if (location[0] == null) {
				// Exception creating the root, we cannot continue
				CVSUIPlugin.openError(getContainer().getShell(), CVSUIMessages.AlternativeLocationWizard_exception, null, e); 
				return false;
			} else {
				// Exception validating. We can continue if the user wishes.
				IStatus error = e.getStatus();
				if (error.isMultiStatus() && error.getChildren().length == 1) {
					error = error.getChildren()[0];
				}
					
				if (error.isMultiStatus()) {
					CVSUIPlugin.openError(getContainer().getShell(), CVSUIMessages.AlternativeLocationWizard_validationFailedTitle, null, e); 
				} else {
					useLocation = MessageDialog.openQuestion(getContainer().getShell(),
						CVSUIMessages.AlternativeLocationWizard_validationFailedTitle, 
						NLS.bind(CVSUIMessages.AlternativeLocationWizard_validationFailedText, (new Object[] {error.getMessage()}))); 
				}
			}
		}
		
		if (useLocation) {
			KnownRepositories.getInstance().addRepository(location[0], true /* let the world know */);
		} else {
			KnownRepositories.getInstance().disposeRepository(location[0]);
		}
		
		this.location = useLocation ? location[0] : null;
		return useLocation;
	}
	
	public AlternativeLocationWizard(Properties initialProperties) {
		super(initialProperties);
	}
	
	/**
	 * Creates the wizard pages
	 */
	public void addPages() {
		super.addPages();
	}
	
	protected ConfigurationWizardMainPage createMainPage() {
		return new AlternativeConfigurationWizardMainPage("repositoryPage1", CVSUIMessages.AlternativeLocationWizard_heading, CVSUIPlugin.getPlugin().getImageDescriptor(ICVSUIConstants.IMG_WIZBAN_NEW_LOCATION)); //$NON-NLS-1$
	}
	
	public ICVSRepositoryLocation getLocation() {
		return location;
	}
	
	/**
	 * Wizard page for entering information about a CVS repository location used
	 * while working with Alternative Repository dialog.
	 * 
	 * <p>
	 * Validation works slightly different. When user wants to create a
	 * location, which already exists he/she will be informed that the location
	 * can be obtained from a combo-box.
	 * </p>
	 * 
	 * TODO: enable to create existing location, instead of displaying an error
	 * close the dialog and select the entry with that location in the combo box
	 */
	private class AlternativeConfigurationWizardMainPage extends
			ConfigurationWizardMainPage {

		public AlternativeConfigurationWizardMainPage(String pageName,
				String title, ImageDescriptor titleImage) {
			super(pageName, title, titleImage);
		}

		/*
		 * (non-Javadoc)
		 * 
		 * @see org.eclipse.team.internal.ccvs.ui.wizards.ConfigurationWizardMainPage#validateFields()
		 */
		protected void validateFields() {
			super.validateFields();
			if (!isPageComplete()
					&& getErrorMessage() != null
					&& getErrorMessage().equals(
							CVSUIMessages.ConfigurationWizardMainPage_0)) {
				// add an information that the location already exists and can
				// be selected from a combo box
				setErrorMessage(CVSUIMessages.AlternativeConfigurationWizardMainPage_0);
			}
		}
	}
	
}

Back to the top