blob: d0072b104ec5f88a69a656ae118b8a5402c33a6a [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2011 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
*******************************************************************************/
package org.eclipse.stem.ui.handlers;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IHandler;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.stem.loggers.SimulationLogger;
import org.eclipse.ui.handlers.HandlerUtil;
public class LoggerCommandHandler {
private static SimulationLogger getSelection(ExecutionEvent executionEvent)
throws ExecutionException {
final ISelection selection = HandlerUtil
.getCurrentSelectionChecked(executionEvent);
if (selection instanceof StructuredSelection) {
StructuredSelection selection2 = (StructuredSelection) selection;
Object selected = selection2.getFirstElement();
if (selected instanceof SimulationLogger) {
return (SimulationLogger) selected;
}
}
return null;
}
private static void setLoggerState(final ExecutionEvent executionEvent, boolean enabled) throws ExecutionException
{
SimulationLogger logger = getSelection(executionEvent);
if (logger != null) {
logger.setEnabled(enabled);
}
}
public static class EnableLoggerCommandHandler extends AbstractHandler implements IHandler
{
/**
* @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
*/
public Object execute(final ExecutionEvent executionEvent) throws ExecutionException {
setLoggerState(executionEvent,true);
return null;
} // execute
}
public static class DisableLoggerCommandHandler extends AbstractHandler implements IHandler
{
/**
* @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
*/
public Object execute(final ExecutionEvent executionEvent) throws ExecutionException {
setLoggerState(executionEvent,false);
return null;
} // execute
}
}