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 *******************************************************************************/
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
;
29 File projectSystemFile
;
37 IProjectDescription description
;
40 * Create a record for a project based on the info in the file.
44 ProjectRecord(File file
) {
45 projectSystemFile
= file
;
51 * The parent folder of the .project file
53 * The number of levels deep in the provider the file is
55 ProjectRecord(Object parent
, int level
) {
62 * Set the name of the project based on the projectFile.
64 private void setProjectName() {
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
);
76 description
= ResourcesPlugin
.getWorkspace()
77 .loadProjectDescription(path
);
78 projectName
= description
.getName();
82 } catch (CoreException e
) {
83 // no good couldn't get the name
88 * Returns whether the given project description file path is in the
89 * default location for a project
93 * @return Whether the given path is the default location for a project
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)
100 return path
.removeLastSegments(2).toFile().equals(
101 Platform
.getLocation().toFile());
105 * Get the name of the project
109 public String
getProjectName() {
114 * Gets the label to be used when rendering this project record in the
116 * @param structureProvider
118 * @return String the label
121 public String
getProjectLabel(IImportStructureProvider structureProvider
) {
122 if (description
== null)
125 String path
= projectSystemFile
== null ? structureProvider
126 .getLabel(parent
) : projectSystemFile
.getParent();
128 return NLS
.bind(UIText
.WizardProjectsImportPage_projectLabel
,
133 public String
toString() {