blob: 3cb2144d788c881b76b044aa2fce96e4876f9bf1 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
package org.eclipse.ui.externaltools.internal.ant.launchConfigurations;
/*******************************************************************************
* Copyright (c) 2002 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM - Initial API and implementation
******************************************************************************/
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
public class AntTargetContentProvider implements IStructuredContentProvider {
protected List elements = new ArrayList();
protected TableViewer viewer;
public void add(Object o) {
elements.add(o);
viewer.add(o);
}
public void addAll(List list) {
elements.addAll(list);
viewer.add(list.toArray());
}
public void dispose() {
}
public Object[] getElements(Object inputElement) {
if (elements.isEmpty()) {
return new Object[0];
} else {
return (Object[]) elements.toArray(new Object[elements.size()]);
}
}
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
this.viewer = (TableViewer) viewer;
elements.clear();
if (newInput != null && ((Object[]) newInput).length != 0) {
elements.addAll(Arrays.asList((Object[]) newInput));
}
}
/**
* Removes the given target from the list of targets. Has no effect if the
* given target does not exist in the list.
*
* @param target the target to remove
*/
public void removeTarget(Object target) {
elements.remove(target);
viewer.remove(target);
}
/**
* Moves the given target up in the list of active targets. Has no effect if
* the given target is already the first target in the list or the given
* index is invalid.
*
* @param index the index of the target to move up
*/
public void moveUpTarget(int index) {
Object target = elements.get(index);
if (index == 0 || target == null) {
return;
}
elements.set(index, elements.get(index - 1));
elements.set(index - 1, target);
}
/**
* Moves the given target down in the list of active targets. Has no effect
* if the given target is already the last target in the list or the given
* index is invalid.
*
* @param index the index of the target to move down
*/
public void moveDownTarget(int index) {
Object target = elements.get(index);
if (index == elements.size() - 1 || target == null) {
return;
}
elements.set(index, elements.get(index + 1));
elements.set(index + 1, target);
}
}
|