001package jmri.jmrit.operations.automation.actions; 002 003import javax.swing.JComboBox; 004 005import jmri.InstanceManager; 006import jmri.jmrit.operations.automation.*; 007 008public class GotoAction extends Action { 009 010 private static final int _code = ActionCodes.GOTO; 011 012 @Override 013 public int getCode() { 014 return _code; 015 } 016 017 @Override 018 public String getName() { 019 return Bundle.getMessage("Goto"); 020 } 021 022 @Override 023 public void doAction() { 024 if (getAutomationItem() != null) { 025 AutomationItem gotoAutomationItem = getAutomationItem().getGotoAutomationItem(); 026 if (gotoAutomationItem != null) { 027 setRunning(true); 028 // the old property = null unconditional branch 029 firePropertyChange(ACTION_GOTO_CHANGED_PROPERTY, null, gotoAutomationItem); 030 } 031 finishAction(gotoAutomationItem != null); 032 } 033 } 034 035 @Override 036 public void cancelAction() { 037 setRunning(false); 038 } 039 040 @Override 041 public String getActionSuccessfulString() { 042 return Bundle.getMessage("ButtonOK") + getGotoAutomationItemId(); 043 } 044 045 private String getGotoAutomationItemId() { 046 String id = ""; 047 if (getAutomationItem() != null) { 048 AutomationItem gotoAutomationItem = getAutomationItem().getGotoAutomationItem(); 049 if (gotoAutomationItem != null && getAutomationItem().isGotoBranched()) { 050 id = " -> " + gotoAutomationItem.getId(); 051 } 052 } 053 return id; 054 } 055 056 @Override 057 public JComboBox<AutomationItem> getComboBox() { 058 if (getAutomationItem() != null) { 059 Automation automation = InstanceManager.getDefault(AutomationManager.class) 060 .getAutomationById(getAutomationItem().getId().split(Automation.REGEX)[0]); 061 if (automation != null) { 062 JComboBox<AutomationItem> cb = automation.getComboBox(); 063 cb.removeItem(getAutomationItem()); 064 cb.setSelectedItem(getAutomationItem().getGotoAutomationItem()); 065 return cb; 066 } 067 } 068 return null; 069 } 070 071}