Merge branch 'release/5.19.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / openurl / OpenUrlSelectorElement.java
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 package eu.etaxonomy.taxeditor.ui.openurl;
10
11 import org.eclipse.core.runtime.IStatus;
12 import org.eclipse.jface.wizard.WizardDialog;
13 import org.eclipse.swt.SWT;
14 import org.eclipse.swt.events.SelectionEvent;
15 import org.eclipse.swt.events.SelectionListener;
16 import org.eclipse.swt.widgets.Button;
17 import org.eclipse.swt.widgets.Label;
18
19 import eu.etaxonomy.cdm.model.reference.Reference;
20 import eu.etaxonomy.taxeditor.model.MessagingUtils;
21 import eu.etaxonomy.taxeditor.ui.element.AbstractCdmFormElement;
22 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
23 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
24 import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
25
26 /**
27 * @author n.hoffmann
28 * @created Jan 31, 2011
29 */
30 public class OpenUrlSelectorElement extends AbstractCdmFormElement implements SelectionListener{
31
32 private Button button;
33
34 private Reference reference;
35
36 private String referenceDetail;
37
38 private IOpenUrlEnabled openUrlEnabled;
39
40 /**
41 * @param formFactory
42 * @param parentElement
43 * @param labelString
44 * @param initialUri
45 * @param textHeight
46 * @param style
47 */
48 public OpenUrlSelectorElement(CdmFormFactory formFactory,
49 ICdmFormElement parentElement, String labelString, IOpenUrlEnabled openUrlEnabled, int style) {
50 super(formFactory, parentElement);
51 this.openUrlEnabled = openUrlEnabled;
52
53 Label label = formFactory.createLabel(getLayoutComposite(), null);
54 addControl(label);
55
56 button = formFactory.createButton(getLayoutComposite(), labelString, SWT.PUSH);
57 button.setLayoutData(LayoutConstants.RIGHT());
58 addControl(button);
59 button.addSelectionListener(this);
60 }
61
62 @Override
63 public void widgetSelected(SelectionEvent e) {
64 if(openUrlEnabled.getReference() == null){
65 MessagingUtils.warningDialog("No reference", getClass(), "The given reference is empty");
66 return;
67 }
68
69 OpenUrlSelectorWizard wizard = new OpenUrlSelectorWizard(openUrlEnabled.getReference(), openUrlEnabled.getDetail());
70
71 WizardDialog dialog = new WizardDialog(getLayoutComposite().getShell(), wizard);
72
73 if(dialog.open() == IStatus.OK){
74 openUrlEnabled.setOpenUrl(wizard.getOpenUrlReference().getUri());
75 }
76 }
77
78 public String getDetail() {
79 return referenceDetail;
80 }
81
82 public void setDetail(String referenceDetail){
83 this.referenceDetail = referenceDetail;
84 }
85
86 @Override
87 public void widgetDefaultSelected(SelectionEvent e) {}
88
89 public void setReference(Reference reference) {
90 this.reference = reference;
91 }
92
93 public Reference getReference() {
94 return reference;
95 }
96 }