import java.util.HashSet;
import java.util.Map;
import java.util.Set;
+import java.util.function.BiFunction;
import java.util.function.Consumer;
import org.eclipse.core.runtime.IAdaptable;
import org.simantics.db.ReadGraph;
import org.simantics.db.Resource;
import org.simantics.db.Session;
-import org.simantics.db.common.request.ResourceRead;
-import org.simantics.db.common.utils.Logger;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.layer0.SelectionHints;
+import org.simantics.db.layer0.request.PossibleVariable;
+import org.simantics.db.layer0.request.PossibleVariableRepresents;
import org.simantics.db.layer0.variable.Variable;
-import org.simantics.db.layer0.variable.Variables;
import org.simantics.db.management.ISessionContext;
import org.simantics.db.management.ISessionContextChangedListener;
import org.simantics.db.management.ISessionContextProvider;
import org.simantics.ui.selection.WorkbenchSelectionElement;
import org.simantics.ui.selection.WorkbenchSelectionUtils;
import org.simantics.utils.ObjectUtils;
-import org.simantics.utils.datastructures.BinaryFunction;
import org.simantics.utils.datastructures.Function;
import org.simantics.utils.datastructures.disposable.DisposeState;
import org.simantics.utils.datastructures.hints.HintListenerAdapter;
import org.simantics.utils.datastructures.hints.IHintListener;
import org.simantics.utils.datastructures.hints.IHintObservable;
import org.simantics.utils.datastructures.hints.IHintTracker;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class GraphExplorerComposite extends Composite implements Widget, IAdaptable {
+ private static final Logger LOGGER = LoggerFactory.getLogger(GraphExplorerComposite.class);
+
protected UserSelectedComparableFactoryQueryProcessor userSelectedComparableFactoryQueryProcessor;
protected UserSelectedViewpointFactoryQueryProcessor userSelectedViewpointFactoryQueryProcessor;
protected FilterSelectionRequestQueryProcessor filterSelectionRequestQueryProcessor;
@SuppressWarnings("unchecked")
@Override
public <T> T getContent(WorkbenchSelectionContentType<T> contentType) {
-
- if(wse != null) {
+ if (wse != null) {
T result = wse.getContent(contentType);
- if(result != null) return result;
+ if (result != null)
+ return result;
}
-
- if(contentType instanceof AnyResource) return (T)resource;
- else if(contentType instanceof AnyVariable) {
- AnyVariable type = (AnyVariable)contentType;
+
+ if (contentType instanceof AnyResource) {
+ if (resource != null)
+ return (T) resource;
+ if (variable == null)
+ return null;
+ try {
+ return (T) ((AnyResource) contentType).processor.syncRequest(new PossibleVariableRepresents(variable));
+ } catch (DatabaseException e) {
+ LOGGER.error("Unexpected error occurred while resolving Resource from Variable " + variable, e);
+ }
+ }
+ else if (contentType instanceof AnyVariable) {
+ if (variable != null)
+ return (T) variable;
+ if (resource == null)
+ return null;
try {
-
- if(variable != null) return (T)variable;
-
- if(resource == null) return null;
-
- return (T) type.processor.sync(new ResourceRead<Variable>(resource) {
- @Override
- public Variable perform(ReadGraph graph) throws DatabaseException {
- return Variables.getPossibleVariable(graph, resource);
- }
-
- });
+ return (T) ((AnyVariable) contentType).processor.syncRequest(new PossibleVariable(resource));
} catch (DatabaseException e) {
- Logger.defaultLogError(e);
+ LOGGER.error("Unexpected error occurred while resolving Variable from Resource " + resource, e);
}
} else if (contentType instanceof ExplorerInputContentType) {
- return (T)input;
+ return (T) input;
} else if (contentType instanceof ExplorerColumnContentType) {
- return (T)explorerState.getActiveColumn();
+ return (T) explorerState.getActiveColumn();
}
return null;
}
-
+
@SuppressWarnings("rawtypes")
@Override
public Object getAdapter(Class adapter) {
}
}
- private BinaryFunction<Object[], GraphExplorer, Object[]> selectionTransformation = new BinaryFunction<Object[], GraphExplorer, Object[]>() {
+ private BiFunction<GraphExplorer, Object[], Object[]> selectionTransformation = new BiFunction<GraphExplorer, Object[], Object[]>() {
private Key[] KEYS = new Key[] { SelectionHints.KEY_MAIN };
@Override
- public Object[] call(GraphExplorer explorer, Object[] objects) {
+ public Object[] apply(GraphExplorer explorer, Object[] objects) {
Object[] result = new Object[objects.length];
for (int i = 0; i < objects.length; i++) {
SelectionElement context = new SelectionElement(explorer, KEYS, objects[i]);
event.data = WorkbenchSelectionUtils.getPossibleJSON(selectionProvider.getSelection());
} catch (DatabaseException e) {
event.data = "{ type:\"Exception\" }";
- Logger.defaultLogError(e);
+ LOGGER.error("Failed to get current selection as JSON.", e);
}
} else if (LocalObjectTransfer.getTransfer().isSupportedType(event.dataType)) {
ls.dragSetData(event);
this.filterAreaSource = provider;
}
- public void setSelectionTransformation(BinaryFunction<Object[], GraphExplorer, Object[]> transformation) {
+ public void setSelectionTransformation(BiFunction<GraphExplorer, Object[], Object[]> transformation) {
this.selectionTransformation = transformation;
if(explorer != null) explorer.setSelectionTransformation(transformation);
}