2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* Portions Copyrighted 2007 Sun Microsystems, Inc.
28
package org.netbeans.modules.php.project.ui;
31
import java.text.MessageFormat;
32
import org.netbeans.api.project.FileOwnerQuery;
33
import org.netbeans.api.project.Project;
34
import org.netbeans.api.project.ProjectInformation;
35
import org.netbeans.api.project.ProjectUtils;
36
import org.netbeans.api.project.SourceGroup;
37
import org.netbeans.api.project.Sources;
38
import org.netbeans.modules.php.project.PhpProject;
39
import org.openide.DialogDisplayer;
40
import org.openide.NotifyDescriptor;
41
import org.openide.filesystems.FileObject;
42
import org.openide.filesystems.FileUtil;
43
import org.openide.util.NbBundle;
49
public final class SourceRootsUi {
51
public static final String INVALID_SOURCE_ROOT_MSG = "MSG_InvalidSourceRoot"; // NOI18N
52
public static final String INVALID_SOURCE_ROOT_TTL = "TTL_InvalidSourceRoot"; // NOI18N
55
* checks if suggested source directory root is not occupied by another projects
57
* @param file File object of source root to verify
58
* @param projectFolder project wich will contain this source root
60
public static boolean isRootNotOccupied(File file, File projectFolder) {
61
Project p = FileOwnerQuery.getOwner(file.toURI());
62
boolean isInsideProject = file.getAbsolutePath().startsWith(projectFolder.getAbsolutePath() + File.separatorChar);
63
boolean isEqualToProject = file.getAbsolutePath().equalsIgnoreCase(projectFolder.getAbsolutePath());
65
// actions inside this IF are copied from ruby project and adopted
66
if (p != null && !isInsideProject && !isEqualToProject) {
67
final Sources sources = (Sources) p.getLookup().lookup(Sources.class);
68
if (sources == null) {
71
final SourceGroup[] sourceGroups = sources.getSourceGroups(Sources.TYPE_GENERIC);
72
final SourceGroup[] sourceGroupsPhp = sources.getSourceGroups(PhpProject.SOURCES_TYPE_PHP);
73
final SourceGroup[] groups = new SourceGroup[sourceGroups.length + sourceGroupsPhp.length];
74
System.arraycopy(sourceGroups, 0, groups, 0, sourceGroups.length);
75
System.arraycopy(sourceGroupsPhp, 0, groups, sourceGroups.length, sourceGroupsPhp.length);
76
final FileObject projectDirectory = p.getProjectDirectory();
77
final FileObject fileObject = FileUtil.toFileObject(file);
78
if (projectDirectory == null || fileObject == null) {
81
for (int i = 0; i < groups.length; i++) {
82
final FileObject sgRoot = groups[i].getRootFolder();
83
if (fileObject.equals(sgRoot)) {
86
if (!projectDirectory.equals(sgRoot) && FileUtil.isParentOf(sgRoot, fileObject)) {
95
public static void showSourceUsedDialog(File srcRoot) {
96
String srcRootPath = srcRoot.getPath();
98
Project p = FileOwnerQuery.getOwner(srcRoot.toURI());
99
ProjectInformation pi = ProjectUtils.getInformation(p);
100
String projectName = pi.getDisplayName();
102
String msg = MessageFormat.format(NbBundle.getMessage(SourceRootsUi.class, INVALID_SOURCE_ROOT_MSG), srcRootPath, projectName);
103
String title = NbBundle.getMessage(SourceRootsUi.class, INVALID_SOURCE_ROOT_TTL);
105
NotifyDescriptor d = new NotifyDescriptor(msg, title, NotifyDescriptor.OK_CANCEL_OPTION, NotifyDescriptor.WARNING_MESSAGE, new Object[]{NotifyDescriptor.OK_OPTION}, NotifyDescriptor.OK_OPTION);
106
DialogDisplayer.getDefault().notify(d);