e7ef5ec0b227a867e3d6522b53d4c36cf154acef
[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.swt.SWT;
16 import org.eclipse.swt.widgets.Display;
17 import org.eclipse.swt.widgets.Label;
18
19 /**
20 * @author n.hoffmann
21 * @created Dec 20, 2010
22 * @version 1.0
23 */
24 public class UriWithLabelElement extends TextWithLabelElement {
25
26 private final Label labelException;
27
28 protected UriWithLabelElement(CdmFormFactory formFactory,
29 ICdmFormElement parentElement, String labelString,
30 URI initialUri, Integer textHeight, int style) {
31 super(formFactory, parentElement, labelString, null, textHeight, style);
32
33 labelException = formFactory.createLabel(getLayoutComposite(), "", SWT.WRAP);
34 labelException.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
35 addControl(labelException);
36 setUri(initialUri);
37 }
38
39 public void setUri(URI uri) {
40 if(uri != null){
41 super.setText(uri.toString());
42 }
43 }
44
45 public URI getUri(){
46 try {
47 labelException.setBackground(getPersistentBackground());
48 labelException.setText("");
49 return new URI(super.getText());
50 } catch (Exception e) {
51 labelException.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
52 labelException.setText(e.getMessage());
53 return null;
54 }
55 }
56
57 }