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]"
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
.netbeans
.modules
.git
.ui
.update
;
44 import java
.awt
.event
.ActionEvent
;
46 import java
.util
.List
;
47 import javax
.swing
.Action
;
48 import org
.netbeans
.modules
.git
.Git
;
49 import org
.netbeans
.modules
.git
.GitException
;
50 import org
.netbeans
.modules
.git
.GitProgressSupport
;
51 import org
.netbeans
.modules
.git
.OutputLogger
;
52 import org
.netbeans
.modules
.git
.ui
.actions
.ContextAction
;
53 import org
.netbeans
.modules
.git
.util
.GitCommand
;
54 import org
.netbeans
.modules
.git
.util
.GitUtils
;
55 import org
.netbeans
.modules
.versioning
.spi
.VCSContext
;
56 import org
.openide
.DialogDisplayer
;
57 import org
.openide
.NotifyDescriptor
;
58 import org
.openide
.filesystems
.FileObject
;
59 import org
.openide
.filesystems
.FileUtil
;
60 import org
.openide
.util
.NbBundle
;
61 import org
.openide
.util
.RequestProcessor
;
64 * Update action for Git:
65 * git update - update or merge working directory
69 public class UpdateAction
extends ContextAction
{
71 private final VCSContext context
;
73 public UpdateAction(String name
, VCSContext context
) {
74 this.context
= context
;
75 putValue(Action
.NAME
, name
);
78 public void performAction(ActionEvent e
) {
82 public static void update(final VCSContext ctx
){
83 final File root
= GitUtils
.getRootFile(ctx
);
84 if (root
== null) return;
85 String repository
= root
.getAbsolutePath();
88 final Update update
= new Update(root
);
89 if (!update
.showDialog()) {
92 rev
= update
.getSelectionRevision();
93 final boolean doForcedUpdate
= update
.isForcedUpdateRequested();
94 final String revStr
= rev
;
96 RequestProcessor rp
= Git
.getInstance().getRequestProcessor(repository
);
97 GitProgressSupport support
= new GitProgressSupport() {
98 public void perform() {
99 boolean bNoUpdates
= true;
100 OutputLogger logger
= getLogger();
103 NbBundle
.getMessage(UpdateAction
.class,
104 "MSG_UPDATE_TITLE")); // NOI18N
106 NbBundle
.getMessage(UpdateAction
.class,
107 "MSG_UPDATE_TITLE_SEP")); // NOI18N
109 NbBundle
.getMessage(UpdateAction
.class,
110 "MSG_UPDATE_INFO_SEP", revStr
, root
.getAbsolutePath())); // NOI18N
111 List
<String
> list
= GitCommand
.doUpdateAll(root
, doForcedUpdate
, revStr
);
113 if (list
!= null && !list
.isEmpty()){
114 bNoUpdates
= GitCommand
.isNoUpdates(list
.get(0));
115 //logger.clearOutput();
117 logger
.output(""); // NOI18N
119 // refresh filesystem to take account of changes
120 FileObject rootObj
= FileUtil
.toFileObject(root
);
122 rootObj
.getFileSystem().refresh(true);
123 } catch (Exception ex
) {
126 } catch (GitException ex
) {
127 NotifyDescriptor
.Exception e
= new NotifyDescriptor
.Exception(ex
);
128 DialogDisplayer
.getDefault().notifyLater(e
);
131 // Force Status Refresh from this dir and below
133 GitUtils
.forceStatusRefreshProject(ctx
);
136 NbBundle
.getMessage(UpdateAction
.class,
137 "MSG_UPDATE_DONE")); // NOI18N
138 logger
.output(""); // NOI18N
141 support
.start(rp
, repository
, org
.openide
.util
.NbBundle
.getMessage(UpdateAction
.class, "MSG_Update_Progress")); // NOI18N
145 public boolean isEnabled() {
146 return GitUtils
.getRootFile(context
) != null;