Project

General

Profile

« Previous | Next » 

Revision 59351073

Added by Niels Hoffmann almost 13 years ago

Improved image handling (fixes #2351); Passwords can now be changed by "admin" user (CAUTION: this is done by checking if the currently logged in user is the user named "admin", this has to change once rights are implemented correctly)

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/media/ImageFileElement.java
12 12

  
13 13
import java.io.IOException;
14 14
import java.net.URI;
15
import java.net.URISyntaxException;
16 15

  
17 16
import org.apache.commons.io.FileUtils;
18 17
import org.apache.commons.lang.StringUtils;
18
import org.apache.http.HttpException;
19 19
import org.eclipse.swt.events.SelectionListener;
20 20

  
21
import eu.etaxonomy.cdm.api.service.IMediaService;
22 21
import eu.etaxonomy.cdm.common.media.ImageInfo;
23 22
import eu.etaxonomy.cdm.model.media.ImageFile;
24
import eu.etaxonomy.taxeditor.store.CdmStore;
25 23
import eu.etaxonomy.taxeditor.store.StoreUtil;
26 24
import eu.etaxonomy.taxeditor.ui.forms.AbstractFormSection;
27 25
import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory;
......
29 27
import eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement;
30 28
import eu.etaxonomy.taxeditor.ui.forms.ImageElement;
31 29
import eu.etaxonomy.taxeditor.ui.forms.KeyValueViewerElement;
30
import eu.etaxonomy.taxeditor.ui.forms.LabelElement;
32 31
import eu.etaxonomy.taxeditor.ui.forms.NumberWithLabelElement;
33 32
import eu.etaxonomy.taxeditor.ui.section.supplemental.AbstractMediaRepresentationPartElement;
34 33

  
......
46 45
	private KeyValueViewerElement element_keyValue;
47 46
	private ImageElement element_image;
48 47
	
48
	private LabelElement element_messages;
49
	private Runnable postRunnable = new Runnable(){
50
		public void run() {
51
			StoreUtil.reflowDetailsViewer();
52
			StoreUtil.reflowSupplementalViewer();
53
		}
54
	};
55
	
56
	
49 57
	/**
50 58
	 * <p>Constructor for ImageFileElement.</p>
51 59
	 *
......
71 79
		text_width = formFactory.createIntegerTextWithLabelElement(formElement, "Width", null, style);
72 80
		text_width.setEnabled(false);
73 81
		element_image = formFactory.createImageElement(formElement, null, style);
74
		
82
		element_messages = formFactory.createLabel(formElement, "");
75 83
		element_keyValue = formFactory.createKeyValueViewerElement(formElement, "Key", "Value", null);
76 84
	}
77 85
	
......
79 87
	@Override
80 88
	public void setEntity(ImageFile entity) {
81 89
		this.entity = entity;
82
		if(entity.getUri() != null){
83
			text_uri.setText(entity.getUri().toString());
84
		}		
85 90
		if(entity.getSize() != null){
86 91
			text_size.setText(FileUtils.byteCountToDisplaySize(entity.getSize()));
87 92
		}
88 93
		text_height.setInteger(entity.getHeight());
89 94
		text_width.setInteger(entity.getWidth());
90

  
91
		showImage(entity.getUri());
95
		if(entity.getUri() != null){
96
			text_uri.setText(entity.getUri().toString());
97
		}
98
		try {
99
			showImage(entity.getUri());		
100
			element_messages.setText("");
101
		} catch (Exception e) {
102
			handleException(e);
103
		}
92 104
	}
93 105
	
94
	private void showImage(URI uri){
106
	private void showImage(URI uri) throws IOException, HttpException{
107
		element_image.initImageUri(uri);
108
		
109
		element_image.loadImage(postRunnable );
110
		
111
		
95 112
		if(uri == null){
96 113
			return;
97 114
		}
98
		try {
99
						
100
			try {
101
				
102
				ImageInfo imageInfo = ImageInfo.NewInstanceWithMetaData(uri, 10000);
103
					
104
				text_size.setText(FileUtils.byteCountToDisplaySize(imageInfo.getLength()));
105
				// KLUDGE this is not save for very large files. I don't think we will handle such large files in the near future
106
				getEntity().setSize((int) imageInfo.getLength());
107
				
108
				text_height.setInteger(imageInfo.getHeight());
109
				getEntity().setHeight(imageInfo.getHeight());
110
					
111
				text_width.setInteger(imageInfo.getWidth());
112
				getEntity().setWidth(imageInfo.getWidth());
113
				element_keyValue.setInput(imageInfo.getMetaData());
114
				
115
				element_image.setImageUri(uri);
116
				
117
				element_image.loadImage(new Runnable(){
118
					public void run() {
119
						StoreUtil.reflowDetailsViewer();
120
						StoreUtil.reflowSupplementalViewer();
121
					}
122
				});
115
		
116
		ImageInfo imageInfo = ImageInfo.NewInstanceWithMetaData(uri, 10000);
123 117
				
124
			} catch (IOException e) {
125
				StoreUtil.error(getClass(), e);
126
			}
127
		}  catch (Exception e) {
128
			StoreUtil.error(getClass(), "Image could not be shown: ", e);
129
		}
118
		text_size.setText(FileUtils.byteCountToDisplaySize(imageInfo.getLength()));
119
		// KLUDGE this is not save for very large files, because of the int cast. But then, I don't think we will handle such large files in the near future
120
		getEntity().setSize((int) imageInfo.getLength());
121
		
122
		text_height.setInteger(imageInfo.getHeight());
123
		getEntity().setHeight(imageInfo.getHeight());
124
			
125
		text_width.setInteger(imageInfo.getWidth());
126
		getEntity().setWidth(imageInfo.getWidth());
127
		element_keyValue.setInput(imageInfo.getMetaData());
128
		
129
		element_messages.setText("");
130 130
	}
131 131

  
132 132
	/*
......
142 142
				URI uri = StringUtils.isNotEmpty(uriString) ? new URI(uriString) : null;
143 143
				getEntity().setUri(uri);
144 144
				
145
				
145 146
				showImage(getEntity().getUri());
146

  
147
				
147 148
				firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
148
			} catch (URISyntaxException e) {
149
				StoreUtil.warningDialog("Could not parse URI", getClass(), e.getMessage());
150
			}			
149
			} catch (Exception e) {
150
				handleException(e);
151
			}
151 152
		}
152 153
		
153 154
	}
155

  
156
	private void handleException(Exception e) {
157
		element_messages.setText(e.getMessage());
158
		element_image.unloadImage(postRunnable);
159
		text_size.setText("");
160
		text_height.setInteger(0);
161
		text_width.setInteger(0);
162
		
163
		element_image.loadImage(new Runnable(){
164
			public void run() {
165
				StoreUtil.reflowDetailsViewer();
166
				StoreUtil.reflowSupplementalViewer();
167
			}
168
		});
169
	}
154 170
}

Also available in: Unified diff