Revision: 1242
Author: mathiasbr
Date: 2006-07-26 09:44:04 -0700 (Wed, 26 Jul 2006)
ViewCVS: http://svn.sourceforge.net/spring-rich-c/?rev=1242&view=rev
Log Message:
-----------
fix for RCP-311, thanks Benoit Xhenseval
Factories for button and menu and command services implemntation can now be
configured through spring context
ApplicationServices.hasService renamed to containsService and implemented in
DefaultApplicationServces
Modified Paths:
--------------
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/application/ApplicationServices.java
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/application/support/DefaultApplicationServices.java
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/application/support/StaticApplicationServices.java
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/command/AbstractCommand.java
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/command/config/DefaultCommandConfigurer.java
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/command/support/DefaultCommandManager.java
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/command/support/DefaultCommandServices.java
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/factory/DefaultButtonFactory.java
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/factory/DefaultComponentFactory.java
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/factory/DefaultMenuFactory.java
Modified:
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/application/ApplicationServices.java
===================================================================
---
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/application/ApplicationServices.java
2006-07-26 12:21:04 UTC (rev 1241)
+++
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/application/ApplicationServices.java
2006-07-26 16:44:04 UTC (rev 1242)
@@ -40,5 +40,5 @@
* @param serviceType Type of service to locate
* @return true if service is available, false if not
*/
- boolean hasService( Class serviceType );
+ boolean containsService( Class serviceType );
}
Modified:
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/application/support/DefaultApplicationServices.java
===================================================================
---
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/application/support/DefaultApplicationServices.java
2006-07-26 12:21:04 UTC (rev 1241)
+++
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/application/support/DefaultApplicationServices.java
2006-07-26 16:44:04 UTC (rev 1242)
@@ -40,10 +40,16 @@
import org.springframework.richclient.application.ViewDescriptorRegistry;
import
org.springframework.richclient.application.config.ApplicationObjectConfigurer;
import
org.springframework.richclient.application.config.DefaultApplicationObjectConfigurer;
+import org.springframework.richclient.command.CommandServices;
import org.springframework.richclient.command.config.CommandConfigurer;
import org.springframework.richclient.command.config.DefaultCommandConfigurer;
+import org.springframework.richclient.command.support.DefaultCommandServices;
+import org.springframework.richclient.factory.ButtonFactory;
import org.springframework.richclient.factory.ComponentFactory;
+import org.springframework.richclient.factory.DefaultButtonFactory;
import org.springframework.richclient.factory.DefaultComponentFactory;
+import org.springframework.richclient.factory.DefaultMenuFactory;
+import org.springframework.richclient.factory.MenuFactory;
import org.springframework.richclient.form.binding.BinderSelectionStrategy;
import org.springframework.richclient.form.binding.BindingFactoryProvider;
import
org.springframework.richclient.form.binding.swing.SwingBinderSelectionStrategy;
@@ -180,10 +186,9 @@
return service;
}
- public boolean hasService( Class serviceType ) {
+ public boolean containsService( Class serviceType ) {
Assert.required(serviceType, "serviceType");
- // TODO implement this
- throw new UnsupportedOperationException("Can not test service
presence.");
+ return services.containsKey(serviceType) ||
containsDefaultImplementation(serviceType);
}
/**
@@ -296,6 +301,24 @@
}
/**
+ * Set the command services service implementation
+ *
+ * @param commandServices
+ */
+ public void setCommandServices( CommandServices commandServices ) {
+ services.put(CommandServices.class, commandServices);
+ }
+
+ /**
+ * Set the command services service implementation bean id
+ *
+ * @param commandServicesId bean id
+ */
+ public void setCommandServicesId( String commandServicesId ) {
+ services.put(CommandServices.class, commandServicesId);
+ }
+
+ /**
* Set the command configurer service implementation
*
* @param commandConfigurer
@@ -314,6 +337,42 @@
}
/**
+ * Set the button factory service implementation
+ *
+ * @param buttonFactory
+ */
+ public void setButtonFactory( ButtonFactory buttonFactory ) {
+ services.put(ButtonFactory.class, buttonFactory);
+ }
+
+ /**
+ * Set the button factory service implementation bean id
+ *
+ * @param buttonFactoryId bean id
+ */
+ public void setButtonFactoryId( String buttonFactoryId ) {
+ services.put(ButtonFactory.class, buttonFactoryId);
+ }
+
+ /**
+ * Set the menu factory service implementation
+ *
+ * @param menuFactory
+ */
+ public void setMenuFactory( MenuFactory menuFactory ) {
+ services.put(MenuFactory.class, menuFactory);
+ }
+
+ /**
+ * Set the menu factory service implementation bean id
+ *
+ * @param menuFactoryId bean id
+ */
+ public void setMenuFactoryId( String menuFactoryId ) {
+ services.put(MenuFactory.class, menuFactoryId);
+ }
+
+ /**
* Set the component factory service implementation
*
* @param componentFactory
@@ -548,6 +607,15 @@
}
/**
+ * Set the message translator registry service implementation bean id
+ *
+ * @param messageTranslatorFactory
+ */
+ public void setMessageTranslatorFactoryId(String
messageTranslatorFactoryId ) {
+ services.put(MessageTranslatorFactory.class,
messageTranslatorFactoryId);
+ }
+
+ /**
* Set the view descriptor registry service implementation bean id
*
* @param viewDescriptorRegistryId bean id
@@ -571,6 +639,15 @@
}
return impl;
}
+
+ /**
+ * Tests if a default implementation for the requested service type is
available
+ * @param serviceType the requested service type
+ * @return true if a default implementation is available otherwise false.
+ */
+ protected boolean containsDefaultImplementation(Class serviceType) {
+ return serviceImplBuilders.containsKey(serviceType);
+ }
/**
* Internal interface used to provide default implementation builders.
@@ -591,6 +668,27 @@
}
};
+ protected static final ImplBuilder menuFactoryImplBuilder = new
ImplBuilder() {
+ public Object build( DefaultApplicationServices applicationServices ) {
+ logger.info("Creating default service impl: MenuFactory");
+ return new DefaultMenuFactory();
+ }
+ };
+
+ protected static final ImplBuilder buttonFactoryImplBuilder = new
ImplBuilder() {
+ public Object build( DefaultApplicationServices applicationServices ) {
+ logger.info("Creating default service impl: ButtonFactory");
+ return new DefaultButtonFactory();
+ }
+ };
+
+ protected static final ImplBuilder commandServicesImplBuilder = new
ImplBuilder() {
+ public Object build( DefaultApplicationServices applicationServices ) {
+ logger.info("Creating default service impl: CommandServices");
+ return new DefaultCommandServices();
+ }
+ };
+
protected static final ImplBuilder componentFactoryImplBuilder = new
ImplBuilder() {
public Object build( DefaultApplicationServices applicationServices ) {
logger.info("Creating default service impl: ComponentFactory");
@@ -759,6 +857,9 @@
serviceImplBuilders.put(ApplicationSecurityManager.class,
applicationSecurityManagerImplBuilder);
serviceImplBuilders.put(BinderSelectionStrategy.class,
binderSelectionStrategyImplBuilder);
serviceImplBuilders.put(BindingFactoryProvider.class,
bindingFactoryProviderImplBuilder);
+ serviceImplBuilders.put(ButtonFactory.class, buttonFactoryImplBuilder);
+ serviceImplBuilders.put(MenuFactory.class, menuFactoryImplBuilder);
+ serviceImplBuilders.put(CommandServices.class,
commandServicesImplBuilder);
serviceImplBuilders.put(CommandConfigurer.class,
commandConfigurerImplBuilder);
serviceImplBuilders.put(ComponentFactory.class,
componentFactoryImplBuilder);
serviceImplBuilders.put(ConversionService.class,
conversionServiceImplBuilder);
Modified:
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/application/support/StaticApplicationServices.java
===================================================================
---
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/application/support/StaticApplicationServices.java
2006-07-26 12:21:04 UTC (rev 1241)
+++
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/application/support/StaticApplicationServices.java
2006-07-26 16:44:04 UTC (rev 1242)
@@ -35,7 +35,7 @@
return service;
}
- public boolean hasService(Class serviceType) {
+ public boolean containsService(Class serviceType) {
Assert.required(serviceType, "serviceType");
return services.containsKey(serviceType);
}
Modified:
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/command/AbstractCommand.java
===================================================================
---
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/command/AbstractCommand.java
2006-07-26 12:21:04 UTC (rev 1241)
+++
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/command/AbstractCommand.java
2006-07-26 16:44:04 UTC (rev 1242)
@@ -36,13 +36,13 @@
import
org.springframework.binding.value.support.AbstractPropertyChangePublisher;
import org.springframework.binding.value.support.ValueHolder;
import org.springframework.core.style.ToStringCreator;
+import org.springframework.richclient.application.ApplicationServicesLocator;
import org.springframework.richclient.command.config.CommandButtonConfigurer;
import org.springframework.richclient.command.config.CommandButtonIconInfo;
import org.springframework.richclient.command.config.CommandButtonLabelInfo;
import org.springframework.richclient.command.config.CommandFaceDescriptor;
import
org.springframework.richclient.command.config.CommandFaceDescriptorRegistry;
import org.springframework.richclient.command.support.CommandFaceButtonManager;
-import org.springframework.richclient.command.support.DefaultCommandServices;
import org.springframework.richclient.core.SecurityControllable;
import org.springframework.richclient.factory.ButtonFactory;
import org.springframework.richclient.factory.LabelInfoFactory;
@@ -248,7 +248,7 @@
protected CommandServices getCommandServices() {
if (commandServices == null) {
- return DefaultCommandServices.instance();
+ commandServices = (CommandServices)
ApplicationServicesLocator.services().getService(CommandServices.class);
}
return this.commandServices;
}
Modified:
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/command/config/DefaultCommandConfigurer.java
===================================================================
---
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/command/config/DefaultCommandConfigurer.java
2006-07-26 12:21:04 UTC (rev 1241)
+++
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/command/config/DefaultCommandConfigurer.java
2006-07-26 16:44:04 UTC (rev 1242)
@@ -21,7 +21,6 @@
import
org.springframework.richclient.application.config.ApplicationObjectConfigurer;
import org.springframework.richclient.command.AbstractCommand;
import org.springframework.richclient.command.CommandServices;
-import org.springframework.richclient.command.support.DefaultCommandServices;
import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;
@@ -89,7 +88,7 @@
protected CommandServices getCommandServices() {
if (commandServices == null) {
- return DefaultCommandServices.instance();
+ commandServices = (CommandServices)
ApplicationServicesLocator.services().getService(CommandServices.class);
}
return commandServices;
}
Modified:
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/command/support/DefaultCommandManager.java
===================================================================
---
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/command/support/DefaultCommandManager.java
2006-07-26 12:21:04 UTC (rev 1241)
+++
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/command/support/DefaultCommandManager.java
2006-07-26 16:44:04 UTC (rev 1242)
@@ -22,6 +22,7 @@
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.config.BeanPostProcessor;
+import org.springframework.richclient.application.ApplicationServicesLocator;
import org.springframework.richclient.command.AbstractCommand;
import org.springframework.richclient.command.ActionCommand;
import org.springframework.richclient.command.ActionCommandExecutor;
@@ -37,7 +38,6 @@
import org.springframework.richclient.command.config.CommandButtonConfigurer;
import org.springframework.richclient.command.config.CommandConfigurer;
import org.springframework.richclient.command.config.CommandFaceDescriptor;
-import org.springframework.richclient.command.config.DefaultCommandConfigurer;
import org.springframework.richclient.factory.ButtonFactory;
import org.springframework.richclient.factory.MenuFactory;
import org.springframework.util.Assert;
@@ -52,9 +52,9 @@
private DefaultCommandRegistry commandRegistry = new
DefaultCommandRegistry();
- private CommandServices commandServices =
DefaultCommandServices.instance();
+ private CommandServices commandServices;
- private CommandConfigurer commandConfigurer = new
DefaultCommandConfigurer(this);
+ private CommandConfigurer commandConfigurer;
public DefaultCommandManager() {
@@ -72,37 +72,56 @@
Assert.notNull(commandServices, "A command services implementation is
required");
this.commandServices = commandServices;
}
+
+ public CommandServices getCommandServices() {
+ if(commandServices == null) {
+ commandServices = (CommandServices)
ApplicationServicesLocator.services().getService(CommandServices.class);
+ }
+ return commandServices;
+ }
public void setParent(CommandRegistry parent) {
commandRegistry.setParent(parent);
}
+ public CommandConfigurer getCommandConfigurer() {
+ if(commandConfigurer == null) {
+ commandConfigurer = (CommandConfigurer)
ApplicationServicesLocator.services().getService(CommandConfigurer.class);
+ }
+ return commandConfigurer;
+ }
+
+ public void setCommandConfigurer(CommandConfigurer commandConfigurer) {
+ Assert.notNull(commandConfigurer, "command configurer must not be
null");
+ this.commandConfigurer = commandConfigurer;
+ }
+
public void setBeanFactory(BeanFactory beanFactory) {
this.beanFactory = beanFactory;
}
public ButtonFactory getButtonFactory() {
- return commandServices.getButtonFactory();
+ return getCommandServices().getButtonFactory();
}
public MenuFactory getMenuFactory() {
- return commandServices.getMenuFactory();
+ return getCommandServices().getMenuFactory();
}
public CommandButtonConfigurer getDefaultButtonConfigurer() {
- return commandServices.getDefaultButtonConfigurer();
+ return getCommandServices().getDefaultButtonConfigurer();
}
public CommandButtonConfigurer getToolBarButtonConfigurer() {
- return commandServices.getToolBarButtonConfigurer();
+ return getCommandServices().getToolBarButtonConfigurer();
}
public CommandButtonConfigurer getMenuItemButtonConfigurer() {
- return commandServices.getMenuItemButtonConfigurer();
+ return getCommandServices().getMenuItemButtonConfigurer();
}
public CommandButtonConfigurer getPullDownMenuButtonConfigurer() {
- return commandServices.getPullDownMenuButtonConfigurer();
+ return getCommandServices().getPullDownMenuButtonConfigurer();
}
public CommandFaceDescriptor getFaceDescriptor(AbstractCommand command,
String faceDescriptorId) {
@@ -192,7 +211,7 @@
}
public AbstractCommand configure(AbstractCommand command) {
- return commandConfigurer.configure(command);
+ return getCommandConfigurer().configure(command);
}
public Object postProcessAfterInitialization(Object bean, String beanName)
throws BeansException {
@@ -216,5 +235,4 @@
}
return bean;
}
-
}
\ No newline at end of file
Modified:
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/command/support/DefaultCommandServices.java
===================================================================
---
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/command/support/DefaultCommandServices.java
2006-07-26 12:21:04 UTC (rev 1241)
+++
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/command/support/DefaultCommandServices.java
2006-07-26 16:44:04 UTC (rev 1242)
@@ -21,30 +21,26 @@
import javax.swing.AbstractButton;
import javax.swing.SwingConstants;
+import org.springframework.richclient.application.ApplicationServicesLocator;
import org.springframework.richclient.command.AbstractCommand;
import org.springframework.richclient.command.CommandServices;
import org.springframework.richclient.command.config.CommandButtonConfigurer;
import org.springframework.richclient.command.config.CommandFaceDescriptor;
import
org.springframework.richclient.command.config.DefaultCommandButtonConfigurer;
import org.springframework.richclient.factory.ButtonFactory;
-import org.springframework.richclient.factory.DefaultButtonFactory;
-import org.springframework.richclient.factory.DefaultMenuFactory;
import org.springframework.richclient.factory.MenuFactory;
import org.springframework.richclient.image.ArrowIcon;
-import org.springframework.util.Assert;
/**
* @author Keith Donald
*/
public class DefaultCommandServices implements CommandServices {
- private static DefaultCommandServices INSTANCE = new
DefaultCommandServices();
-
private static final ArrowIcon PULL_DOWN_ICON = new
ArrowIcon(ArrowIcon.Direction.DOWN, 3, Color.BLACK);
- private ButtonFactory buttonFactory = DefaultButtonFactory.instance();
+ private ButtonFactory buttonFactory;
- private MenuFactory menuFactory = DefaultMenuFactory.instance();
+ private MenuFactory menuFactory;
private CommandButtonConfigurer defaultButtonConfigurer;
@@ -54,15 +50,6 @@
private CommandButtonConfigurer pullDownMenuButtonConfigurer;
- public static DefaultCommandServices instance() {
- return INSTANCE;
- }
-
- public static void load(DefaultCommandServices instance) {
- Assert.notNull(instance, "The sole default command services instance
is required");
- INSTANCE = instance;
- }
-
public void setButtonFactory(ButtonFactory buttonFactory) {
this.buttonFactory = buttonFactory;
}
@@ -88,10 +75,16 @@
}
public ButtonFactory getButtonFactory() {
+ if(buttonFactory == null) {
+ buttonFactory = (ButtonFactory)
ApplicationServicesLocator.services().getService(ButtonFactory.class);
+ }
return buttonFactory;
}
public MenuFactory getMenuFactory() {
+ if(menuFactory == null) {
+ menuFactory = (MenuFactory)
ApplicationServicesLocator.services().getService(MenuFactory.class);
+ }
return menuFactory;
}
Modified:
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/factory/DefaultButtonFactory.java
===================================================================
---
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/factory/DefaultButtonFactory.java
2006-07-26 12:21:04 UTC (rev 1241)
+++
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/factory/DefaultButtonFactory.java
2006-07-26 16:44:04 UTC (rev 1242)
@@ -13,24 +13,11 @@
import javax.swing.JRadioButton;
import javax.swing.JToggleButton;
-import org.springframework.util.Assert;
-
/**
* @author Keith Donald
*/
public class DefaultButtonFactory implements ButtonFactory {
- private static ButtonFactory INSTANCE = new DefaultButtonFactory();
-
- public static final ButtonFactory instance() {
- return INSTANCE;
- }
-
- public static void load(DefaultButtonFactory instance) {
- Assert.notNull(instance, "The sole default button factory instance is
required");
- INSTANCE = instance;
- }
-
public JButton createButton() {
return new JButton();
}
Modified:
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/factory/DefaultComponentFactory.java
===================================================================
---
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/factory/DefaultComponentFactory.java
2006-07-26 12:21:04 UTC (rev 1241)
+++
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/factory/DefaultComponentFactory.java
2006-07-26 16:44:04 UTC (rev 1242)
@@ -45,6 +45,7 @@
import org.apache.commons.logging.LogFactory;
import org.springframework.binding.value.ValueModel;
import org.springframework.context.MessageSource;
+import org.springframework.context.MessageSourceAware;
import org.springframework.context.MessageSourceResolvable;
import org.springframework.context.NoSuchMessageException;
import org.springframework.context.support.MessageSourceAccessor;
@@ -69,7 +70,7 @@
*
* @author Keith Donald
*/
-public class DefaultComponentFactory implements ComponentFactory {
+public class DefaultComponentFactory implements ComponentFactory,
MessageSourceAware {
private final Log logger = LogFactory.getLog(getClass());
@@ -252,7 +253,7 @@
protected ButtonFactory getButtonFactory() {
if (buttonFactory == null) {
- return DefaultButtonFactory.instance();
+ buttonFactory = (ButtonFactory)
ApplicationServicesLocator.services().getService(ButtonFactory.class);
}
return buttonFactory;
}
@@ -279,7 +280,7 @@
protected MenuFactory getMenuFactory() {
if (menuFactory == null) {
- return DefaultMenuFactory.instance();
+ menuFactory = (MenuFactory)
ApplicationServicesLocator.services().getService(MenuFactory.class);
}
return menuFactory;
}
Modified:
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/factory/DefaultMenuFactory.java
===================================================================
---
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/factory/DefaultMenuFactory.java
2006-07-26 12:21:04 UTC (rev 1241)
+++
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/factory/DefaultMenuFactory.java
2006-07-26 16:44:04 UTC (rev 1242)
@@ -14,24 +14,11 @@
import javax.swing.JPopupMenu;
import javax.swing.JRadioButtonMenuItem;
-import org.springframework.util.Assert;
-
/**
* @author Keith Donald
*/
public class DefaultMenuFactory implements MenuFactory {
- private static MenuFactory INSTANCE = new DefaultMenuFactory();
-
- public static final MenuFactory instance() {
- return INSTANCE;
- }
-
- public static void load(DefaultMenuFactory instance) {
- Assert.notNull(instance, "The sole default menu factory instance is
required");
- INSTANCE = instance;
- }
-
public JMenu createMenu() {
return new JMenu();
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
spring-rich-c-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/spring-rich-c-cvs