Skip to content

Fix button using both databinding and manual updates #1797

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ public class NicosModel extends ModelObject {
private long lastEntryTime;
private List<QueuedScript> queuedScripts = new ArrayList<>();

private NicosErrorState error = NicosErrorState.NO_ERROR;
// Start with a 'connection failed' error. This will get cleared when
// a successful connection gets made.
private NicosErrorState error = NicosErrorState.CONNECTION_FAILED;

/**
* Default constructor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,16 @@ public void bindControls(Button runButton, Button pauseButton, Button stopButton
bindPauseButton(pauseButton);
bindStopButton(stopButton);
formatButtonsBasedOnStatus(dynamicScriptingManager.getDynamicScriptingStatus());
nicosModel.addPropertyChangeListener(e -> updateButtonEnablement());
nicosModel.addUiThreadPropertyChangeListener(e -> updateButtonEnablement());
}

/**
* Change the state of the run/resume, pause and stop buttons based on the status of the dynamic scripting.
*/
@Override
public void propertyChange(PropertyChangeEvent evt) {
if (evt.getPropertyName().equals(DynamicScriptingProperties.STATE_CHANGE_PROPERTY)) {
var propName = evt.getPropertyName();
if (propName.equals(DynamicScriptingProperties.STATE_CHANGE_PROPERTY) || propName.equals("error")) {
updateButtonEnablement();
}
}
Expand Down Expand Up @@ -125,9 +126,7 @@ private boolean nicosInError() {
}

private void updateButtonEnablement() {
Display.getDefault().asyncExec(() -> {
formatButtonsBasedOnStatus(dynamicScriptingManager.getDynamicScriptingStatus());
});
formatButtonsBasedOnStatus(dynamicScriptingManager.getDynamicScriptingStatus());
}

private void formatButtonsBasedOnStatus(DynamicScriptingStatus status) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ private void makeDynamicScriptingControlButtons(Composite parent) {
.image(Constants.IMAGE_RUN)
.tooltip("Run")
.layoutData(IBEXButton.expandingGrid)
.enabled(false)
.get();
pauseButton = new IBEXButton(dynamicScriptingButtonsGrp, SWT.NONE)
.image(Constants.IMAGE_PAUSE)
Expand Down Expand Up @@ -715,7 +716,6 @@ public void onActionsValidityChange(ScriptGeneratorViewModel viewModel, boolean
}
}

runButton.setEnabled(allActionsValid);
errorLabel.setText(allActionsValid ? "" : "\u26A0 There are invalid actions.");
errorLabel.setVisible(!allActionsValid);
errorLabel.getParent().layout();
Expand Down
Loading