Revision 6221b263
Added by Patrick Plitzner over 6 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/operation/MoveMediaInListOperation.java | ||
---|---|---|
1 | 1 |
/** |
2 | 2 |
* Copyright (C) 2007 EDIT |
3 |
* European Distributed Institute of Taxonomy
|
|
3 |
* European Distributed Institute of Taxonomy |
|
4 | 4 |
* http://www.e-taxonomy.eu |
5 |
*
|
|
5 |
* |
|
6 | 6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
7 | 7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
8 | 8 |
*/ |
... | ... | |
36 | 36 |
* @version 1.0 |
37 | 37 |
*/ |
38 | 38 |
public class MoveMediaInListOperation extends AbstractPostTaxonOperation { |
39 |
|
|
39 |
|
|
40 | 40 |
/** Constant <code>UP=1</code> */ |
41 |
public static final int UP = 1; |
|
41 |
public static final int UP = -1;
|
|
42 | 42 |
/** Constant <code>DOWN=-1</code> */ |
43 |
public static final int DOWN = -1;
|
|
44 |
|
|
43 |
public static final int DOWN = 1; |
|
44 |
|
|
45 | 45 |
private DescriptionBase description; |
46 | 46 |
private Media media; |
47 | 47 |
private int direction; |
... | ... | |
61 | 61 |
Taxon taxon, DescriptionBase description, Media media, |
62 | 62 |
int direction, IPostOperationEnabled postOperationEnabled) { |
63 | 63 |
super(label, undoContext, taxon, postOperationEnabled); |
64 |
|
|
64 |
|
|
65 | 65 |
this.description = description; |
66 | 66 |
this.media = media; |
67 | 67 |
this.direction = direction; |
... | ... | |
76 | 76 |
throws ExecutionException { |
77 | 77 |
|
78 | 78 |
monitor.worked(20); |
79 |
|
|
79 |
|
|
80 | 80 |
moveMedia(description, media, direction); |
81 | 81 |
monitor.worked(40); |
82 | 82 |
|
... | ... | |
89 | 89 |
/** {@inheritDoc} */ |
90 | 90 |
@Override |
91 | 91 |
public IStatus redo(IProgressMonitor monitor, IAdaptable info) |
92 |
throws ExecutionException {
|
|
92 |
throws ExecutionException { |
|
93 | 93 |
return execute(monitor, info); |
94 | 94 |
} |
95 | 95 |
|
... | ... | |
103 | 103 |
moveMedia(description, media, direction * -1); |
104 | 104 |
return postExecute(media); |
105 | 105 |
} |
106 |
|
|
106 |
|
|
107 | 107 |
private void moveMedia(DescriptionBase description, Media media, int direction){ |
108 | 108 |
Set<DescriptionElementBase> elements = description.getElements(); |
109 |
|
|
109 |
|
|
110 | 110 |
if(elements.size() != 1){ |
111 | 111 |
MessagingUtils.error(this.getClass(), Messages.MoveMediaInListOperation_MORE_DESC, null); |
112 | 112 |
} |
113 |
|
|
113 |
|
|
114 | 114 |
DescriptionElementBase element = elements.iterator().next(); |
115 |
|
|
115 |
|
|
116 | 116 |
List<Media> medias = element.getMedia(); |
117 |
|
|
117 |
|
|
118 | 118 |
int index = medias.indexOf(media); |
119 | 119 |
int newIndex = index + direction; |
120 |
|
|
120 |
|
|
121 | 121 |
if(index < 0){ |
122 | 122 |
return; |
123 | 123 |
} |
124 |
|
|
124 |
|
|
125 | 125 |
if (newIndex >= 0 && newIndex < medias.size()) { |
126 | 126 |
try{ |
127 | 127 |
Collections.swap(medias, newIndex, index); |
128 | 128 |
}catch(ArrayIndexOutOfBoundsException e){ |
129 | 129 |
MessagingUtils.error(this.getClass(), e); |
130 | 130 |
} |
131 |
}
|
|
131 |
} |
|
132 | 132 |
} |
133 | 133 |
} |
Also available in: Unified diff
ref #6906 Fix move operation