001: /*******************************************************************************
002: * Copyright (c) 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.tests.views.properties.tabbed.override.tablist;
011:
012: import org.eclipse.swt.widgets.Composite;
013: import org.eclipse.ui.tests.views.properties.tabbed.model.Element;
014: import org.eclipse.ui.tests.views.properties.tabbed.override.items.IOverrideTestsItem;
015: import org.eclipse.ui.views.properties.tabbed.ITabItem;
016:
017: /**
018: * The abstract implementation of a tab list.
019: * <p>
020: * The OverrideTestsView TabbedPropertySheetPage example is a look at the
021: * properties view after the migration of a TabFolder/TabItem framework to the
022: * tabbed properties view. In the case of a TabFolder, the folder (provider)
023: * knows both the tab labels and tab items. This aligns to the tabbed properties
024: * view, but the tab labels are tab descriptors and tab items are section
025: * descriptions. This does not work with the default framework as the tabs
026: * provide the sections. In this case, the IOverridableTabListContentProvider
027: * framework has been provided.
028: * <p>
029: * The overridable tab list is a content provider that provides both the
030: * sections and the tab labels.
031: *
032: * @author Anthony Hunter
033: * @since 3.4
034: */
035: public abstract class AbstractTabList implements IOverrideTestsTabList {
036:
037: private Composite composite;
038:
039: private int selectedTabItem;
040:
041: /*
042: * (non-Javadoc)
043: *
044: * @see org.eclipse.ui.tests.views.properties.tabbed.override.tablist.IOverrideTestsTabList#appliesTo(org.eclipse.ui.tests.views.properties.tabbed.model.Element)
045: */
046: public boolean appliesTo(Element element) {
047: return false;
048: }
049:
050: /*
051: * (non-Javadoc)
052: *
053: * @see org.eclipse.ui.tests.views.properties.tabbed.override.tablist.IOverrideTestsTabList#createControls(org.eclipse.swt.widgets.Composite)
054: */
055: public void createControls(Composite parent) {
056: this .composite = parent;
057: OverrideTestsTabItem activeTab = (OverrideTestsTabItem) (getTabs()[selectedTabItem]);
058: activeTab.getItem().createControls(parent);
059: }
060:
061: /*
062: * (non-Javadoc)
063: *
064: * @see org.eclipse.ui.tests.views.properties.tabbed.override.tablist.IOverrideTestsTabList#dispose()
065: */
066: public void dispose() {
067: OverrideTestsTabItem activeTab = (OverrideTestsTabItem) (getTabs()[selectedTabItem]);
068: activeTab.getItem().dispose();
069: }
070:
071: /*
072: * (non-Javadoc)
073: *
074: * @see org.eclipse.ui.views.properties.tabbed.IOverridableTabList#getTabs()
075: */
076: public ITabItem[] getTabs() {
077: IOverrideTestsItem[] items = getItems();
078: OverrideTestsTabItem[] tabs = new OverrideTestsTabItem[items.length];
079:
080: for (int i = 0; i < items.length; i++) {
081: tabs[i] = new OverrideTestsTabItem(items[i]);
082: if (i == selectedTabItem) {
083: tabs[i].setSelected(true);
084: }
085: }
086:
087: return tabs;
088: }
089:
090: /*
091: * (non-Javadoc)
092: *
093: * @see org.eclipse.ui.tests.views.properties.tabbed.override.tablist.IOverrideTestsTabList#selectionChanged(org.eclipse.ui.tests.views.properties.tabbed.model.Element)
094: */
095: public void selectionChanged(Element element) {
096: ITabItem[] tabs = getTabs();
097: for (int i = 0; i < tabs.length; i++) {
098: if (tabs[i].getText().equals(element.getName())) {
099: selectedTabItem = i;
100: break;
101: }
102: }
103: }
104:
105: /*
106: * (non-Javadoc)
107: *
108: * @see org.eclipse.ui.views.properties.tabbed.IOverridableTabList#selectTab(int)
109: */
110: public void selectTab(int index) {
111: if (selectedTabItem == index) {
112: return;
113: }
114: OverrideTestsTabItem activeTab = (OverrideTestsTabItem) (getTabs()[selectedTabItem]);
115: activeTab.getItem().dispose();
116:
117: selectedTabItem = index;
118:
119: activeTab = (OverrideTestsTabItem) (getTabs()[selectedTabItem]);
120: activeTab.getItem().createControls(composite);
121: composite.layout(true);
122: }
123: }
|