gt:     protected Expression generateExpression() {
context: /*
   * SLD Editor - The Open Source Java SLD Editor
   *
   * Copyright (C) 2016, SCISYS UK Limited
   *
   * This program is free software: you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published by
   * the Free Software Foundation, either version 3 of the License, or
   * (at your option) any later version.
   *
   * This program 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.  See the
   * GNU General Public License for more details.
   *
   * You should have received a copy of the GNU General Public License
   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
   */
  
  package com.sldeditor.ui.detail.config;
  
  import com.sldeditor.common.console.ConsoleManager;
  import com.sldeditor.common.undo.UndoActionInterface;
  import com.sldeditor.common.undo.UndoEvent;
  import com.sldeditor.common.undo.UndoInterface;
  import com.sldeditor.common.undo.UndoManager;
  import com.sldeditor.common.xml.ui.FieldIdEnum;
  import com.sldeditor.ui.detail.BasePanel;
  import com.sldeditor.ui.widgets.FieldPanel;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import java.beans.PropertyChangeEvent;
  import java.beans.PropertyChangeListener;
  import java.util.ArrayList;
  import java.util.List;
  import javax.swing.JButton;
  import javax.swing.JTextField;
  import javax.swing.text.AttributeSet;
  import javax.swing.text.BadLocationException;
  import javax.swing.text.PlainDocument;
  import org.opengis.filter.expression.Expression;
  
  /**
   * The Class FieldConfigString wraps a text field GUI component and an optional
   * value/attribute/expression drop down, Can restrict the maximum number of characters in the
   * string. Able to mark the string as being a regular expression which removes a preceding '.'
   * before display and prepends when field is applied.
   *
   * <p>Supports undo/redo functionality.
   *
   * <p>Instantiated by {@link com.sldeditor.ui.detail.config.panelconfig.ReadPanelConfig}
   *
   * @author Robert Ward (SCISYS)
   */
  public class FieldConfigString extends FieldConfigBase implements UndoActionInterface {
  
      /** The text field. */
      private JTextField textField;
  
      /** The default value. */
      private String defaultValue = "";
  
      /** The old value obj. */
      private Object oldValueObj = null;
  
      /** The button text. */
      private String buttonText = null;
  
      /** The button pressed listener list. */
      private List<FieldConfigStringButtonInterface> buttonPressedListenerList = null;
  
      /** The maximum string size. */
      private int maximumStringSize = -1;
  
      /** The regular expression string flag. */
      private boolean isRegExpString = false;
  
      /** The Class JTextFieldLimit. */
      public class JTextFieldLimit extends PlainDocument {
  
          /** The Constant serialVersionUID. */
          private static final long serialVersionUID = 1L;
  
          /** The maximum number of characters. */
          private int limit;
  
          /**
           * Instantiates a new j text field limit.
           *
           * @param limit the limit
           */
          JTextFieldLimit(int limit) {
              super();
              this.limit = limit;
          }
  
          /*
           * (non-Javadoc)
           *
           * @see javax.swing.text.PlainDocument#insertString(int, java.lang.String, javax.swing.text.AttributeSet)
           */
          @Override
          public void insertString(int offset, String str, AttributeSet attr)
                  throws BadLocationException {
              if (str == null) return;
  
              if ((getLength() + str.length()) <= limit) {
                  String oldValue = this.getText(0, getLength());
                  super.insertString(offset, str, attr);
                  String newValue = this.getText(0, getLength());
  
                  valueStored(oldValue, newValue);
              }
          }
  
          /*
           * (non-Javadoc)
           *
           * @see javax.swing.text.AbstractDocument#remove(int, int)
           */
          @Override
          public void remove(int offs, int len) throws BadLocationException {
              try {
                  String oldValue = this.getText(0, getLength());
                  super.remove(offs, len);
                  String newValue = this.getText(0, getLength());
  
                  valueStored(oldValue, newValue);
              } catch (BadLocationException e) {
                  ConsoleManager.getInstance().exception(this, e);
              }
          }
      }
  
      /**
       * Instantiates a new field config string.
       *
       * @param commonData the common data
       * @param buttonText the button text
       */
      public FieldConfigString(FieldConfigCommonData commonData, String buttonText) {
          super(commonData);
  
          this.buttonText = buttonText;
      }
  
      /** Creates the ui. */
      /*
       * (non-Javadoc)
       *
       * @see com.sldeditor.ui.detail.config.FieldConfigBase#createUI()
       */
      @Override
      public void createUI() {
          if (textField == null) {
              int xPos = getXPos();
              FieldPanel fieldPanel = createFieldPanel(xPos, getLabel());
  
              textField = new TextFieldPropertyChange();
              textField.setBounds(
                      xPos + BasePanel.WIDGET_X_START,
                      0,
                      this.isValueOnly()
                              ? BasePanel.WIDGET_EXTENDED_WIDTH
                              : BasePanel.WIDGET_STANDARD_WIDTH,
                      BasePanel.WIDGET_HEIGHT);
              fieldPanel.add(textField);
  
              textField.addPropertyChangeListener(
                      TextFieldPropertyChange.TEXT_PROPERTY,
                      new PropertyChangeListener() {
  
                          /*
                           * (non-Javadoc)
                           *
                           * @see java.beans.PropertyChangeListener#propertyChange(java.beans. PropertyChangeEvent)
                           */
                          @Override
                          public void propertyChange(PropertyChangeEvent evt) {
                              String originalValue = (String) evt.getOldValue();
                              String newValueObj = (String) evt.getNewValue();
  
                              valueStored(originalValue, newValueObj);
                          }
                      });
  
              if (maximumStringSize > 0) {
                  textField.setDocument(new JTextFieldLimit(maximumStringSize));
              }
  
              if (buttonText != null) {
                  final JButton buttonExternal = new JButton(buttonText);
                  buttonExternal.addActionListener(
                          new ActionListener() {
  
                              public void actionPerformed(ActionEvent e) {
                                  externalButtonPressed(buttonExternal);
                              }
                          });
  
                  int buttonWidth = 26;
                  int padding = 3;
                  buttonExternal.setBounds(
                          xPos + textField.getX() - buttonWidth - padding,
                          0,
                          buttonWidth,
                          BasePanel.WIDGET_HEIGHT);
                  fieldPanel.add(buttonExternal);
              }
  
              if (!isValueOnly()) {
                  setAttributeSelectionPanel(
                          fieldPanel.internalCreateAttrButton(String.class, this, isRasterSymbol()));
              }
          }
      }
  
      /**
       * Attribute selection.
       *
       * @param field the field
       */
      /*
       * (non-Javadoc)
       *
       * @see com.sldeditor.ui.iface.AttributeButtonSelectionInterface#attributeSelection(java.lang.String)
       */
      @Override
      public void attributeSelection(String field) {
          // Not used
      }
  
      /**
       * Sets the enabled.
       *
       * @param enabled the new enabled
       */
      /*
       * (non-Javadoc)
       *
       * @see com.sldeditor.ui.detail.config.FieldConfigBase#setEnabled(boolean)
       */
      @Override
      public void internalSetEnabled(boolean enabled) {
          if (textField != null) {
              textField.setEnabled(enabled);
          }
      }
  
      /**
       * Generate expression.
       *
       * @return the expression
       */
      /*
       * (non-Javadoc)
       *
       * @see com.sldeditor.ui.detail.config.FieldConfigBase#generateExpression()
       */
      @Override
  