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(String message,
        @NotNull @Nls(capitalization = Nls.Capitalization.Title) String title) 

Source Link

Document

Use this method only if you do not know project or component

Usage

From source file:com.intellij.ide.util.projectWizard.importSources.impl.ProjectFromSourcesBuilderImpl.java

License:Apache License

public List<Module> commit(final Project project, final ModifiableModuleModel model,
        final ModulesProvider modulesProvider) {
    final boolean fromProjectStructure = model != null;
    ModifiableModelsProvider modelsProvider = new IdeaModifiableModelsProvider();
    final LibraryTable.ModifiableModel projectLibraryTable = modelsProvider
            .getLibraryTableModifiableModel(project);
    final Map<LibraryDescriptor, Library> projectLibs = new HashMap<LibraryDescriptor, Library>();
    final List<Module> result = new ArrayList<Module>();
    try {//from   w w  w.j a v a2s  . c om
        AccessToken token = WriteAction.start();
        try {
            // create project-level libraries
            for (ProjectDescriptor projectDescriptor : getSelectedDescriptors()) {
                for (LibraryDescriptor lib : projectDescriptor.getLibraries()) {
                    final Collection<File> files = lib.getJars();
                    final Library projectLib = projectLibraryTable.createLibrary(lib.getName());
                    final Library.ModifiableModel libraryModel = projectLib.getModifiableModel();
                    for (File file : files) {
                        libraryModel.addRoot(VfsUtil.getUrlForLibraryRoot(file),
                                BinariesOrderRootType.getInstance());
                    }
                    libraryModel.commit();
                    projectLibs.put(lib, projectLib);
                }
            }
            if (!fromProjectStructure) {
                projectLibraryTable.commit();
            }
        } finally {
            token.finish();
        }
    } catch (Exception e) {
        LOG.info(e);
        Messages.showErrorDialog(IdeBundle.message("error.adding.module.to.project", e.getMessage()),
                IdeBundle.message("title.add.module"));
    }

    final Map<ModuleDescriptor, Module> descriptorToModuleMap = new HashMap<ModuleDescriptor, Module>();

    try {
        AccessToken token = WriteAction.start();
        try {
            final ModifiableModuleModel moduleModel = fromProjectStructure ? model
                    : ModuleManager.getInstance(project).getModifiableModel();
            for (ProjectDescriptor descriptor : getSelectedDescriptors()) {
                for (final ModuleDescriptor moduleDescriptor : descriptor.getModules()) {
                    final Module module;
                    if (moduleDescriptor.isReuseExistingElement()) {
                        final ExistingModuleLoader moduleLoader = ImportImlMode.setUpLoader(
                                FileUtil.toSystemIndependentName(moduleDescriptor.computeModuleDir()));
                        module = moduleLoader.createModule(moduleModel);
                    } else {
                        module = createModule(descriptor, moduleDescriptor, projectLibs, moduleModel);
                    }
                    result.add(module);
                    descriptorToModuleMap.put(moduleDescriptor, module);
                }
            }

            if (!fromProjectStructure) {
                moduleModel.commit();
            }
        } finally {
            token.finish();
        }
    } catch (Exception e) {
        LOG.info(e);
        Messages.showErrorDialog(IdeBundle.message("error.adding.module.to.project", e.getMessage()),
                IdeBundle.message("title.add.module"));
    }

    // setup dependencies between modules
    try {
        AccessToken token = WriteAction.start();
        try {
            for (ProjectDescriptor data : getSelectedDescriptors()) {
                for (final ModuleDescriptor descriptor : data.getModules()) {
                    final Module module = descriptorToModuleMap.get(descriptor);
                    if (module == null) {
                        continue;
                    }
                    final Set<ModuleDescriptor> deps = descriptor.getDependencies();
                    if (deps.size() == 0) {
                        continue;
                    }
                    final ModifiableRootModel rootModel = ModuleRootManager.getInstance(module)
                            .getModifiableModel();
                    for (ModuleDescriptor dependentDescriptor : deps) {
                        final Module dependentModule = descriptorToModuleMap.get(dependentDescriptor);
                        if (dependentModule != null) {
                            rootModel.addModuleOrderEntry(dependentModule);
                        }
                    }
                    rootModel.commit();
                }
            }
        } finally {
            token.finish();
        }
    } catch (Exception e) {
        LOG.info(e);
        Messages.showErrorDialog(IdeBundle.message("error.adding.module.to.project", e.getMessage()),
                IdeBundle.message("title.add.module"));
    }

    AccessToken token = WriteAction.start();
    try {
        ModulesProvider updatedModulesProvider = fromProjectStructure ? modulesProvider
                : new DefaultModulesProvider(project);
        for (ProjectConfigurationUpdater updater : myUpdaters) {
            updater.updateProject(project, modelsProvider, updatedModulesProvider);
        }
    } finally {
        token.finish();
    }

    return result;
}

