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: package org.netbeans.modules.mercurial.ui.pull;
042:
043: import org.netbeans.modules.versioning.spi.VCSContext;
044:
045: import javax.swing.*;
046: import java.awt.event.ActionEvent;
047: import java.io.File;
048: import java.util.List;
049: import java.beans.PropertyChangeListener;
050: import java.beans.PropertyChangeEvent;
051: import org.netbeans.modules.mercurial.HgException;
052: import org.netbeans.modules.mercurial.HgProgressSupport;
053: import org.netbeans.modules.mercurial.Mercurial;
054: import org.netbeans.modules.mercurial.ui.repository.Repository;
055: import org.netbeans.modules.mercurial.ui.actions.ContextAction;
056: import org.netbeans.modules.mercurial.ui.wizards.CloneRepositoryWizardPanel;
057: import org.netbeans.modules.mercurial.util.HgProjectUtils;
058: import org.netbeans.modules.mercurial.util.HgUtils;
059: import org.openide.util.NbBundle;
060: import org.openide.util.RequestProcessor;
061: import org.openide.util.HelpCtx;
062:
063: /**
064: * Pull Other action for mercurial:
065: * hg pull - pull changes from the specified source
066: *
067: * @author John Rice
068: */
069: public class PullOtherAction extends ContextAction implements
070: PropertyChangeListener {
071:
072: private final VCSContext context;
073: private Repository repository = null;
074: private JButton pullButton = null;
075: private JButton cancelButton = null;
076:
077: public PullOtherAction(String name, VCSContext context) {
078: this .context = context;
079: putValue(Action.NAME, name);
080: }
081:
082: public void performAction(ActionEvent e) {
083: final File root = HgUtils.getRootFile(context);
084: if (root == null)
085: return;
086:
087: if (repository == null) {
088: int repositoryModeMask = Repository.FLAG_URL_EDITABLE
089: | Repository.FLAG_URL_ENABLED
090: | Repository.FLAG_SHOW_HINTS
091: | Repository.FLAG_SHOW_PROXY;
092: String title = org.openide.util.NbBundle.getMessage(
093: CloneRepositoryWizardPanel.class,
094: "CTL_Repository_Location"); // NOI18N
095: repository = new Repository(repositoryModeMask, title, true);
096: repository.addPropertyChangeListener(this );
097: }
098:
099: pullButton = new JButton();
100: org.openide.awt.Mnemonics.setLocalizedText(pullButton,
101: org.openide.util.NbBundle.getMessage(
102: PullOtherAction.class, "CTL_Pull_Action_Pull")); // NOI18N
103: pullButton.getAccessibleContext()
104: .setAccessibleDescription(
105: org.openide.util.NbBundle.getMessage(
106: PullOtherAction.class,
107: "ACSD_Pull_Action_Pull")); // NOI18N
108: pullButton.getAccessibleContext()
109: .setAccessibleName(
110: org.openide.util.NbBundle.getMessage(
111: PullOtherAction.class,
112: "ACSN_Pull_Action_Pull")); // NOI18N
113: cancelButton = new JButton();
114: org.openide.awt.Mnemonics.setLocalizedText(cancelButton,
115: org.openide.util.NbBundle
116: .getMessage(PullOtherAction.class,
117: "CTL_Pull_Action_Cancel")); // NOI18N
118: cancelButton.getAccessibleContext().setAccessibleDescription(
119: org.openide.util.NbBundle.getMessage(
120: PullOtherAction.class,
121: "ACSD_Pull_Action_Cancel")); // NOI18N
122: cancelButton.getAccessibleContext().setAccessibleName(
123: org.openide.util.NbBundle.getMessage(
124: PullOtherAction.class,
125: "ACSN_Pull_Action_Cancel")); // NOI18N
126:
127: pullButton.setEnabled(false);
128:
129: Object option = repository.show(org.openide.util.NbBundle
130: .getMessage(PullOtherAction.class,
131: "CTL_PullDialog_Title"), new HelpCtx(
132: PullOtherAction.class), new Object[] { pullButton,
133: cancelButton }, true, "hg.pull.dialog");
134: if (option == pullButton) {
135: final String pullPath = repository.getSelectedRC().getUrl();
136: pull(context, root, pullPath);
137: }
138: }
139:
140: public void propertyChange(PropertyChangeEvent evt) {
141: if (evt.getPropertyName().equals(Repository.PROP_VALID)) {
142: pullButton.setEnabled(repository.isValid());
143: }
144: }
145:
146: public static void pull(final VCSContext ctx, final File root,
147: final String pullPath) {
148: if (root == null || pullPath == null)
149: return;
150: String repository = root.getAbsolutePath();
151: final String fromPrjName = NbBundle.getMessage(
152: PullAction.class, "MSG_EXTERNAL_REPOSITORY"); // NOI18N
153: final String toPrjName = HgProjectUtils.getProjectName(root);
154:
155: RequestProcessor rp = Mercurial.getInstance()
156: .getRequestProcessor(root);
157: HgProgressSupport support = new HgProgressSupport() {
158: public void perform() {
159: PullAction.performPull(PullAction.PullType.OTHER, ctx,
160: root, pullPath, fromPrjName, toPrjName, this
161: .getLogger());
162: }
163: };
164:
165: support.start(rp, repository, org.openide.util.NbBundle
166: .getMessage(PullAction.class, "MSG_PULL_PROGRESS")); // NOI18N
167: }
168:
169: public boolean isEnabled() {
170: return HgUtils.getRootFile(context) != null;
171: }
172: }
|