Example usage for java.beans PropertyChangeEvent getNewValue

List of usage examples for java.beans PropertyChangeEvent getNewValue

Introduction

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

Prototype

public Object getNewValue() 

Source Link

Document

Gets the new value for the property, expressed as an Object.

Usage

From source file:org.pentaho.ui.xul.binding.DefaultBinding.java

protected PropertyChangeListener setupBinding(final Reference a, final String va, final Reference b,
        final String vb, final Direction dir) {
    if (a.get() == null || va == null) {
        handleException(new BindingException("source bean or property is null"));
    }/*from  w ww. ja  v  a 2  s  .  co  m*/
    if (!(a.get() instanceof XulEventSource)) {
        handleException(new BindingException(
                "Binding error, source object " + a.get() + " not a XulEventSource instance"));
    }
    if (b.get() == null || vb == null) {
        handleException(new BindingException("target bean or property is null"));
    }
    Method sourceGetMethod = BindingUtil.findGetMethod(a.get(), va);

    Class getterClazz = BindingUtil.getMethodReturnType(sourceGetMethod, a.get());
    getterMethods.push(sourceGetMethod);

    // find set method
    final Method targetSetMethod = BindingUtil.findSetMethod(b.get(), vb, getterClazz);

    // setup prop change listener to handle binding
    PropertyChangeListener listener = new PropertyChangeListener() {
        public void propertyChange(final PropertyChangeEvent evt) {
            final PropertyChangeListener cThis = this;
            if (evt.getPropertyName().equalsIgnoreCase(va)) {
                try {
                    Object targetObject = b.get();
                    if (targetObject == null) {
                        logger.debug("Binding target was Garbage Collected, removing propListener");
                        DefaultBinding.this.destroyBindings();
                        return;
                    }

                    Object value = doConversions(evt.getNewValue(), dir);
                    final Object finalVal = evaluateExpressions(value);

                    logger.debug("Setting val: " + finalVal + " on: " + targetObject);
                    targetSetMethod.invoke(targetObject, finalVal);

                } catch (Exception e) {
                    logger.debug(e);
                    handleException(new BindingException("Error invoking setter method ["
                            + targetSetMethod.getName() + "] on target: " + target.get(), e));
                }
            }
        }
    };
    ((XulEventSource) a.get()).addPropertyChangeListener(listener);

    return listener;
}

From source file:org.cubictest.ui.sections.IdentifierComposite.java

/**
 * The identifier has changed/*  w ww. j  a  v  a2  s.co m*/
 */
public void propertyChange(PropertyChangeEvent event) {
    if (!this.isDisposed()) {
        String eventName = event.getPropertyName();
        if (Identifier.VALUE.equals(eventName)) {
            value.setText((String) event.getNewValue());
        } else if (Identifier.ACTUAL.equals(eventName)) {
            //TODO
        } else if (Identifier.TYPE.equals(eventName)) {

        } else if (Identifier.MODERATOR.equals(eventName)) {
            moderator.removeSelectionListener(moderatorListener);
            setModerator((Moderator) event.getNewValue());
            moderator.addSelectionListener(moderatorListener);
        } else if (Identifier.PROBABILITY.equals(eventName)) {
            probability.removeSelectionListener(probabilityListener);
            setProbability((Integer) event.getNewValue());
            probability.addSelectionListener(probabilityListener);
        } else if (PageElement.DIRECT_EDIT_IDENTIFIER.equals(eventName)) {
            dirEdit.removeSelectionListener(dirEditListener);
            dirEdit.setSelection(pageElement.getDirectEditIdentifier().equals(identifier));
            dirEdit.addSelectionListener(dirEditListener);
        }
        refresh();
    }
}

From source file:com.codejumble.opentube.Main.java

/**
 * Checks if progress has changed and updates the download progress bar
 * value.//from  w  w w  .j  av a2s  .  co  m
 *
 * @param pce property
 */
@Override
public void propertyChange(PropertyChangeEvent pce) {
    if ("progress".equals(pce.getPropertyName())) {
        int progress = (Integer) pce.getNewValue();
        downloadProgressBar.setValue(progress);
    }
}

From source file:org.squidy.designer.zoom.ActionShape.java

