KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > subversion > ui > status > StatusAction


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
20 package org.netbeans.modules.subversion.ui.status;
21
22 import java.io.File JavaDoc;
23 import org.netbeans.modules.subversion.util.*;
24 import org.netbeans.modules.subversion.util.Context;
25 import org.netbeans.modules.subversion.FileInformation;
26 import org.netbeans.modules.subversion.FileStatusCache;
27 import org.netbeans.modules.subversion.Subversion;
28 import org.netbeans.modules.subversion.client.SvnClient;
29 import org.netbeans.modules.subversion.client.SvnProgressSupport;
30 import org.netbeans.modules.subversion.ui.actions.ContextAction;
31 import org.openide.ErrorManager;
32 import org.openide.nodes.Node;
33 import org.tigris.subversion.svnclientadapter.ISVNStatus;
34 import org.tigris.subversion.svnclientadapter.SVNClientException;
35 import org.tigris.subversion.svnclientadapter.SVNStatusKind;
36
37 /**
38  * Context sensitive status action. It opens the Subversion
39  * view and sets its context.
40  *
41  * @author Petr Kuzel
42  */

43 public class StatusAction extends ContextAction {
44     
45     private static final int enabledForStatus = FileInformation.STATUS_MANAGED;
46     
47     protected String JavaDoc getBaseName(Node[] nodes) {
48         return "CTL_MenuItem_ShowChanges"; // NOI18N
49
}
50
51     protected int getFileEnabledStatus() {
52         return enabledForStatus;
53     }
54
55     public void performContextAction(Node[] nodes) {
56         Context ctx = SvnUtils.getCurrentContext(nodes);
57         final SvnVersioningTopComponent stc = SvnVersioningTopComponent.getInstance();
58         stc.setContentTitle(getContextDisplayName(nodes));
59         stc.setContext(ctx);
60         stc.open();
61         stc.requestActive();
62         stc.performRefreshAction();
63     }
64
65     /**
66      * Connects to repository and gets recent status.
67      */

68     public static void executeStatus(final Context context, SvnProgressSupport support) {
69
70         if (context == null || context.getRoots().size() == 0) {
71             return;
72         }
73             
74         try {
75             SvnClient client;
76             try {
77                 client = Subversion.getInstance().getClient(context, support);
78             } catch (SVNClientException ex) {
79                 ErrorManager.getDefault().notify(ex);
80                 return;
81             }
82
83             Subversion.getInstance().getStatusCache().refreshCached(context);
84             File JavaDoc[] roots = context.getRootFiles();
85             for (int i=0; i<roots.length; i++) {
86                 if(support.isCanceled()) {
87                     return;
88                 }
89                 File JavaDoc root = roots[i];
90                 ISVNStatus[] statuses = client.getStatus(root, true, false, true); // cache refires events
91
if(support.isCanceled()) {
92                     return;
93                 }
94
95                 for (int s = 0; s < statuses.length; s++) {
96                     if(support.isCanceled()) {
97                         return;
98                     }
99                     ISVNStatus status = statuses[s];
100                     FileStatusCache cache = Subversion.getInstance().getStatusCache();
101                     File JavaDoc file = status.getFile();
102                     SVNStatusKind kind = status.getRepositoryTextStatus();
103 // System.err.println(" File: " + file.getAbsolutePath() + " repo-status:" + kind );
104
cache.refresh(file, status);
105                 }
106             }
107         } catch (SVNClientException ex) {
108             support.annotate(ex);
109         }
110     }
111 }
Popular Tags