/** * SlingBeans - NetBeans Sling plugin * https://github.com/jkan997/SlingBeans * Licensed under Apache 2.0 license * http://www.apache.org/licenses/LICENSE-2.0 */ package org.jkan997.slingbeans.dialogs; import javax.swing.DefaultComboBoxModel; import org.jkan997.slingbeans.helper.PropertyType; public class NewPropertyDialog extends javax.swing.JDialog { private boolean createProperty = false; public NewPropertyDialog(java.awt.Frame parent, boolean modal) { super(parent, modal); initComponents(); propertyTypeCombo.setModel(new DefaultComboBoxModel(PropertyType.TYPES)); propertyTypeCombo.setSelectedIndex(0); valueEditor.setTypeAndValue(propertyTypeCombo.getSelectedItem().toString(), "value"); } public void init() { } /** * 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() { propertyNameText = new javax.swing.JTextField(); jLabel2 = new javax.swing.JLabel(); jPanel1 = new javax.swing.JPanel(); cancelBtn = new javax.swing.JButton(); addBtn = new javax.swing.JButton(); errorLabel = new javax.swing.JLabel(); jLabel4 = new javax.swing.JLabel(); jLabel5 = new javax.swing.JLabel(); propertyTypeCombo = new javax.swing.JComboBox(); valueEditor = new org.jkan997.slingbeans.components.valueeditor.ValueEditorContainer(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setTitle(org.openide.util.NbBundle.getMessage(NewPropertyDialog.class, "NewPropertyDialog.title")); // NOI18N propertyNameText.setText(org.openide.util.NbBundle.getMessage(NewPropertyDialog.class, "NewPropertyDialog.propertyNameText.text")); // NOI18N jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); jLabel2.setText(org.openide.util.NbBundle.getMessage(NewPropertyDialog.class, "NewPropertyDialog.jLabel2.text")); // NOI18N cancelBtn.setText(org.openide.util.NbBundle.getMessage(NewPropertyDialog.class, "NewPropertyDialog.cancelBtn.text")); // NOI18N cancelBtn.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cancelBtnActionPerformed(evt); } }); addBtn.setText(org.openide.util.NbBundle.getMessage(NewPropertyDialog.class, "NewPropertyDialog.addBtn.text")); // NOI18N addBtn.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { addBtnActionPerformed(evt); } }); errorLabel.setForeground(new java.awt.Color(255, 0, 0)); errorLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); errorLabel.setText(org.openide.util.NbBundle.getMessage(NewPropertyDialog.class, "NewPropertyDialog.errorLabel.text")); // NOI18N errorLabel.setToolTipText(org.openide.util.NbBundle.getMessage(NewPropertyDialog.class, "NewPropertyDialog.errorLabel.toolTipText")); // NOI18N org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(jPanel1Layout.createSequentialGroup() .addContainerGap() .add(errorLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(cancelBtn) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(addBtn) .addContainerGap()) ); jPanel1Layout.linkSize(new java.awt.Component[] {addBtn, cancelBtn}, org.jdesktop.layout.GroupLayout.HORIZONTAL); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(jPanel1Layout.createSequentialGroup() .addContainerGap() .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(errorLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .add(jPanel1Layout.createSequentialGroup() .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(addBtn) .add(cancelBtn)) .add(0, 0, Short.MAX_VALUE))) .addContainerGap()) ); jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); jLabel4.setText(org.openide.util.NbBundle.getMessage(NewPropertyDialog.class, "NewPropertyDialog.jLabel4.text")); // NOI18N jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); jLabel5.setText(org.openide.util.NbBundle.getMessage(NewPropertyDialog.class, "NewPropertyDialog.jLabel5.text")); // NOI18N propertyTypeCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); propertyTypeCombo.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { propertyTypeComboActionPerformed(evt); } }); propertyTypeCombo.addPropertyChangeListener(new java.beans.PropertyChangeListener() { public void propertyChange(java.beans.PropertyChangeEvent evt) { propertyTypeComboPropertyChange(evt); } }); org.jdesktop.layout.GroupLayout valueEditorLayout = new org.jdesktop.layout.GroupLayout(valueEditor); valueEditor.setLayout(valueEditorLayout); valueEditorLayout.setHorizontalGroup( valueEditorLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(0, 0, Short.MAX_VALUE) ); valueEditorLayout.setVerticalGroup( valueEditorLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(0, 26, Short.MAX_VALUE) ); org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .addContainerGap() .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .add(layout.createSequentialGroup() .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) .add(jLabel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 89, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .add(jLabel4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 89, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(propertyNameText) .add(valueEditor, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) .add(layout.createSequentialGroup() .add(jLabel5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 89, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(propertyTypeCombo, 0, 281, Short.MAX_VALUE))) .addContainerGap()))) ); layout.setVerticalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(jLabel5) .add(propertyTypeCombo, 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(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(jLabel2) .add(propertyNameText, 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(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false) .add(jLabel4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 26, Short.MAX_VALUE) .add(valueEditor, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) ); pack(); }// </editor-fold>//GEN-END:initComponents private void propertyTypeComboPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_propertyTypeComboPropertyChange //propertyNameText.setText(); }//GEN-LAST:event_propertyTypeComboPropertyChange private void addBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addBtnActionPerformed if (!valueEditor.isValidValue()) { errorLabel.setText("Invalid value"); } else { //errorLabel.setText("Value OK"); createProperty = true; setVisible(false); this.dispose(); } }//GEN-LAST:event_addBtnActionPerformed private void propertyTypeComboActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_propertyTypeComboActionPerformed valueEditor.setTypeAndValue(propertyTypeCombo.getSelectedItem().toString(), null); //SwingHelper.showMessage(propertyTypeCombo.getSelectedItem().toString()); }//GEN-LAST:event_propertyTypeComboActionPerformed private void cancelBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelBtnActionPerformed this.setVisible(false); this.dispose(); }//GEN-LAST:event_cancelBtnActionPerformed public boolean isCreateProperty() { return createProperty; } public String getPropertyName() { return propertyNameText.getText(); } public String getPropertyType() { return propertyTypeCombo.getSelectedItem().toString(); } public Object getPropertyValue() { return valueEditor.getValue(); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton addBtn; private javax.swing.JButton cancelBtn; private javax.swing.JLabel errorLabel; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JPanel jPanel1; private javax.swing.JTextField propertyNameText; private javax.swing.JComboBox propertyTypeCombo; private org.jkan997.slingbeans.components.valueeditor.ValueEditorContainer valueEditor; // End of variables declaration//GEN-END:variables }