Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormkersten2006-12-22 02:44:13 -0500
committermkersten2006-12-22 02:44:13 -0500
commit47ade0afe8dc55a2c02cd108403b583ae6b2f529 (patch)
treea2264f1379e27b96d65e2c4e946208f93557ba90
parentbc29341c58b473deab215d816d32515bb08b4f20 (diff)
downloadorg.eclipse.mylyn.tasks-47ade0afe8dc55a2c02cd108403b583ae6b2f529.tar.gz
org.eclipse.mylyn.tasks-47ade0afe8dc55a2c02cd108403b583ae6b2f529.tar.xz
org.eclipse.mylyn.tasks-47ade0afe8dc55a2c02cd108403b583ae6b2f529.zip
NEW - bug 168817: Should not show context menu for task repository if no repo is selected
https://bugs.eclipse.org/bugs/show_bug.cgi?id=168817
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/DeleteTaskRepositoryAction.java28
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/EditRepositoryPropertiesAction.java29
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/ResetRepositoryConfigurationAction.java22
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/TaskRepositoriesView.java24
4 files changed, 51 insertions, 52 deletions
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/DeleteTaskRepositoryAction.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/DeleteTaskRepositoryAction.java
index 224a0c777..e749dbc0e 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/DeleteTaskRepositoryAction.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/DeleteTaskRepositoryAction.java
@@ -15,41 +15,41 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Set;
-import org.eclipse.jface.action.Action;
-import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.mylar.context.core.MylarStatusHandler;
-import org.eclipse.mylar.internal.tasks.ui.views.TaskRepositoriesView;
import org.eclipse.mylar.tasks.core.AbstractRepositoryQuery;
import org.eclipse.mylar.tasks.core.TaskRepository;
import org.eclipse.mylar.tasks.ui.TasksUiPlugin;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.actions.BaseSelectionListenerAction;
import org.eclipse.ui.internal.WorkbenchImages;
/**
* @author Mik Kersten
*/
-public class DeleteTaskRepositoryAction extends Action {
+public class DeleteTaskRepositoryAction extends BaseSelectionListenerAction {
private static final String ID = "org.eclipse.mylar.tasklist.repositories.delete";
- private TaskRepositoriesView repositoriesView;
-
- public DeleteTaskRepositoryAction(TaskRepositoriesView repositoriesView) {
- this.repositoriesView = repositoriesView;
+ public DeleteTaskRepositoryAction() {
+ super("Delete Repository");
setImageDescriptor(WorkbenchImages.getImageDescriptor(ISharedImages.IMG_TOOL_DELETE));
- setText("Delete Repository");
setId(ID);
+ setEnabled(false);
+ }
+
+ @Override
+ protected boolean updateSelection(IStructuredSelection selection) {
+ return selection != null && !selection.isEmpty();
}
public void init(IViewPart view) {
// ignore
}
-
+
@Override
public void run() {
try {
@@ -57,7 +57,7 @@ public class DeleteTaskRepositoryAction extends Action {
boolean deleteConfirmed = MessageDialog.openQuestion(PlatformUI.getWorkbench().getActiveWorkbenchWindow()
.getShell(), "Confirm Delete", "Delete the selected task repositories?");
if (deleteConfirmed) {
- IStructuredSelection selection = (IStructuredSelection) repositoriesView.getViewer().getSelection();
+ IStructuredSelection selection = getStructuredSelection();
Set<AbstractRepositoryQuery> queries = TasksUiPlugin.getTaskListManager().getTaskList()
.getQueries();
List<TaskRepository> repositoriesInUse = new ArrayList<TaskRepository>();
@@ -94,8 +94,4 @@ public class DeleteTaskRepositoryAction extends Action {
MylarStatusHandler.fail(e, e.getMessage(), true);
}
}
-
- public void selectionChanged(IAction action, ISelection selection) {
- // TODO Auto-generated method stub
- }
}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/EditRepositoryPropertiesAction.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/EditRepositoryPropertiesAction.java
index 12a4a329a..3d0ce06a1 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/EditRepositoryPropertiesAction.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/EditRepositoryPropertiesAction.java
@@ -11,43 +11,34 @@
package org.eclipse.mylar.internal.tasks.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.IStructuredSelection;
-import org.eclipse.mylar.internal.tasks.ui.views.TaskRepositoriesView;
import org.eclipse.mylar.tasks.core.TaskRepository;
import org.eclipse.mylar.tasks.ui.TasksUiUtil;
-import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.actions.BaseSelectionListenerAction;
/**
* @author Mik Kersten
*/
-public class EditRepositoryPropertiesAction extends Action {
+public class EditRepositoryPropertiesAction extends BaseSelectionListenerAction {
private static final String ID = "org.eclipse.mylar.tasklist.repositories.properties";
- private TaskRepositoriesView repositoriesView;
-
- public EditRepositoryPropertiesAction(TaskRepositoriesView repositoriesView) {
- this.repositoriesView = repositoriesView;
- setText("Properties");
+ public EditRepositoryPropertiesAction() {
+ super("Properties");
setId(ID);
+ setEnabled(false);
}
- public void init(IViewPart view) {
- // ignore
+ @Override
+ protected boolean updateSelection(IStructuredSelection selection) {
+ return selection != null && !selection.isEmpty();
}
-
+
@Override
public void run() {
- IStructuredSelection selection = (IStructuredSelection) repositoriesView.getViewer().getSelection();
+ IStructuredSelection selection = getStructuredSelection();
if (selection.getFirstElement() instanceof TaskRepository) {
TasksUiUtil.openEditRepositoryWizard((TaskRepository) selection.getFirstElement());
}
}
-
- public void selectionChanged(IAction action, ISelection selection) {
- // TODO Auto-generated method stub
- }
}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/ResetRepositoryConfigurationAction.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/ResetRepositoryConfigurationAction.java
index cdbe0fa01..1042b5197 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/ResetRepositoryConfigurationAction.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/ResetRepositoryConfigurationAction.java
@@ -15,7 +15,6 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
@@ -23,31 +22,30 @@ import org.eclipse.mylar.context.core.MylarStatusHandler;
import org.eclipse.mylar.tasks.core.AbstractRepositoryConnector;
import org.eclipse.mylar.tasks.core.TaskRepository;
import org.eclipse.mylar.tasks.ui.TasksUiPlugin;
-import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.actions.BaseSelectionListenerAction;
/**
* @author Mik Kersten
*/
-public class ResetRepositoryConfigurationAction extends Action {
+public class ResetRepositoryConfigurationAction extends BaseSelectionListenerAction {
private static final String ID = "org.eclipse.mylar.tasklist.repositories.reset";
- private TaskRepositoriesView repositoriesView;
-
- public ResetRepositoryConfigurationAction(TaskRepositoriesView repositoriesView) {
- this.repositoriesView = repositoriesView;
- setText("Update Attributes");
+ public ResetRepositoryConfigurationAction() {
+ super("Update Attributes");
setId(ID);
+ setEnabled(false);
}
- public void init(IViewPart view) {
- // ignore
+ @Override
+ protected boolean updateSelection(IStructuredSelection selection) {
+ return selection != null && !selection.isEmpty();
}
-
+
@Override
public void run() {
try {
- IStructuredSelection selection = (IStructuredSelection) repositoriesView.getViewer().getSelection();
+ IStructuredSelection selection = getStructuredSelection();
for (Iterator<?> iter = selection.iterator(); iter.hasNext();) {
Object selectedObject = iter.next();
if (selectedObject instanceof TaskRepository) {
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/TaskRepositoriesView.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/TaskRepositoriesView.java
index be59cb631..ab43dd74f 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/TaskRepositoriesView.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/TaskRepositoriesView.java
@@ -36,6 +36,7 @@ import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.actions.BaseSelectionListenerAction;
import org.eclipse.ui.part.ViewPart;
/**
@@ -49,11 +50,11 @@ public class TaskRepositoriesView extends ViewPart {
private Action addRepositoryAction = new AddRepositoryAction();
- private Action deleteRepositoryAction = new DeleteTaskRepositoryAction(this);
+ private BaseSelectionListenerAction deleteRepositoryAction;
- private Action repositoryPropertiesAction = new EditRepositoryPropertiesAction(this);
+ private BaseSelectionListenerAction repositoryPropertiesAction;
- private Action resetConrigurationAction = new ResetRepositoryConfigurationAction(this);
+ private BaseSelectionListenerAction resetConrigurationAction;
private final ITaskRepositoryListener REPOSITORY_LISTENER = new ITaskRepositoryListener() {
@@ -131,11 +132,23 @@ public class TaskRepositoriesView extends ViewPart {
}
});
+ makeActions();
hookContextMenu();
contributeToActionBars();
getSite().setSelectionProvider(getViewer());
}
+ private void makeActions() {
+ deleteRepositoryAction = new DeleteTaskRepositoryAction();
+ viewer.addSelectionChangedListener(deleteRepositoryAction);
+
+ repositoryPropertiesAction = new EditRepositoryPropertiesAction();
+ viewer.addSelectionChangedListener(repositoryPropertiesAction);
+
+ resetConrigurationAction = new ResetRepositoryConfigurationAction();
+ viewer.addSelectionChangedListener(resetConrigurationAction);
+ }
+
private void hookContextMenu() {
MenuManager menuMgr = new MenuManager("#PopupMenu");
menuMgr.setRemoveAllWhenShown(true);
@@ -161,11 +174,12 @@ public class TaskRepositoriesView extends ViewPart {
private void fillContextMenu(IMenuManager manager) {
manager.add(addRepositoryAction);
- manager.add(deleteRepositoryAction);
manager.add(new Separator());
- manager.add(repositoryPropertiesAction);
+ manager.add(deleteRepositoryAction);
manager.add(resetConrigurationAction);
manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
+ manager.add(new Separator());
+ manager.add(repositoryPropertiesAction);
}
private void fillLocalToolBar(IToolBarManager manager) {

Back to the top