mirror of
https://gitee.com/jmix/cuba.git
synced 2024-12-04 12:17:41 +08:00
NPE when setting null action to DesktopButton #PL-5165
This commit is contained in:
parent
cf3481c744
commit
6b51107dd6
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user