001 package org.springframework.richclient.command.support; 002 003 import org.springframework.richclient.application.Application; 004 import org.springframework.richclient.application.config.ApplicationObjectConfigurer; 005 import org.springframework.richclient.dialog.ApplicationDialog; 006 import org.springframework.richclient.dialog.TitledWidgetApplicationDialog; 007 008 import java.awt.*; 009 010 /** 011 * Widget Dialog Command shows a specific widget in a dialog. 012 */ 013 public class WidgetDialogCommand extends AbstractWidgetCommand 014 { 015 private ApplicationDialog dialog; 016 017 /** parent for centering the dialog. */ 018 private Component parent; 019 020 public WidgetDialogCommand() 021 { 022 super(); 023 } 024 025 public WidgetDialogCommand(String id) 026 { 027 super(); 028 setId(id); 029 } 030 031 protected void doExecuteCommand() 032 { 033 dialog = (dialog == null) ? createDialog() : dialog; 034 if (getParent() != null) 035 { 036 dialog.setParentComponent(getParent()); 037 } 038 dialog.showDialog(); 039 } 040 041 protected ApplicationDialog createDialog() 042 { 043 ApplicationDialog newlyCreatedDialog = new TitledWidgetApplicationDialog(getWidget()); 044 ((ApplicationObjectConfigurer) Application.services().getService(ApplicationObjectConfigurer.class)) 045 .configure(newlyCreatedDialog, getId()); 046 return newlyCreatedDialog; 047 } 048 049 public Component getParent() 050 { 051 return parent; 052 } 053 054 /** 055 * @param dialogParent 056 * The parent of the dialog for preservation of hierarchy and correct modality. 057 */ 058 public void setParent(Component dialogParent) 059 { 060 this.parent = dialogParent; 061 } 062 } 063