From source file:com.intellij.ide.util.projectWizard.ModuleBuilder.java

License:Apache License

@Nullable
public Module commitModule(@NotNull final Project project, @Nullable final ModifiableModuleModel model) {
    if (canCreateModule()) {
        if (myName == null) {
            myName = project.getName();/* w  ww  .java  2 s .  c o  m*/
        }
        if (moduleDirPath == null) {
            moduleDirPath = project.getBaseDir().getPath() + File.separator + myName;
        }
        try {
            return ApplicationManager.getApplication()
                    .runWriteAction(new ThrowableComputable<Module, Exception>() {
                        @Override
                        public Module compute() throws Exception {
                            return createAndCommitIfNeeded(project, model, true);
                        }
                    });
        } catch (Exception ex) {
            LOG.warn(ex);
            Messages.showErrorDialog(IdeBundle.message("error.adding.module.to.project", ex.getMessage()),
                    IdeBundle.message("title.add.module"));
        }
    }
    return null;
}

From source file:com.intellij.ide.util.projectWizard.ProjectWizardUtil.java

License:Apache License

public static boolean createDirectoryIfNotExists(final String promptPrefix, String directoryPath,
        boolean promptUser) {
    File dir = new File(directoryPath);
    if (!dir.exists()) {
        if (promptUser) {
            final int answer = Messages.showOkCancelDialog(
                    IdeBundle.message("promot.projectwizard.directory.does.not.exist", promptPrefix,
                            dir.getPath(), ApplicationNamesInfo.getInstance().getFullProductName()),
                    IdeBundle.message("title.directory.does.not.exist"), Messages.getQuestionIcon());
            if (answer != 0) {
                return false;
            }/*  w  ww . jav a 2 s. c  o m*/
        }
        try {
            VfsUtil.createDirectories(dir.getPath());
        } catch (IOException e) {
            Messages.showErrorDialog(IdeBundle.message("error.failed.to.create.directory", dir.getPath()),
                    CommonBundle.getErrorTitle());
            return false;
        }
    }
    return true;
}

From source file:com.intellij.ide.wizard.AbstractWizard.java

License:Apache License

