/*
 * Copyright 2020 DiffPlug
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.diffplug.common.swt.widgets;


import com.diffplug.common.base.Preconditions;
import com.diffplug.common.swt.ControlWrapper;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.Listener;

/** Added a control that uses an SWT Link to implement the standard Button interface. */
public class LinkBtn extends ControlWrapper.AroundControl<Link> {
	public LinkBtn(Composite parent, int style) {
		super(new Link(parent, SWT.NONE));
		Preconditions.checkArgument(style == SWT.PUSH, "LinkBtn only supports SWT.PUSH");
	}

	public void setText(String text) {
		wrapped.setText("<a>" + text + "</a>");
	}

	/** Returns the text. */
	public String getText() {
		String txt = wrapped.getText();
		return txt.substring("<a>".length(), txt.length() - "</a>".length());
	}

	/** Adds a listener. */
	public void addListener(int eventType, Listener listener) {
		wrapped.addListener(eventType, listener);
	}

	/** Removes a listener. */
	public void removeListener(int eventType, Listener listener) {
		wrapped.removeListener(eventType, listener);
	}

	/** Determines whether this FlatBtn is enabled or not. */
	public void setEnabled(boolean enabled) {
		wrapped.setEnabled(enabled);
	}
}

@@ -1856,11 +1856,270 @@
 led);%0A%09%7D
+%0A%0A%09/** Quick method to create a LinkBtn. */%0A%09public static LinkBtn create(Composite parent, String txt, Runnable action) %7B%0A%09%09LinkBtn btn = new LinkBtn(parent, SWT.PUSH);%0A%09%09btn.setText(txt);%0A%09%09btn.addListener(SWT.Selection, e -%3E action.run());%0A%09%09return btn;%0A%09%7D
 %0A%7D%0A

Add LinkBtn.create()