View | Details | Raw Unified | Return to bug 308284 | Differences between
and this patch

Collapse All | Expand All

(-)a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/clone/GitProjectsImportPage.java (-105 / +1 lines)
Lines 88-197 Link Here
88
88
89
	private File gitRepositoryDir;
89
	private File gitRepositoryDir;
90
90
91
	class ProjectRecord {
92
		File projectSystemFile;
93
94
		String projectName;
95
96
		Object parent;
97
98
		int level;
99
100
		IProjectDescription description;
101
102
		/**
103
		 * Create a record for a project based on the info in the file.
104
		 *
105
		 * @param file
106
		 */
107
		ProjectRecord(File file) {
108
			projectSystemFile = file;
109
			setProjectName();
110
		}
111
112
		/**
113
		 * @param parent
114
		 *            The parent folder of the .project file
115
		 * @param level
116
		 *            The number of levels deep in the provider the file is
117
		 */
118
		ProjectRecord(Object parent, int level) {
119
			this.parent = parent;
120
			this.level = level;
121
			setProjectName();
122
		}
123
124
		/**
125
		 * Set the name of the project based on the projectFile.
126
		 */
127
		private void setProjectName() {
128
			try {
129
				// If we don't have the project name try again
130
				if (projectName == null) {
131
					IPath path = new Path(projectSystemFile.getPath());
132
					// if the file is in the default location, use the directory
133
					// name as the project name
134
					if (isDefaultLocation(path)) {
135
						projectName = path.segment(path.segmentCount() - 2);
136
						description = ResourcesPlugin.getWorkspace()
137
								.newProjectDescription(projectName);
138
					} else {
139
						description = ResourcesPlugin.getWorkspace()
140
								.loadProjectDescription(path);
141
						projectName = description.getName();
142
					}
143
144
				}
145
			} catch (CoreException e) {
146
				// no good couldn't get the name
147
			}
148
		}
149
150
		/**
151
		 * Returns whether the given project description file path is in the
152
		 * default location for a project
153
		 *
154
		 * @param path
155
		 *            The path to examine
156
		 * @return Whether the given path is the default location for a project
157
		 */
158
		private boolean isDefaultLocation(IPath path) {
159
			// The project description file must at least be within the project,
160
			// which is within the workspace location
161
			if (path.segmentCount() < 2)
162
				return false;
163
			return path.removeLastSegments(2).toFile().equals(
164
					Platform.getLocation().toFile());
165
		}
166
167
		/**
168
		 * Get the name of the project
169
		 *
170
		 * @return String
171
		 */
172
		public String getProjectName() {
173
			return projectName;
174
		}
175
176
		/**
177
		 * Gets the label to be used when rendering this project record in the
178
		 * UI.
179
		 *
180
		 * @return String the label
181
		 * @since 3.4
182
		 */
183
		public String getProjectLabel() {
184
			if (description == null)
185
				return projectName;
186
187
			String path = projectSystemFile == null ? structureProvider
188
					.getLabel(parent) : projectSystemFile.getParent();
189
190
			return NLS.bind(UIText.WizardProjectsImportPage_projectLabel,
191
					projectName, path);
192
		}
193
	}
194
195
	private TreeViewer projectsList;
91
	private TreeViewer projectsList;
196
92
197
	private ProjectRecord[] selectedProjects = new ProjectRecord[0];
93
	private ProjectRecord[] selectedProjects = new ProjectRecord[0];
Lines 367-373 public String getText(Object element) { Link Here
367
					else
263
					else
368
						item.setChecked(false);
264
						item.setChecked(false);
369
				}
265
				}
370
				return ((ProjectRecord) element).getProjectLabel();
266
				return ((ProjectRecord) element).getProjectLabel(structureProvider);
371
			}
267
			}
372
		});
268
		});
