001 /*
002 * Copyright 2002-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.dialog.control;
017
018 import javax.swing.JLabel;
019 import javax.swing.JTabbedPane;
020 import javax.swing.event.ChangeEvent;
021 import javax.swing.event.ChangeListener;
022
023 import org.springframework.richclient.util.EventListenerListHelper.EventBroadcastException;
024
025 import junit.framework.TestCase;
026
027 /**
028 *
029 * @author Peter De Bruycker
030 */
031 public class ExtTabbedPaneTests extends TestCase {
032 // testcase for RCP-528
033 public void testGetTabInsideChangeHandlerThrowsIndexOutOfBoundsException() {
034 final ExtTabbedPane extTabbedPane = new ExtTabbedPane();
035
036 // when the changelistener performs a getTab(index) call, an IndexOutOfBoundsException
037 extTabbedPane.addChangeListener(new ChangeListener() {
038 public void stateChanged(ChangeEvent e) {
039 JTabbedPane tabbedPane = (JTabbedPane) extTabbedPane.getControl();
040 int index = tabbedPane.getSelectedIndex();
041
042 if (index >= 0) {
043 index = extTabbedPane.convertUIIndexToModelIndex(index);
044 Tab tab = extTabbedPane.getTab(index);
045 assertNotNull(tab);
046 }
047 }
048 });
049
050 Tab tab1 = new Tab("test1", new JLabel("test1"));
051 Tab tab2 = new Tab("test2", new JLabel("test2"));
052
053 try {
054 extTabbedPane.addTab(tab1);
055 }
056 catch (EventBroadcastException e) {
057 fail(e.getMessage());
058 }
059
060
061 try {
062 extTabbedPane.addTab(0, tab2);
063 }
064 catch (EventBroadcastException e) {
065 fail(e.getMessage());
066 }
067
068 extTabbedPane.selectTab(tab1);
069
070 try {
071 extTabbedPane.removeTab(tab1);
072 }
073 catch (EventBroadcastException e) {
074 fail(e.getMessage());
075 }
076 }
077 }