/*******************************************************************************
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * Copyright (c) 2007, 2020 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
import org.eclipse.core.runtime.Status;
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.osgi.util.NLS;
import org.simantics.Simantics;
import org.simantics.db.ReadGraph;
import org.simantics.db.RequestProcessor;
import org.simantics.db.layer0.request.IsLinkedTo;
import org.simantics.db.layer0.util.Layer0Utils;
import org.simantics.db.service.SerialisationSupport;
-import org.simantics.diagram.Logger;
import org.simantics.diagram.adapter.GraphToDiagramSynchronizer;
import org.simantics.diagram.content.Change;
import org.simantics.diagram.content.DiagramContentChanges;
import org.simantics.ui.selection.WorkbenchSelectionElement;
import org.simantics.ui.workbench.e4.E4WorkbenchUtils;
import org.simantics.utils.logging.TimeLogger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* This participant populates Elements from ElementClass-resources drops
*/
public class PopulateElementDropParticipant extends AbstractDiagramParticipant implements IDropTargetParticipant {
+ private static final Logger LOGGER = LoggerFactory.getLogger(PopulateElementDropParticipant.class);
+
@Dependency PickContext pickContext;
@Dependency TransformUtil transformUtil;
return processor.syncRequest(new UniqueRead<String>() {
@Override
public String perform(ReadGraph graph) throws DatabaseException {
-// System.out.println("dragged resource: " + draggedResource);
-// System.out.println("drop target resource: " + dropTarget);
+ // System.out.println("dragged resource: " + draggedResource);
+ // System.out.println("drop target resource: " + dropTarget);
Resource sourceModel = graph.syncRequest(new PossibleIndexRoot(draggedResource));
Resource targetModel = graph.syncRequest(new PossibleIndexRoot(dropTarget));
-// System.out.println("source model: " + sourceModel);
-// System.out.println("target model: " + targetModel);
+ // System.out.println("source model: " + sourceModel);
+ // System.out.println("target model: " + targetModel);
// Prevent dragging data from one source model to another.
// If source is not part of any model, everything is okay.
if (sourceModel != null && !graph.syncRequest(new IsLinkedTo(targetModel, sourceModel))) {
// Prevent a symbol instantiating within its own configuration.
// NOTE: this doesn't handle transitive cycles.
- return "Cannot instantiate " + NameUtils.getSafeName(graph, draggedResource) + " into model "
- + NameUtils.getURIOrSafeNameInternal(graph, targetModel) + ". The source namespace ("
- + NameUtils.getURIOrSafeNameInternal(graph, sourceModel) + ") is not linked to the target model.";
+ return NLS.bind(Messages.PopulateElementDropParticipant_CannotInstantiate,
+ new Object[] { NameUtils.getSafeName(graph, draggedResource),
+ NameUtils.getURIOrSafeNameInternal(graph, targetModel),
+ NameUtils.getURIOrSafeNameInternal(graph, sourceModel) });
}
-
+
// Prevent dragging to published components
ModelingResources MOD = ModelingResources.getInstance(graph);
StructuralResource2 STR = StructuralResource2.getInstance(graph);
Resource configuration = graph.getPossibleObject(dropTarget, MOD.DiagramToComposite);
if (configuration != null) {
Resource componentTypeFromDiagram = graph.getPossibleObject(configuration, STR.Defines);
- if(componentTypeFromDiagram != null) {
- if(Layer0Utils.isPublished(graph, componentTypeFromDiagram))
- return "Cannot create elements into a diagram that belongs to a published user component.";
+ if (componentTypeFromDiagram != null) {
+ if (Layer0Utils.isPublished(graph, componentTypeFromDiagram))
+ return Messages.PopulateElementDropParticipant_CannotCreateElementIntoDiagram;
}
}
if (componentTypeFromSymbol != null) {
if (configuration != null) {
Resource componentTypeFromDiagram = graph.getPossibleObject(configuration, STR.Defines);
- if (componentTypeFromDiagram != null && componentTypeFromSymbol.equals(componentTypeFromDiagram)) {
- return "Cannot instantiate user component within its own configuration.";
+ if (componentTypeFromDiagram != null
+ && componentTypeFromSymbol.equals(componentTypeFromDiagram)) {
+ return Messages.PopulateElementDropParticipant_CannotInstantiateUserComponent;
}
}
}
@Override
public void drop(DropTargetDropEvent dtde, final IDnDContext dp) {
- TimeLogger.resetTimeAndLog(getClass(), "drop");
+ TimeLogger.resetTimeAndLog(getClass(), "drop"); //$NON-NLS-1$
final IDiagram d = getHint(DiagramHints.KEY_DIAGRAM);
if (d == null)
});
} catch (DatabaseException e) {
- Logger.defaultLogError(e);
+ LOGGER.error("symbolDropHandler invocation failed", e);
}
return;
}
}
} catch (DatabaseException e) {
- Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Diagram content change tracking failed.", e));
+ Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.PopulateElementDropParticipant_ActivatorDiagramContentTrackingFailed, e));
}
}