1 /*
2 * File: MutableListContentProvider.java
3 * Copyright (c) 2004-2007 Peter Kliem (Peter.Kliem@jaret.de)
4 * A commercial license is available, see http://www.jaret.de.
5 *
6 * All rights reserved. This program and the accompanying materials
7 * are made available under the terms of the Common Public License v1.0
8 * which accompanies this distribution, and is available at
9 * http://www.eclipse.org/legal/cpl-v10.html
10 */
11 package de.jaret.util.ui.model;
12
13 import java.util.List;
14
15 import org.eclipse.jface.viewers.Viewer;
16
17 /**
18 * An implementation of the IMutableContentProvider interface working on a java.util.List.
19 *
20 * @author Peter Kliem
21 * @version $Id: MutableListContentProvider.java 242 2007-02-11 21:05:07Z olk $
22 */
23 public class MutableListContentProvider implements IMutableContentProvider {
24 private List _content;
25
26 /**
27 * Constructor
28 *
29 * @param content List that holds the content and that is modified.
30 */
31 public MutableListContentProvider(List content) {
32 _content = content;
33 }
34
35 public Object[] getElements(Object element) {
36 return _content.toArray();
37 }
38
39 /*
40 * (non-Javadoc)
41 *
42 * @see de.jaret.util.ui.model.IMutableContentProvider#addToDest(java.lang.Object)
43 */
44 public void addToDest(Object o) {
45 if (!_content.contains(o)) {
46 _content.add(o);
47 }
48 }
49
50 /*
51 * (non-Javadoc)
52 *
53 * @see de.jaret.util.ui.model.IMutableContentProvider#remFromDest(java.lang.Object)
54 */
55 public void remFromDest(Object o) {
56 _content.remove(o);
57 }
58
59 /*
60 * (non-Javadoc)
61 *
62 * @see de.jaret.util.ui.model.IMutableContentProvider#clear()
63 */
64 public void clear() {
65 _content.clear();
66 }
67
68 /*
69 * (non-Javadoc)
70 *
71 * @see org.eclipse.jface.viewers.IContentProvider#dispose()
72 */
73 public void dispose() {
74 }
75
76 /*
77 * (non-Javadoc)
78 *
79 * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object,
80 * java.lang.Object)
81 */
82 public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
83 }
84
85 /*
86 * (non-Javadoc)
87 *
88 * @see de.jaret.util.ui.model.IMutableContentProvider#contains(java.lang.Object)
89 */
90 public boolean contains(Object o) {
91 return _content.contains(o);
92 }
93
94 }