KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ant > internal > ui > views > AntTargetContentProvider


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

11 package org.eclipse.ant.internal.ui.views;
12
13
14 import java.util.ArrayList JavaDoc;
15 import java.util.List JavaDoc;
16
17 import org.eclipse.jface.viewers.IStructuredContentProvider;
18 import org.eclipse.jface.viewers.Viewer;
19 import org.eclipse.ant.internal.ui.views.elements.TargetNode;
20
21 /**
22  * Content provider which provides a list of ant targets chosen by the user
23  */

24 public class AntTargetContentProvider implements IStructuredContentProvider {
25
26     /**
27      * The collection of currently active targets
28      */

29     private List JavaDoc targets = new ArrayList JavaDoc();
30
31     /**
32      * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
33      */

34     public Object JavaDoc[] getElements(Object JavaDoc inputElement) {
35         return targets.toArray();
36     }
37
38     /**
39      * @see org.eclipse.jface.viewers.IContentProvider#dispose()
40      */

41     public void dispose() {
42     }
43
44     /**
45      * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
46      */

47     public void inputChanged(Viewer viewer, Object JavaDoc oldInput, Object JavaDoc newInput) {
48     }
49
50     /**
51      * Returns the user's currently selected targets. The list contains
52      * <code>TargetNode</code> objects.
53      *
54      * @return List the user's currently selected targets
55      */

56     public List JavaDoc getTargets() {
57         return targets;
58     }
59
60     /**
61      * Adds the given target to the list of selected targets. Targets will
62      * appear in the list as often as they are added.
63      *
64      * @param target the target to add
65      */

66     public void addTarget(TargetNode target) {
67         targets.add(target);
68     }
69
70     /**
71      * Removes the given target from the list of selected targets. Has no effect
72      * if the given index is invalid.
73      *
74      * @param index the index of the the target to remove
75      */

76     public void removeTarget(int index) {
77         if (targets.size() > index && index >= 0) {
78             targets.remove(index);
79         }
80     }
81     
82     /**
83      * Moves the given target up in the list of active targets. Has no effect if
84      * the given target is already the first target in the list or the given
85      * index is invalid.
86      *
87      * @param index the index of the target to move up
88      */

89     public void moveUpTarget(int index) {
90         Object JavaDoc target= targets.get(index);
91         if (index == 0 || target == null) {
92             return;
93         }
94         targets.set(index, targets.get(index - 1));
95         targets.set(index - 1, target);
96     }
97     
98     /**
99      * Moves the given target down in the list of active targets. Has no effect
100      * if the given target is already the last target in the list or the given
101      * index is invalid.
102      *
103      * @param index the index of the target to move down
104      */

105     public void moveDownTarget(int index) {
106         Object JavaDoc target= targets.get(index);
107         if (index == targets.size() - 1 || target == null) {
108             return;
109         }
110         targets.set(index, targets.get(index + 1));
111         targets.set(index + 1, target);
112     }
113
114 }
115
Popular Tags