KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2004, 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 - current implementation
10  *******************************************************************************/

11
12 package org.eclipse.ant.internal.ui.views;
13
14 import java.util.ArrayList JavaDoc;
15 import java.util.Arrays JavaDoc;
16 import java.util.List JavaDoc;
17
18 import org.eclipse.ant.internal.ui.model.AntModelContentProvider;
19 import org.eclipse.jface.viewers.StructuredSelection;
20 import org.eclipse.jface.viewers.TreeViewer;
21 import org.eclipse.jface.viewers.Viewer;
22
23
24 public class AntViewContentProvider extends AntModelContentProvider {
25     
26     private TreeViewer fTreeViewer;
27     private List JavaDoc fElements= new ArrayList JavaDoc();
28     
29     /* (non-Javadoc)
30      * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(Object)
31      */

32     public Object JavaDoc[] getElements(Object JavaDoc anInputElement) {
33         if (anInputElement instanceof Object JavaDoc[]) {
34             return fElements.toArray();
35         }
36         return EMPTY_ARRAY;
37     }
38     
39     public void add(Object JavaDoc o) {
40         if (fElements.contains(o)) {
41             return;
42         }
43         fElements.add(o);
44         fTreeViewer.add(fTreeViewer.getInput(), o);
45         fTreeViewer.setSelection(new StructuredSelection(o), true);
46     }
47     
48     public void addAll(Object JavaDoc[] o) {
49         fElements.addAll(Arrays.asList(o));
50         fTreeViewer.add(fTreeViewer.getInput(), o);
51     }
52     
53     /**
54      * do nothing
55      * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(Viewer, Object, Object)
56      */

57     public void inputChanged(Viewer viewer, Object JavaDoc oldInput, Object JavaDoc newInput) {
58         fTreeViewer= (TreeViewer)viewer;
59     }
60     
61     public void remove(Object JavaDoc o) {
62         fElements.remove(o);
63         fTreeViewer.remove(o);
64     }
65     
66     public void removeAll() {
67         fTreeViewer.remove(fElements.toArray());
68         fElements.clear();
69     }
70     
71     /* (non-Javadoc)
72      * @see org.eclipse.jface.viewers.IContentProvider#dispose()
73      */

74     public void dispose() {
75     }
76 }
77
Popular Tags