KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > subversion > ui > commit > DeleteLocalAction


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.subversion.ui.commit;
21
22 import org.netbeans.modules.subversion.*;
23 import org.netbeans.modules.subversion.client.*;
24 import org.netbeans.modules.subversion.ui.actions.*;
25 import org.netbeans.modules.subversion.util.*;
26 import org.openide.filesystems.FileObject;
27 import org.openide.filesystems.FileUtil;
28 import org.openide.filesystems.FileLock;
29 import org.openide.ErrorManager;
30 import org.openide.NotifyDescriptor;
31 import org.openide.DialogDisplayer;
32 import org.openide.nodes.Node;
33 import org.openide.util.NbBundle;
34
35 import javax.swing.*;
36 import java.io.File JavaDoc;
37 import java.io.IOException JavaDoc;
38 import org.tigris.subversion.svnclientadapter.*;
39
40 /**
41  * Delete action enabled for new local files (not yet in repository).
42  * It eliminates <tt>.svn/entries</tt> scheduling if exists too.
43  *
44  * @author Petr Kuzel
45  */

46 public final class DeleteLocalAction extends ContextAction {
47
48     public static final int LOCALLY_DELETABLE_MASK = FileInformation.STATUS_NOTVERSIONED_NEWLOCALLY | FileInformation.STATUS_VERSIONED_ADDEDLOCALLY;
49
50     protected String JavaDoc getBaseName(Node [] activatedNodes) {
51         return "Delete"; // NOI18N
52
}
53
54     protected int getFileEnabledStatus() {
55         return LOCALLY_DELETABLE_MASK;
56     }
57     
58     protected void performContextAction(final Node[] nodes) {
59         NotifyDescriptor descriptor = new NotifyDescriptor.Confirmation(NbBundle.getMessage(DeleteLocalAction.class, "CTL_DeleteLocal_Prompt")); // NOI18N
60
descriptor.setTitle(NbBundle.getMessage(DeleteLocalAction.class, "CTL_DeleteLocal_Title")); // NOI18N
61
descriptor.setMessageType(JOptionPane.WARNING_MESSAGE);
62         descriptor.setOptionType(NotifyDescriptor.YES_NO_OPTION);
63
64         Object JavaDoc res = DialogDisplayer.getDefault().notify(descriptor);
65         if (res != NotifyDescriptor.YES_OPTION) {
66             return;
67         }
68         
69         final Context ctx = getContext(nodes);
70         ProgressSupport support = new ContextAction.ProgressSupport(this, nodes) {
71             public void perform() {
72                 performDelete(ctx, this);
73             }
74         };
75         support.start(createRequestProcessor(nodes));
76     }
77     
78     public static void performDelete(Context ctx, SvnProgressSupport support) {
79
80         SvnClient client;
81         try {
82             client = Subversion.getInstance().getClient(ctx, support);
83         } catch (SVNClientException ex) {
84             ErrorManager.getDefault().notify(ex);
85             return;
86         }
87
88         if(support.isCanceled()) {
89             return;
90         }
91         File JavaDoc[] files = ctx.getFiles();
92         for (int i = 0; i < files.length; i++) {
93             if(support.isCanceled()) {
94                 return;
95             }
96         
97             File JavaDoc file = files[i];
98             FileObject fo = FileUtil.toFileObject(file);
99             if (fo != null) {
100                 FileLock lock = null;
101                 try {
102                     try {
103                         client.revert(file, false);
104                     } catch (SVNClientException ex) {
105                         // XXX use ExceptionHandler
106
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
107                     }
108                     lock = fo.lock();
109                     fo.delete(lock);
110                 } catch (IOException JavaDoc e) {
111                     ErrorManager err = ErrorManager.getDefault();
112                     err.annotate(e, NbBundle.getMessage(DeleteLocalAction.class, "BK0001", file.getAbsolutePath())); // NOI18N
113
err.notify(e);
114                 } finally {
115                     if (lock != null) {
116                         lock.releaseLock();
117                     }
118                 }
119             }
120         }
121     }
122     
123 }
124
Popular Tags