Continued work to remove a bunch of Hg-related commands.
[nbgit.git] / src / org / netbeans / modules / git / ui / rollback / RollbackAction.java
blob0e3d0e141137459ead95c11fbdb51186a20c5a15
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.netbeans.modules.git.ui.rollback;
44 import java.awt.event.ActionEvent;
45 import java.io.File;
46 import java.util.List;
47 import javax.swing.Action;
48 import javax.swing.JOptionPane;
49 import org.netbeans.modules.git.FileInformation;
50 import org.netbeans.modules.git.FileStatusCache;
51 import org.netbeans.modules.git.Git;
52 import org.netbeans.modules.git.GitException;
53 import org.netbeans.modules.git.GitProgressSupport;
54 import org.netbeans.modules.git.OutputLogger;
55 import org.netbeans.modules.git.ui.actions.ContextAction;
56 import org.netbeans.modules.git.ui.update.ConflictResolvedAction;
57 import org.netbeans.modules.git.util.GitCommand;
58 import org.netbeans.modules.git.util.GitUtils;
59 import org.netbeans.modules.versioning.spi.VCSContext;
60 import org.openide.DialogDisplayer;
61 import org.openide.NotifyDescriptor;
62 import org.openide.util.NbBundle;
63 import org.openide.util.RequestProcessor;
66 /**
67 * Pull action for Git:
68 * git pull - pull changes from the specified source
70 * @author John Rice
72 public class RollbackAction extends ContextAction {
74 private final VCSContext context;
76 public RollbackAction(String name, VCSContext context) {
77 this.context = context;
78 putValue(Action.NAME, name);
81 public void performAction(ActionEvent e) {
82 rollback(context);
85 public static void rollback(final VCSContext ctx){
86 final File root = GitUtils.getRootFile(ctx);
87 if (root == null) return;
88 String repository = root.getAbsolutePath();
90 RequestProcessor rp = Git.getInstance().getRequestProcessor(repository);
91 GitProgressSupport support = new GitProgressSupport() {
92 public void perform() {
94 OutputLogger logger = getLogger();
95 try {
96 logger.outputInRed(
97 NbBundle.getMessage(RollbackAction.class,
98 "MSG_ROLLBACK_TITLE")); // NOI18N
99 logger.outputInRed(
100 NbBundle.getMessage(RollbackAction.class,
101 "MSG_ROLLBACK_TITLE_SEP")); // NOI18N
102 logger.output(
103 NbBundle.getMessage(StripAction.class,
104 "MSG_ROLLBACK_INFO_SEP", root.getAbsolutePath())); // NOI18N
105 NotifyDescriptor descriptor = new NotifyDescriptor.Confirmation(NbBundle.getMessage(RollbackAction.class, "MSG_ROLLBACK_CONFIRM_QUERY")); // NOI18N
106 descriptor.setTitle(NbBundle.getMessage(RollbackAction.class, "MSG_ROLLBACK_CONFIRM")); // NOI18N
107 descriptor.setMessageType(JOptionPane.WARNING_MESSAGE);
108 descriptor.setOptionType(NotifyDescriptor.YES_NO_OPTION);
110 Object res = DialogDisplayer.getDefault().notify(descriptor);
111 if (res == NotifyDescriptor.NO_OPTION) {
112 logger.outputInRed(
113 NbBundle.getMessage(RollbackAction.class,
114 "MSG_ROLLBACK_CANCELED", root.getAbsolutePath())); // NOI18N
115 return;
117 List<String> list = GitCommand.doRollback(root, logger);
120 if(list != null && !list.isEmpty()){
121 //logger.clearOutput();
123 if(GitCommand.isNoRollbackPossible(list.get(0))){
124 logger.output(
125 NbBundle.getMessage(RollbackAction.class,
126 "MSG_NO_ROLLBACK")); // NOI18N
127 }else{
128 logger.output(list.get(0));
129 if (GitCommand.hasHistory(root)) {
130 descriptor = new NotifyDescriptor.Confirmation(NbBundle.getMessage(RollbackAction.class, "MSG_ROLLBACK_CONFIRM_UPDATE_QUERY")); // NOI18N
131 descriptor.setTitle(NbBundle.getMessage(RollbackAction.class, "MSG_ROLLBACK_CONFIRM")); // NOI18N
132 descriptor.setMessageType(JOptionPane.WARNING_MESSAGE);
133 descriptor.setOptionType(NotifyDescriptor.YES_NO_OPTION);
134 res = DialogDisplayer.getDefault().notify(descriptor);
135 if (res == NotifyDescriptor.YES_OPTION) {
136 logger.output(
137 NbBundle.getMessage(RollbackAction.class,
138 "MSG_ROLLBACK_FORCE_UPDATE", root.getAbsolutePath())); // NOI18N
139 //list = GitCommand.doUpdateAll(root, true, null);
141 FileStatusCache cache = Git.getInstance().getFileStatusCache();
142 if(cache.listFiles(ctx, FileInformation.STATUS_VERSIONED_CONFLICT).length != 0){
143 ConflictResolvedAction.resolved(ctx);
145 GitUtils.forceStatusRefreshProject(ctx);
146 Git.getInstance().changesetChanged(root);
148 //if (list != null && !list.isEmpty()){
149 // logger.output(list);
151 } else {
152 GitUtils.forceStatusRefreshProject(ctx);
153 Git.getInstance().changesetChanged(root);
155 } else {
156 JOptionPane.showMessageDialog(null,
157 NbBundle.getMessage(RollbackAction.class,"MSG_ROLLBACK_MESSAGE_NOHISTORY") , // NOI18N
158 NbBundle.getMessage(RollbackAction.class,"MSG_ROLLBACK_MESSAGE"), // NOI18N
159 JOptionPane.INFORMATION_MESSAGE,null);
163 logger.outputInRed(
164 NbBundle.getMessage(RollbackAction.class,
165 "MSG_ROLLBACK_INFO")); // NOI18N
167 } catch (GitException ex) {
168 NotifyDescriptor.Exception e = new NotifyDescriptor.Exception(ex);
169 DialogDisplayer.getDefault().notifyLater(e);
170 } finally {
171 logger.outputInRed(
172 NbBundle.getMessage(RollbackAction.class,
173 "MSG_ROLLBACK_DONE")); // NOI18N
174 logger.output(""); // NOI18N
178 support.start(rp, repository,org.openide.util.NbBundle.getMessage(RollbackAction.class, "MSG_ROLLBACK_PROGRESS")); // NOI18N
181 @Override
182 public boolean isEnabled() {
183 return GitUtils.getRootFile(context) != null;