1 11 package org.eclipse.jdt.internal.debug.ui.actions; 12 13 14 import java.util.Iterator ; 15 import java.util.List ; 16 17 import org.eclipse.jdt.internal.debug.ui.launcher.IClasspathViewer; 18 import org.eclipse.jface.viewers.IStructuredSelection; 19 20 23 public class MoveUpAction extends RuntimeClasspathAction { 24 25 public MoveUpAction(IClasspathViewer viewer) { 26 super(ActionMessages.MoveUpAction_Move_U_p_1, viewer); 27 } 28 33 public void run() { 34 List targets = getOrderedSelection(); 35 if (targets.isEmpty()) { 36 return; 37 } 38 int top = 0; 39 int index = 0; 40 List list = getEntriesAsList(); 41 Iterator entries = targets.iterator(); 42 while (entries.hasNext()) { 43 Object target = entries.next(); 44 index = list.indexOf(target); 45 if (index > top) { 46 top = index - 1; 47 Object temp = list.get(top); 48 list.set(top, target); 49 list.set(index, temp); 50 } 51 top = index; 52 } 53 setEntries(list); 54 } 55 56 59 protected boolean updateSelection(IStructuredSelection selection) { 60 if (selection.isEmpty()) { 61 return false; 62 } 63 return getViewer().updateSelection(getActionType(), selection) && !isIndexSelected(selection, 0); 64 } 65 66 protected int getActionType() { 67 return MOVE; 68 } 69 } 70 | Popular Tags |