Index: plugin.xml =================================================================== --- plugin.xml (revision 808556) +++ plugin.xml (working copy) @@ -89,6 +89,20 @@ class="org.apache.ivyde.eclipse.ui.actions.ResolveAction" enablesFor="1" /> + + + + + */ +public abstract class IvyDEProjectAction implements IActionDelegate { + protected abstract void selectionChanged(IAction action, IProject[] projects); + + /** + * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, + * org.eclipse.jface.viewers.ISelection) + */ + public final void selectionChanged(IAction action, ISelection selection) { + if (selection instanceof IStructuredSelection) { + Collection/**/ projects = new ArrayList/**/(); + + for (Iterator it = ((IStructuredSelection) selection).iterator(); it.hasNext();) { + Object element = it.next(); + IProject project = null; + if (element instanceof IProject) { + project = (IProject) element; + } else if (element instanceof IAdaptable) { + project = (IProject) ((IAdaptable) element).getAdapter(IProject.class); + } + + if (project != null) { + // TODO validate a project's "Ivy nature" here (has an ivy.xml or an ivy classpath container) + projects.add(project); + } + } + + if(projects.size() > 0) { + action.setEnabled(true); + selectionChanged(action, (IProject[]) projects.toArray(new IProject[projects.size()])); + } + else { + action.setEnabled(false); + } + } + } +} Index: src/java/org/apache/ivyde/eclipse/ui/actions/IvyDEProjectMenuAction.java =================================================================== --- src/java/org/apache/ivyde/eclipse/ui/actions/IvyDEProjectMenuAction.java (revision 0) +++ src/java/org/apache/ivyde/eclipse/ui/actions/IvyDEProjectMenuAction.java (revision 0) @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.ivyde.eclipse.ui.actions; + +import org.eclipse.core.resources.IProject; +import org.eclipse.jface.action.ActionContributionItem; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.action.IMenuCreator; +import org.eclipse.swt.events.MenuAdapter; +import org.eclipse.swt.events.MenuEvent; +import org.eclipse.swt.events.MenuListener; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.MenuItem; + +public class IvyDEProjectMenuAction extends IvyDEProjectAction implements IMenuCreator { + private boolean selectionChanged; + private IAction proxyAction; + private IProject[] projects; + + private MenuListener menuListener = new MenuAdapter() { + public void menuShown(MenuEvent e) { + if (selectionChanged) { + Menu m = (Menu) e.widget; + MenuItem[] items = m.getItems(); + for (int i = 0; i < items.length; i++) { + items[i].dispose(); + } + fill(m, projects); + selectionChanged = false; + } + } + }; + + protected void fill(Menu menu, IProject[] projects) { + ProjectResolveAction resolveAction = new ProjectResolveAction(projects); + new ActionContributionItem(resolveAction).fill(menu, -1); + } + + public Menu getMenu(Control parent) { + Menu menu = new Menu(parent); + fill(menu, projects); + menu.addMenuListener(menuListener); + return menu; + } + + public Menu getMenu(Menu parent) { + Menu menu = new Menu(parent); + fill(menu, projects); + menu.addMenuListener(menuListener); + return menu; + } + + protected void selectionChanged(IAction a, IProject[] projects) { + this.projects = projects; + selectionChanged = true; + if (proxyAction != a) { + proxyAction = a; + proxyAction.setMenuCreator(this); + } + } + + public void run(IAction action) { + // nothing to run + } + + public void dispose() { + // nothing to dispose + } +} Index: src/java/org/apache/ivyde/eclipse/ui/actions/ProjectResolveAction.java =================================================================== --- src/java/org/apache/ivyde/eclipse/ui/actions/ProjectResolveAction.java (revision 0) +++ src/java/org/apache/ivyde/eclipse/ui/actions/ProjectResolveAction.java (revision 0) @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.ivyde.eclipse.ui.actions; + +import java.util.Iterator; +import java.util.List; + +import org.apache.ivyde.eclipse.cpcontainer.IvyClasspathContainer; +import org.apache.ivyde.eclipse.cpcontainer.IvyClasspathUtil; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.SubProgressMonitor; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jface.action.Action; + +public class ProjectResolveAction extends Action { + IProject[] projects; + + public ProjectResolveAction(IProject[] projects) { + this.projects = projects; + this.setText("Resolve"); + } + + public void run() { + final IProject[] finalProjects = projects; + + Job multipleResolveJob = new Job("Resolving dependencies") { + protected IStatus run(IProgressMonitor monitor) { + for (int i = 0; i < finalProjects.length; i++) { + IJavaProject javaProject = JavaCore.create(finalProjects[i]); + if (javaProject == null) + continue; + + List/* */classpathContainers = IvyClasspathUtil + .getIvyClasspathContainers(javaProject); + + Iterator containerIterator = classpathContainers.iterator(); + while (containerIterator.hasNext()) { + if (monitor.isCanceled()) { + return Status.CANCEL_STATUS; + } + SubProgressMonitor subMonitor = new SubProgressMonitor(monitor, 1); + IvyClasspathContainer container = (IvyClasspathContainer) containerIterator + .next(); + container.launchResolve(false, true, subMonitor); + } + } + + return Status.OK_STATUS; + } + }; + + multipleResolveJob.setUser(true); + multipleResolveJob.schedule(); + } +}