1 package siouxsie.desktop.commands.impl; 2 3 import java.beans.PropertyChangeEvent; 4 import java.beans.PropertyChangeListener; 5 6 import org.pietschy.command.ActionCommand; 7 import org.pietschy.command.CommandManager; 8 9 import siouxsie.desktop.commands.ICommand; 10 import siouxsie.desktop.commands.IExceptionHandler; 11 12 /** 13 * Bridge from Siouxsie command to GUI framework command. 14 * @author Arnaud Cogoluegnes 15 * @version $Id: SiouxsieActionCommand.java 114 2008-02-22 15:04:46Z acogo $ 16 */ 17 public class SiouxsieActionCommand extends ActionCommand implements ISiouxsieCommand { 18 19 /** the command */ 20 private ICommand command; 21 22 private IExceptionHandler exceptionHandler; 23 24 25 public SiouxsieActionCommand(CommandManager cmdManager, String commandId) { 26 super(cmdManager,commandId); 27 } 28 29 /** 30 * Execute the command. 31 * @todo configurable pre and post action (ex.: event) 32 */ 33 @Override 34 protected void handleExecute() { 35 try { 36 command.execute(); 37 } catch(Exception e) { 38 exceptionHandler.handleException(e); 39 } 40 } 41 42 public IExceptionHandler getExceptionHandler() { 43 return exceptionHandler; 44 } 45 46 public void setExceptionHandler(IExceptionHandler exceptionHandler) { 47 this.exceptionHandler = exceptionHandler; 48 } 49 50 public ICommand getCommand() { 51 return command; 52 } 53 54 public void setCommand(ICommand command) { 55 this.command = command; 56 setEnabled(command.isEnabled()); 57 command.addPropertyChangeListener(new EnableListener()); 58 } 59 60 /** 61 * Listens the enabled property of the command. 62 * @author Arnaud Cogoluegnes 63 * @version $Id: SiouxsieActionCommand.java 114 2008-02-22 15:04:46Z acogo $ 64 */ 65 class EnableListener implements PropertyChangeListener { 66 public void propertyChange(PropertyChangeEvent evt) { 67 if(ICommand.PROPERTY_ENABLED.equals(evt.getPropertyName())) { 68 Boolean enabled = (Boolean) evt.getNewValue(); 69 setEnabled(enabled.booleanValue()); 70 } 71 } 72 73 } 74 75 }