use of com.intellij.openapi.progress.ProgressIndicator in project intellij-community by JetBrains.
the class CompileDriver method notifyCompilationCompleted.
/** @noinspection SSBasedInspection*/
private long notifyCompilationCompleted(final CompileContextImpl compileContext, final CompileStatusNotification callback, final ExitStatus _status) {
final long duration = System.currentTimeMillis() - compileContext.getStartCompilationStamp();
if (!myProject.isDisposed()) {
// refresh on output roots is required in order for the order enumerator to see all roots via VFS
final Module[] affectedModules = compileContext.getCompileScope().getAffectedModules();
if (_status != ExitStatus.UP_TO_DATE && _status != ExitStatus.CANCELLED) {
// have to refresh in case of errors too, because run configuration may be set to ignore errors
Collection<String> affectedRoots = ContainerUtil.newHashSet(CompilerPathsEx.getOutputPaths(affectedModules));
if (!affectedRoots.isEmpty()) {
ProgressIndicator indicator = compileContext.getProgressIndicator();
indicator.setText("Synchronizing output directories...");
CompilerUtil.refreshOutputRoots(affectedRoots);
indicator.setText("");
}
}
}
SwingUtilities.invokeLater(() -> {
int errorCount = 0;
int warningCount = 0;
try {
errorCount = compileContext.getMessageCount(CompilerMessageCategory.ERROR);
warningCount = compileContext.getMessageCount(CompilerMessageCategory.WARNING);
} finally {
if (callback != null) {
callback.finished(_status == ExitStatus.CANCELLED, errorCount, warningCount, compileContext);
}
}
if (!myProject.isDisposed()) {
final String statusMessage = createStatusMessage(_status, warningCount, errorCount, duration);
final MessageType messageType = errorCount > 0 ? MessageType.ERROR : warningCount > 0 ? MessageType.WARNING : MessageType.INFO;
if (duration > ONE_MINUTE_MS && CompilerWorkspaceConfiguration.getInstance(myProject).DISPLAY_NOTIFICATION_POPUP) {
ToolWindowManager.getInstance(myProject).notifyByBalloon(ToolWindowId.MESSAGES_WINDOW, messageType, statusMessage);
}
final String wrappedMessage = _status != ExitStatus.UP_TO_DATE ? "<a href='#'>" + statusMessage + "</a>" : statusMessage;
final Notification notification = CompilerManager.NOTIFICATION_GROUP.createNotification("", wrappedMessage, messageType.toNotificationType(), new MessagesActivationListener(compileContext)).setImportant(false);
compileContext.getBuildSession().registerCloseAction(notification::expire);
notification.notify(myProject);
if (_status != ExitStatus.UP_TO_DATE && compileContext.getMessageCount(null) > 0) {
final String msg = DateFormatUtil.formatDateTime(new Date()) + " - " + statusMessage;
compileContext.addMessage(CompilerMessageCategory.INFORMATION, msg, null, -1, -1);
}
}
});
return duration;
}
use of com.intellij.openapi.progress.ProgressIndicator in project intellij-community by JetBrains.
the class CompilerTask method addIndicatorDelegate.
private void addIndicatorDelegate() {
ProgressIndicator indicator = myIndicator;
if (!(indicator instanceof ProgressIndicatorEx)) {
return;
}
((ProgressIndicatorEx) indicator).addStateDelegate(new AbstractProgressIndicatorExBase() {
@Override
public void cancel() {
super.cancel();
selectFirstMessage();
stopAppIconProgress();
}
@Override
public void stop() {
super.stop();
if (!isCanceled()) {
selectFirstMessage();
}
stopAppIconProgress();
}
private void selectFirstMessage() {
if (!isHeadlessMode()) {
SwingUtilities.invokeLater(() -> {
if (myProject != null && myProject.isDisposed()) {
return;
}
synchronized (myMessageViewLock) {
if (myErrorTreeView != null) {
myErrorTreeView.selectFirstMessage();
}
}
});
}
}
private void stopAppIconProgress() {
UIUtil.invokeLaterIfNeeded(() -> {
if (myProject != null && myProject.isDisposed()) {
return;
}
final AppIcon appIcon = AppIcon.getInstance();
if (appIcon.hideProgress(myProject, APP_ICON_ID)) {
if (myErrorCount > 0) {
appIcon.setErrorBadge(myProject, String.valueOf(myErrorCount));
appIcon.requestAttention(myProject, true);
} else if (!myCompilationStartedAutomatically) {
appIcon.setOkBadge(myProject, true);
appIcon.requestAttention(myProject, false);
}
}
});
}
@Override
public void setText(final String text) {
super.setText(text);
updateProgressText();
}
@Override
public void setText2(final String text) {
super.setText2(text);
updateProgressText();
}
@Override
public void setFraction(final double fraction) {
super.setFraction(fraction);
updateProgressText();
GuiUtils.invokeLaterIfNeeded(() -> AppIcon.getInstance().setProgress(myProject, APP_ICON_ID, AppIconScheme.Progress.BUILD, fraction, true), ModalityState.any());
}
@Override
protected void onProgressChange() {
prepareMessageView();
}
});
}
use of com.intellij.openapi.progress.ProgressIndicator in project azure-tools-for-java by Microsoft.
the class IDEHelperImpl method getCancellableBackgroundTask.
@org.jetbrains.annotations.NotNull
private static Task.Backgroundable getCancellableBackgroundTask(final Project project, @NotNull final String name, @Nullable final String indicatorText, final CancellableTaskHandleImpl handle, @NotNull final CancellableTask cancellableTask) {
return new Task.Backgroundable(project, name, true) {
private final Semaphore lock = new Semaphore(0);
@Override
public void run(@org.jetbrains.annotations.NotNull ProgressIndicator indicator) {
indicator.setIndeterminate(true);
handle.setProgressIndicator(indicator);
if (indicatorText != null) {
indicator.setText(indicatorText);
}
ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
@Override
public void run() {
try {
cancellableTask.run(handle);
} catch (Throwable t) {
handle.setException(t);
} finally {
lock.release();
}
}
});
try {
while (!lock.tryAcquire(1, TimeUnit.SECONDS)) {
if (handle.isCancelled()) {
ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
@Override
public void run() {
cancellableTask.onCancel();
}
});
return;
}
}
ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
@Override
public void run() {
if (handle.getException() == null) {
cancellableTask.onSuccess();
} else {
cancellableTask.onError(handle.getException());
}
}
});
} catch (InterruptedException ignored) {
}
}
};
}
use of com.intellij.openapi.progress.ProgressIndicator in project azure-tools-for-java by Microsoft.
the class MachineSettingsStep method prepare.
@Override
public JComponent prepare(WizardNavigationState wizardNavigationState) {
rootPanel.revalidate();
boolean isLinux;
try {
AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
azure = azureManager.getAzure(((VMWizardModel) model).getSubscription().getSubscriptionId());
} catch (Exception ex) {
DefaultLoader.getUIHelper().logError("An error occurred when trying to authenticate\n\n" + ex.getMessage(), ex);
}
if (model.isKnownMachineImage()) {
isLinux = model.getKnownMachineImage() instanceof KnownLinuxVirtualMachineImage;
} else {
isLinux = model.getVirtualMachineImage().osDiskImage().operatingSystem().equals(OperatingSystemTypes.LINUX);
}
if (isLinux) {
certificateCheckBox.setEnabled(true);
passwordCheckBox.setEnabled(true);
certificateCheckBox.setSelected(false);
passwordCheckBox.setSelected(true);
} else {
certificateCheckBox.setSelected(false);
passwordCheckBox.setSelected(true);
certificateCheckBox.setEnabled(false);
passwordCheckBox.setEnabled(false);
}
validateEmptyFields();
if (vmSizeComboBox.getItemCount() == 0) {
vmSizeComboBox.setModel(new DefaultComboBoxModel(new String[] { "<Loading...>" }));
ProgressManager.getInstance().run(new Task.Backgroundable(project, "Loading VM sizes...", false) {
@Override
public void run(@NotNull ProgressIndicator progressIndicator) {
progressIndicator.setIndeterminate(true);
PagedList<com.microsoft.azure.management.compute.VirtualMachineSize> sizes = azure.virtualMachines().sizes().listByRegion(model.getRegion().name());
Collections.sort(sizes, new Comparator<VirtualMachineSize>() {
@Override
public int compare(VirtualMachineSize t0, VirtualMachineSize t1) {
if (t0.name().contains("Basic") && t1.name().contains("Basic")) {
return t0.name().compareTo(t1.name());
} else if (t0.name().contains("Basic")) {
return -1;
} else if (t1.name().contains("Basic")) {
return 1;
}
int coreCompare = Integer.valueOf(t0.numberOfCores()).compareTo(t1.numberOfCores());
if (coreCompare == 0) {
return Integer.valueOf(t0.memoryInMB()).compareTo(t1.memoryInMB());
} else {
return coreCompare;
}
}
});
ApplicationManager.getApplication().invokeAndWait(new Runnable() {
@Override
public void run() {
vmSizeComboBox.setModel(new DefaultComboBoxModel<>(sizes.stream().map(VirtualMachineSize::name).toArray(String[]::new)));
selectDefaultSize();
}
}, ModalityState.any());
}
});
} else {
selectDefaultSize();
}
return rootPanel;
}
use of com.intellij.openapi.progress.ProgressIndicator in project azure-tools-for-java by Microsoft.
the class SettingsStep method onFinish.
@Override
public boolean onFinish() {
final boolean isNewResourceGroup = createNewRadioButton.isSelected();
final String resourceGroupName = isNewResourceGroup ? resourceGrpField.getText() : resourceGrpCombo.getSelectedItem().toString();
ProgressManager.getInstance().run(new Task.Backgroundable(project, "Creating virtual machine " + model.getName() + "...", false) {
@Override
public void run(@NotNull ProgressIndicator progressIndicator) {
progressIndicator.setIndeterminate(true);
try {
String certificate = model.getCertificate();
byte[] certData = new byte[0];
if (!certificate.isEmpty()) {
File certFile = new File(certificate);
if (certFile.exists()) {
FileInputStream certStream = null;
try {
certStream = new FileInputStream(certFile);
certData = new byte[(int) certFile.length()];
if (certStream.read(certData) != certData.length) {
throw new Exception("Unable to process certificate: stream longer than informed size.");
}
} finally {
if (certStream != null) {
try {
certStream.close();
} catch (IOException ignored) {
}
}
}
}
}
// for (StorageAccount account : AzureManagerImpl.getManager(project).getStorageAccounts(
// model.getSubscription().getId(), true)) {
// if (account.getName().equals(storageAccount.getName())) {
// storageAccount = account;
// break;
// }
// }
final com.microsoft.azure.management.compute.VirtualMachine vm = AzureSDKManager.createVirtualMachine(model.getSubscription().getSubscriptionId(), model.getName(), resourceGroupName, createNewRadioButton.isSelected(), model.getSize(), model.getRegion().name(), model.getVirtualMachineImage(), model.getKnownMachineImage(), model.isKnownMachineImage(), model.getStorageAccount(), model.getNewStorageAccount(), model.isWithNewStorageAccount(), model.getVirtualNetwork(), model.getNewNetwork(), model.isWithNewNetwork(), model.getSubnet(), model.getPublicIpAddress(), model.isWithNewPip(), model.getAvailabilitySet(), model.isWithNewAvailabilitySet(), model.getUserName(), model.getPassword(), certData.length > 0 ? new String(certData) : null);
// update resource groups cache if new resource group was created when creating vm
ResourceGroup rg = null;
if (createNewRadioButton.isSelected()) {
rg = azure.resourceGroups().getByName(resourceGroupName);
AzureModelController.addNewResourceGroup(model.getSubscription(), rg);
}
if (model.isWithNewStorageAccount() && model.getNewStorageAccount().isNewResourceGroup() && (rg == null || !rg.name().equals(model.getNewStorageAccount().getResourceGroupName()))) {
rg = azure.resourceGroups().getByName(model.getNewStorageAccount().getResourceGroupName());
AzureModelController.addNewResourceGroup(model.getSubscription(), rg);
}
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
try {
parent.addChildNode(new com.microsoft.tooling.msservices.serviceexplorer.azure.vmarm.VMNode(parent, model.getSubscription().getSubscriptionId(), vm));
} catch (AzureCmdException e) {
String msg = "An error occurred while attempting to refresh the list of virtual machines.";
DefaultLoader.getUIHelper().showException(msg, e, "Azure Services Explorer - Error Refreshing VM List", false, true);
AzurePlugin.log(msg, e);
}
}
});
} catch (Exception e) {
String msg = "An error occurred while attempting to create the specified virtual machine." + "<br>" + String.format(message("webappExpMsg"), e.getMessage());
DefaultLoader.getUIHelper().showException(msg, e, message("errTtl"), false, true);
AzurePlugin.log(msg, e);
}
}
});
return super.onFinish();
}
Aggregations