001 /* 002 * Copyright 2002-2007 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of 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, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.springframework.richclient.command.support; 017 018 import org.springframework.richclient.application.ApplicationServicesLocator; 019 import org.springframework.richclient.command.CommandServices; 020 import org.springframework.richclient.command.config.CommandButtonConfigurer; 021 import org.springframework.richclient.command.config.DefaultCommandButtonConfigurer; 022 import org.springframework.richclient.command.config.MenuItemButtonConfigurer; 023 import org.springframework.richclient.command.config.PullDownMenuButtonConfigurer; 024 import org.springframework.richclient.command.config.ToolBarCommandButtonConfigurer; 025 import org.springframework.richclient.factory.ButtonFactory; 026 import org.springframework.richclient.factory.ComponentFactory; 027 import org.springframework.richclient.factory.MenuFactory; 028 029 /** 030 * @author Keith Donald 031 */ 032 public class DefaultCommandServices implements CommandServices { 033 private ComponentFactory componentFactory; 034 035 private ButtonFactory toolBarButtonFactory; 036 037 private ButtonFactory buttonFactory; 038 039 private MenuFactory menuFactory; 040 041 private CommandButtonConfigurer defaultButtonConfigurer; 042 043 private CommandButtonConfigurer toolBarButtonConfigurer; 044 045 private CommandButtonConfigurer menuItemButtonConfigurer; 046 047 private CommandButtonConfigurer pullDownMenuButtonConfigurer; 048 049 public void setComponentFactory(ComponentFactory componentFactory){ 050 this.componentFactory = componentFactory; 051 } 052 053 public void setToolBarButtonFactory(ButtonFactory buttonFactory){ 054 this.toolBarButtonFactory = buttonFactory; 055 } 056 057 public void setButtonFactory(ButtonFactory buttonFactory) { 058 this.buttonFactory = buttonFactory; 059 } 060 061 public void setMenuFactory(MenuFactory menuFactory) { 062 this.menuFactory = menuFactory; 063 } 064 065 public void setDefaultButtonConfigurer(CommandButtonConfigurer defaultButtonConfigurer) { 066 this.defaultButtonConfigurer = defaultButtonConfigurer; 067 } 068 069 public void setToolBarButtonConfigurer(CommandButtonConfigurer toolBarButtonConfigurer) { 070 this.toolBarButtonConfigurer = toolBarButtonConfigurer; 071 } 072 073 public void setMenuItemButtonConfigurer(CommandButtonConfigurer menuItemButtonConfigurer) { 074 this.menuItemButtonConfigurer = menuItemButtonConfigurer; 075 } 076 077 public void setPullDownMenuButtonConfigurer(CommandButtonConfigurer pullDownMenuButtonConfigurer) { 078 this.pullDownMenuButtonConfigurer = pullDownMenuButtonConfigurer; 079 } 080 081 public ComponentFactory getComponentFactory(){ 082 if(componentFactory == null){ 083 componentFactory = (ComponentFactory) ApplicationServicesLocator.services().getService(ComponentFactory.class); 084 } 085 return componentFactory; 086 } 087 088 public ButtonFactory getToolBarButtonFactory(){ 089 if(toolBarButtonFactory == null){ 090 toolBarButtonFactory = (ButtonFactory) ApplicationServicesLocator.services().getService(ButtonFactory.class); 091 } 092 return toolBarButtonFactory; 093 } 094 095 public ButtonFactory getButtonFactory() { 096 if(buttonFactory == null) { 097 buttonFactory = (ButtonFactory) ApplicationServicesLocator.services().getService(ButtonFactory.class); 098 } 099 return buttonFactory; 100 } 101 102 public MenuFactory getMenuFactory() { 103 if(menuFactory == null) { 104 menuFactory = (MenuFactory) ApplicationServicesLocator.services().getService(MenuFactory.class); 105 } 106 return menuFactory; 107 } 108 109 public CommandButtonConfigurer getDefaultButtonConfigurer() { 110 if (defaultButtonConfigurer == null) { 111 defaultButtonConfigurer = createDefaultButtonConfigurer(); 112 } 113 return defaultButtonConfigurer; 114 } 115 116 public CommandButtonConfigurer getToolBarButtonConfigurer() { 117 if (toolBarButtonConfigurer == null) { 118 toolBarButtonConfigurer = createToolBarButtonConfigurer(); 119 } 120 return toolBarButtonConfigurer; 121 } 122 123 public CommandButtonConfigurer getMenuItemButtonConfigurer() { 124 if (menuItemButtonConfigurer == null) { 125 menuItemButtonConfigurer = createMenuItemButtonConfigurer(); 126 } 127 return menuItemButtonConfigurer; 128 } 129 130 public CommandButtonConfigurer getPullDownMenuButtonConfigurer() { 131 if (pullDownMenuButtonConfigurer == null) { 132 pullDownMenuButtonConfigurer = createPullDownMenuButtonConfigurer(); 133 } 134 return pullDownMenuButtonConfigurer; 135 } 136 137 protected CommandButtonConfigurer createDefaultButtonConfigurer() { 138 return new DefaultCommandButtonConfigurer(); 139 } 140 141 protected CommandButtonConfigurer createToolBarButtonConfigurer() { 142 return new ToolBarCommandButtonConfigurer(); 143 } 144 145 protected CommandButtonConfigurer createMenuItemButtonConfigurer() { 146 return new MenuItemButtonConfigurer(); 147 } 148 149 protected CommandButtonConfigurer createPullDownMenuButtonConfigurer() { 150 return new PullDownMenuButtonConfigurer(); 151 } 152 153 }