65219a1cdd13b2022723b5175d4556493ee30052
[taxeditor.git] / eclipseprojects / eu.etaxonomy.taxeditor / src / eu / etaxonomy / taxeditor / editor / images / UrlDialog.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.editor.images;
12
13 import java.net.MalformedURLException;
14 import java.net.URL;
15
16 import org.apache.log4j.Logger;
17 import org.eclipse.jface.dialogs.IInputValidator;
18 import org.eclipse.jface.dialogs.InputDialog;
19 import org.eclipse.swt.widgets.Shell;
20
21 /**
22 * @author p.ciardelli
23 * @created 31.03.2009
24 * @version 1.0
25 */
26 public class UrlDialog extends InputDialog {
27 private static final Logger logger = Logger.getLogger(UrlDialog.class);
28 private URL url;
29
30 /**
31 * @param parentShell
32 * @param dialogTitle
33 * @param dialogMessage
34 * @param initialValue
35 * @param validator
36 */
37 public UrlDialog(Shell parentShell, String dialogTitle,
38 String dialogMessage) {
39 super(parentShell, "Enter image URL",
40 "Enter the new image's URL:", "http://", new IInputValidator() {
41
42 @Override
43 public String isValid(String text) {
44 URL url = null;
45 try {
46 url = new URL(text);
47 } catch (MalformedURLException e) {
48 return "URL not correctly formed.";
49 }
50
51 if (text.length() <= "http://".length()) {
52 return "";
53 }
54
55 return null;
56 }
57
58 });
59 }
60
61 public URL getUrl() {
62 URL url = null;
63 try {
64 url = new URL(getValue());
65 } catch (MalformedURLException e) {
66 // TODO Auto-generated catch block
67 e.printStackTrace();
68 }
69 return url;
70 }
71 }