Java Code Examples for com.intellij.openapi.util.AsyncResult#resolved()

The following examples show how to use com.intellij.openapi.util.AsyncResult#resolved() . 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: ProjectUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
private static AsyncResult<Integer> confirmOpenNewProjectAsync(UIAccess uiAccess, boolean isNewProject) {
  final GeneralSettings settings = GeneralSettings.getInstance();
  int confirmOpenNewProject = settings.getConfirmOpenNewProject();
  if (confirmOpenNewProject == GeneralSettings.OPEN_PROJECT_ASK) {
    Alert<Integer> alert = Alert.create();
    alert.asQuestion();
    alert.remember(ProjectNewWindowDoNotAskOption.INSTANCE);
    alert.title(isNewProject ? IdeBundle.message("title.new.project") : IdeBundle.message("title.open.project"));
    alert.text(IdeBundle.message("prompt.open.project.in.new.frame"));

    alert.button(IdeBundle.message("button.existingframe"), () -> GeneralSettings.OPEN_PROJECT_SAME_WINDOW);
    alert.asDefaultButton();

    alert.button(IdeBundle.message("button.newframe"), () -> GeneralSettings.OPEN_PROJECT_NEW_WINDOW);

    alert.button(Alert.CANCEL, Alert.CANCEL);
    alert.asExitButton();

    AsyncResult<Integer> result = AsyncResult.undefined();
    uiAccess.give(() -> alert.showAsync().notify(result));
    return result;
  }

  return AsyncResult.resolved(confirmOpenNewProject);
}
 
Example 2
Source File: AbstractProjectViewPSIPane.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
public AsyncResult<Void> selectCB(Object element, VirtualFile file, boolean requestFocus) {
  if (file != null) {
    AbstractTreeBuilder builder = getTreeBuilder();
    if (builder instanceof BaseProjectTreeBuilder) {
      beforeSelect().doWhenDone(() -> UIUtil.invokeLaterIfNeeded(() -> {
        if (!builder.isDisposed()) {
          ((BaseProjectTreeBuilder)builder).selectAsync(element, file, requestFocus);
        }
      }));
    }
    else if (myAsyncSupport != null) {
      myAsyncSupport.select(myTree, element, file);
    }
  }
  return AsyncResult.resolved();
}
 
Example 3
Source File: BaseStructureConfigurableNoDaemon.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public AsyncResult<Void> navigateTo(@Nullable final Place place, final boolean requestFocus) {
  if (place == null) return AsyncResult.resolved();

  final Object object = place.getPath(TREE_OBJECT);
  final String byName = (String)place.getPath(TREE_NAME);

  if (object == null && byName == null) return AsyncResult.resolved();

  final MyNode node = object == null ? null : findNodeByObject(myRoot, object);
  final MyNode nodeByName = byName == null ? null : findNodeByName(myRoot, byName);

  if (node == null && nodeByName == null) return AsyncResult.resolved();

  final NamedConfigurable config;
  if (node != null) {
    config = node.getConfigurable();
  }
  else {
    config = nodeByName.getConfigurable();
  }

  AsyncResult<Void> result = AsyncResult.<Void>undefined().doWhenDone(() -> myAutoScrollEnabled = true);

  myAutoScrollEnabled = false;
  myAutoScrollHandler.cancelAllRequests();
  final MyNode nodeToSelect = node != null ? node : nodeByName;
  selectNodeInTree(nodeToSelect, requestFocus).doWhenDone(new Runnable() {
    @Override
    public void run() {
      setSelectedNode(nodeToSelect);
      Place.goFurther(config, place, requestFocus).notifyWhenDone(result);
    }
  });

  return result;
}
 
Example 4
Source File: TabbedModuleEditor.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public AsyncResult<Void> navigateTo(@Nullable final Place place, final boolean requestFocus) {
  if (place != null) {
    selectEditor((String)place.getPath(SELECTED_EDITOR_NAME));
  }
  return AsyncResult.resolved();
}
 
Example 5
Source File: NewOrImportModuleUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@RequiredUIAccess
public static <T extends ModuleImportContext> AsyncResult<Project> importProject(@Nonnull T context, @Nonnull ModuleImportProvider<T> importProvider) {
  final ProjectManagerEx projectManager = ProjectManagerEx.getInstanceEx();
  final String projectFilePath = context.getPath();
  String projectName = context.getName();

  try {
    File projectDir = new File(projectFilePath);
    FileUtil.ensureExists(projectDir);
    File projectConfigDir = new File(projectDir, Project.DIRECTORY_STORE_FOLDER);
    FileUtil.ensureExists(projectConfigDir);

    final Project newProject = projectManager.createProject(projectName, projectFilePath);

    if (newProject == null) return AsyncResult.rejected();

    newProject.save();

    ModifiableModuleModel modifiableModel = ModuleManager.getInstance(newProject).getModifiableModel();

    importProvider.process(context, newProject, modifiableModel, module -> {
    });

    WriteAction.runAndWait(modifiableModel::commit);

    newProject.save();

    context.dispose();

    return AsyncResult.resolved(newProject);
  }
  catch (Exception e) {
    context.dispose();

    return AsyncResult.<Project>undefined().rejectWithThrowable(e);
  }
}
 
