1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  *
4  * This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License 2.0
6  * which accompanies this distribution, and is available at
7  * https://www.eclipse.org/legal/epl-2.0/
8  *
9  * SPDX-License-Identifier: EPL-2.0
10  *
11  * Contributors:
12  *     IBM Corporation - initial API and implementation
13  *******************************************************************************/
14 package org.eclipse.team.internal.ccvs.ui.wizards;
15 
16 
17 import org.eclipse.core.resources.IProject;
18 import org.eclipse.jface.dialogs.Dialog;
19 import org.eclipse.jface.resource.ImageDescriptor;
20 import org.eclipse.swt.SWT;
21 import org.eclipse.swt.layout.GridData;
22 import org.eclipse.swt.widgets.*;
23 import org.eclipse.team.core.TeamException;
24 import org.eclipse.team.internal.ccvs.core.ICVSFolder;
25 import org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation;
26 import org.eclipse.team.internal.ccvs.core.connection.CVSRepositoryLocation;
27 import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot;
28 import org.eclipse.team.internal.ccvs.core.syncinfo.FolderSyncInfo;
29 import org.eclipse.team.internal.ccvs.ui.*;
30 import org.eclipse.ui.PlatformUI;
31 
32 /**
33  * This configuration page explains to the user that CVS/ directories already exists and
34  * it will attach the selected project to the repository that is specified in the CVS/ files.
35  *
36  * This is useful for people who have checked out a project using command-line tools.
37  */
38 public class ConfigurationWizardAutoconnectPage extends CVSWizardPage {
39 	private boolean validate = true;
40 	private FolderSyncInfo info;
41 	ICVSRepositoryLocation location;
42 
ConfigurationWizardAutoconnectPage(String pageName, String title, ImageDescriptor titleImage)43 	public ConfigurationWizardAutoconnectPage(String pageName, String title, ImageDescriptor titleImage) {
44 		super(pageName, title, titleImage);
45 	}
46 
47 	@Override
createControl(Composite parent)48 	public void createControl(Composite parent) {
49 		Composite composite = createComposite(parent, 2, false);
50 		setControl(composite);
51 
52 		// set F1 help
53 		PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IHelpContextIds.SHARING_AUTOCONNECT_PAGE);
54 
55 		Label description = new Label(composite, SWT.WRAP);
56 		GridData data = new GridData();
57 		data.horizontalSpan = 2;
58 		data.widthHint = 350;
59 		description.setLayoutData(data);
60 		description.setText(CVSUIMessages.ConfigurationWizardAutoconnectPage_description);
61 
62 		if (location == null) return;
63 
64 		// Spacer
65 		createLabel(composite, ""); //$NON-NLS-1$
66 		createLabel(composite, ""); //$NON-NLS-1$
67 
68 		createLabel(composite, CVSUIMessages.ConfigurationWizardAutoconnectPage_user);
69 		createLabel(composite, location.getUsername());
70 		createLabel(composite, CVSUIMessages.ConfigurationWizardAutoconnectPage_host);
71 		createLabel(composite, location.getHost());
72 		createLabel(composite, CVSUIMessages.ConfigurationWizardAutoconnectPage_port);
73 		int port = location.getPort();
74 		if (port == ICVSRepositoryLocation.USE_DEFAULT_PORT) {
75 			createLabel(composite, CVSUIMessages.ConfigurationWizardAutoconnectPage_default);
76 		} else {
77 			createLabel(composite, "" + port); //$NON-NLS-1$
78 		}
79 		createLabel(composite, CVSUIMessages.ConfigurationWizardAutoconnectPage_connectionType);
80 		createLabel(composite, location.getMethod().getName());
81 		createLabel(composite, CVSUIMessages.ConfigurationWizardAutoconnectPage_repositoryPath);
82 		createLabel(composite, location.getRootDirectory());
83 		createLabel(composite, CVSUIMessages.ConfigurationWizardAutoconnectPage_module);
84 		createLabel(composite, info.getRepository());
85 
86 		// Spacer
87 		createLabel(composite, ""); //$NON-NLS-1$
88 		createLabel(composite, ""); //$NON-NLS-1$
89 
90 		final Button check = new Button(composite, SWT.CHECK);
91 		data = new GridData();
92 		data.horizontalSpan = 2;
93 		check.setText(CVSUIMessages.ConfigurationWizardAutoconnectPage_validate);
94 		check.addListener(SWT.Selection, event -> validate = check.getSelection());
95 		check.setSelection(true);
96 		Dialog.applyDialogFont(parent);
97 	}
98 
getFolderSyncInfo()99 	public FolderSyncInfo getFolderSyncInfo() {
100 		return info;
101 	}
getValidate()102 	public boolean getValidate() {
103 		return validate;
104 	}
setProject(IProject project)105 	public boolean setProject(IProject project) {
106 		try {
107 			ICVSFolder folder = (ICVSFolder)CVSWorkspaceRoot.getCVSResourceFor(project);
108 			info = folder.getFolderSyncInfo();
109 			if (info == null) {
110 				// This should never happen
111 				CVSUIPlugin.openError(null, CVSUIMessages.ConfigurationWizardAutoconnectPage_noSyncInfo, CVSUIMessages.ConfigurationWizardAutoconnectPage_noCVSDirectory, null); //
112 				return false;
113 			}
114 			location = CVSRepositoryLocation.fromString(info.getRoot());
115 			return true;
116 		} catch (TeamException e) {
117 			CVSUIPlugin.openError(null, null, null, e);
118 			return false;
119 		}
120 	}
121 
122 	/**
123 	 * Gets the location.
124 	 * @return Returns a ICVSRepositoryLocation
125 	 */
getLocation()126 	public ICVSRepositoryLocation getLocation() {
127 		return location;
128 	}
129 
130 }
131