PageRenderTime 178ms CodeModel.GetById 118ms RepoModel.GetById 0ms app.codeStats 0ms

/projects/netbeans-7.3/mercurial/src/org/netbeans/modules/mercurial/ui/diff/DiffAction.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus
Java | 142 lines | 78 code | 15 blank | 49 comment | 10 complexity | 12a0341d5920659cbcb00c0338b7377c 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-2006 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.diff;
  45. import org.netbeans.modules.versioning.spi.VCSContext;
  46. import org.netbeans.modules.versioning.util.Utils;
  47. import javax.swing.*;
  48. import java.io.File;
  49. import java.util.Set;
  50. import org.netbeans.modules.mercurial.FileInformation;
  51. import org.netbeans.modules.mercurial.FileStatus;
  52. import org.netbeans.modules.mercurial.Mercurial;
  53. import org.netbeans.modules.mercurial.OutputLogger;
  54. import org.netbeans.modules.mercurial.util.HgUtils;
  55. import org.netbeans.modules.mercurial.ui.actions.ContextAction;
  56. import org.netbeans.modules.mercurial.ui.log.HgLogMessage.HgRevision;
  57. import org.openide.nodes.Node;
  58. import org.openide.util.NbBundle;
  59. /**
  60. * Diff action for mercurial:
  61. * hg diff - diff repository (or selected files)
  62. *
  63. * @author John Rice
  64. */
  65. public class DiffAction extends ContextAction {
  66. @Override
  67. protected boolean enable(Node[] nodes) {
  68. VCSContext context = HgUtils.getCurrentContext(nodes);
  69. Set<File> ctxFiles = context != null? context.getRootFiles(): null;
  70. if(!HgUtils.isFromHgRepository(context) || ctxFiles == null || ctxFiles.isEmpty())
  71. return false;
  72. return true;
  73. }
  74. @Override
  75. protected String getBaseName(Node[] nodes) {
  76. return "CTL_MenuItem_Diff"; // NOI18N
  77. }
  78. @Override
  79. protected String iconResource () {
  80. return "org/netbeans/modules/mercurial/resources/icons/diff.png"; // NOI18N
  81. }
  82. @Override
  83. protected void performContextAction(Node[] nodes) {
  84. VCSContext context = HgUtils.getCurrentContext(nodes);
  85. String contextName = Utils.getContextDisplayName(context);
  86. File [] files = context.getRootFiles().toArray(new File[context.getRootFiles().size()]);
  87. boolean bNotManaged = !HgUtils.isFromHgRepository(context) || ( files == null || files.length == 0);
  88. if (bNotManaged) {
  89. OutputLogger logger = OutputLogger.getLogger(Mercurial.MERCURIAL_OUTPUT_TAB_TITLE);
  90. logger.outputInRed( NbBundle.getMessage(DiffAction.class,"MSG_DIFF_TITLE")); // NOI18N
  91. logger.outputInRed( NbBundle.getMessage(DiffAction.class,"MSG_DIFF_TITLE_SEP")); // NOI18N
  92. logger.outputInRed(
  93. NbBundle.getMessage(DiffAction.class, "MSG_DIFF_NOT_SUPPORTED_INVIEW_INFO")); // NOI18N
  94. logger.output(""); // NOI18N
  95. logger.closeLog();
  96. JOptionPane.showMessageDialog(null,
  97. NbBundle.getMessage(DiffAction.class, "MSG_DIFF_NOT_SUPPORTED_INVIEW"),// NOI18N
  98. NbBundle.getMessage(DiffAction.class, "MSG_DIFF_NOT_SUPPORTED_INVIEW_TITLE"),// NOI18N
  99. JOptionPane.INFORMATION_MESSAGE);
  100. return;
  101. }
  102. diff(context, Setup.DIFFTYPE_LOCAL, contextName);
  103. }
  104. public static void diff(VCSContext ctx, int type, String contextName) {
  105. MultiDiffPanel panel = new MultiDiffPanel(ctx, type, contextName); // spawns background DiffPrepareTask
  106. DiffTopComponent tc = new DiffTopComponent(panel);
  107. tc.setName(NbBundle.getMessage(DiffAction.class, "CTL_DiffPanel_Title", contextName)); // NOI18N
  108. tc.open();
  109. tc.requestActive();
  110. }
  111. public static void diff(File file1, HgRevision rev1, File file2, HgRevision rev2) {
  112. MultiDiffPanel panel = new MultiDiffPanel(file2, rev1, rev2,
  113. new FileInformation(FileInformation.STATUS_VERSIONED_UPTODATE, new FileStatus(file2, file1), false),
  114. false); // spawns background DiffPrepareTask
  115. DiffTopComponent tc = new DiffTopComponent(panel);
  116. tc.setName(NbBundle.getMessage(DiffAction.class, "CTL_DiffPanel_Title", file2.getName())); // NOI18N
  117. tc.open();
  118. tc.requestActive();
  119. }
  120. public void diff (File[] roots, HgRevision rev1, HgRevision rev2, String diffViewName, boolean displayUnversionedFiles) {
  121. MultiDiffPanel panel = new MultiDiffPanel(roots, rev1, rev2, displayUnversionedFiles); // spawns background DiffPrepareTask
  122. DiffTopComponent tc = new DiffTopComponent(panel);
  123. tc.setName(diffViewName);
  124. tc.open();
  125. tc.requestActive();
  126. }
  127. }