Externalize strings
[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 import eu.etaxonomy.taxeditor.Messages;
21
22 /**
23 * @author n.hoffmann
24 * @created Dec 20, 2010
25 * @version 1.0
26 */
27 public class UriWithLabelElement extends TextWithLabelElement {
28
29 private final Label labelException;
30
31 protected UriWithLabelElement(CdmFormFactory formFactory,
32 ICdmFormElement parentElement, String labelString,
33 URI initialUri, Integer textHeight, int style) {
34 super(formFactory, parentElement, labelString, null, textHeight, style);
35
36 labelException = formFactory.createLabel(getLayoutComposite(), "", SWT.WRAP); //$NON-NLS-1$
37 labelException.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
38 addControl(labelException);
39 setUri(initialUri);
40 }
41
42 public void setUri(URI uri) {
43 if(uri != null){
44 super.setText(uri.toString());
45 }
46 }
47
48 public URI getUri(){
49 try {
50 labelException.setFont(JFaceResources.getFontRegistry().get(JFaceResources.DEFAULT_FONT));
51 labelException.setForeground(getPersistentBackground());
52 labelException.setText(""); //$NON-NLS-1$
53 return new URI(super.getText());
54 } catch (Exception e) {
55 labelException.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT));
56 labelException.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
57 labelException.setText(Messages.UriWithLabelElement_URL_NOT_SAVED+e.getMessage());
58 return null;
59 }
60 }
61
62 }