Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 23a934fd9c7605902cc0fb2dab9842acbe095a70 (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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/*******************************************************************************
 * Copyright (c) 2007, 2018 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;

import java.util.Map;
import java.util.Properties;

import org.eclipse.jface.dialogs.*;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.IWizard;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.*;
import org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation;
import org.eclipse.team.internal.ccvs.core.connection.CVSRepositoryLocation;
import org.eclipse.team.internal.ccvs.ui.wizards.AlternativeLocationWizard;
import org.eclipse.ui.PlatformUI;

public class ConfigureRepositoryLocationsDialog extends TitleAreaDialog {

	private Image dlgTitleImage;
	private ConfigureRepositoryLocationsTable fConfigureRepositoryLocationsTable;

	/**
	 * Creates a new AlternativeRepositoryDialog.
	 * 
	 * @param parentShell
	 *            the parent shell
	 * @param alternativesMap
	 *            Map with a repository location (ICVSRepositoryLocation) from
	 *            the Team Project Set as a key and list of alternatives found
	 *            (also ICVSRepositoryLocation) as a value.
	 * @param message
	 *            a message to display to the user
	 */
	public ConfigureRepositoryLocationsDialog(Shell parentShell, Map alternativesMap) {
		super(parentShell);
		setShellStyle(getShellStyle() | SWT.RESIZE);
		fConfigureRepositoryLocationsTable = new ConfigureRepositoryLocationsTable(
				alternativesMap);
	}

	@Override
	protected Control createContents(Composite parent) {
		Control contents = super.createContents(parent);
		setTitle(CVSUIMessages.ConfigureRepositoryLocationsWizard_title);
		setMessage(CVSUIMessages.ConfigureRepositoryLocationsWizard_message);
		dlgTitleImage = CVSUIPlugin.getPlugin().getImageDescriptor(
				ICVSUIConstants.IMG_WIZBAN_NEW_LOCATION).createImage();
		setTitleImage(dlgTitleImage);
		return contents;
	}

	@Override
	public boolean close() {
		if (dlgTitleImage != null) {
			dlgTitleImage.dispose();
		}
		return super.close();
	}

	@Override
	protected void configureShell(Shell shell) {
		super.configureShell(shell);
		shell.setText(CVSUIMessages.ConfigureRepositoryLocationsWizard_title);
		// set F1 help
		PlatformUI.getWorkbench().getHelpSystem().setHelp(shell,
				IHelpContextIds.ALTERNATIVE_REPOSITORY_DIALOG);
	}

	@Override
	protected Control createDialogArea(Composite parent) {
		initializeDialogUnits(parent);

		final Composite composite = new Composite(parent, SWT.NONE);
		composite.setLayout(new GridLayout(2, false));

		GridData childData = new GridData(GridData.FILL_BOTH);
		composite.setLayoutData(childData);

		Composite table = fConfigureRepositoryLocationsTable.createControl(composite);
		GridData gridData = new GridData(GridData.VERTICAL_ALIGN_FILL);
		gridData.horizontalSpan = 2;
		gridData.horizontalAlignment = GridData.FILL;
		gridData.grabExcessHorizontalSpace = true;
		gridData.grabExcessVerticalSpace = true;
		table.setLayoutData(gridData);
		
		final Button showOnlyCompatibleLocationsButton = new Button(composite,
				SWT.CHECK);
		showOnlyCompatibleLocationsButton
				.setText(CVSUIMessages.ConfigureRepositoryLocationsWizard_showOnlyCompatible);
		showOnlyCompatibleLocationsButton.setSelection(true);
		showOnlyCompatibleLocationsButton.addListener(SWT.Selection,
				event -> fConfigureRepositoryLocationsTable
						.setShowOnlyCompatibleLocations(showOnlyCompatibleLocationsButton
								.getSelection()));
		showOnlyCompatibleLocationsButton.setLayoutData(new GridData(
				SWT.BEGINNING, SWT.NONE, false, false));
		
		final Button createLocationButton = new Button(composite, SWT.PUSH);
		createLocationButton
				.setText(CVSUIMessages.ConfigureRepositoryLocationsWizard_createLocation);
		createLocationButton
				.setToolTipText(CVSUIMessages.ConfigureRepositoryLocationsWizard_createLocationTooltip);
		createLocationButton.addListener(SWT.Selection, event -> {

			CVSRepositoryLocation selectedAlternativeRepository = fConfigureRepositoryLocationsTable
					.getSelectedAlternativeRepository();

			Properties properties = new Properties();
			properties
					.put(
							"connection", selectedAlternativeRepository.getMethod().getName()); //$NON-NLS-1$
			properties.put(
					"user", selectedAlternativeRepository.getUsername()); //$NON-NLS-1$
			// TODO: retrieve password (if available) and use it to prime
			// the field
			// properties.put("password", ""); //$NON-NLS-1$
			properties.put("host", selectedAlternativeRepository.getHost()); //$NON-NLS-1$
			int port = selectedAlternativeRepository.getPort();
			if (port != ICVSRepositoryLocation.USE_DEFAULT_PORT)
				properties.put("port", String.valueOf(port)); //$NON-NLS-1$
			properties
					.put(
							"root", selectedAlternativeRepository.getRootDirectory()); //$NON-NLS-1$

			AlternativeLocationWizard wizard = new AlternativeLocationWizard(
					properties);
			wizard.setSwitchPerspectives(false);
			WizardDialog dialog = new ConfigureRepositoryLocationsWizardDialog(
					getShell(), wizard);
			dialog.open();

			ICVSRepositoryLocation location = wizard.getLocation();
			if (location != null)
				fConfigureRepositoryLocationsTable
						.addAlternativeRepository(location);
		});
		createLocationButton.setEnabled(fConfigureRepositoryLocationsTable
				.getSelection().getFirstElement() != null);
		createLocationButton.setLayoutData(new GridData(SWT.END, SWT.NONE,
				false, false));
		
		fConfigureRepositoryLocationsTable.getViewer().addSelectionChangedListener(
				event -> {
					IStructuredSelection sel = event.getStructuredSelection();
					Object firstElement = sel.getFirstElement();
					createLocationButton.setEnabled(firstElement != null);
				});

		return composite;
	}

	public Map getSelected() {
		return fConfigureRepositoryLocationsTable.getSelected();
	}

	@Override
	protected IDialogSettings getDialogBoundsSettings() {
		String sectionName = getClass().getName() + "_dialogBounds"; //$NON-NLS-1$
		IDialogSettings settings = CVSUIPlugin.getPlugin().getDialogSettings();
		IDialogSettings section = settings.getSection(sectionName);
		if (section == null) {
			section = settings.addNewSection(sectionName);
			section.put("DIALOG_HEIGHT", 300); //$NON-NLS-1$
			section.put("DIALOG_WIDTH", 600); //$NON-NLS-1$
		}
		return section;
	}

	/*
	 * @see org.eclipse.jface.dialogs.Dialog#getDialogBoundsStrategy()
	 * @since 3.2
	 */
	@Override
	protected int getDialogBoundsStrategy() {
		return DIALOG_PERSISTLOCATION | DIALOG_PERSISTSIZE;
	}
	
	/**
	 * This class is made only to change Wizard's default "Finish" button label
	 * to "Create".
	 */
	private class ConfigureRepositoryLocationsWizardDialog extends WizardDialog {

		public ConfigureRepositoryLocationsWizardDialog(Shell parentShell,
				IWizard newWizard) {
			super(parentShell, newWizard);
		}

		@Override
		protected Button createButton(Composite parent, int id, String label,
				boolean defaultButton) {
			if (id == IDialogConstants.FINISH_ID)
				label = CVSUIMessages.ConfigureRepositoryLocationsWizardDialog_finish;
			return super.createButton(parent, id, label, defaultButton);
		}

	}
}

Back to the top