fixes #1235 and #1228
[taxeditor.git] / taxeditor-editor / src / main / java / eu / etaxonomy / taxeditor / editor / descriptiontree / detailpage / ImageDetailsSection.java
1 /**
2 *
3 */
4 package eu.etaxonomy.taxeditor.editor.descriptiontree.detailpage;
5
6 import java.net.URI;
7 import java.net.URISyntaxException;
8
9 import org.eclipse.swt.SWT;
10 import org.eclipse.swt.events.SelectionEvent;
11 import org.eclipse.swt.events.SelectionListener;
12 import org.eclipse.swt.layout.GridData;
13 import org.eclipse.swt.widgets.Composite;
14
15 import eu.etaxonomy.cdm.common.CdmUtils;
16 import eu.etaxonomy.cdm.model.media.ImageFile;
17 import eu.etaxonomy.taxeditor.editor.EditorUtil;
18 import eu.etaxonomy.taxeditor.forms.ImageComposite;
19 import eu.etaxonomy.taxeditor.forms.TextActionComposite;
20
21 /**
22 * @author nho
23 *
24 */
25 public class ImageDetailsSection extends AbstractDescriptionDetailSection implements SelectionListener{
26
27 private TextActionComposite textAction;
28 private ImageComposite imageComposite;
29 private boolean changed = false;
30
31 /**
32 * @param parent
33 * @param page
34 * @param style
35 */
36 public ImageDetailsSection(Composite parent,
37 AbstractDescriptionDetailsPage page, int style) {
38 super(parent, page, style);
39
40 GridData layoutData = (GridData) getLayoutData();
41 layoutData.verticalAlignment = SWT.FILL;
42 layoutData.grabExcessVerticalSpace = true;
43
44 setText("Image Details"); //$NON-NLS-1$
45
46 textAction = toolkit.createTextActionComposite(getClient(), "Image Uri", null, SWT.WRAP);
47 textAction.addSelectionListener(this);
48
49 imageComposite = toolkit.createImageComposite(getClient(), null, SWT.WRAP);
50
51 // TODO
52 // imageMetadataComposite = FormFactory.createImageMetaDataComposite(getClient(), null, SWT.WRAP);
53 }
54
55 /* (non-Javadoc)
56 * @see eu.etaxonomy.taxeditor.editor.descriptiontree.detailpage.AbstractDescriptionDetailSection#updateSection()
57 */
58 @Override
59 public void updateSection() {
60 textAction.setText(getImageFile().getUri());
61 try {
62 imageComposite.setImageUri(new URI(CdmUtils.Nz(getImageFile().getUri())));
63 } catch (URISyntaxException e) {
64 // TODO remove this once cdmlib returns URIs where it seems like it does so
65 e.printStackTrace();
66 }
67 internalUpdateSection(changed);
68 changed = false;
69 }
70
71 private ImageFile getImageFile(){
72 return (ImageFile) page.input;
73 }
74
75 /* (non-Javadoc)
76 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
77 */
78 public void widgetSelected(SelectionEvent e) {
79 try {
80 // TODO simplify once cdmlib accepts URIs where it seems like it should
81 URI uri = new URI(textAction.getText());
82 getImageFile().setUri(uri.toString());
83 changed = true;
84 } catch (URISyntaxException e1) {
85 EditorUtil.warningDialog("Given image URI is not valid", "The image URI " +
86 "'" + textAction.getText() + "' is not valid. Please check the spelling.");
87 return;
88 }
89
90 updateSection();
91 }
92
93 public void widgetDefaultSelected(SelectionEvent e) {}
94 }