Example usage for java.beans PropertyChangeEvent PropertyChangeEvent

List of usage examples for java.beans PropertyChangeEvent PropertyChangeEvent

Introduction

In this page you can find the example usage for java.beans PropertyChangeEvent PropertyChangeEvent.

Prototype

public PropertyChangeEvent(Object source, String propertyName, Object oldValue, Object newValue) 

Source Link

Document

Constructs a new PropertyChangeEvent .

Usage

From source file:org.eclipse.virgo.ide.runtime.internal.core.Server.java

protected void fireConfigurationChanged(String key, Object oldValue, Object newValue) {
    PropertyChangeEvent event = new PropertyChangeEvent(this, key, oldValue, newValue);
    for (PropertyChangeListener listener : listeners) {
        listener.propertyChange(event);/*from  w w  w  .  j ava 2s. c  o m*/
    }
}

From source file:com.interface21.beans.BeanWrapperImpl.java

/**
 * Convert the value to the required type (if necessary from a String).
 * Conversions from String to any type use the setAsText() method of
 * the PropertyEditor class. Note that a PropertyEditor must be registered
 * for this class for this to work. This is a standard Java Beans API.
 * A number of property editors are automatically registered by this class.
 * @param target target bean//from ww  w. j ava 2 s  .c o m
 * @param propertyName name of the property
 * @param oldValue previous value, if available. May be null.
 * @param newValue proposed change value.
 * @param requiredType type we must convert to
 * @throws BeansException if there is an internal error
 * @return new value, possibly the result of type convertion.
 */
public Object doTypeConversionIfNecessary(Object target, String propertyName, Object oldValue, Object newValue,
        Class requiredType) throws BeansException {
    // Only need to cast if value isn't null
    if (newValue != null) {
        // We may need to change the value of newValue
        // custom editor for this type?
        PropertyEditor pe = findCustomEditor(requiredType, propertyName);
        if ((pe != null || !requiredType.isAssignableFrom(newValue.getClass()))
                && (newValue instanceof String)) {
            if (logger.isDebugEnabled())
                logger.debug("Convert: String to " + requiredType);
            if (pe == null) {
                // no custom editor -> check BeanWrapper's default editors
                pe = (PropertyEditor) defaultEditors.get(requiredType);
                if (pe == null) {
                    // no BeanWrapper default editor -> check standard editors
                    pe = PropertyEditorManager.findEditor(requiredType);
                }
            }
            if (logger.isDebugEnabled())
                logger.debug("Using property editor [" + pe + "]");
            if (pe != null) {
                try {
                    pe.setAsText((String) newValue);
                    newValue = pe.getValue();
                } catch (IllegalArgumentException ex) {
                    throw new TypeMismatchException(
                            new PropertyChangeEvent(target, propertyName, oldValue, newValue), requiredType,
                            ex);
                }
            }
        }
    }
    return newValue;
}

From source file:org.ngrinder.recorder.ui.RecordingControlPanel.java

/**
 * Create "Start Recording" Button and attach the event handler.
 * /*w  ww. ja v a 2s. co m*/
 * @return created Button.
 */
private JToggleButton createRecordingButton() {
    JToggleButton button = decoratedToSimpleButton(new JToggleButton("Start Recording"));
    button.setText("Start Recording");
    button.setSelected(false);
    button.setMinimumSize(new Dimension(100, 30));
    button.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JToggleButton button = (JToggleButton) e.getSource();
            if (button.isSelected()) {
                button.setText("Stop Recording");
                button.setSelected(true);
                messageBus.getPublisher(Topics.START_RECORDING).propertyChange(new PropertyChangeEvent(
                        RecordingControlPanel.this, "Start Recording", null, getFilteredFileTypes()));
            } else {
                if (!stopConfirm()) {
                    button.setSelected(true);
                    return;
                }
                messageBus.getPublisher(Topics.STOP_RECORDING)
                        .propertyChange(new PropertyChangeEvent(RecordingControlPanel.this, "Stop Recording",
                                null, Pair.of(getFilteredFileTypes(), getGenerationOption())));
                button.setText("Start Recording");
            }
        }
    });
    return button;
}

From source file:de.schlichtherle.xml.GenericCertificate.java

