Java tutorial
/* * Maui, Maltcms User Interface. * Copyright (C) 2008-2014, The authors of Maui. All rights reserved. * * Project website: http://maltcms.sf.net * * Maui may be used under the terms of either the * * GNU Lesser General Public License (LGPL) * http://www.gnu.org/licenses/lgpl.html * * or the * * Eclipse Public License (EPL) * http://www.eclipse.org/org/documents/epl-v10.php * * As a user/recipient of Maui, you may choose which license to receive the code * under. Certain files or entire directories may not be covered by this * dual license, but are subject to licenses compatible to both LGPL and EPL. * License exceptions are explicitly declared in all relevant files or in a * LICENSE file in the relevant directories. * * Maui is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. Please consult the relevant license documentation * for details. */ package maltcms.ui.fileHandles.properties.wizards; import maltcms.ui.fileHandles.properties.graph.widget.PipelineGeneralConfigWidget; import maltcms.ui.fileHandles.properties.tools.ModelBuilder; import org.apache.commons.configuration.Configuration; import org.apache.commons.configuration.PropertiesConfiguration; import org.openide.DialogDisplayer; import org.openide.NotifyDescriptor; /** * * @author Mathias Wilhelm */ public class PipelinePropertiesVisualPanel2 extends javax.swing.JPanel { private PipelineGeneralConfigWidget node; /** * Creates new form PipelinePropertiesVisualPanel2 */ public PipelinePropertiesVisualPanel2(PipelineGeneralConfigWidget node) { this.node = node; initComponents(); refreshTableModel(); } @Override public String getName() { return "Change Properties"; } /** * 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() { jLabel1 = new javax.swing.JLabel(); addPropertyButton = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); jScrollPane2 = new javax.swing.JScrollPane(); jScrollPane1 = new javax.swing.JScrollPane(); jTable1 = new javax.swing.JTable(); jLabel1.setText(org.openide.util.NbBundle.getMessage(PipelinePropertiesVisualPanel2.class, "PipelinePropertiesVisualPanel2.jLabel1.text")); // NOI18N addPropertyButton.setText(org.openide.util.NbBundle.getMessage(PipelinePropertiesVisualPanel2.class, "PipelinePropertiesVisualPanel2.addPropertyButton.text_1")); // NOI18N addPropertyButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { addPropertyButtonActionPerformed(evt); } }); jButton2.setText(org.openide.util.NbBundle.getMessage(PipelinePropertiesVisualPanel2.class, "PipelinePropertiesVisualPanel2.jButton2.text_1")); // NOI18N jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } }); jTable1.setModel( new javax.swing.table.DefaultTableModel( new Object[][] { { null, null, null, null }, { null, null, null, null }, { null, null, null, null }, { null, null, null, null } }, new String[] { "Title 1", "Title 2", "Title 3", "Title 4" })); jScrollPane1.setViewportView(jTable1); jScrollPane2.setViewportView(jScrollPane1); 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).addComponent(jLabel1) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addComponent(jButton2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 112, Short.MAX_VALUE) .addComponent(addPropertyButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) .addGap(18, 18, 18) .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 463, Short.MAX_VALUE) .addContainerGap())); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addContainerGap().addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup().addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(addPropertyButton) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton2).addGap(0, 191, Short.MAX_VALUE))) .addContainerGap())); }// </editor-fold>//GEN-END:initComponents private void addPropertyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addPropertyButtonActionPerformed NotifyDescriptor.InputLine nd = new NotifyDescriptor.InputLine("Please enter name", "New Property Name"); Object o = DialogDisplayer.getDefault().notify(nd); if (o == NotifyDescriptor.OK_OPTION) { String s = nd.getInputText(); if (s.isEmpty()) { NotifyDescriptor nd2 = new NotifyDescriptor.Message("Property name must not be empty!", NotifyDescriptor.INFORMATION_MESSAGE); DialogDisplayer.getDefault().notify(nd2); addPropertyButtonActionPerformed(evt); } else { this.node.setProperty(s, "newPropertyValue"); refreshTableModel(); } } }//GEN-LAST:event_addPropertyButtonActionPerformed private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed int row = this.jTable1.getSelectedRow(); int col = this.jTable1.getSelectedColumn(); String s = (String) jTable1.getValueAt(row, 0); this.node.removeProperty(s); refreshTableModel(); }//GEN-LAST:event_jButton2ActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton addPropertyButton; private javax.swing.JButton jButton2; private javax.swing.JLabel jLabel1; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JTable jTable1; // End of variables declaration//GEN-END:variables private void refreshTableModel() { Configuration property = new PropertiesConfiguration(); if (!this.node.getProperties().isEmpty()) { property = this.node.getProperties(); } this.jTable1.setModel(ModelBuilder.getModel(property, null)); } }