Skip to main content
summaryrefslogtreecommitdiffstats
blob: afa336899f5403f7e3148333291a47930d891989 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*******************************************************************************
 * Copyright (c) 2004, 2008 Tasktop Technologies 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
 *
 * Contributors:
 *     Tasktop Technologies - initial API and implementation
 *******************************************************************************/

package org.eclipse.mylyn.internal.tasks.ui.actions;

import org.eclipse.mylyn.internal.provisional.commons.ui.CommonImages;
import org.eclipse.mylyn.internal.tasks.core.AbstractTask;
import org.eclipse.mylyn.internal.tasks.core.RepositoryQuery;
import org.eclipse.mylyn.internal.tasks.ui.util.ClipboardCopier;
import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal;
import org.eclipse.mylyn.tasks.core.IRepositoryElement;
import org.eclipse.mylyn.tasks.core.IRepositoryQuery;
import org.eclipse.mylyn.tasks.core.ITask;
import org.eclipse.ui.actions.BaseSelectionListenerAction;

/**
 * @author Mik Kersten
 */
public class CopyTaskDetailsAction extends BaseSelectionListenerAction {

	public static final String ID = "org.eclipse.mylyn.tasklist.actions.copy"; //$NON-NLS-1$

	private final ClipboardCopier copier;

	public CopyTaskDetailsAction() {
		super(Messages.CopyTaskDetailsAction_Copy_Details);
		setToolTipText(Messages.CopyTaskDetailsAction_Copy_Details);
		setId(ID);
		setImageDescriptor(CommonImages.COPY);
		this.copier = new ClipboardCopier() {
			@Override
			protected String getTextForElement(Object element) {
				return getTextForTask(element);
			}
		};
	}

	@Override
	public void run() {
		copier.copy(getStructuredSelection());
	}

	public void dispose() {
		copier.dispose();
	}

	// TODO move to TasksUiUtil / into core
	public static String getTextForTask(Object object) {
		StringBuffer sb = new StringBuffer();
		if (object instanceof ITask) {
			AbstractTask task = (AbstractTask) object;
			if (task.getTaskKey() != null) {
				sb.append(task.getTaskKey());
				sb.append(": "); //$NON-NLS-1$
			}

			sb.append(task.getSummary());
			if (TasksUiInternal.isValidUrl(task.getUrl())) {
				sb.append(ClipboardCopier.LINE_SEPARATOR);
				sb.append(task.getUrl());
			}
		} else if (object instanceof IRepositoryQuery) {
			RepositoryQuery query = (RepositoryQuery) object;
			sb.append(query.getSummary());
			if (TasksUiInternal.isValidUrl(query.getUrl())) {
				sb.append(ClipboardCopier.LINE_SEPARATOR);
				sb.append(query.getUrl());
			}
		} else if (object instanceof IRepositoryElement) {
			IRepositoryElement element = (IRepositoryElement) object;
			sb.append(element.getSummary());
		}
		return sb.toString();
	}

}

Back to the top