Project

General

Profile

Revision 47c992a7

ID47c992a7f2bdb3fbdadb2f8d5e6fd2f02023190a
Parent ca1b4808
Child ccf1adbd

Added by Patrick Plitzner over 1 year ago

ref #8129 Fix image disposing

  • refactoring

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/media/MediaDetailElement.java
76 76
                    }
77 77
                    singleMediaRepresentationPart.getMediaRepresentation().setMimeType(imageInfo.getMimeType());
78 78
                    singleMediaRepresentationPart.getMediaRepresentation().setSuffix(imageInfo.getSuffix());
79
                    disposeImage();
79 80
                    element_image = formFactory.createImageElement(parentFormElement, uri, style);
80 81
                    StoreUtil.reflowParentScrolledForm(getLayoutComposite(), true);
81 82
                    try {
82 83
                        element_image.initImageUri(uri);
83 84
                    } catch (IOException | HttpException e) {
84
                        exception(e, uri);
85
                        exception(e);
85 86
                    }
86 87
                    element_image.loadImage();
87 88
                    disposeErrorLabel();
88 89
                });
89 90
            } catch (IOException|HttpException e){
90
               exception(e, uri);
91
               exception(e);
91 92
            }
92 93
            return Status.OK_STATUS;
93 94
        }
......
145 146
        }
146 147
    }
147 148

  
148
    private void exception(Exception e, URI uri){
149
    private void exception(Exception e){
149 150
        getLayoutComposite().getDisplay().asyncExec(()->{
151
            String exceptionString;
150 152
            if(e.getCause()!=null && e.getCause().getClass().equals(ImageReadException.class)){
151 153
                disposeErrorLabel();
152
                handleException(uri, "No preview available for this file type");
154
                exceptionString = "No preview available for this file type";
153 155
            }
154 156
            else{
155 157
                disposeErrorLabel();
156
                handleException(uri, "No file found");
158
                exceptionString = "No file found";
157 159
            }
160
            disposeImage();
161
            if(lblNoImage==null){
162
            	lblNoImage = formFactory.createLabel(getLayoutComposite(), exceptionString);
163
                lblNoImage.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
164
                lblNoImage.setAlignment(SWT.CENTER);
165
            }
166
            getLayoutComposite().redraw();
158 167
        });
159 168
    }
160 169

  
170
    private void disposeImage(){
171
        if(element_image!=null){
172
            element_image.unloadImage();
173
            element_image.dispose();
174
            element_image = null;
175
        }
176
    }
177

  
161 178
	private void disposeErrorLabel() {
162 179
		if(lblNoImage!=null){
163 180
		    lblNoImage.dispose();
......
237 254
        isAdvancedMediaView =  false;
238 255
    }
239 256

  
240
    private void handleException(URI uri, String labelText) {
241
        if(element_image!=null){
242
            element_image.unloadImage();
243
            element_image.loadImage();
244
            element_image.dispose();
245
        }
246
        if(lblNoImage==null){
247
			lblNoImage = formFactory.createLabel(getLayoutComposite(), labelText);
248
            lblNoImage.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
249
            lblNoImage.setAlignment(SWT.CENTER);
250
        }
251
    }
252

  
253 257
    public boolean isAdvancedMediaView() {
254 258
        return isAdvancedMediaView;
255 259
    }

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)