753d783dd53ef8c0c73f80357e9c41aa6cbb258e
1 /*******************************************************************************
2 * Copyright (c) 2012, 2013 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
<>();
75 public void dispose() {
77 for (ITmfViewer viewer
: fViewers
.values()) {
80 if (fFolder
!= null) {
86 * Disposes of all the viewers contained in the folder and restart to a
90 for (ITmfViewer viewer
: fViewers
.values()) {
99 * Create a new tab that will hold the viewer content. The viewer name will
100 * be used as the name for the tab. The viewer ID must be unique and can be
101 * used to retrieve the viewer from the folder.
103 * The parent of the viewer control must be the folder returned by
104 * {@link #getParentFolder()}
107 * The viewer to put in the new tab
109 * The ID that will be assigned to this viewer for easy
112 * The style of the widget to build
113 * @return true on success, false otherwise
115 public boolean addTab(ITmfViewer viewer
, String viewerID
, int style
) {
117 || viewer
.getControl().getParent() != fFolder
118 || fViewers
.containsKey(viewerID
)) {
121 CTabItem item
= new CTabItem(fFolder
, style
);
122 item
.setText(viewer
.getName());
123 item
.setControl(viewer
.getControl());
124 // Register the viewer in the map to dispose it at closing time
125 fViewers
.put(viewerID
, viewer
);
130 * Gets the folder that will be use as the parent of tabs that will hold the
133 * In order to be able to add new tabs in this view, the parent of the
134 * viewer control has to be this composite.
136 * @return the folder composite to use as the parent for the viewer control
139 public Composite
getParentFolder() {
144 * Gets a viewer based on his name.
147 * The name of the viewer to find in the folder
148 * @return The viewer which name is viewerName, or null if there is no such
151 public ITmfViewer
getViewer(String viewerName
) {
152 return fViewers
.get(viewerName
);
156 * Gets the viewers list contained in the folder view. The list can return
157 * the viewers in any order. It is not to be assumed that the viewers are
158 * returned in the same order as they were inserted.
160 * @return a collection of viewers contained in this view.
162 public Collection
<ITmfViewer
> getViewers() {
163 return fViewers
.values();
167 * Selects the tab at the specified index from the insertion order
170 * The index of the tab to be selected
171 * @throws SWTException
173 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
175 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
176 * thread that created the receiver</li>
179 public void setSelection(int index
) throws SWTException
{
180 fFolder
.setSelection(index
);
184 * Initializes the folder or put it a back to a clean state.
186 private void initFolder() {
187 if (fFolder
!= null) {
190 fFolder
= new CTabFolder(this, SWT
.LEFT
| SWT
.BORDER
);
191 fFolder
.setSimple(false);
This page took 0.06348 seconds and 5 git commands to generate.