1 19 package org.netbeans.modules.subversion.ui.relocate; 20 21 import java.awt.Dialog ; 22 import java.awt.event.ActionEvent ; 23 import java.awt.event.ActionListener ; 24 import java.io.File ; 25 import java.net.MalformedURLException ; 26 import java.util.ResourceBundle ; 27 import java.util.Set ; 28 import javax.swing.AbstractAction ; 29 import javax.swing.JButton ; 30 import javax.swing.event.DocumentEvent ; 31 import javax.swing.event.DocumentListener ; 32 import org.netbeans.modules.subversion.Subversion; 33 import org.netbeans.modules.subversion.client.SvnClient; 34 import org.netbeans.modules.subversion.client.SvnProgressSupport; 35 import org.netbeans.modules.subversion.util.SvnUtils; 36 import org.netbeans.modules.versioning.spi.VCSContext; 37 import org.openide.DialogDescriptor; 38 import org.openide.DialogDisplayer; 39 import org.openide.ErrorManager; 40 import org.openide.util.HelpCtx; 41 import org.openide.util.NbBundle; 42 import org.openide.util.RequestProcessor; 43 import org.tigris.subversion.svnclientadapter.SVNClientException; 44 import org.tigris.subversion.svnclientadapter.SVNUrl; 45 46 50 public class RelocateAction extends AbstractAction { 51 52 VCSContext ctx; 53 SvnProgressSupport support; 54 55 56 public RelocateAction(String name, VCSContext ctx) { 57 super(name); 58 this.ctx = ctx; 59 } 60 61 public boolean isEnabled() { 62 Set <File > roots = ctx.getRootFiles(); 63 if(roots == null || roots.size() != 1) { 64 return false; 65 } 66 File file = roots.iterator().next(); 67 return file != null && file.isDirectory(); 68 } 69 70 public void actionPerformed(ActionEvent event) { 71 ResourceBundle loc = NbBundle.getBundle(RelocateAction.class); 72 73 final RelocatePanel panel = new RelocatePanel(); 74 panel.getCurrentURL().setText(getCurrentURL()); 75 panel.getWorkingCopy().setText(getWorkingCopy()); 76 77 78 final JButton btnRelocate = new JButton (loc.getString("CTL_Relocate_Action_Name")); 79 btnRelocate.setEnabled(false); 80 btnRelocate.setToolTipText(loc.getString("TT_Relocate_Action")); 81 82 panel.getNewURL().getDocument().addDocumentListener(new DocumentListener () { 83 public void insertUpdate(DocumentEvent event) { 84 validate(panel, btnRelocate); 85 } 86 87 public void removeUpdate(DocumentEvent event) { 88 validate(panel, btnRelocate); 89 } 90 91 public void changedUpdate(DocumentEvent event) { 92 validate(panel, btnRelocate); 93 } 94 }); 95 JButton btnCancel = new JButton (loc.getString("CTL_Relocate_Action_Cancel")); 96 btnCancel.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(RelocateAction.class, "ACSD_Relocate_Action_Cancel")); DialogDescriptor descriptor = new DialogDescriptor(panel, loc.getString("CTL_Relocate_Title"), true, new Object [] {btnRelocate, btnCancel}, btnRelocate, DialogDescriptor.BOTTOM_ALIGN, null, null); 98 descriptor.setClosingOptions(null); 99 descriptor.setHelpCtx(new HelpCtx(RelocateAction.class)); 100 Dialog dialog = DialogDisplayer.getDefault().createDialog(descriptor); 101 dialog.getAccessibleContext().setAccessibleDescription(loc.getString("ACSD_Relocate")); 102 103 dialog.setVisible(true); 104 if (descriptor.getValue() != btnRelocate) 105 return; 106 107 panel.getNewURL().addActionListener(new ActionListener () { 108 public void actionPerformed(ActionEvent event) { 109 validate(panel, btnRelocate); 110 } 111 }); 112 113 final String newUrl = panel.getNewURL().getText(); 114 115 File root = ctx.getRootFiles().iterator().next(); 116 final SVNUrl repositoryUrl = SvnUtils.getRepositoryRootUrl(root); 117 final String wc = root.getAbsolutePath(); 118 RequestProcessor rp = Subversion.getInstance().getRequestProcessor(repositoryUrl); 119 try { 120 support = new SvnProgressSupport() { 121 SvnClient client = null; 122 protected void perform() { 123 try { 124 client = Subversion.getInstance().getClient(repositoryUrl); 125 } catch (SVNClientException ex) { 126 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 127 return; 128 } 129 130 try { 131 client.relocate(repositoryUrl.toString(), newUrl, wc, true); 132 } catch (SVNClientException ex) { 133 ErrorManager.getDefault().notify(ErrorManager.ERROR, ex); 134 } catch (Exception e) { 135 ErrorManager.getDefault().notify(ErrorManager.ERROR, e); 136 } 137 } 138 }; 139 support.start(rp, repositoryUrl, loc.getString("LBL_Relocate_Progress")); 140 } finally { 141 support = null; 142 } 143 } 144 145 private String getCurrentURL() { 146 File root = ctx.getRootFiles().iterator().next(); 147 final SVNUrl repositoryUrl = SvnUtils.getRepositoryRootUrl(root); 148 return repositoryUrl.toString(); 149 } 150 151 private String getWorkingCopy() { 152 File root = ctx.getRootFiles().iterator().next(); 153 final String working = root.getAbsolutePath(); 154 return working; 155 } 156 157 public void validate(RelocatePanel panel, JButton btnOk) { 158 try { 159 new SVNUrl(panel.getNewURL().getText()); 160 btnOk.setEnabled(true); 161 } catch (MalformedURLException e) { 162 btnOk.setEnabled(false); 163 } 164 165 } 166 } | Popular Tags |