373
269
(-)a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/clone/ProjectRecord.java (-1 / +136 lines)
Added Link Here
0
- 
1
package org.eclipse.egit.ui.internal.clone;
2
3
/*******************************************************************************
4
 * Copyright (c) 2004, 2008 IBM Corporation and others.
5
 * Copyright (C) 2007, Martin Oberhuber (martin.oberhuber@windriver.com)
6
 * Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@dewire.com>
7
 * Copyright (C) 2009, Mykola Nikishov <mn@mn.com.ua>
8
 * Copyright (C) 2010, Wim Jongman <wim.jongman@remainsoftware.com>
9
 *
10
 * All rights reserved. This program and the accompanying materials
11
 * are made available under the terms of the Eclipse Public License v1.0
12
 * which accompanies this distribution, and is available at
13
 * http://www.eclipse.org/legal/epl-v10.html
14
 *******************************************************************************/
15
16
import java.io.File;
17
18
import org.eclipse.core.resources.IProjectDescription;
19
import org.eclipse.core.resources.ResourcesPlugin;
20
import org.eclipse.core.runtime.CoreException;
21
import org.eclipse.core.runtime.IPath;
22
import org.eclipse.core.runtime.Path;
23
import org.eclipse.core.runtime.Platform;
24
import org.eclipse.egit.ui.UIText;
25
import org.eclipse.osgi.util.NLS;
26
import org.eclipse.ui.wizards.datatransfer.IImportStructureProvider;
27
28
class ProjectRecord {
29
	File projectSystemFile;
30
31
	String projectName;
32
33
	Object parent;
34
35
	int level;
36
37
	IProjectDescription description;
38
39
	/**
40
	 * Create a record for a project based on the info in the file.
41
	 *
42
	 * @param file
43
	 */
44
	ProjectRecord(File file) {
45
		projectSystemFile = file;
46
		setProjectName();
47
	}
48
49
	/**
50
	 * @param parent
51
	 *            The parent folder of the .project file
52
	 * @param level
53
	 *            The number of levels deep in the provider the file is
54
	 */
55
	ProjectRecord(Object parent, int level) {
56
		this.parent = parent;
57
		this.level = level;
58
		setProjectName();
59
	}
60
61
	/**
62
	 * Set the name of the project based on the projectFile.
63
	 */
64
	private void setProjectName() {
65
		try {
66
			// If we don't have the project name try again
67
			if (projectName == null) {
68
				IPath path = new Path(projectSystemFile.getPath());
69
				// if the file is in the default location, use the directory
70
				// name as the project name
71
				if (isDefaultLocation(path)) {
72
					projectName = path.segment(path.segmentCount() - 2);
73
					description = ResourcesPlugin.getWorkspace()
74
							.newProjectDescription(projectName);
75
				} else {
76
					description = ResourcesPlugin.getWorkspace()
77
							.loadProjectDescription(path);
78
					projectName = description.getName();
79
				}
80
81
			}
82
		} catch (CoreException e) {
83
			// no good couldn't get the name
84
		}
85
	}
86
87
	/**
88
	 * Returns whether the given project description file path is in the
89
	 * default location for a project
90
	 *
91
	 * @param path
92
	 *            The path to examine
93
	 * @return Whether the given path is the default location for a project
94
	 */
95
	private boolean isDefaultLocation(IPath path) {
96
		// The project description file must at least be within the project,
97
		// which is within the workspace location
98
		if (path.segmentCount() < 2)
99
			return false;
100
		return path.removeLastSegments(2).toFile().equals(
101
				Platform.getLocation().toFile());
102
	}
103
104
	/**
105
	 * Get the name of the project
106
	 *
107
	 * @return String
108
	 */
109
	public String getProjectName() {
110
		return projectName;
111
	}
112
113
	/**
114
	 * Gets the label to be used when rendering this project record in the
115
	 * UI.
116
	 * @param structureProvider
117
	 *
118
	 * @return String the label
119
	 * @since 3.4
120
	 */
121
	public String getProjectLabel(IImportStructureProvider structureProvider) {
122
		if (description == null)
123
			return projectName;
124
125
		String path = projectSystemFile == null ? structureProvider
126
				.getLabel(parent) : projectSystemFile.getParent();
127
128
		return NLS.bind(UIText.WizardProjectsImportPage_projectLabel,
129
				projectName, path);
130
	}
131
132
	@Override
133
	public String toString() {
134
		return projectName;
135
	}
136
}

Return to bug 308284