Author: fbricon
Date: 2011-07-09 11:53:19 -0400 (Sat, 09 Jul 2011)
New Revision: 32782
Added:
trunk/maven/plugins/org.jboss.tools.maven.ui/icons/
trunk/maven/plugins/org.jboss.tools.maven.ui/icons/maven-profiles.gif
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/profiles/
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/profiles/IProfileManager.java
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/profiles/ProfileManager.java
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/handlers/
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/profiles/handlers/ProfileSelectionHandler.java
Modified:
trunk/maven/plugins/org.jboss.tools.maven.ui/META-INF/MANIFEST.MF
trunk/maven/plugins/org.jboss.tools.maven.ui/build.properties
trunk/maven/plugins/org.jboss.tools.maven.ui/plugin.xml
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/Messages.java
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/messages.properties
Log:
JBIDE-8969 : added a dialog window to select maven profiles. For some reason I can't
add the corresponding command to the maven menu. The dialog is currently accessed via the
toolbar (Maven Profile button) or using the shortcut Ctrl+Shift+P. Cascading profile
update to sub modules not implemented. Needs SWTBot tests too.
Modified: trunk/maven/plugins/org.jboss.tools.maven.ui/META-INF/MANIFEST.MF
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.ui/META-INF/MANIFEST.MF 2011-07-09 00:55:28
UTC (rev 32781)
+++ trunk/maven/plugins/org.jboss.tools.maven.ui/META-INF/MANIFEST.MF 2011-07-09 15:53:19
UTC (rev 32782)
@@ -11,7 +11,9 @@
org.eclipse.jst.common.project.facet.ui,
org.eclipse.wst.common.frameworks.ui,
org.eclipse.core.resources,
- org.jboss.tools.maven.core
+ org.jboss.tools.maven.core,
+ org.eclipse.m2e.core.ui;bundle-version="[1.0.0,1.1.0)",
+ org.eclipse.ui.ide
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-Vendor: %Bundle-Vendor
Modified: trunk/maven/plugins/org.jboss.tools.maven.ui/build.properties
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.ui/build.properties 2011-07-09 00:55:28 UTC
(rev 32781)
+++ trunk/maven/plugins/org.jboss.tools.maven.ui/build.properties 2011-07-09 15:53:19 UTC
(rev 32782)
@@ -8,4 +8,5 @@
about.mappings,\
about.ini,\
about.html,\
- plugin.properties
+ plugin.properties,\
+ icons/
Added: trunk/maven/plugins/org.jboss.tools.maven.ui/icons/maven-profiles.gif
===================================================================
(Binary files differ)
Property changes on:
trunk/maven/plugins/org.jboss.tools.maven.ui/icons/maven-profiles.gif
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Modified: trunk/maven/plugins/org.jboss.tools.maven.ui/plugin.xml
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.ui/plugin.xml 2011-07-09 00:55:28 UTC (rev
32781)
+++ trunk/maven/plugins/org.jboss.tools.maven.ui/plugin.xml 2011-07-09 15:53:19 UTC (rev
32782)
@@ -11,7 +11,7 @@
<extension
point="org.eclipse.jst.common.project.facet.ui.libraryProviderActionPanels">
<panel
- provider="maven-library-provider"
+ provider="mapass-library-provider"
class="org.jboss.tools.maven.ui.internal.libprov.MavenUserLibraryProviderInstallPanel"/>
</extension>
@@ -29,4 +29,84 @@
<initializer
class="org.jboss.tools.maven.ui.preferences.ConfiguratorPreferencesInitializer"/>
</extension>
+ <!-- Maven Profile Selection-->
+ <extension
+ point="org.eclipse.ui.commands">
+ <category
+ id="org.jboss.tools.maven.ui.commands.profiles"
+ name="Maven Profiles">
+ </category>
+ <command
+ categoryId="org.jboss.tools.maven.ui.commands.profiles"
+ id="org.jboss.tools.maven.ui.commands.selectMavenProfileCommand"
+ name="Select Maven Profiles">
+ </command>
+ </extension>
+
+ <extension
+ point="org.eclipse.ui.handlers">
+ <handler
+
class="org.jboss.tools.maven.ui.internal.profiles.handlers.ProfileSelectionHandler"
+
commandId="org.jboss.tools.maven.ui.commands.selectMavenProfileCommand">
+ </handler>
+ </extension>
+ <extension
+ point="org.eclipse.ui.bindings">
+ <key
+
commandId="org.jboss.tools.maven.ui.commands.selectMavenProfileCommand"
+ contextId="org.eclipse.ui.contexts.window"
+ schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
+ sequence="Ctrl+Shift+P">
+ </key>
+ </extension>
+
+ <!--FIXME I can't make the menu appear in the maven menu-->
+ <extension
+ point="org.eclipse.ui.menus">
+ <menuContribution
locationURI="popup:org.eclipse.m2e.core.mavenMenu?after=update"
allPopups="true">
+ <!--menuContribution locationURI="popup:common.new.menu?after=new"
allPopups="true" -->
+ <command
+
commandId="org.jboss.tools.maven.ui.commands.selectMavenProfileCommand"
+ id="org.jboss.tools.maven.ui.menus.selectMavenProfileCommand"
+ mnemonic="P">
+
+ <!--reference
+ definitionId="org.jboss.tools.maven.ui.mavenProject">
+ </reference-->
+
+ </command>
+ </menuContribution>
+ </extension>
+
+ <extension
+ point="org.eclipse.ui.menus">
+ <menuContribution
+
locationURI="toolbar:org.eclipse.ui.main.toolbar?after=additions">
+ <toolbar
+
id="org.jboss.tools.maven.ui.toolbars.selectMavenProfilesToolbar">
+ <command
+
commandId="org.jboss.tools.maven.ui.commands.selectMavenProfileCommand"
+ icon="icons/maven-profiles.gif"
+
id="org.jboss.tools.maven.ui.toolbars.selectMavenProfilesCommand"
+ tooltip="Select Maven Profiles">
+ </command>
+ </toolbar>
+ </menuContribution>
+ </extension>
+
+ <extension
+ point="org.eclipse.core.expressions.definitions">
+ <definition id="org.jboss.tools.maven.ui.mavenProject">
+ <with variable="selection">
+ <iterate ifEmpty="false" operator="or">
+ <adapt type="org.eclipse.core.resources.IProject">
+ <and>
+ <objectState name="open" value="true"/>
+ <objectState name="nature"
value="org.eclipse.m2e.core.maven2Nature"/>
+ </and>
+ </adapt>
+ </iterate>
+ </with>
+ </definition>
+ </extension>
</plugin>
Modified:
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/Messages.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/Messages.java 2011-07-09
00:55:28 UTC (rev 32781)
+++
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/Messages.java 2011-07-09
15:53:19 UTC (rev 32782)
@@ -54,7 +54,22 @@
public static String ConfiguratorPreferencePage_Configure_Seam_Runtime;
public static String
ConfiguratorPreferencePage_Configure_Seam_when_importing_Maven_projects;
public static String
ConfiguratorPreferencePage_When_importing_Maven_projects_configure_the_following;
+ public static String ProfileManager_Updating_maven_profiles;
+ public static String SelectProfilesDialog_autoactivated;
+ public static String SelectProfilesDialog_Activate_menu;
+ public static String SelectProfilesDialog_Available_profiles;
+ public static String SelectProfilesDialog_deactivated;
+ public static String SelectProfilesDialog_Deactivate_menu;
+ public static String SelectProfilesDialog_DeselectAll;
+ public static String SelectProfilesDialog_Force_update;
+ public static String SelectProfilesDialog_Maven_profile_selection;
+ public static String SelectProfilesDialog_Offline;
+ public static String SelectProfilesDialog_Project_has_no_available_profiles;
+ public static String SelectProfilesDialog_Select_Maven_profiles;
+ public static String SelectProfilesDialog_Select_the_active_Maven_profiles;
+ public static String SelectProfilesDialog_SelectAll;
+
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
Added:
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/profiles/IProfileManager.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/profiles/IProfileManager.java
(rev 0)
+++
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/profiles/IProfileManager.java 2011-07-09
15:53:19 UTC (rev 32782)
@@ -0,0 +1,19 @@
+package org.jboss.tools.maven.ui.internal.profiles;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.maven.model.Profile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.m2e.core.project.IMavenProjectFacade;
+
+public interface IProfileManager {
+
+ Map<Profile, Boolean> getAvailableProfiles(IMavenProjectFacade project) throws
CoreException;
+
+ Map<Profile, Boolean> getAvailableSettingProfiles() throws CoreException;
+
+ void updateActiveProfiles(IMavenProjectFacade mavenProjectFacade,
+ List<String> profiles, boolean isOffline, boolean isForceUpdate)
+ throws CoreException;
+}
Added:
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/profiles/ProfileManager.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/profiles/ProfileManager.java
(rev 0)
+++
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/profiles/ProfileManager.java 2011-07-09
15:53:19 UTC (rev 32782)
@@ -0,0 +1,136 @@
+package org.jboss.tools.maven.ui.internal.profiles;
+
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.maven.model.Profile;
+import org.apache.maven.settings.Settings;
+import org.apache.maven.settings.SettingsUtils;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.WorkspaceJob;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+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.MavenUpdateRequest;
+import org.eclipse.m2e.core.project.ResolverConfiguration;
+import org.jboss.tools.maven.ui.Messages;
+
+public class ProfileManager implements IProfileManager {
+
+ public void updateActiveProfiles(final IMavenProjectFacade mavenProjectFacade,
+ final List<String> profiles,
+ final boolean isOffline,
+ final boolean isForceUpdate) throws CoreException {
+
+ final IProjectConfigurationManager configurationManager =
MavenPlugin.getProjectConfigurationManager();
+ final ResolverConfiguration configuration =configurationManager
+ .getResolverConfiguration(mavenProjectFacade.getProject());
+
+ final String profilesAsString = getAsString(profiles);
+ if (profilesAsString.equals(configuration.getActiveProfiles())) {
+ //Nothing changed
+ return;
+ }
+
+ WorkspaceJob job = new WorkspaceJob(Messages.ProfileManager_Updating_maven_profiles) {
+
+ public IStatus runInWorkspace(IProgressMonitor monitor) {
+ try {
+
+ IProject project = mavenProjectFacade.getProject();
+
+ configuration.setActiveProfiles(profilesAsString);
+ boolean isSet = configurationManager.setResolverConfiguration(project,
configuration);
+ if (isSet) {
+ MavenUpdateRequest request = new MavenUpdateRequest(project, isOffline,
isForceUpdate);
+ configurationManager.updateProjectConfiguration(request, monitor);
+ }
+
+ } catch (CoreException ex) {
+ return ex.getStatus();
+ }
+ return Status.OK_STATUS;
+ }
+ };
+ job.setRule(configurationManager.getRule());
+ job.schedule();
+ }
+
+ private String getAsString(List<String> profiles) {
+ StringBuilder sb = new StringBuilder();
+ boolean addComma = false;
+ if (profiles != null){
+ for (String p : profiles) {
+ if (addComma) {
+ sb.append(", "); //$NON-NLS-1$
+ }
+ sb.append(p);
+ addComma = true;
+ }
+ }
+ return sb.toString();
+ }
+
+ public Map<Profile, Boolean> getAvailableProfiles(IMavenProjectFacade facade)
throws CoreException {
+ if (facade == null) {
+ return Collections.emptyMap();
+ }
+ List<Profile> modelProfiles = facade.getMavenProject().getModel().getProfiles();
+ if (modelProfiles == null || modelProfiles.isEmpty()) {
+ return Collections.emptyMap();
+ }
+
+ ResolverConfiguration resolverConfiguration =
MavenPlugin.getProjectConfigurationManager()
+ .getResolverConfiguration(facade.getProject());
+
+ Map<Profile, Boolean> projectProfiles = new LinkedHashMap<Profile,
Boolean>(modelProfiles.size());
+ List<Profile> activeProfiles = facade.getMavenProject().getActiveProfiles();
+
+ for (Profile p : modelProfiles) {
+ boolean isAutomaticallyActivated = isActive(p, activeProfiles)
+ && !resolverConfiguration.getActiveProfileList().contains(p.getId());
+ projectProfiles.put(p, isAutomaticallyActivated);
+ }
+ System.err.println(projectProfiles);
+ return Collections.unmodifiableMap(projectProfiles);
+ }
+
+
+ public Map<Profile, Boolean> getAvailableSettingProfiles() throws CoreException {
+ Map<Profile, Boolean> settingsProfiles = new LinkedHashMap<Profile,
Boolean>();
+ Settings settings = MavenPlugin.getMaven().getSettings();
+ List<String> activeProfiles = settings.getActiveProfiles();
+
+ for (org.apache.maven.settings.Profile sp : settings.getProfiles()) {
+ Profile p = SettingsUtils.convertFromSettingsProfile(sp);
+ boolean isAutomaticallyActivated = isActive2(p, activeProfiles);
+ settingsProfiles.put(p, isAutomaticallyActivated);
+ }
+ return Collections.unmodifiableMap(settingsProfiles);
+ }
+
+ private boolean isActive(Profile p, List<Profile> activeProfiles) {
+ for (Profile activeProfile : activeProfiles) {
+ if (activeProfile.getId().equals(p.getId())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private boolean isActive2(Profile p, List<String> activeProfiles) {
+ for (String activeProfile : activeProfiles) {
+ if (activeProfile.equals(p.getId())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+}
Added:
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
(rev 0)
+++
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/profiles/SelectProfilesDialog.java 2011-07-09
15:53:19 UTC (rev 32782)
@@ -0,0 +1,383 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Sonatype, Inc.
+ * 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
+ *******************************************************************************/
+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 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.CheckboxTableViewer;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITableColorProvider;
+import org.eclipse.jface.viewers.ITableFontProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+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.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.FontData;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.Shell;
+import org.jboss.tools.maven.ui.Messages;
+
+public class SelectProfilesDialog extends TitleAreaDialog implements IMenuListener {
+
+ private CheckboxTableViewer profileTableViewer;
+
+ 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) {
+ super(parentShell);
+ this.facade = facade;
+
+ availableProfiles = new
ArrayList<Map.Entry<Profile,Boolean>>(availableProjectProfiles.entrySet());
+ availableProfiles.addAll(availableSettingsProfiles.entrySet());
+
+ offlineMode = MavenPlugin.getMavenConfiguration().isOffline();
+ forceUpdate = false;
+
+ 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);
+ }
+ }
+ inactiveProfileIds.addAll(initialInactiveProfileIds);
+ }
+
+ @Override
+ protected void configureShell(Shell shell) {
+ super.configureShell(shell);
+ shell.setText(Messages.SelectProfilesDialog_Select_Maven_profiles);
+ }
+
+ /**
+ * Create contents of the dialog.
+ * @param parent
+ */
+ @Override
+ @SuppressWarnings("rawtypes")
+ protected Control createDialogArea(Composite parent) {
+ Composite area = (Composite) super.createDialogArea(parent);
+ Composite container = new Composite(area, SWT.NONE);
+
+ GridLayout layout = new GridLayout(2, false);
+ layout.marginLeft = 12;
+ container.setLayout(layout);
+ container.setLayoutData(new GridData(GridData.FILL_BOTH));
+
+ setTitle(Messages.SelectProfilesDialog_Maven_profile_selection);
+
setMessage(Messages.SelectProfilesDialog_Select_the_active_Maven_profiles+facade.getProject().getName());
+
+ boolean hasProfiles = !availableProfiles.isEmpty();
+ Label lblAvailable = new Label(container, SWT.NONE);
+ if (hasProfiles) {
+ lblAvailable.setText(Messages.SelectProfilesDialog_Available_profiles);
+ } else {
+
lblAvailable.setText(Messages.SelectProfilesDialog_Project_has_no_available_profiles+facade.getProject().getName()
+"' has no available profiles"); //$NON-NLS-2$
+ }
+ lblAvailable.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 2, 1));
+
+ if (hasProfiles) {
+ profileTableViewer = CheckboxTableViewer.newCheckList(container, SWT.BORDER);
+ profileTableViewer.setContentProvider(new IStructuredContentProvider() {
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ // nothing to do
+ }
+
+ public void dispose() {
+ // nothing to do
+ }
+
+ public Object[] getElements(Object input) {
+ if(input instanceof Collection) {
+ return ((Collection) input).toArray();
+ }
+ return null;
+ }
+ });
+
+ profileTableViewer.setLabelProvider(new ProfileLabelProvider(this));
+
+ profileTableViewer.setInput(availableProfiles);
+
+ GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 4);
+ gd.heightHint = 200;
+ gd.widthHint = 200;
+ profileTableViewer.getTable().setLayoutData(gd);
+
+ Button selectAllBtn = new Button(container, SWT.NONE);
+ selectAllBtn.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1,
1));
+ selectAllBtn.setText(Messages.SelectProfilesDialog_SelectAll);
+ selectAllBtn.addSelectionListener(new SelectionListener() {
+ public void widgetSelected(SelectionEvent e) {
+ for(Map.Entry<Profile, Boolean> entry: availableProfiles) {
+ profileTableViewer.setChecked(entry, true);
+ }
+ }
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+
+ }
+ });
+
+ Button deselectAllBtn = new Button(container, SWT.NONE);
+ deselectAllBtn.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false, 1,
1));
+ deselectAllBtn.setText(Messages.SelectProfilesDialog_DeselectAll);
+ deselectAllBtn.addSelectionListener(new SelectionListener() {
+ public void widgetSelected(SelectionEvent e) {
+ for(Map.Entry<Profile, Boolean> entry: availableProfiles) {
+ profileTableViewer.setChecked(entry, false);
+ }
+ }
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+
+ }
+ });
+
+ offlineModeBtn = new Button(container, SWT.CHECK);
+ offlineModeBtn.setText(Messages.SelectProfilesDialog_Offline);
+ offlineModeBtn.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 2,
1));
+ offlineModeBtn.setSelection(offlineMode);
+
+ forceUpdateBtn = new Button(container, SWT.CHECK);
+ forceUpdateBtn.setText(Messages.SelectProfilesDialog_Force_update);
+ forceUpdateBtn.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 2,
1));
+ forceUpdateBtn.setSelection(forceUpdate);
+
+ createMenu();
+
+ }
+
+ return area;
+ }
+
+
+ private class ProfileLabelProvider extends LabelProvider implements ITableFontProvider,
ITableColorProvider{
+
+ private final SelectProfilesDialog selectProfilesDialog;
+
+ private Font implicitActivationFont;
+
+ private Color inactiveColor;
+
+ public ProfileLabelProvider(SelectProfilesDialog selectProfilesDialog) {
+ this.selectProfilesDialog = selectProfilesDialog;
+
+ Font defaultFont = selectProfilesDialog.profileTableViewer.getTable().getFont();
+ FontData[] fds = defaultFont.getFontData();
+ for(FontData fd : fds) {
+ fd.setStyle(SWT.ITALIC);
+ }
+ implicitActivationFont = new Font(defaultFont.getDevice(), fds);
+ inactiveColor = Display.getCurrent().getSystemColor(SWT.COLOR_GRAY);
+ }
+
+ public String getText(Object element) {
+ Entry<Profile, Boolean> entry = getEntry(element);
+ StringBuilder text = new StringBuilder();
+ if (entry!= null) {
+ boolean isDeactivated = isDeactivated(entry);
+ Profile profile = entry.getKey();
+ text.append(profile.getId());
+ if (isDeactivated) {
+ text.append(Messages.SelectProfilesDialog_deactivated);
+ } else if (Boolean.TRUE.equals(entry.getValue())) {
+ text.append(Messages.SelectProfilesDialog_autoactivated);
+ }
+ }
+ return text.toString();
+ }
+
+
+
+ public Font getFont(Object element, int columnIndex) {
+ Entry<Profile, Boolean> entry = getEntry(element);
+ Font font = null;
+ if (entry!=null && Boolean.TRUE.equals(entry.getValue())) {
+ font = implicitActivationFont;
+ }
+ return font;
+ }
+
+ public Color getForeground(Object element, int columnIndex) {
+ Entry<Profile, Boolean> entry = getEntry(element);
+ if (isDeactivated(entry)) {
+ return inactiveColor;
+ }
+ return null;
+ }
+
+ public Color getBackground(Object element, int columnIndex) {
+ return null;
+ }
+
+ }
+
+ 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());
+ }
+
+ /**
+ * Create contents of the button bar.
+ * @param parent
+ */
+ @Override
+ protected void createButtonsForButtonBar(Composite parent) {
+ if (profileTableViewer != null) {
+ createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
+ }
+ createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL,
false);
+ }
+
+ 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++ ) {
+ 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;
+
+ offlineMode = offlineModeBtn.getSelection();
+ forceUpdate = forceUpdateBtn.getSelection();
+ }
+ super.okPressed();
+ }
+
+ public List<String> getSelectedProfiles() {
+ return selectedProfiles;
+ }
+
+ public boolean isOffline() {
+ return offlineMode;
+ }
+
+ public boolean isForceUpdate() {
+ return forceUpdate;
+ }
+
+ private void createMenu() {
+ MenuManager menuMgr = new MenuManager();
+ Menu contextMenu = menuMgr.createContextMenu(profileTableViewer.getControl());
+ menuMgr.addMenuListener(this);
+ 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);
+ }
+ }
+
+ final Action activationAction = new Action("") { //$NON-NLS-1$
+ @Override
+ public void run() {
+ 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);
+ }
+ profileTableViewer.refresh();
+ }
+ super.run();
+ }
+ };
+
+
+ /* (non-Javadoc)
+ * @see
org.eclipse.jface.action.IMenuListener#menuAboutToShow(org.eclipse.jface.action.IMenuManager)
+ */
+ 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);
+ if (isDeactivated) {
+ activationAction.setText(Messages.SelectProfilesDialog_Activate_menu+
entry.getKey().getId());
+ } else {
+ activationAction.setText(Messages.SelectProfilesDialog_Deactivate_menu+
entry.getKey().getId());
+ }
+ manager.add(activationAction);
+ }
+
+ }
+
+
+
+}
Added:
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/profiles/handlers/ProfileSelectionHandler.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/profiles/handlers/ProfileSelectionHandler.java
(rev 0)
+++
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/profiles/handlers/ProfileSelectionHandler.java 2011-07-09
15:53:19 UTC (rev 32782)
@@ -0,0 +1,103 @@
+package org.jboss.tools.maven.ui.internal.profiles.handlers;
+
+import java.util.Map;
+
+import org.apache.maven.model.Profile;
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.window.Window;
+import org.eclipse.m2e.core.MavenPlugin;
+import org.eclipse.m2e.core.internal.IMavenConstants;
+import org.eclipse.m2e.core.project.IMavenProjectFacade;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.jboss.tools.maven.ui.internal.profiles.IProfileManager;
+import org.jboss.tools.maven.ui.internal.profiles.ProfileManager;
+import org.jboss.tools.maven.ui.internal.profiles.SelectProfilesDialog;
+
+/**
+ * Our sample handler extends AbstractHandler, an IHandler base class.
+ * @see org.eclipse.core.commands.IHandler
+ * @see org.eclipse.core.commands.AbstractHandler
+ */
+public class ProfileSelectionHandler extends AbstractHandler {
+
+ /**
+ * the command has been executed, so extract extract the needed information
+ * from the application context.
+ */
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
+ IMavenProjectFacade facade = getSelectedMavenProject(event);
+ if (facade != null) {
+
+ IProfileManager profileManager = new ProfileManager();
+
+ Map<Profile, Boolean> availableProfiles;
+ Map<Profile, Boolean> availableSettingsProfiles;
+ facade.getMavenProject().getActiveProfiles();
+ try {
+ availableProfiles = profileManager.getAvailableProfiles(facade);
+
+ availableSettingsProfiles = profileManager.getAvailableSettingProfiles();
+
+ } catch (CoreException e) {
+ throw new ExecutionException("Unable to open the Maven Profile selection
dialog", e);
+ }
+ SelectProfilesDialog dialog = new SelectProfilesDialog(window.getShell(),
+ facade,
+ availableProfiles,
+ availableSettingsProfiles);
+ if(dialog.open() == Window.OK) {
+ try {
+ profileManager.updateActiveProfiles(facade, dialog.getSelectedProfiles(),
+ dialog.isOffline(), dialog.isForceUpdate());
+ } catch (CoreException e) {
+ throw new ExecutionException("Unable to update the profiles for
"+facade.getProject().getName(), e);
+ }
+ }
+ }
+ return null;
+ }
+
+ private IMavenProjectFacade getSelectedMavenProject(ExecutionEvent event) {
+ ISelection selection = HandlerUtil.getCurrentSelection(event);
+ IProject project = getSelectedProject(selection);
+ try {
+ if (project == null) {
+ IEditorInput input = HandlerUtil.getActiveEditorInput(event);
+ if(input instanceof IFileEditorInput) {
+ IFileEditorInput fileInput = (IFileEditorInput) input;
+ project = fileInput.getFile().getProject();
+ }
+ }
+ if (project != null && project.hasNature(IMavenConstants.NATURE_ID)) {
+ return MavenPlugin.getMavenProjectRegistry().getProject(project);
+ }
+ } catch (CoreException e) {
+ e.printStackTrace();
+ }
+
+ return null;
+ }
+
+ private IProject getSelectedProject(ISelection selection) {
+ if (selection instanceof IStructuredSelection) {
+ IStructuredSelection structuredSelection = (IStructuredSelection) selection;
+ Object firstElement = structuredSelection.getFirstElement();
+ if (firstElement instanceof IResource) {
+ return ((IResource) firstElement).getProject();
+ }
+ }
+ return null;
+ }
+
+}
Modified:
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/messages.properties
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/messages.properties 2011-07-09
00:55:28 UTC (rev 32781)
+++
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/messages.properties 2011-07-09
15:53:19 UTC (rev 32782)
@@ -34,3 +34,17 @@
ConfiguratorPreferencePage_Configure_Seam_when_importing_Maven_projects=Seam
ConfiguratorPreferencePage_When_importing_Maven_projects_configure_the_following=When
importing Maven projects configure the following:
+ProfileManager_Updating_maven_profiles=Updating maven profiles
+SelectProfilesDialog_Activate_menu=Activate
+SelectProfilesDialog_autoactivated=\ (auto activated)
+SelectProfilesDialog_Available_profiles=Available profiles
+SelectProfilesDialog_Deactivate_menu=Deactivate
+SelectProfilesDialog_deactivated=\ (deactivated)
+SelectProfilesDialog_DeselectAll=Deselect all
+SelectProfilesDialog_Force_update=Force update
+SelectProfilesDialog_Maven_profile_selection=Maven Profile selection
+SelectProfilesDialog_Offline=Offline
+SelectProfilesDialog_Project_has_no_available_profiles=Project '
+SelectProfilesDialog_Select_Maven_profiles=Select Maven profiles
+SelectProfilesDialog_Select_the_active_Maven_profiles=Select the active Maven profiles
for
+SelectProfilesDialog_SelectAll=Select All