Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsminto2005-07-21 18:51:14 +0000
committersminto2005-07-21 18:51:14 +0000
commit7df845e2d3ea6ca7c7421c2680425910c9904944 (patch)
tree666a46b160991bee7849645435aebffd55ac3609 /org.eclipse.mylyn.tasks.ui
parent5f5e4360bfbdea9d0ee80bca960819bab78eb1b5 (diff)
downloadorg.eclipse.mylyn.tasks-7df845e2d3ea6ca7c7421c2680425910c9904944.tar.gz
org.eclipse.mylyn.tasks-7df845e2d3ea6ca7c7421c2680425910c9904944.tar.xz
org.eclipse.mylyn.tasks-7df845e2d3ea6ca7c7421c2680425910c9904944.zip
fixed Bug #103881: Context menu actions are enabled for all elements
Diffstat (limited to 'org.eclipse.mylyn.tasks.ui')
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ITaskHandler.java3
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/views/TaskListView.java134
2 files changed, 72 insertions, 65 deletions
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ITaskHandler.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ITaskHandler.java
index bf613e5e0..879f64c3a 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ITaskHandler.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ITaskHandler.java
@@ -1,5 +1,6 @@
package org.eclipse.mylar.tasks;
+import org.eclipse.jface.action.Action;
import org.eclipse.mylar.tasks.internal.TaskCategory;
import org.eclipse.mylar.tasks.ui.views.TaskListView;
import org.eclipse.ui.IWorkbenchPage;
@@ -22,4 +23,6 @@ public interface ITaskHandler {
public abstract ITask taskAdded(ITask newTask);
public abstract void restoreState(TaskListView taskListView);
+
+ public abstract boolean enableAction(Action action, ITaskListElement element);
} \ No newline at end of file
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/views/TaskListView.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/views/TaskListView.java
index c3c844966..dd790e9df 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/views/TaskListView.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/views/TaskListView.java
@@ -917,78 +917,82 @@ public class TaskListView extends ViewPart {
}
void fillContextMenu(IMenuManager manager) {
- manager.add(completeTask);
- manager.add(incompleteTask);
- manager.add(delete);
- manager.add(new Separator());
- manager.add(createTask);
- manager.add(new Separator("mylar"));
-
+ ITaskListElement element = null;;
final Object selectedObject = ((IStructuredSelection)viewer.getSelection()).getFirstElement();
if (selectedObject instanceof ITaskListElement) {
-
- for (ITaskListDynamicSubMenuContributor contributor : MylarTasksPlugin.getDefault().getDynamicMenuContributers()) {
- manager.add(new Separator());
- MenuManager subMenuManager = contributor.getSubMenuManager(this, (ITaskListElement)selectedObject);
- if (subMenuManager != null) manager.add(subMenuManager);
- }
+ element = (ITaskListElement) selectedObject;
}
+
+ addAction(completeTask, manager, element);
+ addAction(incompleteTask, manager, element);
+ addAction(delete, manager, element);
+ manager.add(new Separator());
+ addAction(createTask, manager, element);
+ manager.add(new Separator("mylar"));
+
+ for (ITaskListDynamicSubMenuContributor contributor : MylarTasksPlugin.getDefault().getDynamicMenuContributers()) {
+ manager.add(new Separator());
+ MenuManager subMenuManager = contributor.getSubMenuManager(this, (ITaskListElement)selectedObject);
+ if (subMenuManager != null) addMenuManager(subMenuManager, manager, element);
+ }
+
manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
- updateActionEnablement(selectedObject);
}
- private void updateActionEnablement(Object sel) {
-// XXX use enables for part of contribution
-// if(sel != null && sel instanceof ITaskListElement){
-// if(sel instanceof BugzillaHit){
-// BugzillaTask task = ((BugzillaHit)sel).getAssociatedTask();
-// if(task == null){
-// clearSelectedTaskscapeAction.setEnabled(false);
-// } else {
-// clearSelectedTaskscapeAction.setEnabled(true);
-// }
-// completeTask.setEnabled(false);
-// incompleteTask.setEnabled(false);
-// moveTaskToRoot.setEnabled(false);
-// delete.setEnabled(false);
-// refreshQuery.setEnabled(false);
-// } else if(sel instanceof BugzillaTask){
-// clearSelectedTaskscapeAction.setEnabled(true);
-// completeTask.setEnabled(false);
-// incompleteTask.setEnabled(false);
-// moveTaskToRoot.setEnabled(true);
-// delete.setEnabled(true);
-// refreshQuery.setEnabled(false);
-// } else if(sel instanceof AbstractCategory){
-// clearSelectedTaskscapeAction.setEnabled(false);
-// completeTask.setEnabled(false);
-// incompleteTask.setEnabled(false);
-// moveTaskToRoot.setEnabled(false);
-// delete.setEnabled(true);
-// if (sel instanceof BugzillaQueryCategory) {
-// refreshQuery.setEnabled(true);
-// } else {
-// refreshQuery.setEnabled(false);
-// }
-// //delete.setEnabled(true);
-// } else {
-// clearSelectedTaskscapeAction.setEnabled(true);
-// completeTask.setEnabled(true);
-// incompleteTask.setEnabled(true);
-// moveTaskToRoot.setEnabled(true);
-// delete.setEnabled(true);
-// refreshQuery.setEnabled(false);
-// }
-// } else {
-// clearSelectedTaskscapeAction.setEnabled(false);
-// completeTask.setEnabled(false);
-// incompleteTask.setEnabled(false);
-// moveTaskToRoot.setEnabled(false);
-// delete.setEnabled(false);
-// refreshQuery.setEnabled(false);
-// }
+ private void addMenuManager(IMenuManager menuToAdd, IMenuManager manager, ITaskListElement element) {
+ if(element != null && element instanceof ITask){
+ manager.add(menuToAdd);
+ }
}
-
+
+
+ private void addAction(Action action, IMenuManager manager, ITaskListElement element) {
+ manager.add(action);
+ if(element != null){
+ ITaskHandler handler = MylarTasksPlugin.getDefault().getTaskHandlerForElement(element);
+ if(handler != null){
+ action.setEnabled(handler.enableAction(action, element));
+ } else {
+ updateActionEnablement(action, element);
+ }
+ }
+ }
+
+ private void updateActionEnablement(Action action, ITaskListElement element){
+
+ if(element instanceof Task){
+ if(action instanceof MarkTaskCompleteAction){
+ if(element.isCompleted()){
+ action.setEnabled(false);
+ } else {
+ action.setEnabled(true);
+ }
+ } else if(action instanceof MarkTaskIncompleteAction){
+ if(element.isCompleted()){
+ action.setEnabled(true);
+ } else {
+ action.setEnabled(false);
+ }
+ } else if(action instanceof DeleteAction){
+ action.setEnabled(true);
+ } else if(action instanceof CreateTaskAction){
+ action.setEnabled(false);
+ }
+ } else if(element instanceof TaskCategory) {
+ if(action instanceof MarkTaskCompleteAction){
+ action.setEnabled(false);
+ } else if(action instanceof MarkTaskIncompleteAction){
+ action.setEnabled(false);
+ } else if(action instanceof DeleteAction){
+ action.setEnabled(true);
+ } else if(action instanceof CreateTaskAction){
+ action.setEnabled(true);
+ }
+ } else {
+ action.setEnabled(true);
+ }
+ }
+
/**
* @see org.eclipse.pde.internal.ui.view.HistoryDropDownAction
*

Back to the top