Java Code Examples for com.intellij.openapi.util.ActionCallback#setDone()

The following examples show how to use com.intellij.openapi.util.ActionCallback#setDone() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SourceJarGenerator.java    From intellij-pants-plugin with Apache License 2.0 6 votes vote down vote up
@Override
public ActionCallback perform(Collection<Library> libraries) {
  ActionCallback callback = new ActionCallback();
  Task task = new Task.Backgroundable(psiFile.getProject(), "Generating source jar from Pants") {
    @Override
    public void run(@NotNull ProgressIndicator indicator) {
      try {
        indicator.setText("Generating source jar");
        File sourceJar = generateSourceJar(indicator, target, sourceJarPath, psiFile);
        indicator.setText("Attaching source jar");
        attach(sourceJar, libraries);
        callback.setDone();
      }
      catch (Exception e) {
        String msg = "Error while generating sources ";
        LOG.warn(msg, e);
        callback.reject(msg + e.getMessage());
      }
    }
  };
  task.queue();
  return callback;
}
 
Example 2
Source File: UpdaterTreeState.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void processNextHang(Object element, final ActionCallback callback) {
  if (element == null || myUi.getSelectedElements().contains(element)) {
    callback.setDone();
  }
  else {
    final Object nextElement = myUi.getTreeStructure().getParentElement(element);
    if (nextElement == null) {
      callback.setDone();
    }
    else {
      myUi.select(nextElement, new TreeRunnable("UpdaterTreeState.processNextHang") {
        @Override
        public void perform() {
          processNextHang(nextElement, callback);
        }
      }, true);
    }
  }
}
 
Example 3
Source File: FavoritesViewSelectInTarget.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static ActionCallback select(@Nonnull Project project, Object toSelect, VirtualFile virtualFile, boolean requestFocus) {
  final ActionCallback result = new ActionCallback();

  ToolWindowManager windowManager = ToolWindowManager.getInstance(project);
  final ToolWindow favoritesToolWindow = windowManager.getToolWindow(ToolWindowId.FAVORITES_VIEW);

  if (favoritesToolWindow != null) {
    final Runnable runnable = () -> {
      final FavoritesTreeViewPanel panel = UIUtil.findComponentOfType(favoritesToolWindow.getComponent(), FavoritesTreeViewPanel.class);
      if (panel != null) {
        panel.selectElement(toSelect, virtualFile, requestFocus);
        result.setDone();
      }
    };

    if (requestFocus) {
      favoritesToolWindow.activate(runnable, false);
    }
    else {
      favoritesToolWindow.show(runnable);
    }
  }

  return result;
}
 
Example 4
Source File: UpdaterTreeState.java    From consulo with Apache License 2.0 5 votes vote down vote up
private ActionCallback processHangByParent(Set<Object> elements) {
  if (elements.isEmpty()) return ActionCallback.DONE;

  ActionCallback result = new ActionCallback(elements.size());
  for (Object hangElement : elements) {
    if (!myAdjustmentCause2Adjustment.containsKey(hangElement)) {
      processHangByParent(hangElement).notify(result);
    }
    else {
      result.setDone();
    }
  }
  return result;
}
 
Example 5
Source File: KeyCodeTypeCommand.java    From consulo with Apache License 2.0 5 votes vote down vote up
private ActionCallback typeCodes(final PlaybackContext context, final Robot robot, final String codes) {
  final ActionCallback result = new ActionCallback();

  Runnable runnable = new Runnable() {
    public void run() {
      String[] pairs = codes.split(CODE_DELIMITER);
      for (String eachPair : pairs) {
        try {
          String[] splits = eachPair.split(MODIFIER_DELIMITER);
          Integer code = Integer.valueOf(splits[0]);
          Integer modifier = Integer.valueOf(splits[1]);
          type(robot, code.intValue(), modifier.intValue());
        }
        catch (NumberFormatException e) {
          dumpError(context, "Invalid code: " + eachPair);
          result.setRejected();
          return;
        }
      }

      result.setDone();
    }
  };


  if (SwingUtilities.isEventDispatchThread()) {
    ApplicationManager.getApplication().executeOnPooledThread(runnable);
  } else {
    runnable.run();
  }

  return result;
}
 
Example 6
Source File: GridCellImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
public ActionCallback restoreLastUiState() {
  final ActionCallback result = new ActionCallback();

  restoreProportions();

  Content[] contents = getContents();
  int window = 0;
  for (Content each : contents) {
    final View view = myContainer.getStateFor(each);
    if (view.isMinimizedInGrid()) {
      minimize(each);
    }
    window = view.getWindow();
  }
  final Tab tab = myContainer.getTab();
  final boolean detached = (tab != null && tab.isDetached(myPlaceInGrid)) || window != myContext.getWindow();
  if (detached && contents.length > 0) {
    if (tab != null) {
      tab.setDetached(myPlaceInGrid, false);
    }
    myContext.detachTo(window, this).notifyWhenDone(result);
  }
  else {
    result.setDone();
  }

  return result;
}
 