protected JComponent createSouthPanel() {
    JPanel panel = new JPanel(new BorderLayout());
    panel.setBorder(BorderFactory.createEmptyBorder(8, 0, 0, 0));

    JPanel buttonPanel = new JPanel();

    if (SystemInfo.isMac) {
        panel.add(buttonPanel, BorderLayout.EAST);
        buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));

        if (!UIUtil.isUnderDarcula()) {
            myHelpButton.putClientProperty("JButton.buttonType", "help");
        }//from   w  ww .ja v a  2 s.  c  o m
        if (UIUtil.isUnderAquaLookAndFeel()) {
            myHelpButton.setText("");
        }

        JPanel leftPanel = new JPanel();
        if (ApplicationInfo.contextHelpAvailable()) {
            leftPanel.add(myHelpButton);
        }
        leftPanel.add(myCancelButton);
        panel.add(leftPanel, BorderLayout.WEST);

        if (mySteps.size() > 1) {
            buttonPanel.add(Box.createHorizontalStrut(5));
            buttonPanel.add(myPreviousButton);
        }
        buttonPanel.add(Box.createHorizontalStrut(5));
        buttonPanel.add(myNextButton);
    } else {
        panel.add(buttonPanel, BorderLayout.CENTER);
        GroupLayout layout = new GroupLayout(buttonPanel);
        buttonPanel.setLayout(layout);
        layout.setAutoCreateGaps(true);

        final GroupLayout.SequentialGroup hGroup = layout.createSequentialGroup();
        final GroupLayout.ParallelGroup vGroup = layout.createParallelGroup();
        final Collection<Component> buttons = ContainerUtil.newArrayListWithCapacity(5);
        final boolean helpAvailable = ApplicationInfo.contextHelpAvailable();

        if (helpAvailable && UIUtil.isUnderGTKLookAndFeel()) {
            add(hGroup, vGroup, buttons, myHelpButton);
        }
        add(hGroup, vGroup, null, Box.createHorizontalGlue());
        if (mySteps.size() > 1) {
            add(hGroup, vGroup, buttons, myPreviousButton);
        }
        add(hGroup, vGroup, buttons, myNextButton, myCancelButton);
        if (helpAvailable && !UIUtil.isUnderGTKLookAndFeel()) {
            add(hGroup, vGroup, buttons, myHelpButton);
        }

        layout.setHorizontalGroup(hGroup);
        layout.setVerticalGroup(vGroup);
        layout.linkSize(buttons.toArray(new Component[buttons.size()]));
    }

    myPreviousButton.setEnabled(false);
    myPreviousButton.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            doPreviousAction();
        }
    });
    myNextButton.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            if (isLastStep()) {
                // Commit data of current step and perform OK action
                final Step currentStep = mySteps.get(myCurrentStep);
                LOG.assertTrue(currentStep != null);
                try {
                    currentStep._commit(true);
                    doOKAction();
                } catch (final CommitStepException exc) {
                    String message = exc.getMessage();
                    if (message != null) {
                        Messages.showErrorDialog(myContentPanel, message);
                    }
                }
            } else {
                doNextAction();
            }
        }
    });

    myCancelButton.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            doCancelAction();
        }
    });
    myHelpButton.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            helpAction();
        }
    });

    return panel;
}

From source file:com.intellij.ide.wizard.AbstractWizard.java

License:Apache License

protected void doPreviousAction() {
    // Commit data of current step
    final Step currentStep = mySteps.get(myCurrentStep);
    LOG.assertTrue(currentStep != null);
    try {//from www . j  ava  2 s  .c o m
        currentStep._commit(false);
    } catch (final CommitStepException exc) {
        Messages.showErrorDialog(myContentPanel, exc.getMessage());
        return;
    }

    myCurrentStep = getPreviousStep(myCurrentStep);
    updateStep();
}

From source file:com.intellij.ide.wizard.AbstractWizard.java

License:Apache License

protected void doNextAction() {
    // Commit data of current step
    final Step currentStep = mySteps.get(myCurrentStep);
    LOG.assertTrue(currentStep != null);
    LOG.assertTrue(!isLastStep(), "steps: " + mySteps + " current: " + currentStep);
    try {/*from  www .  j av  a2  s  .c om*/
        currentStep._commit(false);
    } catch (final CommitStepException exc) {
        Messages.showErrorDialog(myContentPanel, exc.getMessage());
        return;
    }

    myCurrentStep = getNextStep(myCurrentStep);
    updateStep();
}

From source file:com.intellij.ide.wizard.AbstractWizardEx.java

License:Apache License

protected void doPreviousAction() {
    // Commit data of current step
    final AbstractWizardStepEx currentStep = mySteps.get(myCurrentStep);
    try {/*from   w w  w .  j  av  a  2s  .  c  o m*/
        currentStep._commitPrev();
    } catch (final CommitStepCancelledException e) {
        return;
    } catch (CommitStepException e) {
        Messages.showErrorDialog(getContentPane(), e.getMessage());
        return;
    }

    myCurrentStep = getPreviousStep(myCurrentStep);
    updateStep();
}

From source file:com.intellij.ide.wizard.AbstractWizardEx.java

License:Apache License

