NPE when setting null action to DesktopButton #PL-5165

This commit is contained in:
Yuriy Artamonov 2015-03-31 14:52:41 +00:00
parent cf3481c744
commit 6b51107dd6

View File

@ -29,6 +29,8 @@ public class DesktopButton extends DesktopAbstractComponent<JButton> implements
protected long responseEndTs = 0; protected long responseEndTs = 0;
protected boolean shouldBeFocused = true; protected boolean shouldBeFocused = true;
protected PropertyChangeListener actionPropertyChangeListener;
public DesktopButton() { public DesktopButton() {
impl = createImplementation(); impl = createImplementation();
impl.addActionListener(new ValidationAwareActionListener() { impl.addActionListener(new ValidationAwareActionListener() {
@ -65,29 +67,35 @@ public class DesktopButton extends DesktopAbstractComponent<JButton> implements
@Override @Override
public void setAction(Action action) { public void setAction(Action action) {
this.action = action; if (action != this.action) {
if (this.action != null) {
this.action.removeOwner(this);
this.action.removePropertyChangeListener(actionPropertyChangeListener);
}
String caption = action.getCaption(); this.action = action;
if (!StringUtils.isEmpty(caption) && StringUtils.isEmpty(impl.getText())) {
impl.setText(caption);
}
String description = action.getDescription(); if (action != null) {
if (!StringUtils.isEmpty(description) && StringUtils.isEmpty(getDescription())) { String caption = action.getCaption();
setDescription(description); if (!StringUtils.isEmpty(caption) && StringUtils.isEmpty(impl.getText())) {
} impl.setText(caption);
}
setEnabled(action.isEnabled()); String description = action.getDescription();
setVisible(action.isVisible()); if (!StringUtils.isEmpty(description) && StringUtils.isEmpty(getDescription())) {
setDescription(description);
}
if (action.getIcon() != null) { setEnabled(action.isEnabled());
setIcon(action.getIcon()); setVisible(action.isVisible());
}
action.addOwner(this); if (action.getIcon() != null) {
setIcon(action.getIcon());
}
action.addPropertyChangeListener( action.addOwner(this);
new PropertyChangeListener() {
actionPropertyChangeListener = new PropertyChangeListener() {
@Override @Override
public void propertyChange(PropertyChangeEvent evt) { public void propertyChange(PropertyChangeEvent evt) {
if (Action.PROP_ICON.equals(evt.getPropertyName())) { if (Action.PROP_ICON.equals(evt.getPropertyName())) {
@ -102,10 +110,12 @@ public class DesktopButton extends DesktopAbstractComponent<JButton> implements
setVisible(DesktopButton.this.action.isVisible()); setVisible(DesktopButton.this.action.isVisible());
} }
} }
} };
); action.addPropertyChangeListener(actionPropertyChangeListener);
assignAutoDebugId(); assignAutoDebugId();
}
}
} }
@Override @Override