Skip to content

Commit

Permalink
Prevent recursive name indexing in Add new range of Blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
silverailscolo committed May 11, 2018
1 parent c1eee4b commit 3c5243f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
13 changes: 5 additions & 8 deletions java/src/jmri/BlockManager.java
Expand Up @@ -18,23 +18,22 @@

/**
* Basic Implementation of a BlockManager.
* <P>
* <p>
* Note that this does not enforce any particular system naming convention.
* <P>
* <p>
* Note this is a concrete class, unlike the interface/implementation pairs of
* most Managers, because there are currently only one implementation for
* Blocks.
* <hr>
* This file is part of JMRI.
* <P>
* <p>
* JMRI is free software; you can redistribute it and/or modify it under the
* terms of version 2 of the GNU General Public License as published by the Free
* Software Foundation. See the "COPYING" file for a copy of this license.
* <P>
* <p>
* JMRI is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
* <P>
*
* @author Bob Jacobsen Copyright (C) 2006
*/
Expand Down Expand Up @@ -357,8 +356,6 @@ public void propertyChange(PropertyChangeEvent e) {
}
}



/**
* Returns the amount of time since the layout was last powered up,
* in milliseconds. If the layout has not been powered up as far as
Expand All @@ -373,6 +370,6 @@ public long timeSinceLastLayoutPowerOn() {
return Instant.now().toEpochMilli() - lastTimeLayoutPowerOn.toEpochMilli();
}


private final static Logger log = LoggerFactory.getLogger(BlockManager.class);

}
2 changes: 1 addition & 1 deletion java/src/jmri/jmrit/beantable/BeanTableBundle.properties
Expand Up @@ -289,7 +289,7 @@ ErrorIdTagAddFailed = Could not create ID tag "{0}" to add it.
ErrorRouteAddFailed = Could not create Route "{0}" to add it.
ErrorLRouteAddFailed = Could not create LRoute "{0}" to add it.
ErrorSectionAddFailed = Could not create Section "{0}" to add it.
ErrorAddFailedCheck = Check that number/name is OK.
ErrorAddFailedCheck = Check that number/name is OK and not in use.
ErrorSignalMastInvalidHead = Could not create Signal Mast "{0}".\nThe Signal Head "{1}" is not valid.
ErrorSignalMastBox1 = Failed to create definition. Did you select a Signal System?
ErrorSignalMastBox2 = Failed to read definition. Did you select a Signal System?
Expand Down
23 changes: 15 additions & 8 deletions java/src/jmri/jmrit/beantable/BlockTableAction.java
Expand Up @@ -966,6 +966,11 @@ void cancelPressed(ActionEvent e) {
addFrame = null;
}

/**
* Respond to Create new item pressed on Add Block pane.
*
* @param e the click event
*/
void okPressed(ActionEvent e) {

int NumberOfBlocks = 1;
Expand All @@ -982,14 +987,16 @@ void okPressed(ActionEvent e) {
}
}
String user = userName.getText();
String uName = user; // result stored separately to prevent incremental manipulation
user = NamedBean.normalizeUserName(user);
if (user == null || user.length() == 0) {
user = null;
}
String sName = sysName.getText();
String system = sysName.getText();
String sName = system; // result stored separately to prevent incremental manipulation
sName = InstanceManager.getDefault(BlockManager.class).normalizeSystemName(sName);
// initial check for empty entry using the raw name
if (sName.length() < 3 && !_autoSystemName.isSelected()) { // Using 3 to catch an plain IB
if (sName.length() < 3 && !_autoSystemName.isSelected()) { // Using 3 to catch a plain IB
statusBar.setText(Bundle.getMessage("WarningSysNameEmpty"));
statusBar.setForeground(Color.red);
sysName.setBackground(Color.red);
Expand All @@ -1003,15 +1010,15 @@ void okPressed(ActionEvent e) {
StringBuilder b;

for (int x = 0; x < NumberOfBlocks; x++) {
if (x != 0) {
if (x != 0) { // start at 2nd Block
if (user != null) {
b = new StringBuilder(user);
b.append(":");
b.append(Integer.toString(x));
user = b.toString();
uName = b.toString();
}
if (!_autoSystemName.isSelected()) {
b = new StringBuilder(sName);
b = new StringBuilder(system);
b.append(":");
b.append(Integer.toString(x));
sName = b.toString();
Expand All @@ -1021,13 +1028,13 @@ void okPressed(ActionEvent e) {
String xName = "";
try {
if (_autoSystemName.isSelected()) {
blk = InstanceManager.getDefault(jmri.BlockManager.class).createNewBlock(user);
blk = InstanceManager.getDefault(jmri.BlockManager.class).createNewBlock(uName);
if (blk == null) {
xName = user;
xName = uName;
throw new java.lang.IllegalArgumentException();
}
} else {
blk = InstanceManager.getDefault(jmri.BlockManager.class).createNewBlock(sName, user);
blk = InstanceManager.getDefault(jmri.BlockManager.class).createNewBlock(sName, uName);
if (blk == null) {
xName = sName;
throw new java.lang.IllegalArgumentException();
Expand Down
2 changes: 1 addition & 1 deletion java/src/jmri/jmrit/beantable/TurnoutTableAction.java
Expand Up @@ -1668,7 +1668,7 @@ void cancelPressed(ActionEvent e) {
}

/**
* Respond to Create new item pressed on Add Turnout pane
* Respond to Create new item pressed on Add Turnout pane.
*
* @param e the click event
*/
Expand Down

0 comments on commit 3c5243f

Please sign in to comment.