Project

General

Profile

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

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

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

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

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

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

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

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

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

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

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

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