/**
 * /*from w w  w .j  av  a2  s .co  m*/
 * Verifies the digital signature of the encoded content in this
 * certificate and locks it.
 * <p>
 * Please note the following:
 * <ul>
 * <li>This method will throw a <tt>PropertyVetoException</tt> if this
 *     certificate is already locked, i.e. if it has been signed or
 *     verified before.</li>
 * <li>Because this method locks this certificate, a subsequent call to
 *     {@link #sign(Object, PrivateKey, Signature)} or
 *     {@link #verify(PublicKey, Signature)} is redundant
 *     and will throw a <tt>PropertyVetoException</tt>.
 *     Use {@link #isLocked()} to detect whether a
 *     generic certificate has been successfuly signed or verified before
 *     or call {@link #getContent()} and expect an 
 *     Exception to be thrown if it hasn't.</li>
 * <li>There is no way to unlock this certificate.
 *     Call the copy constructor of {@link GenericCertificate} if you
 *     need an unlocked copy of the certificate.</li>
 * </ul>
 * 
 * @param verificationKey The public key for verification
 *        - may <em>not</em> be <tt>null</tt>.
 * @param verificationEngine The signature verification engine
 *        - may <em>not</em> be <tt>null</tt>.
 * 
 * @throws NullPointerException If the preconditions for the parameters
 *         do not hold.
 * @throws GenericCertificateIsLockedException If this certificate is
 *         already locked by signing or verifying it before.
 *         Note that this is actually a subclass of
 *         {@link PropertyVetoException}.
 * @throws PropertyVetoException If locking the certifificate (and thus
 *         verifying the object) is vetoed by any listener.
 * @throws InvalidKeyException If the verification key is invalid.
 * @throws SignatureException If signature verification failed.
 * @throws GenericCertificateIntegrityException If the integrity of this
 *         certificate has been compromised.
 */
public synchronized final void verify(final PublicKey verificationKey, final Signature verificationEngine)
        throws NullPointerException, GenericCertificateIsLockedException, PropertyVetoException,
        InvalidKeyException, SignatureException, GenericCertificateIntegrityException {
    // Check parameters.
    if (verificationKey == null)
        throw new NullPointerException("verificationKey");
    if (verificationEngine == null)
        throw new NullPointerException("verificationEngine");

    // Check lock status.
    final PropertyChangeEvent evt = new PropertyChangeEvent(this, "locked", Boolean.valueOf(isLocked()),
            Boolean.TRUE); // NOI18N
    if (isLocked())
        throw new GenericCertificateIsLockedException(evt);

    // Notify vetoable listeners and give them a chance to veto.
    fireVetoableChange(evt);

    try {
        // Init the byte encoded object.
        final byte[] beo = getEncoded().getBytes(XML_CHARSET);

        // Verify the byte encoded object.
        verificationEngine.initVerify(verificationKey);
        verificationEngine.update(beo);
        final byte[] b64ds = Base64.decodeBase64(getSignature().getBytes(BASE64_CHARSET));
        if (!verificationEngine.verify(b64ds))
            throw new GenericCertificateIntegrityException();

        // Reset signature parameters.
        setSignatureAlgorithm(verificationEngine.getAlgorithm());
        setSignatureEncoding(SIGNATURE_ENCODING);
    } catch (UnsupportedEncodingException cannotHappen) {
        throw new AssertionError(cannotHappen);
    }

    // Lock this certificate and notify property change listeners.
    this.locked = true;
    firePropertyChange(evt);
}

From source file:org.opennms.netmgt.poller.remote.support.ScanReportPollerFrontEnd.java

private void firePropertyChange(final String propertyName, final Object oldValue, final Object newValue) {
    if (nullSafeEquals(oldValue, newValue)) {
        // no change no event
        return;//from  ww  w  . ja  v a  2  s. com

    }
    final PropertyChangeEvent event = new PropertyChangeEvent(this, propertyName, oldValue, newValue);

    for (final PropertyChangeListener listener : m_propertyChangeListeners) {
        listener.propertyChange(event);
    }
}

From source file:com.jaspersoft.studio.server.ServerManager.java

public static void selectIfExists(final IProgressMonitor monitor, MServerProfile sp, MResource mres) {
    if (mres.getParent() instanceof MServerProfile) {
        try {/*from w  w w . j ava2s .  c om*/
            WSClientHelper.connectGetData(sp, monitor);
            propertyChangeSupport.firePropertyChange(new PropertyChangeEvent(sp, SERVERPROFILE, null, sp));
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else {
        final String puri = ((MResource) mres.getParent()).getValue().getUriString();
        final String uri = mres.getValue().getUriString();
        if (ModelUtils.isEmpty(sp))
            try {
                WSClientHelper.connectGetData(sp, monitor);
            } catch (Exception e) {
                e.printStackTrace();
                return;
            }
        new ModelVisitor<MResource>(sp) {

            @Override
            public boolean visit(INode n) {
                if (n instanceof MResource) {
                    MResource r = (MResource) n;
                    if (r.getValue().getUriString().equals(puri)) {
                        for (INode cn : r.getChildren())
                            if (cn instanceof MResource
                                    && ((MResource) cn).getValue().getUriString().equals(uri))
                                doRefresh((MResource) cn, monitor);
                        doRefresh(r, monitor);
                    }
                }
                if (monitor.isCanceled())
                    stop();
                return true;
            }

            private void doRefresh(MResource r, IProgressMonitor monitor) {
                try {
                    WSClientHelper.refreshResource(r, monitor);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                stop();
            }

        };
    }
}

From source file:org.tinygroup.weblayer.webcontext.parser.util.BeanWrapperImpl.java

/**
 * Convert the given value for the specified property to the latter's type.
 * <p>This method is only intended for optimizations in a BeanFactory.
 * Use the <code>convertIfNecessary</code> methods for programmatic conversion.
 * @param value the value to convert/*from  w  ww .  j  av a  2  s .  c  om*/
 * @param propertyName the target property
 * (note that nested or indexed properties are not supported here)
 * @return the new value, possibly the result of type conversion
 * @throws TypeMismatchException if type conversion failed
 */
public Object convertForProperty(Object value, String propertyName) throws TypeMismatchException {
    PropertyDescriptor pd = getCachedIntrospectionResults().getPropertyDescriptor(propertyName);
    if (pd == null) {
        throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName,
                "No property '" + propertyName + "' found");
    }
    try {
        return this.typeConverterDelegate.convertIfNecessary(null, value, pd);
    } catch (IllegalArgumentException ex) {
        PropertyChangeEvent pce = new PropertyChangeEvent(this.rootObject, this.nestedPath + propertyName, null,
                value);
        throw new TypeMismatchException(pce, pd.getPropertyType(), ex);
    }
}

From source file:edu.ku.brc.specify.tasks.subpane.ESResultsTablePanel.java

/**
 * Constructor of a results "table" which is really a panel
 * @param esrPane the parent//www  .j  a v a 2  s. co m
 * @param erTableInfo the info describing the results
 * @param installServices indicates whether services should be installed
 * @param isExpandedAtStartUp enough said
 * @param inclCloseBtn whether to include the close button on the bar
 */
public ESResultsTablePanel(final ExpressSearchResultsPaneIFace esrPane, final QueryForIdResultsIFace results,
        final boolean installServices, final boolean isExpandedAtStartUp, final boolean inclCloseBtn) {
    super(new BorderLayout());

    this.esrPane = esrPane;
    this.results = results;
    this.bannerColor = results.getBannerColor();
    this.isEditable = results.isEditingEnabled();

    table = new JTable();
    table.setShowVerticalLines(false);
    table.setRowSelectionAllowed(true);
    table.setSelectionMode(results.isMultipleSelection() ? ListSelectionModel.MULTIPLE_INTERVAL_SELECTION
            : ListSelectionModel.SINGLE_SELECTION);

    setBackground(table.getBackground());

    if (isEditable) {
        addContextMenu();
    }

    topTitleBar = new GradiantLabel(results.getTitle(), SwingConstants.LEFT);
    topTitleBar.setBGBaseColor(bannerColor);
    topTitleBar.setTextColor(Color.WHITE);
    topTitleBar.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {

            if (e.getClickCount() == 2) {
                expandBtn.doClick();
            }
        }
    });

    String description = results.getDescription();
    if (StringUtils.isNotEmpty(description)) {
        topTitleBar.setToolTipText(description);
    }

    expandBtn = new TriangleButton();
    expandBtn.setToolTipText(getResourceString("CollapseTBL"));
    expandBtn.setForeground(bannerColor);
    expandBtn.setTextColor(Color.WHITE);

    showTopNumEntriesBtn = new GradiantButton(
            String.format(getResourceString("ShowTopEntries"), new Object[] { topNumEntries }));
    showTopNumEntriesBtn.setForeground(bannerColor);
    showTopNumEntriesBtn.setTextColor(Color.WHITE);
    showTopNumEntriesBtn.setVisible(false);
    showTopNumEntriesBtn.setCursor(handCursor);

    List<ServiceInfo> services = installServices ? getServices() : null;

    //System.out.println("["+tableInfo.getTableId()+"]["+services.size()+"]");
    StringBuffer colDef = new StringBuffer("p,0px,p:g,0px,p,0px,");
    int numCols = (installServices ? services.size() : 0) + (inclCloseBtn ? 1 : 0);
    colDef.append(UIHelper.createDuplicateJGoodiesDef("p", "0px", numCols)); // add additional col defs for services

    PanelBuilder builder = new PanelBuilder(new FormLayout(colDef.toString(), "f:p:g"));
    CellConstraints cc = new CellConstraints();

    int col = 1;
    builder.add(expandBtn, cc.xy(col, 1));
    col += 2;

    builder.add(topTitleBar, cc.xy(col, 1));
    col += 2;

    builder.add(showTopNumEntriesBtn, cc.xy(col, 1));
    col += 2;

    if (installServices && services.size() > 0) {
        serviceBtns = new Hashtable<ServiceInfo, JButton>();

        //IconManager.IconSize size = IconManager.
        int iconSize = AppPreferences.getLocalPrefs().getInt("banner.icon.size", 20);
        // Install the buttons on the banner with available services
        for (ServiceInfo serviceInfo : services) {
            GradiantButton btn = new GradiantButton(serviceInfo.getIcon(iconSize)); // XXX PREF
            btn.setToolTipText(serviceInfo.getTooltip());
            btn.setForeground(bannerColor);
            builder.add(btn, cc.xy(col, 1));
            ESTableAction esta = new ESTableAction(serviceInfo.getCommandAction(), table,
                    serviceInfo.getTooltip());
            esta.setProperty("gridtitle", results.getTitle());
            btn.addActionListener(esta);
            serviceBtns.put(serviceInfo, btn);
            col += 2;
        }
    }

    GradiantButton closeBtn = null;
    if (inclCloseBtn) {
        closeBtn = new GradiantButton(IconManager.getIcon("Close"));
        closeBtn.setToolTipText(getResourceString("ESCloseTable"));
        closeBtn.setForeground(bannerColor);
        closeBtn.setRolloverEnabled(true);
        closeBtn.setRolloverIcon(IconManager.getIcon("CloseHover"));
        closeBtn.setPressedIcon(IconManager.getIcon("CloseHover"));
        builder.add(closeBtn, cc.xy(col, 1));
        col += 2;
    }

    add(builder.getPanel(), BorderLayout.NORTH);

    tablePane = new JPanel(new BorderLayout());
    setupTablePane();

    if (isEditable) {
        //delRSItems = UIHelper.createI18NButton("RESTBL_DEL_ITEMS");
        delRSItems = UIHelper.createIconBtn("DelRec", "ESDelRowsTT", null);
        delRSItems.addActionListener(createRemoveItemAL());
        delRSItems.setEnabled(false);

        table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
            public void valueChanged(ListSelectionEvent e) {
                if (!e.getValueIsAdjusting()) {
                    delRSItems.setEnabled(table.getSelectedRowCount() > 0);
                }
            }
        });
    }

    add(tablePane, BorderLayout.CENTER);

    moveToRSCmd = new DragSelectedRowsBtn(IconManager.getIcon("Record_Set", IconManager.IconSize.Std16));

    if (installServices) {
        PanelBuilder bottomBar = new PanelBuilder(
                new FormLayout("4px,p,4px,p,4px,p," + (delRSItems != null ? "4px,p," : "") + "f:p:g", "p"));
        bottomBar.add(moveToRSCmd, cc.xy(2, 1));
        bottomBar.add(selectAllBtn, cc.xy(4, 1));
        bottomBar.add(deselectAllBtn, cc.xy(6, 1));
        if (delRSItems != null) {
            bottomBar.add(delRSItems, cc.xy(8, 1));
        }
        botBtnPanel = bottomBar.getPanel();

        deselectAllBtn.setEnabled(false);
        selectAllBtn.setEnabled(true);
        moveToRSCmd.setEnabled(true);

        deselectAllBtn.setToolTipText(getResourceString("SELALLTOOLTIP"));
        selectAllBtn.setToolTipText(getResourceString("DESELALLTOOLTIP"));
        moveToRSCmd.setToolTipText(getResourceString("MOVEROWSTOOLTIP"));

        selectAllBtn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                table.selectAll();
            }
        });

        deselectAllBtn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                table.clearSelection();
            }
        });

        moveToRSCmd.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                RecordSetIFace src = (RecordSetIFace) moveToRSCmd.getData();
                CommandDispatcher
                        .dispatch(new CommandAction(RecordSetTask.RECORD_SET, "AskForNewRS", src, null, null));
            }
        });

        add(botBtnPanel, BorderLayout.SOUTH);

    } else {
        botBtnPanel = null;
    }

    expandBtn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            expandTable(false);
        }
    });

    if (!isExpandedAtStartUp) {
        expandTable(true);
    }

    showTopNumEntriesBtn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            morePanel.setVisible(true);
            showTopNumEntriesBtn.setVisible(false);
            showingAllRows = false;
            setDisplayRows(rowCount, topNumEntries);

            // If it is collapsed then expand it
            if (!expandBtn.isDown()) {
                tablePane.setVisible(true);
                expandBtn.setDown(true);
            }

            // Make sure the layout is updated
            invalidate();
            doLayout();
            esrPane.revalidateScroll();
        }
    });

    if (closeBtn != null) {
        closeBtn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        removeMe();
                    }
                });

            }
        });
    }

    ResultSetTableModel rsm = createModel();
    rsm.setPropertyListener(this);
    resultSetTableModel = rsm;
    table.setRowSorter(new TableRowSorter<ResultSetTableModel>(resultSetTableModel));

    table.setRowSelectionAllowed(true);
    table.setModel(rsm);

    configColumns();

    rowCount = rsm.getRowCount();
    if (rowCount > topNumEntries + 2) {
        buildMorePanel();
        setDisplayRows(rowCount, topNumEntries);
    } else {
        setDisplayRows(rowCount, Integer.MAX_VALUE);
    }

    invalidate();
    doLayout();
    UIRegistry.forceTopFrameRepaint();

    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                if (botBtnPanel != null) {
                    deselectAllBtn.setEnabled(table.getSelectedRowCount() > 0);
                    selectAllBtn.setEnabled(table.getSelectedRowCount() != table.getRowCount());
                    moveToRSCmd.setEnabled(table.getSelectedRowCount() > 0);
                }
            }
            if (propChangeListener != null) {
                if (!e.getValueIsAdjusting()) {
                    propChangeListener.propertyChange(
                            new PropertyChangeEvent(this, "selection", table.getSelectedRowCount(), 0));

                } else {
                    propChangeListener.propertyChange(
                            new PropertyChangeEvent(this, "selection", table.getSelectedRowCount(), 0));
                }
            }
        }
    });

    table.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
            //synchronized (((JTable)e.getSource()).getTreeLock()) 
            //{
            doDoubleClickOnRow(e);
            //}
        }
    });

    // Horizontal Alignment is set later
    TableColumnModel tableColModel = table.getColumnModel();
    for (int i = 0; i < tableColModel.getColumnCount(); i++) {
        tableColModel.getColumn(i).setCellRenderer(new BiColorTableCellRenderer());
    }
}

