00001 package edu.ksu.cis.bandera.pdgslicer.dependency;
00002
00003 import java.awt.*;
00004 import java.awt.dnd.*;
00005 import java.awt.datatransfer.*;
00006 import javax.swing.*;
00007 import java.io.*;
00008 import java.util.*;
00009 import java.util.List;
00010 import edu.ksu.cis.bandera.annotation.*;
00011 import edu.ksu.cis.bandera.pdgslicer.datastructure.SlicePoint;
00012
00013
00014
00015
00016
00017 public class DroppableStatementsList extends DroppableList {
00018
00019
00020
00021 public DroppableStatementsList() {
00022 super();
00023 }
00024 public void dragEnter(DropTargetDragEvent dropTargetDragEvent) {
00025 Transferable tr = DraggableTree.currentDraggingTreeNode;
00026 if (tr == null) {
00027 dropTargetDragEvent.rejectDrag();
00028 return;
00029 }
00030 Object userObject = null;
00031 try {
00032 userObject = tr.getTransferData(TransferableTreeNode.DEFAULT_MUTABLE_TREENODE_FLAVOR);
00033 } catch (IOException io) {
00034 io.printStackTrace();
00035 dropTargetDragEvent.rejectDrag();
00036 } catch (UnsupportedFlavorException ufe) {
00037 ufe.printStackTrace();
00038 dropTargetDragEvent.rejectDrag();
00039 }
00040 if (userObject instanceof FieldDeclarationAnnotation)
00041 dropTargetDragEvent.rejectDrag();
00042 else
00043 dropTargetDragEvent.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);
00044 }
00045 public void drop(DropTargetDropEvent dropTargetDropEvent) {
00046 try {
00047 Transferable tr = DraggableTree.currentDraggingTreeNode;
00048 if (tr.isDataFlavorSupported(TransferableTreeNode.DEFAULT_MUTABLE_TREENODE_FLAVOR)) {
00049 dropTargetDropEvent.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
00050 Object userObject = tr.getTransferData(TransferableTreeNode.DEFAULT_MUTABLE_TREENODE_FLAVOR);
00051 SlicePoint[] sp = criterionViewer.calculateSliceStatements(userObject);
00052 boolean isStatementNode = true;
00053 for (int i = 0; i < sp.length; i++) {
00054 criterionViewer.addStatementToCriterion(sp[i], sp, (Annotation) userObject);
00055 }
00056 dropTargetDropEvent.getDropTargetContext().dropComplete(true);
00057 } else {
00058 System.err.println("Rejected");
00059 dropTargetDropEvent.rejectDrop();
00060 }
00061 } catch (IOException io) {
00062 io.printStackTrace();
00063 dropTargetDropEvent.rejectDrop();
00064 } catch (UnsupportedFlavorException ufe) {
00065 ufe.printStackTrace();
00066 dropTargetDropEvent.rejectDrop();
00067 }
00068 }
00069 }