blob: 943580c4b7800c649286a92191af3493b7e24ac7 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2004, 2007 Mylyn project committers 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
*******************************************************************************/
package org.eclipse.mylyn.internal.context.ui.actions;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.mylyn.context.core.ContextCore;
import org.eclipse.mylyn.tasks.core.ITask;
import org.eclipse.ui.IViewActionDelegate;
/**
* Controls enablement
*
* @author Mik Kersten
*/
public abstract class TaskContextAction extends Action implements IViewActionDelegate {
protected ISelection selection;
protected ITask getSelectedTask(ISelection newSelection) {
if (selection instanceof StructuredSelection) {
Object selectedObject = ((StructuredSelection) selection).getFirstElement();
if (selectedObject instanceof ITask) {
return (ITask) selectedObject;
}
// else if (selectedObject instanceof AbstractQueryHit) {
// return ((AbstractQueryHit) selectedObject).getCorrespondingTask();
// }
}
return null;
}
public void selectionChanged(IAction action, ISelection selection) {
this.selection = selection;
ITask selectedTask = getSelectedTask(selection);
if (selectedTask != null) {
action.setEnabled(ContextCore.getContextManager().hasContext(selectedTask.getHandleIdentifier()));
} else {
action.setEnabled(false);
}
}
}