@Override
public void initialize() {
    super.initialize();

    if (getProcessable() != null) {
        // Add property change listener that allows to start valve
        // processing this way.
        getProcessable().addStatusChangeListener(Processable.PROPERTY_PROCESSING, new PropertyChangeListener() {

            public void propertyChange(PropertyChangeEvent evt) {
                firePropertyChange(0, Processable.PROPERTY_PROCESSING, evt.getOldValue(), evt.getNewValue());
            }/*  w  w  w .j av a 2  s .c om*/
        });

        getProcessable().addStatusChangeListener(Processable.STATUS_PROCESSABLE_DELETED,
                new PropertyChangeListener() {

                    public void propertyChange(PropertyChangeEvent evt) {
                        if (Pipe.class.isAssignableFrom(evt.getOldValue().getClass()))
                            return;
                        removeFromParent();
                    }
                });

        getProcessable().addStatusChangeListener(Processable.PROPERTY_FAILURE_PUBLISH,
                new PropertyChangeListener() {

                    /*
                     * (non-Javadoc)
                     * 
                     * @see
                     * java.beans.PropertyChangeListener#propertyChange(
                     * java.beans.PropertyChangeEvent)
                     */
                    public void propertyChange(PropertyChangeEvent evt) {
                        Throwable e = (Throwable) evt.getNewValue();
                        publishFailure(e);
                    }
                });

        getProcessable().addStatusChangeListener(Processable.PROPERTY_FAILURE_RESOLVE,
                new PropertyChangeListener() {

                    /*
                     * (non-Javadoc)
                     * 
                     * @see
                     * java.beans.PropertyChangeListener#propertyChange(
                     * java.beans.PropertyChangeEvent)
                     */
                    public void propertyChange(PropertyChangeEvent evt) {
                        resolveFailure();

                        // for (Object o : getChildrenReference()) {
                        // if (o instanceof ZoomActionShape) {
                        // ((ZoomActionShape<?>) o).resolveFailure();
                        // }
                        // }
                    }
                });

        getProcessable().addStatusChangeListener(Processable.PROPERTY_NOTIFICATION,
                new PropertyChangeListener() {

                    /*
                     * (non-Javadoc)
                     * 
                     * @see
                     * java.beans.PropertyChangeListener#propertyChange(
                     * java.beans.PropertyChangeEvent)
                     */
                    public void propertyChange(PropertyChangeEvent evt) {
                        publishNotification(new TemporaryNotification(evt.getNewValue().toString()));
                    }
                });
    }
}

From source file:ru.zinin.redis.session.RedisManager.java

@Override
public void propertyChange(PropertyChangeEvent event) {
    log.trace(String.format("EXEC propertyChange(%s);", event));

    if (!(event.getSource() instanceof Context)) {
        return;/*from w  w  w.  j  a va 2s  .c o m*/
    }

    if (event.getPropertyName().equals("sessionTimeout")) {
        try {
            setMaxInactiveInterval((Integer) event.getNewValue() * 60);
        } catch (NumberFormatException e) {
            log.error(sm.getString("managerBase.sessionTimeout", event.getNewValue()));
        }
    }
}

From source file:edu.ku.brc.specify.config.FixAttachments.java

/**
 * @param resultsHashMap/*from   w ww.j a v  a  2s . co  m*/
 * @param tableHash
 * @param totalFiles
 */
private void doAttachmentRefCleanup(final HashMap<Integer, Vector<Object[]>> resultsHashMap,
        final HashMap<Integer, AttchTableModel> tableHash, final int totalFiles) {
    final int numAttachs = getNumberofBadAttachments();

    final String CNT = "CNT";
    final SwingWorker<Integer, Integer> worker = new SwingWorker<Integer, Integer>() {
        int filesCnt = 0;
        int errs = 0;

        @Override
        protected Integer doInBackground() throws Exception {
            try {
                for (int tblId : resultsHashMap.keySet()) {
                    DBTableInfo ti = DBTableIdMgr.getInstance().getInfoById(tblId);
                    AttchTableModel model = tableHash.get(tblId);
                    for (int r = 0; r < model.getRowCount(); r++) {
                        int attachId = model.getAttachmentId(r);
                        int attachJoinId = model.getAttachmentJoinId(r);

                        String sql = String.format("DELETE FROM %s WHERE %s = %d", ti.getName(),
                                ti.getIdColumnName(), attachJoinId);
                        int rv = BasicSQLUtils.update(sql);
                        if (rv == 1) {
                            rv = BasicSQLUtils
                                    .update("DELETE FROM attachment WHERE AttachmentID = " + attachId);
                            if (rv == 1) {
                                filesCnt++;
                            } else {
                                errs++;
                            }
                        } else {
                            errs++;
                        }

                        firePropertyChange(CNT, 0, (int) ((double) filesCnt / (double) totalFiles * 100.0));
                    }
                }

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

        @Override
        protected void done() {
            UIRegistry.clearSimpleGlassPaneMsg();
            UIRegistry.displayInfoMsgDlg(String.format("Attachments removed: %d / %d", filesCnt, numAttachs));

            if (errs > 0) {
                UIRegistry.displayErrorDlg(
                        String.format("There were %d errors when deleting the attachments.", errs));
            } else {
                if (getNumberofBadAttachments() == 0) {
                    AppPreferences.getGlobalPrefs().putBoolean("CHECK_ATTCH_ERR", false);
                }
            }
            super.done();
        }
    };

    final SimpleGlassPane glassPane = UIRegistry
            .writeSimpleGlassPaneMsg(String.format("Removing %d attachments.", numAttachs), 24);
    glassPane.setProgress(0);

    worker.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(final PropertyChangeEvent evt) {
            if (CNT.equals(evt.getPropertyName())) {
                glassPane.setProgress((Integer) evt.getNewValue());
            }
        }
    });

    worker.execute();
}

