/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 2012 Oracle and/or its affiliates. All rights reserved.
*
* Oracle and Java are registered trademarks of Oracle and/or its affiliates.
* Other names may be trademarks of their respective owners.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common
* Development and Distribution License("CDDL") (collectively, the
* "License"). You may not use this file except in compliance with the
* License. You can obtain a copy of the License at
* http://www.netbeans.org/cddl-gplv2.html
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
* specific language governing permissions and limitations under the
* License. When distributing the software, include this License Header
* Notice in each file and include the License file at
* nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the
* License Header, with the fields enclosed by brackets [] replaced by
* your own identifying information:
* "Portions Copyrighted [year] [name of copyright owner]"
*
* If you wish your version of this file to be governed by only the CDDL
* or only the GPL Version 2, indicate your decision by adding
* "[Contributor] elects to include this software in this distribution
* under the [CDDL or GPL Version 2] license." If you do not indicate a
* single choice of license, a recipient has the option to distribute
* your version of this file under either the CDDL, the GPL Version 2 or
* to extend the choice of license to its licensees as provided above.
* However, if you add GPL Version 2 code and therefore, elected the GPL
* Version 2 license, then the option applies only if the new code is
* made subject to such option by the copyright holder.
*
* Contributor(s):
*
* Portions Copyrighted 2012 Sun Microsystems, Inc.
*/
package org.netbeans.modules.php.fuel.ui;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import javax.swing.ButtonGroup;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JRadioButton;
import org.netbeans.modules.php.api.util.StringUtils;
import org.netbeans.modules.php.fuel.options.FuelPhpOptions;
import org.netbeans.modules.php.fuel.util.FuelDownloads;
import org.openide.util.Exceptions;
/**
*
* @author junichi11
*/
public class NewProjectConfigurationPanel extends javax.swing.JPanel {
private static final long serialVersionUID = 7874450246517944114L;
private final Map<String, String> downloadsMap = new HashMap<String, String>();
private String errorMessage = null; // NOI18N
/**
* Creates new form NewProjectConfigurationPanel
*/
public NewProjectConfigurationPanel() {
initComponents();
this.unzipRadioButton.setSelected(true);
FuelDownloads fuelDownloads = new FuelDownloads();
downloadsMap.putAll(fuelDownloads.getDownloadsMap());
versionList.setListData(fuelDownloads.getDownloadVersions());
versionList.setSelectedIndex(0);
if (!FuelDownloads.isInternetReachable()) {
errorMessage = "Is not connected to the network.";
}
gettingFileInfoLabel.setText(errorMessage);
}
public Map<String, String> getDownloadsMap() {
return downloadsMap;
}
public JLabel getGettingFileInfoLabel() {
return gettingFileInfoLabel;
}
public JList<String> getVersionList() {
return versionList;
}
public String getErrorMessage() {
return errorMessage;
}
public ButtonGroup getButtonGroup() {
return buttonGroup;
}
public JRadioButton getGitCloneRadioButton() {
return gitCloneRadioButton;
}
public JRadioButton getUnzipRadioButton() {
return unzipRadioButton;
}
public void setGitCommandLabel(String command) {
gitCommandLabel.setText(command);
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
buttonGroup = new javax.swing.ButtonGroup();
selectVersionLabel = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
versionList = new javax.swing.JList<String>();
gettingFileInfoLabel = new javax.swing.JLabel();
gitCloneRadioButton = new javax.swing.JRadioButton();
unzipRadioButton = new javax.swing.JRadioButton();
gitCommandLabel = new javax.swing.JLabel();
selectVersionLabel.setText(org.openide.util.NbBundle.getMessage(NewProjectConfigurationPanel.class, "NewProjectConfigurationPanel.selectVersionLabel.text")); // NOI18N
versionList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
jScrollPane1.setViewportView(versionList);
gettingFileInfoLabel.setText(org.openide.util.NbBundle.getMessage(NewProjectConfigurationPanel.class, "NewProjectConfigurationPanel.gettingFileInfoLabel.text")); // NOI18N
buttonGroup.add(gitCloneRadioButton);
gitCloneRadioButton.setText(org.openide.util.NbBundle.getMessage(NewProjectConfigurationPanel.class, "NewProjectConfigurationPanel.gitCloneRadioButton.text")); // NOI18N
gitCloneRadioButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
gitCloneRadioButtonActionPerformed(evt);
}
});
buttonGroup.add(unzipRadioButton);
unzipRadioButton.setText(org.openide.util.NbBundle.getMessage(NewProjectConfigurationPanel.class, "NewProjectConfigurationPanel.unzipRadioButton.text")); // NOI18N
gitCommandLabel.setText(org.openide.util.NbBundle.getMessage(NewProjectConfigurationPanel.class, "NewProjectConfigurationPanel.gitCommandLabel.text")); // NOI18N
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(gitCloneRadioButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(unzipRadioButton)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 226, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(gettingFileInfoLabel)
.addComponent(selectVersionLabel)
.addComponent(gitCommandLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap(139, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(unzipRadioButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(selectVersionLabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(gettingFileInfoLabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(gitCloneRadioButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(gitCommandLabel)
.addContainerGap(45, Short.MAX_VALUE))
);
}// </editor-fold>//GEN-END:initComponents
private void gitCloneRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_gitCloneRadioButtonActionPerformed
String branchName = FuelPhpOptions.getInstance().getGitBranchName();
if (StringUtils.isEmpty(branchName)) {
setEnabledColenRadioButton(false);
return;
}
try {
Process process = Runtime.getRuntime().exec("git"); // NOI18N
process.waitFor();
} catch (InterruptedException ex) {
Exceptions.printStackTrace(ex);
} catch (IOException ex) {
setEnabledColenRadioButton(false);
}
}//GEN-LAST:event_gitCloneRadioButtonActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.ButtonGroup buttonGroup;
private javax.swing.JLabel gettingFileInfoLabel;
private javax.swing.JRadioButton gitCloneRadioButton;
private javax.swing.JLabel gitCommandLabel;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JLabel selectVersionLabel;
private javax.swing.JRadioButton unzipRadioButton;
private javax.swing.JList<String> versionList;
// End of variables declaration//GEN-END:variables
private void setEnabledColenRadioButton(boolean isEnabled) {
gitCloneRadioButton.setSelected(isEnabled);
unzipRadioButton.setSelected(!isEnabled);
gitCloneRadioButton.setEnabled(isEnabled);
}
}