Example usage for com.intellij.openapi.ui Messages showErrorDialog

List of usage examples for com.intellij.openapi.ui Messages showErrorDialog

Introduction

In this page you can find the example usage for com.intellij.openapi.ui Messages showErrorDialog.

Prototype

public static void showErrorDialog(@Nullable Component component, String message,
            @NotNull @Nls(capitalization = Nls.Capitalization.Title) String title) 

Source Link

Usage

From source file:com.android.tools.idea.avdmanager.AvdOptionsModel.java

License:Apache License

@Override
protected void handleFinished() {
    // By this point we should have both a Device and a SystemImage
    Device device = myDevice.getValue();
    SystemImageDescription systemImage = mySystemImage.getValue();

    Map<String, String> hardwareProperties = DeviceManager.getHardwareProperties(device);
    Map<String, Object> userEditedProperties = generateUserEditedPropertiesMap();

    // Remove the SD card setting that we're not using
    String sdCard = null;//from w  w w  .j  av a2  s .c o  m

    boolean useExisting = myUseExternalSdCard.get();
    if (!useExisting) {
        if (sdCardStorage().get().isPresent() && myOriginalSdCard != null
                && sdCardStorage().getValue().equals(myOriginalSdCard.get())) {
            // unchanged, use existing card
            useExisting = true;
        }
    }

    boolean hasSdCard = false;
    if (!useExisting) {

        userEditedProperties.remove(AvdWizardUtils.EXISTING_SD_LOCATION);
        Storage storage = null;
        myOriginalSdCard = new ObjectValueProperty<>(mySdCardStorage.getValue());
        if (mySdCardStorage.get().isPresent()) {
            storage = mySdCardStorage.getValue();
            sdCard = toIniString(storage, false);
        }
        hasSdCard = storage != null && storage.getSize() > 0;
    } else if (!Strings.isNullOrEmpty(existingSdLocation.get())) {
        sdCard = existingSdLocation.get();
        userEditedProperties.remove(AvdWizardUtils.SD_CARD_STORAGE_KEY);
        hasSdCard = true;
    }
    hardwareProperties.put(HardwareProperties.HW_SDCARD, toIniString(hasSdCard));
    // Remove any internal keys from the map
    userEditedProperties = Maps.filterEntries(userEditedProperties,
            input -> !input.getKey().startsWith(AvdWizardUtils.WIZARD_ONLY) && input.getValue() != null);

    // Call toIniString() on all remaining values
    hardwareProperties.putAll(Maps.transformEntries(userEditedProperties, (key, value) -> {
        if (value instanceof Storage) {
            if (key.equals(AvdWizardUtils.RAM_STORAGE_KEY) || key.equals(AvdWizardUtils.VM_HEAP_STORAGE_KEY)) {
                return toIniString((Storage) value, true);
            } else {
                return toIniString((Storage) value, false);
            }
        } else if (value instanceof Boolean) {
            return toIniString((Boolean) value);
        } else if (value instanceof File) {
            return toIniString((File) value);
        } else if (value instanceof Double) {
            return toIniString((Double) value);
        } else if (value instanceof GpuMode) {
            return ((GpuMode) value).getGpuSetting();
        } else {
            return value.toString();
        }
    }));

    File skinFile = (myAvdDeviceData.customSkinFile().get().isPresent())
            ? myAvdDeviceData.customSkinFile().getValue()
            : AvdWizardUtils.resolveSkinPath(device.getDefaultHardware().getSkinFile(), systemImage,
                    FileOpUtils.create());

    if (myBackupSkinFile.get().isPresent()) {
        hardwareProperties.put(AvdManager.AVD_INI_BACKUP_SKIN_PATH, myBackupSkinFile.getValue().getPath());
    }

    // Add defaults if they aren't already set differently
    if (!hardwareProperties.containsKey(AvdManager.AVD_INI_SKIN_DYNAMIC)) {
        hardwareProperties.put(AvdManager.AVD_INI_SKIN_DYNAMIC, toIniString(true));
    }
    if (!hardwareProperties.containsKey(HardwareProperties.HW_KEYBOARD)) {
        hardwareProperties.put(HardwareProperties.HW_KEYBOARD, toIniString(false));
    }

    boolean isCircular = myAvdDeviceData.isScreenRound().get();

    String tempAvdName = myAvdId.get();
    final String avdName = tempAvdName.isEmpty() ? calculateAvdName(myAvdInfo, hardwareProperties, device)
            : tempAvdName;

    // If we're editing an AVD and we downgrade a system image, wipe the user data with confirmation
    if (myAvdInfo != null) {
        ISystemImage image = myAvdInfo.getSystemImage();
        if (image != null) {
            int oldApiLevel = image.getAndroidVersion().getFeatureLevel();
            int newApiLevel = systemImage.getVersion().getFeatureLevel();
            final String oldApiName = image.getAndroidVersion().getApiString();
            final String newApiName = systemImage.getVersion().getApiString();
            if (oldApiLevel > newApiLevel || (oldApiLevel == newApiLevel
                    && image.getAndroidVersion().isPreview() && !systemImage.getVersion().isPreview())) {
                final AtomicReference<Boolean> shouldContinue = new AtomicReference<>();
                ApplicationManager.getApplication().invokeAndWait(() -> {
                    String message = String.format(Locale.getDefault(),
                            "You are about to downgrade %1$s from API level %2$s to API level %3$s.\n"
                                    + "This requires a wipe of the userdata partition of the AVD.\nDo you wish to "
                                    + "continue with the data wipe?",
                            avdName, oldApiName, newApiName);
                    int result = Messages.showYesNoDialog((Project) null, message, "Confirm Data Wipe",
                            AllIcons.General.QuestionDialog);
                    shouldContinue.set(result == Messages.YES);
                }, ModalityState.any());
                if (shouldContinue.get()) {
                    AvdManagerConnection.getDefaultAvdManagerConnection().wipeUserData(myAvdInfo);
                } else {
                    return;
                }
            }
        }
    }

    AvdManagerConnection connection = AvdManagerConnection.getDefaultAvdManagerConnection();
    myCreatedAvd = connection.createOrUpdateAvd(myAvdInfo, avdName, device, systemImage,
            mySelectedAvdOrientation.get(), isCircular, sdCard, skinFile, hardwareProperties, false);
    if (myCreatedAvd == null) {
        ApplicationManager.getApplication().invokeAndWait(() -> Messages.showErrorDialog((Project) null,
                "An error occurred while creating the AVD. See idea.log for details.", "Error Creating AVD"),
                ModalityState.any());
    }
}

