KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > sourcelookup > DownAction


1 /*******************************************************************************
2  * Copyright (c) 2003, 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.debug.internal.ui.sourcelookup;
12
13 import java.util.List JavaDoc;
14
15 import org.eclipse.jface.viewers.IStructuredSelection;
16
17 /**
18  * The action for sorting the order of source containers in the dialog.
19  *
20  */

21 public class DownAction extends SourceContainerAction {
22     
23     public DownAction() {
24         super(SourceLookupUIMessages.sourceTab_downButton);
25     }
26     /**
27      * @see IAction#run()
28      */

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

54     protected boolean updateSelection(IStructuredSelection selection) {
55         return !selection.isEmpty() && !isIndexSelected(selection, getEntriesAsList().size() - 1) && getViewer().getTree().getSelection()[0].getParentItem()==null;
56     }
57     
58 }
59
Popular Tags