/*
* The contents of this file are subject to the terms of the Common Development
* and Distribution License (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.html
* or http://www.netbeans.org/cddl.txt.
*
* When distributing Covered Code, include this CDDL Header Notice in each file
* and include the License file at http://www.netbeans.org/cddl.txt.
* If applicable, add the following below the CDDL Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyrighted [year] [name of copyright owner]"
*
* The Original Software is NetBeans. The Initial Developer of the Original
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
* Microsystems, Inc. All Rights Reserved.
*/
package org.netbeans.modules.gwt4nb;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import javax.swing.JFileChooser;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import org.netbeans.api.project.Project;
import org.openide.util.NbBundle;
import org.openide.awt.HtmlBrowser;
/**
* Visual panel for GWT project settings configuration.
*
* @author Tomas.Zezula@Sun.COM
* @author Tomasz.Slota@Sun.COM
* @author see https://github.com/gwt4nb/gwt4nb/
*/
public class GWTConfigPanelVisual extends javax.swing.JPanel {
private static final long serialVersionUID = 1;
private GWTConfigPanel controller;
private ChangeNotifier changeNotifier = new ChangeNotifier();
private Project project = null;
/**
* Creates new form GWTConfigPanelVisual
*
* @param controller ?
* @param project ?
*/
public GWTConfigPanelVisual(GWTConfigPanel controller, Project project) {
this.controller = controller;
this.project = project;
initComponents();
gwtFolder.getDocument().addDocumentListener(changeNotifier);
gwtModule.getDocument().addDocumentListener(changeNotifier);
GWTProjectInfo pi = null;
if (project != null)
pi = GWTProjectInfo.get(project);
btnGWTBrowse.setEnabled(pi == null);
gwtFolder.setEditable(pi == null);
}
/** 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.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
lblGWTFolder = new javax.swing.JLabel();
gwtFolder = new javax.swing.JTextField();
btnGWTBrowse = new javax.swing.JButton();
lblGWTModule = new javax.swing.JLabel();
gwtModule = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
lblGWTFolder.setLabelFor(gwtFolder);
java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/netbeans/modules/gwt4nb/Bundle"); // NOI18N
org.openide.awt.Mnemonics.setLocalizedText(lblGWTFolder, bundle.getString("GWTConfigPanelVisual.lblGWTFolder.text")); // NOI18N
org.openide.awt.Mnemonics.setLocalizedText(btnGWTBrowse, bundle.getString("GWTConfigPanelVisual.btnGWTBrowse.text")); // NOI18N
btnGWTBrowse.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnGWTBrowsebrowse(evt);
}
});
lblGWTModule.setLabelFor(gwtModule);
org.openide.awt.Mnemonics.setLocalizedText(lblGWTModule, bundle.getString("GWTConfigPanelVisual.lblGWTModule.text")); // NOI18N
gwtModule.setText(org.openide.util.NbBundle.getMessage(GWTConfigPanelVisual.class, "GWTConfigPanelVisual.gwtModule.text")); // NOI18N
org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(GWTConfigPanelVisual.class, "GWTConfigPanelVisual.jLabel1.text")); // NOI18N
jLabel1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jLabel1MouseClicked(evt);
}
});
org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(GWTConfigPanelVisual.class, "GWTConfigPanelVisual.jLabel2.text")); // NOI18N
jLabel2.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jLabel2MouseClicked(evt);
}
});
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(lblGWTFolder)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(gwtFolder, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 518, Short.MAX_VALUE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(btnGWTBrowse))
.add(layout.createSequentialGroup()
.add(lblGWTModule)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(gwtModule, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 234, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addContainerGap(398, Short.MAX_VALUE))
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
.addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(org.jdesktop.layout.GroupLayout.TRAILING, jLabel2)))
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(lblGWTFolder)
.add(gwtFolder, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(btnGWTBrowse))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jLabel2)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(gwtModule, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(lblGWTModule)))
);
}// </editor-fold>//GEN-END:initComponents
private void btnGWTBrowsebrowse(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGWTBrowsebrowse
JFileChooser chooser = new JFileChooser();
chooser.setDialogTitle(NbBundle.getMessage(GWTConfigPanelVisual.class,"LBL_SelectGWTLocation")); // NOI18N
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
String path = gwtFolder.getText();
if (path.length() > 0) {
File f = new File(path);
if (f.exists())
chooser.setSelectedFile(f);
}
if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) {
File projectDir = chooser.getSelectedFile();
gwtFolder.setText(projectDir.getAbsolutePath());
}
}//GEN-LAST:event_btnGWTBrowsebrowse
private void jLabel1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel1MouseClicked
try {
HtmlBrowser.URLDisplayer.getDefault().
showURL(new URL("http://code.google.com/intl/en-EN/webtoolkit/download.html")); // NOI18N
} catch (MalformedURLException ex) {
GWT4NBUtil.unexpectedException(ex);
}
}//GEN-LAST:event_jLabel1MouseClicked
private void jLabel2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel2MouseClicked
// TODO add your handling code here:
}//GEN-LAST:event_jLabel2MouseClicked
public void enableComponents(boolean enabled){
lblGWTModule.setVisible(enabled);
gwtModule.setVisible(enabled);
}
public void setGWTFolder(File folder){
gwtFolder.setText(String.valueOf(folder));
}
public File getGWTFolder(){
return new File(gwtFolder.getText());
}
/**
* @param p a project or null for a new project
*/
public void setProject(Project p){
project = p;
}
public Project getProject(){
return project;
}
public void setGWTModule(String path){
gwtModule.setText(path);
}
public String getGWTModule(){
return gwtModule.getText();
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnGWTBrowse;
private javax.swing.JTextField gwtFolder;
private javax.swing.JTextField gwtModule;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel lblGWTFolder;
private javax.swing.JLabel lblGWTModule;
// End of variables declaration//GEN-END:variables
private class ChangeNotifier implements DocumentListener{
public void insertUpdate(DocumentEvent arg0) {
controller.fireChangeEvent();
}
public void removeUpdate(DocumentEvent arg0) {
controller.fireChangeEvent();
}
public void changedUpdate(DocumentEvent arg0) {
controller.fireChangeEvent();
}
}
}