private boolean firstCall = true;
@Override
protected void run()
{
final Screen currentScreen = DkMain.controller().getCurrentScreen();
// if there is no screen displayed or if the screen to display is not the same than the current screen.
if (currentScreen == null || !currentScreen.getClass().getName().equals(clazz.getName()))
{
if (firstCall && !DkMain.controller().onBeforeScreenLeft(this))
{
BaseShowScreenAction.log.debug("[BaseShowScreenAction Screen {"
+ (currentScreen == null ? "null" : currentScreen.getClass().getName()) + "} can't be left.]");
firstCall = false;
this.stopChain();
}
else
{
// there we verify that the screen to show is not already created and stored in the
// MainController screens map. If it is not , a new one is created.
final Screen toShow = DkMain.controller().getScreenInstance(clazz);
final SimpleContainer screenContainerPanel = DkMain.controller().getGui().getScreenContainerPanel();
if (currentScreen == null || screenContainerPanel.remove(currentScreen))
{
DkMain.controller().setCurrentScreen(null);
if (currentScreen != null)
{
BaseShowScreenAction.log.debug("[BaseShowScreenAction Screen {" + currentScreen.getClass().getName()
+ "} Closed]");
}
screenContainerPanel.add(toShow);
DkMain.controller().setPreviousScreen(currentScreen);
DkMain.controller().setCurrentScreen(toShow);
DkMain.controller().setScreenDisplayId(DkIdGenerator.generateRandomId(10));
DkMain.controller().onScreenBeforeShow(currentScreen, optionalArgs);
screenContainerPanel.forceLayout();
BaseShowScreenAction.log.debug("[BaseShowScreenAction Screen {" + toShow.getClass().getName()
+ "} Displayed (layout forced)]");
}
else
{
BaseShowScreenAction.log.warn("[BaseShowScreenAction Screen {" + clazz.getName() + "} NOT Removable]");