01: package org.drools.eclipse.dsl.editor;
02:
03: import org.drools.lang.dsl.DSLMappingEntry;
04: import org.eclipse.jface.viewers.IStructuredContentProvider;
05: import org.eclipse.jface.viewers.TableViewer;
06: import org.eclipse.jface.viewers.Viewer;
07:
08: /**
09: * Content provider for the Domain Specific Language editor.
10: * @author Michael Neale
11: * @author <a href="mailto:kris_verlaenen@hotmail.com">Kris Verlaenen</a>
12: */
13: public class DSLContentProvider implements IStructuredContentProvider,
14: IMappingListViewer {
15:
16: private TableViewer viewer;
17: private NLGrammarModel model;
18:
19: public DSLContentProvider(TableViewer viewer, NLGrammarModel model) {
20: this .viewer = viewer;
21: this .model = model;
22: }
23:
24: public void dispose() {
25: model.removeChangeListener(this );
26: }
27:
28: public void inputChanged(Viewer viewer, Object oldInput,
29: Object newInput) {
30: if (newInput != null)
31: ((NLGrammarModel) newInput).addChangeListener(this );
32: if (oldInput != null)
33: ((NLGrammarModel) oldInput).removeChangeListener(this );
34:
35: }
36:
37: public void addMapping(DSLMappingEntry item) {
38: viewer.add(item);
39:
40: }
41:
42: public void removeMapping(DSLMappingEntry item) {
43:
44: viewer.remove(item);
45: }
46:
47: public void updateMapping(DSLMappingEntry item) {
48: viewer.update(item, null);
49: }
50:
51: public Object[] getElements(Object inputElement) {
52: return model.getEntries().toArray();
53: }
54:
55: }
|