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