KickJava   Java API By Example, From Geeks To Geeks.

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


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.List JavaDoc;
15
16 import org.eclipse.jdt.internal.debug.ui.launcher.IClasspathViewer;
17 import org.eclipse.jface.viewers.IStructuredSelection;
18
19 /**
20  * Moves selected enries in a runtime classpath viewer down one position.
21  */

22 public class MoveDownAction extends RuntimeClasspathAction {
23
24     public MoveDownAction(IClasspathViewer viewer) {
25         super(ActionMessages.MoveDownAction_M_ove_Down_1, viewer);
26     }
27     /**
28      * @see IAction#run()
29      */

30     public void run() {
31         List JavaDoc targets = getOrderedSelection();
32         if (targets.isEmpty()) {
33             return;
34         }
35         List JavaDoc list = getEntriesAsList();
36         int bottom = list.size() - 1;
37         int index = 0;
38         for (int i = targets.size() - 1; i >= 0; i--) {
39             Object JavaDoc target = targets.get(i);
40             index = list.indexOf(target);
41             if (index < bottom) {
42                 bottom = index + 1;
43                 Object JavaDoc temp = list.get(bottom);
44                 list.set(bottom, target);
45                 list.set(index, temp);
46             }
47             bottom = index;
48         }
49         setEntries(list);
50     }
51
52     /**
53      * @see SelectionListenerAction#updateSelection(IStructuredSelection)
54      */

55     protected boolean updateSelection(IStructuredSelection selection) {
56         if (selection.isEmpty()) {
57             return false;
58         }
59         return getViewer().updateSelection(getActionType(), selection) && !isIndexSelected(selection, getEntriesAsList().size() - 1);
60     }
61     
62     protected int getActionType() {
63         return MOVE;
64     }
65 }
66
Popular Tags