1 package org.simantics.views.swt.client.impl;
3 import java.util.HashSet;
7 import org.eclipse.jface.viewers.ISelectionChangedListener;
8 import org.eclipse.jface.viewers.ISelectionProvider;
9 import org.eclipse.jface.viewers.SelectionChangedEvent;
10 import org.eclipse.swt.SWT;
11 import org.eclipse.swt.custom.CTabFolder;
12 import org.eclipse.swt.custom.CTabItem;
13 import org.eclipse.swt.widgets.Composite;
14 import org.eclipse.swt.widgets.Control;
15 import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite;
16 import org.simantics.utils.ui.jface.BasePostSelectionProvider;
17 import org.simantics.views.ViewUtils.LayoutBean;
18 import org.simantics.views.swt.client.base.ISWTViewNode;
19 import org.simantics.views.swt.client.base.SingleSWTViewNode;
21 public class SWTTabFolder extends SingleSWTViewNode<CTabFolder> {
23 private static final long serialVersionUID = -8003676031533344133L;
25 public List<String> childNames;
27 public LayoutBean layout;
29 final BasePostSelectionProvider selectionProvider = new BasePostSelectionProvider();
31 ISelectionChangedListener selectionListener = new ISelectionChangedListener() {
34 public void selectionChanged(SelectionChangedEvent event) {
35 selectionProvider.firePostSelection(event.getSelection());
40 private CTabItem createItem(int index, CTabFolder folder, Control control) {
42 CTabItem item = new CTabItem(folder, SWT.NONE, index);
43 item.setControl(control);
49 public void createControls(Composite parent) {
50 control = new CTabFolder(parent, SWT.BOTTOM | SWT.FLAT);
52 createChildComposites();
56 protected void childrenChanged() {
57 // FIXME: this is probably not what is intended, just modified it like this to get rid of the NPE it was producing.
58 if (control != null && !control.isDisposed())
62 protected void updateFolder() {
64 assert(childNames != null);
66 HashSet<Control> existing = new HashSet<Control>();
68 for(CTabItem c : control.getItems()) {
69 existing.add(c.getControl());
72 int index = existing.size();
73 boolean hasSomeSelectionProviders = false;
75 for(ISWTViewNode node : getChildComposites()) {
77 Control c = node.getControl();
78 if(c != null && !existing.contains(c)) {
80 CTabItem item = createItem(index, control, c);
81 item.setText(childNames.get(index++));
83 for(Control c2 : getControls(item)) {
84 if(c2 instanceof GraphExplorerComposite) {
85 GraphExplorerComposite gec = (GraphExplorerComposite)c2;
86 ISelectionProvider sp = (ISelectionProvider)gec.getAdapter(ISelectionProvider.class);
87 sp.addSelectionChangedListener(selectionListener);
88 hasSomeSelectionProviders = true;
95 if(hasSomeSelectionProviders) {
96 // We use our combined selection provider
97 getSite().setSelectionProvider(selectionProvider);
100 control.setSelection(0);
104 Set<Control> getControls(CTabItem item) {
105 HashSet<Control> result = new HashSet<Control>();
106 forControl(item.getControl(), result);
110 void forControl(Control control, HashSet<Control> controls) {
111 controls.add(control);
112 if(control instanceof Composite) {
113 Composite composite = (Composite)control;
114 for(Control child : composite.getChildren()) forControl(child, controls);
118 public void synchronizeChildNames(List<String> childNames) {
122 final public void synchronizeLayout(LayoutBean layout) {