Java 类com.intellij.openapi.util.ActionCallback 实例源码

项目:intellij-ce-playground    文件:CardLayoutPanel.java   
private void selectLater(final ActionCallback callback, final K key) {
  ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
    @Override
    public void run() {
      if (!myDisposed) {
        final UI ui = prepare(key);
        ApplicationManager.getApplication().invokeLater(new Runnable() {
          @Override
          public void run() {
            if (!myDisposed) {
              select(callback, key, ui);
            }
            else callback.setRejected();
          }
        }, ModalityState.any());
      }
      else callback.setRejected();
    }
  });
}
项目:intellij-ce-playground    文件:AlphaNumericTypeCommand.java   
protected ActionCallback type(final PlaybackContext context, final String text) {
  final ActionCallback result = new ActionCallback();

  IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(new Runnable() {
    @Override
    public void run() {
      TypingTarget typingTarget = findTarget(context);
      if (typingTarget != null) {
        typingTarget.type(text).doWhenDone(result.createSetDoneRunnable()).doWhenRejected(new Runnable() {
          public void run() {
            typeByRobot(context.getRobot(), text).notify(result);
          }
        });
      } else {
        typeByRobot(context.getRobot(), text).notify(result);
      }
    }
  });

  return result;
}
项目:intellij-ce-playground    文件:TodoTreeBuilder.java   
@Override
protected final AbstractTreeUpdater createUpdater() {
  return new AbstractTreeUpdater(this) {
    @Override
    protected ActionCallback beforeUpdate(final TreeUpdatePass pass) {
      if (!myDirtyFileSet.isEmpty()) { // suppress redundant cache validations
        final AsyncResult callback = new AsyncResult();
        DumbService.getInstance(myProject).runWhenSmart(new Runnable() {
          @Override
          public void run() {
            try {
              validateCache();
              getTodoTreeStructure().validateCache();
            }
            finally {
              callback.setDone();
            }
          }
        });
        return callback;
      }

      return ActionCallback.DONE;
    }
  };
}
项目:intellij-ce-playground    文件:RegistryValueCommand.java   
@Override
protected ActionCallback _execute(PlaybackContext context) {
  final String[] keyValue = getText().substring(PREFIX.length()).trim().split("=");
  if (keyValue.length != 2) {
    context.error("Expected expresstion: " + PREFIX + " key=value", getLine());
    return ActionCallback.REJECTED;
  }

  final String key = keyValue[0];
  final String value = keyValue[1];

  context.storeRegistryValue(key);

  Registry.get(key).setValue(value);

  return ActionCallback.DONE;
}
项目:intellij-ce-playground    文件:TogglePresentationModeAction.java   
private static ActionCallback tweakFrameFullScreen(Project project, boolean inPresentation) {
  Window window = IdeFrameImpl.getActiveFrame();
  if (window instanceof IdeFrameImpl) {
    IdeFrameImpl frame = (IdeFrameImpl)window;
    PropertiesComponent propertiesComponent = PropertiesComponent.getInstance(project);
    if (inPresentation) {
      propertiesComponent.setValue("full.screen.before.presentation.mode", String.valueOf(frame.isInFullScreen()));
      return frame.toggleFullScreen(true);
    }
    else {
      if (frame.isInFullScreen()) {
        final String value = propertiesComponent.getValue("full.screen.before.presentation.mode");
        return frame.toggleFullScreen("true".equalsIgnoreCase(value));
      }
    }
  }
  return ActionCallback.DONE;
}
项目:intellij-ce-playground    文件:AbstractAttachSourceProvider.java   
@Override
public ActionCallback perform(List<LibraryOrderEntry> orderEntriesContainingFile) {
  ApplicationManager.getApplication().assertIsDispatchThread();

  ActionCallback callback = new ActionCallback();
  callback.setDone();

  if (!mySrcFile.isValid()) return callback;

  if (myLibrary != getLibraryFromOrderEntriesList(orderEntriesContainingFile)) return callback;

  AccessToken accessToken = WriteAction.start();
  try {
    addSourceFile(mySrcFile, myLibrary);
  }
  finally {
    accessToken.finish();
  }

  return callback;
}
项目:intellij-ce-playground    文件:RequestFocusInEditorComponentCmd.java   
public RequestFocusInEditorComponentCmd(@NotNull final EditorsSplitters splitters, IdeFocusManager
                                        focusManager, final Runnable finishCallBack, boolean forced){
  super(finishCallBack);

  boolean shouldLogFocuses = Registry.is("ide.log.focuses");
  if (shouldLogFocuses) {
    LOG.info(new Exception());
  }
  myComponent = null;
  final EditorWindow window = splitters.getCurrentWindow();
  if (window != null) {
    final EditorWithProviderComposite editor = window.getSelectedEditor();
    if (editor != null) {
      myComponent = editor.getPreferredFocusedComponent();
    }
  }

  myForced = forced;
  myFocusManager = focusManager;

  myDoneCallback = new ActionCallback();

  myTimestamp = myFocusManager.getTimestamp(true);
}
项目:intellij-ce-playground    文件:SettingsTreeView.java   
@Override
protected ActionCallback refilterNow(Object preferredSelection, boolean adjustSelection) {
  final List<Object> toRestore = new ArrayList<Object>();
  if (myFilter.myContext.isHoldingFilter() && !myWasHoldingFilter && myToExpandOnResetFilter == null) {
    myToExpandOnResetFilter = myBuilder.getUi().getExpandedElements();
  }
  else if (!myFilter.myContext.isHoldingFilter() && myWasHoldingFilter && myToExpandOnResetFilter != null) {
    toRestore.addAll(myToExpandOnResetFilter);
    myToExpandOnResetFilter = null;
  }

  myWasHoldingFilter = myFilter.myContext.isHoldingFilter();

  ActionCallback result = super.refilterNow(preferredSelection, adjustSelection);
  myRefilteringNow = true;
  return result.doWhenDone(new Runnable() {
    public void run() {
      myRefilteringNow = false;
      if (!myFilter.myContext.isHoldingFilter() && getSelectedElements().isEmpty()) {
        restoreExpandedState(toRestore);
      }
    }
  });
}
项目:intellij-ce-playground    文件:UpdaterTreeState.java   
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);
    }
  }
}
项目:educational-plugin    文件:EduStepicUpdater.java   
private static ActionCallback updateCourseList() {
  ActionCallback callback = new ActionCallback();
  ApplicationManager.getApplication().executeOnPooledThread(() -> {
    final List<Course> courses = EduStepicConnector.getCourses(null);
    StudySettings.getInstance().setLastTimeChecked(System.currentTimeMillis());

    if (!courses.isEmpty()) {
      List<Course> updated = new ArrayList<>();
      for (Course course : courses) {
        if (course instanceof RemoteCourse && ((RemoteCourse)course).getUpdateDate().
                                              after(new Date(StudySettings.getInstance().getLastTimeChecked()))) {
          updated.add(course);
        }
      }
      if (updated.isEmpty()) return;
      final String message;
      final String title;
      if (updated.size() == 1) {
        message = updated.get(0).getName();
        title = "New course available";
      }
      else {
        title = "New courses available";
        message = StringUtil.join(updated, Course::getName, ", ");
      }
      final Notification notification = new Notification("New.course", title, message, NotificationType.INFORMATION);
      notification.notify(null);
    }
  });
  return callback;
}
项目:intellij-ce-playground    文件:AbstractTreeStructure.java   
@NotNull
public static ActionCallback asyncCommitDocuments(@NotNull Project project) {
  if (project.isDisposed()) return ActionCallback.DONE;
  PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
  if (!documentManager.hasUncommitedDocuments()) {
    return ActionCallback.DONE;
  }
  final ActionCallback callback = new ActionCallback();
  documentManager.performWhenAllCommitted(callback.createSetDoneRunnable());
  return callback;
}
项目:intellij-ce-playground    文件:GridImpl.java   
public ActionCallback restoreLastUiState() {
  final ActionCallback result = new ActionCallback(myPlaceInGrid2Cell.values().size());
  for (final GridCellImpl cell : myPlaceInGrid2Cell.values()) {
    cell.restoreLastUiState().notifyWhenDone(result);
  }

  return result;
}
项目:intellij-ce-playground    文件:FavoritesViewTreeBuilder.java   
@Override
@NotNull
public ActionCallback updateFromRootCB() {
  getStructure().rootsChanged();
  if (isDisposed()) return ActionCallback.DONE;
  getUpdater().cancelAllRequests();
  return super.updateFromRootCB();
}
项目:intellij-ce-playground    文件:FocusTrackback.java   
private ActionCallback _restoreFocus() {
  final List<FocusTrackback> stack = getCleanStack();

  if (!stack.contains(this)) return ActionCallback.REJECTED;

  Component toFocus = queryToFocus(stack, this, true);

  final ActionCallback result = new ActionCallback();
  if (toFocus != null) {
    final Component ownerBySwing = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
    if (ownerBySwing != null) {
      final Window ownerBySwingWindow = SwingUtilities.getWindowAncestor(ownerBySwing);
      if (ownerBySwingWindow != null && ownerBySwingWindow == SwingUtilities.getWindowAncestor(toFocus)) {
        if (!UIUtil.isMeaninglessFocusOwner(ownerBySwing)) {
          toFocus = ownerBySwing;
        }
      }
    }

    if (myParentWindow != null) {
      final Window to = UIUtil.getWindow(toFocus);
      if (to != null && UIUtil.findUltimateParent(to) == UIUtil.findUltimateParent(myParentWindow)) {  // IDEADEV-34537
        requestFocus(toFocus);
        result.setDone();
      }
    } else {
      requestFocus(toFocus);
      result.setDone();
    }
  }

  if (!result.isDone()) {
    result.setRejected();
  }

  stack.remove(this);
  dispose();

  return result;
}
项目:intellij-ce-playground    文件:ModuleStructureConfigurable.java   
public ActionCallback selectOrderEntry(@NotNull final Module module, @Nullable final OrderEntry orderEntry) {
  for (final ModuleStructureExtension extension : ModuleStructureExtension.EP_NAME.getExtensions()) {
    final ActionCallback callback = extension.selectOrderEntry(module, orderEntry);
    if (callback != null) {
      return callback;
    }
  }

  Place p = new Place();
  p.putPath(ProjectStructureConfigurable.CATEGORY, this);
  Runnable r = null;

  final MasterDetailsComponent.MyNode node = findModuleNode(module);
  if (node != null) {
    p.putPath(TREE_OBJECT, module);
    p.putPath(ModuleEditor.SELECTED_EDITOR_NAME, ClasspathEditor.NAME);
    r = new Runnable() {
      @Override
      public void run() {
        if (orderEntry != null) {
          ModuleEditor moduleEditor = ((ModuleConfigurable)node.getConfigurable()).getModuleEditor();
          ModuleConfigurationEditor editor = moduleEditor.getEditor(ClasspathEditor.NAME);
          if (editor instanceof ClasspathEditor) {
            ((ClasspathEditor)editor).selectOrderEntry(orderEntry);
          }
        }
      }
    };
  }
  final ActionCallback result = ProjectStructureConfigurable.getInstance(myProject).navigateTo(p, true);
  return r != null ? result.doWhenDone(r) : result;
}
项目:intellij-ce-playground    文件:OptionsEditorContext.java   
ActionCallback fireModifiedAdded(@NotNull final Configurable configurable, @Nullable OptionsEditorColleague requestor) {
  if (myModified.contains(configurable)) return ActionCallback.REJECTED;

  myModified.add(configurable);

  return notify(new ColleagueAction() {
    public ActionCallback process(final OptionsEditorColleague colleague) {
      return colleague.onModifiedAdded(configurable);
    }
  }, requestor);

}
项目:intellij-ce-playground    文件:PackageFileWorker.java   
public static ActionCallback startPackagingFiles(final Project project, final List<VirtualFile> files,
                                                 final Artifact[] artifacts, final boolean packIntoArchives) {
  final ActionCallback callback = new ActionCallback();
  ProgressManager.getInstance().run(new Task.Backgroundable(project, "Packaging Files") {
    @Override
    public void run(@NotNull ProgressIndicator indicator) {
      try {
        for (final VirtualFile file : files) {
          indicator.checkCanceled();
          new ReadAction() {
            @Override
            protected void run(@NotNull final Result result) {
              try {
                packageFile(file, project, artifacts, packIntoArchives);
              }
              catch (IOException e) {
                String message = CompilerBundle.message("message.tect.package.file.io.error", e.toString());
                Notifications.Bus.notify(new Notification("Package File", "Cannot package file", message, NotificationType.ERROR));
              }
            }
          }.execute();
          callback.setDone();
        }
      }
      finally {
        if (!callback.isDone()) {
          callback.setRejected();
        }
      }
    }
  });
  return callback;
}
项目:intellij-ce-playground    文件:OptionsEditor.java   
public ActionCallback select(Configurable configurable) {
  if (myFilter.getFilterText().isEmpty()) {
    return select(configurable, "");
  }
  else {
    return myFilter.update(true, true);
  }
}
项目:intellij-ce-playground    文件:MasterDetailsComponent.java   
public ActionCallback selectNodeInTree(final DefaultMutableTreeNode nodeToSelect, boolean center, final boolean requestFocus) {
  if (requestFocus) {
    myTree.requestFocus();
  }
  if (nodeToSelect != null) {
    return TreeUtil.selectInTree(nodeToSelect, requestFocus, myTree, center);
  }
  else {
    return TreeUtil.selectFirstNode(myTree);
  }
}
项目:intellij-ce-playground    文件:WindowSystemPlaybackCall.java   
public static ActionCallback getUiReady(final PlaybackContext context) {
  final ActionCallback result = new ActionCallback();
  context.flushAwtAndRunInEdt(new Runnable() {
    @Override
    public void run() {
      UiActivityMonitor.getInstance().getBusy().getReady(context).notify(result);
    }
  });
  return result;
}
项目:intellij-ce-playground    文件:ElementFilter.java   
public ActionCallback fireUpdate(@Nullable final T preferredSelection, final boolean adjustSelection, final boolean now) {
  final ActionCallback result = new ActionCallback(myListeners.size());
  for (final Listener<T> myListener : myListeners) {
    myListener.update(preferredSelection, adjustSelection, now).doWhenProcessed(result.createSetDoneRunnable());
  }

  return result;
}
项目:intellij-ce-playground    文件:FilteringTreeBuilder.java   
public FilteringTreeBuilder(Tree tree,
                            ElementFilter filter,
                            AbstractTreeStructure structure,
                            @Nullable Comparator<NodeDescriptor> comparator) {
  super(tree,
        (DefaultTreeModel)tree.getModel(),
        structure instanceof FilteringTreeStructure ? structure
                                                    : new FilteringTreeStructure(filter, structure),
        comparator);

  myTree = tree;
  initRootNode();

  if (filter instanceof ElementFilter.Active) {
    ((ElementFilter.Active)filter).addListener(new ElementFilter.Listener() {
      @Override
      public ActionCallback update(final Object preferredSelection, final boolean adjustSelection, final boolean now) {
        return refilter(preferredSelection, adjustSelection, now);
      }
    }, this);
  }

  myTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
    @Override
    public void valueChanged(TreeSelectionEvent e) {
      TreePath newPath = e.getNewLeadSelectionPath();
      if (newPath != null) {
        Object element = getElementFor(newPath.getLastPathComponent());
        if (element != null) {
          myLastSuccessfulSelect = element;
        }
      }
    }
  });
}
项目:intellij-ce-playground    文件:LaterInvocator.java   
public RunnableInfo(@NotNull Runnable runnable,
                    @NotNull ModalityState modalityState,
                    @NotNull Condition<?> expired,
                    @NotNull ActionCallback callback) {
  this.runnable = runnable;
  this.modalityState = modalityState;
  this.expired = expired;
  this.callback = callback;
}
项目:intellij-ce-playground    文件:OptionsEditorContext.java   
ActionCallback notify(ColleagueAction action, OptionsEditorColleague requestor) {
  final ActionCallback.Chunk chunk = new ActionCallback.Chunk();
  for (Iterator<OptionsEditorColleague> iterator = myColleagues.iterator(); iterator.hasNext();) {
    OptionsEditorColleague each = iterator.next();
    if (each != requestor) {
      chunk.add(action.process(each));
    }
  }

  return chunk.getWhenProcessed();
}
项目:intellij-ce-playground    文件:TreeUtil.java   
@NotNull
public static ActionCallback moveDown(@NotNull final JTree tree) {
  final int size = tree.getRowCount();
  int row = tree.getLeadSelectionRow();
  if (row < size - 1) {
    row++;
    return showAndSelect(tree, row, row + 2, row, getSelectedRow(tree), false, true, true);
  } else {
    return ActionCallback.DONE;
  }
}
项目:intellij-ce-playground    文件:PopStage.java   
@Override
protected ActionCallback _execute(PlaybackContext context) {
  StageInfo stage = context.popStage();
  if (stage != null) {
    context.test("Test finished OK: " + stage.getName(), getLine());
    context.addPassed(stage);
  }
  return ActionCallback.DONE;
}
项目:intellij-ce-playground    文件:TreeUtil.java   
@NotNull
public static ActionCallback movePageUp(@NotNull final JTree tree) {
  final int visible = getVisibleRowCount(tree);
  if (visible <= 0){
    return moveHome(tree);
  }
  final int decrement = visible - 1;
  final int row = Math.max(getSelectedRow(tree) - decrement, 0);
  final int top = getFirstVisibleRow(tree) - decrement;
  final int bottom = top + visible - 1;
  return showAndSelect(tree, top, bottom, row, getSelectedRow(tree));
}
项目:intellij-ce-playground    文件:IdeFrameDecorator.java   
@Override
public ActionCallback toggleFullScreen(boolean state) {
  if (myFrame != null) {
    myRequestedState = state;
    X11UiUtil.toggleFullScreenMode(myFrame);
  }
  return ActionCallback.DONE;
}
项目:intellij-ce-playground    文件:ScopeViewPane.java   
@NotNull
@Override
public ActionCallback updateFromRoot(boolean restoreExpandedPaths) {
  saveExpandedPaths();
  myViewPanel.selectScope(NamedScopesHolder.getScope(myProject, getSubId()));
  restoreExpandedPaths();
  return ActionCallback.DONE;
}
项目:intellij-ce-playground    文件:OptionsEditor.java   
@Override
public void dispose() {
  assertIsDispatchThread();

  if (myDisposed) {
    return;
  }

  myDisposed = true;

  myProperties.setValue(MAIN_SPLITTER_PROPORTION, String.valueOf(myMainSplitter.getProportion()));
  myProperties.setValue(DETAILS_SPLITTER_PROPORTION, String.valueOf(myContentWrapper.myLastSplitterProportion));

  Toolkit.getDefaultToolkit().removeAWTEventListener(this);


  final Set<Configurable> configurables = new HashSet<Configurable>();
  configurables.addAll(myConfigurable2Content.keySet());
  configurables.addAll(myConfigurable2LoadCallback.keySet());
  for (final Configurable each : configurables) {
    ActionCallback loadCb = myConfigurable2LoadCallback.get(each);
    if (loadCb != null) {
      loadCb.doWhenProcessed(new Runnable() {
        @Override
        public void run() {
          assertIsDispatchThread();
          each.disposeUIResources();
        }
      });
    } else {
      each.disposeUIResources();
    }
  }

  Disposer.clearOwnFields(this);
}
项目:intellij-ce-playground    文件:TreeUtil.java   
@NotNull
public static ActionCallback selectInTree(@Nullable DefaultMutableTreeNode node, boolean requestFocus, @NotNull JTree tree, boolean center) {
  if (node == null) return ActionCallback.DONE;

  final TreePath treePath = new TreePath(node.getPath());
  tree.expandPath(treePath);
  if (requestFocus) {
    tree.requestFocus();
  }
  return selectPath(tree, treePath, center);
}
项目:intellij-ce-playground    文件:TreeUtil.java   
@NotNull
public static ActionCallback selectInTree(Project project, @Nullable DefaultMutableTreeNode node, boolean requestFocus, @NotNull JTree tree, boolean center) {
  if (node == null) return ActionCallback.DONE;

  final TreePath treePath = new TreePath(node.getPath());
  tree.expandPath(treePath);
  if (requestFocus) {
    ActionCallback result = new ActionCallback(2);
    IdeFocusManager.getInstance(project).requestFocus(tree, true).notifyWhenDone(result);
    selectPath(tree, treePath, center).notifyWhenDone(result);
    return result;
  }
  return selectPath(tree, treePath, center);
}
项目:intellij-ce-playground    文件:ConfigurableEditor.java   
final ActionCallback select(final Configurable configurable) {
  assert !myDisposed : "Already disposed";
  ActionCallback callback = myCardPanel.select(configurable, false);
  callback.doWhenDone(new Runnable() {
    @Override
    public void run() {
      myConfigurable = configurable;
      updateCurrent(configurable, false);
    }
  });
  return callback;
}
项目:intellij-ce-playground    文件:ToolWindowImpl.java   
@NotNull
public ActionCallback setActivation(@NotNull ActionCallback activation) {
  if (!myActivation.isProcessed() && !myActivation.equals(activation)) {
    myActivation.setRejected();
  }

  myActivation = activation;
  return myActivation;
}
项目:intellij-ce-playground    文件:ProjectView.java   
@NotNull
public abstract ActionCallback changeViewCB(@NotNull String viewId, String subId);
项目:intellij-ce-playground    文件:SdkEditor.java   
@Override
public ActionCallback navigateTo(@Nullable final Place place, final boolean requestFocus) {
  if (place == null) return ActionCallback.DONE;
  myTabbedPane.setSelectedTitle((String)place.getPath(SDK_TAB));
  return ActionCallback.DONE;
}
项目:intellij-ce-playground    文件:IdeFocusManagerImpl.java   
@Override
@NotNull
public ActionCallback requestFocus(@NotNull final FocusCommand command, final boolean forced) {
  return getGlobalInstance().requestFocus(command, forced);
}
项目:intellij-ce-playground    文件:AbstractAttachSourceProvider.java   
@Override
public ActionCallback perform(List<LibraryOrderEntry> orderEntriesContainingFile) {
  final ActionCallback callback = new ActionCallback();
  Task task = new Task.Backgroundable(myProject, "Downloading Sources", true) {
    @Override
    public void run(@NotNull final ProgressIndicator indicator) {
      final byte[] bytes;
      try {
        LOG.info("Downloading sources JAR: " + myUrl);
        indicator.checkCanceled();
        bytes = HttpRequests.request(myUrl).readBytes(indicator);
      }
      catch (IOException e) {
        LOG.warn(e);
        ApplicationManager.getApplication().invokeLater(new Runnable() {
          @Override
          public void run() {
            new Notification(myMessageGroupId,
                             "Downloading failed",
                             "Failed to download sources: " + myUrl,
                             NotificationType.ERROR)
              .notify(getProject());

            callback.setDone();
          }
        });
        return;
      }

      ApplicationManager.getApplication().invokeLater(new Runnable() {
        @Override
        public void run() {
          AccessToken accessToken = WriteAction.start();
          try {
            storeFile(bytes);
          }
          finally {
            accessToken.finish();
            callback.setDone();
          }
        }
      });
    }

    @Override
    public void onCancel() {
      callback.setRejected();
    }
  };

  task.queue();

  return callback;
}
项目:intellij-ce-playground    文件:ToolWindowHeadlessManagerImpl.java   
@NotNull
@Override
public ActionCallback requestFocus(@Nullable final Content content, final boolean forced) {
  return ActionCallback.DONE;
}
项目:intellij-ce-playground    文件:SettingsTreeView.java   
@Override
public ActionCallback onSelected(@Nullable Configurable configurable, Configurable oldConfigurable) {
  return select(configurable);
}