| /** |
| * |
| * Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany) |
| * |
| * 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: |
| * Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation |
| */ |
| package org.eclipse.osbp.preferences.ui.component; |
| |
| import java.awt.Desktop; |
| import java.io.File; |
| import java.net.URI; |
| |
| import org.eclipse.core.filesystem.EFS; |
| import org.eclipse.core.filesystem.IFileStore; |
| import org.eclipse.jface.preference.FieldEditor; |
| import org.eclipse.swt.SWT; |
| import org.eclipse.swt.events.SelectionEvent; |
| import org.eclipse.swt.events.SelectionListener; |
| import org.eclipse.swt.layout.GridData; |
| import org.eclipse.swt.widgets.Button; |
| import org.eclipse.swt.widgets.Composite; |
| import org.eclipse.swt.widgets.Event; |
| import org.eclipse.swt.widgets.Label; |
| import org.eclipse.swt.widgets.Link; |
| import org.eclipse.swt.widgets.Listener; |
| import org.eclipse.ui.IWorkbenchPage; |
| import org.eclipse.ui.PartInitException; |
| import org.eclipse.ui.PlatformUI; |
| import org.eclipse.ui.ide.IDE; |
| |
| public class LinkFieldEditor extends FieldEditor { |
| |
| public class WebLinkListener implements Listener { |
| |
| @Override |
| public void handleEvent(Event event) { |
| try { |
| Desktop.getDesktop().browse(new URI(event.text)); |
| } |
| catch (Exception e) { |
| e.printStackTrace(); |
| } |
| } |
| } |
| |
| private boolean isValid; |
| private String oldValue; |
| private String compTitle; |
| private Label title; |
| private Link urlLink; |
| |
| protected LinkFieldEditor() { |
| } |
| |
| public LinkFieldEditor(String name, String labelText, Composite parent) { |
| init(name, labelText); |
| createControl(parent); |
| } |
| |
| protected boolean checkState() { |
| return true; |
| } |
| |
| protected boolean doCheckState() { |
| return true; |
| } |
| |
| @Override |
| protected void doFillIntoGrid(Composite parent, int numColumns) { |
| title = new Label(parent, SWT.UP); |
| title.setFont(parent.getFont()); |
| title.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); |
| title.setVisible(false); |
| |
| urlLink = new Link(parent, SWT.NONE); |
| GridData gd = new GridData(GridData.FILL_HORIZONTAL); |
| gd.widthHint = 100; |
| urlLink.setLayoutData(gd); |
| urlLink.setFont(parent.getFont()); |
| //urlLink.setText(getPreferenceStore().getString(getPreferenceName())); |
| urlLink.addListener(SWT.Selection, new WebLinkListener()); |
| urlLink.setEnabled(true); |
| } |
| |
| @Override |
| protected void doLoad() { |
| urlLink.setText(getPreferenceStore().getString(getPreferenceName())); |
| } |
| |
| @Override |
| protected void doLoadDefault() { |
| } |
| |
| @Override |
| protected void doStore() { |
| } |
| |
| @Override |
| public int getNumberOfControls() { |
| return 2; |
| } |
| |
| public String getStringValue() { |
| return null; |
| } |
| |
| @Override |
| public boolean isValid() { |
| return true; |
| } |
| |
| @Override |
| protected void adjustForNumColumns(int numColumns) { |
| } |
| } |