import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.BiFunction;
import java.util.function.Consumer;
import org.eclipse.core.runtime.Assert;
import org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer;
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer;
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer.MoveDirectionEnum;
-import org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand;
import org.eclipse.nebula.widgets.nattable.sort.config.SingleClickSortConfiguration;
import org.eclipse.nebula.widgets.nattable.style.CellStyleAttributes;
import org.eclipse.nebula.widgets.nattable.style.DisplayMode;
import org.simantics.browsing.ui.swt.ViewerRowReference;
import org.simantics.browsing.ui.swt.internal.Threads;
import org.simantics.db.layer0.SelectionHints;
-import org.simantics.utils.datastructures.BinaryFunction;
import org.simantics.utils.datastructures.MapList;
import org.simantics.utils.datastructures.disposable.AbstractDisposable;
import org.simantics.utils.datastructures.hints.IHintContext;
private boolean expand;
private boolean verticalBarVisible = false;
- private BinaryFunction<Object[], GraphExplorer, Object[]> selectionTransformation = new BinaryFunction<Object[], GraphExplorer, Object[]>() {
+ private BiFunction<GraphExplorer, Object[], Object[]> selectionTransformation = new BiFunction<GraphExplorer, Object[], Object[]>() {
@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++) {
IHintContext context = new AdaptableHintContext(SelectionHints.KEY_MAIN);
}
protected Object[] transformSelection(Object[] objects) {
- return selectionTransformation.call(this, objects);
+ return selectionTransformation.apply(this, objects);
}
protected static Object[] filter(SelectionFilter filter, NodeContext[] contexts) {
@Override
public void setSelectionTransformation(
- BinaryFunction<Object[], GraphExplorer, Object[]> f) {
+ BiFunction<GraphExplorer, Object[], Object[]> f) {
this.selectionTransformation = f;
}
com.lowagie.text;bundle-version="2.1.5",
org.simantics.scl.ui.editor;bundle-version="0.1.3";visibility:=reexport,
org.simantics.scl.compiler.dummy;bundle-version="0.1.3",
- org.eclipse.e4.core.contexts;bundle-version="1.4.0"
+ org.eclipse.e4.core.contexts;bundle-version="1.4.0",
+ org.slf4j.api;bundle-version="1.7.20"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Export-Package: org.simantics.browsing.ui.swt,
org.simantics.browsing.ui.swt.contentassist,
package org.simantics.browsing.ui.swt;
import java.lang.reflect.Method;
+import java.util.function.BiFunction;
import org.eclipse.core.runtime.Platform;
import org.eclipse.swt.SWT;
import org.simantics.db.layer0.variable.Variable;
import org.simantics.db.layer0.variable.Variables;
import org.simantics.simulation.ontology.SimulationResource;
-import org.simantics.utils.datastructures.BinaryFunction;
import org.simantics.utils.datastructures.hints.IHintContext;
import org.simantics.utils.ui.ExceptionUtils;
private IServiceLocator serviceLocator;
- private BinaryFunction<Object[], GraphExplorer, Object[]> selectionTransformation = new BinaryFunction<Object[], GraphExplorer, Object[]>() {
+ private BiFunction<GraphExplorer, Object[], Object[]> selectionTransformation = new BiFunction<GraphExplorer, Object[], Object[]>() {
private Resource getModel(final Object object) {
if(object instanceof NodeContext) {
return null;
}
-
@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++) {
IHintContext context = new AdaptableHintContext(SelectionHints.KEY_MAIN);
return this;
}
- public GraphExplorerFactory selectionTransformation(BinaryFunction<Object[], GraphExplorer, Object[]> transformation) {
+ public GraphExplorerFactory selectionTransformation(BiFunction<GraphExplorer, Object[], Object[]> transformation) {
this.selectionTransformation = transformation;
return this;
}
//GraphExplorerImpl2 explorer = new GraphExplorerImpl2(parent, style);
try {
Bundle bundle = Platform.getBundle("org.simantics.browsing.ui.nattable");
- Class<GraphExplorer> clazz = (Class<GraphExplorer>)bundle.loadClass("org.simantics.browsing.ui.nattable.NatTableGraphExplorer");
+ @SuppressWarnings("unchecked")
+ Class<GraphExplorer> clazz = (Class<GraphExplorer>)bundle.loadClass("org.simantics.browsing.ui.nattable.NatTableGraphExplorer");
//Class<GraphExplorer> clazz = (Class<GraphExplorer>)bundle.getClass().getClassLoader().loadClass("org.simantics.browsing.ui.nattable.NatTableGraphExplorer");
GraphExplorer explorer = clazz.getConstructor(Composite.class, int.class).newInstance(parent,style);
explorer.setSelectionDataResolver(selectionDataResolver);
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.BiFunction;
import java.util.function.Consumer;
import org.eclipse.core.runtime.Assert;
import org.simantics.db.layer0.SelectionHints;
import org.simantics.utils.ObjectUtils;
import org.simantics.utils.datastructures.BijectionMap;
-import org.simantics.utils.datastructures.BinaryFunction;
import org.simantics.utils.datastructures.disposable.AbstractDisposable;
import org.simantics.utils.datastructures.hints.IHintContext;
import org.simantics.utils.threads.IThreadWorkQueue;
protected BasePostSelectionProvider selectionProvider = new BasePostSelectionProvider();
protected SelectionDataResolver selectionDataResolver;
protected SelectionFilter selectionFilter;
- protected BinaryFunction<Object[], GraphExplorer, Object[]> selectionTransformation = new BinaryFunction<Object[], GraphExplorer, Object[]>() {
+ protected BiFunction<GraphExplorer, Object[], Object[]> selectionTransformation = new BiFunction<GraphExplorer, Object[], Object[]>() {
@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++) {
IHintContext context = new AdaptableHintContext(SelectionHints.KEY_MAIN);
}
@Override
- public void setSelectionTransformation(BinaryFunction<Object[], GraphExplorer, Object[]> f) {
+ public void setSelectionTransformation(BiFunction<GraphExplorer, Object[], Object[]> f) {
this.selectionTransformation = f;
}
}
protected Object[] transformSelection(Object[] objects) {
- return selectionTransformation.call(this, objects);
+ return selectionTransformation.apply(this, objects);
}
protected static Object[] filter(SelectionFilter filter, NodeContext[] contexts) {
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.BiFunction;
import java.util.function.Consumer;
import org.eclipse.core.runtime.Assert;
import org.simantics.db.layer0.SelectionHints;
import org.simantics.ui.SimanticsUI;
import org.simantics.utils.datastructures.BijectionMap;
-import org.simantics.utils.datastructures.BinaryFunction;
import org.simantics.utils.datastructures.MapList;
import org.simantics.utils.datastructures.disposable.AbstractDisposable;
import org.simantics.utils.datastructures.hints.IHintContext;
private boolean expand;
private boolean verticalBarVisible = false;
- private BinaryFunction<Object[], GraphExplorer, Object[]> selectionTransformation = new BinaryFunction<Object[], GraphExplorer, Object[]>() {
+ private BiFunction<GraphExplorer, Object[], Object[]> selectionTransformation = new BiFunction<GraphExplorer, Object[], Object[]>() {
@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++) {
IHintContext context = new AdaptableHintContext(SelectionHints.KEY_MAIN);
}
protected Object[] transformSelection(Object[] objects) {
- return selectionTransformation.call(this, objects);
+ return selectionTransformation.apply(this, objects);
}
protected static Object[] filter(SelectionFilter filter, NodeContext[] contexts) {
@Override
public void setSelectionTransformation(
- BinaryFunction<Object[], GraphExplorer, Object[]> f) {
+ BiFunction<GraphExplorer, Object[], Object[]> f) {
this.selectionTransformation = f;
}
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);
}
import java.util.Collection;
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.browsing.ui.NodeContext.QueryKey;
import org.simantics.browsing.ui.content.Labeler;
import org.simantics.browsing.ui.content.Labeler.Modifier;
-import org.simantics.utils.datastructures.BinaryFunction;
import org.simantics.utils.threads.IThreadWorkQueue;
/**
*/
void setSelectionFilter(SelectionFilter f);
- void setSelectionTransformation(BinaryFunction<Object[], GraphExplorer, Object[]> f);
+ void setSelectionTransformation(BiFunction<GraphExplorer, Object[], Object[]> f);
//ISelectionProvider getSelectionProvider();
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2017 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Semantum Oy - initial API and implementation
+ *******************************************************************************/
+package org.simantics.db.layer0.request;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.variable.Variable;
+
+/**
+ * @author Tuukka Lehtonen
+ * @since 1.28.0
+ */
+public class PossibleVariableRepresents extends VariableRead<Resource> {
+
+ public PossibleVariableRepresents(Variable var) {
+ super(var);
+ }
+
+ @Override
+ public Resource perform(ReadGraph graph) throws DatabaseException {
+ return variable.getPossibleRepresents(graph);
+ }
+
+}
package org.simantics.diagram.handler;
import static org.simantics.diagram.handler.Paster.ComposedCutProcedure.compose;
-import gnu.trove.map.hash.THashMap;
-import gnu.trove.set.hash.THashSet;
import java.awt.geom.AffineTransform;
import java.awt.geom.Point2D;
import java.util.Map;
import java.util.Queue;
import java.util.Set;
+import java.util.function.BiFunction;
import org.simantics.databoard.Bindings;
import org.simantics.db.ReadGraph;
import org.simantics.structural2.modelingRules.CPTerminal;
import org.simantics.structural2.modelingRules.ConnectionJudgement;
import org.simantics.structural2.modelingRules.IConnectionPoint;
-import org.simantics.utils.datastructures.BinaryFunction;
import org.simantics.utils.datastructures.map.Tuple;
+import gnu.trove.map.hash.THashMap;
+import gnu.trove.set.hash.THashSet;
+
/**
* @author Tuukka Lehtonen
*/
* Diagram mapping will have problems and potentially break the
* configuration if the type is not the same as in the source.
*/
- BinaryFunction<StatementEvaluation, ReadGraph, Statement> statementAdvisor =
- new BinaryFunction<StatementEvaluation, ReadGraph, Statement>() {
+ BiFunction<ReadGraph, Statement, StatementEvaluation> statementAdvisor =
+ new BiFunction<ReadGraph, Statement, StatementEvaluation>() {
@Override
- public StatementEvaluation call(ReadGraph graph, Statement stm) {
+ public StatementEvaluation apply(ReadGraph graph, Statement stm) {
if (DIA.HasFlagType.equals(stm.getPredicate()))
return StatementEvaluation.INCLUDE;
return StatementEvaluation.USE_DEFAULT;
import java.util.Map;
import java.util.Set;
+import java.util.function.BiFunction;
import org.simantics.databoard.Bindings;
import org.simantics.databoard.binding.Binding;
import org.simantics.graph.db.TransferableGraphs;
import org.simantics.graph.representation.TransferableGraph1;
import org.simantics.layer0.Layer0;
-import org.simantics.utils.datastructures.BinaryFunction;
/**
* This class contains utility methods for the basic cut/copy operations
* @return the copied resource
* @throws DatabaseException
*/
- public static Resource copy(WriteGraph graph, Resource source, BinaryFunction<Boolean, ReadGraph, Statement> advisor) throws DatabaseException {
+ public static Resource copy(WriteGraph graph, Resource source, BiFunction<ReadGraph, Statement, Boolean> advisor) throws DatabaseException {
return copy(graph, source, 0, advisor, new THashMap<Object, Object>());
}
* @return
* @throws DatabaseException
*/
- public static Resource copy(WriteGraph graph, Resource source, BinaryFunction<Boolean, ReadGraph, Statement> advisor, Map<Object, Object> copyMap) throws DatabaseException {
+ public static Resource copy(WriteGraph graph, Resource source, BiFunction<ReadGraph, Statement, Boolean> advisor, Map<Object, Object> copyMap) throws DatabaseException {
return copy(graph, source, 0, advisor, copyMap);
}
- private static Resource copy(WriteGraph graph, Resource source, int level, BinaryFunction<Boolean, ReadGraph, Statement> advisor, Map<Object, Object> copyMap) throws DatabaseException {
+ private static Resource copy(WriteGraph graph, Resource source, int level, BiFunction<ReadGraph, Statement, Boolean> advisor, Map<Object, Object> copyMap) throws DatabaseException {
if (DEBUG_COPY)
System.out.println("[" + level + "] CopyAdvisorUtil.copy(" + NameUtils.getSafeName(graph, source) + ", advisor=" + advisor + ")");
}
} else {
if (advisor != null) {
- Boolean result = advisor.call(graph, stm);
+ Boolean result = advisor.apply(graph, stm);
if (Boolean.TRUE.equals(result)) {
// Don't clone the object, just add relation to the same object.
if (inverse != null)
* @throws DatabaseException
*/
public static Resource copy2(WriteGraph graph, Resource source,
- BinaryFunction<StatementEvaluation, ReadGraph, Statement> advisor) throws DatabaseException {
+ BiFunction<ReadGraph, Statement, StatementEvaluation> advisor) throws DatabaseException {
return copy2(graph, source, 0, advisor, new THashMap<Object, Object>());
}
* @throws DatabaseException
*/
public static Resource copy2(WriteGraph graph, Resource source,
- BinaryFunction<StatementEvaluation, ReadGraph, Statement> advisor, Map<Object, Object> copyMap)
+ BiFunction<ReadGraph, Statement, StatementEvaluation> advisor, Map<Object, Object> copyMap)
throws DatabaseException {
return copy2(graph, source, 0, advisor, copyMap);
}
private static Resource copy2(final WriteGraph graph, final Resource source, final int level,
- BinaryFunction<StatementEvaluation, ReadGraph, Statement> advisor, Map<Object, Object> copyMap)
+ BiFunction<ReadGraph, Statement, StatementEvaluation> advisor, Map<Object, Object> copyMap)
throws DatabaseException {
if (DEBUG_COPY)
System.out.println("[" + level + "] CopyAdvisorUtil.copy(" + NameUtils.getSafeName(graph, source) + ", advisor=" + advisor + ")");
* @throws DatabaseException
*/
public static Resource copy3(WriteGraph graph, Resource source, Resource model,
- BinaryFunction<StatementEvaluation, ReadGraph, Statement> advisor) throws DatabaseException {
+ BiFunction<ReadGraph, Statement, StatementEvaluation> advisor) throws DatabaseException {
String modelURI = graph.getURI(model);
return copy3(graph, modelURI, source, 0, advisor, new THashMap<Object, Object>());
}
* @throws DatabaseException
*/
public static Resource copy3(WriteGraph graph, Resource source, Resource model,
- BinaryFunction<StatementEvaluation, ReadGraph, Statement> advisor, Map<Object, Object> copyMap) throws DatabaseException {
+ BiFunction<ReadGraph, Statement, StatementEvaluation> advisor, Map<Object, Object> copyMap) throws DatabaseException {
String modelURI = graph.getURI(model);
return copy3(graph, modelURI, source, 0, advisor, copyMap);
}
private static Resource copy3(WriteGraph graph, String modelURI, Resource source, int level,
- BinaryFunction<StatementEvaluation, ReadGraph, Statement> advisor, Map<Object, Object> copyMap)
+ BiFunction<ReadGraph, Statement, StatementEvaluation> advisor, Map<Object, Object> copyMap)
throws DatabaseException {
if (DEBUG_COPY)
System.out.println("[" + level + "] CopyAdvisorUtil.copy(" + NameUtils.getSafeName(graph, source) + ", advisor=" + advisor + ")");
return copy;
}
- protected static StatementEvaluation evaluate(ReadGraph graph, Statement stm, BinaryFunction<StatementEvaluation, ReadGraph, Statement> tester) {
+ protected static StatementEvaluation evaluate(ReadGraph graph, Statement stm, BiFunction<ReadGraph, Statement, StatementEvaluation> tester) {
if (tester == null)
return StatementEvaluation.USE_DEFAULT;
- return tester.call(graph, stm);
+ return tester.apply(graph, stm);
}
/**
import java.util.HashSet;
import java.util.TreeMap;
import java.util.UUID;
+import java.util.function.BiFunction;
import org.simantics.databoard.Accessors;
import org.simantics.databoard.Bindings;
import org.simantics.graph.representation.Identity;
import org.simantics.graph.representation.TransferableGraph1;
import org.simantics.graph.representation.Value;
-import org.simantics.utils.datastructures.BinaryFunction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
session.getService(SerialisationSupport.class));
}
- public static void importGraph1(Session session, final TransferableGraph1 tg, IImportAdvisor advisor, final BinaryFunction<Boolean, WriteOnlyGraph, TransferableGraphImportProcess> callback) throws DatabaseException, TransferableGraphException {
+ public static void importGraph1(Session session, final TransferableGraph1 tg, IImportAdvisor advisor, final BiFunction<WriteOnlyGraph, TransferableGraphImportProcess, Boolean> callback) throws DatabaseException, TransferableGraphException {
final TransferableGraphImportProcess process = new TransferableGraphImportProcess(tg,
advisor == null ? new ImportAdvisor() : advisor);
session.syncRequest(new ReadRequest() {
public void perform(WriteOnlyGraph graph) throws DatabaseException {
process.write(graph);
if(callback != null)
- callback.call(graph, process);
+ callback.apply(graph, process);
}
});
}
});
}
- public static void importGraph1WithChanges(Session session, final TransferableGraph1 tg, IImportAdvisor advisor, final BinaryFunction<Boolean, WriteGraph, TransferableGraphImportProcess> callback) throws DatabaseException, TransferableGraphException {
+ public static void importGraph1WithChanges(Session session, final TransferableGraph1 tg, IImportAdvisor advisor, final BiFunction<WriteGraph, TransferableGraphImportProcess, Boolean> callback) throws DatabaseException, TransferableGraphException {
final TransferableGraphImportProcess process = new TransferableGraphImportProcess(tg,
advisor == null ? new ImportAdvisor() : advisor);
session.syncRequest(new ReadRequest() {
comments.add("Imported transferable graph with " + tg.resourceCount + " resources");
graph.addMetadata(comments);
if(callback != null)
- callback.call(graph, process);
+ callback.apply(graph, process);
}
});
}
*******************************************************************************/
package org.simantics.graph.db.old;
+import java.util.function.BiFunction;
+
import org.simantics.db.ReadGraph;
import org.simantics.db.Session;
import org.simantics.db.WriteGraph;
import org.simantics.graph.db.ImportAdvisor;
import org.simantics.graph.db.TransferableGraphException;
import org.simantics.graph.representation.old.OldTransferableGraph1;
-import org.simantics.utils.datastructures.BinaryFunction;
public class OldTransferableGraphs {
- public static void importGraph1(Session session, final OldTransferableGraph1 tg, IImportAdvisor advisor, final BinaryFunction<Boolean, WriteOnlyGraph, OldTransferableGraphImportProcess1> callback) throws DatabaseException, TransferableGraphException {
+ public static void importGraph1(Session session, final OldTransferableGraph1 tg, IImportAdvisor advisor, final BiFunction<WriteOnlyGraph, OldTransferableGraphImportProcess1, Boolean> callback) throws DatabaseException, TransferableGraphException {
final OldTransferableGraphImportProcess1 process = new OldTransferableGraphImportProcess1(tg,
advisor == null ? new ImportAdvisor() : advisor);
session.syncRequest(new ReadRequest() {
public void perform(WriteOnlyGraph graph) throws DatabaseException {
process.write(graph);
if(callback != null)
- callback.call(graph, process);
+ callback.apply(graph, process);
}
});
}
/*******************************************************************************
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * Copyright (c) 2007, 2017 Association for Decentralized Information Management
* in Industry THTH ry.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
*
* Contributors:
* VTT Technical Research Centre of Finland - initial API and implementation
+ * Semantum Oy - #7116 regression fix
*******************************************************************************/
package org.simantics.modeling.ui.modelBrowser.handlers;
import org.simantics.databoard.Bindings;
import org.simantics.db.ReadGraph;
import org.simantics.db.Resource;
-import org.simantics.db.common.request.ResourceRead;
-import org.simantics.db.common.utils.Logger;
+import org.simantics.db.common.request.UniqueRead;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.layer0.variable.Variable;
import org.simantics.modeling.ModelingResources;
import org.simantics.modeling.PropertyVariables;
import org.simantics.ui.selection.WorkbenchSelectionUtils;
import org.simantics.utils.ui.AdaptionUtils;
+import org.slf4j.LoggerFactory;
public class ContextualHelp extends AbstractHandler {
+ private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(ContextualHelp.class);
+
private static String getPossibleId(ExecutionEvent event) {
- String id = null;
try {
- Resource element = WorkbenchSelectionUtils.getPossibleResource(event);
- id = Simantics.getSession().syncRequest(new ResourceRead<String>(element) {
+ ISelection sel = HandlerUtil.getCurrentSelection(event);
+ Resource resource = WorkbenchSelectionUtils.getPossibleResource(sel);
+ Variable variable = WorkbenchSelectionUtils.getPossibleVariable(sel);
+ if (sel.isEmpty() && resource == null && variable == null)
+ return null;
+ return Simantics.getSession().syncRequest(new UniqueRead<String>() {
@Override
public String perform(ReadGraph graph) throws DatabaseException {
ModelingResources MOD = ModelingResources.getInstance(graph);
- Resource component = graph.getPossibleObject(element, MOD.ElementToComponent);
- if (component != null)
- return graph.getPossibleRelatedValue2(component, MOD.contextualHelpId, Bindings.STRING);
+ if (resource != null) {
+ Resource component = graph.getPossibleObject(resource, MOD.ElementToComponent);
+ String id = component != null ? graph.getPossibleRelatedValue2(component, MOD.contextualHelpId, Bindings.STRING) : null;
+ if (id != null)
+ return id;
+ id = graph.getPossibleRelatedValue2(resource, MOD.contextualHelpId, Bindings.STRING);
+ if (id != null)
+ return id;
+ }
- Variable var = WorkbenchSelectionUtils.getPossibleVariable(event);
- if (var != null)
- return var.getPossiblePropertyValue(graph, MOD.contextualHelpId, Bindings.STRING);
+ if (variable != null) {
+ String id = variable.getPossiblePropertyValue(graph, MOD.contextualHelpId, Bindings.STRING);
+ if (id != null)
+ return id;
+ }
- ISelection sel = HandlerUtil.getCurrentSelection(event);
+ // TODO: consider removing this block
if (sel != null) {
PropertyVariables vars = AdaptionUtils.adaptToSingle(sel, PropertyVariables.class);
- if (vars != null) {
- var = vars.getConfiguration();
- if (var != null)
- var.getPossiblePropertyValue(graph, MOD.contextualHelpId, Bindings.STRING);
- }
+ Variable var = vars != null ? vars.getConfiguration() : null;
+ String id = var != null ? var.getPossiblePropertyValue(graph, MOD.contextualHelpId, Bindings.STRING) : null;
+ if (id != null)
+ return id;
}
+
return null;
}
});
} catch (DatabaseException e) {
- Logger.defaultLogError(e);
+ LOGGER.error("", e);
+ return null;
}
- return id;
}
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
-
String id = getPossibleId(event);
if (id != null)
PlatformUI.getWorkbench().getHelpSystem().displayHelp(id);
-
return null;
-
}
}
*******************************************************************************/
package org.simantics.modeling.mapping;
-import gnu.trove.map.hash.THashMap;
-
import java.util.Map;
+import java.util.function.BiFunction;
import org.simantics.db.ReadGraph;
import org.simantics.db.Resource;
import org.simantics.diagram.synchronization.graph.GraphCopyAdvisor;
import org.simantics.diagram.synchronization.graph.GraphSynchronizationHints;
import org.simantics.layer0.Layer0;
-import org.simantics.utils.datastructures.BinaryFunction;
+
+import gnu.trove.map.hash.THashMap;
/**
* @author Tuukka Lehtonen
* Diagram mapping will have problems and potentially break the
* configuration if the type is not the same as in the source.
*/
- BinaryFunction<StatementEvaluation, ReadGraph, Statement> statementAdvisor =
- new BinaryFunction<StatementEvaluation, ReadGraph, Statement>() {
+ BiFunction<ReadGraph, Statement, StatementEvaluation> statementAdvisor =
+ new BiFunction<ReadGraph, Statement, StatementEvaluation>() {
@Override
- public StatementEvaluation call(ReadGraph graph, Statement stm) {
+ public StatementEvaluation apply(ReadGraph graph, Statement stm) {
if (DIA.HasFlagType.equals(stm.getPredicate()))
return StatementEvaluation.INCLUDE;
if (G2D.HasFontStyle.equals(stm.getPredicate()))
}
public static Resource getPossibleResource(RequestProcessor processor, Object input, Resource type) throws DatabaseException {
- if(input instanceof Collection && !((Collection)input).isEmpty()) {
- Object element = ((Collection)input).iterator().next();
+ if(input instanceof Collection && !((Collection<?>)input).isEmpty()) {
+ Object element = ((Collection<?>)input).iterator().next();
if(element instanceof Resource)
return (Resource)element;
}
*******************************************************************************/
package org.simantics.utils.datastructures;
-public interface BinaryCallback<T1, T2> {
+import java.util.function.BiConsumer;
+
+/**
+ * @deprecated use {@link BiConsumer} instead
+ */
+@Deprecated
+public interface BinaryCallback<T1, T2> extends BiConsumer<T1, T2> {
void run(T1 arg1, T2 arg2);
-
+
+ @Override
+ default void accept(T1 arg, T2 arg2) {
+ run(arg, arg2);
+ }
+
}
*/
@Deprecated
@FunctionalInterface
-public interface Callable<T> {
+public interface Callable<T> extends Supplier<T> {
public T call();
+ @Override
+ default T get() {
+ return call();
+ }
+
}
import java.io.PrintStream;
import java.util.concurrent.TimeUnit;
+import java.util.function.BiConsumer;
/**
}
}
- public static class PrintCallback implements BinaryCallback<Long, TimeUnit> {
+ public static class PrintCallback implements BiConsumer<Long, TimeUnit> {
String task;
PrintStream stream;
PrintCallback(String task) {
this.stream = stream;
}
@Override
- public void run(Long arg1, TimeUnit arg2) {
+ public void accept(Long arg1, TimeUnit arg2) {
stream.println(task + " took " + arg1 + " " + arg2.toString());
}
};
time(runnable, reportTimeUnit, new PrintCallback(runnable.toString(), stream));
}
- public static void time(Runnable runnable, TimeUnit reportTimeUnit, BinaryCallback<Long, TimeUnit> result) {
+ public static void time(Runnable runnable, TimeUnit reportTimeUnit, BiConsumer<Long, TimeUnit> result) {
long start = System.nanoTime();
runnable.run();
long end = System.nanoTime();
- result.run(reportTimeUnit.convert(end-start, TimeUnit.NANOSECONDS), reportTimeUnit);
+ result.accept(reportTimeUnit.convert(end-start, TimeUnit.NANOSECONDS), reportTimeUnit);
}
}
*******************************************************************************/
package org.simantics.utils.datastructures;
-public interface UnaryFunction<R, A> {
+import java.util.function.Function;
+
+/**
+ * @deprecated use {@link Function} instead
+ */
+@Deprecated
+public interface UnaryFunction<R, A> extends Function<A, R> {
public R call(A arg);
-
+
+ @Override
+ default R apply(A t) {
+ return call(t);
+ }
+
}