/******************************************************************************* * Copyright (c) 2011 Spring IDE Developers * 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: * Spring IDE Developers - initial API and implementation *******************************************************************************/ package org.springframework.ide.eclipse.ui.internal.actions; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jface.action.IAction; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.ui.IObjectActionDelegate; import org.eclipse.ui.IWorkbenchPart; import org.springframework.ide.eclipse.core.SpringCore; import org.springframework.ide.eclipse.core.java.JdtUtils; /** * This action implementation will reset the internal classloader cache * @author Martin Lippert * @since 2.6.0 */ public class ResetInternalCacheAction implements IObjectActionDelegate { private List<IProject> selected = new ArrayList<IProject>(); /** * {@inheritDoc} */ public void setActivePart(IAction action, IWorkbenchPart targetPart) { // intentionally left empty } /** * {@inheritDoc} */ public void selectionChanged(IAction action, ISelection selection) { selected.clear(); if (selection instanceof IStructuredSelection) { boolean enabled = true; Iterator iter = ((IStructuredSelection) selection).iterator(); while (iter.hasNext()) { Object obj = iter.next(); if (obj instanceof IJavaProject) { obj = ((IJavaProject) obj).getProject(); } if (obj instanceof IProject) { IProject project = (IProject) obj; if (!project.isOpen()) { enabled = false; break; } else { selected.add(project); } } else { enabled = false; break; } } action.setEnabled(enabled); } } /** * {@inheritDoc} */ public void run(IAction action) { Iterator iter = selected.iterator(); while (iter.hasNext()) { IProject project = (IProject) iter.next(); JdtUtils.removeClassLoaderEntryFromCache(project); try { project.touch(null); } catch (CoreException e) { SpringCore.log(e); } } } }