From source file:com.android.tools.idea.avdmanager.DeleteAvdAction.java

License:Apache License

@Override
public void actionPerformed(ActionEvent e) {
    AvdManagerConnection connection = AvdManagerConnection.getDefaultAvdManagerConnection();
    AvdInfo info = getAvdInfo();//from  www .j a v  a  2 s .c  o  m
    if (info == null) {
        return;
    }
    if (connection.isAvdRunning(info)) {
        Messages.showErrorDialog(myAvdInfoProvider.getComponent(),
                "The selected AVD is currently running in the Emulator. Please exit the emulator instance and try deleting again.",
                "Cannot Delete A Running AVD");
        return;
    }
    int result = Messages.showYesNoDialog(myAvdInfoProvider.getComponent(),
            "Do you really want to delete AVD " + info.getName() + "?", "Confirm Deletion",
            AllIcons.General.QuestionDialog);
    if (result == Messages.YES) {
        if (!connection.deleteAvd(info)) {
            Messages.showErrorDialog(myAvdInfoProvider.getComponent(),
                    "An error occurred while deleting the AVD. See idea.log for details.",
                    "Error Deleting AVD");
        }
        refreshAvds();
    }
}

From source file:com.android.tools.idea.avdmanager.WipeAvdDataAction.java

License:Apache License

