ca.uhn.hunit.swing.ui.iface.JmsInterfaceForm.java Source code

Java tutorial

Introduction

Here is the source code for ca.uhn.hunit.swing.ui.iface.JmsInterfaceForm.java

Source

/**
 *
 * The contents of this file are subject to the Mozilla Public License Version 1.1
 * (the "License"); you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at http://www.mozilla.org/MPL/
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the
 * specific language governing rights and limitations under the License.
 *
 * The Initial Developer of the Original Code is University Health Network. Copyright (C)
 * 2001.  All Rights Reserved.
 *
 * Alternatively, the contents of this file may be used under the terms of the
 * GNU General Public License (the  "GPL"), in which case the provisions of the GPL are
 * applicable instead of those above.  If you wish to allow use of your version of this
 * file only under the terms of the GPL and not to allow others to use your version
 * of this file under the MPL, indicate your decision by deleting  the provisions above
 * and replace  them with the notice and other provisions required by the GPL License.
 * If you do not delete the provisions above, a recipient may use your version of
 * this file under either the MPL or the GPL.
 */
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JmsInterfaceForm.java
 *
 * Created on 9-Oct-2009, 7:30:51 PM
 */
package ca.uhn.hunit.swing.ui.iface;

import ca.uhn.hunit.iface.JmsInterfaceImpl;
import ca.uhn.hunit.l10n.Colours;
import ca.uhn.hunit.swing.controller.ctx.JmsInterfaceContextController;
import ca.uhn.hunit.swing.ui.AbstractContextForm;
import ca.uhn.hunit.util.log.LogFactory;

import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.beans.PropertyVetoException;
import javax.swing.event.UndoableEditEvent;
import javax.swing.event.UndoableEditListener;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;

/**
 *
 * @author James
 */
public class JmsInterfaceForm extends AbstractContextForm<JmsInterfaceContextController> {

    private static final long serialVersionUID = 1;
    //private Log myLog;

    /** Creates new form JmsInterfaceForm */
    public JmsInterfaceForm() {
        initComponents();
    }

    /** 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() {

        jLabel5 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        myQueueNameTextBox = new javax.swing.JTextField();
        myQueueTopicCombo = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        myUsernameTextBox = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        myPasswordTextBox = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        myConnectionFactoryBeanEditor = new ca.uhn.hunit.swing.ui.util.BeanDefinitionForm();

        jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        jLabel5.setText("Username");

        setPreferredSize(new java.awt.Dimension(401, 300));

        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("ca/uhn/hunit/l10n/UiStrings"); // NOI18N
        jPanel1.setBorder(
                javax.swing.BorderFactory.createTitledBorder(bundle.getString("interface.jms.jms_properties"))); // NOI18N

        myQueueNameTextBox.setText("jTextField1");

        myQueueTopicCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Queue", "Topic" }));

        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        jLabel2.setText("Username");

        myUsernameTextBox.setText("jTextField1");

        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        jLabel3.setText("Password");

        myPasswordTextBox.setText("jTextField1");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(jPanel1Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup().addGroup(jPanel1Layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup().addContainerGap()
                                .addComponent(myQueueTopicCombo, javax.swing.GroupLayout.PREFERRED_SIZE, 120,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(myQueueNameTextBox, javax.swing.GroupLayout.DEFAULT_SIZE, 286,
                                        Short.MAX_VALUE))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                jPanel1Layout.createSequentialGroup().addGap(35, 35, 35)
                                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 95,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(myUsernameTextBox, javax.swing.GroupLayout.PREFERRED_SIZE, 95,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel3)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(myPasswordTextBox, javax.swing.GroupLayout.DEFAULT_SIZE, 139,
                                                Short.MAX_VALUE)))
                        .addContainerGap()));
        jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup().addGroup(jPanel1Layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(myQueueTopicCombo, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(myQueueNameTextBox, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 14,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(myUsernameTextBox, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, 20, Short.MAX_VALUE)
                                .addComponent(myPasswordTextBox, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap()));

        jPanel2.setBorder(javax.swing.BorderFactory
                .createTitledBorder(bundle.getString("interface.jms.conn_factory_properties"))); // NOI18N

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(jPanel2Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 432, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(
                        myConnectionFactoryBeanEditor, javax.swing.GroupLayout.Alignment.TRAILING,
                        javax.swing.GroupLayout.DEFAULT_SIZE, 432, Short.MAX_VALUE)));
        jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 167, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel2Layout
                                .createSequentialGroup().addComponent(myConnectionFactoryBeanEditor,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, 156, Short.MAX_VALUE)
                                .addContainerGap())));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                        Short.MAX_VALUE)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                        Short.MAX_VALUE));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
    }// </editor-fold>//GEN-END:initComponents
     // Variables declaration - do not modify//GEN-BEGIN:variables

    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private ca.uhn.hunit.swing.ui.util.BeanDefinitionForm myConnectionFactoryBeanEditor;
    private javax.swing.JTextField myPasswordTextBox;
    private javax.swing.JTextField myQueueNameTextBox;
    private javax.swing.JComboBox myQueueTopicCombo;
    private javax.swing.JTextField myUsernameTextBox;
    // End of variables declaration//GEN-END:variables

    /**
     * {@inheritDoc }
     */
    @Override
    public void setController(JmsInterfaceContextController theController) {
        final JmsInterfaceImpl model = theController.getModel();

        myUsernameTextBox.setText(model.getUsername());
        myUsernameTextBox.getDocument().addUndoableEditListener(new UndoableEditListener() {

            public void undoableEditHappened(UndoableEditEvent e) {
                model.setUsername(myUsernameTextBox.getText());
            }
        });

        myPasswordTextBox.setText(model.getPassword());
        myPasswordTextBox.getDocument().addUndoableEditListener(new UndoableEditListener() {

            public void undoableEditHappened(UndoableEditEvent e) {
                model.setPassword(myPasswordTextBox.getText());
            }
        });

        myQueueNameTextBox.setText(model.getQueueName());
        if (StringUtils.isBlank(model.getQueueName())) {
            myQueueNameTextBox.setBackground(Colours.getTextFieldError());
        }
        myQueueNameTextBox.getDocument().addUndoableEditListener(new UndoableEditListener() {

            @Override
            public void undoableEditHappened(UndoableEditEvent e) {
                try {
                    model.setQueueName(myQueueNameTextBox.getText());
                    myQueueNameTextBox.setBackground(Colours.getTextFieldOk());
                } catch (PropertyVetoException ex) {
                    LogFactory.INSTANCE.getSystem(getClass()).error(ex.getMessage());
                    myQueueNameTextBox.setBackground(Colours.getTextFieldError());
                }
            }
        });

        myQueueTopicCombo.setSelectedIndex(model.isPubSubDomain() ? 1 : 0);
        myQueueTopicCombo.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(ItemEvent e) {
                model.setPubSubDomain(myQueueTopicCombo.getSelectedIndex() == 1);
            }
        });

        myConnectionFactoryBeanEditor.setController(theController.getConstructorArgsController());
    }

    /**
     * {@inheritDoc }
     */
    @Override
    public void tearDown() {
        // nothing
    }
}