Example 6
Source File: DesktopAlertImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
@Nonnull
@Override
public AsyncResult<V> showAsync(@Nullable Window component) {
  if (myButtons.isEmpty()) {
    throw new UnsupportedOperationException("Buttons empty");
  }

  if (myExitValue == null) {
    throw new UnsupportedOperationException("Exit value is not set. Use #asExitButton() or #exitValue()");
  }

  V value = myRemember != null ? myRemember.getValue() : null;
  if (value != null) {
    return AsyncResult.resolved(value);
  }

  AsyncResult<V> result = AsyncResult.undefined();
  DialogImpl dialog = new DialogImpl(false);
  AsyncResult<Void> async = dialog.showAsync();
  async.doWhenProcessed(() -> {
    V selectValue = dialog.mySelectedValue;
    if (myRemember != null) {
      if (dialog.myRememberBox.getValue()) {
        myRemember.setValue(selectValue);
      }
    }

    result.setDone(selectValue);
  });
  return result;
}
 
Example 7
Source File: AbstractTreeStructure.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public AsyncResult<Object> revalidateElement(@Nonnull Object element) {
  return AsyncResult.resolved(element);
}
 
Example 8
Source File: MockProject.java    From consulo with Apache License 2.0 4 votes vote down vote up
@RequiredWriteAction
@Nonnull
@Override
public AsyncResult<Void> saveAsync(UIAccess uiAccess) {
  return AsyncResult.resolved();
}
 
Example 9
Source File: UnknownBeforeRunTaskProvider.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public AsyncResult<Void> executeTaskAsync(UIAccess uiAccess, DataContext context, RunConfiguration configuration, ExecutionEnvironment env, UnknownTask task) {
  return AsyncResult.resolved();
}
 
Example 10
Source File: SdkEditor.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public AsyncResult<Void> navigateTo(@Nullable final Place place, final boolean requestFocus) {
  if (place == null) return AsyncResult.resolved();
  myTabbedPane.setSelectedTitle((String)place.getPath(SDK_TAB));
  return AsyncResult.resolved();
}
 
Example 11
Source File: UnifiedContentManager.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public AsyncResult<Void> requestFocus(@Nullable Content content, boolean forced) {
  return AsyncResult.resolved();  //TODO [VISTALL]
}
 
Example 12
Source File: CallChain.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public static Link<Void, Void> first(@Nullable UIAccess uiAccess) {
  CallChain callChain = new CallChain(uiAccess);
  return new Link<>(callChain, (f) -> AsyncResult.resolved());
}
 
Example 13
Source File: LightProject.java    From consulo with Apache License 2.0 4 votes vote down vote up
@RequiredWriteAction
@Nonnull
@Override
public AsyncResult<Void> saveAsync(UIAccess uiAccess) {
  return AsyncResult.resolved();
}
 
Example 14
Source File: CompileStepBeforeRun.java    From consulo with Apache License 2.0 4 votes vote down vote up
static AsyncResult<Void> doMake(UIAccess uiAccess, final Project myProject, final RunConfiguration configuration, final boolean ignoreErrors) {
  if (!(configuration instanceof RunProfileWithCompileBeforeLaunchOption)) {
    return AsyncResult.rejected();
  }

  if (configuration instanceof RunConfigurationBase && ((RunConfigurationBase)configuration).excludeCompileBeforeLaunchOption()) {
    return AsyncResult.resolved();
  }

  final RunProfileWithCompileBeforeLaunchOption runConfiguration = (RunProfileWithCompileBeforeLaunchOption)configuration;
  AsyncResult<Void> result = AsyncResult.undefined();
  try {
    final CompileStatusNotification callback = (aborted, errors, warnings, compileContext) -> {
      if ((errors == 0 || ignoreErrors) && !aborted) {
        result.setDone();
      }
      else {
        result.setRejected();
      }
    };

    TransactionGuard.submitTransaction(myProject, () -> {
      CompileScope scope;
      final CompilerManager compilerManager = CompilerManager.getInstance(myProject);
      if (Comparing.equal(Boolean.TRUE.toString(), System.getProperty(MAKE_PROJECT_ON_RUN_KEY))) {
        // user explicitly requested whole-project make
        scope = compilerManager.createProjectCompileScope();
      }
      else {
        final Module[] modules = runConfiguration.getModules();
        if (modules.length > 0) {
          for (Module module : modules) {
            if (module == null) {
              LOG.error("RunConfiguration should not return null modules. Configuration=" + runConfiguration.getName() + "; class=" + runConfiguration.getClass().getName());
            }
          }
          scope = compilerManager.createModulesCompileScope(modules, true);
        }
        else {
          scope = compilerManager.createProjectCompileScope();
        }
      }

      if (!myProject.isDisposed()) {
        compilerManager.make(scope, callback);
      }
      else {
        result.setRejected();
      }
    });
  }
  catch (Exception e) {
    result.rejectWithThrowable(e);
  }

  return result;
}
 
Example 15
Source File: BaseSdkEditor.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public AsyncResult<Void> navigateTo(@Nullable final Place place, final boolean requestFocus) {
  return AsyncResult.resolved();
}
 
Example 16
Source File: WebProjectIdeFocusManagerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public AsyncResult<Void> requestDefaultFocus(boolean forced) {
  return AsyncResult.resolved(null);
}
 
Example 17
Source File: ToolWindowHeadlessManagerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public AsyncResult<Void> setSelectedContentCB(@Nonnull Content content) {
  setSelectedContent(content);
  return AsyncResult.resolved();
}
 
Example 18
Source File: ToolWindowHeadlessManagerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public AsyncResult<Void> selectPreviousContent() {
  return AsyncResult.resolved();
}
 
Example 19
Source File: ToolWindowHeadlessManagerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public AsyncResult<Void> selectNextContent() {
  return AsyncResult.resolved();
}
 
Example 20
Source File: DesktopIdeFocusManagerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public AsyncResult<Void> requestDefaultFocus(boolean forced) {
  //todo need to implement
  return AsyncResult.resolved();
}