Search in sources :

Example 1 with CheckBoxList

use of com.intellij.ui.CheckBoxList in project intellij-community by JetBrains.

the class AbstractModuleDataService method ruleOrphanModules.

/**
   * There is a possible case that an external module has been un-linked from ide project. There are two ways to process
   * ide modules which correspond to that external project:
   * <pre>
   * <ol>
   *   <li>Remove them from ide project as well;</li>
   *   <li>Keep them at ide project as well;</li>
   * </ol>
   * </pre>
   * This method handles that situation, i.e. it asks a user what should be done and acts accordingly.
   *
   * @param orphanModules    modules which correspond to the un-linked external project
   * @param project          current ide project
   * @param externalSystemId id of the external system which project has been un-linked from ide project
   */
private static void ruleOrphanModules(@NotNull final List<Module> orphanModules, @NotNull final Project project, @NotNull final ProjectSystemId externalSystemId, @NotNull final Consumer<List<Module>> result) {
    ExternalSystemApiUtil.executeOnEdt(true, () -> {
        List<Module> toRemove = ContainerUtil.newSmartList();
        if (ApplicationManager.getApplication().isHeadlessEnvironment()) {
            toRemove.addAll(orphanModules);
        } else {
            final JPanel content = new JPanel(new GridBagLayout());
            content.add(new JLabel(ExternalSystemBundle.message("orphan.modules.text", externalSystemId.getReadableName())), ExternalSystemUiUtil.getFillLineConstraints(0));
            final CheckBoxList<Module> orphanModulesList = new CheckBoxList<>();
            orphanModulesList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
            orphanModulesList.setItems(orphanModules, module -> module.getName());
            for (Module module : orphanModules) {
                orphanModulesList.setItemSelected(module, true);
            }
            orphanModulesList.setBorder(IdeBorderFactory.createEmptyBorder(8));
            content.add(orphanModulesList, ExternalSystemUiUtil.getFillLineConstraints(0));
            content.setBorder(IdeBorderFactory.createEmptyBorder(0, 0, 8, 0));
            DialogWrapper dialog = new DialogWrapper(project) {

                {
                    setTitle(ExternalSystemBundle.message("import.title", externalSystemId.getReadableName()));
                    init();
                }

                @Nullable
                @Override
                protected JComponent createCenterPanel() {
                    return new JBScrollPane(content);
                }

                @NotNull
                protected Action[] createActions() {
                    return new Action[] { getOKAction() };
                }
            };
            dialog.showAndGet();
            for (int i = 0; i < orphanModules.size(); i++) {
                Module module = orphanModules.get(i);
                if (orphanModulesList.isItemSelected(i)) {
                    toRemove.add(module);
                }
            }
        }
        result.consume(toRemove);
    });
}
Also used : CheckBoxList(com.intellij.ui.CheckBoxList) Module(com.intellij.openapi.module.Module) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) JBScrollPane(com.intellij.ui.components.JBScrollPane)

Aggregations

Module (com.intellij.openapi.module.Module)1 DialogWrapper (com.intellij.openapi.ui.DialogWrapper)1 CheckBoxList (com.intellij.ui.CheckBoxList)1 JBScrollPane (com.intellij.ui.components.JBScrollPane)1