예제 #1
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;
  }
  @Override
  public Object execute(final ExecutionEvent event) throws ExecutionException {
    final String actionId = event.getCommand().getId();
    PlatformUI.getWorkbench()
        .getActiveWorkbenchWindow()
        .getActivePage()
        .getActiveEditor()
        .setFocus();
    try {
      GlobalParameters.setSelection(
          PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getSelection());
    } catch (final WranglerException e1) {
      MessageDialog.openError(
          PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
          "Error",
          e1.getMessage());
      return null;
    }
    try {
      final File tmpFile = File.createTempFile("wrangler_graph_", ".dot");
      tmpFile.deleteOnExit();

      final IErlSelection wranglerSelection = GlobalParameters.getWranglerSelection();

      if (actionId.equals("org.erlide.wrangler.refactoring.codeinspection.cyclicdependencies")) {
        final Boolean answer =
            MessageDialog.openQuestion(
                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                "Labels",
                "Label edges with function names called?");
        runInspection(
            "Cyclic module dependency",
            CYCLYC_VIEW_ID,
            "There is no cyclic dependent modules in the project!",
            tmpFile,
            "cyclic_dependent_modules",
            "ssx",
            tmpFile.getAbsolutePath(),
            wranglerSelection.getSearchPath(),
            new OtpErlangBoolean(answer));
      } else if (actionId.equals(
          "org.erlide.wrangler.refactoring.codeinspection.generatefunctioncallgraph")) {
        runInspection(
            "Function callgraph",
            FUNCTION_CALL_GRAPH_VIEW_ID,
            "There is no dependent functions in the module!",
            tmpFile,
            "gen_function_callgraph",
            "sss",
            tmpFile.getAbsolutePath(),
            wranglerSelection.getFilePath(),
            wranglerSelection.getSearchPath());

      } else if (actionId.equals(
          "org.erlide.wrangler.refactoring.codeinspection.generatemodulegraph")) {
        final Boolean answer =
            MessageDialog.openQuestion(
                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                "Labels",
                "Label edges with function names called?");
        runInspection(
            "Module dependency graph",
            MODULE_GRAPH_VIEW_ID,
            "There is no dependent modules in the project!",
            tmpFile,
            "gen_module_graph",
            "ssx",
            tmpFile.getAbsolutePath(),
            wranglerSelection.getSearchPath(),
            new OtpErlangBoolean(answer));

      } else if (actionId.equals(
          "org.erlide.wrangler.refactoring.codeinspection.improperdependecies")) {
        runInspection(
            "Improper module dependencies",
            IMPROPER_DEPENDECIES_VIEW_ID,
            "There is no improper module dependecies!",
            tmpFile,
            "improper_inter_module_calls",
            "ss",
            tmpFile.getAbsolutePath(),
            wranglerSelection.getSearchPath());
      }

    } catch (final Exception e) {
      ErlLogger.error(e);
    }
    return event;
  }