001 package org.springframework.richclient.samples.showcase.command;
002
003 import java.text.DateFormat;
004 import java.util.Calendar;
005 import java.util.Locale;
006
007 import org.springframework.richclient.command.support.ApplicationWindowAwareCommand;
008
009 /**
010 * Simple command testing the {@link ApplicationWindowAwareCommand} class. If
011 * everything goes as expected, a timestamp will be set on the correct window.
012 *
013 * @author Jan Hoskens
014 *
015 */
016 public class TitleBarTimeStampCommand extends ApplicationWindowAwareCommand {
017
018 private static final String TIMESTAMP_PREFIX = " [time: ";
019
020 private static final String TIMESTAMP_POSTFIX = "]";
021
022 private DateFormat format = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.FULL, Locale.getDefault());
023
024 @Override
025 protected void doExecuteCommand() {
026 Calendar currentTime = Calendar.getInstance();
027 String title = getApplicationWindow().getControl().getTitle();
028 int pos = title.indexOf(TIMESTAMP_PREFIX);
029 if (pos != -1)
030 title = title.substring(0, pos);
031 title += TIMESTAMP_PREFIX + format.format(currentTime.getTime()) + TIMESTAMP_POSTFIX;
032 getApplicationWindow().getControl().setTitle(title);
033 }
034 }