From: Tuukka Lehtonen Date: Fri, 31 Mar 2017 13:14:02 +0000 (+0300) Subject: Replaced use of deprecated BinaryFunction et al with BiFunction et al X-Git-Tag: v1.28.0~31 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=aaa119360108a77eb4fcf6f2ade0591cbfaf0415;p=simantics%2Fplatform.git Replaced use of deprecated BinaryFunction et al with BiFunction et al Also added missing logic to GraphExplorerComposite.SelectionElement to discover Resource from Variable when WorkbenchSelectionElement is asked for AnyResource. This is part of the fix for #7116. Fixed breakage from ContextualHelp F1 keystroke handler which was introduced in the original SVN commit r32734 (#6446). refs #7116 refs #7117 Change-Id: Ia7c88d2c1b274fd788a0a18d95c2f059cea36086 (cherry picked from commit e84008c029ef2336cf55ad371256c9a12a889e98) --- diff --git a/bundles/org.simantics.browsing.ui.nattable/src/org/simantics/browsing/ui/nattable/NatTableGraphExplorer.java b/bundles/org.simantics.browsing.ui.nattable/src/org/simantics/browsing/ui/nattable/NatTableGraphExplorer.java index cc978e7e8..3bb05553d 100644 --- a/bundles/org.simantics.browsing.ui.nattable/src/org/simantics/browsing/ui/nattable/NatTableGraphExplorer.java +++ b/bundles/org.simantics.browsing.ui.nattable/src/org/simantics/browsing/ui/nattable/NatTableGraphExplorer.java @@ -19,6 +19,7 @@ import java.util.concurrent.Semaphore; 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; @@ -89,7 +90,6 @@ import org.eclipse.nebula.widgets.nattable.painter.NatTableBorderOverlayPainter; 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; @@ -190,7 +190,6 @@ import org.simantics.browsing.ui.swt.ViewerCellReference; 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; @@ -297,10 +296,10 @@ public class NatTableGraphExplorer extends GraphExplorerImplBase implements Grap private boolean expand; private boolean verticalBarVisible = false; - private BinaryFunction selectionTransformation = new BinaryFunction() { + private BiFunction selectionTransformation = new BiFunction() { @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); @@ -846,7 +845,7 @@ public class NatTableGraphExplorer extends GraphExplorerImplBase implements Grap } protected Object[] transformSelection(Object[] objects) { - return selectionTransformation.call(this, objects); + return selectionTransformation.apply(this, objects); } protected static Object[] filter(SelectionFilter filter, NodeContext[] contexts) { @@ -859,7 +858,7 @@ public class NatTableGraphExplorer extends GraphExplorerImplBase implements Grap @Override public void setSelectionTransformation( - BinaryFunction f) { + BiFunction f) { this.selectionTransformation = f; } diff --git a/bundles/org.simantics.browsing.ui.swt/META-INF/MANIFEST.MF b/bundles/org.simantics.browsing.ui.swt/META-INF/MANIFEST.MF index 9869cab3d..37466aeda 100644 --- a/bundles/org.simantics.browsing.ui.swt/META-INF/MANIFEST.MF +++ b/bundles/org.simantics.browsing.ui.swt/META-INF/MANIFEST.MF @@ -16,7 +16,8 @@ Require-Bundle: org.simantics.utils.thread.swt;bundle-version="1.0.0", 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, diff --git a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/GraphExplorerFactory.java b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/GraphExplorerFactory.java index de4215659..b99962bf0 100644 --- a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/GraphExplorerFactory.java +++ b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/GraphExplorerFactory.java @@ -12,6 +12,7 @@ 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; @@ -34,7 +35,6 @@ import org.simantics.db.layer0.SelectionHints; 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; @@ -50,7 +50,7 @@ public class GraphExplorerFactory { private IServiceLocator serviceLocator; - private BinaryFunction selectionTransformation = new BinaryFunction() { + private BiFunction selectionTransformation = new BiFunction() { private Resource getModel(final Object object) { if(object instanceof NodeContext) { @@ -90,9 +90,8 @@ public class GraphExplorerFactory { 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); @@ -120,7 +119,7 @@ public class GraphExplorerFactory { return this; } - public GraphExplorerFactory selectionTransformation(BinaryFunction transformation) { + public GraphExplorerFactory selectionTransformation(BiFunction transformation) { this.selectionTransformation = transformation; return this; } @@ -194,7 +193,8 @@ public class GraphExplorerFactory { //GraphExplorerImpl2 explorer = new GraphExplorerImpl2(parent, style); try { Bundle bundle = Platform.getBundle("org.simantics.browsing.ui.nattable"); - Class clazz = (Class)bundle.loadClass("org.simantics.browsing.ui.nattable.NatTableGraphExplorer"); + @SuppressWarnings("unchecked") + Class clazz = (Class)bundle.loadClass("org.simantics.browsing.ui.nattable.NatTableGraphExplorer"); //Class clazz = (Class)bundle.getClass().getClassLoader().loadClass("org.simantics.browsing.ui.nattable.NatTableGraphExplorer"); GraphExplorer explorer = clazz.getConstructor(Composite.class, int.class).newInstance(parent,style); explorer.setSelectionDataResolver(selectionDataResolver); diff --git a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/GraphExplorerImpl.java b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/GraphExplorerImpl.java index 62b284858..0e45f86ca 100644 --- a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/GraphExplorerImpl.java +++ b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/GraphExplorerImpl.java @@ -31,6 +31,7 @@ import java.util.concurrent.ScheduledExecutorService; 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; @@ -161,7 +162,6 @@ import org.simantics.browsing.ui.swt.internal.Threads; 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; @@ -544,10 +544,10 @@ class GraphExplorerImpl extends GraphExplorerImplBase implements Listener, Graph protected BasePostSelectionProvider selectionProvider = new BasePostSelectionProvider(); protected SelectionDataResolver selectionDataResolver; protected SelectionFilter selectionFilter; - protected BinaryFunction selectionTransformation = new BinaryFunction() { + protected BiFunction selectionTransformation = new BiFunction() { @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); @@ -1812,7 +1812,7 @@ class GraphExplorerImpl extends GraphExplorerImplBase implements Listener, Graph } @Override - public void setSelectionTransformation(BinaryFunction f) { + public void setSelectionTransformation(BiFunction f) { this.selectionTransformation = f; } @@ -3168,7 +3168,7 @@ class GraphExplorerImpl extends GraphExplorerImplBase implements Listener, Graph } protected Object[] transformSelection(Object[] objects) { - return selectionTransformation.call(this, objects); + return selectionTransformation.apply(this, objects); } protected static Object[] filter(SelectionFilter filter, NodeContext[] contexts) { diff --git a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/GraphExplorerImpl2.java b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/GraphExplorerImpl2.java index 79bd35b87..928bed03f 100644 --- a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/GraphExplorerImpl2.java +++ b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/GraphExplorerImpl2.java @@ -30,6 +30,7 @@ import java.util.concurrent.Semaphore; 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; @@ -164,7 +165,6 @@ import org.simantics.browsing.ui.swt.internal.Threads; 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; @@ -251,10 +251,10 @@ public class GraphExplorerImpl2 extends GraphExplorerImplBase implements GraphEx private boolean expand; private boolean verticalBarVisible = false; - private BinaryFunction selectionTransformation = new BinaryFunction() { + private BiFunction selectionTransformation = new BiFunction() { @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); @@ -885,7 +885,7 @@ public class GraphExplorerImpl2 extends GraphExplorerImplBase implements GraphEx } protected Object[] transformSelection(Object[] objects) { - return selectionTransformation.call(this, objects); + return selectionTransformation.apply(this, objects); } protected static Object[] filter(SelectionFilter filter, NodeContext[] contexts) { @@ -898,7 +898,7 @@ public class GraphExplorerImpl2 extends GraphExplorerImplBase implements GraphEx @Override public void setSelectionTransformation( - BinaryFunction f) { + BiFunction f) { this.selectionTransformation = f; } diff --git a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/widgets/GraphExplorerComposite.java b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/widgets/GraphExplorerComposite.java index 4b5a48e14..f583d7e7f 100644 --- a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/widgets/GraphExplorerComposite.java +++ b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/widgets/GraphExplorerComposite.java @@ -16,6 +16,7 @@ import java.util.Collections; 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; @@ -102,12 +103,11 @@ import org.simantics.db.AsyncReadGraph; 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; @@ -126,7 +126,6 @@ import org.simantics.ui.selection.WorkbenchSelectionContentType; 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; @@ -135,10 +134,14 @@ import org.simantics.utils.datastructures.hints.IHintContext.Key; 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; @@ -248,39 +251,41 @@ public class GraphExplorerComposite extends Composite implements Widget, IAdapta @SuppressWarnings("unchecked") @Override public T getContent(WorkbenchSelectionContentType 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(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) { @@ -297,12 +302,12 @@ public class GraphExplorerComposite extends Composite implements Widget, IAdapta } } - private BinaryFunction selectionTransformation = new BinaryFunction() { + private BiFunction selectionTransformation = new BiFunction() { 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]); @@ -723,7 +728,7 @@ public class GraphExplorerComposite extends Composite implements Widget, IAdapta 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); @@ -863,7 +868,7 @@ public class GraphExplorerComposite extends Composite implements Widget, IAdapta this.filterAreaSource = provider; } - public void setSelectionTransformation(BinaryFunction transformation) { + public void setSelectionTransformation(BiFunction transformation) { this.selectionTransformation = transformation; if(explorer != null) explorer.setSelectionTransformation(transformation); } diff --git a/bundles/org.simantics.browsing.ui/src/org/simantics/browsing/ui/GraphExplorer.java b/bundles/org.simantics.browsing.ui/src/org/simantics/browsing/ui/GraphExplorer.java index 0bc3e0215..0745d1d81 100644 --- a/bundles/org.simantics.browsing.ui/src/org/simantics/browsing/ui/GraphExplorer.java +++ b/bundles/org.simantics.browsing.ui/src/org/simantics/browsing/ui/GraphExplorer.java @@ -14,6 +14,7 @@ package org.simantics.browsing.ui; 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; @@ -22,7 +23,6 @@ import org.simantics.browsing.ui.NodeContext.PrimitiveQueryKey; 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; /** @@ -205,7 +205,7 @@ public interface GraphExplorer extends IAdaptable { */ void setSelectionFilter(SelectionFilter f); - void setSelectionTransformation(BinaryFunction f); + void setSelectionTransformation(BiFunction f); //ISelectionProvider getSelectionProvider(); diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/PossibleVariableRepresents.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/PossibleVariableRepresents.java new file mode 100644 index 000000000..bb6a77da6 --- /dev/null +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/PossibleVariableRepresents.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * 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 { + + public PossibleVariableRepresents(Variable var) { + super(var); + } + + @Override + public Resource perform(ReadGraph graph) throws DatabaseException { + return variable.getPossibleRepresents(graph); + } + +} diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/handler/Paster.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/handler/Paster.java index 0f243db48..03edda6bd 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/handler/Paster.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/handler/Paster.java @@ -1,8 +1,6 @@ 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; @@ -14,6 +12,7 @@ import java.util.HashSet; 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; @@ -62,9 +61,11 @@ import org.simantics.structural.stubs.StructuralResource2; 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 */ @@ -688,10 +689,10 @@ public class Paster { * Diagram mapping will have problems and potentially break the * configuration if the type is not the same as in the source. */ - BinaryFunction statementAdvisor = - new BinaryFunction() { + BiFunction statementAdvisor = + new BiFunction() { @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; diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/CopyAdvisorUtil.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/CopyAdvisorUtil.java index 60d4c56ae..61d09acdd 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/CopyAdvisorUtil.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/CopyAdvisorUtil.java @@ -15,6 +15,7 @@ import gnu.trove.map.hash.THashMap; import java.util.Map; import java.util.Set; +import java.util.function.BiFunction; import org.simantics.databoard.Bindings; import org.simantics.databoard.binding.Binding; @@ -44,7 +45,6 @@ import org.simantics.diagram.synchronization.SynchronizationHints; 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 @@ -223,7 +223,7 @@ public class CopyAdvisorUtil { * @return the copied resource * @throws DatabaseException */ - public static Resource copy(WriteGraph graph, Resource source, BinaryFunction advisor) throws DatabaseException { + public static Resource copy(WriteGraph graph, Resource source, BiFunction advisor) throws DatabaseException { return copy(graph, source, 0, advisor, new THashMap()); } @@ -238,11 +238,11 @@ public class CopyAdvisorUtil { * @return * @throws DatabaseException */ - public static Resource copy(WriteGraph graph, Resource source, BinaryFunction advisor, Map copyMap) throws DatabaseException { + public static Resource copy(WriteGraph graph, Resource source, BiFunction advisor, Map copyMap) throws DatabaseException { return copy(graph, source, 0, advisor, copyMap); } - private static Resource copy(WriteGraph graph, Resource source, int level, BinaryFunction advisor, Map copyMap) throws DatabaseException { + private static Resource copy(WriteGraph graph, Resource source, int level, BiFunction advisor, Map copyMap) throws DatabaseException { if (DEBUG_COPY) System.out.println("[" + level + "] CopyAdvisorUtil.copy(" + NameUtils.getSafeName(graph, source) + ", advisor=" + advisor + ")"); @@ -320,7 +320,7 @@ public class CopyAdvisorUtil { } } 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) @@ -363,7 +363,7 @@ public class CopyAdvisorUtil { * @throws DatabaseException */ public static Resource copy2(WriteGraph graph, Resource source, - BinaryFunction advisor) throws DatabaseException { + BiFunction advisor) throws DatabaseException { return copy2(graph, source, 0, advisor, new THashMap()); } @@ -379,13 +379,13 @@ public class CopyAdvisorUtil { * @throws DatabaseException */ public static Resource copy2(WriteGraph graph, Resource source, - BinaryFunction advisor, Map copyMap) + BiFunction advisor, Map copyMap) throws DatabaseException { return copy2(graph, source, 0, advisor, copyMap); } private static Resource copy2(final WriteGraph graph, final Resource source, final int level, - BinaryFunction advisor, Map copyMap) + BiFunction advisor, Map copyMap) throws DatabaseException { if (DEBUG_COPY) System.out.println("[" + level + "] CopyAdvisorUtil.copy(" + NameUtils.getSafeName(graph, source) + ", advisor=" + advisor + ")"); @@ -536,7 +536,7 @@ public class CopyAdvisorUtil { * @throws DatabaseException */ public static Resource copy3(WriteGraph graph, Resource source, Resource model, - BinaryFunction advisor) throws DatabaseException { + BiFunction advisor) throws DatabaseException { String modelURI = graph.getURI(model); return copy3(graph, modelURI, source, 0, advisor, new THashMap()); } @@ -554,13 +554,13 @@ public class CopyAdvisorUtil { * @throws DatabaseException */ public static Resource copy3(WriteGraph graph, Resource source, Resource model, - BinaryFunction advisor, Map copyMap) throws DatabaseException { + BiFunction advisor, Map 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 advisor, Map copyMap) + BiFunction advisor, Map copyMap) throws DatabaseException { if (DEBUG_COPY) System.out.println("[" + level + "] CopyAdvisorUtil.copy(" + NameUtils.getSafeName(graph, source) + ", advisor=" + advisor + ")"); @@ -698,10 +698,10 @@ public class CopyAdvisorUtil { return copy; } - protected static StatementEvaluation evaluate(ReadGraph graph, Statement stm, BinaryFunction tester) { + protected static StatementEvaluation evaluate(ReadGraph graph, Statement stm, BiFunction tester) { if (tester == null) return StatementEvaluation.USE_DEFAULT; - return tester.call(graph, stm); + return tester.apply(graph, stm); } /** diff --git a/bundles/org.simantics.graph.db/src/org/simantics/graph/db/TransferableGraphs.java b/bundles/org.simantics.graph.db/src/org/simantics/graph/db/TransferableGraphs.java index bdfd3de6e..cd9111ec1 100644 --- a/bundles/org.simantics.graph.db/src/org/simantics/graph/db/TransferableGraphs.java +++ b/bundles/org.simantics.graph.db/src/org/simantics/graph/db/TransferableGraphs.java @@ -21,6 +21,7 @@ import java.util.Collection; 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; @@ -61,7 +62,6 @@ import org.simantics.graph.representation.External; 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; @@ -154,7 +154,7 @@ public class TransferableGraphs { session.getService(SerialisationSupport.class)); } - public static void importGraph1(Session session, final TransferableGraph1 tg, IImportAdvisor advisor, final BinaryFunction callback) throws DatabaseException, TransferableGraphException { + public static void importGraph1(Session session, final TransferableGraph1 tg, IImportAdvisor advisor, final BiFunction callback) throws DatabaseException, TransferableGraphException { final TransferableGraphImportProcess process = new TransferableGraphImportProcess(tg, advisor == null ? new ImportAdvisor() : advisor); session.syncRequest(new ReadRequest() { @@ -168,7 +168,7 @@ public class TransferableGraphs { public void perform(WriteOnlyGraph graph) throws DatabaseException { process.write(graph); if(callback != null) - callback.call(graph, process); + callback.apply(graph, process); } }); } @@ -235,7 +235,7 @@ public class TransferableGraphs { }); } - public static void importGraph1WithChanges(Session session, final TransferableGraph1 tg, IImportAdvisor advisor, final BinaryFunction callback) throws DatabaseException, TransferableGraphException { + public static void importGraph1WithChanges(Session session, final TransferableGraph1 tg, IImportAdvisor advisor, final BiFunction callback) throws DatabaseException, TransferableGraphException { final TransferableGraphImportProcess process = new TransferableGraphImportProcess(tg, advisor == null ? new ImportAdvisor() : advisor); session.syncRequest(new ReadRequest() { @@ -252,7 +252,7 @@ public class TransferableGraphs { comments.add("Imported transferable graph with " + tg.resourceCount + " resources"); graph.addMetadata(comments); if(callback != null) - callback.call(graph, process); + callback.apply(graph, process); } }); } diff --git a/bundles/org.simantics.graph.db/src/org/simantics/graph/db/old/OldTransferableGraphs.java b/bundles/org.simantics.graph.db/src/org/simantics/graph/db/old/OldTransferableGraphs.java index 2d786a580..4786abd3b 100644 --- a/bundles/org.simantics.graph.db/src/org/simantics/graph/db/old/OldTransferableGraphs.java +++ b/bundles/org.simantics.graph.db/src/org/simantics/graph/db/old/OldTransferableGraphs.java @@ -11,6 +11,8 @@ *******************************************************************************/ 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; @@ -22,11 +24,10 @@ import org.simantics.graph.db.IImportAdvisor; 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 callback) throws DatabaseException, TransferableGraphException { + public static void importGraph1(Session session, final OldTransferableGraph1 tg, IImportAdvisor advisor, final BiFunction callback) throws DatabaseException, TransferableGraphException { final OldTransferableGraphImportProcess1 process = new OldTransferableGraphImportProcess1(tg, advisor == null ? new ImportAdvisor() : advisor); session.syncRequest(new ReadRequest() { @@ -40,7 +41,7 @@ public class OldTransferableGraphs { public void perform(WriteOnlyGraph graph) throws DatabaseException { process.write(graph); if(callback != null) - callback.call(graph, process); + callback.apply(graph, process); } }); } diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser/handlers/ContextualHelp.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser/handlers/ContextualHelp.java index df01fe5d2..9a1ea8360 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser/handlers/ContextualHelp.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser/handlers/ContextualHelp.java @@ -1,5 +1,5 @@ /******************************************************************************* - * 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 @@ -8,6 +8,7 @@ * * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation + * Semantum Oy - #7116 regression fix *******************************************************************************/ package org.simantics.modeling.ui.modelBrowser.handlers; @@ -21,61 +22,71 @@ import org.simantics.Simantics; 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(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() { @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; - } } diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/mapping/ElementCopyAdvisor.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/mapping/ElementCopyAdvisor.java index be13d8cf8..994aa1ab1 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/mapping/ElementCopyAdvisor.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/mapping/ElementCopyAdvisor.java @@ -11,9 +11,8 @@ *******************************************************************************/ 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; @@ -33,7 +32,8 @@ import org.simantics.diagram.synchronization.graph.CopyAdvisorUtil; 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 @@ -48,10 +48,10 @@ public class ElementCopyAdvisor extends GraphCopyAdvisor { * Diagram mapping will have problems and potentially break the * configuration if the type is not the same as in the source. */ - BinaryFunction statementAdvisor = - new BinaryFunction() { + BiFunction statementAdvisor = + new BiFunction() { @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())) diff --git a/bundles/org.simantics.ui/src/org/simantics/ui/selection/WorkbenchSelectionUtils.java b/bundles/org.simantics.ui/src/org/simantics/ui/selection/WorkbenchSelectionUtils.java index 34b01b8f2..765a37c2a 100644 --- a/bundles/org.simantics.ui/src/org/simantics/ui/selection/WorkbenchSelectionUtils.java +++ b/bundles/org.simantics.ui/src/org/simantics/ui/selection/WorkbenchSelectionUtils.java @@ -119,8 +119,8 @@ public class WorkbenchSelectionUtils { } 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; } diff --git a/bundles/org.simantics.utils.datastructures/src/org/simantics/utils/datastructures/BinaryCallback.java b/bundles/org.simantics.utils.datastructures/src/org/simantics/utils/datastructures/BinaryCallback.java index e384efeb9..331a81cd0 100644 --- a/bundles/org.simantics.utils.datastructures/src/org/simantics/utils/datastructures/BinaryCallback.java +++ b/bundles/org.simantics.utils.datastructures/src/org/simantics/utils/datastructures/BinaryCallback.java @@ -11,8 +11,19 @@ *******************************************************************************/ package org.simantics.utils.datastructures; -public interface BinaryCallback { +import java.util.function.BiConsumer; + +/** + * @deprecated use {@link BiConsumer} instead + */ +@Deprecated +public interface BinaryCallback extends BiConsumer { void run(T1 arg1, T2 arg2); - + + @Override + default void accept(T1 arg, T2 arg2) { + run(arg, arg2); + } + } diff --git a/bundles/org.simantics.utils.datastructures/src/org/simantics/utils/datastructures/Callable.java b/bundles/org.simantics.utils.datastructures/src/org/simantics/utils/datastructures/Callable.java index 6bf58494b..5ba3face2 100644 --- a/bundles/org.simantics.utils.datastructures/src/org/simantics/utils/datastructures/Callable.java +++ b/bundles/org.simantics.utils.datastructures/src/org/simantics/utils/datastructures/Callable.java @@ -18,8 +18,13 @@ import java.util.function.Supplier; */ @Deprecated @FunctionalInterface -public interface Callable { +public interface Callable extends Supplier { public T call(); + @Override + default T get() { + return call(); + } + } diff --git a/bundles/org.simantics.utils.datastructures/src/org/simantics/utils/datastructures/TimingUtil.java b/bundles/org.simantics.utils.datastructures/src/org/simantics/utils/datastructures/TimingUtil.java index 42eed9b89..99e952bb4 100644 --- a/bundles/org.simantics.utils.datastructures/src/org/simantics/utils/datastructures/TimingUtil.java +++ b/bundles/org.simantics.utils.datastructures/src/org/simantics/utils/datastructures/TimingUtil.java @@ -13,6 +13,7 @@ package org.simantics.utils.datastructures; import java.io.PrintStream; import java.util.concurrent.TimeUnit; +import java.util.function.BiConsumer; /** @@ -31,7 +32,7 @@ public final class TimingUtil { } } - public static class PrintCallback implements BinaryCallback { + public static class PrintCallback implements BiConsumer { String task; PrintStream stream; PrintCallback(String task) { @@ -42,7 +43,7 @@ public final class TimingUtil { 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()); } }; @@ -59,11 +60,11 @@ public final class TimingUtil { time(runnable, reportTimeUnit, new PrintCallback(runnable.toString(), stream)); } - public static void time(Runnable runnable, TimeUnit reportTimeUnit, BinaryCallback result) { + public static void time(Runnable runnable, TimeUnit reportTimeUnit, BiConsumer 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); } } diff --git a/bundles/org.simantics.utils.datastructures/src/org/simantics/utils/datastructures/UnaryFunction.java b/bundles/org.simantics.utils.datastructures/src/org/simantics/utils/datastructures/UnaryFunction.java index bb38164b7..bb2148f48 100644 --- a/bundles/org.simantics.utils.datastructures/src/org/simantics/utils/datastructures/UnaryFunction.java +++ b/bundles/org.simantics.utils.datastructures/src/org/simantics/utils/datastructures/UnaryFunction.java @@ -11,8 +11,19 @@ *******************************************************************************/ package org.simantics.utils.datastructures; -public interface UnaryFunction { +import java.util.function.Function; + +/** + * @deprecated use {@link Function} instead + */ +@Deprecated +public interface UnaryFunction extends Function { public R call(A arg); - + + @Override + default R apply(A t) { + return call(t); + } + }