KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > subversion > ui > browser > SelectPathAction


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.subversion.ui.browser;
20
21 import java.awt.event.ActionEvent JavaDoc;
22 import java.beans.PropertyVetoException JavaDoc;
23 import javax.swing.AbstractAction JavaDoc;
24 import javax.swing.Action JavaDoc;
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 /**
31  *
32  * @author Tomas Stupka
33  */

34 public class SelectPathAction extends AbstractAction JavaDoc {
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")); // NOI18N
45
setEnabled(true);
46     }
47     
48     public void actionPerformed(ActionEvent JavaDoc 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 JavaDoc ex) {
57             ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); // should not happen
58
}
59     }
60
61     private Node[] getSelectionNodes() {
62         if(selectionNodes == null) {
63             String JavaDoc[] 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