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