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]"
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
.view
;
44 import java
.awt
.event
.ActionEvent
;
46 import javax
.swing
.Action
;
47 import javax
.swing
.JOptionPane
;
48 import org
.netbeans
.modules
.git
.GitException
;
49 import org
.netbeans
.modules
.git
.OutputLogger
;
50 import org
.netbeans
.modules
.git
.config
.GitConfigFiles
;
51 import org
.netbeans
.modules
.git
.ui
.actions
.ContextAction
;
52 import org
.netbeans
.modules
.git
.util
.GitCommand
;
53 import org
.netbeans
.modules
.git
.util
.GitUtils
;
54 import org
.netbeans
.modules
.versioning
.spi
.VCSContext
;
55 import org
.openide
.DialogDisplayer
;
56 import org
.openide
.NotifyDescriptor
;
57 import org
.openide
.util
.NbBundle
;
58 import org
.openide
.util
.RequestProcessor
;
61 * View action for Git:
62 * git view - launch git view to view the dependency tree for the repository
66 public class ViewAction
extends ContextAction
{
68 private final VCSContext context
;
69 private static final String GIT_SCRIPTS_DIR
= "scripts";
71 public ViewAction(String name
, VCSContext context
) {
72 this.context
= context
;
73 putValue(Action
.NAME
, name
);
76 public void performAction(ActionEvent e
) {
77 final File root
= GitUtils
.getRootFile(context
);
78 if (root
== null) return;
79 String repository
= root
.getAbsolutePath();
80 RequestProcessor rp
= RequestProcessor
.getDefault();
81 rp
.post(new Runnable() {
88 static void performView(File root
) {
89 OutputLogger logger
= OutputLogger
.getLogger(root
.getAbsolutePath());
91 logger
.outputInRed(NbBundle
.getMessage(ViewAction
.class, "MSG_VIEW_TITLE")); // NOI18N
92 logger
.outputInRed(NbBundle
.getMessage(ViewAction
.class, "MSG_VIEW_TITLE_SEP")); // NOI18N
94 String gitkCommand
= GitCommand
.GITK_COMMAND
;
95 // if(Utilities.isWindows()){
96 // gitkCommand = gitkCommand + GitCommand.GIT_WINDOWS_CMD;
98 boolean bGitkFound
= false;
99 // if(GitUtils.isInUserPath(gitkCommand)){
101 // } else if(GitUtils.isSolaris()){
102 // File f = new File(GitCommand.HG_HGK_PATH_SOLARIS10, hgkCommand);
103 // if(f.exists() && f.isFile())
105 // }else if(Utilities.isWindows()){
106 // bHgkFound = HgUtils.isInUserPath(HG_SCRIPTS_DIR + File.separator + hgkCommand);
108 boolean bGitkPropExists
= GitConfigFiles
.getInstance().containsProperty(
109 GitConfigFiles
.GIT_EXTENSIONS
, GitConfigFiles
.GIT_EXTENSIONS_GITK
);
113 NbBundle
.getMessage(ViewAction
.class, "MSG_VIEW_GITK_NOT_FOUND_INFO")); // NOI18N
114 logger
.output(""); // NOI18N
115 JOptionPane
.showMessageDialog(null,
116 NbBundle
.getMessage(ViewAction
.class, "MSG_VIEW_GITK_NOT_FOUND"),// NOI18N
117 NbBundle
.getMessage(ViewAction
.class, "MSG_VIEW_GITK_NOT_FOUND_TITLE"),// NOI18N
118 JOptionPane
.INFORMATION_MESSAGE
);
122 if(!bGitkPropExists
){
123 boolean bConfirmSetGitkProp
= false;
124 bConfirmSetGitkProp
= GitUtils
.confirmDialog(
125 ViewAction
.class, "MSG_VIEW_SETGITK_PROP_CONFIRM_TITLE", // NOI18N
126 "MSG_VIEW_SETGITK_PROP_CONFIRM_QUERY"); // NOI18N
127 if (bConfirmSetGitkProp
) {
129 NbBundle
.getMessage(ViewAction
.class, "MSG_VIEW_SETGITK_PROP_DO_INFO")); // NOI18N
130 GitConfigFiles
.getInstance().setProperty(GitConfigFiles
.GIT_EXTENSIONS_GITK
, ""); // NOI18N
133 NbBundle
.getMessage(ViewAction
.class, "MSG_VIEW_NOTSETGITK_PROP_INFO")); // NOI18N
134 logger
.output(""); // NOI18N
140 logger
.outputInRed(NbBundle
.getMessage(ViewAction
.class,
141 "MSG_VIEW_LAUNCH_INFO", root
.getAbsolutePath())); // NOI18N
142 logger
.output(""); // NOI18N
143 GitCommand
.doView(root
, logger
);
145 } catch (GitException ex
) {
146 NotifyDescriptor
.Exception e
= new NotifyDescriptor
.Exception(ex
);
147 DialogDisplayer
.getDefault().notifyLater(e
);
152 public boolean isEnabled() {
153 return GitUtils
.getRootFile(context
) != null;