From: Tuukka Lehtonen Date: Tue, 30 Oct 2018 07:23:54 +0000 (+0200) Subject: Added possibility to directly schedule filter setting type URI X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=c632f433edd52877a08bf79a40fd6d9d0c942615;p=simantics%2Fplatform.git Added possibility to directly schedule filter setting type URI Also changed the typeURI load to directly set the filter text instead of scheduling it to be set after a quiet time (500ms). This makes way for a bit cleaner UI experience. gitlab #140 Change-Id: If999ccf69182e56da2f520e2922ba2a7ed26ffdc (cherry picked from commit eb81a8ba87fabc50f712525508c938080d98da10) --- diff --git a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/FilterArea.java b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/FilterArea.java index 27c32abc0..1ed2a0c67 100644 --- a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/FilterArea.java +++ b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/FilterArea.java @@ -288,9 +288,14 @@ public class FilterArea extends Composite implements IFocusable, IFilterArea, IF }); } }, FILTER_DELAY, TimeUnit.MILLISECONDS); - } - + + protected void applyFilter(String filter) { + final NodeContext context = getFilteredNode(); + if (context != null) + applyFilter(context, filter, true); + } + protected void applyFilter(NodeContext context, String filter, boolean updateUI) { if (updateUI) { String current = filterText.getText(); diff --git a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/TypeContextFilterArea.java b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/TypeContextFilterArea.java index 72ee0fffb..299b96c1c 100644 --- a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/TypeContextFilterArea.java +++ b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/TypeContextFilterArea.java @@ -17,6 +17,9 @@ import org.simantics.db.common.request.ReadRequest; import org.simantics.db.exception.DatabaseException; import org.simantics.db.management.ISessionContext; import org.simantics.layer0.Layer0; +import org.simantics.utils.ui.SWTUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Resource Type specific filters. @@ -26,9 +29,12 @@ import org.simantics.layer0.Layer0; * @author Marko Luukkainen * */ -public class TypeContextFilterArea extends RootFilterArea implements Widget{ +public class TypeContextFilterArea extends RootFilterArea implements Widget { + + private static final Logger LOGGER = LoggerFactory.getLogger(TypeContextFilterArea.class); + String preferencePrefix; - + String typeUri; /** @@ -43,7 +49,7 @@ public class TypeContextFilterArea extends RootFilterArea implements Widget{ public TypeContextFilterArea(GraphExplorer explorer, FilterSelectionRequestQueryProcessor queryProcessor, WidgetSupport support, Composite parent, String id, int style) { super(explorer, queryProcessor, parent, style); - this.preferencePrefix = id +"_TypeFilter_"; + this.preferencePrefix = id +"_TypeFilter_"; //$NON-NLS-1$ support.register(this); } @@ -54,7 +60,6 @@ public class TypeContextFilterArea extends RootFilterArea implements Widget{ if (resource == null) return; context.getSession().asyncRequest(new ReadRequest() { - @Override public void run(ReadGraph graph) throws DatabaseException { setInput(graph, resource); @@ -64,23 +69,18 @@ public class TypeContextFilterArea extends RootFilterArea implements Widget{ public void setInput(ReadGraph graph, Resource resource) throws DatabaseException{ Resource type = getType(graph, resource); - final String typeUri = type == null ? null : graph.getPossibleURI(type); - if (typeUri != null) { - Display.getDefault().asyncExec(new Runnable() { - @Override - public void run() { - load(typeUri); - } - }); - } + String typeUri = type == null ? null : graph.getPossibleURI(type); + setTypeURI(typeUri); + } + + public void setTypeURI(String typeUri) { + if (typeUri != null) + SWTUtils.asyncExec(Display.getDefault(), () -> load(typeUri)); } protected Resource getType(ReadGraph graph, Resource resource) throws DatabaseException { - Layer0 L0 = Layer0.getInstance(graph); - Resource type = graph.getPossibleType(resource, L0.Entity); - return type; + return graph.getPossibleType(resource, Layer0.getInstance(graph).Entity); } - @Override protected synchronized void applyFilter(NodeContext context, String filter, boolean updateUI) { @@ -94,11 +94,12 @@ public class TypeContextFilterArea extends RootFilterArea implements Widget{ if (filter != null && filter.length() > 0) store.setValue(preferencePrefix+typeUri, filter); else - store.setValue(preferencePrefix+typeUri,""); + store.setValue(preferencePrefix+typeUri, ""); //$NON-NLS-1$ try { store.save(); } catch (IOException e) { - + LOGGER.error("Failed to save filter preference '{}' for type-contextual filter area with type URI {}", //$NON-NLS-1$ + filter, typeUri, e); } } @@ -107,7 +108,7 @@ public class TypeContextFilterArea extends RootFilterArea implements Widget{ ScopedPreferenceStore store = new ScopedPreferenceStore(InstanceScope.INSTANCE, Activator.PLUGIN_ID); String filter = store.getString(preferencePrefix+typeUri); if (filter != null && filter.length() > 0) { - setFilter(filter); + applyFilter(filter); } }