From source file:edu.ku.brc.specify.config.FixAttachments.java

/**
 * @param resultsHashMap/*from   w ww  .  j a v a2 s  .  co m*/
 * @param tableHash
 * @param totalFiles
 */
private void reattachFiles(final HashMap<Integer, Vector<Object[]>> resultsHashMap,
        final HashMap<Integer, AttchTableModel> tableHash, final int totalFiles) {
    final String CNT = "CNT";
    final SwingWorker<Integer, Integer> worker = new SwingWorker<Integer, Integer>() {
        int filesCnt = 0;

        @Override
        protected Integer doInBackground() throws Exception {
            DataProviderSessionIFace session = DataProviderFactory.getInstance().createSession();
            if (session != null) {
                try {
                    for (int tblId : resultsHashMap.keySet()) {
                        AttchTableModel model = tableHash.get(tblId);
                        int cnt = 0;
                        for (int r = 0; r < model.getRowCount(); r++) {
                            if (model.isRecoverable(r)) {
                                Thread.sleep(100);

                                session.beginTransaction();
                                Integer attachID = model.getAttachmentId(r);
                                Attachment attachment = session.get(Attachment.class, attachID);
                                AttachmentUtils.getAttachmentManager()
                                        .setStorageLocationIntoAttachment(attachment, false);
                                try {
                                    attachment.storeFile(true); // false means do not display an error dialog
                                    session.saveOrUpdate(attachment);
                                    session.commit();
                                    model.setRecovered(r, true);
                                    filesCnt++;

                                } catch (IOException ex) {
                                    session.rollback();
                                }
                            }
                            cnt++;
                            firePropertyChange(CNT, 0, (int) ((double) cnt / (double) totalFiles * 100.0));
                        }
                    }
                } catch (Exception ex) {
                    session.rollback();

                } finally {
                    session.close();
                }
            }
            return null;
        }

        @Override
        protected void done() {
            UIRegistry.clearSimpleGlassPaneMsg();
            UIRegistry.displayInfoMsgDlg(String.format("Files recovered: %d / %d", filesCnt, totalFiles));

            File file = produceSummaryReport(resultsHashMap, tableHash, totalFiles);
            if (file != null) {
                try {
                    AttachmentUtils.openFile(file);
                } catch (Exception e) {
                }
            }

            if (getNumberofBadAttachments() == 0) {
                AppPreferences.getGlobalPrefs().putBoolean("CHECK_ATTCH_ERR", true);
            }
            super.done();
        }
    };

    final SimpleGlassPane glassPane = UIRegistry
            .writeSimpleGlassPaneMsg(String.format("Recovering %d files.", totalFiles), 24);
    glassPane.setProgress(0);

    worker.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(final PropertyChangeEvent evt) {
            if (CNT.equals(evt.getPropertyName())) {
                glassPane.setProgress((Integer) evt.getNewValue());
            }
        }
    });

    worker.execute();
}

From source file:ome.formats.importer.gui.HistoryTable.java

public void propertyChange(PropertyChangeEvent e) {
    String prop = e.getPropertyName();
    if (prop.equals("QUICK_HISTORY"))
        getQuickHistory((Integer) e.getNewValue());
    if (prop.equals("date")) {
        getItemQuery(-1, getExperimenterID(), searchField.getText(), fromDate.getDate(), toDate.getDate());
    }//from ww w. j  a va2s.  com

}

From source file:it.cnr.icar.eric.client.ui.swing.BusinessQueryPanel.java

public void propertyChange(PropertyChangeEvent ev) {
    //System.err.println(ev);
    if (ev.getPropertyName().equals(ConceptsTreeDialog.PROPERTY_SELECTED_CONCEPTS)) {
        processSelectedConceptsChange(ev);
    } else if (ev.getPropertyName().equals(RegistryBrowser.PROPERTY_LOCALE)) {
        processLocaleChange((Locale) ev.getNewValue());
    }//from   w  w  w.  j  a  v  a 2s .c  o  m
}

From source file:edu.ucla.stat.SOCR.analyses.gui.AnovaOneWay.java

/** Implementation of PropertyChageListener.*/
public void propertyChange(PropertyChangeEvent e) {
    String propertyName = e.getPropertyName();

    System.err.println("From RegCorrAnal:: propertyName =" + propertyName + "!!!");

    if (propertyName.equals("DataUpdate")) {
        //update the local version of the dataTable by outside source
        dataTable = (JTable) (e.getNewValue());
        dataPanel.removeAll();//from   ww w.j  av a 2s  .  c  om
        dataPanel.add(new JScrollPane(dataTable));

        System.err.println("From RegCorrAnal:: data UPDATED!!!");
    }
}