Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 21ab9b26887b9d73e5580c46c66af868b637e6f8 (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
/*******************************************************************************
 * Copyright (c) 2009, 2010 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 ******************************************************************************/

package org.eclipse.equinox.internal.p2.ui.dialogs;

import org.eclipse.equinox.internal.p2.ui.ProvUIImages;
import org.eclipse.equinox.p2.ui.ICopyable;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.*;

public class CopyPopup {

	ICopyable copySource;
	Control control;

	public CopyPopup(ICopyable copyable, final Control control) {
		this.copySource = copyable;
		this.control = control;
		Menu copyMenu = new Menu(control);
		MenuItem copyItem = new MenuItem(copyMenu, SWT.NONE);
		copyItem.setImage(ProvUIImages.getImage(ProvUIImages.IMG_COPY));
		copyItem.addSelectionListener(new SelectionListener() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				copySource.copyToClipboard(control);
			}

			@Override
			public void widgetDefaultSelected(SelectionEvent e) {
				copySource.copyToClipboard(control);
			}
		});
		copyItem.setText(JFaceResources.getString("copy")); //$NON-NLS-1$
		control.setMenu(copyMenu);
	}
}

Back to the top