Author: fbricon
Date: 2011-07-18 09:15:17 -0400 (Mon, 18 Jul 2011)
New Revision: 33011
Added:
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/profiles/ProfileState.java
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/profiles/ProfileStatus.java
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/profiles/ActiveMavenProfilesNode.java
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/profiles/ActiveProfilesContentProvider.java
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/profiles/ActiveProfilesLabelProvider.java
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/profiles/ProfileSelection.java
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/profiles/ProfileSelectionStatus.java
Modified:
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/internal/profiles/ProfileManager.java
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/profiles/IProfileManager.java
trunk/maven/plugins/org.jboss.tools.maven.ui/plugin.xml
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/profiles/ProfileSelectionHandler.java
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/profiles/SelectProfilesDialog.java
Log:
JBIDE-8969 : Enable multiple project selection
Modified:
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/internal/profiles/ProfileManager.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/internal/profiles/ProfileManager.java 2011-07-18
12:16:44 UTC (rev 33010)
+++
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/internal/profiles/ProfileManager.java 2011-07-18
13:15:17 UTC (rev 33011)
@@ -1,9 +1,14 @@
package org.jboss.tools.maven.core.internal.profiles;
+import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import org.apache.maven.model.Profile;
import org.apache.maven.settings.Settings;
@@ -17,6 +22,8 @@
import org.eclipse.m2e.core.project.MavenUpdateRequest;
import org.eclipse.m2e.core.project.ResolverConfiguration;
import org.jboss.tools.maven.core.profiles.IProfileManager;
+import org.jboss.tools.maven.core.profiles.ProfileState;
+import org.jboss.tools.maven.core.profiles.ProfileStatus;
public class ProfileManager implements IProfileManager {
@@ -25,7 +32,9 @@
final boolean isOffline,
final boolean isForceUpdate,
IProgressMonitor monitor) throws CoreException {
-
+ if (mavenProjectFacade == null) {
+ return;
+ }
final IProjectConfigurationManager configurationManager =
MavenPlugin.getProjectConfigurationManager();
final ResolverConfiguration configuration =configurationManager
.getResolverConfiguration(mavenProjectFacade.getProject());
@@ -117,4 +126,99 @@
return false;
}
+ public List<ProfileStatus> getProfilesStatuses(
+ IMavenProjectFacade facade) throws CoreException {
+ if (facade == null) {
+ return Collections.emptyList();
+ }
+
+ ResolverConfiguration resolverConfiguration =
MavenPlugin.getProjectConfigurationManager()
+ .getResolverConfiguration(facade.getProject());
+
+ List<String> configuredProfiles = resolverConfiguration.getActiveProfileList();
+
+ final List<Profile> activeProfiles =
facade.getMavenProject().getActiveProfiles();
+
+ List<Profile> projectProfiles = new
ArrayList<Profile>(facade.getMavenProject().getModel().getProfiles());
+
+ final Map<Profile, Boolean> availableSettingsProfiles =
getAvailableSettingProfiles();
+ Set<Profile> settingsProfiles = new
HashSet<Profile>(availableSettingsProfiles.keySet());
+
+ List<ProfileStatus> statuses = new ArrayList<ProfileStatus>();
+
+ //First we put user configured profiles
+ for (String pId : configuredProfiles) {
+ if ("".equals(pId.trim())) continue;
+ boolean isDisabled = pId.startsWith("!");
+ String id = (isDisabled)?pId.substring(1):pId;
+ ProfileStatus status = new ProfileStatus(id);
+ status.setUserSelected(true);
+ ProfileState state = isDisabled?ProfileState.Disabled
+ :ProfileState.Active;
+ status.setActivationState(state);
+
+ Profile p = get(id, projectProfiles);
+
+ if (p == null){
+ p = get(id, settingsProfiles);
+ if(p != null){
+ status.setAutoActive(availableSettingsProfiles.get(p));
+ }
+ }
+
+ if (p == null) {
+ status.setSource("undefined");
+ } else {
+ status.setSource(p.getSource());
+ }
+ statuses.add(status);
+ }
+
+ //Iterate on the remaining project profiles
+ addStatuses(statuses, projectProfiles, new ActivationPredicate() {
+ @Override
+ boolean isActive(Profile p) {
+ return ProfileManager.this.isActive(p, activeProfiles);
+ }
+ });
+
+ //Iterate on the remaining settings profiles
+ addStatuses(statuses, settingsProfiles, new ActivationPredicate() {
+ @Override
+ boolean isActive(Profile p) {
+ return availableSettingsProfiles.get(p);
+ }
+ });
+ return Collections.unmodifiableList(statuses);
+ }
+
+ private void addStatuses(List<ProfileStatus> statuses, Collection<Profile>
profiles, ActivationPredicate predicate) {
+ for (Profile p : profiles) {
+ ProfileStatus status = new ProfileStatus(p.getId());
+ status.setSource(p.getSource());
+ boolean isActive = predicate.isActive(p);
+ ProfileState activationState = (isActive)?ProfileState.Active:ProfileState.Inactive;
+ status.setAutoActive(isActive);
+ status.setActivationState(activationState);
+ statuses.add(status);
+ }
+ }
+
+ private Profile get(String id, Collection<Profile> profiles) {
+ Iterator<Profile> ite = profiles.iterator();
+ Profile found = null;
+ while(ite.hasNext()) {
+ Profile p = ite.next();
+ if(p.getId().equals(id)) {
+ found = p;
+ ite.remove();
+ break;
+ }
+ }
+ return found;
+ }
+
+ private abstract class ActivationPredicate {
+ abstract boolean isActive(Profile p);
+ }
}
Modified:
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/profiles/IProfileManager.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/profiles/IProfileManager.java 2011-07-18
12:16:44 UTC (rev 33010)
+++
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/profiles/IProfileManager.java 2011-07-18
13:15:17 UTC (rev 33011)
@@ -2,6 +2,7 @@
import java.util.List;
import java.util.Map;
+import java.util.Set;
import org.apache.maven.model.Profile;
import org.eclipse.core.runtime.CoreException;
@@ -24,7 +25,9 @@
* @throws CoreException
*/
Map<Profile, Boolean> getAvailableProfiles(IMavenProjectFacade mavenProjectFacade)
throws CoreException;
-
+
+ List<ProfileStatus> getProfilesStatuses(IMavenProjectFacade mavenProjectFacade)
throws CoreException;
+
/**
* Returns an unmodifiable Map of all the available profiles defined in the
* Maven settings.xml file.<br/>
Added:
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/profiles/ProfileState.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/profiles/ProfileState.java
(rev 0)
+++
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/profiles/ProfileState.java 2011-07-18
13:15:17 UTC (rev 33011)
@@ -0,0 +1,18 @@
+package org.jboss.tools.maven.core.profiles;
+
+public enum ProfileState {
+ Disabled(false),
+ Inactive(false),
+ Active(true);
+
+ private boolean active;
+
+ ProfileState(boolean active) {
+ this.active = active;
+ }
+
+ public boolean isActive() {
+ return active;
+ }
+
+}
Added:
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/profiles/ProfileStatus.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/profiles/ProfileStatus.java
(rev 0)
+++
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/profiles/ProfileStatus.java 2011-07-18
13:15:17 UTC (rev 33011)
@@ -0,0 +1,100 @@
+package org.jboss.tools.maven.core.profiles;
+
+public class ProfileStatus {
+ private String id;
+ private boolean autoActive;
+ private boolean userSelected;
+ private ProfileState activationState;
+ private String source;
+
+ public ProfileStatus(String id) {
+ this.id = id;
+ }
+
+ public String getId() {
+ return id;
+ }
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public boolean isAutoActive() {
+ return autoActive;
+ }
+
+ public void setAutoActive(boolean autoActive) {
+ this.autoActive = autoActive;
+ }
+
+ public ProfileState getActivationState() {
+ return activationState;
+ }
+ public void setActivationState(ProfileState activationState) {
+ this.activationState = activationState;
+ }
+ public String getSource() {
+ return source;
+ }
+ public void setSource(String source) {
+ this.source = source;
+ }
+
+ public boolean isUserSelected() {
+ return userSelected;
+ }
+
+ public void setUserSelected(boolean userSelected) {
+ this.userSelected = userSelected;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result
+ + ((activationState == null) ? 0 : activationState.hashCode());
+ result = prime * result + (autoActive ? 1231 : 1237);
+ result = prime * result + ((id == null) ? 0 : id.hashCode());
+ result = prime * result + ((source == null) ? 0 : source.hashCode());
+ result = prime * result + (userSelected ? 1231 : 1237);
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ ProfileStatus other = (ProfileStatus) obj;
+ if (activationState != other.activationState)
+ return false;
+ if (autoActive != other.autoActive)
+ return false;
+ if (id == null) {
+ if (other.id != null)
+ return false;
+ } else if (!id.equals(other.id))
+ return false;
+ if (source == null) {
+ if (other.source != null)
+ return false;
+ } else if (!source.equals(other.source))
+ return false;
+ if (userSelected != other.userSelected)
+ return false;
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return "ProfileStatus [id=" + id + ", autoActive=" + autoActive
+ + ", userSelected=" + userSelected + ", activationState="
+ + activationState + ", source=" + source + "]";
+ }
+
+
+
+}
Modified: trunk/maven/plugins/org.jboss.tools.maven.ui/plugin.xml
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.ui/plugin.xml 2011-07-18 12:16:44 UTC (rev
33010)
+++ trunk/maven/plugins/org.jboss.tools.maven.ui/plugin.xml 2011-07-18 13:15:17 UTC (rev
33011)
@@ -153,4 +153,55 @@
</repository></pattern>
</template>
</extension>
+ <!--
+ <extension
+ point="org.eclipse.ui.navigator.viewer">
+ <viewerContentBinding
+ viewerId="org.eclipse.ui.navigator.ProjectExplorer">
+ <includes>
+ <contentExtension
+ isRoot="false"
+
pattern="org.jboss.tools.maven.profiles.navigatorContent">
+ </contentExtension>
+ </includes>
+ </viewerContentBinding>
+ </extension>
+
+
+ <extension point="org.eclipse.ui.navigator.navigatorContent">
+ <navigatorContent
id="org.jboss.tools.maven.profiles.navigatorContent"
+
contentProvider="org.jboss.tools.maven.ui.internal.profiles.ActiveProfilesContentProvider"
+
labelProvider="org.jboss.tools.maven.ui.internal.profiles.ActiveProfilesLabelProvider"
+ appearsBefore="org.eclipse.jdt.java.ui.javaContent"
+ name="Active Maven Profiles"
+ activeByDefault="true"
+ icon="icons/maven-profiles.gif"
+ priority="normal">
+
+ <possibleChildren>
+ <instanceof
value="org.jboss.tools.maven.ui.internal.profiles.ActiveMavenProfilesNode"/>
+ </possibleChildren>
+
+ <triggerPoints>
+ <or>
+ <instanceof
+
value="org.jboss.tools.maven.ui.internal.profiles.ActiveMavenProfilesNode">
+ </instanceof>
+ <and>
+ <instanceof
+ value="org.eclipse.core.resources.IProject">
+ </instanceof>
+ <test
+ forcePluginActivation="true"
+ property="org.eclipse.core.resources.projectNature"
+ value="org.eclipse.m2e.core.maven2Nature">
+ </test>
+ </and>
+ </or>
+ </triggerPoints>
+
+ </navigatorContent>
+ </extension>
+ -->
+
</plugin>
Added:
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/profiles/ActiveMavenProfilesNode.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/profiles/ActiveMavenProfilesNode.java
(rev 0)
+++
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/profiles/ActiveMavenProfilesNode.java 2011-07-18
13:15:17 UTC (rev 33011)
@@ -0,0 +1,70 @@
+/*************************************************************************************
+ * Copyright (c) 2009-2011 Red Hat, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+
+package org.jboss.tools.maven.ui.internal.profiles;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.maven.model.Profile;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.model.IWorkbenchAdapter;
+import org.jboss.tools.maven.ui.Activator;
+
+
+/**
+ * Maven profile resource node
+ *
+ * @author Fred Bricon
+ */
+public class ActiveMavenProfilesNode implements IWorkbenchAdapter {
+
+ private Object[] ids = null;
+
+ public static ImageDescriptor icon =
Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID,
"icons/maven-profiles.png");
+
+
+ public ActiveMavenProfilesNode(List<Profile> profiles) {
+ ids = getProfileIds(profiles);
+ }
+
+ public Object[] getResources() {
+ return ids;
+ }
+
+ private Object[] getProfileIds(List<Profile> profiles) {
+ if(profiles != null && !profiles.isEmpty()) {
+ List<String> idList = new ArrayList<String>(profiles.size());
+ for (Profile p : profiles) {
+ idList.add(p.getId());
+ }
+ return idList.toArray();
+ }
+ return null;
+ }
+
+ public String getLabel(Object o) {
+ return "Active Maven profiles";
+ }
+
+ public ImageDescriptor getImageDescriptor(Object object) {
+ return icon;
+ }
+
+ public Object getParent(Object o) {
+ return null;
+ }
+
+ public Object[] getChildren(Object o) {
+ return ids;
+ }
+
+}
Added:
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/profiles/ActiveProfilesContentProvider.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/profiles/ActiveProfilesContentProvider.java
(rev 0)
+++
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/profiles/ActiveProfilesContentProvider.java 2011-07-18
13:15:17 UTC (rev 33011)
@@ -0,0 +1,60 @@
+package org.jboss.tools.maven.ui.internal.profiles;
+
+import java.util.List;
+
+import org.apache.maven.model.Profile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.m2e.core.MavenPlugin;
+import org.eclipse.m2e.core.internal.IMavenConstants;
+import org.eclipse.m2e.core.project.IMavenProjectFacade;
+
+public class ActiveProfilesContentProvider implements
+ITreeContentProvider {
+
+ public void dispose() {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public Object[] getElements(Object inputElement) {
+ if (inputElement instanceof IProject) {
+ IProject project = (IProject) inputElement;
+ try {
+ if (project.isAccessible() && project.hasNature(IMavenConstants.NATURE_ID))
{
+ IMavenProjectFacade facade =
MavenPlugin.getMavenProjectRegistry().getProject(project);
+ if (facade != null && facade.getMavenProject() != null) {
+ List<Profile> profiles = facade.getMavenProject().getActiveProfiles();
+ return new Object[] { new ActiveMavenProfilesNode(profiles)};
+ }
+ }
+ } catch (CoreException e) {
+ e.printStackTrace();
+ }
+ }
+ return null;
+ }
+
+ public Object[] getChildren(Object parentElement) {
+ return getElements(parentElement);
+ }
+
+ public Object getParent(Object element) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public boolean hasChildren(Object element) {
+ // TODO Auto-generated method stub
+ return true;
+ }
+
+}
Added:
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/profiles/ActiveProfilesLabelProvider.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/profiles/ActiveProfilesLabelProvider.java
(rev 0)
+++
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/profiles/ActiveProfilesLabelProvider.java 2011-07-18
13:15:17 UTC (rev 33011)
@@ -0,0 +1,56 @@
+/*************************************************************************************
+ * Copyright (c) 2009-2011 Red Hat, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.jboss.tools.maven.ui.internal.profiles;
+
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.swt.graphics.Image;
+
+public class ActiveProfilesLabelProvider implements ILabelProvider {
+
+ //public static ImageDescriptor icon =
Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID,
"icons/maven-profiles.png");
+
+ public Image image = null;
+
+ public ActiveProfilesLabelProvider() {
+ //image = icon.createImage();
+ }
+
+ public void addListener(ILabelProviderListener listener) {
+ }
+
+ public void dispose() {
+ if (image != null) {
+ image.dispose();
+ }
+ }
+
+ public boolean isLabelProperty(Object element, String property) {
+ return true;
+ }
+
+ public void removeListener(ILabelProviderListener listener) {
+ }
+
+ public Image getImage(Object element) {
+ return image;
+ }
+
+ public String getText(Object element) {
+ if(element instanceof ActiveMavenProfilesNode) {
+ return ((ActiveMavenProfilesNode)element).getLabel(null);
+ } else if (element instanceof String) {
+ return element.toString();
+ }
+ return null;
+ }
+
+}
Added:
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/profiles/ProfileSelection.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/profiles/ProfileSelection.java
(rev 0)
+++
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/profiles/ProfileSelection.java 2011-07-18
13:15:17 UTC (rev 33011)
@@ -0,0 +1,51 @@
+/*************************************************************************************
+ * Copyright (c) 2009-2011 Red Hat, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.jboss.tools.maven.ui.internal.profiles;
+
+import org.jboss.tools.maven.core.profiles.ProfileState;
+
+public class ProfileSelection {
+ private String id;
+ private Boolean autoActive;
+ private Boolean selected;
+ private ProfileState activationState;
+ private String source;
+ public String getId() {
+ return id;
+ }
+ public void setId(String id) {
+ this.id = id;
+ }
+ public Boolean getAutoActive() {
+ return autoActive;
+ }
+ public void setAutoActive(Boolean autoActive) {
+ this.autoActive = autoActive;
+ }
+ public Boolean getSelected() {
+ return selected;
+ }
+ public void setSelected(Boolean selected) {
+ this.selected = selected;
+ }
+ public ProfileState getActivationState() {
+ return activationState;
+ }
+ public void setActivationState(ProfileState activationState) {
+ this.activationState = activationState;
+ }
+ public String getSource() {
+ return source;
+ }
+ public void setSource(String source) {
+ this.source = source;
+ }
+}
Modified:
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/profiles/ProfileSelectionHandler.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/profiles/ProfileSelectionHandler.java 2011-07-18
12:16:44 UTC (rev 33010)
+++
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/profiles/ProfileSelectionHandler.java 2011-07-18
13:15:17 UTC (rev 33011)
@@ -1,11 +1,23 @@
+/*************************************************************************************
+ * Copyright (c) 2009-2011 Red Hat, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
package org.jboss.tools.maven.ui.internal.profiles;
+import java.util.ArrayList;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import java.util.Set;
-import org.apache.maven.model.Profile;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
@@ -30,6 +42,8 @@
import org.eclipse.ui.handlers.HandlerUtil;
import org.jboss.tools.maven.core.MavenCoreActivator;
import org.jboss.tools.maven.core.profiles.IProfileManager;
+import org.jboss.tools.maven.core.profiles.ProfileState;
+import org.jboss.tools.maven.core.profiles.ProfileStatus;
import org.jboss.tools.maven.ui.Activator;
import org.jboss.tools.maven.ui.Messages;
@@ -49,36 +63,89 @@
System.out.print("Select projects "+facades);
final IProfileManager profileManager =
MavenCoreActivator.getDefault().getProfileManager();
-
- Map<Profile, Boolean> availableProfiles;
- Map<Profile, Boolean> availableSettingsProfiles;
- final IMavenProjectFacade facade = facades.iterator().next();
+ final List<ProfileSelection> sharedProfiles;
+ final Map<IMavenProjectFacade, List<ProfileStatus>> allProfiles;
try {
- availableProfiles = profileManager.getAvailableProfiles(facade);
-
- availableSettingsProfiles = profileManager.getAvailableSettingProfiles();
-
+ allProfiles = getAllProfiles(facades, profileManager);
+ sharedProfiles = getSharedProfiles(allProfiles);
} catch (CoreException e) {
throw new ExecutionException("Unable to open the Maven Profile selection
dialog", e);
}
final SelectProfilesDialog dialog = new SelectProfilesDialog(window.getShell(),
- facade,
- availableProfiles,
- availableSettingsProfiles);
+ facades,
+ sharedProfiles);
if(dialog.open() == Window.OK) {
+
WorkspaceJob job = new WorkspaceJob(Messages.ProfileManager_Updating_maven_profiles)
{
public IStatus runInWorkspace(IProgressMonitor monitor) {
try {
-
- profileManager.updateActiveProfiles(facade, dialog.getSelectedProfiles(),
+
+ for (Map.Entry<IMavenProjectFacade, List<ProfileStatus>> entry :
allProfiles.entrySet()){
+
+ IMavenProjectFacade facade = entry.getKey();
+ List<String> activeProfiles = getActiveProfiles(sharedProfiles,
entry.getValue());
+
+ profileManager.updateActiveProfiles(facade, activeProfiles,
dialog.isOffline(), dialog.isForceUpdate(), monitor);
+ }
} catch (CoreException ex) {
Activator.log(ex);
return ex.getStatus();
}
return Status.OK_STATUS;
}
+
+ private List<String> getActiveProfiles(
+ List<ProfileSelection> sharedProfiles,
+ List<ProfileStatus> availableProfiles) {
+ List<String> ids = new ArrayList<String>();
+
+ for (ProfileStatus st : availableProfiles) {
+ ProfileSelection selection = findSelectedProfile(st.getId(), sharedProfiles);
+ String id = null;
+ boolean isDisabled = false;
+ if (selection == null) {
+ //was not displayed. Use existing value.
+ if (st.isUserSelected()) {
+ id = st.getId();
+ isDisabled = st.getActivationState().equals(ProfileState.Disabled);
+ }
+ } else {
+ if (null == selection.getSelected()) {
+ //Value was displayed but its state is unknown, use previous state
+ if (st.isUserSelected()) {
+ id = st.getId();
+ isDisabled = st.getActivationState().equals(ProfileState.Disabled);
+ }
+ } else {
+ //Value was displayed and is consistent
+ if (Boolean.TRUE.equals(selection.getSelected())) {
+ id = st.getId();
+ isDisabled = st.getActivationState().equals(ProfileState.Disabled);
+ }
+ }
+ }
+
+ if (id != null) {
+ if (isDisabled) {
+ id = "!"+id;
+ }
+ ids.add(id);
+ }
+ }
+ return ids;
+ }
+
+ private ProfileSelection findSelectedProfile(String id,
+ List<ProfileSelection> sharedProfiles) {
+ for (ProfileSelection sel : sharedProfiles) {
+ if (id.equals(sel.getId())) {
+ return sel;
+ }
+ }
+ return null;
+ }
};
job.setRule( MavenPlugin.getProjectConfigurationManager().getRule());
job.schedule();
@@ -87,6 +154,86 @@
return null;
}
+ private List<ProfileSelection> getSharedProfiles(
+ Map<IMavenProjectFacade, List<ProfileStatus>> projectProfilesMap) {
+
+ List<ProfileStatus> currentSelection = null;
+ List<List<ProfileStatus>> projectProfiles = new
ArrayList<List<ProfileStatus>>(projectProfilesMap.values());
+ int smallestSize = Integer.MAX_VALUE;
+ for(List<ProfileStatus> profiles : projectProfiles ){
+ int size = profiles.size();
+ if (size < smallestSize) {
+ smallestSize = size;
+ currentSelection = profiles;
+ }
+ }
+ projectProfiles.remove(currentSelection);
+
+ //Init the smallest profiles selection possible
+ List<ProfileSelection> selection = new ArrayList<ProfileSelection>();
+ for(ProfileStatus p : currentSelection) {
+ ProfileSelection ps = new ProfileSelection();
+ ps.setId(p.getId());
+ ps.setActivationState(p.getActivationState());
+ ps.setAutoActive(p.isAutoActive());
+ ps.setSource(p.getSource());
+ ps.setSelected(p.isUserSelected());
+ selection.add(ps);
+ }
+
+ if (!projectProfiles.isEmpty()) {
+ //Restrict to the common profiles only
+ Iterator<ProfileSelection> ite = selection.iterator();
+
+ while (ite.hasNext()) {
+ ProfileSelection p = ite.next();
+ for (List<ProfileStatus> statuses : projectProfiles) {
+ ProfileStatus s = hasProfile(p.getId(), statuses);
+ if (s == null) {
+ //remove any non-common profile selection
+ ite.remove();
+ break;
+ }
+ //reset non common settings
+ if (p.getAutoActive() != null &&
!p.getAutoActive().equals(s.isAutoActive())) {
+ p.setAutoActive(null);
+ }
+ if (p.getSource() != null && !p.getSource().equals(s.getSource())) {
+ p.setSource(null);
+ }
+ if (p.getSelected() != null && !p.getSelected().equals(s.isUserSelected()))
{
+ p.setSelected(null);
+ }
+ if (p.getActivationState() != null &&
!p.getActivationState().equals(s.getActivationState())){
+ p.setActivationState(null);
+ p.setAutoActive(null);
+ }
+ }
+ }
+ }
+
+ return selection;
+ }
+
+ private ProfileStatus hasProfile(String id, List<ProfileStatus> statuses) {
+ for (ProfileStatus p : statuses){
+ if (id.equals(p.getId())){
+ return p;
+ }
+ }
+ return null;
+ }
+
+ private Map<IMavenProjectFacade, List<ProfileStatus>> getAllProfiles(final
Set<IMavenProjectFacade> facades,
+ final IProfileManager profileManager) throws CoreException {
+ Map<IMavenProjectFacade, List<ProfileStatus>> allProfiles =
+ new HashMap<IMavenProjectFacade, List<ProfileStatus>>(facades.size());
+ for (IMavenProjectFacade facade : facades) {
+ allProfiles.put(facade, profileManager.getProfilesStatuses(facade));
+ }
+ return allProfiles;
+ }
+
/**
* Returns an IMavenProjectFacade from the selected IResource, or from the active editor
* @param event
Added:
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/profiles/ProfileSelectionStatus.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/profiles/ProfileSelectionStatus.java
(rev 0)
+++
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/profiles/ProfileSelectionStatus.java 2011-07-18
13:15:17 UTC (rev 33011)
@@ -0,0 +1,15 @@
+/*************************************************************************************
+ * Copyright (c) 2009-2011 Red Hat, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.jboss.tools.maven.ui.internal.profiles;
+
+public enum ProfileSelectionStatus {
+ Undefined, Inactivated, Activated, Disabled
+}
Modified:
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/profiles/SelectProfilesDialog.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/profiles/SelectProfilesDialog.java 2011-07-18
12:16:44 UTC (rev 33010)
+++
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/profiles/SelectProfilesDialog.java 2011-07-18
13:15:17 UTC (rev 33011)
@@ -1,29 +1,28 @@
-/*******************************************************************************
- * Copyright (c) 2011 Sonatype, Inc.
- * All rights reserved. This program and the accompanying materials
+/*************************************************************************************
+ * Copyright (c) 2009-2011 Red Hat, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
*
http://www.eclipse.org/legal/epl-v10.html
- *
+ *
* Contributors:
- * Sonatype, Inc. - initial API and implementation
- *******************************************************************************/
+ * JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
package org.jboss.tools.maven.ui.internal.profiles;
-import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
+import java.util.Set;
-import org.apache.maven.model.Profile;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.TitleAreaDialog;
+import org.eclipse.jface.viewers.CheckStateChangedEvent;
import org.eclipse.jface.viewers.CheckboxTableViewer;
+import org.eclipse.jface.viewers.ICheckStateListener;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITableColorProvider;
@@ -33,8 +32,6 @@
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.m2e.core.MavenPlugin;
import org.eclipse.m2e.core.project.IMavenProjectFacade;
-import org.eclipse.m2e.core.project.IProjectConfigurationManager;
-import org.eclipse.m2e.core.project.ResolverConfiguration;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
@@ -54,6 +51,7 @@
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
+import org.jboss.tools.maven.core.profiles.ProfileState;
import org.jboss.tools.maven.ui.Messages;
public class SelectProfilesDialog extends TitleAreaDialog implements
@@ -66,41 +64,22 @@
private Button offlineModeBtn;
private Button forceUpdateBtn;
- private final IMavenProjectFacade facade;
-
- private List<Map.Entry<Profile, Boolean>> availableProfiles;
- private List<String> initialInactiveProfileIds = new ArrayList<String>();
- private List<String> initialActiveProfileIds = new ArrayList<String>();
- private List<String> inactiveProfileIds = new ArrayList<String>();
- private List<String> selectedProfiles;
-
private boolean offlineMode ;
private boolean forceUpdate;
- public SelectProfilesDialog(Shell parentShell, IMavenProjectFacade facade,
- Map<Profile, Boolean> availableProjectProfiles,
- Map<Profile, Boolean> availableSettingsProfiles) {
+ List<ProfileSelection> sharedProfiles;
+ Set<IMavenProjectFacade> facades;
+ IMavenProjectFacade facade;
+
+ public SelectProfilesDialog(Shell parentShell, Set<IMavenProjectFacade> facades,
+ List<ProfileSelection> sharedProfiles) {
super(parentShell);
-
- this.facade = facade;
-
- availableProfiles = new ArrayList<Map.Entry<Profile,
Boolean>>(availableProjectProfiles.entrySet());
- availableProfiles.addAll(availableSettingsProfiles.entrySet());
-
offlineMode = MavenPlugin.getMavenConfiguration().isOffline();
-
- final IProjectConfigurationManager configurationManager = MavenPlugin
- .getProjectConfigurationManager();
- final ResolverConfiguration configuration = configurationManager
- .getResolverConfiguration(facade.getProject());
- for (String p : configuration.getActiveProfileList()) {
- if (p.startsWith("!")) { //$NON-NLS-1$
- initialInactiveProfileIds.add(p.substring(1));
- } else {
- initialActiveProfileIds.add(p);
- }
+ this.facades = facades;
+ if(facades.size() == 1){
+ facade = facades.iterator().next();
}
- inactiveProfileIds.addAll(initialInactiveProfileIds);
+ this.sharedProfiles = sharedProfiles;
}
@Override
@@ -127,19 +106,34 @@
container.setLayoutData(new GridData(GridData.FILL_BOTH));
setTitle(Messages.SelectProfilesDialog_Maven_profile_selection);
- setMessage(NLS.bind(
- Messages.SelectProfilesDialog_Select_the_active_Maven_profiles,
- facade.getProject().getName()));
+ String text;
+ if (facade == null) {
+ text = "Select the active profiles for selected projects";
+ } else {
+ text = NLS.bind(
+ Messages.SelectProfilesDialog_Select_the_active_Maven_profiles,
+ facade.getProject().getName());
+ }
+ setMessage(text);
- boolean hasProfiles = !availableProfiles.isEmpty();
+ boolean hasProfiles = !sharedProfiles.isEmpty();
Label lblAvailable = new Label(container, SWT.NONE);
String textLabel;
if (hasProfiles) {
- textLabel = Messages.SelectProfilesDialog_Available_profiles;
+ if (facade == null) {
+ textLabel = "Common profiles for selected projects";
+ } else {
+ textLabel = Messages.SelectProfilesDialog_Available_profiles;
+ }
} else {
- textLabel = Messages.SelectProfilesDialog_Project_has_no_available_profiles;
+ if (facade == null) {
+ textLabel = "There are no common profiles for the selected projects";
+ } else {
+ textLabel =
+ NLS.bind(Messages.SelectProfilesDialog_Project_has_no_available_profiles,
facade.getProject().getName());
+ }
}
- lblAvailable.setText(NLS.bind(textLabel, facade.getProject().getName()));
+ lblAvailable.setText(textLabel);
lblAvailable.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true,
false, 2, 1));
@@ -187,7 +181,22 @@
profileTableViewer.setLabelProvider(new ProfileLabelProvider(parent
.getFont()));
- profileTableViewer.setInput(availableProfiles);
+
+ profileTableViewer.addCheckStateListener(new ICheckStateListener() {
+
+ public void checkStateChanged(CheckStateChangedEvent event) {
+ ProfileSelection profile = (ProfileSelection) event.getElement();
+ if (profileTableViewer.getGrayed(profile)) {
+ profileTableViewer.setGrayed(profile, false);
+ }
+ profile.setSelected(profileTableViewer.getChecked(profile));
+ if (profile.getActivationState() == null) {
+ profile.setActivationState(ProfileState.Active);
+ }
+ }
+ });
+
+ profileTableViewer.setInput(sharedProfiles);
addSelectionButton(container, Messages.SelectProfilesDialog_SelectAll, true);
@@ -220,8 +229,14 @@
button.setText(label);
button.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
- for (Map.Entry<Profile, Boolean> entry : availableProfiles) {
- profileTableViewer.setChecked(entry, ischecked);
+ profileTableViewer.setAllGrayed(false);
+ for (ProfileSelection profile : sharedProfiles) {
+ profileTableViewer.setChecked(profile, ischecked);
+
+ profile.setSelected(profileTableViewer.getChecked(profile));
+ if (profile.getActivationState() == null) {
+ profile.setActivationState(ProfileState.Active);
+ }
}
}
@@ -233,19 +248,6 @@
return button;
}
- @SuppressWarnings("unchecked")
- private Map.Entry<Profile, Boolean> getEntry(Object o) {
- if (o instanceof Map.Entry<?, ?>) {
- return (Map.Entry<Profile, Boolean>) o;
- }
- return null;
- }
-
- private boolean isDeactivated(Entry<Profile, Boolean> entry) {
- return entry != null
- && inactiveProfileIds.contains(entry.getKey().getId());
- }
-
@Override
protected void createButtonsForButtonBar(Composite parent) {
if (profileTableViewer != null) {
@@ -257,20 +259,8 @@
@Override
protected void okPressed() {
if (profileTableViewer != null) {
- Object[] obj = profileTableViewer.getCheckedElements();
- List<String> selectedProfiles = new ArrayList<String>(obj.length);
- for (int i = 0; i < obj.length; i++) {
- @SuppressWarnings("unchecked")
- Map.Entry<Profile, Boolean> entry = (Map.Entry<Profile, Boolean>)
obj[i];
- String id = entry.getKey().getId();
- if (isDeactivated(entry)) {
- selectedProfiles.add("!" + id); //$NON-NLS-1$
- } else {
- selectedProfiles.add(id);
- }
- }
- this.selectedProfiles = selectedProfiles;
-
+ //Object[] obj = profileTableViewer.getCheckedElements();
+ //for (int i = 0; i < obj.length; i++) {}
offlineMode = offlineModeBtn.getSelection();
forceUpdate = forceUpdateBtn.getSelection();
}
@@ -285,11 +275,14 @@
profileTableViewer.getControl().setMenu(contextMenu);
menuMgr.setRemoveAllWhenShown(true);
- for (Map.Entry<Profile, Boolean> entry : availableProfiles) {
- String id = entry.getKey().getId();
- boolean isSelected = initialActiveProfileIds.contains(id)
- || inactiveProfileIds.contains(id);
- profileTableViewer.setChecked(entry, isSelected);
+ for (ProfileSelection p : sharedProfiles) {
+ Boolean selected = p.getSelected();
+ if (selected ==null || p.getActivationState() == null) {
+ profileTableViewer.setGrayed(p, true);
+ profileTableViewer.setChecked(p, true);
+ } else if(selected != null) {
+ profileTableViewer.setChecked(p, selected );
+ }
}
}
@@ -299,44 +292,53 @@
IStructuredSelection selection = (IStructuredSelection) profileTableViewer
.getSelection();
if (!selection.isEmpty()) {
- final Map.Entry<Profile, Boolean> entry =
getEntry(selection.getFirstElement());
- final boolean isDeactivated = isDeactivated(entry);
-
- if (isDeactivated) {
- inactiveProfileIds.remove(entry.getKey().getId());
- } else {
- inactiveProfileIds.add(entry.getKey().getId());
- profileTableViewer.setChecked(entry, true);
- }
+ final ProfileSelection entry = (ProfileSelection) selection.getFirstElement();
+ entry.setActivationState(ProfileState.Active);
+ profileTableViewer.setChecked(entry, true);
+ profileTableViewer.setGrayed(entry, false);
profileTableViewer.refresh();
}
super.run();
}
};
+ final Action deActivationAction = new Action("") { //$NON-NLS-1$
+ @Override
+ public void run() {
+ IStructuredSelection selection = (IStructuredSelection) profileTableViewer
+ .getSelection();
+ if (!selection.isEmpty()) {
+ final ProfileSelection entry = (ProfileSelection) selection.getFirstElement();
+ entry.setActivationState(ProfileState.Disabled);
+ profileTableViewer.setChecked(entry, true);
+ profileTableViewer.setGrayed(entry, false);
+ profileTableViewer.refresh();
+ }
+ super.run();
+ }
+ };
+
public void menuAboutToShow(IMenuManager manager) {
IStructuredSelection selection = (IStructuredSelection) profileTableViewer
.getSelection();
if (!selection.isEmpty()) {
- final Map.Entry<Profile, Boolean> entry = getEntry(selection
- .getFirstElement());
- final boolean isDeactivated = isDeactivated(entry);
- String text;
- if (isDeactivated) {
+ final ProfileSelection entry = (ProfileSelection) selection.getFirstElement();
+ String text = "";
+ ProfileState state = entry.getActivationState();
+ if ( state == null || state.equals(ProfileState.Disabled)) {
text = Messages.SelectProfilesDialog_Activate_menu;
- } else {
+ activationAction.setText(NLS.bind(text, entry.getId()));
+ manager.add(activationAction);
+ }
+ if( !ProfileState.Disabled.equals(state)) {
text = Messages.SelectProfilesDialog_Deactivate_menu;
+ deActivationAction.setText(NLS.bind(text, entry.getId()));
+ manager.add(deActivationAction);
}
- activationAction.setText(NLS.bind(text, entry.getKey().getId()));
- manager.add(activationAction);
}
}
- public List<String> getSelectedProfiles() {
- return selectedProfiles;
- }
-
public boolean isOffline() {
return offlineMode;
}
@@ -362,9 +364,9 @@
}
public Font getFont(Object element, int columnIndex) {
- Entry<Profile, Boolean> entry = getEntry(element);
+ ProfileSelection entry = (ProfileSelection) element;
Font font = null;
- if (entry != null && Boolean.TRUE.equals(entry.getValue())
+ if (Boolean.TRUE.equals(entry.getAutoActive())
&& PROFILE_ID_COLUMN == columnIndex) {
font = implicitActivationFont;
}
@@ -372,8 +374,8 @@
}
public Color getForeground(Object element, int columnIndex) {
- Entry<Profile, Boolean> entry = getEntry(element);
- if (isDeactivated(entry)) {
+ ProfileSelection entry = (ProfileSelection) element;
+ if (ProfileState.Disabled.equals(entry.getActivationState())) {
return inactiveColor;
}
return null;
@@ -388,20 +390,20 @@
}
public String getColumnText(Object element, int columnIndex) {
- Entry<Profile, Boolean> entry = getEntry(element);
+ ProfileSelection entry = (ProfileSelection) element;
StringBuilder text = new StringBuilder();
if (entry != null) {
- boolean isDeactivated = isDeactivated(entry);
- Profile profile = entry.getKey();
if (columnIndex == PROFILE_ID_COLUMN) {
- text.append(profile.getId());
- if (isDeactivated) {
+ text.append(entry.getId());
+
+ ProfileState state = entry.getActivationState();
+ if (state == ProfileState.Disabled) {
text.append(Messages.SelectProfilesDialog_deactivated);
- } else if (Boolean.TRUE.equals(entry.getValue())) {
+ } else if (Boolean.TRUE.equals(entry.getAutoActive())) {
text.append(Messages.SelectProfilesDialog_autoactivated);
}
} else if (columnIndex == SOURCE_COLUMN) {
- text.append(profile.getSource());
+ text.append(entry.getSource());
}
}
return text.toString();