@ -16,34 +16,34 @@ import de.srsoftware.web4rail.tiles.Block;
@@ -16,34 +16,34 @@ import de.srsoftware.web4rail.tiles.Block;
import de.srsoftware.web4rail.tiles.Shadow ;
import de.srsoftware.web4rail.tiles.Tile ;
public class DisableEnableBlock extends Action {
public class DisableEnableTile extends Action {
public DisableEnableBlock ( BaseClass parent ) {
public DisableEnableTile ( BaseClass parent ) {
super ( parent ) ;
}
private Block block = null ;
private Tile tile = null ;
private boolean disable = true ;
@Override
public boolean fire ( Context context ) {
if ( isNull ( block ) ) block = context . block ( ) ;
if ( isNull ( block ) ) return false ;
block . setEnabled ( ! disable ) ;
if ( isNull ( tile ) ) tile = context . block ( ) ;
if ( isNull ( tile ) ) return false ;
tile . setEnabled ( ! disable ) ;
return true ;
}
@Override
public JSONObject json ( ) {
JSONObject json = super . json ( ) ;
if ( isSet ( block ) ) json . put ( BLOCK , block . id ( ) ) ;
if ( isSet ( tile ) ) json . put ( BLOCK , tile . id ( ) ) ;
json . put ( STATE , ! disable ) ;
return json ;
}
@Override
protected String highlightId ( ) {
return isSet ( block ) ? block . id ( ) . toString ( ) : null ;
return isSet ( tile ) ? tile . id ( ) . toString ( ) : null ;
}
@ -53,7 +53,7 @@ public class DisableEnableBlock extends Action {
@@ -53,7 +53,7 @@ public class DisableEnableBlock extends Action {
if ( json . has ( BLOCK ) ) new LoadCallback ( ) {
@Override
public void afterLoad ( ) {
block = Block . get ( Id . from ( json , BLOCK ) ) ;
tile = Block . get ( Id . from ( json , BLOCK ) ) ;
}
} ;
return super . load ( json ) ;
@ -62,7 +62,7 @@ public class DisableEnableBlock extends Action {
@@ -62,7 +62,7 @@ public class DisableEnableBlock extends Action {
@Override
protected Window properties ( List < Fieldset > preForm , FormInput formInputs , List < Fieldset > postForm , String . . . errors ) {
formInputs . add ( t ( "Block" ) + ": " + ( isNull ( block ) ? t ( "block from context" ) : block ) , button ( t ( "Select from plan" ) , Map . of ( ACTION , ACTION_UPDATE , ASSIGN , Block . class . getSimpleName ( ) ) ) ) ;
formInputs . add ( t ( "Block" ) + ": " + ( isNull ( tile ) ? t ( "tile from context" ) : tile ) , button ( t ( "Select from plan" ) , Map . of ( ACTION , ACTION_UPDATE , ASSIGN , Tile . class . getSimpleName ( ) ) ) ) ;
Tag radios = new Tag ( "p" ) ;
new Radio ( STATE , "enable" , t ( "enable" ) , ! disable ) . addTo ( radios ) ;
new Radio ( STATE , "disable" , t ( "disable" ) , disable ) . addTo ( radios ) ;
@ -72,22 +72,22 @@ public class DisableEnableBlock extends Action {
@@ -72,22 +72,22 @@ public class DisableEnableBlock extends Action {
@Override
protected void removeChild ( BaseClass child ) {
if ( child = = block ) block = null ;
if ( child = = tile ) tile = null ;
super . removeChild ( child ) ;
}
public String toString ( ) {
String blk = isSet ( block ) ? block . toString ( ) : t ( "block from context" ) ;
String blk = isSet ( tile ) ? tile . toString ( ) : t ( "block from context" ) ;
return t ( disable ? "disable {}" : "enable {}" , blk ) ;
} ;
@Override
protected Object update ( Params params ) {
LOG . debug ( "update: {}" , params ) ;
Id block Id = Id . from ( params , Block . class . getSimpleName ( ) ) ;
Tile t ile = isSet ( blockId ) ? BaseClass . get ( blockId ) : null ;
if ( t ile instanceof Shadow ) t ile = ( ( Shadow ) t ile) . overlay ( ) ;
if ( tile instanceof Block ) block = ( Block ) t ile;
Id tile Id = Id . from ( params , Tile . class . getSimpleName ( ) ) ;
Tile newT ile = BaseClass . get ( tileId ) ; ;
if ( newT ile instanceof Shadow ) newT ile = ( ( Shadow ) newT ile) . overlay ( ) ;
if ( isSet ( newTile ) ) tile = newT ile;
disable = ! "enable" . equals ( params . get ( STATE ) ) ;
return properties ( ) ;
}