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.diff;
042:
043: import org.netbeans.modules.versioning.spi.VCSContext;
044: import org.netbeans.modules.versioning.util.Utils;
045:
046: import javax.swing.*;
047: import java.awt.event.ActionEvent;
048: import java.io.File;
049:
050: import org.netbeans.modules.mercurial.FileInformation;
051: import org.netbeans.modules.mercurial.FileStatusCache;
052: import org.netbeans.modules.mercurial.Mercurial;
053: import org.netbeans.modules.mercurial.OutputLogger;
054: import org.netbeans.modules.mercurial.util.HgUtils;
055: import org.netbeans.modules.mercurial.ui.actions.ContextAction;
056: import org.openide.nodes.Node;
057: import org.openide.util.NbBundle;
058:
059: /**
060: * Diff action for mercurial:
061: * hg diff - diff repository (or selected files)
062: *
063: * @author John Rice
064: */
065: public class DiffAction extends ContextAction {
066:
067: private final VCSContext context;
068:
069: public DiffAction(String name, VCSContext context) {
070: this .context = context;
071: putValue(Action.NAME, name);
072: }
073:
074: public void performAction(ActionEvent e) {
075: String contextName = Utils.getContextDisplayName(context);
076:
077: File root = HgUtils.getRootFile(context);
078: File[] files = context.getRootFiles().toArray(
079: new File[context.getRootFiles().size()]);
080: boolean bNotManaged = (root == null)
081: || (files == null || files.length == 0);
082:
083: if (bNotManaged) {
084: OutputLogger logger = OutputLogger
085: .getLogger(Mercurial.MERCURIAL_OUTPUT_TAB_TITLE);
086: logger.outputInRed(NbBundle.getMessage(DiffAction.class,
087: "MSG_DIFF_TITLE")); // NOI18N
088: logger.outputInRed(NbBundle.getMessage(DiffAction.class,
089: "MSG_DIFF_TITLE_SEP")); // NOI18N
090: logger.outputInRed(NbBundle.getMessage(DiffAction.class,
091: "MSG_DIFF_NOT_SUPPORTED_INVIEW_INFO")); // NOI18N
092: logger.output(""); // NOI18N
093: logger.closeLog();
094: JOptionPane.showMessageDialog(null, NbBundle.getMessage(
095: DiffAction.class, "MSG_DIFF_NOT_SUPPORTED_INVIEW"),// NOI18N
096: NbBundle.getMessage(DiffAction.class,
097: "MSG_DIFF_NOT_SUPPORTED_INVIEW_TITLE"),// NOI18N
098: JOptionPane.INFORMATION_MESSAGE);
099: return;
100: }
101:
102: diff(context, Setup.DIFFTYPE_LOCAL, contextName);
103: }
104:
105: public boolean isEnabled() {
106: FileStatusCache cache = Mercurial.getInstance()
107: .getFileStatusCache();
108: return cache.containsFileOfStatus(context,
109: FileInformation.STATUS_LOCAL_CHANGE);
110: }
111:
112: public static void diff(VCSContext ctx, int type, String contextName) {
113:
114: MultiDiffPanel panel = new MultiDiffPanel(ctx, type,
115: contextName); // spawns background DiffPrepareTask
116: DiffTopComponent tc = new DiffTopComponent(panel);
117: tc.setName(NbBundle.getMessage(DiffAction.class,
118: "CTL_DiffPanel_Title", contextName)); // NOI18N
119: tc.open();
120: tc.requestActive();
121: }
122:
123: public static void diff(File file, String rev1, String rev2) {
124: MultiDiffPanel panel = new MultiDiffPanel(file, rev1, rev2); // spawns background DiffPrepareTask
125: DiffTopComponent tc = new DiffTopComponent(panel);
126: tc.setName(NbBundle.getMessage(DiffAction.class,
127: "CTL_DiffPanel_Title", file.getName())); // NOI18N
128: tc.open();
129: tc.requestActive();
130: }
131: }
|