Search in sources :

Example 41 with ProgressIndicator

use of com.intellij.openapi.progress.ProgressIndicator in project azure-tools-for-java by Microsoft.

the class AzureNewDockerHostStep method updateDockerHostVMSizeComboBox.

private void updateDockerHostVMSizeComboBox(boolean prefferedSizesOnly) {
    DefaultComboBoxModel<String> dockerHostVMSizeComboModel = new DefaultComboBoxModel<>();
    if (prefferedSizesOnly) {
        for (KnownDockerVirtualMachineSizes knownDockerVirtualMachineSize : KnownDockerVirtualMachineSizes.values()) {
            dockerHostVMSizeComboModel.addElement(knownDockerVirtualMachineSize.name());
        }
        if (dockerHostVMSizeComboModel.getSize() > 0) {
            dockerHostVMSizeComboModel.setSelectedItem(dockerHostVMSizeComboModel.getElementAt(0));
        }
    } else {
        dockerHostVMSizeComboModel.addElement("<Loading...>");
        ProgressManager.getInstance().run(new Task.Backgroundable(model.getProject(), "Loading VM Sizes...", false) {

            @Override
            public void run(@NotNull ProgressIndicator progressIndicator) {
                progressIndicator.setIndeterminate(true);
                Azure azureClient = ((AzureDockerSubscription) dockerSubscriptionComboBox.getSelectedItem()).azureClient;
                PagedList<VirtualMachineSize> sizes = null;
                try {
                    sizes = azureClient.virtualMachines().sizes().listByRegion(preferredLocation);
                    Collections.sort(sizes, new Comparator<VirtualMachineSize>() {

                        @Override
                        public int compare(VirtualMachineSize size1, VirtualMachineSize size2) {
                            if (size1.name().contains("Basic") && size2.name().contains("Basic")) {
                                return size1.name().compareTo(size2.name());
                            } else if (size1.name().contains("Basic")) {
                                return -1;
                            } else if (size2.name().contains("Basic")) {
                                return 1;
                            }
                            int coreCompare = Integer.valueOf(size1.numberOfCores()).compareTo(size2.numberOfCores());
                            if (coreCompare == 0) {
                                return Integer.valueOf(size1.memoryInMB()).compareTo(size2.memoryInMB());
                            } else {
                                return coreCompare;
                            }
                        }
                    });
                } catch (Exception notHandled) {
                }
                PagedList<VirtualMachineSize> sortedSizes = sizes;
                ApplicationManager.getApplication().invokeAndWait(new Runnable() {

                    @Override
                    public void run() {
                        dockerHostVMSizeComboModel.removeAllElements();
                        if (sortedSizes != null) {
                            for (VirtualMachineSize vmSize : sortedSizes) {
                                dockerHostVMSizeComboModel.addElement(vmSize.name());
                            }
                        }
                        dockerHostVMSizeComboBox.repaint();
                    }
                }, ModalityState.any());
            }
        });
    }
    dockerHostVMSizeComboBox.setModel(dockerHostVMSizeComboModel);
    dockerHostVMSizeComboBox.setSelectedItem(newHost.hostVM.vmSize);
    if (!newHost.hostVM.vmSize.equals((String) dockerHostVMSizeComboBox.getSelectedItem())) {
        dockerHostVMSizeComboModel.addElement(newHost.hostVM.vmSize);
        dockerHostVMSizeComboBox.setSelectedItem(newHost.hostVM.vmSize);
    }
    updateDockerSelectStorageComboBox((AzureDockerSubscription) dockerSubscriptionComboBox.getSelectedItem());
}
Also used : Task(com.intellij.openapi.progress.Task) Azure(com.microsoft.azure.management.Azure) PagedList(com.microsoft.azure.PagedList) VirtualMachineSize(com.microsoft.azure.management.compute.VirtualMachineSize) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator)

Example 42 with ProgressIndicator

use of com.intellij.openapi.progress.ProgressIndicator in project intellij-elixir by KronicDeth.

the class MixProjectRootStep method fetchDependencies.

private static void fetchDependencies(@NotNull final VirtualFile projectRoot, @NotNull final String mixPath) {
    final Project project = ProjectImportBuilder.getCurrentProject();
    String sdkPath = project != null ? ElixirSdkType.getSdkPath(project) : null;
    final String elixirPath = sdkPath != null ? JpsElixirSdkType.getScriptInterpreterExecutable(sdkPath).getAbsolutePath() : JpsElixirSdkType.getExecutableFileName(JpsElixirSdkType.SCRIPT_INTERPRETER);
    ProgressManager.getInstance().run(new Task.Modal(project, "Fetching dependencies", true) {

        @Override
        public void run(@NotNull final ProgressIndicator indicator) {
            indicator.setIndeterminate(true);
            GeneralCommandLine commandLine = new GeneralCommandLine();
            commandLine.withWorkDirectory(projectRoot.getCanonicalPath());
            commandLine.setExePath(elixirPath);
            commandLine.addParameter(mixPath);
            commandLine.addParameter("deps.get");
            try {
                OSProcessHandler handler = new OSProcessHandler(commandLine.createProcess(), commandLine.getPreparedCommandLine(Platform.current()));
                handler.addProcessListener(new ProcessAdapter() {

                    @Override
                    public void onTextAvailable(ProcessEvent event, Key outputType) {
                        String text = event.getText();
                        indicator.setText2(text);
                    }
                });
                ProcessTerminatedListener.attach(handler);
                handler.startNotify();
                handler.waitFor();
                indicator.setText2("Refreshing");
            } catch (ExecutionException e) {
                LOG.warn(e);
            }
        }
    });
}
Also used : Project(com.intellij.openapi.project.Project) Task(com.intellij.openapi.progress.Task) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) ExecutionException(com.intellij.execution.ExecutionException) Key(com.intellij.openapi.util.Key)

