KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > views > memory > ViewTabEnablementManager


1 /*******************************************************************************
2  * Copyright (c) 2004, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.debug.internal.ui.views.memory;
13
14 import org.eclipse.swt.events.SelectionEvent;
15 import org.eclipse.swt.events.SelectionListener;
16 import org.eclipse.swt.widgets.TabFolder;
17 import org.eclipse.swt.widgets.TabItem;
18
19 /**
20  * Controls view tab enablement based on tab folder selection
21  *
22  * @since 3.0
23  */

24 public class ViewTabEnablementManager implements SelectionListener {
25
26     /* (non-Javadoc)
27      * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
28      */

29     public void widgetSelected(SelectionEvent e) {
30         if (e.getSource() instanceof TabFolder)
31         {
32             handleTabFolderSelection(e);
33         }
34     }
35
36     /* (non-Javadoc)
37      * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
38      */

39     public void widgetDefaultSelected(SelectionEvent e) {
40          
41         
42     }
43     
44     private void handleTabFolderSelection(SelectionEvent event)
45     {
46         TabFolder folder = (TabFolder)event.getSource();
47         
48         TabItem[] selectedItems = folder.getSelection();
49         TabItem selectedItem;
50         IMemoryViewTab selectedViewTab;
51         
52         // get selected view tab
53
if (selectedItems.length > 0)
54         {
55             selectedItem = selectedItems[0];
56             
57             Object JavaDoc obj = selectedItem.getData();
58             
59             if (obj instanceof IMemoryViewTab)
60             {
61                 selectedViewTab = (IMemoryViewTab)obj;
62             }
63             else
64             {
65                 return;
66             }
67         }
68         else
69         {
70             return;
71         }
72         
73         // get all tabs
74
TabItem[] allTabs = folder.getItems();
75         
76         // check all tabs to make sure they are enabled/disabled properly
77
for (int i=0; i<allTabs.length; i++)
78         {
79             IMemoryViewTab viewTab;
80             Object JavaDoc obj = allTabs[i].getData();
81             
82             if (obj instanceof IMemoryViewTab)
83             {
84                 viewTab = (IMemoryViewTab)obj;
85                 
86                 // if view tab matches the selected item
87
if (viewTab == selectedViewTab && !viewTab.isEnabled() )
88                 {
89                     // if the item has been selected and this tab is not enabled
90
// enable it.
91
viewTab.setEnabled(true);
92                     viewTab.getRendering().activated();
93                     
94                 }
95                 else if (viewTab != selectedViewTab && viewTab.isEnabled())
96                 {
97                     // if the tab is not selected, disable it
98
viewTab.setEnabled(false);
99                     viewTab.getRendering().deactivated();
100                 }
101             }
102         }
103     }
104
105 }
106
Popular Tags