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; public class ExternalScriptPanel extends BasePanel { protected MirthEditorPane parent; protected final boolean isStep; public ExternalScriptPanel(MirthEditorPane p, boolean step) { parent = p; isStep = step; initComponents(); variableTextField.getDocument().addDocumentListener(new DocumentListener() { public void changedUpdate(DocumentEvent arg0) { } public void insertUpdate(DocumentEvent arg0) { if (isStep) { updateTable(); } parent.modified = true; } public void removeUpdate(DocumentEvent arg0) { if (isStep) { updateTable(); } parent.modified = true; } }); } public void updateTable() { if (parent.getSelectedRow() != -1 && !parent.getTableModel() .getValueAt(parent.getSelectedRow(), parent.STEP_TYPE_COL).toString().equals("File")) { 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() { return StringUtils.isNotBlank(variableTextField.getText()); } public Map<Object, Object> getData() { Map<Object, Object> m = new LinkedHashMap<Object, Object>(); m.put("Variable", variableTextField.getText().trim()); return m; } public void setData(Map<Object, Object> data) { boolean modified = parent.modified; if (data != null) { variableTextField.setText((String) data.get("Variable")); } else { variableTextField.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() { jLabel1 = new javax.swing.JLabel(); variableTextField = new javax.swing.JTextField(); jLabel2 = new javax.swing.JLabel(); setBackground(new java.awt.Color(255, 255, 255)); jLabel1.setText("Script Path:"); jLabel2.setText("Enter the path of an external JavaScript file accessible from the Mirth Connect server."); 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(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 534, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup().addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(variableTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 474, Short.MAX_VALUE))) .addContainerGap())); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addContainerGap().addComponent(jLabel2).addGap(8, 8, 8) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1).addComponent(variableTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(255, Short.MAX_VALUE))); }// </editor-fold>//GEN-END:initComponents // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JTextField variableTextField; // End of variables declaration//GEN-END:variables }