Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFred Bricon2014-02-13 07:09:51 -0500
committerGerrit Code Review @ Eclipse.org2014-03-04 12:16:45 -0500
commit11cc8834103f0c654450689dd34520ec9adbbc22 (patch)
tree15071ccc883e0a43a42d1aab35c1cb2c21ae777f /org.eclipse.m2e.profiles.ui
parent8f1095d2e358ddda2002431f1e535d57451cad84 (diff)
downloadm2e-core-11cc8834103f0c654450689dd34520ec9adbbc22.tar.gz
m2e-core-11cc8834103f0c654450689dd34520ec9adbbc22.tar.xz
m2e-core-11cc8834103f0c654450689dd34520ec9adbbc22.zip
428094 : contribute Maven Profile Manager UI
Change-Id: Ib3049263268f33e1d628faa7c99aefde55fe5d9c Signed-off-by: Fred Bricon <fbricon@gmail.com>
Diffstat (limited to 'org.eclipse.m2e.profiles.ui')
-rw-r--r--org.eclipse.m2e.profiles.ui/META-INF/MANIFEST.MF19
-rw-r--r--org.eclipse.m2e.profiles.ui/about.html38
-rw-r--r--org.eclipse.m2e.profiles.ui/build.properties8
-rw-r--r--org.eclipse.m2e.profiles.ui/icons/maven-profiles.gifbin0 -> 251 bytes
-rw-r--r--org.eclipse.m2e.profiles.ui/plugin.properties6
-rw-r--r--org.eclipse.m2e.profiles.ui/plugin.xml93
-rw-r--r--org.eclipse.m2e.profiles.ui/pom.xml17
-rw-r--r--org.eclipse.m2e.profiles.ui/src/org/eclipse/m2e/profiles/ui/internal/MavenProfilesUIActivator.java29
-rw-r--r--org.eclipse.m2e.profiles.ui/src/org/eclipse/m2e/profiles/ui/internal/Messages.java59
-rw-r--r--org.eclipse.m2e.profiles.ui/src/org/eclipse/m2e/profiles/ui/internal/actions/GenericCommandActionDelegate.java248
-rw-r--r--org.eclipse.m2e.profiles.ui/src/org/eclipse/m2e/profiles/ui/internal/actions/ProfileSelectionHandler.java368
-rw-r--r--org.eclipse.m2e.profiles.ui/src/org/eclipse/m2e/profiles/ui/internal/dialog/ProfileSelection.java64
-rw-r--r--org.eclipse.m2e.profiles.ui/src/org/eclipse/m2e/profiles/ui/internal/dialog/ProfileSelectionStatus.java21
-rw-r--r--org.eclipse.m2e.profiles.ui/src/org/eclipse/m2e/profiles/ui/internal/dialog/ProfileUtil.java47
-rw-r--r--org.eclipse.m2e.profiles.ui/src/org/eclipse/m2e/profiles/ui/internal/dialog/SelectProfilesDialog.java502
-rw-r--r--org.eclipse.m2e.profiles.ui/src/org/eclipse/m2e/profiles/ui/internal/messages.properties28
16 files changed, 1547 insertions, 0 deletions
diff --git a/org.eclipse.m2e.profiles.ui/META-INF/MANIFEST.MF b/org.eclipse.m2e.profiles.ui/META-INF/MANIFEST.MF
new file mode 100644
index 00000000..380606a1
--- /dev/null
+++ b/org.eclipse.m2e.profiles.ui/META-INF/MANIFEST.MF
@@ -0,0 +1,19 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %Bundle-Name
+Bundle-SymbolicName: org.eclipse.m2e.profiles.ui;singleton:=true
+Bundle-Version: 1.5.0.qualifier
+Bundle-Localization: plugin
+Bundle-Activator: org.eclipse.m2e.profiles.ui.internal.MavenProfilesUIActivator
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.eclipse.core.resources,
+ org.eclipse.m2e.core.ui;bundle-version="[1.5.0,1.6.0)",
+ org.eclipse.ui.ide,
+ org.eclipse.jface.text,
+ org.eclipse.m2e.profiles.core;bundle-version="[1.5.0,1.6.0)",
+ org.slf4j.api;bundle-version="1.6.2"
+Bundle-ActivationPolicy: lazy
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Bundle-Vendor: %Bundle-Vendor
+Export-Package: org.eclipse.m2e.profiles.ui.internal;x-internal:=true
diff --git a/org.eclipse.m2e.profiles.ui/about.html b/org.eclipse.m2e.profiles.ui/about.html
new file mode 100644
index 00000000..091e5d04
--- /dev/null
+++ b/org.eclipse.m2e.profiles.ui/about.html
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
+<title>Maven Profile Management</title>
+<style type="text/css" media="screen">
+<!--
+ body {
+ font-family: Sans-serif, Arial, Helvetica;
+ }
+
+-->
+</style>
+</head>
+<body>
+<h1>Maven Profile Management</h1>
+
+<h2>About This Content</h2>
+
+<p>October 29, 2010</p>
+<h3>License</h3>
+
+<p>The Eclipse Foundation makes available all content in this plug-in (&quot;Content&quot;). Unless otherwise
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 (&quot;EPL&quot;). A copy of the EPL is available
+at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
+For purposes of the EPL, &quot;Program&quot; will mean the Content.</p>
+
+<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
+being redistributed by another party (&quot;Redistributor&quot;) and different terms and conditions may
+apply to your use of any object code in the Content. Check the Redistributor's license that was
+provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
+indicated below, the terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p>
+
+</body>
+</html>
diff --git a/org.eclipse.m2e.profiles.ui/build.properties b/org.eclipse.m2e.profiles.ui/build.properties
new file mode 100644
index 00000000..0198093c
--- /dev/null
+++ b/org.eclipse.m2e.profiles.ui/build.properties
@@ -0,0 +1,8 @@
+source.. = src/
+output.. = target/classes/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml,\
+ about.html,\
+ plugin.properties,\
+ icons/
diff --git a/org.eclipse.m2e.profiles.ui/icons/maven-profiles.gif b/org.eclipse.m2e.profiles.ui/icons/maven-profiles.gif
new file mode 100644
index 00000000..31f4413f
--- /dev/null
+++ b/org.eclipse.m2e.profiles.ui/icons/maven-profiles.gif
Binary files differ
diff --git a/org.eclipse.m2e.profiles.ui/plugin.properties b/org.eclipse.m2e.profiles.ui/plugin.properties
new file mode 100644
index 00000000..6c1cb0de
--- /dev/null
+++ b/org.eclipse.m2e.profiles.ui/plugin.properties
@@ -0,0 +1,6 @@
+Bundle-Vendor = Eclipse.org - m2e
+Bundle-Name = Maven Profiles Management UI
+
+#Maven Profile selection menu
+Select_Maven_Profiles_Cmd= Select Maven Profiles
+Select_Maven_Profiles_Menu= Select Maven Profiles...
diff --git a/org.eclipse.m2e.profiles.ui/plugin.xml b/org.eclipse.m2e.profiles.ui/plugin.xml
new file mode 100644
index 00000000..62eb934a
--- /dev/null
+++ b/org.eclipse.m2e.profiles.ui/plugin.xml
@@ -0,0 +1,93 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <!-- Maven Profile Selection-->
+ <extension
+ point="org.eclipse.ui.commands">
+ <command
+ categoryId="org.eclipse.ui.category.window"
+ id="org.eclipse.m2e.profiles.ui.commands.selectMavenProfileCommand"
+ name="%Select_Maven_Profiles_Cmd">
+ </command>
+ </extension>
+
+ <extension
+ point="org.eclipse.ui.handlers">
+ <handler
+ class="org.eclipse.m2e.profiles.ui.internal.actions.ProfileSelectionHandler"
+ commandId="org.eclipse.m2e.profiles.ui.commands.selectMavenProfileCommand">
+ </handler>
+ </extension>
+ <extension
+ point="org.eclipse.ui.bindings">
+ <key
+ commandId="org.eclipse.m2e.profiles.ui.commands.selectMavenProfileCommand"
+ contextId="org.eclipse.ui.contexts.window"
+ schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
+ sequence="Ctrl+Alt+P">
+ </key>
+ </extension>
+
+ <extension point="org.eclipse.ui.popupMenus">
+ <objectContribution id="org.eclipse.m2e.profiles.ui.profiles.selectFromProject"
+ objectClass="org.eclipse.core.resources.IProject"
+ adaptable="true">
+ <action id="org.eclipse.m2e.profiles.ui.commands.selectMavenProfileAction"
+ class="org.eclipse.m2e.profiles.ui.internal.actions.GenericCommandActionDelegate:org.eclipse.m2e.profiles.ui.commands.selectMavenProfileCommand"
+ label="%Select_Maven_Profiles_Menu"
+ style="push"
+ definitionId="org.eclipse.m2e.profiles.ui.commands.selectMavenProfileCommand"
+ menubarPath="org.eclipse.m2e.core.mavenMenu/open"
+ enablesFor="+"/>
+ <visibility>
+ <and>
+ <objectState name="open" value="true"/>
+ <objectState name="nature" value="org.eclipse.m2e.core.maven2Nature"/>
+ </and>
+ </visibility>
+ </objectContribution>
+
+ <objectContribution id="org.eclipse.m2e.profiles.ui.profiles.selectFromPom"
+ objectClass="org.eclipse.core.resources.IFile"
+ adaptable="true">
+ <action id="org.eclipse.m2e.profiles.ui.commands.selectMavenProfileAction"
+ class="org.eclipse.m2e.profiles.ui.internal.actions.GenericCommandActionDelegate:org.eclipse.m2e.profiles.ui.commands.selectMavenProfileCommand"
+ label="%Select_Maven_Profiles_Menu"
+ style="push"
+ definitionId="org.eclipse.m2e.profiles.ui.commands.selectMavenProfileCommand"
+ menubarPath="org.eclipse.m2e.core.fileMenu/open"
+ enablesFor="+"/>
+ <visibility>
+ <objectState name="name" value="pom.xml"/>
+ </visibility>
+ </objectContribution>
+
+ <objectContribution id="org.eclipse.m2e.profiles.ui.profiles.selectFromWorkingSet"
+ adaptable="true"
+ objectClass="org.eclipse.ui.IWorkingSet">
+ <action id="org.eclipse.m2e.profiles.ui.commands.selectMavenProfileAction"
+ class="org.eclipse.m2e.profiles.ui.internal.actions.GenericCommandActionDelegate:org.eclipse.m2e.profiles.ui.commands.selectMavenProfileCommand"
+ label="%Select_Maven_Profiles_Menu"
+ style="push"
+ definitionId="org.eclipse.m2e.profiles.ui.commands.selectMavenProfileCommand"
+ menubarPath="org.eclipse.m2e.core.workingSetMenu/open"
+ enablesFor="+"/>
+ </objectContribution>
+
+ </extension>
+ <extension
+ point="org.eclipse.ui.menus">
+ <menuContribution
+ locationURI="toolbar:org.eclipse.ui.main.toolbar?after=additions">
+ <toolbar
+ id="org.eclipse.m2e.profiles.ui.toolbars.selectMavenProfilesToolbar">
+ <command
+ commandId="org.eclipse.m2e.profiles.ui.commands.selectMavenProfileCommand"
+ icon="icons/maven-profiles.gif"
+ id="org.eclipse.m2e.profiles.ui.toolbars.selectMavenProfilesCommand"
+ tooltip="%Select_Maven_Profiles_Cmd">
+ </command>
+ </toolbar>
+ </menuContribution>
+ </extension>
+</plugin>
diff --git a/org.eclipse.m2e.profiles.ui/pom.xml b/org.eclipse.m2e.profiles.ui/pom.xml
new file mode 100644
index 00000000..d4957bdc
--- /dev/null
+++ b/org.eclipse.m2e.profiles.ui/pom.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.eclipse.m2e</groupId>
+ <artifactId>m2e-core</artifactId>
+ <version>1.5.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>org.eclipse.m2e.profiles.ui</artifactId>
+
+ <name>Maven Profile Manager UI</name>
+
+ <packaging>eclipse-plugin</packaging>
+</project> \ No newline at end of file
diff --git a/org.eclipse.m2e.profiles.ui/src/org/eclipse/m2e/profiles/ui/internal/MavenProfilesUIActivator.java b/org.eclipse.m2e.profiles.ui/src/org/eclipse/m2e/profiles/ui/internal/MavenProfilesUIActivator.java
new file mode 100644
index 00000000..73929686
--- /dev/null
+++ b/org.eclipse.m2e.profiles.ui/src/org/eclipse/m2e/profiles/ui/internal/MavenProfilesUIActivator.java
@@ -0,0 +1,29 @@
+/*************************************************************************************
+ * Copyright (c) 2011-2014 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:
+ * Fred Bricon / JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.eclipse.m2e.profiles.ui.internal;
+
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+
+/**
+ * The activator class controls the plug-in life cycle
+ *
+ * @since 1.5.0
+ */
+public class MavenProfilesUIActivator extends AbstractUIPlugin {
+
+ public static final String PLUGIN_ID = "org.eclipse.m2e.profiles.ui";
+
+ /**
+ * The constructor
+ */
+ public MavenProfilesUIActivator() {
+ }
+}
diff --git a/org.eclipse.m2e.profiles.ui/src/org/eclipse/m2e/profiles/ui/internal/Messages.java b/org.eclipse.m2e.profiles.ui/src/org/eclipse/m2e/profiles/ui/internal/Messages.java
new file mode 100644
index 00000000..b64d567d
--- /dev/null
+++ b/org.eclipse.m2e.profiles.ui/src/org/eclipse/m2e/profiles/ui/internal/Messages.java
@@ -0,0 +1,59 @@
+/*************************************************************************************
+ * Copyright (c) 2011-2014 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:
+ * Fred Bricon / JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.eclipse.m2e.profiles.ui.internal;
+
+import org.eclipse.osgi.util.NLS;
+
+/**
+ *
+ * @author Fred Bricon
+ * @since 1.5.0
+ */
+public class Messages extends NLS {
+ private static final String BUNDLE_NAME = "org.eclipse.m2e.profiles.ui.internal.messages"; //$NON-NLS-1$
+
+ public static String ProfileManager_Updating_maven_profiles;
+ public static String ProfileSelectionHandler_Loading_maven_profiles;
+ public static String ProfileSelectionHandler_Maven_Builder_still_processing;
+ public static String ProfileSelectionHandler_multiple_definitions;
+ public static String ProfileSelectionHandler_Select_some_maven_projects;
+ public static String ProfileSelectionHandler_Unable_to_open_profile_dialog;
+ public static String SelectProfilesDialog_autoactivated;
+ public static String SelectProfilesDialog_Activate_menu;
+ public static String SelectProfilesDialog_Active_Profiles_for_Project;
+ public static String SelectProfilesDialog_Available_profiles;
+ public static String SelectProfilesDialog_Warning_Common_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_Move_Down;
+ public static String SelectProfilesDialog_Move_Up;
+ public static String SelectProfilesDialog_No_Common_Profiles;
+ public static String SelectProfilesDialog_Offline;
+ public static String SelectProfilesDialog_Profile_id_header;
+ public static String SelectProfilesDialog_Profile_source_header;
+ public static String SelectProfilesDialog_Project_has_no_available_profiles;
+ public static String SelectProfilesDialog_Read_Only_profiles;
+ public static String SelectProfilesDialog_Select_active_profiles_for_selected_projects;
+ 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);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/org.eclipse.m2e.profiles.ui/src/org/eclipse/m2e/profiles/ui/internal/actions/GenericCommandActionDelegate.java b/org.eclipse.m2e.profiles.ui/src/org/eclipse/m2e/profiles/ui/internal/actions/GenericCommandActionDelegate.java
new file mode 100644
index 00000000..532c64ad
--- /dev/null
+++ b/org.eclipse.m2e.profiles.ui/src/org/eclipse/m2e/profiles/ui/internal/actions/GenericCommandActionDelegate.java
@@ -0,0 +1,248 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM Corporation 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:
+ * IBM Corporation - initial API and implementation
+ * Fred Bricon / Red Hat - minor refactoring
+ *
+ * Original code taken from <a href="http://wiki.eclipse.org/Platform_Command_Framework#Using_an_IActionDelegate_to_execute_a_command">
+ * http://wiki.eclipse.org/Platform_Command_Framework#Using_an_IActionDelegate_to_execute_a_command</a>
+ ******************************************************************************/
+package org.eclipse.m2e.profiles.ui.internal.actions;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.eclipse.core.commands.Command;
+import org.eclipse.core.commands.IParameter;
+import org.eclipse.core.commands.Parameterization;
+import org.eclipse.core.commands.ParameterizedCommand;
+import org.eclipse.core.commands.common.NotDefinedException;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExecutableExtension;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.ui.IEditorActionDelegate;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.IViewActionDelegate;
+import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.IWorkbenchWindowActionDelegate;
+import org.eclipse.ui.commands.ICommandService;
+import org.eclipse.ui.handlers.IHandlerService;
+import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants;
+
+/**
+ * This action delegate can be used to specify a command with or without
+ * parameters be called from an &lt;action/&gt; specified in actionSets,
+ * editorActions, viewActions, or popupMenus.
+ */
+public class GenericCommandActionDelegate implements
+ IWorkbenchWindowActionDelegate, IViewActionDelegate,
+ IEditorActionDelegate, IObjectActionDelegate, IExecutableExtension {
+
+ /**
+ * The commandId parameter needed when using the &lt;class/&gt; form for
+ * this IActionDelegate. Value is "commandId".
+ */
+ public static final String PARM_COMMAND_ID = "commandId"; //$NON-NLS-1$
+
+ private String commandId = null;
+
+ private Map<?, ?> parameterMap = null;
+
+ private ParameterizedCommand parameterizedCommand = null;
+
+ private IHandlerService handlerService = null;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
+ */
+ public void dispose() {
+ handlerService = null;
+ parameterizedCommand = null;
+ parameterMap = null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
+ */
+ public void run(IAction action) {
+ if (handlerService == null) {
+ // what, no handler service ... no problem
+ return;
+ }
+ try {
+ if (commandId != null) {
+ handlerService.executeCommand(commandId, null);
+ } else if (parameterizedCommand != null) {
+ handlerService.executeCommand(parameterizedCommand, null);
+ }
+ // else there is no command for this delegate
+ } catch (Exception e) {
+ // exceptions reduced for brevity
+ // and we won't just do a print out :-)
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction,
+ * org.eclipse.jface.viewers.ISelection)
+ */
+ public void selectionChanged(IAction action, ISelection selection) {
+ // we don't care, handlers get their selection from the
+ // ExecutionEvent application context
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement,
+ * java.lang.String, java.lang.Object)
+ */
+ public void setInitializationData(IConfigurationElement config,
+ String propertyName, Object data) throws CoreException {
+ String id = config.getAttribute(IWorkbenchRegistryConstants.ATT_ID);
+ // save the data until our init(*) call, where we can get
+ // the services.
+ if (data instanceof String) {
+ commandId = (String) data;
+ } else if (data instanceof Map) {
+ parameterMap = (Map<?, ?>) data;
+ if (parameterMap.get(PARM_COMMAND_ID) == null) {
+ Status status = new Status(IStatus.ERROR,
+ "org.jboss.tools.maven.ui.generic", "The '" + id
+ + "' action won't work without a commandId");
+ throw new CoreException(status);
+ }
+ } else {
+ Status status = new Status(
+ IStatus.ERROR,
+ "org.jboss.tools.maven.ui.generic",
+ "The '"
+ + id
+ + "' action won't work without some initialization parameters");
+ throw new CoreException(status);
+ }
+ }
+
+ /**
+ * Build a command from the executable extension information.
+ *
+ * @param commandService
+ * to get the Command object
+ */
+ private void createCommand(ICommandService commandService) {
+ String id = (String) parameterMap.get(PARM_COMMAND_ID);
+ if (id == null) {
+ return;
+ }
+ if (parameterMap.size() == 1) {
+ commandId = id;
+ return;
+ }
+ try {
+ Command cmd = commandService.getCommand(id);
+ if (!cmd.isDefined()) {
+ // command not defined? no problem ...
+ return;
+ }
+ ArrayList<Parameterization> parameters = new ArrayList<Parameterization>();
+ Iterator<?> i = parameterMap.keySet().iterator();
+ while (i.hasNext()) {
+ String parmName = (String) i.next();
+ if (PARM_COMMAND_ID.equals(parmName)) {
+ continue;
+ }
+ IParameter parm = cmd.getParameter(parmName);
+ if (parm == null) {
+ // asking for a bogus parameter? No problem
+ return;
+ }
+ parameters.add(new Parameterization(parm, (String) parameterMap
+ .get(parmName)));
+ }
+ parameterizedCommand = new ParameterizedCommand(cmd,
+ (Parameterization[]) parameters
+ .toArray(new Parameterization[parameters.size()]));
+ } catch (NotDefinedException e) {
+ // command is bogus? No problem, we'll do nothing.
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow)
+ */
+ public void init(IWorkbenchWindow window) {
+ if (handlerService != null) {
+ // already initialized
+ return;
+ }
+
+ handlerService = (IHandlerService) window
+ .getService(IHandlerService.class);
+ if (parameterMap != null) {
+ ICommandService commandService = (ICommandService) window
+ .getService(ICommandService.class);
+ createCommand(commandService);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.IViewActionDelegate#init(org.eclipse.ui.IViewPart)
+ */
+ public void init(IViewPart view) {
+ init(view.getSite().getWorkbenchWindow());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.IEditorActionDelegate#setActiveEditor(org.eclipse.jface.action.IAction,
+ * org.eclipse.ui.IEditorPart)
+ */
+ public void setActiveEditor(IAction action, IEditorPart targetEditor) {
+ // we don't actually care about the active editor, since that
+ // information is in the ExecutionEvent application context
+ // but we need to make sure we're initialized.
+ if (targetEditor != null) {
+ init(targetEditor.getSite().getWorkbenchWindow());
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction,
+ * org.eclipse.ui.IWorkbenchPart)
+ */
+ public void setActivePart(IAction action, IWorkbenchPart targetPart) {
+ // we don't actually care about the active part, since that
+ // information is in the ExecutionEvent application context
+ // but we need to make sure we're initialized.
+ if (targetPart != null) {
+ init(targetPart.getSite().getWorkbenchWindow());
+ }
+ }
+}
+
diff --git a/org.eclipse.m2e.profiles.ui/src/org/eclipse/m2e/profiles/ui/internal/actions/ProfileSelectionHandler.java b/org.eclipse.m2e.profiles.ui/src/org/eclipse/m2e/profiles/ui/internal/actions/ProfileSelectionHandler.java
new file mode 100644
index 00000000..43493c1c
--- /dev/null
+++ b/org.eclipse.m2e.profiles.ui/src/org/eclipse/m2e/profiles/ui/internal/actions/ProfileSelectionHandler.java
@@ -0,0 +1,368 @@
+/*************************************************************************************
+ * Copyright (c) 2011-2014 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:
+ * Fred Bricon / JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.eclipse.m2e.profiles.ui.internal.actions;
+
+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.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.WorkspaceJob;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.SubMonitor;
+import org.eclipse.core.runtime.jobs.IJobChangeEvent;
+import org.eclipse.core.runtime.jobs.IJobChangeListener;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.core.runtime.jobs.JobChangeAdapter;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.m2e.core.MavenPlugin;
+import org.eclipse.m2e.core.internal.IMavenConstants;
+import org.eclipse.m2e.core.project.IMavenProjectFacade;
+import org.eclipse.m2e.core.ui.internal.actions.SelectionUtil;
+import org.eclipse.m2e.profiles.core.internal.IProfileManager;
+import org.eclipse.m2e.profiles.core.internal.MavenProfilesCoreActivator;
+import org.eclipse.m2e.profiles.core.internal.ProfileState;
+import org.eclipse.m2e.profiles.core.internal.ProfileData;
+import org.eclipse.m2e.profiles.ui.internal.MavenProfilesUIActivator;
+import org.eclipse.m2e.profiles.ui.internal.Messages;
+import org.eclipse.m2e.profiles.ui.internal.dialog.ProfileSelection;
+import org.eclipse.m2e.profiles.ui.internal.dialog.SelectProfilesDialog;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.IWorkingSet;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Handles profile selection commands.
+ *
+ * @author Fred Bricon
+ * @since 1.5.0
+ */
+public class ProfileSelectionHandler extends AbstractHandler {
+
+ private static final Logger log = LoggerFactory.getLogger(ProfileSelectionHandler.class);
+
+ /**
+ * Opens the Maven profile selection Dialog window.
+ */
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
+ Set<IMavenProjectFacade> facades = getSelectedMavenProjects(event);
+
+ if (facades.isEmpty()) {
+ display(window, Messages.ProfileSelectionHandler_Select_some_maven_projects);
+ return null;
+ }
+
+ final IProfileManager profileManager = MavenProfilesCoreActivator.getDefault().getProfileManager();
+
+ GetProfilesJob getProfilesJob = new GetProfilesJob(facades, profileManager);
+ getProfilesJob.addJobChangeListener(onProfilesFetched(getProfilesJob, facades, profileManager, window.getShell()));
+ getProfilesJob.setUser(true);
+ getProfilesJob.schedule();
+ return Status.OK_STATUS;
+ }
+
+ private IJobChangeListener onProfilesFetched(final GetProfilesJob getProfilesJob, final Set<IMavenProjectFacade> facades, final IProfileManager profileManager, final Shell shell) {
+ return new JobChangeAdapter() {
+
+ @Override
+ public void done(IJobChangeEvent event) {
+ if (getProfilesJob.getResult().isOK()) {
+ shell.getDisplay().syncExec(new Runnable() {
+
+ public void run() {
+ List<ProfileSelection> sharedProfiles = getProfilesJob.getSharedProfiles();
+ Map<IMavenProjectFacade, List<ProfileData>> allProfiles = getProfilesJob.getAllProfiles();
+ final SelectProfilesDialog dialog = new SelectProfilesDialog(shell,
+ facades,
+ sharedProfiles);
+ if(dialog.open() == Dialog.OK) {
+ Job job = new UpdateProfilesJob(allProfiles, sharedProfiles, profileManager, dialog);
+ job.setRule( MavenPlugin.getProjectConfigurationManager().getRule());
+ job.schedule();
+ }
+ }
+ });
+
+ }
+ }
+ };
+ }
+
+ private void display(IWorkbenchWindow window, String message) {
+ MessageDialog.openInformation(
+ window.getShell(),
+ Messages.SelectProfilesDialog_Select_Maven_profiles,
+ message);
+ }
+
+ /**
+ * Returns an IMavenProjectFacade from the selected IResource, or from the
+ * active editor
+ *
+ * @param event
+ * @return the selected IMavenProjectFacade
+ */
+ private Set<IMavenProjectFacade> getSelectedMavenProjects(ExecutionEvent event) {
+ ISelection selection = HandlerUtil.getCurrentSelection(event);
+ IProject[] projects = SelectionUtil.getProjects(selection, false);
+ Set<IMavenProjectFacade> facades = new HashSet<IMavenProjectFacade>();
+ try {
+ if (projects.length == 0) {
+ IEditorInput input = HandlerUtil.getActiveEditorInput(event);
+ if (input instanceof IFileEditorInput) {
+ IFileEditorInput fileInput = (IFileEditorInput) input;
+ projects = new IProject[] { fileInput.getFile().getProject() };
+ }
+ }
+ IProgressMonitor monitor = new NullProgressMonitor();
+ for (IProject p : projects) {
+ if (p != null && p.isAccessible() && p.hasNature(IMavenConstants.NATURE_ID)) {
+ IFile pom = p.getFile(IMavenConstants.POM_FILE_NAME);
+ IMavenProjectFacade facade = MavenPlugin.getMavenProjectRegistry().create(pom, true, monitor);
+ facades.add(facade);
+ }
+ }
+ } catch (CoreException e) {
+ log.error("Unable to select Maven projects", e);
+ }
+
+ return facades;
+ }
+
+ class GetProfilesJob extends Job {
+
+ private IProfileManager profileManager;
+ private Set<IMavenProjectFacade> facades;
+ private Map<IMavenProjectFacade, List<ProfileData>> allProfiles;
+ private List<ProfileSelection> sharedProfiles;
+
+ private GetProfilesJob(final Set<IMavenProjectFacade> facades, IProfileManager profileManager) {
+ super(Messages.ProfileSelectionHandler_Loading_maven_profiles);
+ this.facades = facades;
+ this.profileManager = profileManager;
+ }
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ try {
+ this.allProfiles = getAllProfiles(facades, profileManager);
+ this.sharedProfiles = getSharedProfiles(allProfiles);
+ } catch (CoreException e) {
+ return new Status(IStatus.ERROR, MavenProfilesUIActivator.PLUGIN_ID,
+ Messages.ProfileSelectionHandler_Unable_to_open_profile_dialog, e);
+ }
+ return Status.OK_STATUS;
+ }
+
+ private List<ProfileSelection> getSharedProfiles(
+ Map<IMavenProjectFacade, List<ProfileData>> projectProfilesMap) {
+
+ List<ProfileData> currentSelection = null;
+ List<List<ProfileData>> projectProfiles = new ArrayList<List<ProfileData>>(projectProfilesMap.values());
+ int smallestSize = Integer.MAX_VALUE;
+ for (List<ProfileData> 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 (ProfileData 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<ProfileData> statuses : projectProfiles) {
+ ProfileData 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(Messages.ProfileSelectionHandler_multiple_definitions);
+ }
+ 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 ProfileData hasProfile(String id, List<ProfileData> statuses) {
+ for (ProfileData p : statuses) {
+ if (id.equals(p.getId())) {
+ return p;
+ }
+ }
+ return null;
+ }
+
+ private Map<IMavenProjectFacade, List<ProfileData>> getAllProfiles(final Set<IMavenProjectFacade> facades,
+ final IProfileManager profileManager) throws CoreException {
+ Map<IMavenProjectFacade, List<ProfileData>> allProfiles =
+ new HashMap<IMavenProjectFacade, List<ProfileData>>(facades.size());
+ IProgressMonitor monitor = new NullProgressMonitor();
+ for (IMavenProjectFacade facade : facades) {
+ allProfiles.put(facade, profileManager.getProfileDatas(facade, monitor));
+ }
+ return allProfiles;
+ }
+
+ public List<ProfileSelection> getSharedProfiles() {
+ return sharedProfiles;
+ }
+
+ public Map<IMavenProjectFacade, List<ProfileData>> getAllProfiles() {
+ return allProfiles;
+ }
+ }
+
+ class UpdateProfilesJob extends WorkspaceJob {
+
+ private Map<IMavenProjectFacade, List<ProfileData>> allProfiles;
+ private List<ProfileSelection> sharedProfiles;
+ private IProfileManager profileManager;
+ private SelectProfilesDialog dialog;
+
+ private UpdateProfilesJob(Map<IMavenProjectFacade, List<ProfileData>> allProfiles,
+ List<ProfileSelection> sharedProfiles, IProfileManager profileManager, SelectProfilesDialog dialog) {
+ super(Messages.ProfileManager_Updating_maven_profiles);
+ this.allProfiles = allProfiles;
+ this.sharedProfiles = sharedProfiles;
+ this.profileManager = profileManager;
+ this.dialog = dialog;
+ }
+
+ public IStatus runInWorkspace(IProgressMonitor monitor) {
+ try {
+ SubMonitor progress = SubMonitor.convert(monitor, Messages.ProfileManager_Updating_maven_profiles, 100);
+ SubMonitor subProgress = SubMonitor.convert(progress.newChild(5), allProfiles.size() * 100);
+ for (Map.Entry<IMavenProjectFacade, List<ProfileData>> entry : allProfiles.entrySet()) {
+ if (progress.isCanceled()) {
+ throw new OperationCanceledException();
+ }
+ IMavenProjectFacade facade = entry.getKey();
+ List<String> activeProfiles = getActiveProfiles(sharedProfiles, entry.getValue());
+
+ profileManager.updateActiveProfiles(facade, activeProfiles,
+ dialog.isOffline(), dialog.isForceUpdate(), subProgress.newChild(100));
+ }
+ } catch (CoreException ex) {
+ log.error("Unable to update Maven profiles", ex);
+ return ex.getStatus();
+ }
+ return Status.OK_STATUS;
+ }
+
+ private List<String> getActiveProfiles(
+ List<ProfileSelection> sharedProfiles,
+ List<ProfileData> availableProfiles) {
+ List<String> ids = new ArrayList<String>();
+
+ for (ProfileData 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 = selection.getId();
+ isDisabled = selection.getActivationState().equals(ProfileState.Disabled);
+ }
+ }
+ }
+
+ if (id != null) {
+ if (isDisabled) {
+ id = "!" + id; //$NON-NLS-1$
+ }
+ 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;
+ }
+ }
+}
diff --git a/org.eclipse.m2e.profiles.ui/src/org/eclipse/m2e/profiles/ui/internal/dialog/ProfileSelection.java b/org.eclipse.m2e.profiles.ui/src/org/eclipse/m2e/profiles/ui/internal/dialog/ProfileSelection.java
new file mode 100644
index 00000000..a6443126
--- /dev/null
+++ b/org.eclipse.m2e.profiles.ui/src/org/eclipse/m2e/profiles/ui/internal/dialog/ProfileSelection.java
@@ -0,0 +1,64 @@
+/*************************************************************************************
+ * Copyright (c) 2011-2014 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:
+ * Fred Bricon / JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.eclipse.m2e.profiles.ui.internal.dialog;
+
+import org.eclipse.m2e.profiles.core.internal.ProfileState;
+
+/* Model of a Maven Profile Selection
+ *
+ * @author Fred Bricon
+ * @since 1.5.0
+ */
+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;
+ }
+
+ public String toMavenString() {
+ String s = id;
+ if (ProfileState.Disabled == activationState) {
+ s = "!"+id;
+ }
+ return s;
+ }
+}
diff --git a/org.eclipse.m2e.profiles.ui/src/org/eclipse/m2e/profiles/ui/internal/dialog/ProfileSelectionStatus.java b/org.eclipse.m2e.profiles.ui/src/org/eclipse/m2e/profiles/ui/internal/dialog/ProfileSelectionStatus.java
new file mode 100644
index 00000000..dafe292d
--- /dev/null
+++ b/org.eclipse.m2e.profiles.ui/src/org/eclipse/m2e/profiles/ui/internal/dialog/ProfileSelectionStatus.java
@@ -0,0 +1,21 @@
+/*************************************************************************************
+ * Copyright (c) 2011-2014 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:
+ * Fred Bricon / JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.eclipse.m2e.profiles.ui.internal.dialog;
+
+/**
+ * Enumeration of all valid Profile selection statuses.
+ *
+ * @author Fred Bricon
+ * @since 1.5.0
+ */
+public enum ProfileSelectionStatus {
+ Undefined, Inactivated, Activated, Disabled
+}
diff --git a/org.eclipse.m2e.profiles.ui/src/org/eclipse/m2e/profiles/ui/internal/dialog/ProfileUtil.java b/org.eclipse.m2e.profiles.ui/src/org/eclipse/m2e/profiles/ui/internal/dialog/ProfileUtil.java
new file mode 100644
index 00000000..12932715
--- /dev/null
+++ b/org.eclipse.m2e.profiles.ui/src/org/eclipse/m2e/profiles/ui/internal/dialog/ProfileUtil.java
@@ -0,0 +1,47 @@
+/*************************************************************************************
+ * Copyright (c) 2011-2014 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.eclipse.m2e.profiles.ui.internal.dialog;
+
+import java.util.Collection;
+
+/**
+ * Utility class to manipulate Profiles
+ *
+ * @author Fred Bricon
+ * @since 1.5.0
+ */
+public class ProfileUtil {
+
+ private ProfileUtil(){}
+
+ private static final String COMMA = ", ";
+
+ /**
+ * Turns a {@link ProfileSelection} collection as a String, joined by a comma separator.
+ */
+ public static String toString(Collection<ProfileSelection> profiles) {
+ StringBuilder sb = new StringBuilder();
+ if(profiles != null && !profiles.isEmpty()) {
+ boolean addComma = false;
+ for (ProfileSelection ps : profiles) {
+ if (ps !=null && Boolean.TRUE.equals(ps.getSelected())) {
+ if (addComma) {
+ sb.append(COMMA);
+ }
+ sb.append(ps.toMavenString());
+ addComma = true;
+ }
+ }
+ }
+ return sb.toString();
+ }
+
+}
diff --git a/org.eclipse.m2e.profiles.ui/src/org/eclipse/m2e/profiles/ui/internal/dialog/SelectProfilesDialog.java b/org.eclipse.m2e.profiles.ui/src/org/eclipse/m2e/profiles/ui/internal/dialog/SelectProfilesDialog.java
new file mode 100644
index 00000000..7c011272
--- /dev/null
+++ b/org.eclipse.m2e.profiles.ui/src/org/eclipse/m2e/profiles/ui/internal/dialog/SelectProfilesDialog.java
@@ -0,0 +1,502 @@
+/*************************************************************************************
+ * Copyright (c) 2011-2014 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:
+ * Fred Bricon / JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.eclipse.m2e.profiles.ui.internal.dialog;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+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.layout.GridDataFactory;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.CheckStateChangedEvent;
+import org.eclipse.jface.viewers.CheckboxTableViewer;
+import org.eclipse.jface.viewers.ICheckStateListener;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITableColorProvider;
+import org.eclipse.jface.viewers.ITableFontProvider;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.m2e.core.MavenPlugin;
+import org.eclipse.m2e.core.project.IMavenProjectFacade;
+import org.eclipse.m2e.profiles.core.internal.ProfileState;
+import org.eclipse.m2e.profiles.ui.internal.Messages;
+import org.eclipse.osgi.util.NLS;
+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.graphics.Image;
+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.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.swt.widgets.Text;
+
+/**
+ * Maven Profile selection dialog.
+ *
+ * @author Fred Bricon
+ * @since 1.5.0
+ */
+@SuppressWarnings("synthetic-access")
+public class SelectProfilesDialog extends TitleAreaDialog implements
+ IMenuListener {
+
+ private static int PROFILE_ID_COLUMN = 0;
+ private static int SOURCE_COLUMN = 1;
+
+ private CheckboxTableViewer profileTableViewer;
+ private Button offlineModeBtn;
+ private Button forceUpdateBtn;
+ private Text profilesText;
+
+ private boolean offlineMode ;
+ private boolean forceUpdate;
+
+ List<ProfileSelection> sharedProfiles;
+ Set<IMavenProjectFacade> facades;
+ IMavenProjectFacade facade;
+
+ final Action activationAction = new ChangeProfileStateAction(ProfileState.Active);
+
+ final Action deActivationAction = new ChangeProfileStateAction(ProfileState.Disabled);
+ private Label warningImg;
+ private Label warningLabel;
+
+ public SelectProfilesDialog(Shell parentShell, Set<IMavenProjectFacade> facades,
+ List<ProfileSelection> sharedProfiles) {
+ super(parentShell);
+ setShellStyle(super.getShellStyle() | SWT.RESIZE | SWT.MODELESS);
+ offlineMode = MavenPlugin.getMavenConfiguration().isOffline();
+ this.facades = facades;
+ if(facades.size() == 1){
+ facade = facades.iterator().next();
+ }
+ this.sharedProfiles = sharedProfiles;
+ }
+
+ @Override
+ protected void configureShell(Shell shell) {
+ super.configureShell(shell);
+ shell.setText(Messages.SelectProfilesDialog_Select_Maven_profiles);
+ }
+
+
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ Composite area = (Composite) super.createDialogArea(parent);
+
+ Composite container = new Composite(area, SWT.NONE);
+ container.setEnabled(true);
+
+ GridLayout layout = new GridLayout(3, false);
+ layout.marginLeft = 12;
+ container.setLayout(layout);
+ container.setLayoutData(new GridData(GridData.FILL_BOTH));
+
+ setTitle(Messages.SelectProfilesDialog_Maven_profile_selection);
+ String text;
+ boolean hasProfiles = !sharedProfiles.isEmpty();
+ if (facade == null) {
+ text = NLS.bind(Messages.SelectProfilesDialog_Select_active_profiles_for_selected_projects,
+ facades.size()
+ );
+ } else {
+ text = NLS.bind(
+ Messages.SelectProfilesDialog_Select_the_active_Maven_profiles,
+ facade.getProject().getName());
+ if (hasProfiles) {
+ displayProfilesAsText(container);
+ }
+ }
+ setMessage(text);
+
+ if (hasProfiles && facade == null) {
+ displayWarning(container);
+ }
+
+ Label lblAvailable = new Label(container, SWT.NONE);
+ lblAvailable.setLayoutData(new GridData(SWT.WRAP, SWT.CENTER, true,
+ false, 2, 1));
+
+ String textLabel = getAvailableText(hasProfiles);
+ lblAvailable.setText(textLabel);
+
+ if (hasProfiles) {
+
+ displayProfilesTable(container);
+
+ addSelectionButton(container, Messages.SelectProfilesDialog_SelectAll, true);
+ addSelectionButton(container, Messages.SelectProfilesDialog_DeselectAll, false);
+ addActivationButton(container, "Activate", ProfileState.Active);
+ addActivationButton(container, "Deactivate", ProfileState.Disabled);
+ offlineModeBtn = addCheckButton(container, Messages.SelectProfilesDialog_Offline, offlineMode);
+ forceUpdateBtn = addCheckButton(container, Messages.SelectProfilesDialog_Force_update, forceUpdate);
+ }
+
+ return area;
+ }
+
+ private void displayWarning(Composite container) {
+ warningImg = new Label(container, SWT.CENTER);
+ warningLabel = new Label(container, SWT.NONE);
+ warningLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1));
+ GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(warningImg);
+ warningImg.setImage(JFaceResources.getImage(DLG_IMG_MESSAGE_WARNING));
+ warningLabel.setText( Messages.SelectProfilesDialog_Warning_Common_profiles);
+ }
+
+ private String getAvailableText(boolean hasProfiles) {
+ String textLabel;
+ if (hasProfiles) {
+ textLabel = Messages.SelectProfilesDialog_Available_profiles;
+ } else {
+ if (facade == null) {
+ textLabel = NLS.bind(Messages.SelectProfilesDialog_No_Common_Profiles,
+ facades.size());
+ } else {
+ textLabel =
+ NLS.bind(Messages.SelectProfilesDialog_Project_has_no_available_profiles,
+ facade.getProject().getName());
+ }
+ }
+ return textLabel;
+ }
+
+ private void displayProfilesTable(Composite container) {
+ GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 4);
+ gd.heightHint = 200;
+ gd.widthHint = 500;
+
+ profileTableViewer = CheckboxTableViewer.newCheckList(container, SWT.BORDER | SWT.MULTI);
+ Table table = profileTableViewer.getTable();
+ table.setFocus();
+ table.setLayoutData(gd);
+ table.setLinesVisible(true);
+ table.setHeaderVisible(true);
+
+ TableColumn profileColumn = new TableColumn(table, SWT.NONE);
+ profileColumn.setText(Messages.SelectProfilesDialog_Profile_id_header);
+ profileColumn.setWidth(350);
+
+ TableColumn sourceColumn = new TableColumn(table, SWT.NONE);
+ sourceColumn.setText(Messages.SelectProfilesDialog_Profile_source_header);
+ sourceColumn.setWidth(120);
+
+
+ profileTableViewer.setContentProvider(ArrayContentProvider.getInstance());
+
+ profileTableViewer.setLabelProvider(new ProfileLabelProvider(container
+ .getFont()));
+
+
+ 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 (Boolean.FALSE.equals(profile.getSelected())
+ || profile.getActivationState() == null) {
+ profile.setActivationState(ProfileState.Active);
+ }
+
+ updateProfilesAsText();
+ profileTableViewer.refresh();
+ }
+ });
+
+ profileTableViewer.setInput(sharedProfiles);
+
+ createMenu();
+ }
+
+ private void displayProfilesAsText(Composite container) {
+ Label profilesLabel = new Label(container, SWT.NONE);
+ profilesLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1));
+ profilesLabel.setText(NLS.bind(Messages.SelectProfilesDialog_Active_Profiles_for_Project,
+ facade.getProject().getName()));
+
+ profilesText = new Text(container, SWT.BORDER);
+ profilesText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
+ profilesText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_DARK_GRAY));
+ profilesText.setEditable(false);
+ profilesText.setToolTipText(Messages.SelectProfilesDialog_Read_Only_profiles);
+
+ updateProfilesAsText();
+ }
+
+ private void updateProfilesAsText() {
+ if (profilesText != null) {
+ profilesText.setText(ProfileUtil.toString(sharedProfiles));
+ }
+ }
+
+ private Button addCheckButton(Composite container, String label, boolean selected) {
+ Button checkBtn = new Button(container, SWT.CHECK);
+ checkBtn.setText(label);
+ checkBtn.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER,
+ true, false, 2, 1));
+ checkBtn.setSelection(selected);
+ return checkBtn;
+ }
+
+ private Button addSelectionButton(Composite container, String label, final boolean ischecked) {
+ Button button = new Button(container, SWT.NONE);
+ button.setLayoutData(new GridData(SWT.FILL, SWT.UP,
+ false, false, 1, 1));
+ button.setText(label);
+ button.addSelectionListener(new SelectionListener() {
+ public void widgetSelected(SelectionEvent e) {
+ profileTableViewer.setAllGrayed(false);
+ for (ProfileSelection profile : sharedProfiles) {
+ profileTableViewer.setChecked(profile, ischecked);
+ profile.setSelected(ischecked);
+ if (!ischecked || profile.getActivationState() == null) {
+ profile.setActivationState(ProfileState.Active);
+ }
+ }
+ refresh();
+ }
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+
+ }
+ });
+
+ return button;
+ }
+
+ private Button addActivationButton(Composite container, String label, final ProfileState state) {
+ Button button = new Button(container, SWT.NONE);
+ button.setLayoutData(new GridData(SWT.FILL, SWT.UP,
+ false, false, 1, 1));
+ button.setText(label);
+ button.addSelectionListener(new SelectionListener() {
+ public void widgetSelected(SelectionEvent e) {
+ ISelection s = profileTableViewer.getSelection();
+ if (s instanceof IStructuredSelection) {
+ IStructuredSelection sel = (IStructuredSelection) s;
+ setActivationState(sel, state);
+ }
+ refresh();
+ }
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+
+ }
+ });
+
+ return button;
+ }
+
+
+ @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);
+ }
+
+ @Override
+ protected void okPressed() {
+ if (profileTableViewer != null) {
+ offlineMode = offlineModeBtn.getSelection();
+ forceUpdate = forceUpdateBtn.getSelection();
+ }
+ super.okPressed();
+ }
+
+ private void createMenu() {
+ MenuManager menuMgr = new MenuManager();
+ Menu contextMenu = menuMgr.createContextMenu(profileTableViewer
+ .getControl());
+ menuMgr.addMenuListener(this);
+ profileTableViewer.getControl().setMenu(contextMenu);
+ menuMgr.setRemoveAllWhenShown(true);
+
+ for (ProfileSelection p : sharedProfiles) {
+ Boolean selected = p.getSelected();
+ if (selected ==null || p.getActivationState() == null) {
+ profileTableViewer.setGrayed(p, true);
+ profileTableViewer.setChecked(p, true);
+ } else {
+ profileTableViewer.setChecked(p, selected );
+ }
+ }
+ }
+
+ public void menuAboutToShow(IMenuManager manager) {
+
+ IStructuredSelection selection = (IStructuredSelection) profileTableViewer
+ .getSelection();
+ if (!selection.isEmpty()) {
+ boolean multiSelection = selection.size() > 1;
+ ProfileState state = null;
+ String selectionText;
+ String text;
+ if (multiSelection) {
+ selectionText = "selected profiles";
+ } else {
+ ProfileSelection entry = (ProfileSelection) selection.getFirstElement();
+ state = entry.getActivationState();
+ selectionText = entry.getId();
+ }
+
+ if ( state == null || ProfileState.Disabled.equals(state)) {
+ text = Messages.SelectProfilesDialog_Activate_menu;
+ activationAction.setText(NLS.bind(text, selectionText));
+ manager.add(activationAction);
+ }
+ if( !ProfileState.Disabled.equals(state)) {
+ text = Messages.SelectProfilesDialog_Deactivate_menu;
+ deActivationAction.setText(NLS.bind(text, selectionText));
+ manager.add(deActivationAction);
+ }
+ }
+ }
+
+ public boolean isOffline() {
+ return offlineMode;
+ }
+
+ public boolean isForceUpdate() {
+ return forceUpdate;
+ }
+
+ private void setActivationState(final IStructuredSelection sel, ProfileState state) {
+ if (sel == null) return;
+ Iterator<?> ite = sel.iterator();
+ while (ite.hasNext()) {
+ Object o = ite.next();
+ if (o instanceof ProfileSelection) {
+ ProfileSelection ps = (ProfileSelection) o;
+ ps.setActivationState(state);
+ profileTableViewer.setGrayed(ps, false);
+ if (ProfileState.Disabled.equals(state)) {
+ profileTableViewer.setChecked(ps, true);
+ ps.setSelected(true);
+ }
+ }
+ }
+ }
+
+
+ private void refresh() {
+ profileTableViewer.refresh();
+ updateProfilesAsText();
+ }
+
+
+ private class ChangeProfileStateAction extends Action {
+
+ private final ProfileState state;
+
+ public ChangeProfileStateAction(ProfileState state) {
+ this.state = state;
+ }
+
+ @Override
+ public void run() {
+ IStructuredSelection selection = (IStructuredSelection) profileTableViewer
+ .getSelection();
+ if (!selection.isEmpty()) {
+ setActivationState(selection, state);
+ refresh();
+ }
+ super.run();
+ }
+ }
+
+ private class ProfileLabelProvider extends LabelProvider implements
+ ITableLabelProvider, ITableFontProvider, ITableColorProvider {
+
+ private Font implicitActivationFont;
+
+ private Color inactiveColor;
+
+ public ProfileLabelProvider(Font defaultFont) {
+ 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 Font getFont(Object element, int columnIndex) {
+ ProfileSelection entry = (ProfileSelection) element;
+ Font font = null;
+ if (Boolean.TRUE.equals(entry.getAutoActive())
+ && PROFILE_ID_COLUMN == columnIndex) {
+ font = implicitActivationFont;
+ }
+ return font;
+ }
+
+ public Color getForeground(Object element, int columnIndex) {
+ ProfileSelection entry = (ProfileSelection) element;
+ if (ProfileState.Disabled.equals(entry.getActivationState())) {
+ return inactiveColor;
+ }
+ return null;
+ }
+
+ public Color getBackground(Object element, int columnIndex) {
+ return null;
+ }
+
+ public Image getColumnImage(Object element, int columnIndex) {
+ return null;
+ }
+
+ public String getColumnText(Object element, int columnIndex) {
+ ProfileSelection entry = (ProfileSelection) element;
+ StringBuilder text = new StringBuilder();
+ if (entry != null) {
+ if (columnIndex == PROFILE_ID_COLUMN) {
+ text.append(entry.getId());
+ ProfileState state = entry.getActivationState();
+ if (Boolean.TRUE.equals(entry.getSelected())
+ && state == ProfileState.Disabled) {
+ text.append(Messages.SelectProfilesDialog_deactivated);
+ } else if (Boolean.TRUE.equals(entry.getAutoActive())) {
+ text.append(Messages.SelectProfilesDialog_autoactivated);
+ }
+ } else if (columnIndex == SOURCE_COLUMN) {
+ text.append(entry.getSource());
+ }
+ }
+ return text.toString();
+ }
+ }
+}
diff --git a/org.eclipse.m2e.profiles.ui/src/org/eclipse/m2e/profiles/ui/internal/messages.properties b/org.eclipse.m2e.profiles.ui/src/org/eclipse/m2e/profiles/ui/internal/messages.properties
new file mode 100644
index 00000000..e739a119
--- /dev/null
+++ b/org.eclipse.m2e.profiles.ui/src/org/eclipse/m2e/profiles/ui/internal/messages.properties
@@ -0,0 +1,28 @@
+ProfileManager_Updating_maven_profiles=Updating maven profiles
+ProfileSelectionHandler_Loading_maven_profiles=Loading project profiles
+ProfileSelectionHandler_Maven_Builder_still_processing=The maven builder has not finished processing the selected project(s) yet.
+ProfileSelectionHandler_multiple_definitions=multiple definitions
+ProfileSelectionHandler_Select_some_maven_projects=You must select at least one active Maven project
+ProfileSelectionHandler_Unable_to_open_profile_dialog=Unable to open the Maven Profile selection dialog
+SelectProfilesDialog_Activate_menu=Activate {0}
+SelectProfilesDialog_Active_Profiles_for_Project=Active profiles for {0} :
+SelectProfilesDialog_autoactivated=\ (auto activated)
+SelectProfilesDialog_Available_profiles=Available profiles :
+SelectProfilesDialog_Warning_Common_profiles=Only the profiles common to all selected projects are displayed. Other profiles will not be affected.
+SelectProfilesDialog_Deactivate_menu=Deactivate {0}
+SelectProfilesDialog_deactivated=\ (deactivated)
+SelectProfilesDialog_DeselectAll=Deselect all
+SelectProfilesDialog_Force_update=Force update
+SelectProfilesDialog_Maven_profile_selection=Maven Profile selection
+SelectProfilesDialog_Move_Down=Move Down
+SelectProfilesDialog_Move_Up=Move Up
+SelectProfilesDialog_No_Common_Profiles=There are no common profiles for the {0} selected projects.
+SelectProfilesDialog_Offline=Offline
+SelectProfilesDialog_Profile_id_header=Profile id
+SelectProfilesDialog_Profile_source_header=Source
+SelectProfilesDialog_Project_has_no_available_profiles=Project {0} has no available profiles
+SelectProfilesDialog_Read_Only_profiles=Active profiles area is read-only
+SelectProfilesDialog_Select_active_profiles_for_selected_projects=Select the active Maven profiles for the {0} selected projects. Right-click to (de)activate a profile.
+SelectProfilesDialog_Select_Maven_profiles=Select Maven profiles
+SelectProfilesDialog_Select_the_active_Maven_profiles=Select the active Maven profiles for project {0}. Right-click to (de)activate a profile.
+SelectProfilesDialog_SelectAll=Select All

Back to the top