/**
  * get the list of good command by taking in account if this is a change order or a drop into
  *
  * @param target the target object of the drop
  * @return the list of command
  */
 public List<Command> getDrop(Object target) {
   CommonDropAdapter dropAdapter = getCommonDropAdapter();
   List<Command> commandList = new ArrayList<Command>();
   switch (dropAdapter.getCurrentOperation()) {
     case DND.DROP_MOVE:
       if (dropAdapter.getCurrentLocation() == ViewerDropAdapter.LOCATION_BEFORE) {
         if (target instanceof ModelElementItem) {
           commandList = getOrderChangeCommand(target, true);
         }
       } else if (dropAdapter.getCurrentLocation() == ViewerDropAdapter.LOCATION_AFTER) {
         if (target instanceof ModelElementItem) {
           commandList = getOrderChangeCommand(target, false);
         }
       } else if (dropAdapter.getCurrentLocation() == ViewerDropAdapter.LOCATION_ON) {
         if (target instanceof ModelElementItem) {
           commandList = getDropIntoCommand(target, null);
         }
         if (target instanceof LinkItem) {
           commandList =
               getDropIntoCommand(
                   ((LinkItem) target).getParent(), ((LinkItem) target).getReference());
         }
       } else if (dropAdapter.getCurrentLocation() == ViewerDropAdapter.LOCATION_NONE) {
       }
       break;
   }
   return commandList;
 }
Ejemplo n.º 2
0
  @Override
  public IStatus handleDrop(
      final CommonDropAdapter dropAdapter,
      final DropTargetEvent dropTargetEvent,
      final Object target) {

    // get the source data
    final TransferData td = dropAdapter.getCurrentTransfer();
    final ISelection sel = (ISelection) LocalSelectionTransfer.getTransfer().nativeToJava(td);
    final TreeSelection s = (TreeSelection) sel;
    try {
      GlobalParameters.setSelection(s);
    } catch (final WranglerException e1) {
      e1.printStackTrace();
    }

    // get the target data
    String moduleName;
    IFile file;
    if (target instanceof IFile) {
      file = (IFile) target;
    } else {
      file = (IFile) ((IErlElement) target).getResource();
    }
    moduleName = file.getName();

    moduleName = moduleName.substring(0, moduleName.lastIndexOf("."));

    final MoveFunctionRefactoring refactoring = new MoveFunctionRefactoring();
    refactoring.setUserInput(moduleName);
    final RefactoringWizard wizard =
        new DefaultWranglerRefactoringWizard(
            refactoring,
            RefactoringWizard.DIALOG_BASED_USER_INTERFACE,
            new ArrayList<WranglerPage>());

    final Shell shell = PlatformUI.getWorkbench().getDisplay().getActiveShell();

    final RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation(wizard);

    try {
      op.run(shell, refactoring.getName());
    } catch (final Exception e) {
      e.printStackTrace();
    }

    System.out.print("hand");

    return Status.OK_STATUS;
  }