001 /*
002 * Copyright 2002-2004 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.command;
017
018 import javax.swing.Icon;
019
020 import org.springframework.richclient.command.config.CommandFaceDescriptor;
021
022 /**
023 * A {@link CommandGroup} that can only contain ToggleCommands and for which only one togglecommand can be
024 * chosen. Comparable to a radio button group.
025 */
026 public class ExclusiveCommandGroup extends CommandGroup {
027
028 private ExclusiveCommandGroupSelectionController controller = new ExclusiveCommandGroupSelectionController();
029
030 public ExclusiveCommandGroup() {
031 super();
032 }
033
034 public ExclusiveCommandGroup(String groupId) {
035 super(groupId);
036 }
037
038 public ExclusiveCommandGroup(String groupId, CommandFaceDescriptor faceDescriptor) {
039 super(groupId, faceDescriptor);
040 }
041
042 public ExclusiveCommandGroup(String groupId, CommandRegistry commandRegistry) {
043 super(groupId, commandRegistry);
044 }
045
046 public ExclusiveCommandGroup(String id, String encodedLabel) {
047 super(id, encodedLabel);
048 }
049
050 public ExclusiveCommandGroup(String id, String encodedLabel, Icon icon, String caption) {
051 super(id, encodedLabel, icon, caption);
052 }
053
054 public void setAllowsEmptySelection(boolean allowsEmptySelection) {
055 controller.setAllowsEmptySelection(allowsEmptySelection);
056 }
057
058 public boolean getAllowsEmptySelection() {
059 return controller.getAllowsEmptySelection();
060 }
061
062 protected ExclusiveCommandGroupSelectionController getSelectionController() {
063 return controller;
064 }
065
066 public boolean isAllowedMember(AbstractCommand prospectiveMember) {
067 return prospectiveMember instanceof ToggleCommand;
068 }
069 }