blob: 71f59acdcf5496ca52287c99ee5a117782a3e52b [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2011, 2012 Ericsson AB 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
*
* Description:
*
* This class implements the navigator view toolbar command to remove all
* applied filters
*
* Contributors:
* Sebastien Dubois - Created for Mylyn Review R4E project
*
******************************************************************************/
package org.eclipse.mylyn.reviews.r4e.ui.internal.commands.filters;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.NotEnabledException;
import org.eclipse.core.commands.NotHandledException;
import org.eclipse.core.commands.common.NotDefinedException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.mylyn.reviews.r4e.ui.R4EUIPlugin;
import org.eclipse.mylyn.reviews.r4e.ui.internal.model.R4EUIModelController;
import org.eclipse.mylyn.reviews.r4e.ui.internal.navigator.ReviewNavigatorActionGroup;
import org.eclipse.ui.progress.UIJob;
/**
* @author Sebastien Dubois
* @version $Revision: 1.0 $
*/
public class RemoveAllFiltersHandler extends AbstractHandler {
// ------------------------------------------------------------------------
// Constants
// ------------------------------------------------------------------------
/**
* Field COMMAND_MESSAGE. (value is ""Removing all applied Filters..."")
*/
private static final String COMMAND_MESSAGE = "Removing all applied Filters...";
// ------------------------------------------------------------------------
// Methods
// ------------------------------------------------------------------------
/**
* Method execute.
*
* @param aEvent
* ExecutionEvent
* @return Object
* @see org.eclipse.core.commands.IHandler#execute(ExecutionEvent)
*/
public Object execute(ExecutionEvent aEvent) {
final UIJob job = new UIJob(COMMAND_MESSAGE) {
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
monitor.beginTask(COMMAND_MESSAGE, 1);
R4EUIPlugin.Ftracer.traceInfo(COMMAND_MESSAGE);
//We need to preserve the expansion state and restore it afterwards
final Object[] elements = R4EUIModelController.getNavigatorView().getTreeViewer().getExpandedElements();
try {
((ReviewNavigatorActionGroup) R4EUIModelController.getNavigatorView().getActionSet()).resetAllFilterActions();
} catch (NotDefinedException e) {
R4EUIPlugin.Ftracer.traceError("Exception: " + e.toString() + " (" + e.getMessage() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
R4EUIPlugin.getDefault().logError("Exception: " + e.toString(), e); //$NON-NLS-1$
monitor.done();
return Status.CANCEL_STATUS;
} catch (NotEnabledException e) {
R4EUIPlugin.Ftracer.traceError("Exception: " + e.toString() + " (" + e.getMessage() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
R4EUIPlugin.getDefault().logError("Exception: " + e.toString(), e); //$NON-NLS-1$
monitor.done();
return Status.CANCEL_STATUS;
} catch (NotHandledException e) {
R4EUIPlugin.Ftracer.traceError("Exception: " + e.toString() + " (" + e.getMessage() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
R4EUIPlugin.getDefault().logError("Exception: " + e.toString(), e); //$NON-NLS-1$
monitor.done();
return Status.CANCEL_STATUS;
} catch (ExecutionException e) {
R4EUIPlugin.Ftracer.traceError("Exception: " + e.toString() + " (" + e.getMessage() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
R4EUIPlugin.getDefault().logError("Exception: " + e.toString(), e); //$NON-NLS-1$
monitor.done();
return Status.CANCEL_STATUS;
}
R4EUIModelController.getNavigatorView().getTreeViewer().setExpandedElements(elements);
monitor.worked(1);
monitor.done();
return Status.OK_STATUS;
}
};
job.setUser(true);
job.schedule();
return null;
}
}