X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.views.swt.client%2Fsrc%2Forg%2Fsimantics%2Fviews%2Fswt%2Fclient%2Fimpl%2FSWTExplorer.java;h=1666413e9c56d45ee16e8afeda3baf3e07e17446;hp=3c0ce5a1f0504273960714cb0d470ff2159893e8;hb=b7250834202635a09dd18e25370ed9b4c32b1380;hpb=089832880807e21e696b5f321a81fa93473c07a9 diff --git a/bundles/org.simantics.views.swt.client/src/org/simantics/views/swt/client/impl/SWTExplorer.java b/bundles/org.simantics.views.swt.client/src/org/simantics/views/swt/client/impl/SWTExplorer.java index 3c0ce5a1f..1666413e9 100644 --- a/bundles/org.simantics.views.swt.client/src/org/simantics/views/swt/client/impl/SWTExplorer.java +++ b/bundles/org.simantics.views.swt.client/src/org/simantics/views/swt/client/impl/SWTExplorer.java @@ -1,195 +1,195 @@ -package org.simantics.views.swt.client.impl; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.eclipse.jface.viewers.IPostSelectionProvider; -import org.eclipse.jface.viewers.ISelection; -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.widgets.Composite; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Listener; -import org.eclipse.ui.IWorkbenchSite; -import org.simantics.browsing.ui.Column; -import org.simantics.browsing.ui.StatePersistor; -import org.simantics.browsing.ui.swt.PassThruInputSource; -import org.simantics.browsing.ui.swt.widgets.ModelBrowser; -import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupportImpl; -import org.simantics.scl.runtime.function.Function1; -import org.simantics.views.ViewUtils.ColumnBean; -import org.simantics.views.ViewUtils.LayoutBean; -import org.simantics.views.swt.client.base.SWTViewUtils; -import org.simantics.views.swt.client.base.SingleSWTViewNode; - -public class SWTExplorer extends SingleSWTViewNode { - - private static final long serialVersionUID = 7932335224632082902L; - - public LayoutBean layout; - public String browseContext; - public String contextMenuId; - public String uiContext; - public Function1 selectionListener; - public Object input; - public List columns; - public List editingColumns; - public Boolean columnsVisible; - public Boolean displayFilter; - public Boolean publishSelection; - public Boolean useNodeBrowseContexts; - public Boolean useNodeActionContexts; - public StatePersistor persistor; - - public ISelection lastSelection; - - @Override - public void createControls(Composite parent) { - - if(browseContext == null) return; - - final IWorkbenchSite site = getSite(); - - Map args = new HashMap(); - args.put("displaySelectors", Boolean.FALSE); - args.put("displayFilter", displayFilter != null ? displayFilter : Boolean.FALSE); - if(useNodeBrowseContexts != null && useNodeBrowseContexts) { - args.put("useNodeBrowseContexts", true); - } - if(useNodeActionContexts != null && useNodeActionContexts) { - args.put("useNodeActionContexts", true); - } - - control = new ModelBrowser(Collections.singleton(browseContext), args, site, parent, new WidgetSupportImpl(), style); - control.setContextMenuId(contextMenuId); - if (uiContext != null) { - control.setUiContexts(Collections.singleton(uiContext)); - } - - control.setStatePersistor(persistor); - - control.finish(); - - setProperties(); - - control.setInputSource(PassThruInputSource.INSTANCE); - - ISelectionProvider sp = (ISelectionProvider)control.getExplorer().getAdapter(ISelectionProvider.class); - sp.addSelectionChangedListener(new ISelectionChangedListener() { - - @Override - public void selectionChanged(SelectionChangedEvent event) { - if (site != null) { - ISelectionProvider sp = site.getSelectionProvider(); - if (sp != null) { - sp.setSelection(event.getSelection()); - } - } - } - - }); - - IPostSelectionProvider psp = (IPostSelectionProvider)control.getExplorer().getAdapter(IPostSelectionProvider.class); - psp.addPostSelectionChangedListener(new ISelectionChangedListener() { - - @Override - public void selectionChanged(SelectionChangedEvent event) { - -// ISelection selection = (ISelection)control.getExplorer().getWidgetSelection(); - if (site != null) { - ISelectionProvider sp = site.getSelectionProvider(); - if (sp != null) { - sp.setSelection(event.getSelection()); - } - } - - } - - }); - - control.addListenerToControl(SWT.Selection, new Listener() { - - @Override - public void handleEvent(Event event) { - - if(selectionListener != null) - selectionListener.apply(event); - - ISelection selection = (ISelection)control.getExplorer().getWidgetSelection(); - // [Tuukka@2012-04-08] Disabled this because it was causing - // horrible selection feedback effects in the Model Browser - // view that is using it. It causes the browser to react to - // external selections which were initially published as its own - // with a delay. - //System.out.println("selection: " + selection); -// if(publishSelection != null && publishSelection) { -// if (site != null) { -// ISelectionProvider sp = site.getSelectionProvider(); -// if (sp != null) { -// sp.setSelection(selection); -// } -// } -// } - - propertyCallback.apply("selection", selection); - - lastSelection = selection; - - } - - }); - - } - - public void synchronizeColumnsVisible(Boolean columnsVisible) { - if(columnsVisible != null) control.setColumnsVisible(columnsVisible); - } - - public void synchronizeDisplayFilter(Boolean displayFilter) { -// if(displayFilter != null) control.setColumnsVisible(displayFilter); - } - - public void synchronizePublishSelection(Boolean publishSelection) { - } - - public void synchronizeInput(Object input) { - if(input != null) control.setInput(input, false); - } - - public void synchronizeBrowseContext(String browseContext) { - } - - public void synchronizeContextMenuId(String contextMenuId) { - } - - public void synchronizeSelectionListener(Function1 selectionListener) { - } - - public void synchronizePersistor(StatePersistor persistor) { - } - - public void synchronizeColumns(ArrayList columns) { - if(columns != null) { - Column[] cols = new Column[columns.size()]; - for(int i=0;i columns) { - if(columns != null) { - String[] ecs = new String[columns.size()]; - for(int i=0;i { + + private static final long serialVersionUID = 7932335224632082902L; + + public LayoutBean layout; + public String browseContext; + public String contextMenuId; + public String uiContext; + public Function1 selectionListener; + public Object input; + public List columns; + public List editingColumns; + public Boolean columnsVisible; + public Boolean displayFilter; + public Boolean publishSelection; + public Boolean useNodeBrowseContexts; + public Boolean useNodeActionContexts; + public StatePersistor persistor; + + public ISelection lastSelection; + + @Override + public void createControls(Composite parent) { + + if(browseContext == null) return; + + final IWorkbenchSite site = getSite(); + + Map args = new HashMap(); + args.put("displaySelectors", Boolean.FALSE); + args.put("displayFilter", displayFilter != null ? displayFilter : Boolean.FALSE); + if(useNodeBrowseContexts != null && useNodeBrowseContexts) { + args.put("useNodeBrowseContexts", true); + } + if(useNodeActionContexts != null && useNodeActionContexts) { + args.put("useNodeActionContexts", true); + } + + control = new ModelBrowser(Collections.singleton(browseContext), args, site, parent, new WidgetSupportImpl(), style); + control.setContextMenuId(contextMenuId); + if (uiContext != null) { + control.setUiContexts(Collections.singleton(uiContext)); + } + + control.setStatePersistor(persistor); + + control.finish(); + + setProperties(); + + control.setInputSource(PassThruInputSource.INSTANCE); + + ISelectionProvider sp = (ISelectionProvider)control.getExplorer().getAdapter(ISelectionProvider.class); + sp.addSelectionChangedListener(new ISelectionChangedListener() { + + @Override + public void selectionChanged(SelectionChangedEvent event) { + if (site != null) { + ISelectionProvider sp = site.getSelectionProvider(); + if (sp != null) { + sp.setSelection(event.getSelection()); + } + } + } + + }); + + IPostSelectionProvider psp = (IPostSelectionProvider)control.getExplorer().getAdapter(IPostSelectionProvider.class); + psp.addPostSelectionChangedListener(new ISelectionChangedListener() { + + @Override + public void selectionChanged(SelectionChangedEvent event) { + +// ISelection selection = (ISelection)control.getExplorer().getWidgetSelection(); + if (site != null) { + ISelectionProvider sp = site.getSelectionProvider(); + if (sp != null) { + sp.setSelection(event.getSelection()); + } + } + + } + + }); + + control.addListenerToControl(SWT.Selection, new Listener() { + + @Override + public void handleEvent(Event event) { + + if(selectionListener != null) + selectionListener.apply(event); + + ISelection selection = (ISelection)control.getExplorer().getWidgetSelection(); + // [Tuukka@2012-04-08] Disabled this because it was causing + // horrible selection feedback effects in the Model Browser + // view that is using it. It causes the browser to react to + // external selections which were initially published as its own + // with a delay. + //System.out.println("selection: " + selection); +// if(publishSelection != null && publishSelection) { +// if (site != null) { +// ISelectionProvider sp = site.getSelectionProvider(); +// if (sp != null) { +// sp.setSelection(selection); +// } +// } +// } + + propertyCallback.apply("selection", selection); + + lastSelection = selection; + + } + + }); + + } + + public void synchronizeColumnsVisible(Boolean columnsVisible) { + if(columnsVisible != null) control.setColumnsVisible(columnsVisible); + } + + public void synchronizeDisplayFilter(Boolean displayFilter) { +// if(displayFilter != null) control.setColumnsVisible(displayFilter); + } + + public void synchronizePublishSelection(Boolean publishSelection) { + } + + public void synchronizeInput(Object input) { + if(input != null) control.setInput(input, false); + } + + public void synchronizeBrowseContext(String browseContext) { + } + + public void synchronizeContextMenuId(String contextMenuId) { + } + + public void synchronizeSelectionListener(Function1 selectionListener) { + } + + public void synchronizePersistor(StatePersistor persistor) { + } + + public void synchronizeColumns(ArrayList columns) { + if(columns != null) { + Column[] cols = new Column[columns.size()]; + for(int i=0;i columns) { + if(columns != null) { + String[] ecs = new String[columns.size()]; + for(int i=0;i