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
* The Original Software is NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
* Microsystems, Inc. All Rights Reserved.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
42
package org.netbeans.modules.subversion.ui.project;
44
import org.netbeans.modules.subversion.Subversion;
45
import org.netbeans.modules.subversion.client.SvnProgressSupport;
46
import org.netbeans.modules.subversion.ui.commit.CommitAction;
47
import org.openide.util.actions.NodeAction;
48
import org.openide.util.*;
49
import org.openide.nodes.Node;
50
import org.openide.filesystems.FileObject;
51
import org.openide.filesystems.FileUtil;
52
import org.openide.loaders.DataObject;
53
import org.openide.loaders.DataShadow;
54
import org.netbeans.api.project.*;
57
import org.netbeans.modules.subversion.FileInformation;
58
import org.netbeans.modules.subversion.FileStatusCache;
59
import org.netbeans.modules.subversion.client.SvnClientExceptionHandler;
60
import org.netbeans.modules.subversion.ui.wizards.ImportWizard;
61
import org.netbeans.modules.subversion.util.Context;
62
import org.netbeans.modules.subversion.util.SvnUtils;
63
import org.tigris.subversion.svnclientadapter.SVNClientException;
64
import org.tigris.subversion.svnclientadapter.SVNUrl;
70
public final class ImportAction extends NodeAction {
72
public ImportAction() {
74
putValue("noIconInMenu", Boolean.TRUE); // NOI18N
77
public String getName() {
78
return NbBundle.getMessage(ImportAction.class, "BK0006"); // NOI18N
81
public HelpCtx getHelpCtx() {
85
protected boolean enable(Node[] nodes) {
86
if (nodes.length == 1) {
87
FileStatusCache cache = Subversion.getInstance().getStatusCache();
88
File dir = lookupImportDirectory(nodes[0]);
89
if (dir != null && dir.isDirectory()) {
90
FileInformation status = cache.getStatus(dir);
91
// mutually exclusive enablement logic with commit
92
if ((status.getStatus() & FileInformation.STATUS_MANAGED) == 0) {
93
// do not allow to import partial/nonatomic project, all must lie under imported common root
94
FileObject fo = FileUtil.toFileObject(dir);
95
Project p = FileOwnerQuery.getOwner(fo);
99
FileObject projectDir = p.getProjectDirectory();
100
return FileUtil.isParentOf(projectDir, fo) == false;
107
protected boolean asynchronous() {
111
protected void performAction(Node[] nodes) {
113
if(!Subversion.getInstance().checkClientAvailable()) {
117
if (nodes.length == 1) {
118
final File importDirectory = lookupImportDirectory(nodes[0]);
119
if (importDirectory != null) {
121
List<File> list = new ArrayList<File>(1);
122
list.add(importDirectory);
123
Context context = new Context(Context.getEmptyList(), list, Context.getEmptyList());
124
ImportWizard wizard = new ImportWizard(context);
125
if (!wizard.show()) return;
127
Map commitFiles = wizard.getCommitFiles();
128
String message = wizard.getMessage();
130
performAction(context, commitFiles, message);
135
private void performAction(final Context context,
136
final Map/*<SvnFileNode, CommitOptions>*/ commitFiles,
137
final String message)
141
repository = SvnUtils.getRepositoryRootUrl(context.getRootFiles()[0]);
142
} catch (SVNClientException ex) {
143
SvnClientExceptionHandler.notifyException(ex, true, true);
146
RequestProcessor rp = Subversion.getInstance().getRequestProcessor(repository);
147
SvnProgressSupport support = new SvnProgressSupport() {
148
public void perform() {
149
CommitAction.performCommit(message, commitFiles, context, this, true);
152
support.start(rp, repository, org.openide.util.NbBundle.getMessage(ImportAction.class, "LBL_Import_Progress"));
155
public boolean cancel() {
159
private File lookupImportDirectory(Node node) {
160
File importDirectory = null;
161
Project project = (Project) node.getLookup().lookup(Project.class);
162
if (project != null) {
163
Sources sources = ProjectUtils.getSources(project);
164
SourceGroup[] groups = sources.getSourceGroups(Sources.TYPE_GENERIC);
165
if (groups.length == 1) {
166
FileObject root = groups[0].getRootFolder();
167
importDirectory = FileUtil.toFile(root);
169
importDirectory = FileUtil.toFile(project.getProjectDirectory());
172
FileObject fo = null;
173
Collection<? extends FileObject> fileObjects = node.getLookup().lookup(new Lookup.Template<FileObject>(FileObject.class)).allInstances();
174
if (fileObjects.size() > 0) {
175
fo = fileObjects.iterator().next();
177
DataObject dataObject = node.getCookie(DataObject.class);
178
if (dataObject instanceof DataShadow) {
179
dataObject = ((DataShadow) dataObject).getOriginal();
181
if (dataObject != null) {
182
fo = dataObject.getPrimaryFile();
187
File f = FileUtil.toFile(fo);
188
if (f != null && f.isDirectory()) {
193
return importDirectory;