blob: af9038340c9a598836f1f92c6703f617022cad92 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
/*******************************************************************************
* Copyright (c) 2004, 2008 John Krasnay and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* John Krasnay - initial API and implementation
*******************************************************************************/
package org.eclipse.vex.ui.internal.handlers;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.vex.core.provisional.dom.ContentRange;
import org.eclipse.vex.ui.internal.handlers.VexHandlerUtil.SelectedRows;
import org.eclipse.vex.ui.internal.swt.VexWidget;
/**
* Moves the current table row either down below its next sibling or up above its previous sibling.
*
* @see MoveRowUpHandler
* @see MoveRowDownHandler
*/
public abstract class AbstractMoveRowHandler extends AbstractVexWidgetHandler {
@Override
public void execute(final VexWidget widget) throws ExecutionException {
final VexHandlerUtil.SelectedRows selected = VexHandlerUtil.getSelectedTableRows(widget);
if (selected.getRows() == null || targetRow(selected) == null) {
return;
}
widget.doWork(true, new Runnable() {
public void run() {
final ContentRange range = VexHandlerUtil.getOuterRange(targetRow(selected));
widget.moveTo(range.getStartOffset());
widget.moveTo(range.getEndOffset(), true);
widget.cutSelection();
widget.moveTo(target(selected));
widget.paste();
}
});
}
/**
* @param selected
* current selected row
* @return the row with which to switch current row
*/
protected abstract Object targetRow(SelectedRows selected);
/**
* @param selected
* current selected row
* @return offset where to move to
*/
protected abstract int target(SelectedRows selected);
}
|