diff --git a/build/org.eclipse.cdt.managedbuilder.ui/plugin.properties b/build/org.eclipse.cdt.managedbuilder.ui/plugin.properties
index 79c08ba4dd7..befc5db8906 100644
--- a/build/org.eclipse.cdt.managedbuilder.ui/plugin.properties
+++ b/build/org.eclipse.cdt.managedbuilder.ui/plugin.properties
@@ -1,5 +1,5 @@
###############################################################################
-# Copyright (c) 2003, 2005 IBM Corporation and others.
+# Copyright (c) 2003, 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
@@ -29,3 +29,10 @@ MngResourceProp.name=C/C++ Build
#The Project Converter page
ConvertTargetAction.label=Convert To...
+
+# Build configuration actions
+BuildConfigActionSet.label=Build Configuration
+BuildConfigToolbarAction.label=Active Build Configuration
+BuildConfigMenuAction.label=Active Buil&d Configuration
+BuildConfigContextAction.label=Active Bui&ld Configuration
+BuildConfigAction.tooltip=Change active build configuration for the current project
diff --git a/build/org.eclipse.cdt.managedbuilder.ui/plugin.xml b/build/org.eclipse.cdt.managedbuilder.ui/plugin.xml
index d4099e1bb50..4b3b31837ed 100644
--- a/build/org.eclipse.cdt.managedbuilder.ui/plugin.xml
+++ b/build/org.eclipse.cdt.managedbuilder.ui/plugin.xml
@@ -120,5 +120,57 @@
value="org.eclipse.cdt.managedbuilder.core.managedBuildNature">
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/actions/BuildConfigAction.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/actions/BuildConfigAction.java
new file mode 100644
index 00000000000..75dc499902d
--- /dev/null
+++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/actions/BuildConfigAction.java
@@ -0,0 +1,62 @@
+/*******************************************************************************
+ * Copyright (c) 2006 Intel 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:
+ * Intel Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.managedbuilder.ui.actions;
+
+import java.util.*;
+
+import org.eclipse.cdt.managedbuilder.core.*;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.jface.action.Action;
+
+/**
+ * Action which changes active build configuration of the current project to
+ * the given one.
+ */
+public class BuildConfigAction extends Action {
+
+ private String fConfigName = null;
+ private HashSet fProjects = null;
+
+ /**
+ * Constructs the action.
+ * @param projects List of selected managed-built projects
+ * @param configName Build configuration name
+ * @param accel Number to be used as accelerator
+ */
+ public BuildConfigAction(HashSet projects, String configName, String displayName, int accel) {
+ super("&" + accel + " " + displayName); //$NON-NLS-1$ //$NON-NLS-2$
+ fProjects = projects;
+ fConfigName = configName;
+ }
+
+
+
+ /**
+ * @see org.eclipse.jface.action.IAction#run()
+ */
+ public void run() {
+ Iterator iter = fProjects.iterator();
+ while (iter.hasNext()) {
+ IManagedBuildInfo info = ManagedBuildManager.getBuildInfo((IProject)iter.next());
+ IConfiguration[] configs = info.getManagedProject().getConfigurations();
+ int i = 0;
+ for (; i < configs.length; i++) {
+ if (configs[i].getName().equals(fConfigName)) {
+ break;
+ }
+ }
+ if (i != configs.length) {
+ info.setDefaultConfiguration(configs[i]);
+ info.setSelectedConfiguration(configs[i]);
+ }
+ }
+ }
+}
diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/actions/ChangeBuildConfigActionBase.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/actions/ChangeBuildConfigActionBase.java
new file mode 100644
index 00000000000..ca39fd1878a
--- /dev/null
+++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/actions/ChangeBuildConfigActionBase.java
@@ -0,0 +1,212 @@
+/*******************************************************************************
+ * Copyright (c) 2006 Intel 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:
+ * Intel Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.managedbuilder.ui.actions;
+
+import java.util.*;
+
+import org.eclipse.cdt.core.model.*;
+import org.eclipse.cdt.managedbuilder.core.*;
+import org.eclipse.core.resources.*;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.action.*;
+import org.eclipse.jface.viewers.*;
+import org.eclipse.swt.widgets.*;
+
+/**
+ * Base class for build configuration actions.
+ */
+public class ChangeBuildConfigActionBase {
+
+ /**
+ * List of selected managed-built projects
+ */
+ protected HashSet fProjects = new HashSet();
+
+ /**
+ * Fills the menu with build configurations which are common for all selected projects
+ * @param menu The menu to fill
+ */
+ protected void fillMenu(Menu menu) {
+ if (menu == null) {
+ // This should not happen
+ return;
+ }
+
+ MenuItem[] items = menu.getItems();
+ for (int i = 0; i < items.length; i++) {
+ items[i].dispose();
+ }
+
+ TreeSet configNames = new TreeSet();
+ Iterator projIter = fProjects.iterator();
+ String sCurrentConfig = null;
+ boolean bCurrentConfig = true;
+ while (projIter.hasNext()) {
+ IManagedBuildInfo info = ManagedBuildManager.getBuildInfo((IProject)projIter.next());
+ if (bCurrentConfig) {
+ String sNewConfig = info.getDefaultConfiguration().getName();
+ if (sCurrentConfig == null) {
+ sCurrentConfig = sNewConfig;
+ }
+ else {
+ if (!sCurrentConfig.equals(sNewConfig)) {
+ bCurrentConfig = false;
+ }
+ }
+ }
+ if (info != null) {
+ IConfiguration[] configs = info.getManagedProject().getConfigurations();
+ for (int i = 0; i < configs.length; i++) {
+ configNames.add(configs[i].getName());
+ }
+ }
+ }
+
+ Iterator confIter = configNames.iterator();
+ int accel = 0;
+ while (confIter.hasNext()) {
+ String sName = (String)confIter.next();
+ String sDesc = null;
+ projIter = fProjects.iterator();
+ boolean commonName = true;
+ boolean commonDesc = true;
+ boolean firstProj = true;
+ while (projIter.hasNext()) {
+ IManagedBuildInfo info = ManagedBuildManager.getBuildInfo((IProject)projIter.next());
+ if (info != null) {
+ IConfiguration[] configs = info.getManagedProject().getConfigurations();
+ int i = 0;
+ for (; i < configs.length; i++) {
+ if (configs[i].getName().equals(sName)) {
+ String sNewDesc = configs[i].getDescription();
+ if (sNewDesc.equals("")) { //$NON-NLS-1$
+ sNewDesc = null;
+ }
+ if (commonDesc) {
+ if (firstProj) {
+ sDesc = sNewDesc;
+ firstProj = false;
+ } else if (sNewDesc == null && sDesc != null || sNewDesc != null && !sNewDesc.equals(sDesc)) {
+ commonDesc = false;
+ }
+ }
+ break;
+ }
+ }
+ if (i == configs.length) {
+ commonName = false;
+ break;
+ }
+ }
+ }
+ if (commonName) {
+ StringBuilder builder = new StringBuilder(sName);
+ if (commonDesc) {
+ if (sDesc != null) {
+ builder.append(" ("); //$NON-NLS-1$
+ builder.append(sDesc);
+ builder.append(")"); //$NON-NLS-1$
+ }
+ } else {
+ builder.append(" (...)"); //$NON-NLS-1$
+ }
+
+ IAction action = new BuildConfigAction(fProjects, sName, builder.toString(), accel + 1);
+ if (bCurrentConfig && sCurrentConfig.equals(sName)) {
+ action.setChecked(true);
+ }
+ ActionContributionItem item = new ActionContributionItem(action);
+ item.fill(menu, -1);
+ accel++;
+ }
+ }
+ }
+
+ /**
+ * selectionChanged() event handler. Fills the list of managed-built projects
+ * based on the selection. If some non-managed-built projects are selected,
+ * disables the action.
+ * @param action The action
+ * @param selection The selection
+ */
+ protected void onSelectionChanged(IAction action, ISelection selection) {
+ fProjects.clear();
+
+ if (!action.isEnabled()) {
+ return;
+ }
+
+ boolean found = false;
+ if (selection != null && selection instanceof IStructuredSelection) {
+ Iterator iter = ((IStructuredSelection)selection).iterator();
+ while (iter.hasNext()) {
+ Object selItem = iter.next();
+ IProject project = null;
+ if (selItem instanceof ICElement) {
+ ICProject cproject = ((ICElement)selItem).getCProject();
+ if (cproject != null) {
+ project = cproject.getProject();
+ }
+ }
+ else if (selItem instanceof IResource) {
+ project = ((IResource)selItem).getProject();
+ }
+ if (project != null) {
+ try {
+ if (project != null && !project.hasNature(ManagedCProjectNature.MNG_NATURE_ID)) {
+ project = null;
+ }
+ }
+ catch (CoreException xE) {
+ // do nothing
+ }
+ }
+ if (project != null) {
+ fProjects.add(project);
+ } else {
+ found = true;
+ break;
+ }
+ }
+ }
+
+ boolean enable = false;
+ if (!found && !fProjects.isEmpty()) {
+ Iterator iter = fProjects.iterator();
+ IProject first = (IProject)iter.next();
+ IConfiguration[] firstConfigs = ManagedBuildManager.getBuildInfo(first).getManagedProject().getConfigurations();
+ for (int i = 0; i < firstConfigs.length; i++)
+ {
+ boolean common = true;
+ iter = fProjects.iterator();
+ while (iter.hasNext()) {
+ IProject current = (IProject)iter.next();
+ IConfiguration[] currentConfigs = ManagedBuildManager.getBuildInfo(current).getManagedProject().getConfigurations();
+ int j = 0;
+ for (; j < currentConfigs.length; j++) {
+ if (firstConfigs[i].getName().equals(currentConfigs[j].getName())) {
+ break;
+ }
+ }
+ if (j == currentConfigs.length) {
+ common = false;
+ break;
+ }
+ }
+ if (common) {
+ enable = true;
+ break;
+ }
+ }
+ }
+ action.setEnabled(enable);
+ }
+}
diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/actions/ChangeBuildConfigContextAction.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/actions/ChangeBuildConfigContextAction.java
new file mode 100644
index 00000000000..99c8e607139
--- /dev/null
+++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/actions/ChangeBuildConfigContextAction.java
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * Copyright (c) 2006 Intel 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:
+ * Intel Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.managedbuilder.ui.actions;
+
+import org.eclipse.jface.action.*;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.swt.events.*;
+import org.eclipse.swt.widgets.*;
+import org.eclipse.ui.*;
+
+/**
+ * This context menu action is used to change active build configuration for the project
+ */
+public class ChangeBuildConfigContextAction extends ChangeBuildConfigActionBase implements
+ IMenuCreator, IObjectActionDelegate {
+
+ /**
+ * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart)
+ */
+ public void setActivePart(IAction action, IWorkbenchPart targetPart) {
+ // do nothing
+ }
+
+ /**
+ * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
+ */
+ public void run(IAction action) {
+ // do nothing
+ }
+
+ /**
+ * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
+ */
+ public void selectionChanged(IAction action, ISelection selection) {
+ onSelectionChanged(action, selection);
+ action.setMenuCreator(this);
+ }
+
+ /**
+ * @see org.eclipse.jface.action.IMenuCreator#dispose()
+ */
+ public void dispose() {
+ // do nothing
+ }
+
+ /**
+ * @see org.eclipse.jface.action.IMenuCreator#getMenu(org.eclipse.swt.widgets.Control)
+ */
+ public Menu getMenu(Control parent) {
+ // this method is never called
+ return null;
+ }
+
+ /**
+ * @see org.eclipse.jface.action.IMenuCreator#getMenu(org.eclipse.swt.widgets.Menu)
+ */
+ public Menu getMenu(Menu parent) {
+ Menu menu = new Menu(parent);
+ menu.addMenuListener(new MenuAdapter() {
+ public void menuShown(MenuEvent e) {
+ fillMenu((Menu)e.widget);
+ }
+ });
+ return menu;
+ }
+}
diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/actions/ChangeBuildConfigMenuAction.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/actions/ChangeBuildConfigMenuAction.java
new file mode 100644
index 00000000000..e97fec062f2
--- /dev/null
+++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/actions/ChangeBuildConfigMenuAction.java
@@ -0,0 +1,83 @@
+/*******************************************************************************
+ * Copyright (c) 2006 Intel 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:
+ * Intel Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.managedbuilder.ui.actions;
+
+import org.eclipse.jface.action.*;
+import org.eclipse.jface.viewers.*;
+import org.eclipse.core.resources.*;
+import org.eclipse.swt.events.*;
+import org.eclipse.swt.widgets.*;
+import org.eclipse.ui.*;
+
+/**
+ * Action which changes active build configuration of the current project
+ */
+public class ChangeBuildConfigMenuAction extends ChangeBuildConfigActionBase implements
+ IWorkbenchWindowPulldownDelegate2 {
+
+ /**
+ * @see org.eclipse.ui.IWorkbenchWindowPulldownDelegate2#getMenu(org.eclipse.swt.widgets.Menu)
+ */
+ public Menu getMenu(Menu parent) {
+ Menu menu = new Menu(parent);
+ addMenuListener(menu);
+ return menu;
+ }
+
+ /**
+ * @see org.eclipse.ui.IWorkbenchWindowPulldownDelegate#getMenu(org.eclipse.swt.widgets.Control)
+ */
+ public Menu getMenu(Control parent) {
+ Menu menu = new Menu(parent);
+ addMenuListener(menu);
+ return menu;
+ }
+
+ /**
+ * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
+ */
+ public void dispose() {
+ // do nothing
+ }
+
+ /**
+ * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow)
+ */
+ public void init(IWorkbenchWindow window) {
+ // do nothing
+ }
+
+ /**
+ * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
+ */
+ public void run(IAction action) {
+ // do nothing
+ }
+
+ /**
+ * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
+ */
+ public void selectionChanged(IAction action, ISelection selection) {
+ onSelectionChanged(action, selection);
+ }
+
+ /**
+ * Adds a listener to the given menu to repopulate it each time is is shown
+ * @param menu The menu to add listener to
+ */
+ private void addMenuListener(Menu menu) {
+ menu.addMenuListener(new MenuAdapter() {
+ public void menuShown(MenuEvent e) {
+ fillMenu((Menu)e.widget);
+ }
+ });
+ }
+}