Project

General

Profile

Download (3.11 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy 
4
* http://www.e-taxonomy.eu
5
* 
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9

    
10
package eu.etaxonomy.taxeditor.ui.openurl;
11

    
12
import org.eclipse.core.runtime.IStatus;
13
import org.eclipse.jface.wizard.WizardDialog;
14
import org.eclipse.swt.SWT;
15
import org.eclipse.swt.events.SelectionEvent;
16
import org.eclipse.swt.events.SelectionListener;
17
import org.eclipse.swt.widgets.Button;
18
import org.eclipse.swt.widgets.Label;
19

    
20
import eu.etaxonomy.cdm.model.reference.Reference;
21
import eu.etaxonomy.taxeditor.model.MessagingUtils;
22
import eu.etaxonomy.taxeditor.ui.element.AbstractCdmFormElement;
23
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
24
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
25
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
26

    
27
/**
28
 * @author n.hoffmann
29
 * @created Jan 31, 2011
30
 * @version 1.0
31
 */
32
public class OpenUrlSelectorElement extends AbstractCdmFormElement implements SelectionListener{
33

    
34
	private Button button;
35
	
36
	private Reference reference;
37
	
38
	private String referenceDetail;
39

    
40
	private IOpenUrlEnabled openUrlEnabled;
41
	
42
	/**
43
	 * @param formFactory
44
	 * @param parentElement
45
	 * @param labelString
46
	 * @param initialUri
47
	 * @param textHeight
48
	 * @param style
49
	 */
50
	public OpenUrlSelectorElement(CdmFormFactory formFactory,
51
			ICdmFormElement parentElement, String labelString, IOpenUrlEnabled openUrlEnabled, int style) {
52
		super(formFactory, parentElement);
53
		this.openUrlEnabled = openUrlEnabled;
54
		
55
		Label label = formFactory.createLabel(getLayoutComposite(), null);
56
		addControl(label);
57
		
58
		button = formFactory.createButton(getLayoutComposite(), labelString, SWT.PUSH);
59
		button.setLayoutData(LayoutConstants.RIGHT());
60
		addControl(button);
61
		button.addSelectionListener(this);
62
	}
63

    
64
	/* (non-Javadoc)
65
	 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
66
	 */
67
	@Override
68
	public void widgetSelected(SelectionEvent e) {
69
		if(openUrlEnabled.getReference() == null){
70
			MessagingUtils.warningDialog("No reference", getClass(), "The given reference is empty");
71
			return;
72
		}
73
		
74
		OpenUrlSelectorWizard wizard = new OpenUrlSelectorWizard(openUrlEnabled.getReference(), openUrlEnabled.getDetail());
75
		
76
		WizardDialog dialog = new WizardDialog(getLayoutComposite().getShell(), wizard);
77
		
78
		if(dialog.open() == IStatus.OK){
79
			openUrlEnabled.setOpenUrl(wizard.getOpenUrlReference().getUri());
80
		}
81
	}
82

    
83
	/**
84
	 * @return
85
	 */
86
	public String getDetail() {
87
		return referenceDetail;
88
	}
89
	
90
	public void setDetail(String referenceDetail){
91
		this.referenceDetail = referenceDetail;
92
	}
93

    
94
	/* (non-Javadoc)
95
	 * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
96
	 */
97
	@Override
98
	public void widgetDefaultSelected(SelectionEvent e) {}
99

    
100
	/**
101
	 * @param reference the reference to set
102
	 */
103
	public void setReference(Reference reference) {
104
		this.reference = reference;
105
	}
106

    
107
	/**
108
	 * @return the reference
109
	 */
110
	public Reference getReference() {
111
		return reference;
112
	}
113
}
(6-6/7)