Cleanup code whitespace
[nbgit.git] / src / org / nbgit / ui / update / UpdateAction.java
blob0eaff71e0a14b47a28a9cb0d01652e50c752f52b
1 /*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6 * The contents of this file are subject to the terms of either the GNU
7 * General Public License Version 2 only ("GPL") or the Common
8 * Development and Distribution License("CDDL") (collectively, the
9 * "License"). You may not use this file except in compliance with the
10 * License. You can obtain a copy of the License at
11 * http://www.netbeans.org/cddl-gplv2.html
12 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13 * specific language governing permissions and limitations under the
14 * License. When distributing the software, include this License Header
15 * Notice in each file and include the License file at
16 * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17 * particular file as subject to the "Classpath" exception as provided
18 * by Sun in the GPL Version 2 section of the License file that
19 * accompanied this code. If applicable, add the following below the
20 * License Header, with the fields enclosed by brackets [] replaced by
21 * your own identifying information:
22 * "Portions Copyrighted [year] [name of copyright owner]"
24 * Contributor(s):
26 * The Original Software is NetBeans. The Initial Developer of the Original
27 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28 * Microsystems, Inc. All Rights Reserved.
29 * Portions Copyright 2008 Alexander Coles (Ikonoklastik Productions).
31 * If you wish your version of this file to be governed by only the CDDL
32 * or only the GPL Version 2, indicate your decision by adding
33 * "[Contributor] elects to include this software in this distribution
34 * under the [CDDL or GPL Version 2] license." If you do not indicate a
35 * single choice of license, a recipient has the option to distribute
36 * your version of this file under either the CDDL, the GPL Version 2 or
37 * to extend the choice of license to its licensees as provided above.
38 * However, if you add GPL Version 2 code and therefore, elected the GPL
39 * Version 2 license, then the option applies only if the new code is
40 * made subject to such option by the copyright holder.
42 package org.nbgit.ui.update;
44 import java.awt.event.ActionEvent;
45 import java.io.File;
46 import java.util.List;
47 import org.nbgit.Git;
48 import org.nbgit.GitProgressSupport;
49 import org.nbgit.OutputLogger;
50 import org.nbgit.util.GitCommand;
51 import org.nbgit.util.GitUtils;
52 import org.nbgit.ui.ContextAction;
53 import org.netbeans.modules.versioning.spi.VCSContext;
54 import org.openide.filesystems.FileObject;
55 import org.openide.filesystems.FileUtil;
56 import org.openide.util.NbBundle;
57 import org.openide.util.RequestProcessor;
59 /**
60 * Update action for Git:
61 * git update - update or merge working directory
63 * @author John Rice
65 public class UpdateAction extends ContextAction {
67 public UpdateAction(String name, VCSContext context)
69 super(name, context);
72 public void performAction(ActionEvent e)
74 update(context);
77 public static void update(final VCSContext ctx)
79 final File root = GitUtils.getRootFile(ctx);
80 if (root == null)
81 return;
82 String repository = root.getAbsolutePath();
83 String rev = null;
85 final Update update = new Update(root);
86 if (!update.showDialog())
87 return;
88 rev = update.getSelectionRevision();
89 final boolean doForcedUpdate = update.isForcedUpdateRequested();
90 final String revStr = rev;
92 RequestProcessor rp = Git.getInstance().getRequestProcessor(repository);
93 GitProgressSupport support = new GitProgressSupport() {
95 public void perform()
97 boolean bNoUpdates = true;
98 OutputLogger logger = getLogger();
100 logger.outputInRed(
101 NbBundle.getMessage(UpdateAction.class,
102 "MSG_UPDATE_TITLE")); // NOI18N
103 logger.outputInRed(
104 NbBundle.getMessage(UpdateAction.class,
105 "MSG_UPDATE_TITLE_SEP")); // NOI18N
106 logger.output(
107 NbBundle.getMessage(UpdateAction.class,
108 "MSG_UPDATE_INFO_SEP", revStr, root.getAbsolutePath())); // NOI18N
109 List<String> list = GitCommand.doUpdateAll(root, doForcedUpdate, revStr);
111 if (list != null && !list.isEmpty()) {
112 bNoUpdates = GitCommand.isNoUpdates(list.get(0));
113 //logger.clearOutput();
114 logger.output(list);
115 logger.output(""); // NOI18N
117 // refresh filesystem to take account of changes
118 FileObject rootObj = FileUtil.toFileObject(root);
119 try {
120 rootObj.getFileSystem().refresh(true);
121 } catch (Exception ex) {
124 // Force Status Refresh from this dir and below
125 if (!bNoUpdates)
126 GitUtils.forceStatusRefreshProject(ctx);
128 logger.outputInRed(
129 NbBundle.getMessage(UpdateAction.class,
130 "MSG_UPDATE_DONE")); // NOI18N
131 logger.output(""); // NOI18N
135 support.start(rp, repository, org.openide.util.NbBundle.getMessage(UpdateAction.class, "MSG_Update_Progress")); // NOI18N