]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Added possibility to directly schedule filter setting type URI 82/2382/1
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Tue, 30 Oct 2018 07:23:54 +0000 (09:23 +0200)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Tue, 30 Oct 2018 08:00:26 +0000 (08:00 +0000)
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)

bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/FilterArea.java
bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/TypeContextFilterArea.java

index 27c32abc03190dc6e43ad1bef26737d95ed5140a..1ed2a0c671656b94e238c0aabd9c3b24e08c476d 100644 (file)
@@ -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();
index 72ee0fffbbbefac02d4467b3c55275d8dbbd86a9..299b96c1c4ad87315ddc0397153008dc69459dcf 100644 (file)
@@ -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 <marko.luukkainen@semantum.fi>
  *
  */
-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);
                }
        }