@Override
public void actionPerformed(ActionEvent e) {
    AvdManagerConnection connection = AvdManagerConnection.getDefaultAvdManagerConnection();
    AvdInfo avdInfo = getAvdInfo();//www  .  j a v  a 2s .com
    if (avdInfo == null) {
        return;
    }
    if (connection.isAvdRunning(avdInfo)) {
        Messages.showErrorDialog(myAvdInfoProvider.getComponent(),
                "The selected AVD is currently running in the Emulator. "
                        + "Please exit the emulator instance and try wiping again.",
                "Cannot Wipe A Running AVD");
        return;
    }
    int result = Messages.showYesNoDialog(myAvdInfoProvider.getComponent(),
            "Do you really want to wipe user files from AVD " + avdInfo.getName() + "?", "Confirm Data Wipe",
            AllIcons.General.QuestionDialog);
    if (result == Messages.YES) {
        connection.wipeUserData(avdInfo);
        refreshAvds();
    }
}

From source file:com.android.tools.idea.ddms.actions.ScreenshotAction.java

License:Apache License

@Override
protected void performAction(@NotNull final IDevice device) {
    final Project project = myProject;

    new ScreenshotTask(project, device) {
        @Override/*from  w ww . j  ava 2 s. c o  m*/
        public void onSuccess() {
            String msg = getError();
            if (msg != null) {
                Messages.showErrorDialog(project, msg,
                        AndroidBundle.message("android.ddms.actions.screenshot"));
                return;
            }

            try {
                File backingFile = FileUtil.createTempFile("screenshot", SdkConstants.DOT_PNG, true);
                ImageIO.write(getScreenshot(), SdkConstants.EXT_PNG, backingFile);

                final ScreenshotViewer viewer = new ScreenshotViewer(project, getScreenshot(), backingFile,
                        device, device.getProperty(IDevice.PROP_DEVICE_MODEL));
                viewer.showAndGetOk().doWhenDone((Consumer<Boolean>) ok -> {
                    if (ok) {
                        File screenshot = viewer.getScreenshot();
                        VirtualFile vf = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(screenshot);
                        if (vf != null) {
                            vf.refresh(false, false);
                            FileEditorManager.getInstance(project).openFile(vf, true);
                        }
                    }
                });
            } catch (Exception e) {
                Logger.getInstance(ScreenshotAction.class).warn("Error while displaying screenshot viewer: ",
                        e);
                Messages.showErrorDialog(project,
                        AndroidBundle.message("android.ddms.screenshot.generic.error", e),
                        AndroidBundle.message("android.ddms.actions.screenshot"));
            }
        }
    }.queue();
}

From source file:com.android.tools.idea.ddms.actions.ToggleMethodProfilingAction.java

License:Apache License

@Override
protected void setSelected(@NotNull Client c) {
    ClientData cd = c.getClientData();/*from  ww  w .j a va  2  s .  co m*/
    try {
        if (cd.getMethodProfilingStatus() == ClientData.MethodProfilingStatus.TRACER_ON) {
            c.stopMethodTracer();
        } else {
            c.startMethodTracer();
        }
    } catch (IOException e1) {
        Messages.showErrorDialog(myProject, "Unexpected error while toggling method profiling: " + e1,
                "Method Profiling");
    }
}

From source file:com.android.tools.idea.ddms.DumpSysAction.java

License:Apache License

private static void showError(@Nullable final Project project, @NotNull final String message,
        @Nullable final Throwable throwable) {
    ApplicationManager.getApplication().invokeLater(new Runnable() {
        @Override//www.  java 2  s  .  co m
        public void run() {
            String msg = message;
            if (throwable != null) {
                msg += throwable.getLocalizedMessage() != null ? ": " + throwable.getLocalizedMessage() : "";
            }

            Messages.showErrorDialog(project, msg, TITLE);
        }
    });
}

From source file:com.android.tools.idea.ddms.OpenVmTraceHandler.java

License:Apache License

private void showError(final String message) {
    LOG.error("Method Profiling: " + message);
    ApplicationManager.getApplication().invokeLater(new Runnable() {
        @Override/*from  w w  w.  j a  v  a 2 s.c om*/
        public void run() {
            Messages.showErrorDialog(myProject, message, "Method Trace");
        }
    });
}

