use of com.intellij.openapi.progress.Task in project intellij-community by JetBrains.
the class LogConsoleBase method getSearchComponent.
@Override
public JComponent getSearchComponent() {
myLogFilterCombo.setModel(new DefaultComboBoxModel(myFilters.toArray(new LogFilter[myFilters.size()])));
resetLogFilter();
myLogFilterCombo.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
final LogFilter filter = (LogFilter) myLogFilterCombo.getSelectedItem();
final Task.Backgroundable task = new Task.Backgroundable(myProject, APPLYING_FILTER_TITLE) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
myModel.selectFilter(filter);
}
};
ProgressManager.getInstance().run(task);
}
});
myTextFilterWrapper.removeAll();
myTextFilterWrapper.add(getTextFilterComponent());
return mySearchComponent;
}
use of com.intellij.openapi.progress.Task in project intellij-community by JetBrains.
the class DependenciesHandlerBase method analyze.
public void analyze() {
final List<DependenciesBuilder> builders = new ArrayList<>();
final Task task;
if (canStartInBackground()) {
task = new Task.Backgroundable(myProject, getProgressTitle(), true, new PerformAnalysisInBackgroundOption(myProject)) {
@Override
public void run(@NotNull final ProgressIndicator indicator) {
perform(builders);
}
@Override
public void onSuccess() {
DependenciesHandlerBase.this.onSuccess(builders);
}
};
} else {
task = new Task.Modal(myProject, getProgressTitle(), true) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
perform(builders);
}
@Override
public void onSuccess() {
DependenciesHandlerBase.this.onSuccess(builders);
}
};
}
ProgressManager.getInstance().run(task);
}
use of com.intellij.openapi.progress.Task in project intellij-community by JetBrains.
the class FindJarFix method findJarsForFqn.
private void findJarsForFqn(final String fqn, final Editor editor) {
final Map<String, String> libs = new HashMap<>();
final Runnable runnable = () -> {
try {
final DOMParser parser = new DOMParser();
parser.parse(CLASS_ROOT_URL + fqn.replace('.', '/') + CLASS_PAGE_EXT);
final Document doc = parser.getDocument();
if (doc != null) {
final NodeList links = doc.getElementsByTagName(LINK_TAG_NAME);
for (int i = 0; i < links.getLength(); i++) {
final Node link = links.item(i);
final String libName = link.getTextContent();
final NamedNodeMap attributes = link.getAttributes();
if (attributes != null) {
final Node href = attributes.getNamedItem(LINK_ATTR_NAME);
if (href != null) {
final String pathToJar = href.getTextContent();
if (pathToJar != null && (pathToJar.startsWith("/jar/") || pathToJar.startsWith("/class/../"))) {
libs.put(libName, SERVICE_URL + pathToJar);
}
}
}
}
}
} catch (IOException ignore) {
//
} catch (Exception e) {
//
LOG.warn(e);
}
};
final Task.Modal task = new Task.Modal(editor.getProject(), "Looking for libraries", true) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
indicator.setIndeterminate(true);
runUncanceledRunnableWithProgress(runnable, indicator);
}
@Override
public void onSuccess() {
super.onSuccess();
if (libs.isEmpty()) {
HintManager.getInstance().showInformationHint(editor, "No libraries found for '" + fqn + "'");
} else {
final ArrayList<String> variants = new ArrayList<>(libs.keySet());
Collections.sort(variants, (o1, o2) -> o1.compareTo(o2));
final JBList libNames = new JBList(variants);
libNames.installCellRenderer(o -> new JLabel(o.toString(), PlatformIcons.JAR_ICON, SwingConstants.LEFT));
if (libs.size() == 1) {
final String jarName = libs.keySet().iterator().next();
final String url = libs.get(jarName);
initiateDownload(url, jarName);
} else {
JBPopupFactory.getInstance().createListPopupBuilder(libNames).setTitle("Select a JAR file").setItemChoosenCallback(() -> {
final Object value = libNames.getSelectedValue();
if (value instanceof String) {
final String jarName = (String) value;
final String url = libs.get(jarName);
if (url != null) {
initiateDownload(url, jarName);
}
}
}).createPopup().showInBestPositionFor(editor);
}
}
}
};
ProgressManager.getInstance().run(task);
}
use of com.intellij.openapi.progress.Task in project intellij-plugins by JetBrains.
the class RubyMotionUtilExt method createMotionRunConfiguration.
public static void createMotionRunConfiguration(final Module module) {
final Project project = module.getProject();
final String title = RBundle.message("rails.facet.builder.run.configuration.server.creating");
final Task task = new Task.Backgroundable(project, title, true) {
public void run(@NotNull ProgressIndicator indicator) {
indicator.setText(RBundle.message("progress.backgnd.indicator.title.please.wait", getTitle()));
final RunManager runManager = RunManager.getInstance(project);
ApplicationManager.getApplication().runReadAction(() -> {
// requires read action
// Rake : "simulator"
final String taskName = RubyMotionUtil.getInstance().getMainRakeTask(module);
final RunnerAndConfigurationSettings simulator = createAndAddRakeConfiguration(taskName, module, runManager);
// Rake : "spec"
createAndAddRakeConfiguration(RakeUtilBase.TASKS_SPEC_FULLCMD, module, runManager);
// make development config active
runManager.setSelectedConfiguration(simulator);
});
}
};
final Runnable taskRunner = () -> ProgressManager.getInstance().run(task);
if (!project.isInitialized()) {
StartupManager.getInstance(project).registerPostStartupActivity(taskRunner);
} else {
taskRunner.run();
}
}
use of com.intellij.openapi.progress.Task in project android by JetBrains.
the class SmwOldApiDirectInstall method startSdkInstallUsingNonSwtOldApi.
private void startSdkInstallUsingNonSwtOldApi() {
// Get the SDK instance.
final AndroidSdkHandler sdkHandler = AndroidSdks.getInstance().tryToChooseSdkHandler();
if (sdkHandler.getLocation() == null) {
myErrorLabel.setText("Error: can't get SDK instance.");
myErrorLabel.setIcon(AllIcons.General.BalloonError);
return;
}
File androidSdkPath = IdeSdks.getInstance().getAndroidSdkPath();
if (androidSdkPath != null && androidSdkPath.exists() && !androidSdkPath.canWrite()) {
myErrorLabel.setText(String.format("SDK folder is read-only: '%1$s'", androidSdkPath.getPath()));
myErrorLabel.setIcon(AllIcons.General.BalloonError);
return;
}
myLabelSdkPath.setText(sdkHandler.getLocation().getPath());
final CustomLogger logger = new CustomLogger();
final com.android.repository.api.ProgressIndicator repoProgress = new StudioLoggerProgressIndicator(getClass());
RepoManager.RepoLoadedCallback onComplete = packages -> UIUtil.invokeLaterIfNeeded(() -> {
List<String> requestedChanges = myState.get(INSTALL_REQUESTS_KEY);
if (requestedChanges == null) {
assert false : "Shouldn't be in installer with no requests";
myInstallFinished = true;
invokeUpdate(null);
return;
}
Map<String, RemotePackage> remotes = packages.getRemotePackages();
List<RemotePackage> requestedPackages = Lists.newArrayList();
boolean notFound = false;
for (String path : requestedChanges) {
RemotePackage remotePackage = remotes.get(path);
if (remotePackage != null) {
requestedPackages.add(remotePackage);
} else {
notFound = true;
}
}
if (requestedPackages.isEmpty()) {
myInstallFinished = true;
invokeUpdate(null);
} else {
requestedPackages = InstallerUtil.computeRequiredPackages(requestedPackages, packages, repoProgress);
if (requestedPackages == null) {
notFound = true;
} else {
InstallTask task = new InstallTask(sdkHandler, requestedPackages, logger);
BackgroundableProcessIndicator indicator = new BackgroundableProcessIndicator(task);
logger.setIndicator(indicator);
ProgressManager.getInstance().runProcessWithProgressAsynchronously(task, indicator);
}
}
if (notFound) {
myErrorLabel.setText("Problem: Some required packages could not be installed. Check internet connection.");
myErrorLabel.setIcon(AllIcons.General.BalloonError);
}
});
StudioProgressRunner runner = new StudioProgressRunner(false, false, "Updating SDK", false, null);
sdkHandler.getSdkManager(repoProgress).load(RepoManager.DEFAULT_EXPIRATION_PERIOD_MS, null, ImmutableList.of(onComplete), null, runner, new StudioDownloader(), StudioSettingsController.getInstance(), false);
}
Aggregations