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.dialog;
|
11
|
|
12
|
import java.net.URI;
|
13
|
import java.net.URISyntaxException;
|
14
|
|
15
|
import org.eclipse.jface.dialogs.IInputValidator;
|
16
|
import org.eclipse.jface.dialogs.InputDialog;
|
17
|
import org.eclipse.jface.window.Window;
|
18
|
import org.eclipse.swt.widgets.Shell;
|
19
|
|
20
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
21
|
|
22
|
/**
|
23
|
* <p>UriDialog class.</p>
|
24
|
*
|
25
|
* @author p.ciardelli
|
26
|
* @created 31.03.2009
|
27
|
* @version 1.0
|
28
|
*
|
29
|
* TODO make this extend TitleAreaDialog
|
30
|
*/
|
31
|
public class UriDialog extends InputDialog {
|
32
|
|
33
|
/**
|
34
|
* @param parentShell
|
35
|
* @param dialogTitle
|
36
|
* @param dialogMessage
|
37
|
* @param initialValue
|
38
|
* @param validator
|
39
|
*/
|
40
|
private UriDialog(Shell parentShell, String dialogTitle,
|
41
|
String dialogMessage) {
|
42
|
super(parentShell, dialogTitle,
|
43
|
dialogMessage, "http://", new IInputValidator() {
|
44
|
|
45
|
public String isValid(String text) {
|
46
|
|
47
|
try {
|
48
|
new URI(text);
|
49
|
} catch (URISyntaxException e) {
|
50
|
return "URL not correctly formed.";
|
51
|
}
|
52
|
|
53
|
|
54
|
if (text.length() <= "http://".length()) {
|
55
|
return "";
|
56
|
}
|
57
|
return null;
|
58
|
}
|
59
|
|
60
|
});
|
61
|
}
|
62
|
|
63
|
private URI getUri() {
|
64
|
URI uri = null;
|
65
|
try {
|
66
|
uri = new URI(getValue());
|
67
|
} catch (URISyntaxException e) {
|
68
|
MessagingUtils.error(getClass(), e);
|
69
|
}
|
70
|
return uri;
|
71
|
}
|
72
|
|
73
|
/**
|
74
|
* <p>getUri</p>
|
75
|
*
|
76
|
* @param shell a {@link org.eclipse.swt.widgets.Shell} object.
|
77
|
* @param dialogTitle a {@link java.lang.String} object.
|
78
|
* @param dialogMessage a {@link java.lang.String} object.
|
79
|
* @return a {@link java.net.URI} object.
|
80
|
*/
|
81
|
public static URI getUri(Shell shell, String dialogTitle,
|
82
|
String dialogMessage) {
|
83
|
UriDialog dialog = new UriDialog(shell,
|
84
|
dialogTitle,
|
85
|
dialogMessage);
|
86
|
if (dialog.open() == Window.CANCEL) {
|
87
|
return null;
|
88
|
}
|
89
|
return dialog.getUri();
|
90
|
}
|
91
|
}
|