From: Tuukka Lehtonen Date: Fri, 7 Dec 2018 09:53:05 +0000 (+0200) Subject: Fixed StandardCutHandler IllegalThreadAccess problem X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=4aa15c31ccd0d91cfdfbc9d63eca79e9045cc337;p=simantics%2Fplatform.git Fixed StandardCutHandler IllegalThreadAccess problem Also changed old deprecated logger to SLF4J logging to the related classes. gitlab #74 gitlab #133 Change-Id: I0dbb14d4025a5fc2c58519d933e3dfdf03de1878 (cherry picked from commit f7073364d424fb9b1ef84ade1cfa49553a694c22) --- diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser/handlers/StandardCopyHandler.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser/handlers/StandardCopyHandler.java index 1ce5b2d36..05a698a13 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser/handlers/StandardCopyHandler.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser/handlers/StandardCopyHandler.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007 VTT Technical Research Centre of Finland and others. + * Copyright (c) 2007, 2018 VTT Technical Research Centre of Finland and others. * 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 @@ -7,11 +7,11 @@ * * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation + * Semantum Oy - gitlab simantics/platform#133 *******************************************************************************/ package org.simantics.modeling.ui.modelBrowser.handlers; -import gnu.trove.set.hash.THashSet; - +import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Set; @@ -44,7 +44,6 @@ import org.simantics.browsing.ui.NodeContext; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.common.request.ReadRequest; -import org.simantics.db.common.utils.Logger; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.SelectionHints; import org.simantics.db.layer0.adapter.CopyHandler; @@ -57,9 +56,15 @@ import org.simantics.utils.ui.ISelectionUtils; import org.simantics.utils.ui.SWTUtils; import org.simantics.utils.ui.SWTUtils.ControlFilter; import org.simantics.utils.ui.workbench.WorkbenchUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import gnu.trove.set.hash.THashSet; public class StandardCopyHandler extends AbstractHandler { + private static final Logger LOGGER = LoggerFactory.getLogger(StandardCopyHandler.class); + private static IStatusLineManager status; private static List getVariables(ISelection selection) { @@ -125,7 +130,7 @@ public class StandardCopyHandler extends AbstractHandler { setCopyMessage(builder.getContents().size(), "variable"); return null; } - setCopyMessage(0, ""); + setCopyMessage(0, ""); //$NON-NLS-1$ return null; } @@ -143,7 +148,7 @@ public class StandardCopyHandler extends AbstractHandler { Simantics.setClipboard(builder); setCopyMessage(builder.getContents().size(), "resource"); } catch (DatabaseException e) { - Logger.defaultLogError(e); + LOGGER.error("Failed to copy {} resources to clipboard: {}", rs.length, Arrays.toString(rs), e); //$NON-NLS-1$ } return null; diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser/handlers/StandardCutHandler.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser/handlers/StandardCutHandler.java index 0c6d8ba3d..1bd484ae8 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser/handlers/StandardCutHandler.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser/handlers/StandardCutHandler.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007 VTT Technical Research Centre of Finland and others. + * Copyright (c) 2007, 2018 VTT Technical Research Centre of Finland and others. * 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 @@ -7,10 +7,11 @@ * * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation + * Semantum Oy - gitlab simantics/platform#133 *******************************************************************************/ package org.simantics.modeling.ui.modelBrowser.handlers; - +import java.util.Arrays; import java.util.HashSet; import java.util.Set; @@ -30,15 +31,20 @@ import org.simantics.Simantics; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.common.request.ReadRequest; -import org.simantics.db.common.utils.Logger; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.adapter.CopyHandler; import org.simantics.db.layer0.util.SimanticsClipboardImpl; +import org.simantics.modeling.ui.Activator; import org.simantics.ui.utils.ResourceAdaptionUtils; +import org.simantics.utils.ui.SWTUtils; import org.simantics.utils.ui.workbench.WorkbenchUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class StandardCutHandler extends AbstractHandler { + private static final Logger LOGGER = LoggerFactory.getLogger(StandardCutHandler.class); + private static IStatusLineManager status; @Override @@ -61,7 +67,7 @@ public class StandardCutHandler extends AbstractHandler { Simantics.getSession().syncRequest(new ReadRequest() { @Override public void run(ReadGraph graph) throws DatabaseException { - Set unique = new HashSet(); + Set unique = new HashSet<>(); for (Resource r : rs) { if (!unique.add(r)) continue; @@ -73,11 +79,11 @@ public class StandardCutHandler extends AbstractHandler { Simantics.setClipboard(builder); setCutMessage(builder.getContents().size(), "resource"); - + return Status.OK_STATUS; } catch (DatabaseException e) { - Logger.defaultLogError(e); + LOGGER.error("Cut operation failed", e); //$NON-NLS-1$ + return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Cut operation failed", e); } - return Status.OK_STATUS; } }; job.setUser(true); @@ -96,12 +102,14 @@ public class StandardCutHandler extends AbstractHandler { } private static void setStatus(String message) { - if (status != null) - status.setMessage(message); + if (status != null) { + SWTUtils.asyncExec( + PlatformUI.getWorkbench().getDisplay(), + () -> status.setMessage(message)); + } } public static String cutResourcesToClipboard(final Resource[] rs, ISelection selection) { - try { final SimanticsClipboardImpl builder = new SimanticsClipboardImpl(); Simantics.getSession().syncRequest(new ReadRequest() { @@ -116,10 +124,10 @@ public class StandardCutHandler extends AbstractHandler { Simantics.setClipboard(builder); setCutMessage(builder.getContents().size(), "resource"); } catch (DatabaseException e) { - Logger.defaultLogError(e); + LOGGER.error("Failed to cut {} resources to clipboard: {}", rs.length, Arrays.toString(rs), e); //$NON-NLS-1$ } return null; } - + } diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser/handlers/StandardPasteHandler.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser/handlers/StandardPasteHandler.java index 32e3ef60f..fa4f59530 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser/handlers/StandardPasteHandler.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser/handlers/StandardPasteHandler.java @@ -28,15 +28,18 @@ import org.eclipse.ui.handlers.HandlerUtil; import org.simantics.Simantics; import org.simantics.db.Resource; import org.simantics.db.common.primitiverequest.Adapter; -import org.simantics.db.common.utils.Logger; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.adapter.PasteHandler; import org.simantics.ui.SimanticsUI; import org.simantics.utils.ui.ErrorLogger; import org.simantics.utils.ui.ExceptionUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class StandardPasteHandler extends AbstractHandler implements IHandler { + private static final Logger LOGGER = LoggerFactory.getLogger(StandardPasteHandler.class); + @Override public Object execute(ExecutionEvent event) throws ExecutionException { @@ -90,28 +93,22 @@ public class StandardPasteHandler extends AbstractHandler implements IHandler { return op; } - + public static void pasteResourceFromClipboardWithoutMonitor (final PasteHandler handler) { - try { - handler.pasteFromClipboard(Simantics.getClipboard()); - } catch (DatabaseException e) { - try { - throw new InvocationTargetException(e); - } catch (InvocationTargetException e1) { - e1.getCause().printStackTrace(); - } - e.printStackTrace(); - } + try { + handler.pasteFromClipboard(Simantics.getClipboard()); + } catch (DatabaseException e) { + LOGGER.error("Failed to paste resource from clipboard with handler {}", handler, e); //$NON-NLS-1$ + } } - + public static T getPasteHandlerFromResource (Resource resource, Class assignableFrom) { - - try { - return Simantics.getSession().syncRequest(new Adapter(resource, assignableFrom)); - } catch (DatabaseException e) { - Logger.defaultLogError(e); - return null; - } + try { + return Simantics.getSession().syncRequest(new Adapter(resource, assignableFrom)); + } catch (DatabaseException e) { + LOGGER.error("Failed to get paste handler from resource {}", resource, e); //$NON-NLS-1$ + return null; + } } -} +} \ No newline at end of file