X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.modeling.ui%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fui%2FmodelBrowser%2Fhandlers%2FStandardCopyHandler.java;h=05a698a1339629efb1f98fe049f629c358780b1d;hb=1cd631466bc35e05bc585999b2f325f148cd5629;hp=9730334ccc3dcaabf67ca3ec98c33c82eb729309;hpb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;p=simantics%2Fplatform.git 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 9730334cc..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; @@ -19,6 +19,11 @@ import java.util.Set; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.SubMonitor; +import org.eclipse.core.runtime.jobs.Job; import org.eclipse.jface.action.IStatusLineManager; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.StructuredSelection; @@ -39,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; @@ -52,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) { @@ -91,13 +101,22 @@ public class StandardCopyHandler extends AbstractHandler { if(copyText(selection)) return null; formatSelectionToClipboardText(event); - final Resource[] rs = ResourceAdaptionUtils.toResources(selection); - copyResourcesToClipboard(rs, selection); + Job job = new Job("Copy resources") { + @Override + protected IStatus run(IProgressMonitor monitor) { + monitor.beginTask("Copy resources to clipboard", 1); + copyResourcesToClipboard(rs, selection, SubMonitor.convert(monitor, 1)); + return Status.OK_STATUS; + } + }; + job.setUser(true); + job.schedule(); + return null; } - public static String copyResourcesToClipboard(final Resource[] rs, ISelection selection) { + public static String copyResourcesToClipboard(final Resource[] rs, ISelection selection, IProgressMonitor monitor) { if(rs == null || rs.length == 0) { // This support was added for copying of properties (variables) @@ -105,13 +124,13 @@ public class StandardCopyHandler extends AbstractHandler { if(!variables.isEmpty()) { final SimanticsClipboardImpl builder = new SimanticsClipboardImpl(); for(Variable var : variables) { - builder.addContent(Collections.singleton(ClipboardUtils.createVariable(Simantics.getSession(), var))); + builder.addContent(Collections.singleton(ClipboardUtils.createVariable(Simantics.getSession(), var)), monitor); } Simantics.setClipboard(builder); setCopyMessage(builder.getContents().size(), "variable"); return null; } - setCopyMessage(0, ""); + setCopyMessage(0, ""); //$NON-NLS-1$ return null; } @@ -122,14 +141,14 @@ public class StandardCopyHandler extends AbstractHandler { public void run(ReadGraph graph) throws DatabaseException { for (Resource r : rs) { CopyHandler handler = graph.adapt(r, CopyHandler.class); - handler.copyToClipboard(graph, builder); + handler.copyToClipboard(graph, builder, monitor); } } }); 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; @@ -145,8 +164,11 @@ public class StandardCopyHandler 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)); + } } private boolean formatSelectionToClipboardText(ExecutionEvent event) {