1 /*******************************************************************************
2 * Copyright (c) 2012 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Mathieu Denis <mathieu.denis@polymtl.ca> - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.tabsview
;
15 import java
.util
.Collection
;
16 import java
.util
.HashMap
;
18 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.ITmfViewer
;
19 import org
.eclipse
.swt
.SWT
;
20 import org
.eclipse
.swt
.SWTException
;
21 import org
.eclipse
.swt
.custom
.CTabFolder
;
22 import org
.eclipse
.swt
.custom
.CTabItem
;
23 import org
.eclipse
.swt
.layout
.FillLayout
;
24 import org
.eclipse
.swt
.widgets
.Composite
;
27 * Allows the user to create multiple tabs which makes it look like folders. It
28 * simplifies the management of the viewer contained in each tab.
30 * The indexing of the viewers is based on their name.
32 * @author Mathieu Denis
36 public class TmfViewerFolder
extends Composite
{
39 * The list of viewers in the folder
41 private final HashMap
<String
, ITmfViewer
> fViewers
;
44 * The parent folder that contains all viewers
46 private CTabFolder fFolder
;
49 * Constructor with empty style
52 * The parent composite
54 public TmfViewerFolder(Composite parent
) {
55 this(parent
, SWT
.NONE
);
62 * The parent composite
64 * The style of the view that will be created
66 public TmfViewerFolder(Composite parent
, int style
) {
68 setLayout(new FillLayout());
70 fViewers
= new HashMap
<String
, ITmfViewer
>();
77 * @see org.eclipse.swt.widgets.Widget#dispose()
80 public void dispose() {
82 for (ITmfViewer viewer
: fViewers
.values()) {
85 if (fFolder
!= null) {
91 * Disposes of all the viewers contained in the folder and restart to a
95 for (ITmfViewer viewer
: fViewers
.values()) {
104 * Create a new tab that will hold the viewer content. The viewer name will
105 * be used as the name for the tab. The viewer ID must be unique and can be
106 * used to retrieve the viewer from the folder.
108 * The parent of the viewer control must be the folder returned by
109 * {@link #getParentFolder()}
112 * The viewer to put in the new tab
114 * The ID that will be assigned to this viewer for easy
117 * The style of the widget to build
118 * @return true on success, false otherwise
120 public boolean addTab(ITmfViewer viewer
, String viewerID
, int style
) {
122 || viewer
.getControl().getParent() != fFolder
123 || fViewers
.containsKey(viewerID
)) {
126 CTabItem item
= new CTabItem(fFolder
, style
);
127 item
.setText(viewer
.getName());
128 item
.setControl(viewer
.getControl());
129 // Register the viewer in the map to dispose it at closing time
130 fViewers
.put(viewerID
, viewer
);
135 * Gets the folder that will be use as the parent of tabs that will hold the
138 * In order to be able to add new tabs in this view, the parent of the
139 * viewer control has to be this composite.
141 * @return the folder composite to use as the parent for the viewer control
144 public Composite
getParentFolder() {
149 * Gets a viewer based on his name.
152 * The name of the viewer to find in the folder
153 * @return The viewer which name is viewerName, or null if there is no such
156 public ITmfViewer
getViewer(String viewerName
) {
157 return fViewers
.get(viewerName
);
161 * Gets the viewers list contained in the folder view. The list can return
162 * the viewers in any order. It is not to be assumed that the viewers are
163 * returned in the same order as they were inserted.
165 * @return a collection of viewers contained in this view.
167 public Collection
<ITmfViewer
> getViewers() {
168 return fViewers
.values();
172 * Selects the tab at the specified index from the insertion order
175 * The index of the tab to be selected
176 * @throws SWTException
178 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
180 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
181 * thread that created the receiver</li>
184 public void setSelection(int index
) throws SWTException
{
185 fFolder
.setSelection(index
);
189 * Initializes the folder or put it a back to a clean state.
191 private void initFolder() {
192 if (fFolder
!= null) {
195 fFolder
= new CTabFolder(this, SWT
.LEFT
| SWT
.BORDER
);
196 fFolder
.setSimple(false);
This page took 0.036398 seconds and 6 git commands to generate.