Example 7
Source File: AbstractProjectViewPSIPane.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public final ActionCallback updateFromRoot(boolean restoreExpandedPaths) {
  Runnable afterUpdate;
  final ActionCallback cb = new ActionCallback();
  AbstractTreeBuilder builder = getTreeBuilder();
  if (restoreExpandedPaths && builder != null) {
    final ArrayList<Object> pathsToExpand = new ArrayList<>();
    final ArrayList<Object> selectionPaths = new ArrayList<>();
    TreeBuilderUtil.storePaths(builder, (DefaultMutableTreeNode)myTree.getModel().getRoot(), pathsToExpand, selectionPaths, true);
    afterUpdate = () -> {
      if (myTree != null && !builder.isDisposed()) {
        myTree.setSelectionPaths(new TreePath[0]);
        TreeBuilderUtil.restorePaths(builder, pathsToExpand, selectionPaths, true);
      }
      cb.setDone();
    };
  }
  else {
    afterUpdate = cb.createSetDoneRunnable();
  }
  if (builder != null) {
    builder.addSubtreeToUpdate(builder.getRootNode(), afterUpdate);
  }
  else if (myAsyncSupport != null) {
    myAsyncSupport.updateAll(afterUpdate);
  }
  return cb;
}
 
Example 8
Source File: FilteringTreeBuilder.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
protected Promise<?> refilterNow(Object preferredSelection, boolean adjustSelection) {
  final ActionCallback selectionDone = new ActionCallback();

  getFilteredStructure().refilter();
  getUi().updateSubtree(getRootNode(), false);
  final Runnable selectionRunnable = () -> {
    revalidateTree();

    Object toSelect = preferredSelection != null ? preferredSelection : myLastSuccessfulSelect;

    if (adjustSelection && toSelect != null) {
      final FilteringTreeStructure.FilteringNode nodeToSelect = getFilteredStructure().getVisibleNodeFor(toSelect);

      if (nodeToSelect != null) {
        select(nodeToSelect, () -> {
          if (getSelectedElements().contains(nodeToSelect)) {
            myLastSuccessfulSelect = getOriginalNode(nodeToSelect);
          }
          selectionDone.setDone();
        });
      }
      else {
        TreeUtil.ensureSelection(myTree);
        selectionDone.setDone();
      }
    }
    else {
      selectionDone.setDone();
    }
  };
  if (!ApplicationManager.getApplication().isUnitTestMode()) {
    queueUpdate().doWhenProcessed(selectionRunnable);
  }
  else {
    selectionRunnable.run();
  }

  AsyncPromise<?> result = new AsyncPromise<>();
  selectionDone.doWhenDone(new Runnable() {
    @Override
    public void run() {
      if (!ApplicationManager.getApplication().isUnitTestMode()) {
        scrollSelectionToVisible(new Runnable() {
          @Override
          public void run() {
            getReady(this).doWhenDone(() -> result.setResult(null)).doWhenRejected(s -> result.setError(s));
          }
        }, false);
      }
      else {
        result.setResult(null);
      }
    }
  }).doWhenRejected(() -> result.cancel(true));
  return result;
}
 
Example 9
Source File: UpdaterTreeState.java    From consulo with Apache License 2.0 4 votes vote down vote up
private ActionCallback processAdjusted(final Map<Object, Condition> adjusted, final Set<Object> originallySelected) {
  final ActionCallback result = new ActionCallback();

  final Set<Object> allSelected = myUi.getSelectedElements();

  Set<Object> toSelect = new HashSet<>();
  for (Map.Entry<Object, Condition> entry : adjusted.entrySet()) {
    Condition condition = entry.getValue();
    Object key = entry.getKey();
    if (condition.value(key)) continue;

    for (final Object eachSelected : allSelected) {
      if (isParentOrSame(key, eachSelected)) continue;
      toSelect.add(key);
    }
    if (allSelected.isEmpty()) {
      toSelect.add(key);
    }
  }

  final Object[] newSelection = ArrayUtil.toObjectArray(toSelect);

  if (newSelection.length > 0) {
    myUi._select(newSelection, new TreeRunnable("UpdaterTreeState.processAjusted") {
      @Override
      public void perform() {
        final Set<Object> hangByParent = new HashSet<>();
        processUnsuccessfulSelections(newSelection, o -> {
          if (myUi.isInStructure(o) && !adjusted.get(o).value(o)) {
            hangByParent.add(o);
          }
          else {
            addAdjustedSelection(o, adjusted.get(o), null);
          }
          return null;
        }, originallySelected);

        processHangByParent(hangByParent).notify(result);
      }
    }, false, true);
  }
  else {
    result.setDone();
  }

  return result;
}
 
Example 10
Source File: AlphaNumericTypeCommand.java    From consulo with Apache License 2.0 4 votes vote down vote up
private ActionCallback typeByRobot(final Robot robot, final String text) {
  final ActionCallback result = new ActionCallback();

  Runnable typeRunnable = new Runnable() {
    public void run() {
      for (int i = 0; i < text.length(); i++) {
        final char each = text.charAt(i);
        if ('\\' == each && i + 1 < text.length()) {
          final char next = text.charAt(i + 1);
          boolean processed = true;
          switch (next) {
            case 'n':
              type(robot, KeyEvent.VK_ENTER, 0);
              break;
            case 't':
              type(robot, KeyEvent.VK_TAB, 0);
              break;
            case 'r':
              type(robot, KeyEvent.VK_ENTER, 0);
              break;
            default:
              processed = false;
          }

          if (processed) {
            i++;
            continue;
          }
        }
        type(robot, get(each));
      }

      result.setDone();
    }
  };

  if (SwingUtilities.isEventDispatchThread()) {
    ApplicationManager.getApplication().executeOnPooledThread(typeRunnable);
  } else {
    typeRunnable.run();
  }

  return result;
}