Warn user that URL will not be saved in bold and red (#5065, #5141)
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / element / UriWithLabelElement.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.element;
12
13 import java.net.URI;
14
15 import org.eclipse.jface.resource.JFaceResources;
16 import org.eclipse.swt.SWT;
17 import org.eclipse.swt.widgets.Display;
18 import org.eclipse.swt.widgets.Label;
19
20 /**
21 * @author n.hoffmann
22 * @created Dec 20, 2010
23 * @version 1.0
24 */
25 public class UriWithLabelElement extends TextWithLabelElement {
26
27 private final Label labelException;
28
29 protected UriWithLabelElement(CdmFormFactory formFactory,
30 ICdmFormElement parentElement, String labelString,
31 URI initialUri, Integer textHeight, int style) {
32 super(formFactory, parentElement, labelString, null, textHeight, style);
33
34 labelException = formFactory.createLabel(getLayoutComposite(), "", SWT.WRAP);
35 labelException.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
36 addControl(labelException);
37 setUri(initialUri);
38 }
39
40 public void setUri(URI uri) {
41 if(uri != null){
42 super.setText(uri.toString());
43 }
44 }
45
46 public URI getUri(){
47 try {
48 labelException.setFont(JFaceResources.getFontRegistry().get(JFaceResources.DEFAULT_FONT));
49 labelException.setForeground(getPersistentBackground());
50 labelException.setText("");
51 return new URI(super.getText());
52 } catch (Exception e) {
53 labelException.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT));
54 labelException.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
55 labelException.setText("URL won't be saved! "+e.getMessage());
56 return null;
57 }
58 }
59
60 }