1   /*
2    * Copyright 2002-2008 the original author or authors.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5    * use this file except in compliance with the License. You may obtain a copy of
6    * the License at
7    * 
8    * http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations under
14   * the License.
15   */
16  package org.springframework.richclient.dialog.control;
17  
18  import javax.swing.JLabel;
19  import javax.swing.JTabbedPane;
20  import javax.swing.event.ChangeEvent;
21  import javax.swing.event.ChangeListener;
22  
23  import org.springframework.richclient.util.EventListenerListHelper.EventBroadcastException;
24  
25  import junit.framework.TestCase;
26  
27  /**
28   * 
29   * @author Peter De Bruycker
30   */
31  public class ExtTabbedPaneTests extends TestCase {
32      // testcase for RCP-528
33      public void testGetTabInsideChangeHandlerThrowsIndexOutOfBoundsException() {
34          final ExtTabbedPane extTabbedPane = new ExtTabbedPane();
35  
36          // when the changelistener performs a getTab(index) call, an IndexOutOfBoundsException
37          extTabbedPane.addChangeListener(new ChangeListener() {
38              public void stateChanged(ChangeEvent e) {
39                  JTabbedPane tabbedPane = (JTabbedPane) extTabbedPane.getControl();
40                  int index = tabbedPane.getSelectedIndex();
41  
42                  if (index >= 0) {
43                      index = extTabbedPane.convertUIIndexToModelIndex(index);
44                      Tab tab = extTabbedPane.getTab(index);
45                      assertNotNull(tab);
46                  }
47              }
48          });
49  
50          Tab tab1 = new Tab("test1", new JLabel("test1"));
51          Tab tab2 = new Tab("test2", new JLabel("test2"));
52          
53          try {
54              extTabbedPane.addTab(tab1);
55          }
56          catch (EventBroadcastException e) {
57              fail(e.getMessage());
58          }
59  
60  
61          try {
62              extTabbedPane.addTab(0, tab2);
63          }
64          catch (EventBroadcastException e) {
65              fail(e.getMessage());
66          }
67          
68          extTabbedPane.selectTab(tab1);
69  
70          try {
71              extTabbedPane.removeTab(tab1);
72          }
73          catch (EventBroadcastException e) {
74              fail(e.getMessage());
75          }
76  }
77  }