List of usage examples for java.beans Customizer removePropertyChangeListener
void removePropertyChangeListener(PropertyChangeListener listener);
From source file:org.eclipse.wb.internal.swing.customize.CustomizerAction.java
private void performCustomize0() throws Exception { Customizer customizer = m_customizerClass.newInstance(); // prepare properties information final JavaInfoState javaInfoState = JavaInfoState.getState(m_javaInfo); boolean explicit = isExplicitPropertyChange(m_javaInfo); PropertyChangeListener propertyChangeListener = null; if (explicit) { propertyChangeListener = new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { javaInfoState.changedProperties.add(event.getPropertyName()); javaInfoState.changedPropertyValues.put(event.getPropertyName(), event.getNewValue()); }//from w w w.ja v a 2 s . com }; customizer.addPropertyChangeListener(propertyChangeListener); } // try { // open customizer dialog customizer.setObject(javaInfoState.object); AwtComponentDialog dialog = new AwtComponentDialog(DesignerPlugin.getDefault(), (Component) customizer, ModelMessages.CustomizerAction_dialogTitle, MessageFormat .format(ModelMessages.CustomizerAction_dialogMessage, m_customizerClass.getName())); int dialogResult = dialog.open(); // handle update properties if (dialogResult == Window.OK) { RunnableEx runnable = null; if (explicit) { // update changed properties runnable = new RunnableEx() { public void run() throws Exception { int size = javaInfoState.properties.size(); for (int i = 0; i < size; i++) { Property property = javaInfoState.properties.get(i); if (javaInfoState.changedProperties.contains(property.getTitle())) { Object newValue = javaInfoState.changedPropertyValues.get(property.getTitle()); Object oldValue = javaInfoState.oldValues.get(i); if (!ObjectUtils.equals(newValue, oldValue)) { property.setValue(newValue); } } } } }; } else { // update all properties runnable = new RunnableEx() { public void run() throws Exception { int size = javaInfoState.properties.size(); for (int i = 0; i < size; i++) { Object newValue = javaInfoState.getters.get(i).invoke(javaInfoState.object); Object oldValue = javaInfoState.oldValues.get(i); if (!ObjectUtils.equals(newValue, oldValue)) { javaInfoState.properties.get(i).setValue(newValue); } } } }; } // run update ExecutionUtils.run(m_javaInfo, runnable); } // rollback property changes if (dialogResult == Window.CANCEL) { ExecutionUtils.run(m_javaInfo, new RunnableEx() { public void run() throws Exception { int size = javaInfoState.properties.size(); for (int i = 0; i < size; i++) { Object newValue = javaInfoState.getters.get(i).invoke(javaInfoState.object); Object oldValue = javaInfoState.oldValues.get(i); if (!ObjectUtils.equals(newValue, oldValue)) { javaInfoState.setters.get(i).invoke(javaInfoState.object, oldValue); } } } }); } } finally { if (propertyChangeListener != null) { customizer.removePropertyChangeListener(propertyChangeListener); } } }