From source file:edu.ku.brc.specify.ui.db.ResultSetTableModel.java

@Override
//@SuppressWarnings("null")
public synchronized void exectionDone(final SQLExecutionProcessor process, final ResultSet resultSet) {
    if (statusBar != null) {
        statusBar.incrementValue(getClass().getSimpleName());
    }//from   w  w w  .  ja  v a2 s.  c  om

    if (resultSet == null || results == null) {
        log.error("The " + (resultSet == null ? "resultSet" : "results") + " is null.");
        if (propertyListener != null) {
            propertyListener.propertyChange(new PropertyChangeEvent(this, "rowCount", null, 0));
        }
        return;
    }

    List<ERTICaptionInfo> captions = results.getVisibleCaptionInfo();

    // This can do one of two things:
    // 1) Take multiple columns and create an object and use a DataObjectFormatter to format the object.
    // 2) Table multiple objects that were derived from the columns and roll those up into a single column's value.
    //    This happens when you get back rows of info where part of the columns are duplicated because you really
    //    want those value to be put into a single column.
    //
    // Step One - Is to figure out what type of object needs to be created and what the Columns are 
    //            that need to be set into the object so the dataObjFormatter can do its job.
    //
    // Step Two - If the objects are being aggregated then the object created from the columns are added to a List
    //            and then last formatted as an "aggregation"

    try {
        if (resultSet.next()) {
            ResultSetMetaData metaData = resultSet.getMetaData();

            // Composite
            boolean hasCompositeObj = false;
            DataObjSwitchFormatter dataObjFormatter = null;
            UIFieldFormatterIFace formatter = null;
            Object compObj = null;

            // Aggregates
            ERTICaptionInfo aggCaption = null;
            ERTICaptionInfo compositeCaption = null;
            Vector<Object> aggList = null;
            DataObjectSettable aggSetter = null;
            Stack<Object> aggListRecycler = null;

            DataObjectSettable dataSetter = null; // data getter for Aggregate or the Subclass

            // Loop through the caption to figure out what columns will be displayed.
            // Watch for Captions with an Aggregator or Composite 
            numColumns = captions.size();
            for (ERTICaptionInfo caption : captions) {
                colNames.addElement(caption.getColLabel());

                int inx = caption.getPosIndex() + 1;
                //log.debug(metaData.getColumnClassName(inx));
                Class<?> cls = null;
                try {
                    cls = Class.forName(metaData.getColumnClassName(inx));
                    if (cls == Calendar.class || cls == java.sql.Date.class || cls == Date.class) {
                        cls = String.class;
                    }
                } catch (SQLException ex) {
                    cls = String.class;
                }
                classNames.addElement(cls);
                caption.setColClass(cls);

                if (caption.getAggregatorName() != null) {
                    //log.debug("The Agg is ["+caption.getAggregatorName()+"] "+caption.getColName());

                    // Alright we have an aggregator
                    aggList = new Vector<Object>();
                    aggListRecycler = new Stack<Object>();
                    aggCaption = caption;
                    aggSetter = DataObjectSettableFactory.get(aggCaption.getAggClass().getName(),
                            FormHelper.DATA_OBJ_SETTER);

                    // Now check to see if we are aggregating the this type of object or a child object of this object
                    // For example Collectors use an Agent as part of the aggregation
                    if (aggCaption.getSubClass() != null) {
                        dataSetter = DataObjectSettableFactory.get(aggCaption.getSubClass().getName(),
                                FormHelper.DATA_OBJ_SETTER);
                    } else {
                        dataSetter = aggSetter;
                    }

                } else if (caption.getColInfoList() != null) {
                    formatter = caption.getUiFieldFormatter();
                    if (formatter != null) {
                        compositeCaption = caption;
                    } else {
                        // OK, now aggregation but we will be rolling up multiple columns into a single object for formatting
                        // We need to get the formatter to see what the Class is of the object
                        hasCompositeObj = true;
                        aggCaption = caption;
                        dataObjFormatter = caption.getDataObjFormatter();
                        if (dataObjFormatter != null) {
                            if (dataObjFormatter.getDataClass() != null) {
                                aggSetter = DataObjectSettableFactory.get(
                                        dataObjFormatter.getDataClass().getName(),
                                        "edu.ku.brc.af.ui.forms.DataSetterForObj");
                            } else {
                                log.error("formatterObj.getDataClass() was null for " + caption.getColName());
                            }
                        } else {
                            log.error("DataObjFormatter was null for " + caption.getColName());
                        }
                    }

                }
                //colNames.addElement(metaData.getColumnName(i));
                //System.out.println("**************** " + caption.getColLabel()+ " "+inx+ " " + caption.getColClass().getSimpleName());
            }

            // aggCaption will be non-null for both a Aggregate AND a Composite
            if (aggCaption != null) {
                // Here we need to dynamically discover what the column indexes are that we to grab
                // in order to set them into the created data object
                for (ERTICaptionInfo.ColInfo colInfo : aggCaption.getColInfoList()) {
                    for (int i = 0; i < metaData.getColumnCount(); i++) {
                        String colName = StringUtils.substringAfterLast(colInfo.getColumnName(), ".");
                        if (colName.equalsIgnoreCase(metaData.getColumnName(i + 1))) {
                            colInfo.setPosition(i);
                            break;
                        }
                    }
                }

                // Now check to see if there is an Order Column because the Aggregator 
                // might need it for sorting the Aggregation
                String ordColName = aggCaption.getOrderCol();
                if (StringUtils.isNotEmpty(ordColName)) {
                    String colName = StringUtils.substringAfterLast(ordColName, ".");
                    //log.debug("colName ["+colName+"]");
                    for (int i = 0; i < metaData.getColumnCount(); i++) {
                        //log.debug("["+colName+"]["+metaData.getColumnName(i+1)+"]");
                        if (colName.equalsIgnoreCase(metaData.getColumnName(i + 1))) {
                            aggCaption.setOrderColIndex(i);
                            break;
                        }
                    }
                    if (aggCaption.getOrderColIndex() == -1) {
                        log.error("Agg Order Column Index wasn't found [" + ordColName + "]");
                    }
                }
            }

            if (ids == null) {
                ids = new Vector<Integer>();
            } else {
                ids.clear();
            }

            // Here is the tricky part.
            // When we are doing a Composite we are just taking multiple columns and 
            // essentially replace them with a single value from the DataObjFormatter
            //
            // But when doing an Aggregation we taking several rows and rolling them up into a single value.
            // so this code knows when it is doing an aggregation, so it knows to only add a new row to the display-able
            // results when primary id changes.

            DataObjFieldFormatMgr dataObjMgr = DataObjFieldFormatMgr.getInstance();
            Vector<Object> row = null;
            boolean firstTime = true;
            int prevId = Integer.MAX_VALUE; // really can't assume any value but will choose Max

            int numCols = resultSet.getMetaData().getColumnCount();
            do {
                int id = resultSet.getInt(1);
                //log.debug("id: "+id+"  prevId: "+prevId);

                // Remember aggCaption is used by both a Aggregation and a Composite
                if (aggCaption != null && !hasCompositeObj) {
                    if (firstTime) {
                        prevId = id;
                        row = new Vector<Object>();
                        firstTime = false;
                        cache.add(row);
                        ids.add(id);

                    } else if (id != prevId) {
                        //log.debug("Agg List len: "+aggList.size());

                        if (row != null && aggList != null) {
                            int aggInx = captions.indexOf(aggCaption);
                            row.remove(aggInx);
                            row.insertElementAt(dataObjMgr.aggregate(aggList, aggCaption.getAggClass()),
                                    aggInx);

                            if (aggListRecycler != null) {
                                aggListRecycler.addAll(aggList);
                            }
                            aggList.clear();

                            row = new Vector<Object>();
                            cache.add(row);
                            ids.add(id);
                        }
                        prevId = id;

                    } else if (row == null) {
                        row = new Vector<Object>();
                        cache.add(row);
                        ids.add(id);
                    }
                } else {
                    row = new Vector<Object>();
                    cache.add(row);
                    ids.add(id);
                }

                // Now for each Caption column get a value
                for (ERTICaptionInfo caption : captions) {
                    int posIndex = caption.getPosIndex();
                    if (caption == aggCaption) // Checks to see if we need to take multiple columns and make one column
                    {
                        if (hasCompositeObj) // just doing a Composite
                        {
                            if (aggSetter != null && row != null && dataObjFormatter != null) {
                                if (compObj == null) {
                                    compObj = aggCaption.getAggClass().newInstance();
                                }

                                for (ERTICaptionInfo.ColInfo colInfo : aggCaption.getColInfoList()) {
                                    setField(aggSetter, compObj, colInfo.getFieldName(),
                                            colInfo.getFieldClass(), resultSet, colInfo.getPosition());
                                }
                                row.add(DataObjFieldFormatMgr.getInstance().format(compObj,
                                        compObj.getClass()));

                            } else if (formatter != null) {
                                int len = compositeCaption.getColInfoList().size();
                                Object[] val = new Object[len];
                                int i = 0;
                                for (ERTICaptionInfo.ColInfo colInfo : compositeCaption.getColInfoList()) {
                                    int colInx = colInfo.getPosition() + posIndex + 1;
                                    if (colInx < numCols) {
                                        val[i++] = resultSet.getObject(colInx);
                                    } else {
                                        //val[i++] = resultSet.getObject(posIndex+1);
                                        val[i++] = "(Missing Data)";
                                    }
                                }
                                row.add(formatter.formatToUI(val));

                            } else {
                                log.error("Aggregator is null! [" + aggCaption.getAggregatorName()
                                        + "] or row or aggList");
                            }
                        } else if (aggSetter != null && row != null && aggList != null) // Doing an Aggregation
                        {
                            Object aggObj;
                            if (aggListRecycler.size() == 0) {
                                aggObj = aggCaption.getAggClass().newInstance();
                            } else {
                                aggObj = aggListRecycler.pop();
                            }
                            Object aggSubObj = aggCaption.getSubClass() != null
                                    ? aggCaption.getSubClass().newInstance()
                                    : null;
                            aggList.add(aggObj);

                            //@SuppressWarnings("unused")
                            //DataObjAggregator aggregator = DataObjFieldFormatMgr.getInstance().getAggregator(aggCaption.getAggregatorName());
                            //log.debug(" aggCaption.getOrderColIndex() "+ aggCaption.getOrderColIndex());

                            //aggSetter.setFieldValue(aggObj, aggregator.getOrderFieldName(), resultSet.getObject(aggCaption.getOrderColIndex() + 1));

                            Object dataObj;
                            if (aggSubObj != null) {
                                aggSetter.setFieldValue(aggObj, aggCaption.getSubClassFieldName(), aggSubObj);
                                dataObj = aggSubObj;
                            } else {
                                dataObj = aggObj;
                            }

                            for (ERTICaptionInfo.ColInfo colInfo : aggCaption.getColInfoList()) {
                                setField(dataSetter, dataObj, colInfo.getFieldName(), colInfo.getFieldClass(),
                                        resultSet, colInfo.getPosition());
                            }
                            row.add("PlaceHolder");

                        } else if (aggSetter == null || aggList == null) {
                            log.error("Aggregator is null! [" + aggCaption.getAggregatorName() + "] or aggList["
                                    + aggList + "]");
                        }

                    } else if (row != null) {
                        if (caption.getColName() == null && caption.getColInfoList().size() > 0) {
                            int len = caption.getColInfoList().size();
                            Object[] val = new Object[len];
                            for (int i = 0; i < caption.getColInfoList().size(); i++) {
                                int inx = posIndex + 1 + i;
                                val[i] = caption.processValue(resultSet.getObject(inx));
                            }
                            row.add(caption.getUiFieldFormatter().formatToUI(val));
                            //col += caption.getColInfoList().size() - 1;

                        } else {
                            Object obj = caption.processValue(resultSet.getObject(posIndex + 1));
                            row.add(obj);
                        }
                    }
                }

            } while (resultSet.next());

            // We were always setting the rolled up data when the ID changed
            // but on the last row we need to do it here manually (so to speak)
            if (aggCaption != null && aggList != null && aggList.size() > 0 && row != null) {
                int aggInx = captions.indexOf(aggCaption);
                row.remove(aggInx);
                String colStr;
                if (StringUtils.isNotEmpty(aggCaption.getAggregatorName())) {
                    colStr = DataObjFieldFormatMgr.getInstance().aggregate(aggList,
                            aggCaption.getAggregatorName());

                } else {
                    colStr = DataObjFieldFormatMgr.getInstance().aggregate(aggList, aggCaption.getAggClass());
                }
                row.insertElementAt(colStr, aggInx);
                aggList.clear();
                aggListRecycler.clear();
            }

            fireTableStructureChanged();
            fireTableDataChanged();
        }

    } catch (Exception ex) {
        ex.printStackTrace();
    }

    if (propertyListener != null) {
        propertyListener
                .propertyChange(new PropertyChangeEvent(this, "rowCount", null, new Integer(cache.size())));
    }
}

From source file:com.jaspersoft.studio.server.WSClientHelper.java

public static void fireResourceChanged(final MResource res) {
    Display.getDefault().syncExec(new Runnable() {

        public void run() {
            ServerManager.getPropertyChangeSupport()
                    .firePropertyChange(new PropertyChangeEvent(res, "MODEL", null, res));
        }//from  www .j a  v a2s.  c om
    });
}