Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 93b3b238c4f998d4c042edc92a2a89f5109f8a6e (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
/*******************************************************************************
 * Copyright (c) 2008, 2018 IBM Corporation 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:
 *     IBM Corporation - initial API and implementation
 ******************************************************************************/

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

import org.eclipse.equinox.internal.p2.ui.ProvUIMessages;
import org.eclipse.equinox.p2.ui.ProvisioningUI;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.widgets.Control;

/**
 * @since 3.4
 *
 */
public abstract class RefreshAction extends ProvisioningAction {

	/**
	 */
	public RefreshAction(ProvisioningUI ui, ISelectionProvider selectionProvider, Control control) {
		super(ui, ProvUIMessages.RefreshAction_Label, selectionProvider);
		setToolTipText(ProvUIMessages.RefreshAction_Tooltip);
		hookKeyListener(control);
		init();
	}

	private void hookKeyListener(Control control) {
		control.addKeyListener(KeyListener.keyReleasedAdapter(e -> handleKeyReleased(e)));
	}

	@Override
	public void run() {
		refresh();
	}

	protected abstract void refresh();

	/**
	 * Handle a key released event.  Used internally and also
	 * made available so that clients can watch key events from
	 * any other controls and dispatch to this action.
	 * 
	 * @param event the key event
	 */
	public void handleKeyReleased(KeyEvent event) {
		if (event.keyCode == SWT.F5 && event.stateMask == 0) {
			refresh();
		}
	}
}

Back to the top