blob: 5f2704bde9e5fda3a686188cd97b9115dc04cc69 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
/*******************************************************************************
* Copyright (c) 2011 Mia-Software.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Nicolas Bros (Mia-Software) - initial API and implementation
* Nicolas Bros (Mia-Software) - Bug 334116 - common tree view with columns
*******************************************************************************/
package org.eclipse.papyrus.emf.facet.common.ui.internal.controls.wrappers;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.Tree;
/**
* A factory to obtain a {@link SortableWidget}, that provides a unified API over both SWT
* {@link Tree} and {@link Table}.
*/
public final class SortableWidgetFactory {
private SortableWidgetFactory() {
// utility class
}
/**
* Get a {@link SortableWidget} for the given {@link Viewer}, that can be either a
* {@link TreeViewer} or a {@link TableViewer}.
*
* @param viewer
* a {@link TreeViewer} or a {@link TableViewer}
* @return a {@link SortableWidget} that delegates to the given viewer
*/
public static SortableWidget createSortableWidget(final Viewer viewer) {
if (viewer instanceof TreeViewer) {
TreeViewer treeViewer = (TreeViewer) viewer;
return new SortableTree(treeViewer);
} else if (viewer instanceof TableViewer) {
TableViewer tableViewer = (TableViewer) viewer;
return new SortableTable(tableViewer);
}
throw new IllegalArgumentException();
}
}
|