Refactory: removed unnecessary local variables and imports.
[phpeclipse.git] / net.sourceforge.phpeclipse.externaltools / src / net / sourceforge / phpdt / externaltools / internal / ui / ExternalToolsContentProvider.java
1 package net.sourceforge.phpdt.externaltools.internal.ui;
2
3 /**********************************************************************
4  Copyright (c) 2000, 2002 IBM Corp.  All rights reserved.
5  This file is made available under the terms of the Common Public License v1.0
6  which accompanies this distribution, and is available at
7  http://www.eclipse.org/legal/cpl-v10.html
8  **********************************************************************/
9
10 import java.util.ArrayList;
11 import java.util.Arrays;
12 import java.util.List;
13
14 import org.eclipse.jface.viewers.IStructuredContentProvider;
15 import org.eclipse.jface.viewers.IStructuredSelection;
16 import org.eclipse.jface.viewers.TableViewer;
17 import org.eclipse.jface.viewers.Viewer;
18
19 /**
20  * Content provider that maintains a generic list of objects which are shown in
21  * a table viewer.
22  */
23 public class ExternalToolsContentProvider implements IStructuredContentProvider {
24         protected List elements = new ArrayList();
25
26         protected TableViewer viewer;
27
28         public void add(Object o) {
29                 if (elements.contains(o)) {
30                         return;
31                 }
32                 elements.add(o);
33                 viewer.add(o);
34         }
35
36         public void dispose() {
37         }
38
39         public Object[] getElements(Object inputElement) {
40                 return (Object[]) elements.toArray(new Object[elements.size()]);
41         }
42
43         public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
44                 this.viewer = (TableViewer) viewer;
45                 elements.clear();
46                 if (newInput != null) {
47                         if (newInput instanceof List) {
48                                 elements.addAll((List) newInput);
49                         } else {
50                                 elements.addAll(Arrays.asList((Object[]) newInput));
51                         }
52                 }
53         }
54
55         public void remove(Object o) {
56                 elements.remove(o);
57                 viewer.remove(o);
58         }
59
60         public void remove(IStructuredSelection selection) {
61                 Object[] array = selection.toArray();
62                 elements.removeAll(Arrays.asList(array));
63                 viewer.remove(array);
64         }
65 }