X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.views.swt.client%2Fsrc%2Forg%2Fsimantics%2Fviews%2Fswt%2Fclient%2Fimpl%2FSWTTabFolder.java;h=b1daf17556ee079acfa92c7f5f67a92dc8d0b99a;hb=refs%2Fchanges%2F38%2F238%2F2;hp=b8aebe5375923e6b1239aa91cf7ab481941eed94;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.views.swt.client/src/org/simantics/views/swt/client/impl/SWTTabFolder.java b/bundles/org.simantics.views.swt.client/src/org/simantics/views/swt/client/impl/SWTTabFolder.java index b8aebe537..b1daf1755 100644 --- a/bundles/org.simantics.views.swt.client/src/org/simantics/views/swt/client/impl/SWTTabFolder.java +++ b/bundles/org.simantics.views.swt.client/src/org/simantics/views/swt/client/impl/SWTTabFolder.java @@ -1,125 +1,125 @@ -package org.simantics.views.swt.client.impl; - -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CTabFolder; -import org.eclipse.swt.custom.CTabItem; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite; -import org.simantics.utils.ui.jface.BasePostSelectionProvider; -import org.simantics.views.ViewUtils.GridLayoutBean; -import org.simantics.views.swt.client.base.ISWTViewNode; -import org.simantics.views.swt.client.base.SingleSWTViewNode; - -public class SWTTabFolder extends SingleSWTViewNode { - - private static final long serialVersionUID = -8003676031533344133L; - - public List childNames; - - public GridLayoutBean layout; - - final BasePostSelectionProvider selectionProvider = new BasePostSelectionProvider(); - - ISelectionChangedListener selectionListener = new ISelectionChangedListener() { - - @Override - public void selectionChanged(SelectionChangedEvent event) { - selectionProvider.firePostSelection(event.getSelection()); - } - - }; - - private CTabItem createItem(int index, CTabFolder folder, Control control) { - - CTabItem item = new CTabItem(folder, SWT.NONE, index); - item.setControl(control); - return item; - - } - - @Override - public void createControls(Composite parent) { - control = new CTabFolder(parent, SWT.BOTTOM | SWT.FLAT); - setProperties(); - createChildComposites(); - updateFolder(); - } - - protected void childrenChanged() { - // FIXME: this is probably not what is intended, just modified it like this to get rid of the NPE it was producing. - if (control != null && !control.isDisposed()) - updateFolder(); - } - - protected void updateFolder() { - - assert(childNames != null); - - HashSet existing = new HashSet(); - - for(CTabItem c : control.getItems()) { - existing.add(c.getControl()); - } - - int index = existing.size(); - boolean hasSomeSelectionProviders = false; - - for(ISWTViewNode node : getChildComposites()) { - - Control c = node.getControl(); - if(c != null && !existing.contains(c)) { - - CTabItem item = createItem(index, control, c); - item.setText(childNames.get(index++)); - - for(Control c2 : getControls(item)) { - if(c2 instanceof GraphExplorerComposite) { - GraphExplorerComposite gec = (GraphExplorerComposite)c2; - ISelectionProvider sp = (ISelectionProvider)gec.getAdapter(ISelectionProvider.class); - sp.addSelectionChangedListener(selectionListener); - hasSomeSelectionProviders = true; - } - } - - } - } - - if(hasSomeSelectionProviders) { - // We use our combined selection provider - getSite().setSelectionProvider(selectionProvider); - } - - control.setSelection(0); - control.update(); - } - - Set getControls(CTabItem item) { - HashSet result = new HashSet(); - forControl(item.getControl(), result); - return result; - } - - void forControl(Control control, HashSet controls) { - controls.add(control); - if(control instanceof Composite) { - Composite composite = (Composite)control; - for(Control child : composite.getChildren()) forControl(child, controls); - } - } - - public void synchronizeChildNames(List childNames) { - - } - - final public void synchronizeLayout(GridLayoutBean layout) { - } - -} +package org.simantics.views.swt.client.impl; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CTabFolder; +import org.eclipse.swt.custom.CTabItem; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite; +import org.simantics.utils.ui.jface.BasePostSelectionProvider; +import org.simantics.views.ViewUtils.LayoutBean; +import org.simantics.views.swt.client.base.ISWTViewNode; +import org.simantics.views.swt.client.base.SingleSWTViewNode; + +public class SWTTabFolder extends SingleSWTViewNode { + + private static final long serialVersionUID = -8003676031533344133L; + + public List childNames; + + public LayoutBean layout; + + final BasePostSelectionProvider selectionProvider = new BasePostSelectionProvider(); + + ISelectionChangedListener selectionListener = new ISelectionChangedListener() { + + @Override + public void selectionChanged(SelectionChangedEvent event) { + selectionProvider.firePostSelection(event.getSelection()); + } + + }; + + private CTabItem createItem(int index, CTabFolder folder, Control control) { + + CTabItem item = new CTabItem(folder, SWT.NONE, index); + item.setControl(control); + return item; + + } + + @Override + public void createControls(Composite parent) { + control = new CTabFolder(parent, SWT.BOTTOM | SWT.FLAT); + setProperties(); + createChildComposites(); + updateFolder(); + } + + protected void childrenChanged() { + // FIXME: this is probably not what is intended, just modified it like this to get rid of the NPE it was producing. + if (control != null && !control.isDisposed()) + updateFolder(); + } + + protected void updateFolder() { + + assert(childNames != null); + + HashSet existing = new HashSet(); + + for(CTabItem c : control.getItems()) { + existing.add(c.getControl()); + } + + int index = existing.size(); + boolean hasSomeSelectionProviders = false; + + for(ISWTViewNode node : getChildComposites()) { + + Control c = node.getControl(); + if(c != null && !existing.contains(c)) { + + CTabItem item = createItem(index, control, c); + item.setText(childNames.get(index++)); + + for(Control c2 : getControls(item)) { + if(c2 instanceof GraphExplorerComposite) { + GraphExplorerComposite gec = (GraphExplorerComposite)c2; + ISelectionProvider sp = (ISelectionProvider)gec.getAdapter(ISelectionProvider.class); + sp.addSelectionChangedListener(selectionListener); + hasSomeSelectionProviders = true; + } + } + + } + } + + if(hasSomeSelectionProviders) { + // We use our combined selection provider + getSite().setSelectionProvider(selectionProvider); + } + + control.setSelection(0); + control.update(); + } + + Set getControls(CTabItem item) { + HashSet result = new HashSet(); + forControl(item.getControl(), result); + return result; + } + + void forControl(Control control, HashSet controls) { + controls.add(control); + if(control instanceof Composite) { + Composite composite = (Composite)control; + for(Control child : composite.getChildren()) forControl(child, controls); + } + } + + public void synchronizeChildNames(List childNames) { + + } + + final public void synchronizeLayout(LayoutBean layout) { + } + +}