001    package org.springframework.richclient.command.support;
002    
003    import org.springframework.richclient.application.support.WidgetViewDescriptor;
004    
005    /**
006     * Widget command that shows a widget in a view
007     */
008    public class WidgetViewCommand extends AbstractWidgetCommand
009    {
010    
011        protected WidgetViewDescriptor widgetViewDescriptor;
012    
013        protected String widgetViewDescriptorId;
014    
015        /**
016         * Shows the widget in the view
017         */
018        protected void doExecuteCommand()
019        {
020            if (this.widgetViewDescriptor == null)
021                this.widgetViewDescriptor = createWidgetViewDescriptor();
022    
023            getApplicationWindow().getPage().showView(widgetViewDescriptor.getId());
024    
025        }
026    
027        public void setWidgetViewDescriptorId(String widgetViewDescriptorId)
028        {
029            this.widgetViewDescriptorId = widgetViewDescriptorId;
030        }
031    
032        protected WidgetViewDescriptor createWidgetViewDescriptor()
033        {
034            if (this.widgetViewDescriptorId != null)
035                return (WidgetViewDescriptor)getApplicationContext().getBean(this.widgetViewDescriptorId);
036    
037            return  new WidgetViewDescriptor(getId(), getWidget());
038        }
039    
040        @Override
041        public void setAuthorized(boolean authorized)
042        {
043            super.setAuthorized(authorized);
044            if ((this.widgetViewDescriptor != null) && !authorized)
045                if (this.widgetViewDescriptor.getId().equals(getApplicationWindow().getPage().getActiveComponent().getId()))
046                    getApplicationWindow().getPage().showView(null);
047        }
048    }
049