Java tutorial
/* * Copyright (c) Mirth Corporation. All rights reserved. * * http://www.mirthcorp.com * * The software in this package is published under the terms of the MPL license a copy of which has * been included with this distribution in the LICENSE.txt file. */ package com.mirth.connect.client.ui.editors; import java.util.LinkedHashMap; import java.util.Map; import javax.swing.SwingUtilities; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; import org.apache.commons.lang3.StringUtils; import org.syntax.jedit.SyntaxDocument; import org.syntax.jedit.tokenmarker.XMLTokenMarker; public class XsltStepPanel extends BasePanel { protected static SyntaxDocument mappingDoc; protected MirthEditorPane parent; public XsltStepPanel(MirthEditorPane p) { parent = p; initComponents(); sourceVariableField.getDocument().addDocumentListener(new DocumentListener() { public void changedUpdate(DocumentEvent arg0) { } public void insertUpdate(DocumentEvent arg0) { updateTable(); parent.modified = true; } public void removeUpdate(DocumentEvent arg0) { updateTable(); parent.modified = true; } }); resultVariableField.getDocument().addDocumentListener(new DocumentListener() { public void changedUpdate(DocumentEvent arg0) { } public void insertUpdate(DocumentEvent arg0) { parent.modified = true; } public void removeUpdate(DocumentEvent arg0) { parent.modified = true; } }); mappingDoc = new SyntaxDocument(); mappingDoc.setTokenMarker(new XMLTokenMarker()); xsltTemplateTextPane.setDocument(mappingDoc); } public void updateTable() { if (parent.getSelectedRow() != -1 && !parent.getTableModel() .getValueAt(parent.getSelectedRow(), parent.STEP_TYPE_COL).toString().equals("JavaScript")) { SwingUtilities.invokeLater(new Runnable() { public void run() { //parent.getTableModel().setValueAt(variableTextField.getText(), parent.getSelectedRow(), parent.STEP_NAME_COL); parent.updateTaskPane(parent.getTableModel() .getValueAt(parent.getSelectedRow(), parent.STEP_TYPE_COL).toString()); } }); } } @Override public boolean isModified() { if (StringUtils.isNotBlank(sourceVariableField.getText()) || StringUtils.isNotBlank(resultVariableField.getText()) || StringUtils.isNotBlank(xsltTemplateTextPane.getText()) || StringUtils.isNotBlank(factoryTextField.getText())) { return true; } return false; } public Map<Object, Object> getData() { Map<Object, Object> m = new LinkedHashMap<Object, Object>(); m.put("Source", sourceVariableField.getText().trim()); m.put("Result", resultVariableField.getText().trim()); m.put("XsltTemplate", xsltTemplateTextPane.getText()); if (customRadio.isSelected()) { m.put("Factory", factoryTextField.getText()); } return m; } public void setData(Map<Object, Object> data) { boolean modified = parent.modified; defaultRadio.setSelected(true); customRadio.setSelected(false); factoryTextField.setEnabled(false); factoryTextField.setText(""); if (data != null) { sourceVariableField.setText((String) data.get("Source")); resultVariableField.setText((String) data.get("Result")); xsltTemplateTextPane.setText((String) data.get("XsltTemplate")); String factoryText = (String) data.get("Factory"); if (StringUtils.isNotBlank(factoryText)) { factoryTextField.setText(factoryText); defaultRadio.setSelected(false); customRadio.setSelected(true); factoryTextField.setEnabled(true); } } else { sourceVariableField.setText(""); resultVariableField.setText(""); xsltTemplateTextPane.setText(""); } parent.modified = modified; } /** * 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 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { factoryButtonGroup = new javax.swing.ButtonGroup(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jLabel4 = new javax.swing.JLabel(); sourceVariableField = new javax.swing.JTextField(); resultVariableField = new javax.swing.JTextField(); xsltTemplateTextPane = new com.mirth.connect.client.ui.components.MirthSyntaxTextArea(); jLabel3 = new javax.swing.JLabel(); defaultRadio = new com.mirth.connect.client.ui.components.MirthRadioButton(); customRadio = new com.mirth.connect.client.ui.components.MirthRadioButton(); factoryTextField = new com.mirth.connect.client.ui.components.MirthTextField(); setBackground(new java.awt.Color(255, 255, 255)); jLabel1.setText("Source XML String:"); jLabel2.setText("Result:"); jLabel4.setText("XSLT Template:"); xsltTemplateTextPane.setBorder(javax.swing.BorderFactory.createEtchedBorder()); jLabel3.setText("Transformer Factory:"); defaultRadio.setBackground(new java.awt.Color(255, 255, 255)); factoryButtonGroup.add(defaultRadio); defaultRadio.setSelected(true); defaultRadio.setText("Default"); defaultRadio.setToolTipText( "<html>Select default to use the platform default Transformer Factory.<br/>Select custom to provide a custom Transformer Factory class.</html>"); defaultRadio.setFocusable(false); defaultRadio.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { defaultRadioActionPerformed(evt); } }); customRadio.setBackground(new java.awt.Color(255, 255, 255)); factoryButtonGroup.add(customRadio); customRadio.setText("Custom"); customRadio.setToolTipText( "<html>Select default to use the platform default Transformer Factory.<br/>Select custom to provide a custom Transformer Factory class.</html>"); customRadio.setFocusable(false); customRadio.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { customRadioActionPerformed(evt); } }); factoryTextField.setToolTipText("The fully-qualified class name of the custom Transformer Factory."); factoryTextField.setEnabled(false); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGap(10, 10, 10) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jLabel3).addComponent(jLabel2).addComponent(jLabel4) .addComponent(jLabel1)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(sourceVariableField, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 424, Short.MAX_VALUE) .addComponent(xsltTemplateTextPane, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 424, Short.MAX_VALUE) .addComponent(resultVariableField, javax.swing.GroupLayout.DEFAULT_SIZE, 424, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup().addComponent(defaultRadio) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(customRadio) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(factoryTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 294, 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(sourceVariableField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel1)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel2).addComponent(resultVariableField, 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(defaultRadio).addComponent(customRadio) .addComponent(factoryTextField, 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(xsltTemplateTextPane, javax.swing.GroupLayout.DEFAULT_SIZE, 207, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup().addComponent(jLabel4).addGap(0, 0, Short.MAX_VALUE))) .addContainerGap())); }// </editor-fold>//GEN-END:initComponents private void defaultRadioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_defaultRadioActionPerformed factoryTextField.setEnabled(false); }//GEN-LAST:event_defaultRadioActionPerformed private void customRadioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_customRadioActionPerformed factoryTextField.setEnabled(true); }//GEN-LAST:event_customRadioActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JRadioButton customRadio; private javax.swing.JRadioButton defaultRadio; private javax.swing.ButtonGroup factoryButtonGroup; private javax.swing.JTextField factoryTextField; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JTextField resultVariableField; private javax.swing.JTextField sourceVariableField; private com.mirth.connect.client.ui.components.MirthSyntaxTextArea xsltTemplateTextPane; // End of variables declaration//GEN-END:variables }