Example 43 with ProgressIndicator

use of com.intellij.openapi.progress.ProgressIndicator in project intellij-community by JetBrains.

the class WaitForProgressToShow method runOrInvokeAndWaitAboveProgress.

public static void runOrInvokeAndWaitAboveProgress(final Runnable command, @Nullable final ModalityState modalityState) {
    final Application application = ApplicationManager.getApplication();
    if (application.isDispatchThread()) {
        command.run();
    } else {
        final ProgressIndicator pi = ProgressManager.getInstance().getProgressIndicator();
        if (pi != null) {
            execute(pi);
            application.invokeAndWait(command);
        } else {
            final ModalityState notNullModalityState = modalityState == null ? ModalityState.NON_MODAL : modalityState;
            application.invokeAndWait(command, notNullModalityState);
        }
    }
}
Also used : ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ModalityState(com.intellij.openapi.application.ModalityState) Application(com.intellij.openapi.application.Application)

Example 44 with ProgressIndicator

use of com.intellij.openapi.progress.ProgressIndicator in project intellij-community by JetBrains.

the class WaitForProgressToShow method runOrInvokeLaterAboveProgress.

public static void runOrInvokeLaterAboveProgress(final Runnable command, @Nullable final ModalityState modalityState, @NotNull final Project project) {
    final Application application = ApplicationManager.getApplication();
    if (application.isDispatchThread()) {
        command.run();
    } else {
        final ProgressIndicator pi = ProgressManager.getInstance().getProgressIndicator();
        if (pi != null) {
            execute(pi);
            application.invokeLater(command, pi.getModalityState(), o -> (!project.isOpen()) || project.isDisposed());
        } else {
            final ModalityState notNullModalityState = modalityState == null ? ModalityState.NON_MODAL : modalityState;
            application.invokeLater(command, notNullModalityState, project.getDisposed());
        }
    }
}
Also used : ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ModalityState(com.intellij.openapi.application.ModalityState) Application(com.intellij.openapi.application.Application)

Example 45 with ProgressIndicator

use of com.intellij.openapi.progress.ProgressIndicator in project intellij-community by JetBrains.

the class SearchCommand method startSearching.

public void startSearching() {
    final UsageViewContext context = createUsageViewContext();
    final UsageViewPresentation presentation = new UsageViewPresentation();
    presentation.setOpenInNewTab(FindSettings.getInstance().isShowResultsInSeparateView());
    context.configure(presentation);
    final FindUsagesProcessPresentation processPresentation = new FindUsagesProcessPresentation(presentation);
    processPresentation.setShowNotFoundMessage(true);
    processPresentation.setShowPanelIfOnlyOneUsage(true);
    processPresentation.setProgressIndicatorFactory(new Factory<ProgressIndicator>() {

        @Override
        public ProgressIndicator create() {
            FindProgressIndicator indicator = new FindProgressIndicator(mySearchContext.getProject(), presentation.getScopeText());
            indicator.addStateDelegate(new AbstractProgressIndicatorExBase() {

                @Override
                public void cancel() {
                    super.cancel();
                    stopAsyncSearch();
                }
            });
            return indicator;
        }
    });
    PsiDocumentManager.getInstance(mySearchContext.getProject()).commitAllDocuments();
    final ConfigurableUsageTarget target = context.getTarget();
    ((FindManagerImpl) FindManager.getInstance(mySearchContext.getProject())).getFindUsagesManager().addToHistory(target);
    UsageViewManager.getInstance(mySearchContext.getProject()).searchAndShowUsages(new UsageTarget[] { target }, () -> new UsageSearcher() {

        @Override
        public void generate(@NotNull final Processor<Usage> processor) {
            findUsages(processor);
        }
    }, processPresentation, presentation, new UsageViewManager.UsageViewStateListener() {

        @Override
        public void usageViewCreated(@NotNull UsageView usageView) {
            context.setUsageView(usageView);
            context.configureActions();
        }

        @Override
        public void findingUsagesFinished(final UsageView usageView) {
        }
    });
}
Also used : AbstractProgressIndicatorExBase(com.intellij.openapi.progress.util.AbstractProgressIndicatorExBase) FindProgressIndicator(com.intellij.find.FindProgressIndicator) FindProgressIndicator(com.intellij.find.FindProgressIndicator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator)

Aggregations

ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)400 Task (com.intellij.openapi.progress.Task)151 VirtualFile (com.intellij.openapi.vfs.VirtualFile)106 NotNull (org.jetbrains.annotations.NotNull)101 Project (com.intellij.openapi.project.Project)88 File (java.io.File)59 IOException (java.io.IOException)58 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)47 Nullable (org.jetbrains.annotations.Nullable)46 ProgressManager (com.intellij.openapi.progress.ProgressManager)39 List (java.util.List)36 EmptyProgressIndicator (com.intellij.openapi.progress.EmptyProgressIndicator)31 Ref (com.intellij.openapi.util.Ref)27 Module (com.intellij.openapi.module.Module)26 VcsException (com.intellij.openapi.vcs.VcsException)26 ArrayList (java.util.ArrayList)26 ApplicationManager (com.intellij.openapi.application.ApplicationManager)25 Logger (com.intellij.openapi.diagnostic.Logger)23 AzureString (com.microsoft.azure.toolkit.lib.common.bundle.AzureString)22 AzureTask (com.microsoft.azure.toolkit.lib.common.task.AzureTask)22