001 /* 002 * Copyright 2008 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 005 * use this file except in compliance with the License. You may obtain a copy of 006 * the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 013 * License for the specific language governing permissions and limitations under 014 * the License. 015 */ 016 package org.springframework.richclient.application.support; 017 018 import java.awt.Image; 019 import java.beans.PropertyChangeListener; 020 021 import javax.swing.Icon; 022 023 import org.springframework.binding.value.support.PropertyChangeSupport; 024 import org.springframework.richclient.application.ApplicationWindow; 025 import org.springframework.richclient.application.PageComponent; 026 import org.springframework.richclient.application.View; 027 import org.springframework.richclient.application.ViewDescriptor; 028 import org.springframework.richclient.command.ActionCommand; 029 import org.springframework.richclient.command.config.CommandButtonLabelInfo; 030 import org.springframework.richclient.command.support.ShowViewCommand; 031 import org.springframework.util.Assert; 032 033 /** 034 * {@link ViewDescriptor} implementation for internal purposes (mostly testing). 035 * <p> 036 * This class accepts an existing {@link View} instance, and returns this in the {@link #createPageComponent()} method. 037 * <p> 038 * Normally you should never use this class directly. 039 * 040 * @author Peter De Bruycker 041 */ 042 public class SimpleViewDescriptor implements ViewDescriptor { 043 044 private View view; 045 private String id; 046 private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this); 047 048 public SimpleViewDescriptor(String id, View view) { 049 Assert.notNull(view, "view cannot be null"); 050 051 this.id = id; 052 this.view = view; 053 054 view.setDescriptor(this); 055 } 056 057 public ActionCommand createShowViewCommand(ApplicationWindow window) { 058 return new ShowViewCommand(this, window); 059 } 060 061 public CommandButtonLabelInfo getShowViewCommandLabel() { 062 return new CommandButtonLabelInfo(getDisplayName()); 063 } 064 065 public PageComponent createPageComponent() { 066 return view; 067 } 068 069 public String getId() { 070 return id; 071 } 072 073 public void addPropertyChangeListener(PropertyChangeListener listener) { 074 propertyChangeSupport.addPropertyChangeListener(listener); 075 } 076 077 public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) { 078 propertyChangeSupport.addPropertyChangeListener(propertyName, listener); 079 } 080 081 public void removePropertyChangeListener(PropertyChangeListener listener) { 082 propertyChangeSupport.removePropertyChangeListener(listener); 083 } 084 085 public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) { 086 propertyChangeSupport.removePropertyChangeListener(propertyName, listener); 087 } 088 089 public String getCaption() { 090 return id; 091 } 092 093 public String getDescription() { 094 return id; 095 } 096 097 public String getDisplayName() { 098 return id; 099 } 100 101 public Icon getIcon() { 102 return null; 103 } 104 105 public Image getImage() { 106 return null; 107 } 108 109 }