Adding Git source, NetBeans project files, GPL v2 LICENSE, ant build file.
[nbgit.git] / src / org / netbeans / modules / git / ui / pull / PullOtherAction.java
blob8c2fd367cca7ceea5a762abce28cbb07ab115b7f
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.pull;
44 import java.awt.event.ActionEvent;
45 import java.beans.PropertyChangeEvent;
46 import java.beans.PropertyChangeListener;
47 import java.io.File;
48 import javax.swing.Action;
49 import javax.swing.JButton;
50 import org.netbeans.modules.git.Git;
51 import org.netbeans.modules.git.GitProgressSupport;
52 import org.netbeans.modules.git.ui.actions.ContextAction;
53 import org.netbeans.modules.git.ui.repository.Repository;
54 import org.netbeans.modules.git.ui.wizards.CloneRepositoryWizardPanel;
55 import org.netbeans.modules.git.util.GitProjectUtils;
56 import org.netbeans.modules.git.util.GitUtils;
57 import org.netbeans.modules.versioning.spi.VCSContext;
58 import org.openide.util.HelpCtx;
59 import org.openide.util.NbBundle;
60 import org.openide.util.RequestProcessor;
62 /**
63 * Pull Other action for Git:
64 * git pull - pull changes from the specified source
66 * @author John Rice
68 public class PullOtherAction extends ContextAction implements PropertyChangeListener {
70 private final VCSContext context;
71 private Repository repository = null;
72 private JButton pullButton = null;
73 private JButton cancelButton = null;
75 public PullOtherAction(String name, VCSContext context) {
76 this.context = context;
77 putValue(Action.NAME, name);
80 public void performAction(ActionEvent e) {
81 final File root = GitUtils.getRootFile(context);
82 if (root == null) return;
84 if (repository == null) {
85 int repositoryModeMask = Repository.FLAG_URL_EDITABLE | Repository.FLAG_URL_ENABLED | Repository.FLAG_SHOW_HINTS | Repository.FLAG_SHOW_PROXY;
86 String title = org.openide.util.NbBundle.getMessage(CloneRepositoryWizardPanel.class, "CTL_Repository_Location"); // NOI18N
87 repository = new Repository(repositoryModeMask, title);
88 repository.addPropertyChangeListener(this);
91 pullButton = new JButton();
92 org.openide.awt.Mnemonics.setLocalizedText(pullButton, org.openide.util.NbBundle.getMessage(PullOtherAction.class, "CTL_Pull_Action_Pull")); // NOI18N
93 pullButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PullOtherAction.class, "ACSD_Pull_Action_Pull")); // NOI18N
94 pullButton.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(PullOtherAction.class, "ACSN_Pull_Action_Pull")); // NOI18N
95 cancelButton = new JButton();
96 org.openide.awt.Mnemonics.setLocalizedText(cancelButton, org.openide.util.NbBundle.getMessage(PullOtherAction.class, "CTL_Pull_Action_Cancel")); // NOI18N
97 cancelButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PullOtherAction.class, "ACSD_Pull_Action_Cancel")); // NOI18N
98 cancelButton.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(PullOtherAction.class, "ACSN_Pull_Action_Cancel")); // NOI18N
100 pullButton.setEnabled(false);
102 Object option = repository.show(org.openide.util.NbBundle.getMessage(PullOtherAction.class, "CTL_PullDialog_Title"),
103 new HelpCtx(PullOtherAction.class),
104 new Object[] {pullButton, cancelButton},
105 true,
106 "hg.pull.dialog");
107 if (option == pullButton) {
108 final String pullPath = repository.getSelectedRC().getUrl();
109 pull(context, root, pullPath);
113 public void propertyChange(PropertyChangeEvent evt) {
114 if (evt.getPropertyName().equals(Repository.PROP_VALID)) {
115 pullButton.setEnabled(repository.isValid());
119 public static void pull(final VCSContext ctx, final File root, final String pullPath) {
120 if (root == null || pullPath == null) return;
121 String repository = root.getAbsolutePath();
122 final String fromPrjName = NbBundle.getMessage(PullAction.class, "MSG_EXTERNAL_REPOSITORY"); // NOI18N
123 final String toPrjName = GitProjectUtils.getProjectName(root);
125 RequestProcessor rp = Git.getInstance().getRequestProcessor(root);
126 GitProgressSupport support = new GitProgressSupport() {
127 public void perform() {
128 PullAction.performPull(PullAction.PullType.OTHER, ctx, root, pullPath, fromPrjName, toPrjName, this.getLogger()); } };
130 support.start(rp, repository,
131 org.openide.util.NbBundle.getMessage(PullAction.class, "MSG_PULL_PROGRESS")); // NOI18N
134 @Override
135 public boolean isEnabled() {
136 return GitUtils.getRootFile(context) != null;