Revision a904e4d0
Added by Katja Luther over 6 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/MediaLabelProvider.java | ||
---|---|---|
12 | 12 |
* @version $Id: $ |
13 | 13 |
*/ |
14 | 14 |
public class MediaLabelProvider extends ColumnLabelProvider { |
15 |
|
|
15 |
|
|
16 | 16 |
/** {@inheritDoc} */ |
17 |
public String getText(Object element) { |
|
17 |
@Override |
|
18 |
public String getText(Object element) { |
|
18 | 19 |
if(element instanceof IdentifiableEntity){ |
19 | 20 |
return ((IdentifiableEntity) element).getTitleCache(); |
20 | 21 |
} |
21 |
|
|
22 |
|
|
22 | 23 |
return element.toString(); |
23 | 24 |
} |
25 |
|
|
26 |
|
|
27 |
|
|
24 | 28 |
} |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/MediaViewLabelProvider.java | ||
---|---|---|
1 |
// $Id$ |
|
2 |
/** |
|
3 |
* Copyright (C) 2017 EDIT |
|
4 |
* European Distributed Institute of Taxonomy |
|
5 |
* http://www.e-taxonomy.eu |
|
6 |
* |
|
7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
9 |
*/ |
|
10 |
package eu.etaxonomy.taxeditor.editor.view.media; |
|
11 |
|
|
12 |
import java.io.InputStream; |
|
13 |
import java.net.URI; |
|
14 |
import java.util.List; |
|
15 |
import java.util.Set; |
|
16 |
|
|
17 |
import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider; |
|
18 |
import org.eclipse.jface.viewers.LabelProvider; |
|
19 |
import org.eclipse.jface.viewers.StyledString; |
|
20 |
import org.eclipse.swt.SWT; |
|
21 |
import org.eclipse.swt.graphics.GC; |
|
22 |
import org.eclipse.swt.graphics.Image; |
|
23 |
import org.eclipse.swt.widgets.Display; |
|
24 |
|
|
25 |
import eu.etaxonomy.cdm.common.UriUtils; |
|
26 |
import eu.etaxonomy.cdm.model.common.IdentifiableEntity; |
|
27 |
import eu.etaxonomy.cdm.model.media.Media; |
|
28 |
import eu.etaxonomy.cdm.model.media.MediaRepresentation; |
|
29 |
import eu.etaxonomy.cdm.model.media.MediaRepresentationPart; |
|
30 |
import eu.etaxonomy.taxeditor.preference.PreferencesUtil; |
|
31 |
|
|
32 |
/** |
|
33 |
* @author k.luther |
|
34 |
* @date 11.10.2017 |
|
35 |
* |
|
36 |
*/ |
|
37 |
public class MediaViewLabelProvider extends LabelProvider implements IStyledLabelProvider { |
|
38 |
|
|
39 |
@Override |
|
40 |
public StyledString getStyledText(Object element) { |
|
41 |
if (element instanceof IdentifiableEntity) { |
|
42 |
IdentifiableEntity identifiableEntity= (IdentifiableEntity) element; |
|
43 |
StyledString styledString = new StyledString(identifiableEntity.getTitleCache()); |
|
44 |
|
|
45 |
return styledString; |
|
46 |
} |
|
47 |
return null; |
|
48 |
} |
|
49 |
|
|
50 |
@Override |
|
51 |
public Image getImage(Object element) { |
|
52 |
Image image = null; |
|
53 |
if (element instanceof Media && PreferencesUtil.isShowMediaPreview()){ |
|
54 |
Set<MediaRepresentation> representations = ((Media)element).getRepresentations(); |
|
55 |
if(representations.iterator().hasNext()){ |
|
56 |
MediaRepresentation rep = representations.iterator().next(); |
|
57 |
List<MediaRepresentationPart> parts = rep.getParts(); |
|
58 |
URI uri = parts.get(0).getUri(); |
|
59 |
if (uri == null){ |
|
60 |
return null; |
|
61 |
} |
|
62 |
InputStream imageStream; |
|
63 |
try { |
|
64 |
imageStream = UriUtils.getInputStream(uri); |
|
65 |
image = new Image(Display.getCurrent(), imageStream); |
|
66 |
int height = image.getBounds().height; |
|
67 |
int width = image.getBounds().width; |
|
68 |
int scale = 50; |
|
69 |
if (height>width){ |
|
70 |
width = width/(height/scale); |
|
71 |
height = scale; |
|
72 |
}else{ |
|
73 |
height = height/(width/scale); |
|
74 |
width = scale; |
|
75 |
} |
|
76 |
Image scaled = new Image(Display.getDefault(), scale, scale); |
|
77 |
|
|
78 |
GC gc = new GC(scaled); |
|
79 |
gc.setAntialias(SWT.ON); |
|
80 |
gc.setInterpolation(SWT.HIGH); |
|
81 |
|
|
82 |
|
|
83 |
gc.drawImage(image, 0, 0, |
|
84 |
image.getBounds().width, image.getBounds().height, |
|
85 |
0, 0, width, height); |
|
86 |
|
|
87 |
gc.dispose(); |
|
88 |
image.dispose(); // don't forget about me! |
|
89 |
return scaled; |
|
90 |
|
|
91 |
} catch (Exception e) { |
|
92 |
// TODO Auto-generated catch block |
|
93 |
return null; |
|
94 |
} |
|
95 |
|
|
96 |
} |
|
97 |
|
|
98 |
} |
|
99 |
return image; |
|
100 |
} |
|
101 |
|
|
102 |
@Override |
|
103 |
public void dispose() { |
|
104 |
// garbage collection system resources |
|
105 |
|
|
106 |
} |
|
107 |
|
|
108 |
|
|
109 |
|
|
110 |
} |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/e4/MediaViewPartE4.java | ||
---|---|---|
28 | 28 |
import eu.etaxonomy.taxeditor.editor.view.concept.e4.ConceptViewPartE4; |
29 | 29 |
import eu.etaxonomy.taxeditor.editor.view.descriptive.e4.FactualDataPartE4; |
30 | 30 |
import eu.etaxonomy.taxeditor.editor.view.media.MediaContentProvider; |
31 |
import eu.etaxonomy.taxeditor.editor.view.media.MediaLabelProvider; |
|
31 |
import eu.etaxonomy.taxeditor.editor.view.media.MediaViewLabelProvider;
|
|
32 | 32 |
import eu.etaxonomy.taxeditor.model.AbstractUtility; |
33 | 33 |
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails; |
34 | 34 |
import eu.etaxonomy.taxeditor.model.IPartContentHasMedia; |
... | ... | |
54 | 54 |
| SWT.V_SCROLL | SWT.FULL_SELECTION)); |
55 | 55 |
|
56 | 56 |
treeViewer.setContentProvider(new MediaContentProvider()); |
57 |
treeViewer.setLabelProvider(new MediaLabelProvider()); |
|
57 |
treeViewer.setLabelProvider(new MediaViewLabelProvider()); |
|
58 |
|
|
59 |
// TreeViewerColumn imagePreview = new TreeViewerColumn(treeViewer, SWT.NONE); |
|
60 |
// imagePreview.setLabelProvider(new DelegatingStyledCellLabelProvider( |
|
61 |
// new MediaViewLabelProvider(createImageDescriptor()))); |
|
62 |
|
|
58 | 63 |
treeViewer.setAutoExpandLevel(2); |
59 | 64 |
viewer = treeViewer; |
60 | 65 |
|
... | ... | |
127 | 132 |
return Messages.MediaViewPart_MEDIA; |
128 | 133 |
} |
129 | 134 |
|
135 |
|
|
136 |
|
|
130 | 137 |
} |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/IPreferenceKeys.java | ||
---|---|---|
146 | 146 |
public static final String CHECKLIST_SYMBOL = "eu.etaxonomy.taxeditor.checklist.checklistSymbol"; |
147 | 147 |
public static final String CHECKLIST_SHOW_RANK = "eu.etaxonomy.taxeditor.checklist.checklistShowRank"; |
148 | 148 |
|
149 |
public static final String SHOW_ADVANCED_MEDIA_SECTION = "eu.etaxonomy.taxeditor.media.showAdvancedMedia"; |
|
149 |
|
|
150 | 150 |
public static final String SHOW_SIMPLE_NAME_DETAILS_SECTION = "eu.etaxonomy.taxeditor.name.showSimpleName"; |
151 | 151 |
public static final String SHOW_SIMPLE_NAME_DETAILS_TAXON = "eu.etaxonomy.taxeditor.name.showNameTaxon"; |
152 | 152 |
public static final String SHOW_NAME_DETAILS_SECTION_LSID = "eu.etaxonomy.taxeditor.name.showNameLsid"; |
... | ... | |
217 | 217 |
|
218 | 218 |
public static final String BIOCASE_PROVIDER_LIST = "eu.etaxonomy.taxeditor.abcd_import.biocaseProviderList"; |
219 | 219 |
|
220 |
public static final String SHOW_ADVANCED_MEDIA_SECTION = "eu.etaxonomy.taxeditor.media.showAdvancedMedia"; |
|
221 |
public static final String SHOW_MEDIA_PREVIEW = "eu.etaxonomy.taxeditor.media.showMediaPreview"; |
|
222 |
|
|
220 | 223 |
|
221 | 224 |
|
222 | 225 |
|
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/MediaPreferences.java | ||
---|---|---|
36 | 36 |
addField(new BooleanFieldEditor(IPreferenceKeys.SHOW_ADVANCED_MEDIA_SECTION, |
37 | 37 |
"Show Advanced Media Section", |
38 | 38 |
getFieldEditorParent())); |
39 |
addField(new BooleanFieldEditor(IPreferenceKeys.SHOW_MEDIA_PREVIEW, |
|
40 |
"Show Preview in Media View", |
|
41 |
getFieldEditorParent())); |
|
39 | 42 |
|
40 | 43 |
} |
41 | 44 |
|
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/PreferencesUtil.java | ||
---|---|---|
267 | 267 |
return null; |
268 | 268 |
} |
269 | 269 |
|
270 |
public static boolean isShowMediaPreview(){ |
|
271 |
boolean isShowMediaPreview = getPreferenceStore().getBoolean(SHOW_MEDIA_PREVIEW); |
|
272 |
return isShowMediaPreview; |
|
273 |
} |
|
274 |
|
|
270 | 275 |
/** |
271 | 276 |
* Get the match strategy for the given class that was stored in preferences |
272 | 277 |
* or the default strategy if it was not stored in preferences |
Also available in: Unified diff
ref #7056: add possibility to show preview of the image in media view