Skip to content

Commit

Permalink
Run build error messages on GUI thread
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielBoudreau committed Apr 24, 2019
1 parent d7bd02e commit c8746fc
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 39 deletions.
23 changes: 12 additions & 11 deletions help/en/package/jmri/jmrit/operations/Operations.shtml
Original file line number Diff line number Diff line change
Expand Up @@ -636,12 +636,12 @@
</p>

<p>
If you want a caboose or car with FRED for your train, first configure some of the cars to be
the last car in the train by selecting the "Caboose" or "FRED" <a href="#CabooseFredHazardous">checkbox</a>
in the <a href="#CarsEdit">Edit Car</a> window. Now change the optional train requirements radio button to "Caboose"
or "FRED" in the <a href="#TrainEdit">Edit Train</a> window. Be sure that the last location in
your trains route has a track that will accept the caboose car or the train will not build
properly.
If you want a caboose or car with FRED for your train, first configure some of the cars to be the last car in the
train by selecting the "Caboose" or "FRED" <a href="#CabooseFredHazardous">checkbox</a> in the <a href="#CarsEdit">Edit
Car</a> window. Now change the optional train requirements radio button to "Caboose" or "FRED" in the <a
href="#TrainEdit">Edit Train</a> window. Place the caboose on a track at the first location in your train's route.
Be sure that the last location in your trains route has a track that will accept the caboose or the train will not
build properly.
</p>

<p>
Expand Down Expand Up @@ -2110,11 +2110,12 @@
<p>
<img src="images/AddYard.png">
</p>
<p>Now enter the name of the yard along with the length of the track in scale feet or in
actual inches. Append a double quote (") to the length when entering actual inches and the
program will convert the length into scale feet. Append cm if you want to convert from
centimeters to scale meters. Press the "Add Yard Track" button at the bottom of the window and
the disabled fields should now appear.</p>
<p>Now enter the name of the yard along with the length of the track in scale feet or in actual inches. Append a
double quote (") to the length when entering actual inches and the program will convert the length into scale feet.
Append cm if you want to convert from centimeters to scale meters. If you don't want the program to load your yard
to capacity with cars or locomotives, enter a smaller value for the track length. This can be useful for large
yards where track space for switching cars is needed. Press the "Add Yard Track" button at the bottom of the
window and the disabled fields should now appear.</p>

<a name="TrackServiceDirection" id="TrackServiceDirection"></a>
<h4>Track Service Direction</h4>
Expand Down
62 changes: 34 additions & 28 deletions java/src/jmri/jmrit/operations/trains/TrainBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import jmri.jmrit.operations.setup.Setup;
import jmri.jmrit.operations.trains.schedules.TrainSchedule;
import jmri.jmrit.operations.trains.schedules.TrainScheduleManager;

import org.apache.commons.lang3.ThreadUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -5241,36 +5243,40 @@ private void buildFailed(BuildFailedException e) {
log.debug(msg);

if (trainManager.isBuildMessagesEnabled()) {
if (e.getExceptionType().equals(BuildFailedException.NORMAL)) {
JOptionPane.showMessageDialog(null, msg, MessageFormat.format(Bundle.getMessage("buildErrorMsg"),
new Object[]{_train.getName(), _train.getDescription()}), JOptionPane.ERROR_MESSAGE);
} else {
// build error, could not find destinations for cars departing staging
Object[] options = {Bundle.getMessage("buttonRemoveCars"), Bundle.getMessage("ButtonOK")};
int results = JOptionPane.showOptionDialog(null, msg, MessageFormat.format(Bundle
.getMessage("buildErrorMsg"), new Object[]{_train.getName(), _train.getDescription()}),
JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE, null, options, options[1]);
if (results == 0) {
log.debug("User requested that cars be removed from staging track");
removeCarsFromStaging();
}
}
int size = carManager.getList(_train).size();
if (size > 0) {
if (JOptionPane.showConfirmDialog(null, MessageFormat.format(Bundle.getMessage("buildCarsResetTrain"),
new Object[]{size, _train.getName()}), Bundle.getMessage("buildResetTrain"),
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
_train.reset();
jmri.util.ThreadingUtil.runOnGUI(() -> {
if (e.getExceptionType().equals(BuildFailedException.NORMAL)) {
JOptionPane.showMessageDialog(null, msg, MessageFormat.format(Bundle.getMessage("buildErrorMsg"),
new Object[]{_train.getName(), _train.getDescription()}), JOptionPane.ERROR_MESSAGE);
} else {
// build error, could not find destinations for cars departing staging
Object[] options = {Bundle.getMessage("buttonRemoveCars"), Bundle.getMessage("ButtonOK")};
int results = JOptionPane.showOptionDialog(null, msg, MessageFormat.format(Bundle
.getMessage("buildErrorMsg"), new Object[]{_train.getName(), _train.getDescription()}),
JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE, null, options, options[1]);
if (results == 0) {
log.debug("User requested that cars be removed from staging track");
removeCarsFromStaging();
}
}
} else if ((size = engineManager.getList(_train).size()) > 0) {
if (JOptionPane.showConfirmDialog(null,
MessageFormat.format(Bundle.getMessage("buildEnginesResetTrain"),
new Object[]{size, _train.getName()}),
Bundle.getMessage("buildResetTrain"),
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
_train.reset();
int size = carManager.getList(_train).size();
if (size > 0) {
if (JOptionPane.showConfirmDialog(null,
MessageFormat.format(Bundle.getMessage("buildCarsResetTrain"),
new Object[]{size, _train.getName()}),
Bundle.getMessage("buildResetTrain"),
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
_train.reset();
}
} else if ((size = engineManager.getList(_train).size()) > 0) {
if (JOptionPane.showConfirmDialog(null,
MessageFormat.format(Bundle.getMessage("buildEnginesResetTrain"),
new Object[]{size, _train.getName()}),
Bundle.getMessage("buildResetTrain"),
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
_train.reset();
}
}
}
});
}
if (_buildReport != null) {
addLine(_buildReport, ONE, msg);
Expand Down

0 comments on commit c8746fc

Please sign in to comment.