Project

General

Profile

« Previous | Next » 

Revision ec683ee1

Added by Patrick Plitzner over 7 years ago

Enhance handling of simple and advanced media view

  • Buffer URI string in case of parsing errors
  • disable toggling when media conists of more than one representation or part

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/media/ImageFileElement.java
119 119
			try {
120 120
			    URI uri = text_uri.getUri();
121 121
				getEntity().setUri(uri);
122

  
122
				if(uri==null){
123
				    //buffer URI if parsing error occurred
124
				    MediaDetailElement parentMediaDetailElement = getParentMediaDetailElement();
125
				    if(parentMediaDetailElement!=null){
126
				        parentMediaDetailElement.setUriBuffer(text_uri.getText());
127
				    }
128
				}
123 129

  
124 130
				loadImage(getEntity().getUri(), true);
125 131

  
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.net.URI;
12 13
import java.util.List;
13 14
import java.util.Set;
14 15

  
......
16 17
import eu.etaxonomy.cdm.model.media.MediaRepresentation;
17 18
import eu.etaxonomy.cdm.model.media.MediaRepresentationPart;
18 19
import eu.etaxonomy.cdm.model.media.MediaUtils;
20
import eu.etaxonomy.taxeditor.model.MessagingUtils;
19 21
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
20 22
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
21 23
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
......
39 41
    private ICdmFormElement parentFormElement;
40 42
    private int style;
41 43

  
44
    /**
45
     * Used to store the URI even if it is invalid and thus cannot be stored in CDM
46
     */
47
    private String uriBuffer;
48

  
42 49
    public MediaDetailElement(CdmFormFactory formFactory, ICdmFormElement formElement) {
43 50
        super(formFactory, formElement);
44 51
    }
......
63 70
    public void handleEvent(Object eventSource){
64 71
        if(eventSource==textUri){
65 72
            textUri.setBackground(getPersistentBackground());
66
            singleMediaRepresentationPart.setUri(textUri.getUri());
73
            URI uri = textUri.getUri();
74
            singleMediaRepresentationPart.setUri(uri);
75
            if(uri==null){
76
                uriBuffer=textUri.getText();
77
            }
67 78
        }
68 79
    }
69 80

  
70
    public void toggleAdvancedMediaView(){
81
    public void toggleAdvancedMediaView() {
82
        if (getEntity().getRepresentations() != null
83
                && (getEntity().getRepresentations().size() > 1 ||
84
                        (getEntity().getRepresentations().size() == 1
85
                        && getEntity().getRepresentations().iterator().next().getParts().size() > 1))) {
86
            MessagingUtils.informationDialog("Toggling not possible",
87
                    "Media has consists of multiple representations or representatio parts");
88
            // toggling is only possible if there are no more than one
89
            // MediaRepresentation resp. MediaRepresentationParts
90
            return;
91
        }
71 92
        isAdvancedMediaView = !isAdvancedMediaView;
72 93
        showAdvancedView();
73 94
        reflowParentScrolledForm(true);
......
81 102
            section_mediaRepresentation = formFactory.createMediaRepresentationSection(getConversationHolder(), parentFormElement, style);
82 103
            section_mediaRepresentation.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
83 104
            section_mediaRepresentation.setEntity(getEntity());
105
            //set buffered uri as text if uri had parsing problems in simple view
106
            if(uriBuffer!=null){
107
                section_mediaRepresentation.getLayoutComposite().getChildren();
108
            }
84 109
        }
85 110
        else{
86 111
            if(section_mediaRepresentation!=null){
87 112
                removeElementsAndControls(section_mediaRepresentation);
88 113
            }
89 114
            textUri = formFactory.createUriWithLabelElement(parentFormElement, "Media URI", null, style);
90
            textUri.setUri(singleMediaRepresentationPart.getUri());
115
            URI uri = singleMediaRepresentationPart.getUri();
116
            textUri.setUri(uri);
117
            //set buffered uri as text if uri had parsing problems in advanced view
118
            if(uri==null && uriBuffer!=null){
119
                textUri.setText(uriBuffer);
120
                textUri.getUri();
121
            }
91 122
            textUri.getLayoutComposite().layout();
92 123
        }
93 124
    }
......
116 147
        return isAdvancedMediaView;
117 148
    }
118 149

  
150
    public void setUriBuffer(String uriBuffer) {
151
        this.uriBuffer = uriBuffer;
152
    }
153

  
154
    public String getUriBuffer() {
155
        return uriBuffer;
156
    }
157

  
119 158
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/media/MediaRepresentationPartElement.java
58 58
			text_size.setText(FileUtils.byteCountToDisplaySize(entity.getSize()));
59 59
		}
60 60
		if(entity.getUri() != null){
61
			text_uri.setText(entity.getUri().toString());
62
		}
61
			text_uri.setUri(entity.getUri());
62
		} else {
63
            String uriBuffer = getParentMediaDetailElement().getUriBuffer();
64
            if(uriBuffer!=null){
65
                text_uri.setText(uriBuffer);
66
                text_uri.getUri();//just to update the error label
67
            }
68
        }
63 69
	}
64 70

  
65 71
	@Override
......
67 73
		if(eventSource == text_uri){
68 74
		    URI uri = text_uri.getUri();
69 75
		    getEntity().setUri(uri);
76
		    if(uri==null){
77
                //buffer URI if parsing error occurred
78
                MediaDetailElement parentMediaDetailElement = getParentMediaDetailElement();
79
                if(parentMediaDetailElement!=null){
80
                    parentMediaDetailElement.setUriBuffer(text_uri.getText());
81
                }
82
            }
83

  
70 84
		    firePropertyChangeEvent(this);
71 85
		}
72 86
	}
73 87

  
88
    protected MediaDetailElement getParentMediaDetailElement() {
89
        ICdmFormElement parentElement = getParentElement();
90
        while(parentElement!=null){
91
            parentElement = parentElement.getParentElement();
92
            if(parentElement instanceof MediaDetailElement){
93
                return (MediaDetailElement) parentElement;
94
            }
95
        }
96
        return null;
97
    }
98

  
74 99
}

Also available in: Unified diff