KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > actions > MoveUpAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.debug.ui.actions;
12
13
14 import java.util.Iterator JavaDoc;
15 import java.util.List JavaDoc;
16
17 import org.eclipse.jdt.internal.debug.ui.launcher.IClasspathViewer;
18 import org.eclipse.jface.viewers.IStructuredSelection;
19
20 /**
21  * Moves selected enries in a runtime classpath viewer up one position.
22  */

23 public class MoveUpAction extends RuntimeClasspathAction {
24
25     public MoveUpAction(IClasspathViewer viewer) {
26         super(ActionMessages.MoveUpAction_Move_U_p_1, viewer);
27     }
28     /**
29      * Moves all selected entries up one position (if possible).
30      *
31      * @see IAction#run()
32      */

33     public void run() {
34         List JavaDoc targets = getOrderedSelection();
35         if (targets.isEmpty()) {
36             return;
37         }
38         int top = 0;
39         int index = 0;
40         List JavaDoc list = getEntriesAsList();
41         Iterator JavaDoc entries = targets.iterator();
42         while (entries.hasNext()) {
43             Object JavaDoc target = entries.next();
44             index = list.indexOf(target);
45             if (index > top) {
46                 top = index - 1;
47                 Object JavaDoc 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     /**
57      * @see SelectionListenerAction#updateSelection(IStructuredSelection)
58      */

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