protected void doNextAction() {
    // Commit data of current step
    final AbstractWizardStepEx currentStep = mySteps.get(myCurrentStep);
    try {//from www  .  j ava2 s. c  o m
        currentStep._commit(false);
    } catch (final CommitStepCancelledException e) {
        return;
    } catch (CommitStepException e) {
        Messages.showErrorDialog(getContentPane(), e.getMessage());
        return;
    }

    if (isLastStep()) {
        doOKAction();
        return;
    }
    myCurrentStep = getNextStep(myCurrentStep);
    updateStep();
}

From source file:com.intellij.profile.codeInspection.InspectionProfileManagerImpl.java

License:Apache License

public InspectionProfileManagerImpl(@NotNull InspectionToolRegistrar registrar,
        @NotNull SchemesManagerFactory schemesManagerFactory, @NotNull MessageBus messageBus) {
    myRegistrar = registrar;// w  ww  .ja  va2 s  .co m
    registerProvidedSeverities();

    mySchemesManager = schemesManagerFactory.createSchemesManager(FILE_SPEC,
            new BaseSchemeProcessor<InspectionProfileImpl>() {
                @NotNull
                @Override
                public InspectionProfileImpl readScheme(@NotNull Element element) {
                    final InspectionProfileImpl profile = new InspectionProfileImpl(
                            InspectionProfileLoadUtil.getProfileName(element), myRegistrar,
                            InspectionProfileManagerImpl.this);
                    try {
                        profile.readExternal(element);
                    } catch (Exception ignored) {
                        ApplicationManager.getApplication().invokeLater(new Runnable() {
                            @Override
                            public void run() {
                                Messages.showErrorDialog(
                                        InspectionsBundle.message("inspection.error.loading.message", 0,
                                                profile.getName()),
                                        InspectionsBundle.message("inspection.errors.occurred.dialog.title"));
                            }
                        }, ModalityState.NON_MODAL);
                    }
                    return profile;
                }

                @NotNull
                @Override
                public State getState(@NotNull InspectionProfileImpl scheme) {
                    return scheme.isProjectLevel() ? State.NON_PERSISTENT
                            : (scheme.wasInitialized() ? State.POSSIBLY_CHANGED : State.UNCHANGED);
                }

                @Override
                public Element writeScheme(@NotNull InspectionProfileImpl scheme) {
                    Element root = new Element("inspections");
                    root.setAttribute("profile_name", scheme.getName());
                    scheme.serializeInto(root, false);
                    return root;
                }

                @Override
                public void onSchemeAdded(@NotNull final InspectionProfileImpl scheme) {
                    updateProfileImpl(scheme);
                    fireProfileChanged(scheme);
                    onProfilesChanged();
                }

                @Override
                public void onSchemeDeleted(@NotNull final InspectionProfileImpl scheme) {
                    onProfilesChanged();
                }

                @Override
                public void onCurrentSchemeChanged(final InspectionProfileImpl oldCurrentScheme) {
                    Profile current = mySchemesManager.getCurrentScheme();
                    if (current != null) {
                        fireProfileChanged((Profile) oldCurrentScheme, current, null);
                    }
                    onProfilesChanged();
                }
            }, RoamingType.PER_USER);
    mySeverityRegistrar = new SeverityRegistrar(messageBus);
}

From source file:com.intellij.profile.codeInspection.InspectionProfileManagerImpl.java

License:Apache License

@Override
public Profile loadProfile(@NotNull String path) throws IOException, JDOMException {
    final File file = new File(path);
    if (file.exists()) {
        try {/*from   w  w  w .  j  a  v a  2  s .c  om*/
            return InspectionProfileLoadUtil.load(file, myRegistrar, this);
        } catch (IOException e) {
            throw e;
        } catch (JDOMException e) {
            throw e;
        } catch (Exception ignored) {
            ApplicationManager.getApplication().invokeLater(new Runnable() {
                @Override
                public void run() {
                    Messages.showErrorDialog(
                            InspectionsBundle.message("inspection.error.loading.message", 0, file),
                            InspectionsBundle.message("inspection.errors.occurred.dialog.title"));
                }
            }, ModalityState.NON_MODAL);
        }
    }
    return getProfile(path, false);
}