Project

General

Profile

« Previous | Next » 

Revision b9c5a9df

Added by Patrick Plitzner over 8 years ago

Refactored image loading

  • fix some NPEs

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/media/MediaDetailElement.java
9 9
*/
10 10
package eu.etaxonomy.taxeditor.ui.section.media;
11 11

  
12
import java.io.IOException;
13 12
import java.net.URI;
14 13
import java.util.List;
15 14
import java.util.Set;
16 15

  
17
import org.apache.http.HttpException;
18 16
import org.eclipse.swt.SWT;
19 17
import org.eclipse.swt.widgets.Label;
20 18

  
......
85 83
                uriBuffer=textUri.getText();
86 84
            }
87 85
            else{
86
                createImageElement(uri);
87
            }
88
        }
89
    }
88 90

  
89
                ImageInfo imageInfo;
90
                try {
91
                    imageInfo = ImageInfo.NewInstance(uri, 10000);
92
                    singleMediaRepresentationPart.getMediaRepresentation().setMimeType(imageInfo.getMimeType());
93
                    singleMediaRepresentationPart.getMediaRepresentation().setSuffix(imageInfo.getSuffix());
94
                    element_image = formFactory.createImageElement(parentFormElement, uri, style);
95
                    loadImage(singleMediaRepresentationPart.getUri());
96
                } catch (Exception e) {
97
                    handleException();
98
                }
91
    private void createImageElement(URI uri) {
92
        ImageInfo imageInfo;
93
        try {
94
            imageInfo = ImageInfo.NewInstance(uri, 10000);
95
            singleMediaRepresentationPart.getMediaRepresentation().setMimeType(imageInfo.getMimeType());
96
            singleMediaRepresentationPart.getMediaRepresentation().setSuffix(imageInfo.getSuffix());
97
            element_image = formFactory.createImageElement(parentFormElement, uri, style);
98
            element_image.initImageUri(uri);
99
            element_image.loadImage();
100
            if(uri == null){
101
                return;
102
            }
103
            if(lblNoImage!=null){
104
                lblNoImage.dispose();
99 105
            }
106
            lblNoImage = null;
107
        } catch (Exception e) {
108
            handleException();
100 109
        }
101 110
    }
102 111

  
......
147 156
            }
148 157
            textUri.getLayoutComposite().layout();
149 158

  
150
            element_image = formFactory.createImageElement(parentFormElement, null, style);
151
            try {
152
                loadImage(singleMediaRepresentationPart.getUri());
153
            } catch (Exception e) {
154
                handleException();
155
            }
159
            createImageElement(singleMediaRepresentationPart.getUri());
156 160
        }
157 161
    }
158 162

  
......
176 180
        isAdvancedMediaView =  false;
177 181
    }
178 182

  
179
    private void loadImage(URI uri) throws IOException, HttpException{
180
        element_image.initImageUri(uri);
181
        element_image.loadImage();
182
        if(uri == null){
183
            return;
184
        }
185
        lblNoImage.dispose();
186
        lblNoImage = null;
187
    }
188

  
189 183
    private void handleException() {
190
        element_image.unloadImage();
191
        element_image.loadImage();
192
        element_image.dispose();
184
        if(element_image!=null){
185
            element_image.unloadImage();
186
            element_image.loadImage();
187
            element_image.dispose();
188
        }
193 189
        if(lblNoImage==null){
194 190
            lblNoImage = formFactory.createLabel(getLayoutComposite(), "No Image found");
195 191
            lblNoImage.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));

Also available in: Unified diff