KickJava   Java API By Example, From Geeks To Geeks.

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


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.Iterator JavaDoc;
14 import java.util.List JavaDoc;
15
16 import org.eclipse.jface.viewers.IStructuredSelection;
17
18 /**
19  * The action used to move source containers up in the list
20  */

21 public class UpAction extends SourceContainerAction {
22     
23     public UpAction() {
24         super(SourceLookupUIMessages.sourceTab_upButton);
25     }
26     /**
27      * Moves all selected entries up one position (if possible).
28      *
29      * @see IAction#run()
30      */

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

57     protected boolean updateSelection(IStructuredSelection selection) {
58         //check that something is selected, it's not first in the list, and it is a root tree node.
59
return !selection.isEmpty() && !isIndexSelected(selection, 0) && getViewer().getTree().getSelection()[0].getParentItem()==null;
60     }
61     
62 }
63
Popular Tags