]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/e4/PopulateElementDropParticipant.java
Removed unnecessary dependencies on org.apache.log4j
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / diagramEditor / e4 / PopulateElementDropParticipant.java
index 51f5d82698201b412e8dde2437e8cc13ff2287ac..4e7ac0ab815ab3b8605c5f67ed466018c69c047e 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * 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
@@ -30,6 +30,7 @@ import org.eclipse.core.runtime.IStatus;
 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;
@@ -44,7 +45,6 @@ import org.simantics.db.exception.DatabaseException;
 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;
@@ -82,12 +82,16 @@ import org.simantics.ui.dnd.LocalObjectTransferable;
 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;
        
@@ -210,32 +214,33 @@ public class PopulateElementDropParticipant extends AbstractDiagramParticipant i
         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;
                     }
                 }
 
@@ -244,8 +249,9 @@ public class PopulateElementDropParticipant extends AbstractDiagramParticipant i
                 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;
                         }
                     }
                 }
@@ -284,7 +290,7 @@ public class PopulateElementDropParticipant extends AbstractDiagramParticipant i
 
     @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)
@@ -318,7 +324,7 @@ public class PopulateElementDropParticipant extends AbstractDiagramParticipant i
                                        });
                                        
                                } catch (DatabaseException e) {
-                                       Logger.defaultLogError(e);
+                                       LOGGER.error("symbolDropHandler invocation failed", e);
                                }
                
                return;
@@ -381,7 +387,7 @@ public class PopulateElementDropParticipant extends AbstractDiagramParticipant i
                 }
             }
         } 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));
         }
     }