| /******************************************************************************* |
| * 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.commands; |
| |
| import org.eclipse.core.commands.ExecutionEvent; |
| import org.eclipse.core.commands.ExecutionException; |
| import org.eclipse.jface.dialogs.MessageDialog; |
| import org.eclipse.jface.window.Window; |
| import org.eclipse.jface.wizard.WizardDialog; |
| import org.eclipse.mylyn.internal.context.ui.wizards.ContextAttachWizard; |
| import org.eclipse.mylyn.internal.tasks.core.deprecated.AbstractLegacyRepositoryConnector; |
| import org.eclipse.mylyn.internal.tasks.ui.commands.AbstractTaskHandler; |
| import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector; |
| import org.eclipse.mylyn.tasks.core.ITask; |
| import org.eclipse.mylyn.tasks.core.ITask.SynchronizationState; |
| import org.eclipse.mylyn.tasks.ui.TasksUi; |
| import org.eclipse.swt.widgets.Shell; |
| import org.eclipse.ui.PlatformUI; |
| |
| /** |
| * @author Steffen Pingel |
| */ |
| public class AttachContextHandler extends AbstractTaskHandler { |
| |
| @Override |
| protected void execute(ExecutionEvent event, ITask task) throws ExecutionException { |
| AbstractRepositoryConnector connector = TasksUi.getRepositoryManager().getRepositoryConnector( |
| task.getConnectorKind()); |
| if (connector instanceof AbstractLegacyRepositoryConnector) { |
| if (task.getSynchronizationState() != SynchronizationState.SYNCHRONIZED) { |
| MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), |
| "Context Attachment", "Task must be synchronized before attaching context"); |
| return; |
| } |
| } |
| |
| ContextAttachWizard wizard = new ContextAttachWizard(task); |
| Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); |
| if (shell != null && !shell.isDisposed()) { |
| WizardDialog dialog = new WizardDialog(shell, wizard); |
| dialog.create(); |
| dialog.setTitle("Attach Context"); |
| dialog.setBlockOnOpen(true); |
| if (dialog.open() == Window.CANCEL) { |
| dialog.close(); |
| return; |
| } |
| } |
| } |
| |
| } |