import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
+import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
-import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.dnd.DnDConstants;
import java.awt.dnd.DropTarget;
import java.awt.dnd.DropTargetAdapter;
import java.awt.geom.AffineTransform;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
-import java.io.IOException;
+import java.io.Reader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Random;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
import org.simantics.Simantics;
import org.simantics.db.ChangeSet;
import org.simantics.db.ChangeSetIdentifier;
import org.simantics.db.common.request.ReadRequest;
import org.simantics.db.common.utils.NameUtils;
import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.request.Read;
import org.simantics.db.service.ManagementSupport;
+import org.simantics.db.service.SerialisationSupport;
import org.simantics.debug.graphical.layout.ExtensionLayoutAlgorithm;
import org.simantics.debug.graphical.layout.LayoutGraph;
import org.simantics.debug.graphical.model.Edge;
import org.simantics.ui.dnd.LocalObjectTransferable;
import org.simantics.ui.selection.AnyResource;
import org.simantics.ui.selection.WorkbenchSelectionElement;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.NumericNode;
import gnu.trove.list.array.TDoubleArrayList;
import gnu.trove.map.hash.THashMap;
import gnu.trove.map.hash.TObjectIntHashMap;
public class DebuggerCanvas extends JPanel {
-
+ private static final Logger LOGGER = LoggerFactory.getLogger(DebuggerCanvas.class);
+
private static final long serialVersionUID = -718678297301786379L;
ArrayList<Node> nodes = new ArrayList<Node>();
public void drop(DropTargetDropEvent dtde) {
try {
Transferable transferable = dtde.getTransferable();
-
if( transferable.isDataFlavorSupported(
LocalObjectTransferable.FLAVOR ) ) {
dtde.acceptDrop( DnDConstants.ACTION_MOVE );
- transferable.getTransferData(LocalObjectTransferable.FLAVOR );
+ transferable.getTransferData(LocalObjectTransferable.FLAVOR);
Object obj = LocalObjectTransfer.getTransfer().getObject();
- double x = canvasPosX+dtde.getLocation().getX()/canvasZoom;
- double y = canvasPosY+dtde.getLocation().getY()/canvasZoom;
- handleDrop(x, y, obj);
+ handleDrop(dtde, obj);
dtde.getDropTargetContext().dropComplete( true );
}
else {
+ DataFlavor textFlavor = DataFlavor.selectBestTextFlavor(transferable.getTransferDataFlavors());
+ if(textFlavor != null) {
+ try(Reader reader = textFlavor.getReaderForText(transferable)) {
+ ObjectMapper mapper = new ObjectMapper();
+ JsonNode node = mapper.readTree(reader);
+ Object resourceId = node.get("resourceId");
+ if(resourceId instanceof NumericNode) {
+ dtde.acceptDrop( DnDConstants.ACTION_MOVE );
+
+ transferable.getTransferData(LocalObjectTransferable.FLAVOR);
+ Object obj = new StructuredSelection(Simantics.getSession().syncRequest(new Read<Resource>() {
+ public Resource perform(ReadGraph graph) throws DatabaseException {
+ SerialisationSupport ss = graph.getService(SerialisationSupport.class);
+ return ss.getResource(((NumericNode)resourceId).longValue());
+ }
+ }));
+ handleDrop(dtde, obj);
+
+ dtde.getDropTargetContext().dropComplete( true );
+ return;
+ }
+ }
+ }
dtde.rejectDrop();
}
- } catch( IOException exception ) {
- exception.printStackTrace();
- dtde.rejectDrop();
- } catch( UnsupportedFlavorException ufException ) {
- ufException.printStackTrace();
+ } catch( Exception exception ) {
+ LOGGER.warn("Drop failed.", exception);
dtde.rejectDrop();
- }
+ }
}
});
}
+ private void handleDrop(DropTargetDropEvent dtde, Object obj) {
+ double x = canvasPosX+dtde.getLocation().getX()/canvasZoom;
+ double y = canvasPosY+dtde.getLocation().getY()/canvasZoom;
+ handleDrop(x, y, obj);
+ }
+
public void keyPressed(KeyEvent e) {
switch(e.getKeyCode()) {
case KeyEvent.VK_1:
if(resource != null)
return resource;
}
+ if(obj instanceof Resource)
+ return (Resource)obj;
return null;
}