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;
}
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);
}
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);
}
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);
}
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);
}
Aggregations