Remove dead code from ProjectRecord and GitProjectsImportPage
[egit.git] / org.eclipse.egit.ui / src / org / eclipse / egit / ui / internal / clone / ProjectRecord.java
blob009924728484189f73ff23a730c0a06f259401e8
1 package org.eclipse.egit.ui.internal.clone;
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>
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 *******************************************************************************/
16 import java.io.File;
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;
27 class ProjectRecord {
28 File projectSystemFile;
30 String projectName;
32 IProjectDescription description;
34 /**
35 * Create a record for a project based on the info in the file.
37 * @param file
39 ProjectRecord(File file) {
40 projectSystemFile = file;
41 setProjectName();
44 /**
45 * Set the name of the project based on the projectFile.
47 private void setProjectName() {
48 try {
49 // If we don't have the project name try again
50 if (projectName == null) {
51 IPath path = new Path(projectSystemFile.getPath());
52 // if the file is in the default location, use the directory
53 // name as the project name
54 if (isDefaultLocation(path)) {
55 projectName = path.segment(path.segmentCount() - 2);
56 description = ResourcesPlugin.getWorkspace()
57 .newProjectDescription(projectName);
58 } else {
59 description = ResourcesPlugin.getWorkspace()
60 .loadProjectDescription(path);
61 projectName = description.getName();
65 } catch (CoreException e) {
66 // no good couldn't get the name
70 /**
71 * Returns whether the given project description file path is in the
72 * default location for a project
74 * @param path
75 * The path to examine
76 * @return Whether the given path is the default location for a project
78 private boolean isDefaultLocation(IPath path) {
79 // The project description file must at least be within the project,
80 // which is within the workspace location
81 if (path.segmentCount() < 2)
82 return false;
83 return path.removeLastSegments(2).toFile().equals(
84 Platform.getLocation().toFile());
87 /**
88 * Get the name of the project
90 * @return String
92 public String getProjectName() {
93 return projectName;
96 /**
97 * Gets the label to be used when rendering this project record in the
98 * UI.
100 * @return String the label
101 * @since 3.4
103 public String getProjectLabel() {
104 if (description == null)
105 return projectName;
107 String path = projectSystemFile.getParent();
109 return NLS.bind(UIText.WizardProjectsImportPage_projectLabel,
110 projectName, path);
113 @Override
114 public String toString() {
115 return projectName;