Android Open Source - adb-idea Module Chooser Dialog Helper






From Project

Back to project page adb-idea.

License

The source code is released under:

Apache License

If you think the Android project adb-idea listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.developerphil.adbidea.ui;
//  w w w  .  j a va 2  s.c om
import com.google.common.collect.Lists;
import com.intellij.ide.util.PropertiesComponent;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ui.configuration.ChooseModulesDialog;
import org.jetbrains.android.facet.AndroidFacet;

import java.util.List;

public final class ModuleChooserDialogHelper {

    public static final String SELECTED_MODULE_PROPERTY = ModuleChooserDialogHelper.class.getCanonicalName() + "-SELECTED_MODULE";

    private ModuleChooserDialogHelper() {
    }

    public static AndroidFacet showDialogForFacets(Project project, List<AndroidFacet> facets) {
        List<Module> modules = Lists.newArrayList();
        String previousModuleName = getPreviousModuleName(project);
        List<Module> previousSelectedModule = null;
        for (AndroidFacet facet : facets) {
            Module module = facet.getModule();
            modules.add(module);
            if (module.getName().equals(previousModuleName)) {
                previousSelectedModule = Lists.newArrayList(module);
            }
        }

        ChooseModulesDialog dialog = new ChooseModulesDialog(project, modules, "Choose Module", "");
        dialog.setSingleSelectionMode();
        if (previousSelectedModule != null) {
            dialog.selectElements(previousSelectedModule);
        }
        dialog.show();

        List<Module> chosenElements = dialog.getChosenElements();
        if (chosenElements.isEmpty()) {
            return null;
        }

        Module chosenModule = chosenElements.get(0);
        saveModuleName(project, chosenModule.getName());
        int chosenModuleIndex = modules.indexOf(chosenModule);
        return facets.get(chosenModuleIndex);
    }

    private static void saveModuleName(Project project, String moduleName) {
        final PropertiesComponent properties = PropertiesComponent.getInstance(project);
        properties.setValue(SELECTED_MODULE_PROPERTY, moduleName);
    }

    private static String getPreviousModuleName(Project project) {
        final PropertiesComponent properties = PropertiesComponent.getInstance(project);
        return properties.getValue(SELECTED_MODULE_PROPERTY);
    }

}




Java Source Code List

com.developerphil.TestProjectMultiModule.MyActivity.java
com.developerphil.adbidea.action.AdbAction.java
com.developerphil.adbidea.action.ClearDataAction.java
com.developerphil.adbidea.action.ClearDataAndRestartAction.java
com.developerphil.adbidea.action.KillAction.java
com.developerphil.adbidea.action.RestartAction.java
com.developerphil.adbidea.action.StartAction.java
com.developerphil.adbidea.action.UninstallAction.java
com.developerphil.adbidea.adb.AdbFacade.java
com.developerphil.adbidea.adb.AdbUtil.java
com.developerphil.adbidea.adb.command.ClearDataAndRestartCommand.java
com.developerphil.adbidea.adb.command.ClearDataCommand.java
com.developerphil.adbidea.adb.command.CommandList.java
com.developerphil.adbidea.adb.command.Command.java
com.developerphil.adbidea.adb.command.KillCommand.java
com.developerphil.adbidea.adb.command.RestartPackageCommand.java
com.developerphil.adbidea.adb.command.StartDefaultActivityCommand.java
com.developerphil.adbidea.adb.command.UninstallCommand.java
com.developerphil.adbidea.adb.command.receiver.GenericReceiver.java
com.developerphil.adbidea.ui.DeviceChooserDialog.java
com.developerphil.adbidea.ui.ModuleChooserDialogHelper.java
com.developerphil.adbidea.ui.NotificationHelper.java
com.example.SecondModule.MySecondModuleActivity.java
com.example.app.MainActivity.java
com.example.untitled.MyActivity.java
org.joor.ReflectException.java
org.joor.Reflect.java