1 19 package org.netbeans.modules.subversion.ui.browser; 20 21 import java.awt.event.ActionEvent ; 22 import java.beans.PropertyVetoException ; 23 import javax.swing.AbstractAction ; 24 import javax.swing.Action ; 25 import org.openide.ErrorManager; 26 import org.openide.nodes.Children; 27 import org.openide.nodes.Node; 28 import org.tigris.subversion.svnclientadapter.SVNUrl; 29 30 34 public class SelectPathAction extends AbstractAction { 35 36 private final SVNUrl selectionUrl; 37 private Node[] selectionNodes; 38 private final Browser browser; 39 private final static Node[] EMPTY_NODES = new Node[0]; 40 41 public SelectPathAction(Browser browser, SVNUrl selection) { 42 this.browser = browser; 43 this.selectionUrl = selection; 44 putValue(Action.NAME, org.openide.util.NbBundle.getMessage(RepositoryPathNode.class, "CTL_Action_SelectPath")); setEnabled(true); 46 } 47 48 public void actionPerformed(ActionEvent e) { 49 Node[] nodes = getSelectionNodes(); 50 51 if(nodes == null || nodes == EMPTY_NODES) { 52 return; 53 } 54 try { 55 browser.getExplorerManager().setSelectedNodes(nodes); 56 } catch (PropertyVetoException ex) { 57 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); } 59 } 60 61 private Node[] getSelectionNodes() { 62 if(selectionNodes == null) { 63 String [] segments = selectionUrl.getPathSegments(); 64 Node node = (RepositoryPathNode) browser.getExplorerManager().getRootContext(); 65 66 for (int i = 0; i < segments.length; i++) { 67 Children children = node.getChildren(); 68 node = children.findChild(segments[i]); 69 if(node==null) { 70 break; 71 } 72 } 73 if(node == null) { 74 selectionNodes = EMPTY_NODES; 75 } else { 76 selectionNodes = new Node[] {node}; 77 } 78 } 79 return selectionNodes; 80 } 81 82 } | Popular Tags |