01: /*******************************************************************************
02: * Copyright (c) 2004 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Common Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/cpl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.examples.presentation.wrappedtabs;
11:
12: import org.eclipse.jface.action.ContributionItem;
13: import org.eclipse.swt.SWT;
14: import org.eclipse.swt.events.SelectionAdapter;
15: import org.eclipse.swt.events.SelectionEvent;
16: import org.eclipse.swt.widgets.Menu;
17: import org.eclipse.swt.widgets.MenuItem;
18: import org.eclipse.ui.presentations.IPresentablePart;
19:
20: /**
21: * @since 3.0
22: */
23: public class ShowToolbarContributionItem extends ContributionItem {
24: private WrappedTabsPartPresentation presentation;
25:
26: private static final String DATA_ITEM = "org.eclipse.ui.examples.presentation.wrappedtabs.PartListContributionItem.DATA_ITEM";
27:
28: private SelectionAdapter selectionListener = new SelectionAdapter() {
29: public void widgetSelected(SelectionEvent e) {
30: presentation.showToolbar(((MenuItem) e.widget)
31: .getSelection());
32: }
33: };
34:
35: public ShowToolbarContributionItem(
36: WrappedTabsPartPresentation presentation) {
37: this .presentation = presentation;
38: }
39:
40: public void dispose() {
41: super .dispose();
42: presentation = null;
43: selectionListener = null;
44: }
45:
46: public void fill(Menu menu, int index) {
47: MenuItem item = new MenuItem(menu, SWT.CHECK, index);
48: item.setText("S&how toolbar");
49: item.addSelectionListener(selectionListener);
50: item.setSelection(presentation.isShowingToolbar());
51:
52: IPresentablePart current = presentation.getCurrent();
53: item
54: .setEnabled(current != null
55: && current.getToolBar() != null);
56: }
57:
58: public boolean isDynamic() {
59: return true;
60: }
61: }
|