Search in sources :

Example 1 with MavenProfileKind

use of org.jetbrains.idea.maven.model.MavenProfileKind in project intellij-community by JetBrains.

the class ToggleProfileAction method getTargetState.

@Nullable
private static MavenProfileKind getTargetState(@NotNull MavenProjectsManager projectsManager, Map<String, MavenProfileKind> profiles) {
    MavenExplicitProfiles explicitProfiles = projectsManager.getExplicitProfiles();
    MavenProfileKind targetState = null;
    // all profiles should target to the same state
    for (Map.Entry<String, MavenProfileKind> profile : profiles.entrySet()) {
        MavenProfileKind profileTargetState = getTargetState(profile, explicitProfiles);
        if (targetState == null) {
            targetState = profileTargetState;
        } else if (!targetState.equals(profileTargetState)) {
            targetState = null;
            break;
        }
    }
    return targetState;
}
Also used : MavenProfileKind(org.jetbrains.idea.maven.model.MavenProfileKind) MavenExplicitProfiles(org.jetbrains.idea.maven.model.MavenExplicitProfiles) Map(java.util.Map) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with MavenProfileKind

use of org.jetbrains.idea.maven.model.MavenProfileKind in project intellij-community by JetBrains.

the class ToggleProfileAction method actionPerformed.

@Override
public void actionPerformed(@NotNull AnActionEvent e) {
    MavenProjectsManager manager = MavenActionUtil.getProjectsManager(e.getDataContext());
    if (manager == null)
        return;
    Map<String, MavenProfileKind> selectedProfiles = e.getData(MavenDataKeys.MAVEN_PROFILES);
    if (selectedProfiles == null)
        return;
    Set<String> selectedProfileIds = selectedProfiles.keySet();
    MavenProfileKind targetState = getTargetState(manager, selectedProfiles);
    if (targetState == null)
        return;
    MavenExplicitProfiles newExplicitProfiles = manager.getExplicitProfiles().clone();
    switch(targetState) {
        case NONE:
            // disable explicitly
            newExplicitProfiles.getEnabledProfiles().removeAll(selectedProfileIds);
            newExplicitProfiles.getDisabledProfiles().addAll(selectedProfileIds);
            break;
        case EXPLICIT:
            // enable explicitly
            newExplicitProfiles.getDisabledProfiles().removeAll(selectedProfileIds);
            newExplicitProfiles.getEnabledProfiles().addAll(selectedProfileIds);
            break;
        case IMPLICIT:
        default:
            // reset to default state
            newExplicitProfiles.getEnabledProfiles().removeAll(selectedProfileIds);
            newExplicitProfiles.getDisabledProfiles().removeAll(selectedProfileIds);
            break;
    }
    manager.setExplicitProfiles(newExplicitProfiles);
}
Also used : MavenProfileKind(org.jetbrains.idea.maven.model.MavenProfileKind) MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) MavenExplicitProfiles(org.jetbrains.idea.maven.model.MavenExplicitProfiles)

Example 3 with MavenProfileKind

use of org.jetbrains.idea.maven.model.MavenProfileKind in project intellij-community by JetBrains.

the class ToggleProfileAction method getTargetState.

@Nullable
private static MavenProfileKind getTargetState(AnActionEvent e) {
    Map<String, MavenProfileKind> selectedProfiles = e.getData(MavenDataKeys.MAVEN_PROFILES);
    if (selectedProfiles == null || selectedProfiles.isEmpty())
        return null;
    MavenProjectsManager projectsManager = MavenActionUtil.getProjectsManager(e.getDataContext());
    if (projectsManager == null)
        return null;
    return getTargetState(projectsManager, selectedProfiles);
}
Also used : MavenProfileKind(org.jetbrains.idea.maven.model.MavenProfileKind) MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with MavenProfileKind

use of org.jetbrains.idea.maven.model.MavenProfileKind in project intellij-community by JetBrains.

the class ToggleProfileAction method update.

public void update(AnActionEvent e) {
    super.update(e);
    if (!isAvailable(e))
        return;
    MavenProfileKind targetState = getTargetState(e);
    if (targetState == null)
        return;
    String text;
    switch(targetState) {
        case NONE:
            text = ProjectBundle.message("maven.profile.deactivate");
            break;
        case EXPLICIT:
            text = ProjectBundle.message("maven.profile.activate");
            break;
        case IMPLICIT:
        default:
            text = ProjectBundle.message("maven.profile.default");
            break;
    }
    e.getPresentation().setText(text);
}
Also used : MavenProfileKind(org.jetbrains.idea.maven.model.MavenProfileKind)

Example 5 with MavenProfileKind

use of org.jetbrains.idea.maven.model.MavenProfileKind in project intellij-community by JetBrains.

the class SelectProfilesStep method validate.

public boolean validate() throws ConfigurationException {
    Collection<String> activatedProfiles = myMarkStateDescriptor.getActivatedProfiles();
    MavenExplicitProfiles newSelectedProfiles = MavenExplicitProfiles.NONE.clone();
    for (Map.Entry<String, MavenProfileKind> entry : profileChooser.getElementMarkStates().entrySet()) {
        String profile = entry.getKey();
        MavenProfileKind profileKind = entry.getValue();
        switch(profileKind) {
            case NONE:
                if (activatedProfiles.contains(profile)) {
                    newSelectedProfiles.getDisabledProfiles().add(profile);
                }
                break;
            case EXPLICIT:
                newSelectedProfiles.getEnabledProfiles().add(profile);
                break;
            case IMPLICIT:
                break;
        }
    }
    return getBuilder().setSelectedProfiles(newSelectedProfiles);
}
Also used : MavenProfileKind(org.jetbrains.idea.maven.model.MavenProfileKind) MavenExplicitProfiles(org.jetbrains.idea.maven.model.MavenExplicitProfiles)

Aggregations

MavenProfileKind (org.jetbrains.idea.maven.model.MavenProfileKind)5 MavenExplicitProfiles (org.jetbrains.idea.maven.model.MavenExplicitProfiles)3 Nullable (org.jetbrains.annotations.Nullable)2 MavenProjectsManager (org.jetbrains.idea.maven.project.MavenProjectsManager)2 Map (java.util.Map)1