Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 51f150e8ffcb064e7ea2fd568505e721f6160973 (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
/*******************************************************************************
 * Copyright (c) 2000, 2008 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.team.internal.ccvs.ui.wizards;


import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.*;
import org.eclipse.osgi.util.TextProcessor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.*;
import org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation;
import org.eclipse.team.internal.ccvs.ui.*;
import org.eclipse.team.internal.ccvs.ui.repo.RepositoryComparator;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.model.*;

/**
 * First wizard page for importing a project into a CVS repository.
 * This page prompts the user to select an existing repo or create a new one.
 * If the user selected an existing repo, then getLocation() will return it.
 */
public class RepositorySelectionPage extends CVSWizardPage {
	
	private class DecoratingRepoLabelProvider extends WorkbenchLabelProvider {
		protected String decorateText(String input, Object element) {
			//Used to process RTL locales only
			return TextProcessor.process(input, ":@/"); //$NON-NLS-1$
		}
	}
	
	
	private TableViewer table;
	private Button useExistingRepo;
	private Button useNewRepo;
	
	private ICVSRepositoryLocation result;
	
	String extendedDescription;
	
	/**
	 * RepositorySelectionPage constructor.
	 * 
	 * @param pageName  the name of the page
	 * @param title  the title of the page
	 * @param titleImage  the image for the page
	 */
	public RepositorySelectionPage(String pageName, String title, ImageDescriptor titleImage) {
		super(pageName, title, titleImage);
	}
	protected TableViewer createTable(Composite parent, int span) {
		Table table = new Table(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION);
		GridData data = new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL);
		data.horizontalSpan = span;
		data.widthHint = 200;
		table.setLayoutData(data);
		TableLayout layout = new TableLayout();
		layout.addColumnData(new ColumnWeightData(100, true));
		table.setLayout(layout);
		TableColumn col = new TableColumn(table, SWT.NONE);
		col.setResizable(true);
	
		return new TableViewer(table);
	}
	/**
	 * Creates the UI part of the page.
	 * 
	 * @param parent  the parent of the created widgets
	 */
	public void createControl(Composite parent) {
		Composite composite = createComposite(parent, 1, false);
		// set F1 help
        PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IHelpContextIds.SHARING_SELECT_REPOSITORY_PAGE);
		if (extendedDescription == null) {
			extendedDescription = CVSUIMessages.RepositorySelectionPage_description; 
		}
		createWrappingLabel(composite, extendedDescription, 0 /* indent */, 1 /* columns */); 
		
		useNewRepo = createRadioButton(composite, CVSUIMessages.RepositorySelectionPage_useNew, 1); 
		
		useExistingRepo = createRadioButton(composite, CVSUIMessages.RepositorySelectionPage_useExisting, 1); 
		useExistingRepo.addKeyListener(new KeyAdapter() {
			public void keyPressed(KeyEvent e) {
				if (table.getTable().getItemCount() > 0) {
					table.getTable().setFocus();
					traverseRepositories(e.character);
				}
			}
        });
		
		table = createTable(composite, 1);
		table.setContentProvider(new WorkbenchContentProvider());
		table.setLabelProvider(new DecoratingRepoLabelProvider()/*WorkbenchLabelProvider()*/);
		table.setComparator(new RepositoryComparator());
        table.addDoubleClickListener(new IDoubleClickListener() {
            public void doubleClick(DoubleClickEvent event) {
                getContainer().showPage(getNextPage());
            }
        });
        table.getTable().addKeyListener(new KeyAdapter() {
			public void keyPressed(KeyEvent e) {
				traverseRepositories(e.character);
			}
        });

		setControl(composite);

		initializeValues();
        Dialog.applyDialogFont(parent);
        
        table.addSelectionChangedListener(new ISelectionChangedListener() {
            public void selectionChanged(SelectionChangedEvent event) {
                result = (ICVSRepositoryLocation)((IStructuredSelection)table.getSelection()).getFirstElement();
                setPageComplete(true);
            }
        });
        
        useExistingRepo.addListener(SWT.Selection, new Listener() {
            public void handleEvent(Event event) {
                if (useNewRepo.getSelection()) {
                    table.getTable().setEnabled(false);
                    result = null;
                } else {
                    table.getTable().setEnabled(true);
                    result = (ICVSRepositoryLocation)((IStructuredSelection)table.getSelection()).getFirstElement();
                }
                setPageComplete(true);
            }
        });
	}
	/**
	 * Initializes states of the controls.
	 */
	private void initializeValues() {
		ICVSRepositoryLocation[] locations = CVSUIPlugin.getPlugin().getRepositoryManager().getKnownRepositoryLocations();
		AdaptableList input = new AdaptableList(locations);
		table.setInput(input);
		if (locations.length == 0) {
			useNewRepo.setSelection(true);
            useExistingRepo.setSelection(false);
            table.getTable().setEnabled(false);
		} else {
            useNewRepo.setSelection(false);
			useExistingRepo.setSelection(true);
            table.getTable().setEnabled(true);
            result = locations[0];
			table.setSelection(new StructuredSelection(result));
		}
        setPageComplete(true);
	}
	
	public ICVSRepositoryLocation getLocation() {
		return result;
	}
	public void setVisible(boolean visible) {
		super.setVisible(visible);
		if (visible) {
			useExistingRepo.setFocus();
		}
	}
	
	public void setExtendedDescription(String extendedDescription) {
		this.extendedDescription = extendedDescription;
	}
	
	private void traverseRepositories(char c) {
		TableItem[] items = table.getTable().getItems();
		TableItem currentSelection = table.getTable().getSelection()[0];
		int currentSelectionIndex = 0;
		for (int i = 0; i < items.length; i++) {
			if (items[i].equals(currentSelection)) {
				currentSelectionIndex = i;
				break;
			}
		}
		for (int i = currentSelectionIndex + 1; i < items.length; i++) {
			if (c == items[i].getText().charAt(1)) {
				table.getTable().setSelection(i);
				return;
			}
		}
		for (int i = 0; i < currentSelectionIndex; i++) {
			if (c == items[i].getText().charAt(1)) {
				table.getTable().setSelection(i);
				return;
			}
		}
	}
}

Back to the top