List of usage examples for java.beans PropertyChangeEvent PropertyChangeEvent
public PropertyChangeEvent(Object source, String propertyName, Object oldValue, Object newValue)
From source file:edu.ku.brc.af.core.db.MySQLBackupService.java
/** * @param databaseName//from w w w . j av a 2s.c om * @param restoreFilePath * @param glassPane * @param completionMsgKey */ protected boolean doRestoreInBackground(final String databaseName, final String restoreFilePath, final SimpleGlassPane glassPane, final String completionMsgKey, final PropertyChangeListener pcl, final boolean doSynchronously) { AppPreferences remotePrefs = AppPreferences.getLocalPrefs(); final String mysqlLoc = remotePrefs.get(MYSQL_LOC, getDefaultMySQLLoc()); getNumberofTables(); SynchronousWorker backupWorker = new SynchronousWorker() { long dspMegs = 0; long fileSize = 0; /* (non-Javadoc) * @see javax.swing.SwingWorker#doInBackground() */ @Override protected Integer doInBackground() throws Exception { FileInputStream input = null; try { String userName = itUsername != null ? itUsername : DBConnection.getInstance().getUserName(); String password = itPassword != null ? itPassword : DBConnection.getInstance().getPassword(); String port = DatabaseDriverInfo.getDriver(DBConnection.getInstance().getDriverName()) .getPort(); String server = DBConnection.getInstance().getServerName(); String cmdLine = String.format("%s -u %s --password=%s --host=%s %s %s", mysqlLoc, userName, password, server, (port != null ? ("--port=" + port) : ""), databaseName); Vector<String> args = new Vector<String>(); args.add(mysqlLoc); args.add("--user=" + userName); args.add("--password=" + password); args.add("--host=" + server); if (port != null) { args.add("--port=" + port); } args.add(databaseName); Process process = Runtime.getRuntime().exec(args.toArray(new String[0])); Thread.sleep(100); OutputStream out = process.getOutputStream(); // wait as long it takes till the other process has prompted. try { File inFile = new File(restoreFilePath); fileSize = inFile.length(); //System.out.println(fileSize); double oneMB = (1024.0 * 1024.0); double threshold = fileSize < (oneMB * 4) ? 8192 * 8 : oneMB; long totalBytes = 0; dspMegs = 0; input = new FileInputStream(inFile); try { byte[] bytes = new byte[8192 * 4]; do { int numBytes = input.read(bytes, 0, bytes.length); totalBytes += numBytes; if (numBytes > 0) { out.write(bytes, 0, numBytes); long megs = (long) (totalBytes / threshold); if (megs != dspMegs) { dspMegs = megs; firePropertyChange(MEGS, dspMegs, (int) ((100.0 * totalBytes) / fileSize)); } } else { break; } } while (true); } finally { input.close(); } } catch (IOException ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); //edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(MySQLBackupService.class, ex); ex.printStackTrace(); errorMsg = ex.toString(); UIRegistry.showLocalizedError("MySQLBackupService.EXCP_RS"); } catch (Exception ex) { ex.printStackTrace(); if (pcl != null) { pcl.propertyChange(new PropertyChangeEvent(MySQLBackupService.this, ERROR, 0, 1)); } } setProgress(100); out.flush(); out.close(); BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream())); String line = null; while ((line = in.readLine()) != null) { //System.err.println(line); } in = new BufferedReader(new InputStreamReader(process.getErrorStream())); StringBuilder sb = new StringBuilder(); while ((line = in.readLine()) != null) { if (line.startsWith("ERR")) { sb.append(line); sb.append("\n"); } } errorMsg = sb.toString(); } catch (Exception ex) { ex.printStackTrace(); errorMsg = ex.toString(); if (pcl != null) { pcl.propertyChange(new PropertyChangeEvent(MySQLBackupService.this, ERROR, 0, 1)); } } return null; } @Override protected void done() { super.done(); JStatusBar statusBar = UIRegistry.getStatusBar(); if (statusBar != null) { statusBar.setProgressDone(STATUSBAR_NAME); } if (glassPane != null) { UIRegistry.clearSimpleGlassPaneMsg(); } if (StringUtils.isNotEmpty(errorMsg)) { UIRegistry.showError(errorMsg); } if (statusBar != null) { statusBar.setText(UIRegistry.getLocalizedMessage(completionMsgKey, dspMegs)); } if (pcl != null) { pcl.propertyChange(new PropertyChangeEvent(MySQLBackupService.this, DONE, 0, 1)); } } }; if (glassPane != null) { glassPane.setProgress(0); } backupWorker.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(final PropertyChangeEvent evt) { if (MEGS.equals(evt.getPropertyName()) && glassPane != null) { int value = (Integer) evt.getNewValue(); if (value < 100) { glassPane.setProgress((Integer) evt.getNewValue()); } else { glassPane.setProgress(100); } } } }); if (doSynchronously) { return backupWorker.doWork(); } backupWorker.execute(); return true; }
From source file:com.toolsverse.mvc.model.ModelImpl.java
/** * Sets the new attribute value. Notifies view about the change. * * @param attributeName the attribute name * @param newValue the new value//from w ww. j ava2 s . c om */ public void setAttributeValue(String attributeName, Object newValue) { Attribute attribute = getAttribute(getRealName(attributeName)); if (attribute == null) return; Object oldValue = attribute.getValue(); if (Utils.equals(oldValue, newValue)) return; if (oldValue instanceof Model) { removeSubModel((Model) oldValue); } if (newValue instanceof Model) { addSubModel((Model) newValue); } attribute.setValue(newValue); propertyChange(new PropertyChangeEvent(this, attributeName, oldValue, newValue)); }
From source file:com.itemanalysis.jmetrik.gui.JmetrikPreferencesManager.java
public synchronized void firePropertyChange(String propertyName, Object oldValue, Object newValue) { PropertyChangeEvent e = new PropertyChangeEvent(this, propertyName, oldValue, newValue); for (PropertyChangeListener l : propertyChangeListeners) { l.propertyChange(e);// w w w . j av a 2s.c o m } }
From source file:net.mariottini.swing.JFontChooser.java
private void notifyPropertyChange(String property, Object oldValue, Object newValue) { PropertyChangeEvent evt = new PropertyChangeEvent(this, property, oldValue, newValue); PropertyChangeListener[] listeners = getPropertyChangeListeners(); for (int i = 0; i < listeners.length; ++i) { listeners[i].propertyChange(evt); }/*ww w . j av a 2 s . co m*/ }
From source file:edu.ku.brc.specify.tools.schemalocale.SchemaLocalizerDlg.java
@Override public void copyLocale(final LocalizableIOIFaceListener lcl, Locale srcLocale, Locale dstLocale, final PropertyChangeListener pcl) { UIRegistry.getStatusBar().setProgressRange(SCHEMALOCDLG, 0, getContainerDisplayItems().size()); DataProviderSessionIFace session = DataProviderFactory.getInstance().createSession(); try {// w w w . j a v a2 s. c o m double step = 100.0 / (double) tableDisplayItems.size(); double total = 0.0; for (LocalizableJListItem listItem : tableDisplayItems) { //System.out.println(listItem.getName()); SpLocaleContainer container = (SpLocaleContainer) tableHash.get(listItem.getId()); if (container == null) { container = loadTable(session, listItem.getId()); tableHash.put(listItem.getId(), container); } if (container != null) { copyLocale(container, srcLocale, dstLocale); for (LocalizableItemIFace field : container.getItems()) { //System.out.println(" "+field.getName()); copyLocale(field, srcLocale, dstLocale); } containerChanged(container); if (pcl != null) { pcl.propertyChange(new PropertyChangeEvent(this, "progress", total, (int) (total + step))); } } else { log.error("Couldn't find Container[" + listItem.getId() + "]"); } total += step; } } catch (Exception ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(SchemaLocalizerDlg.class, ex); ex.printStackTrace(); } finally { session.close(); UIRegistry.getStatusBar().setProgressDone(SCHEMALOCDLG); } pcl.propertyChange(new PropertyChangeEvent(this, "progress", 99, 100)); }
From source file:edu.ku.brc.specify.tasks.subpane.ESResultsTablePanel.java
public void propertyChange(final PropertyChangeEvent evt) { // This gets called when all the results have been loaded rowCount = (Integer) evt.getNewValue(); if (rowCount > 0) { synchronized (getTreeLock()) { setTitleBar();//from w w w . ja va2 s .co m esrPane.addTable(ESResultsTablePanel.this); } if (propChangeListener != null) { propChangeListener.propertyChange(new PropertyChangeEvent(this, "loaded", rowCount, rowCount)); } autoResizeColWidth(table, (DefaultTableModel) table.getModel()); } }
From source file:org.tinygroup.weblayer.webcontext.parser.util.BeanWrapperImpl.java
private void setPropertyValue(PropertyTokenHolder tokens, PropertyValue pv) throws BeansException { String propertyName = tokens.canonicalName; String actualName = tokens.actualName; if (tokens.keys != null) { // Apply indexes and map keys: fetch value for all keys but the last one. PropertyTokenHolder getterTokens = new PropertyTokenHolder(); getterTokens.canonicalName = tokens.canonicalName; getterTokens.actualName = tokens.actualName; getterTokens.keys = new String[tokens.keys.length - 1]; System.arraycopy(tokens.keys, 0, getterTokens.keys, 0, tokens.keys.length - 1); Object propValue = null;// w ww . jav a 2 s . c om try { propValue = getPropertyValue(getterTokens); } catch (NotReadablePropertyException ex) { throw new NotWritablePropertyException(getRootClass(), this.nestedPath + propertyName, "Cannot access indexed value in property referenced " + "in indexed property path '" + propertyName + "'", ex); } // Set value for last key. String key = tokens.keys[tokens.keys.length - 1]; if (propValue == null) { throw new NullValueInNestedPathException(getRootClass(), this.nestedPath + propertyName, "Cannot access indexed value in property referenced " + "in indexed property path '" + propertyName + "': returned null"); } else if (propValue.getClass().isArray()) { Class requiredType = propValue.getClass().getComponentType(); int arrayIndex = Integer.parseInt(key); Object oldValue = null; try { if (isExtractOldValueForEditor()) { oldValue = Array.get(propValue, arrayIndex); } Object convertedValue = this.typeConverterDelegate.convertIfNecessary(propertyName, oldValue, pv.getValue(), requiredType); Array.set(propValue, Integer.parseInt(key), convertedValue); } catch (IllegalArgumentException ex) { PropertyChangeEvent pce = new PropertyChangeEvent(this.rootObject, this.nestedPath + propertyName, oldValue, pv.getValue()); throw new TypeMismatchException(pce, requiredType, ex); } catch (IndexOutOfBoundsException ex) { throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName, "Invalid array index in property path '" + propertyName + "'", ex); } } else if (propValue instanceof List) { PropertyDescriptor pd = getCachedIntrospectionResults().getPropertyDescriptor(actualName); Class requiredType = null; if (JdkVersion.isAtLeastJava15()) { requiredType = GenericCollectionTypeResolver.getCollectionReturnType(pd.getReadMethod(), tokens.keys.length); } List list = (List) propValue; int index = Integer.parseInt(key); Object oldValue = null; if (isExtractOldValueForEditor() && index < list.size()) { oldValue = list.get(index); } try { Object convertedValue = this.typeConverterDelegate.convertIfNecessary(propertyName, oldValue, pv.getValue(), requiredType); if (index < list.size()) { list.set(index, convertedValue); } else if (index >= list.size()) { for (int i = list.size(); i < index; i++) { try { list.add(null); } catch (NullPointerException ex) { throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName, "Cannot set element with index " + index + " in List of size " + list.size() + ", accessed using property path '" + propertyName + "': List does not support filling up gaps with null elements"); } } list.add(convertedValue); } } catch (IllegalArgumentException ex) { PropertyChangeEvent pce = new PropertyChangeEvent(this.rootObject, this.nestedPath + propertyName, oldValue, pv.getValue()); throw new TypeMismatchException(pce, requiredType, ex); } } else if (propValue instanceof Map) { PropertyDescriptor pd = getCachedIntrospectionResults().getPropertyDescriptor(actualName); Class mapKeyType = null; Class mapValueType = null; if (JdkVersion.isAtLeastJava15()) { mapKeyType = GenericCollectionTypeResolver.getMapKeyReturnType(pd.getReadMethod(), tokens.keys.length); mapValueType = GenericCollectionTypeResolver.getMapValueReturnType(pd.getReadMethod(), tokens.keys.length); } Map map = (Map) propValue; Object convertedMapKey = null; Object convertedMapValue = null; try { // IMPORTANT: Do not pass full property name in here - property editors // must not kick in for map keys but rather only for map values. convertedMapKey = this.typeConverterDelegate.convertIfNecessary(key, mapKeyType); } catch (IllegalArgumentException ex) { PropertyChangeEvent pce = new PropertyChangeEvent(this.rootObject, this.nestedPath + propertyName, null, pv.getValue()); throw new TypeMismatchException(pce, mapKeyType, ex); } Object oldValue = null; if (isExtractOldValueForEditor()) { oldValue = map.get(convertedMapKey); } try { // Pass full property name and old value in here, since we want full // conversion ability for map values. convertedMapValue = this.typeConverterDelegate.convertIfNecessary(propertyName, oldValue, pv.getValue(), mapValueType, null, new MethodParameter(pd.getReadMethod(), -1, tokens.keys.length + 1)); } catch (IllegalArgumentException ex) { PropertyChangeEvent pce = new PropertyChangeEvent(this.rootObject, this.nestedPath + propertyName, oldValue, pv.getValue()); throw new TypeMismatchException(pce, mapValueType, ex); } map.put(convertedMapKey, convertedMapValue); } else { throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName, "Property referenced in indexed property path '" + propertyName + "' is neither an array nor a List nor a Map; returned value was [" + pv.getValue() + "]"); } } else { PropertyDescriptor pd = pv.resolvedDescriptor; if (pd == null || !pd.getWriteMethod().getDeclaringClass().isInstance(this.object)) { pd = getCachedIntrospectionResults().getPropertyDescriptor(actualName); if (pd == null || pd.getWriteMethod() == null) { PropertyMatches matches = PropertyMatches.forProperty(propertyName, getRootClass()); throw new NotWritablePropertyException(getRootClass(), this.nestedPath + propertyName, matches.buildErrorMessage(), matches.getPossibleMatches()); } pv.getOriginalPropertyValue().resolvedDescriptor = pd; } Object oldValue = null; try { Object originalValue = pv.getValue(); Object valueToApply = originalValue; if (!Boolean.FALSE.equals(pv.conversionNecessary)) { if (pv.isConverted()) { valueToApply = pv.getConvertedValue(); } else { if (isExtractOldValueForEditor() && pd.getReadMethod() != null) { Method readMethod = pd.getReadMethod(); if (!Modifier.isPublic(readMethod.getDeclaringClass().getModifiers())) { readMethod.setAccessible(true); } try { oldValue = readMethod.invoke(this.object, new Object[0]); } catch (Exception ex) { if (logger.isDebugEnabled()) { logger.debug("Could not read previous value of property '" + this.nestedPath + propertyName + "'", ex); } } } valueToApply = this.typeConverterDelegate.convertIfNecessary(oldValue, originalValue, pd); } pv.getOriginalPropertyValue().conversionNecessary = Boolean .valueOf(valueToApply != originalValue); } Method writeMethod = pd.getWriteMethod(); if (!Modifier.isPublic(writeMethod.getDeclaringClass().getModifiers())) { writeMethod.setAccessible(true); } writeMethod.invoke(this.object, new Object[] { valueToApply }); } catch (InvocationTargetException ex) { PropertyChangeEvent propertyChangeEvent = new PropertyChangeEvent(this.rootObject, this.nestedPath + propertyName, oldValue, pv.getValue()); if (ex.getTargetException() instanceof ClassCastException) { throw new TypeMismatchException(propertyChangeEvent, pd.getPropertyType(), ex.getTargetException()); } else { throw new MethodInvocationException(propertyChangeEvent, ex.getTargetException()); } } catch (IllegalArgumentException ex) { PropertyChangeEvent pce = new PropertyChangeEvent(this.rootObject, this.nestedPath + propertyName, oldValue, pv.getValue()); throw new TypeMismatchException(pce, pd.getPropertyType(), ex); } catch (IllegalAccessException ex) { PropertyChangeEvent pce = new PropertyChangeEvent(this.rootObject, this.nestedPath + propertyName, oldValue, pv.getValue()); throw new MethodInvocationException(pce, ex); } } }
From source file:org.kuali.kfs.module.tem.document.TravelDocumentBase.java
/** * @see org.kuali.kfs.module.tem.document.TravelDocument#addActualExpense(org.kuali.kfs.module.tem.businessobject.ActualExpense) *///from w w w. ja v a 2 s . c o m @Override @Transient public void addActualExpense(final ActualExpense line) { final String sequenceName = line.getSequenceName(); final Long sequenceNumber = getSequenceAccessorService().getNextAvailableSequenceNumber(sequenceName, ActualExpense.class); line.setId(sequenceNumber); line.setDocumentNumber(this.documentNumber); notifyChangeListeners(new PropertyChangeEvent(this, TemPropertyConstants.ACTUAL_EXPENSES, null, line)); line.enableExpenseTypeSpecificFields(); getActualExpenses().add(line); }
From source file:org.kuali.kfs.module.tem.document.TravelDocumentBase.java
@Override @Transient/*www.j a va 2s .com*/ public void addExpense(TemExpense line) { final String sequenceName = line.getSequenceName(); // Because all expense types use the same sequence, it doesn't matter which class grabs the sequence final Long sequenceNumber = getSequenceAccessorService().getNextAvailableSequenceNumber(sequenceName, ImportedExpense.class); line.setId(sequenceNumber); line.setDocumentNumber(this.documentNumber); if (line instanceof ActualExpense) { getTravelExpenseService().updateTaxabilityOfActualExpense((ActualExpense) line, this, GlobalVariables.getUserSession().getPerson()); // when adding the expense, attempt to update the taxability if user can't edit taxability getActualExpenses().add((ActualExpense) line); notifyChangeListeners(new PropertyChangeEvent(this, TemPropertyConstants.ACTUAL_EXPENSES, null, line)); ((ActualExpense) line).enableExpenseTypeSpecificFields(); } else { getImportedExpenses().add((ImportedExpense) line); notifyChangeListeners( new PropertyChangeEvent(this, TemPropertyConstants.IMPORTED_EXPENSES, null, line)); } }
From source file:edu.ku.brc.specify.plugins.latlon.LatLonUI.java
public void setChanged(boolean isChanged) { this.isChanged = isChanged; if (isChanged) { for (PropertyChangeListener l : getPropertyChangeListeners()) { l.propertyChange(new PropertyChangeEvent(LatLonUI.this, "latlon", null, getLatLon())); }/*from ww w. j a va2s . co m*/ } if (!isChanged) { for (LatLonUIIFace panel : panels) { panel.setHasChanged(isChanged); } } }