Revision 3be6ef3e
Added by Niels Hoffmann over 13 years ago
taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/dialogs/UriDialog.java | ||
---|---|---|
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.dialogs; |
|
12 |
|
|
13 |
import java.net.URI; |
|
14 |
import java.net.URISyntaxException; |
|
15 |
|
|
16 |
import org.eclipse.jface.dialogs.IInputValidator; |
|
17 |
import org.eclipse.jface.dialogs.InputDialog; |
|
18 |
import org.eclipse.jface.window.Window; |
|
19 |
import org.eclipse.swt.widgets.Shell; |
|
20 |
|
|
21 |
/** |
|
22 |
* @author p.ciardelli |
|
23 |
* @created 31.03.2009 |
|
24 |
* @version 1.0 |
|
25 |
* |
|
26 |
* TODO make this extend TitleAreaDialog |
|
27 |
*/ |
|
28 |
public class UriDialog extends InputDialog { |
|
29 |
|
|
30 |
/** |
|
31 |
* @param parentShell |
|
32 |
* @param dialogTitle |
|
33 |
* @param dialogMessage |
|
34 |
* @param initialValue |
|
35 |
* @param validator |
|
36 |
*/ |
|
37 |
private UriDialog(Shell parentShell, String dialogTitle, |
|
38 |
String dialogMessage) { |
|
39 |
super(parentShell, dialogTitle, |
|
40 |
dialogMessage, "http://", new IInputValidator() { |
|
41 |
|
|
42 |
public String isValid(String text) { |
|
43 |
|
|
44 |
try { |
|
45 |
new URI(text); |
|
46 |
} catch (URISyntaxException e) { |
|
47 |
return "URL not correctly formed."; |
|
48 |
} |
|
49 |
|
|
50 |
|
|
51 |
if (text.length() <= "http://".length()) { |
|
52 |
return ""; |
|
53 |
} |
|
54 |
return null; |
|
55 |
} |
|
56 |
|
|
57 |
}); |
|
58 |
} |
|
59 |
|
|
60 |
private URI getUri() { |
|
61 |
URI uri = null; |
|
62 |
try { |
|
63 |
uri = new URI(getValue()); |
|
64 |
} catch (URISyntaxException e) { |
|
65 |
// TODO Auto-generated catch block |
|
66 |
e.printStackTrace(); |
|
67 |
} |
|
68 |
return uri; |
|
69 |
} |
|
70 |
|
|
71 |
public static URI getUri(Shell shell, String dialogTitle, |
|
72 |
String dialogMessage) { |
|
73 |
UriDialog dialog = new UriDialog(shell, |
|
74 |
dialogTitle, |
|
75 |
dialogMessage); |
|
76 |
if (dialog.open() == Window.CANCEL) { |
|
77 |
return null; |
|
78 |
} |
|
79 |
return dialog.getUri(); |
|
80 |
} |
|
81 |
} |
|
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.dialogs; |
|
12 |
|
|
13 |
import java.net.URI; |
|
14 |
import java.net.URISyntaxException; |
|
15 |
|
|
16 |
import org.eclipse.jface.dialogs.IInputValidator; |
|
17 |
import org.eclipse.jface.dialogs.InputDialog; |
|
18 |
import org.eclipse.jface.window.Window; |
|
19 |
import org.eclipse.swt.widgets.Shell; |
|
20 |
|
|
21 |
/** |
|
22 |
* <p>UriDialog class.</p> |
|
23 |
* |
|
24 |
* @author p.ciardelli |
|
25 |
* @created 31.03.2009 |
|
26 |
* @version 1.0 |
|
27 |
* |
|
28 |
* TODO make this extend TitleAreaDialog |
|
29 |
*/ |
|
30 |
public class UriDialog extends InputDialog { |
|
31 |
|
|
32 |
/** |
|
33 |
* @param parentShell |
|
34 |
* @param dialogTitle |
|
35 |
* @param dialogMessage |
|
36 |
* @param initialValue |
|
37 |
* @param validator |
|
38 |
*/ |
|
39 |
private UriDialog(Shell parentShell, String dialogTitle, |
|
40 |
String dialogMessage) { |
|
41 |
super(parentShell, dialogTitle, |
|
42 |
dialogMessage, "http://", new IInputValidator() { |
|
43 |
|
|
44 |
public String isValid(String text) { |
|
45 |
|
|
46 |
try { |
|
47 |
new URI(text); |
|
48 |
} catch (URISyntaxException e) { |
|
49 |
return "URL not correctly formed."; |
|
50 |
} |
|
51 |
|
|
52 |
|
|
53 |
if (text.length() <= "http://".length()) { |
|
54 |
return ""; |
|
55 |
} |
|
56 |
return null; |
|
57 |
} |
|
58 |
|
|
59 |
}); |
|
60 |
} |
|
61 |
|
|
62 |
private URI getUri() { |
|
63 |
URI uri = null; |
|
64 |
try { |
|
65 |
uri = new URI(getValue()); |
|
66 |
} catch (URISyntaxException e) { |
|
67 |
// TODO Auto-generated catch block |
|
68 |
e.printStackTrace(); |
|
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 |
} |
Also available in: Unified diff
performed javacscript:fix and worked on documentation