PageRenderTime 51ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/projects/netbeans-7.3/mercurial/src/org/netbeans/modules/mercurial/ui/push/PushOtherAction.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus
Java | 154 lines | 93 code | 12 blank | 49 comment | 16 complexity | 466b7efbd3cd3eec1ba29a2b0f35449e MD5 | raw file
  1. /*
  2. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  3. *
  4. * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
  5. *
  6. * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
  7. * Other names may be trademarks of their respective owners.
  8. *
  9. * The contents of this file are subject to the terms of either the GNU
  10. * General Public License Version 2 only ("GPL") or the Common
  11. * Development and Distribution License("CDDL") (collectively, the
  12. * "License"). You may not use this file except in compliance with the
  13. * License. You can obtain a copy of the License at
  14. * http://www.netbeans.org/cddl-gplv2.html
  15. * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
  16. * specific language governing permissions and limitations under the
  17. * License. When distributing the software, include this License Header
  18. * Notice in each file and include the License file at
  19. * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
  20. * particular file as subject to the "Classpath" exception as provided
  21. * by Oracle in the GPL Version 2 section of the License file that
  22. * accompanied this code. If applicable, add the following below the
  23. * License Header, with the fields enclosed by brackets [] replaced by
  24. * your own identifying information:
  25. * "Portions Copyrighted [year] [name of copyright owner]"
  26. *
  27. * Contributor(s):
  28. *
  29. * The Original Software is NetBeans. The Initial Developer of the Original
  30. * Software is Sun Microsystems, Inc. Portions Copyright 1997-2009 Sun
  31. * Microsystems, Inc. All Rights Reserved.
  32. *
  33. * If you wish your version of this file to be governed by only the CDDL
  34. * or only the GPL Version 2, indicate your decision by adding
  35. * "[Contributor] elects to include this software in this distribution
  36. * under the [CDDL or GPL Version 2] license." If you do not indicate a
  37. * single choice of license, a recipient has the option to distribute
  38. * your version of this file under either the CDDL, the GPL Version 2 or
  39. * to extend the choice of license to its licensees as provided above.
  40. * However, if you add GPL Version 2 code and therefore, elected the GPL
  41. * Version 2 license, then the option applies only if the new code is
  42. * made subject to such option by the copyright holder.
  43. */
  44. package org.netbeans.modules.mercurial.ui.push;
  45. import java.net.URISyntaxException;
  46. import javax.swing.event.ChangeEvent;
  47. import javax.swing.event.ChangeListener;
  48. import org.netbeans.modules.mercurial.ui.repository.HgURL;
  49. import org.netbeans.modules.versioning.spi.VCSContext;
  50. import javax.swing.*;
  51. import java.io.File;
  52. import java.util.Set;
  53. import java.util.logging.Level;
  54. import org.netbeans.modules.mercurial.HgProgressSupport;
  55. import org.netbeans.modules.mercurial.Mercurial;
  56. import org.netbeans.modules.mercurial.ui.repository.Repository;
  57. import org.netbeans.modules.mercurial.ui.actions.ContextAction;
  58. import org.netbeans.modules.mercurial.ui.wizards.CloneRepositoryWizardPanel;
  59. import org.netbeans.modules.mercurial.util.HgProjectUtils;
  60. import org.netbeans.modules.mercurial.util.HgUtils;
  61. import org.openide.nodes.Node;
  62. import org.openide.util.NbBundle;
  63. import org.openide.util.RequestProcessor;
  64. import org.openide.util.HelpCtx;
  65. /**
  66. * Push Other action for mercurial:
  67. * hg push - push changes to the specified target
  68. *
  69. * @author John Rice
  70. */
  71. public class PushOtherAction extends ContextAction {
  72. @Override
  73. protected boolean enable(Node[] nodes) {
  74. VCSContext context = HgUtils.getCurrentContext(nodes);
  75. Set<File> ctxFiles = context != null? context.getRootFiles(): null;
  76. if(!HgUtils.isFromHgRepository(context) || ctxFiles == null || ctxFiles.size() == 0)
  77. return false;
  78. return true; // #121293: Speed up menu display, warn user if not set when Push selected
  79. }
  80. protected String getBaseName(Node[] nodes) {
  81. return "CTL_MenuItem_PushOther"; //NOI18N
  82. }
  83. @Override
  84. protected void performContextAction(Node[] nodes) {
  85. VCSContext context = HgUtils.getCurrentContext(nodes);
  86. final File roots[] = HgUtils.getActionRoots(context);
  87. if (roots == null || roots.length == 0) return;
  88. final File root = Mercurial.getInstance().getRepositoryRoot(roots[0]);
  89. int repositoryModeMask = Repository.FLAG_URL_ENABLED | Repository.FLAG_SHOW_HINTS | Repository.FLAG_SHOW_PROXY;
  90. String title = org.openide.util.NbBundle.getMessage(CloneRepositoryWizardPanel.class, "CTL_Repository_Location"); // NOI18N
  91. final JButton pushButton = new JButton();
  92. final Repository repository = new Repository(repositoryModeMask, title, true, root);
  93. repository.addChangeListener(new ChangeListener() {
  94. public void stateChanged(ChangeEvent e) {
  95. pushButton.setEnabled(repository.isValid());
  96. }
  97. });
  98. org.openide.awt.Mnemonics.setLocalizedText(pushButton, org.openide.util.NbBundle.getMessage(PushOtherAction.class, "CTL_Push_Action_Push")); // NOI18N
  99. pushButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PushOtherAction.class, "ACSD_Push_Action_Push")); // NOI18N
  100. pushButton.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(PushOtherAction.class, "ACSN_Push_Action_Push")); // NOI18N
  101. JButton cancelButton = new JButton();
  102. org.openide.awt.Mnemonics.setLocalizedText(cancelButton, org.openide.util.NbBundle.getMessage(PushOtherAction.class, "CTL_Push_Action_Cancel")); // NOI18N
  103. cancelButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PushOtherAction.class, "ACSD_Push_Action_Cancel")); //NOI18N
  104. cancelButton.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(PushOtherAction.class, "ACSN_Push_Action_Cancel")); // NOI18N
  105. pushButton.setEnabled(false);
  106. Object option = repository.show(org.openide.util.NbBundle.getMessage(PushOtherAction.class, "CTL_PushDialog_Title"),
  107. new HelpCtx(PushOtherAction.class),
  108. new Object[] {pushButton, cancelButton},
  109. true,
  110. "hg.push.dialog");
  111. if (option == pushButton) {
  112. final HgURL pushPath;
  113. try {
  114. pushPath = repository.getUrl();
  115. } catch (URISyntaxException ex) {
  116. Mercurial.LOG.log(Level.SEVERE,
  117. this.getClass().getName()
  118. + ": Could not push because of invalid URI." //NOI18N
  119. + repository.getUrlString());
  120. Mercurial.LOG.log(Level.SEVERE,
  121. this.getClass().getName()
  122. + ": Invalid URI: " //NOI18N
  123. + repository.getUrlString());
  124. return;
  125. }
  126. push(context, root, pushPath);
  127. }
  128. }
  129. public static void push(final VCSContext ctx, final File root, final HgURL pushPath) {
  130. if (root == null || pushPath == null) return;
  131. final String fromPrjName = HgProjectUtils.getProjectName(root);
  132. final String toPrjName = NbBundle.getMessage(PushAction.class, "MSG_EXTERNAL_REPOSITORY"); // NOI18N
  133. RequestProcessor rp = Mercurial.getInstance().getRequestProcessor(root);
  134. HgProgressSupport support = new HgProgressSupport() {
  135. public void perform() {
  136. PushAction.performPush(root, pushPath, fromPrjName, toPrjName, this.getLogger(), false);
  137. }
  138. };
  139. support.start(rp, root,
  140. org.openide.util.NbBundle.getMessage(PushAction.class, "MSG_PUSH_PROGRESS")); // NOI18N
  141. }
  142. }