Code example for PropertyChangeSupport

Methods: firePropertyChange

0
  } 
 
  protected void setQuerySelected(final boolean querySelected)
  { 
    this.querySelected = querySelected;
    propertyChangeSupport.firePropertyChange(QUERY_SELECTED, !querySelected, querySelected);
  } 
 
  public void addQuery(final String name, final T value)
  { 
    queries.addElement(new DataSetQuery<T>(name, value));
  } 
 
  public void addQuery(final String name, final T value, final String language, final String script)
  { 
    queries.addElement(new DataSetQuery<T>(name, value, language, script));
  } 
 
  public boolean createQuery() 
  { 
    final String queryNamePattern = Messages.getInstance().getString("NamedQueryModel.Query");
    final String queryName = generateQueryName(queryNamePattern);
    final T defaultObject = createDefaultObject();
    if (defaultObject == null)
    { 
      return false; 
    } 
 
    final DataSetQuery<T> query = new DataSetQuery<T>(queryName, defaultObject);
    queries.addElement(query);
    setSelectedDataSetQuery(query);
    return true; 
  } 
 
  protected abstract T createDefaultObject(); 
 
  public void setSelectedDataSetQuery(final DataSetQuery<T> dataSetQuery)
  { 
    queries.setSelectedItem(dataSetQuery);
  } 
 
  public DataSetQuery<T> getSelectedDataSetQuery() 
  { 
    return queries.getSelectedQuery();
  } 
 
  public void setSelectedQuery(final String selectedQueryName)
  { 
    if (selectedQueryName == null)
    { 
      setSelectedDataSetQuery(null); 
      return; 
    } 
 
    for (int i = 0; i < queries.getSize(); i += 1)
    { 
      final DataSetQuery<T> q = (DataSetQuery<T>) queries.getElementAt(i);
      if (selectedQueryName.equals(q.getQueryName()))
      { 
        setSelectedDataSetQuery(q);
        return; 
      } 
    } 
  } 
 
  public String generateQueryName(final String queryName)
  { 
    final DataSetComboBoxModel queries = getQueries();
    for (int i = 1; i < 1000; ++i)
    { 
      final String newQuery = queryName + " " + i;
      if (queries.getIndexForQuery(newQuery) == -1)
      { 
        return newQuery;
      } 
    } 
    return queryName;
  } 
 
  protected void validateState() 
  { 
    final DefaultComboBoxModel queries = getQueries();
    setQuerySelected(queries.getSelectedItem() != null);
 
    if (queries.getSelectedItem() == null)
    { 
      setPreviewPossible(false); 
      return; 
    } 
 
    final DataSetQuery o = (DataSetQuery) queries.getSelectedItem();
    if (o == null || StringUtils.isEmpty(o.getQueryName()))
    { 
      setPreviewPossible(false); 
      return; 
    } 
 
    setPreviewPossible(true); 
  } 
 
  public void clear() 
  { 
    queries.removeAllElements();
 
    setPreviewPossible(false); 
  } 
 
  public boolean isPreviewPossible() 
  { 
    return previewPossible;
  } 
 
  public void setPreviewPossible(final boolean previewPossible)
  { 
    final boolean oldPreviewPossible = this.previewPossible;
    this.previewPossible = previewPossible;
    propertyChangeSupport.firePropertyChange(PREVIEW_POSSIBLE, oldPreviewPossible, previewPossible);
  } 
 
  public void addPropertyChangeListener(final PropertyChangeListener listener)
  { 
    propertyChangeSupport.addPropertyChangeListener(listener);