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.
* @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;
/**
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);
}
if (resource == null)
return;
context.getSession().asyncRequest(new ReadRequest() {
-
@Override
public void run(ReadGraph graph) throws DatabaseException {
setInput(graph, resource);
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) {
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);
}
}
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);
}
}