001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.subversion.ui.status;
043:
044: import java.io.File;
045: import org.netbeans.modules.subversion.util.*;
046: import org.netbeans.modules.subversion.util.Context;
047: import org.netbeans.modules.subversion.FileInformation;
048: import org.netbeans.modules.subversion.FileStatusCache;
049: import org.netbeans.modules.subversion.Subversion;
050: import org.netbeans.modules.subversion.client.SvnClient;
051: import org.netbeans.modules.subversion.client.SvnClientExceptionHandler;
052: import org.netbeans.modules.subversion.client.SvnProgressSupport;
053: import org.netbeans.modules.subversion.ui.actions.ContextAction;
054: import org.openide.nodes.Node;
055: import org.tigris.subversion.svnclientadapter.ISVNStatus;
056: import org.tigris.subversion.svnclientadapter.SVNClientException;
057: import org.tigris.subversion.svnclientadapter.SVNStatusKind;
058:
059: /**
060: * Context sensitive status action. It opens the Subversion
061: * view and sets its context.
062: *
063: * @author Petr Kuzel
064: */
065: public class StatusAction extends ContextAction {
066:
067: private static final int enabledForStatus = FileInformation.STATUS_MANAGED;
068:
069: protected String getBaseName(Node[] nodes) {
070: return "CTL_MenuItem_ShowChanges"; // NOI18N
071: }
072:
073: protected int getFileEnabledStatus() {
074: return enabledForStatus;
075: }
076:
077: public void performContextAction(Node[] nodes) {
078:
079: if (!Subversion.getInstance().checkClientAvailable()) {
080: return;
081: }
082:
083: Context ctx = SvnUtils.getCurrentContext(nodes);
084: final SvnVersioningTopComponent stc = SvnVersioningTopComponent
085: .getInstance();
086: stc.setContentTitle(getContextDisplayName(nodes));
087: stc.setContext(ctx);
088: stc.open();
089: stc.requestActive();
090: stc.performRefreshAction();
091: }
092:
093: /**
094: * Connects to repository and gets recent status.
095: */
096: public static void executeStatus(final Context context,
097: SvnProgressSupport support) {
098:
099: if (context == null || context.getRoots().size() == 0) {
100: return;
101: }
102:
103: try {
104: SvnClient client;
105: try {
106: client = Subversion.getInstance().getClient(context,
107: support);
108: } catch (SVNClientException ex) {
109: SvnClientExceptionHandler.notifyException(ex, true,
110: true);
111: return;
112: }
113:
114: Subversion.getInstance().getStatusCache().refreshCached(
115: context);
116: File[] roots = context.getRootFiles();
117: for (int i = 0; i < roots.length; i++) {
118: if (support.isCanceled()) {
119: return;
120: }
121: File root = roots[i];
122: ISVNStatus[] statuses = client.getStatus(root, true,
123: false, true); // cache refires events
124: if (support.isCanceled()) {
125: return;
126: }
127:
128: FileStatusCache cache = Subversion.getInstance()
129: .getStatusCache();
130: for (int s = 0; s < statuses.length; s++) {
131: if (support.isCanceled()) {
132: return;
133: }
134: ISVNStatus status = statuses[s];
135: File file = status.getFile();
136: if (file.isDirectory()
137: && status.getTextStatus().equals(
138: SVNStatusKind.UNVERSIONED)) {
139: // XXX could have been created externally and the cache ignores by designe
140: // a newly created folders children.
141: // As this is the place were such files should be recognized,
142: // we will force the refresh recursivelly.
143: SvnUtils.refreshRecursively(file);
144: } else {
145: cache.refresh(file, status);
146: }
147:
148: }
149: }
150: } catch (SVNClientException ex) {
151: support.annotate(ex);
152: }
153: }
154: }
|