From source file:com.android.tools.idea.ddms.screenshot.ScreenshotViewer.java

License:Apache License

private void doRefreshScreenshot() {
    assert myDevice != null;
    new ScreenshotTask(myProject, myDevice) {
        @Override//from w w w.j  a  v a2 s  . c o  m
        public void onSuccess() {
            String msg = getError();
            if (msg != null) {
                Messages.showErrorDialog(myProject, msg,
                        AndroidBundle.message("android.ddms.actions.screenshot"));
                return;
            }

            BufferedImage image = getScreenshot();
            mySourceImageRef.set(image);
            frameScreenshot(myRotationAngle);
        }
    }.queue();
}

From source file:com.android.tools.idea.ddms.screenshot.ScreenshotViewer.java

License:Apache License

@Override
protected void doOKAction() {
    FileSaverDescriptor descriptor = new FileSaverDescriptor(
            AndroidBundle.message("android.ddms.screenshot.save.title"), "", SdkConstants.EXT_PNG);
    FileSaverDialog saveFileDialog = FileChooserFactory.getInstance().createSaveFileDialog(descriptor,
            myProject);/*  www.ja va  2  s. c om*/
    VirtualFile baseDir = ourLastSavedFolder != null ? ourLastSavedFolder : myProject.getBaseDir();
    VirtualFileWrapper fileWrapper = saveFileDialog.save(baseDir, getDefaultFileName());
    if (fileWrapper == null) {
        return;
    }

    myScreenshotFile = fileWrapper.getFile();
    try {
        ImageIO.write(myDisplayedImageRef.get(), SdkConstants.EXT_PNG, myScreenshotFile);
    } catch (IOException e) {
        Messages.showErrorDialog(myProject, AndroidBundle.message("android.ddms.screenshot.save.error", e),
                AndroidBundle.message("android.ddms.actions.screenshot"));
        return;
    }

    VirtualFile virtualFile = fileWrapper.getVirtualFile();
    if (virtualFile != null) {
        //noinspection AssignmentToStaticFieldFromInstanceMethod
        ourLastSavedFolder = virtualFile.getParent();
    }

    super.doOKAction();
}

From source file:com.android.tools.idea.editors.allocations.AllocationsEditor.java

License:Apache License

private void parseAllocationsFileInBackground(final Project project, final VirtualFile file) {
    final Task.Modal parseTask = new Task.Modal(project, "Parsing allocations file", false) {
        private AllocationInfo[] myAllocations;
        private String myErrorMessage;

        @Override//w  w w. j  a  va2 s . c o  m
        public void run(@NotNull ProgressIndicator indicator) {
            indicator.setIndeterminate(true);

            final File allocationsFile = VfsUtilCore.virtualToIoFile(file);
            ByteBuffer data;
            try {
                data = ByteBufferUtil.mapFile(allocationsFile, 0, ByteOrder.BIG_ENDIAN);
            } catch (IOException ex) {
                myErrorMessage = "Error reading from allocations file " + allocationsFile.getAbsolutePath();
                throw new ProcessCanceledException();
            }

            if (AllocationsParser.hasOverflowedNumEntriesBug(data)) {
                myErrorMessage = "Invalid allocations file detected. Please refer to https://code.google.com/p/android/issues/detail?id=204503 for details.";
                throw new ProcessCanceledException();
            }

            try {
                myAllocations = AllocationsParser.parse(data);
            } catch (final Throwable throwable) {
                //noinspection ThrowableResultOfMethodCallIgnored
                myErrorMessage = "Unexpected error while parsing allocations file: "
                        + Throwables.getRootCause(throwable).getMessage();
                throw new ProcessCanceledException();
            }
        }

        @Override
        public void onSuccess() {
            AllocationsView view = new AllocationsView(project, myAllocations);
            myPanel.add(view.getComponent(), BorderLayout.CENTER);
        }

        @Override
        public void onCancel() {
            Messages.showErrorDialog(project, myErrorMessage, getName());
        }
    };

    ApplicationManager.getApplication().invokeLater(parseTask::queue);
}