1 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 ; 37 import java.io.IOException ; 38 import org.tigris.subversion.svnclientadapter.*; 39 40 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 getBaseName(Node [] activatedNodes) { 51 return "Delete"; } 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")); descriptor.setTitle(NbBundle.getMessage(DeleteLocalAction.class, "CTL_DeleteLocal_Title")); descriptor.setMessageType(JOptionPane.WARNING_MESSAGE); 62 descriptor.setOptionType(NotifyDescriptor.YES_NO_OPTION); 63 64 Object 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 [] files = ctx.getFiles(); 92 for (int i = 0; i < files.length; i++) { 93 if(support.isCanceled()) { 94 return; 95 } 96 97 File 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 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 107 } 108 lock = fo.lock(); 109 fo.delete(lock); 110 } catch (IOException e) { 111 ErrorManager err = ErrorManager.getDefault(); 112 err.annotate(e, NbBundle.getMessage(DeleteLocalAction.class, "BK0001", file.getAbsolutePath())); err.notify(e); 114 } finally { 115 if (lock != null) { 116 lock.releaseLock(); 117 } 118 } 119 } 120 } 121 } 122 123 } 124 | Popular Tags |