X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.document.swt.core%2Fsrc%2Forg%2Fsimantics%2Fdocument%2Fswt%2Fcore%2Fwidget%2FExplorer.java;fp=bundles%2Forg.simantics.document.swt.core%2Fsrc%2Forg%2Fsimantics%2Fdocument%2Fswt%2Fcore%2Fwidget%2FExplorer.java;h=e85d08f47f926282e2d70a3d1a4758390a961347;hb=0ffcb1180dcccf28e66a391338885be224ba1c47;hp=deabd7573d3196eb9a0cd2a059f1c1bb20c64ae4;hpb=342a2b006b88330280060c16c2ab50374468a4c6;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/widget/Explorer.java b/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/widget/Explorer.java index deabd7573..e85d08f47 100644 --- a/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/widget/Explorer.java +++ b/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/widget/Explorer.java @@ -1,16 +1,24 @@ package org.simantics.document.swt.core.widget; +import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionProvider; import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeItem; import org.eclipse.ui.IWorkbenchSite; import org.simantics.Simantics; import org.simantics.browsing.ui.Column; @@ -22,15 +30,28 @@ import org.simantics.browsing.ui.swt.widgets.ModelBrowser; import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupportImpl; import org.simantics.db.layer0.variable.VariableBean; import org.simantics.db.management.ISessionContext; +import org.simantics.document.server.IEventCommand; import org.simantics.document.server.JSONObject; +import org.simantics.document.server.bean.Command; +import org.simantics.document.server.client.CommandManager; +import org.simantics.document.server.client.WidgetData; +import org.simantics.document.server.handler.AbstractEventHandler; +import org.simantics.document.server.io.CommandContext; +import org.simantics.document.server.io.CommandContextImpl; +import org.simantics.document.server.io.CommandContextMutable; +import org.simantics.document.server.io.ICommand; +import org.simantics.document.server.io.JSONObjectUtils; import org.simantics.document.swt.core.SWTDocument; import org.simantics.document.swt.core.SWTViews; import org.simantics.document.swt.core.base.LeafWidgetManager; +import org.simantics.document.swt.core.base.PostEventCommand; import org.simantics.document.swt.core.base.WidgetContainer; import org.simantics.document.swt.core.bean.ColumnBean; import org.simantics.document.swt.core.bean.ColumnsBean; import org.simantics.scl.runtime.function.Function1; +import org.simantics.scl.runtime.function.Function2; import org.simantics.ui.selection.WorkbenchSelectionUtils; +import org.simantics.utils.datastructures.Pair; public class Explorer extends LeafWidgetManager { @@ -74,9 +95,15 @@ public class Explorer extends LeafWidgetManager { if(Boolean.TRUE.equals(noscroll)) style |= SWT.NO_SCROLL; - StatePersistor persistor = object.getJSONField("persistor"); + Boolean check = object.getJSONFieldDefault("Check", false); + if(Boolean.TRUE.equals(check)) + style |= SWT.CHECK; + + StatePersistor persistor = object.getJSONField("persistor"); final Function1 selectionListener = object.getJSONField("selectionListener"); + final Function2 checkStateListener = object.getJSONField("checkStateListener"); + DragSourceListenerFactory dragSourceListenerFactory = object.getJSONField("dragSourceListenerFactory"); final IWorkbenchSite site = document.getSite(); @@ -147,6 +174,17 @@ public class Explorer extends LeafWidgetManager { @Override public void handleEvent(Event event) { + + switch (event.type) { + case SWT.Selection: + if (event.detail == SWT.CHECK && event.item != null) { + TreeItem item = (TreeItem) event.item; + boolean checked = item.getChecked(); + if(checkStateListener != null) + selectionListener.apply(event); + } + break; + } if(selectionListener != null) selectionListener.apply(event); @@ -183,4 +221,46 @@ public class Explorer extends LeafWidgetManager { return null; } + public static class ExplorerCommandManager implements CommandManager> { + + @Override + public Collection updateCommandListeners(final SWTDocument document, final JSONObject object, + WidgetContainer container) { + + WidgetData wd = document.getWidget(JSONObjectUtils.getId(object)); + List commands = object.getJSONField("commands"); + HashSet listeners = new HashSet(); + List> data = new ArrayList<>(); + data.addAll(SWTViews.getTriggeredCommands(document, commands, "eventOut")); + data.add(new Pair(wd, new Command("onCheck"))); + Listener listener = new ExplorerListener(wd, data); + ModelBrowser browser = container.getControl(); + if(!browser.isDisposed()) { + browser.addListenerToControl(SWT.Selection, listener); + listeners.add(listener); + } + + return listeners; + + } + + @Override + public void removeListener(WidgetContainer container, Object listener) { + if(container.getControl().isDisposed()) return; + if(listener instanceof ExplorerListener) + container.getControl().removeListenerFromControl(SWT.Selection, (Listener)listener); + } + + } + + @Override + public IEventCommand eventCommand(SWTDocument document, JSONObject object, WidgetContainer widget, ICommand command, CommandContext p) { + if("onCheck".equals(command.getCommand())) { + CommandContextMutable context = new CommandContextImpl().merge(p); + AbstractEventHandler onCheck = object.getJSONField("onCheck"); + return new PostEventCommand(document, onCheck, context); + } + return null; + } + }