/*
 * Copyright 2002-2004 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package org.springframework.richclient.command.support;

import org.springframework.richclient.application.ApplicationWindow;
import org.springframework.richclient.application.View;
import org.springframework.richclient.application.ViewDescriptor;
import org.springframework.richclient.util.Assert;

/**
 * An action command for displaying a {@link View} based on the provided {@link ViewDescriptor}.
 */
public class ShowViewCommand extends ApplicationWindowAwareCommand {
    
    private ViewDescriptor viewDescriptor;

    /**
     * Creates a new {@code ShowViewCommand} with the given view descriptor and associated 
     * application window. The new instance will have a command identifier equal to the id from
     * the view descriptor, the command will be enabled by default.
     *
     * @param viewDescriptor The object describing the view that this command will be 
     * responsible for showing.
     * @param applicationWindow The application window that the command belongs to.
     * 
     * @throw IllegalArgumentException if {@code viewDescriptor} or {@code applicationWindow} are null.
     */
    public ShowViewCommand(ViewDescriptor viewDescriptor, ApplicationWindow applicationWindow) {
        Assert.required(applicationWindow, "applicationWindow");
        setViewDescriptor(viewDescriptor);
        setApplicationWindow(applicationWindow);
        setEnabled(true);
    }

    /**
     * Sets the descriptor for the view that is to be opened by this command object. This
     * command object will be assigned the id, label, icon, and caption from the given view
     * descriptor.
     *
     * @param viewDescriptor The view descriptor, cannot be null.
     * 
     * @throws IllegalArgumentException if {@code viewDescriptor} is null.
     */
    public final void setViewDescriptor(ViewDescriptor viewDescriptor) {
        Assert.required(viewDescriptor, "viewDescriptor");
        setId(viewDescriptor.getId()); 
        setLabel(viewDescriptor.getShowViewCommandLabel());
        setIcon(viewDescriptor.getIcon());
        setCaption(viewDescriptor.getCaption());
        this.viewDescriptor = viewDescriptor;
    }

    /**
     * Causes the view described by this instance's view descriptor to be shown.
     */
    protected void doExecuteCommand() {
        //FIXME getApplicationWindow can potentially return null. This should probably be 
        //made an invariant on the ApplicationWindowAwareCommand, that it never returns null.
        //Same applies to ApplicationWindow.getPage(), can also return null
        getApplicationWindow().getPage().showView(this.viewDescriptor);
    }

}

@@ -697,48 +697,182 @@
 ork.
-richclient.application.ApplicationWindow
+beans.factory.InitializingBean;%0Aimport org.springframework.richclient.application.ApplicationWindow;%0Aimport org.springframework.richclient.application.PropertyNotSetException
 ;%0Aim
@@ -1107,19 +1107,17 @@
 ased on 
-the
+a
  provide
@@ -1213,16 +1213,44 @@
 Command 
+implements InitializingBean 
 %7B%0A    %0A 
@@ -1290,16 +1290,274 @@
 criptor;
+%0A    %0A    /**%0A     * Creates a new uninitialized %7B@code ShowViewCommand%7D. The %7B@code applicationWindow%7D and %0A     * %7B@code viewDescriptor%7D properties must be set before using the new instance.%0A     */%0A    public ShowViewCommand() %7B%0A        //do nothing%0A    %7D
 %0A%0A    /*
@@ -2425,24 +2425,309 @@
 true);%0A    %7D
+%0A    %0A    /**%0A     * %7B@inheritDoc%7D%0A     */%0A    public void afterPropertiesSet() %7B%0A        PropertyNotSetException.throwIfNull(getApplicationWindow(), %22applicationWindow%22, getClass());%0A        PropertyNotSetException.throwIfNull(this.viewDescriptor, %22viewDescriptor%22, getClass());%0A    %7D
 %0A%0A    /**%0A  

Put no-arg constructor back in and now implement InitializingBean to check for applicationWindow and viewDescriptor properties. See RCP-452.