/*******************************************************************************
- * 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
*
* 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;
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;
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<Variable> getVariables(ISelection selection) {
setCopyMessage(builder.getContents().size(), "variable");
return null;
}
- setCopyMessage(0, "");
+ setCopyMessage(0, ""); //$NON-NLS-1$
return null;
}
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;
/*******************************************************************************
- * 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
*
* 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;
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
Simantics.getSession().syncRequest(new ReadRequest() {
@Override
public void run(ReadGraph graph) throws DatabaseException {
- Set<Resource> unique = new HashSet<Resource>();
+ Set<Resource> unique = new HashSet<>();
for (Resource r : rs) {
if (!unique.add(r))
continue;
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);
}
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() {
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;
}
-
+
}
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 {
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> T getPasteHandlerFromResource (Resource resource, Class<T> assignableFrom) {
-
- try {
- return Simantics.getSession().syncRequest(new Adapter<T>(resource, assignableFrom));
- } catch (DatabaseException e) {
- Logger.defaultLogError(e);
- return null;
- }
+ try {
+ return Simantics.getSession().syncRequest(new Adapter<T>(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