1 19 package org.netbeans.modules.subversion.ui.browser; 20 21 import java.awt.event.ActionEvent ; 22 import java.beans.PropertyChangeEvent ; 23 import java.beans.PropertyChangeListener ; 24 import java.beans.PropertyVetoException ; 25 import java.sql.Date ; 26 import javax.swing.Action ; 27 import javax.swing.JButton ; 28 import org.netbeans.modules.subversion.RepositoryFile; 29 import org.netbeans.modules.subversion.ui.browser.RepositoryPathNode.RepositoryPathEntry; 30 import org.openide.DialogDescriptor; 31 import org.openide.DialogDisplayer; 32 import org.openide.ErrorManager; 33 import org.openide.NotifyDescriptor; 34 import org.openide.explorer.ExplorerManager; 35 import org.openide.nodes.Children; 36 import org.openide.nodes.Node; 37 import org.openide.util.RequestProcessor; 38 import org.tigris.subversion.svnclientadapter.SVNNodeKind; 39 import org.tigris.subversion.svnclientadapter.SVNRevision; 40 41 46 public class CreateFolderAction extends BrowserAction implements PropertyChangeListener { 47 private final String defaultFolderName; 48 49 public CreateFolderAction(String defaultFolderName) { 50 this.defaultFolderName = defaultFolderName; 51 putValue(Action.NAME, org.openide.util.NbBundle.getMessage(RepositoryPathNode.class, "CTL_Action_MakeDir")); setEnabled(false); 53 } 54 55 public void propertyChange(PropertyChangeEvent evt) { 56 if (ExplorerManager.PROP_SELECTED_NODES.equals(evt.getPropertyName())) { 57 setEnabled(isEnabled()); 58 } 59 } 60 61 public boolean isEnabled() { 62 Browser browser = getBrowser(); 63 if(browser == null) { 64 return false; 65 } 66 67 if(browser.getBrowserPanel()==null) { 68 return false; 69 } 70 if(browser.getExplorerManager().getRootContext() == Node.EMPTY) { 71 return false; 72 } 73 Node[] nodes = getBrowser().getSelectedNodes(); 74 if(nodes.length != 1) { 75 return false; 76 } 77 return nodes[0] instanceof RepositoryPathNode && 78 ((RepositoryPathNode) nodes[0]).getEntry().getSvnNodeKind() == SVNNodeKind.DIR; 79 } 80 81 84 public void setBrowser(Browser browser) { 85 Browser oldBrowser = getBrowser(); 86 if(oldBrowser!=null) { 87 oldBrowser.removePropertyChangeListener(this); 88 } 89 browser.addPropertyChangeListener(this); 90 super.setBrowser(browser); 91 } 92 93 public void actionPerformed(ActionEvent e) { 94 RequestProcessor.getDefault().post(new Runnable () { 95 public void run() { 96 Node[] nodes = getSelectedNodes(); 97 if(nodes.length > 1) { 98 return; 99 } 100 101 RepositoryPathNode repositoryPathNode = (RepositoryPathNode) nodes[0]; 102 Children children = repositoryPathNode.getChildren(); 103 Node[] childNodes = children.getNodes(); 104 if(childNodes.length > 0) { 105 try { 106 getExplorerManager().setSelectedNodes(new Node[] {childNodes[0]}); 108 } catch (PropertyVetoException ex) { 109 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); } 111 } 112 113 DialogDescriptor.InputLine input = 114 new DialogDescriptor.InputLine(java.util.ResourceBundle.getBundle("org/netbeans/modules/subversion/ui/browser/Bundle").getString("CTL_Browser_NewFolder_Prompt"), java.util.ResourceBundle.getBundle("org/netbeans/modules/subversion/ui/browser/Bundle").getString("CTL_Browser_NewFolder_Title")); 115 input.setInputText(defaultFolderName); 116 DialogDisplayer.getDefault().notify(input); 117 String newDir = input.getInputText().trim(); 118 if(input.getValue() == DialogDescriptor.CANCEL_OPTION || 119 input.getValue() == DialogDescriptor.CLOSED_OPTION || 120 newDir.equals("")) { 122 return; 123 } 124 125 children = repositoryPathNode.getChildren(); 126 if(children != null && children.getNodesCount() > 0) { 127 childNodes = children.getNodes(); 128 for (int i = 0; i < childNodes.length; i++) { 129 if(childNodes[i].getDisplayName().equals(newDir)) { 130 JButton ok = new JButton (java.util.ResourceBundle.getBundle("org/netbeans/modules/subversion/ui/browser/Bundle").getString("CTL_Browser_OK")); 131 NotifyDescriptor descriptor = new NotifyDescriptor( 132 org.openide.util.NbBundle.getMessage(CreateFolderAction.class, "MSG_Browser_FolderExists", newDir), java.util.ResourceBundle.getBundle("org/netbeans/modules/subversion/ui/browser/Bundle").getString("MSG_Browser_WrongFolerName"), NotifyDescriptor.DEFAULT_OPTION, 135 NotifyDescriptor.ERROR_MESSAGE, 136 new Object [] { ok }, 137 ok); 138 DialogDisplayer.getDefault().notify(descriptor); 139 return; 140 } 141 } 142 } 143 144 RepositoryFile parentFile = repositoryPathNode.getEntry().getRepositoryFile(); 145 Node segmentNode = repositoryPathNode; 146 String [] segments = newDir.split("/"); for (int i = 0; i < segments.length; i++) { 148 149 RepositoryFile newFile = parentFile.appendPath(segments[i]); 150 RepositoryPathEntry entry = new RepositoryPathEntry(newFile, SVNNodeKind.DIR, new SVNRevision(0), new Date (System.currentTimeMillis()), ""); Node node = RepositoryPathNode.createBrowserPathNode(getBrowser(), entry); 152 Node[] newChild = new Node[] {node}; 153 segmentNode.getChildren().add(newChild); 154 segmentNode = node; 155 parentFile = newFile; 156 157 if( i == segments.length - 1 ) { 158 try { 160 setSelectedNodes(newChild); 161 } catch (PropertyVetoException ex) { 162 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); } 164 } 165 } 166 } 167 }); 168 } 169 } | Popular Tags |