|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2004, 2008 Tasktop Technologies and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* |
| 8 |
* Contributors: |
| 9 |
* Tasktop Technologies - initial API and implementation |
| 10 |
*******************************************************************************/ |
| 11 |
|
| 12 |
package org.eclipse.mylyn.internal.tasks.ui.actions; |
| 13 |
|
| 14 |
import org.eclipse.jface.action.Action; |
| 15 |
import org.eclipse.jface.action.IAction; |
| 16 |
import org.eclipse.jface.viewers.ISelection; |
| 17 |
import org.eclipse.jface.viewers.ISelectionChangedListener; |
| 18 |
import org.eclipse.jface.viewers.IStructuredSelection; |
| 19 |
import org.eclipse.jface.viewers.SelectionChangedEvent; |
| 20 |
import org.eclipse.mylyn.internal.tasks.core.TaskRepositoryManager; |
| 21 |
import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin; |
| 22 |
import org.eclipse.mylyn.internal.tasks.ui.views.Messages; |
| 23 |
import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector; |
| 24 |
import org.eclipse.mylyn.tasks.core.TaskRepository; |
| 25 |
import org.eclipse.mylyn.tasks.ui.TasksUi; |
| 26 |
|
| 27 |
/** |
| 28 |
* |
| 29 |
* @author "Frank Becker" |
| 30 |
* @since 3.1 |
| 31 |
* |
| 32 |
*/ |
| 33 |
public class DefaultRepositoryAction extends Action implements ISelectionChangedListener { |
| 34 |
public static final String LABEL = Messages.DefaultRepositoryAction_Default; |
| 35 |
|
| 36 |
private static final String ID = "org.eclipse.mylyn.tasklist.repositories.default"; //$NON-NLS-1$ |
| 37 |
|
| 38 |
private TaskRepository repository; |
| 39 |
|
| 40 |
public DefaultRepositoryAction() { |
| 41 |
super(LABEL, IAction.AS_CHECK_BOX); |
| 42 |
setId(ID); |
| 43 |
setEnabled(false); |
| 44 |
} |
| 45 |
|
| 46 |
@Override |
| 47 |
public void run() { |
| 48 |
TaskRepositoryManager repositoryManager = TasksUiPlugin.getRepositoryManager(); |
| 49 |
repositoryManager.setDefaultRepository(repository); |
| 50 |
repositoryManager.notifyRepositorySettingsChanged(repository); |
| 51 |
} |
| 52 |
|
| 53 |
public void selectionChanged(IAction action, ISelection selection) { |
| 54 |
} |
| 55 |
|
| 56 |
public void selectionChanged(SelectionChangedEvent event) { |
| 57 |
ISelection selection = event.getSelection(); |
| 58 |
if (selection instanceof IStructuredSelection) { |
| 59 |
Object selectedObject = ((IStructuredSelection) selection).getFirstElement(); |
| 60 |
if (selectedObject instanceof TaskRepository) { |
| 61 |
AbstractRepositoryConnector connector = TasksUi.getRepositoryManager().getRepositoryConnector( |
| 62 |
((TaskRepository) selectedObject).getConnectorKind()); |
| 63 |
if (connector.isUserManaged()) { |
| 64 |
this.repository = (TaskRepository) selectedObject; |
| 65 |
setChecked(this.repository.isDefault()); |
| 66 |
setEnabled(true); |
| 67 |
return; |
| 68 |
} |
| 69 |
} |
| 70 |
} |
| 71 |
this.repository = null; |
| 72 |
setChecked(false); |
| 73 |
setEnabled(false); |
| 74 |
} |
| 75 |
|
| 76 |
} |