maltcms.ui.fileHandles.properties.wizards.PipelinePropertiesVisualPanel1.java Source code

Java tutorial

Introduction

Here is the source code for maltcms.ui.fileHandles.properties.wizards.PipelinePropertiesVisualPanel1.java

Source

/* 
 * 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 cross.datastructures.tuple.Tuple2D;
import java.awt.Color;
import java.awt.Component;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.ListCellRenderer;
import javax.swing.table.TableModel;
import maltcms.ui.fileHandles.properties.graph.widget.PipelineElementWidget;
import maltcms.ui.fileHandles.properties.graph.PipelineGraphScene;
import maltcms.ui.fileHandles.properties.tools.PropertyLoader;
import org.apache.commons.configuration.Configuration;

public final class PipelinePropertiesVisualPanel1 extends JPanel implements ItemListener {

    private PipelineElementWidget node;
    private final String[] serviceProviders = PropertyLoader
            .getListServiceProviders("cross.commands.fragments.AFragmentCommand");

    /**
     * Creates new form PipelinePropertiesVisualPanel1
     */
    public PipelinePropertiesVisualPanel1(PipelineElementWidget node) {
        this.node = node;
        initComponents();

        this.jTextField1.setEditable(false);
        this.jTextField2.setEditable(false);
        this.jTextField3.setEditable(false);
        this.jTextField5.setEditable(true);
        this.jComboBox1.setRenderer(new CustomComboBoxModelRenderer());
        if (!this.node.getClassName().equals("")) {
            this.jComboBox1.setSelectedItem(node.getClassName());
        }
        this.jComboBox1.addItemListener(this);
        refreshTableModel(node.getBean());
    }

    private class CustomComboBoxModelRenderer extends JLabel implements ListCellRenderer<String> {

        public CustomComboBoxModelRenderer() {
            setOpaque(true);
        }

        @Override
        public Component getListCellRendererComponent(JList<? extends String> list, String value, int index,
                boolean isSelected, boolean cellHasFocus) {

            String valueSuffix = value.substring(value.lastIndexOf(".") + 1);
            setText(valueSuffix);

            Color background;
            Color foreground;

            // check if this cell represents the current DnD drop location
            JList.DropLocation dropLocation = list.getDropLocation();
            if (dropLocation != null && !dropLocation.isInsert() && dropLocation.getIndex() == index) {

                background = Color.BLUE;
                foreground = Color.WHITE;

                // check if this cell is selected
            } else if (isSelected) {
                background = Color.RED;
                foreground = Color.WHITE;

                // unselected, and not the DnD drop location
            } else {
                background = Color.WHITE;
                foreground = Color.BLACK;
            }

            setBackground(background);
            setForeground(foreground);

            return this;
        }
    }

    @Override
    public String getName() {
        return "Select 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.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jComboBox1 = new javax.swing.JComboBox();
        jTextField1 = new javax.swing.JTextField();
        jTextField2 = new javax.swing.JTextField();
        jTextField3 = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jTextField5 = new javax.swing.JTextField();

        org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle
                .getMessage(PipelinePropertiesVisualPanel1.class, "PipelinePropertiesVisualPanel1.jLabel1.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle
                .getMessage(PipelinePropertiesVisualPanel1.class, "PipelinePropertiesVisualPanel1.jLabel2.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle
                .getMessage(PipelinePropertiesVisualPanel1.class, "PipelinePropertiesVisualPanel1.jLabel3.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(jLabel4, org.openide.util.NbBundle
                .getMessage(PipelinePropertiesVisualPanel1.class, "PipelinePropertiesVisualPanel1.jLabel4.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(jLabel5, org.openide.util.NbBundle
                .getMessage(PipelinePropertiesVisualPanel1.class, "PipelinePropertiesVisualPanel1.jLabel5.text")); // NOI18N

        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);

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(
                PropertyLoader.getListServiceProviders("cross.commands.fragments.AFragmentCommand")));
        jComboBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox1ActionPerformed(evt);
            }
        });

        jTextField1.setText(org.openide.util.NbBundle.getMessage(PipelinePropertiesVisualPanel1.class,
                "PipelinePropertiesVisualPanel1.jTextField1.text")); // NOI18N

        jTextField2.setText(org.openide.util.NbBundle.getMessage(PipelinePropertiesVisualPanel1.class,
                "PipelinePropertiesVisualPanel1.jTextField2.text")); // NOI18N

        jTextField3.setText(org.openide.util.NbBundle.getMessage(PipelinePropertiesVisualPanel1.class,
                "PipelinePropertiesVisualPanel1.jTextField3.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(jLabel7, org.openide.util.NbBundle
                .getMessage(PipelinePropertiesVisualPanel1.class, "PipelinePropertiesVisualPanel1.jLabel7.text")); // NOI18N

        jTextField5.setText(org.openide.util.NbBundle.getMessage(PipelinePropertiesVisualPanel1.class,
                "PipelinePropertiesVisualPanel1.jTextField5.text")); // NOI18N
        jTextField5.addCaretListener(new javax.swing.event.CaretListener() {
            public void caretUpdate(javax.swing.event.CaretEvent evt) {
                jTextField5CaretUpdate(evt);
            }
        });
        jTextField5.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextField5KeyTyped(evt);
            }
        });

        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)
                        .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jLabel2).addComponent(jLabel3).addComponent(jLabel4))
                                .addGap(35, 35, 35)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jTextField3, javax.swing.GroupLayout.DEFAULT_SIZE, 442,
                                                Short.MAX_VALUE)
                                        .addComponent(jTextField2, javax.swing.GroupLayout.DEFAULT_SIZE, 442,
                                                Short.MAX_VALUE)
                                        .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 442,
                                                Short.MAX_VALUE)))
                        .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jLabel1).addComponent(jLabel7))
                                .addGap(22, 22, 22).addGroup(
                                        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jTextField5, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        442, Short.MAX_VALUE)
                                                .addGroup(layout.createSequentialGroup()
                                                        .addComponent(jComboBox1, 0, 439, Short.MAX_VALUE)
                                                        .addGap(3, 3, 3))))
                        .addGroup(layout.createSequentialGroup().addComponent(jLabel5).addGap(22, 22, 22)
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 443,
                                        Short.MAX_VALUE)))
                        .addContainerGap()));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel7).addComponent(jTextField5,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel1))
                        .addGap(37, 37, 37)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel2).addComponent(jTextField1,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel3).addComponent(jTextField2,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel4).addComponent(jTextField3,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel5).addComponent(jScrollPane1,
                                        javax.swing.GroupLayout.PREFERRED_SIZE, 178,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
    }// </editor-fold>//GEN-END:initComponents

    private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jComboBox1ActionPerformed

    private void jTextField5CaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_jTextField5CaretUpdate
        if (!jTextField5.getText().isEmpty()) {
            jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(
                    PropertyLoader.filterByPackageName(this.serviceProviders, jTextField5.getText())));
        }
    }//GEN-LAST:event_jTextField5CaretUpdate

    private void jTextField5KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField5KeyTyped
        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(
                PropertyLoader.filterByPackageName(this.serviceProviders, jTextField5.getText())));
    }//GEN-LAST:event_jTextField5KeyTyped
     // Variables declaration - do not modify//GEN-BEGIN:variables

    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField5;
    // End of variables declaration//GEN-END:variables

    @Override
    public void itemStateChanged(final ItemEvent e) {

        refreshTableModel(this.jComboBox1.getSelectedItem());

    }

    private void refreshTableModel(Object object) {
        Configuration properties;
        Configuration variables;
        if (object.getClass().getCanonicalName().equals(this.node.getClassName())
                && !this.node.getProperties().isEmpty()) {
            properties = this.node.getProperties();
            variables = this.node.getVariables();
        } else {
            Tuple2D<Configuration, Configuration> tmp = PropertyLoader.handleShowProperties(object);
            properties = tmp.getFirst();
            variables = tmp.getSecond();
        }
        if (node.getScene() instanceof PipelineGraphScene) {
            PipelineGraphScene scene = (PipelineGraphScene) node.getScene();
            this.node.setLabel(scene.getNodeLabel(node, scene.isShortLabelActive()));
        }
        this.node.setProperties(properties);
        //        this.jTable1.setModel(PropertyLoader.getModel(properties));

        // TODO remove dirty style
        TableModel htm = new HashTableModelFactory().create(this.node, this.jTable1, true, object);

        //        if (className.length() > 17) {
        //            this.node.setLabel(className.substring(17, className.length()));
        //        }
        this.jTextField1.setText(variables.getString(PropertyLoader.REQUIRED_VARS));
        this.jTextField2.setText(variables.getString(PropertyLoader.OPTIONAL_VARS));
        this.jTextField3.setText(variables.getString(PropertyLoader.PROVIDED_VARS));
    }
}