Java tutorial
/******************************************************************************* * Copyright (c) 2013 Obeo. * 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: * Obeo - initial API and implementation *******************************************************************************/ package org.obeonetwork.dsl.uml2.usage.dialog; import java.net.MalformedURLException; import java.net.URL; import org.eclipse.core.runtime.IStatus; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Link; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; import org.obeonetwork.dsl.uml2.usage.UsageActivator; import org.obeonetwork.dsl.uml2.usage.analytics.UsageMessages; /** * Dialog about enabling usage report through google analytics. * * @author Melanie Bats <a * href="mailto:melanie.bats@obeo.fr">melanie.bats@obeo.fr</a> */ public class UsageDialog extends Dialog { public UsageDialog(Shell parentShell) { super(parentShell); } @Override protected void configureShell(Shell shell) { super.configureShell(shell); shell.setText(UsageDialogMessages.Usage_Dialog_Title); } @Override protected Control createDialogArea(Composite parent) { Composite composite = (Composite) super.createDialogArea(parent); Link link = new Link(composite, SWT.NONE); String message = UsageDialogMessages.Usage_Dialog_Message; link.setText(message); link.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { try { // Open default external browser PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser().openURL(new URL(e.text)); } catch (PartInitException ex) { UsageActivator.log(IStatus.ERROR, UsageMessages.Error_OpeningUsageHyperlink, ex); } catch (MalformedURLException ex) { UsageActivator.log(IStatus.ERROR, UsageMessages.Error_OpeningUsageHyperlink, ex); } } }); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false) .hint(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH, SWT.DEFAULT).applyTo(link); applyDialogFont(composite); return composite; } @Override protected void createButtonsForButtonBar(Composite parent) { createButton(parent, IDialogConstants.YES_ID, IDialogConstants.YES_LABEL, false); createButton(parent, IDialogConstants.NO_ID, IDialogConstants.NO_LABEL, false); } @Override protected void buttonPressed(int buttonId) { // Close dialog setReturnCode(buttonId); close(); } }