refactored folder structure
[taxeditor.git] / 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 }