1 19 20 package org.netbeans.modules.versioning.system.cvss.ui.actions; 21 22 import org.openide.filesystems.FileObject; 23 import org.openide.filesystems.FileUtil; 24 import org.openide.filesystems.FileLock; 25 import org.openide.ErrorManager; 26 import org.openide.NotifyDescriptor; 27 import org.openide.DialogDisplayer; 28 import org.openide.nodes.Node; 29 import org.openide.util.*; 30 import org.openide.util.NbBundle; 31 import org.openide.util.RequestProcessor; 32 import org.netbeans.modules.versioning.system.cvss.FileInformation; 33 import org.netbeans.lib.cvsclient.admin.StandardAdminHandler; 34 35 import javax.swing.*; 36 import java.awt.event.ActionEvent ; 37 import java.io.File ; 38 import java.io.IOException ; 39 40 46 public final class DeleteLocalAction extends AbstractSystemAction { 47 48 public static final int LOCALLY_DELETABLE_MASK = FileInformation.STATUS_NOTVERSIONED_NEWLOCALLY | FileInformation.STATUS_VERSIONED_ADDEDLOCALLY; 49 50 public void performCvsAction(Node[] nodes) { 51 NotifyDescriptor descriptor = new NotifyDescriptor.Confirmation(NbBundle.getMessage(DeleteLocalAction.class, "CTL_DeleteLocal_Prompt")); 52 descriptor.setTitle(NbBundle.getMessage(DeleteLocalAction.class, "CTL_DeleteLocal_Title")); 53 descriptor.setMessageType(JOptionPane.WARNING_MESSAGE); 54 descriptor.setOptionType(NotifyDescriptor.YES_NO_OPTION); 55 56 Object res = DialogDisplayer.getDefault().notify(descriptor); 57 if (res != NotifyDescriptor.YES_OPTION) { 58 return; 59 } 60 61 final File [] files = getContext(nodes).getFiles(); 62 RequestProcessor.getDefault().post(new Runnable () { 63 public void run() { 64 async(files); 65 } 66 }); 67 } 68 69 protected int getFileEnabledStatus() { 70 return LOCALLY_DELETABLE_MASK; 71 } 72 73 protected String getBaseName(Node [] activatedNodes) { 74 return "Delete"; } 76 77 protected boolean asynchronous() { 78 return false; 79 } 80 81 public void async(File [] files) { 82 for (int i = 0; i < files.length; i++) { 83 File file = files[i]; 84 StandardAdminHandler entries = new StandardAdminHandler(); 85 FileObject fo = FileUtil.toFileObject(file); 86 if (fo != null) { 87 FileLock lock = null; 88 try { 89 lock = fo.lock(); 90 entries.removeEntry(file); 91 fo.delete(lock); 92 } catch (IOException e) { 93 ErrorManager err = ErrorManager.getDefault(); 94 err.annotate(e, NbBundle.getMessage(DeleteLocalAction.class, "BK0001", file.getAbsolutePath())); 95 err.notify(e); 96 } finally { 97 if (lock != null) { 98 lock.releaseLock(); 99 } 100 } 101 } 102 } 103 } 104 } 105 | Popular Tags |