1 | package de.ugoe.cs.swe.bnftools.ebnf.standalone; |
---|
2 | |
---|
3 | import org.eclipse.emf.ecore.resource.Resource; |
---|
4 | import org.eclipse.jface.viewers.IStructuredContentProvider; |
---|
5 | import org.eclipse.jface.viewers.ITableLabelProvider; |
---|
6 | import org.eclipse.jface.viewers.LabelProvider; |
---|
7 | import org.eclipse.jface.viewers.TableViewer; |
---|
8 | import org.eclipse.jface.viewers.Viewer; |
---|
9 | import org.eclipse.swt.SWT; |
---|
10 | import org.eclipse.swt.custom.SashForm; |
---|
11 | import org.eclipse.swt.graphics.Image; |
---|
12 | import org.eclipse.swt.widgets.Composite; |
---|
13 | import org.eclipse.ui.ISharedImages; |
---|
14 | import org.eclipse.ui.PlatformUI; |
---|
15 | import org.eclipse.ui.part.ViewPart; |
---|
16 | import org.eclipse.xtext.ui.editor.XtextSourceViewer; |
---|
17 | import org.eclipse.xtext.ui.editor.embedded.EmbeddedEditor; |
---|
18 | import org.eclipse.xtext.ui.editor.embedded.EmbeddedEditorModelAccess; |
---|
19 | |
---|
20 | public class View extends ViewPart { |
---|
21 | public static final String ID = "de.ugoe.cs.swe.bnftools.ebnf.standalone.view"; |
---|
22 | |
---|
23 | private TableViewer viewer; |
---|
24 | private EmbeddedEditor handle; |
---|
25 | private SashForm sashForm; |
---|
26 | private EmbeddedEditorModelAccess partialEditor; |
---|
27 | private Resource resource; |
---|
28 | private XtextSourceViewer viewer2; |
---|
29 | |
---|
30 | |
---|
31 | /** |
---|
32 | * The content provider class is responsible for providing objects to the |
---|
33 | * view. It can wrap existing objects in adapters or simply return objects |
---|
34 | * as-is. These objects may be sensitive to the current input of the view, |
---|
35 | * or ignore it and always show the same content (like Task List, for |
---|
36 | * example). |
---|
37 | */ |
---|
38 | class ViewContentProvider implements IStructuredContentProvider { |
---|
39 | public void inputChanged(Viewer v, Object oldInput, Object newInput) { |
---|
40 | } |
---|
41 | |
---|
42 | public void dispose() { |
---|
43 | } |
---|
44 | |
---|
45 | public Object[] getElements(Object parent) { |
---|
46 | if (parent instanceof Object[]) { |
---|
47 | return (Object[]) parent; |
---|
48 | } |
---|
49 | return new Object[0]; |
---|
50 | } |
---|
51 | } |
---|
52 | |
---|
53 | class ViewLabelProvider extends LabelProvider implements |
---|
54 | ITableLabelProvider { |
---|
55 | public String getColumnText(Object obj, int index) { |
---|
56 | return getText(obj); |
---|
57 | } |
---|
58 | |
---|
59 | public Image getColumnImage(Object obj, int index) { |
---|
60 | return getImage(obj); |
---|
61 | } |
---|
62 | |
---|
63 | public Image getImage(Object obj) { |
---|
64 | return PlatformUI.getWorkbench().getSharedImages().getImage( |
---|
65 | ISharedImages.IMG_OBJ_ELEMENT); |
---|
66 | } |
---|
67 | } |
---|
68 | |
---|
69 | /** |
---|
70 | * This is a callback that will allow us to create the viewer and initialize |
---|
71 | * it. |
---|
72 | */ |
---|
73 | public void createPartControl(Composite parent) { |
---|
74 | viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL |
---|
75 | | SWT.V_SCROLL); |
---|
76 | viewer.setContentProvider(new ViewContentProvider()); |
---|
77 | viewer.setLabelProvider(new ViewLabelProvider()); |
---|
78 | // Provide the input to the ContentProvider |
---|
79 | viewer.setInput(new String[] {"One", "Two", "Three"}); |
---|
80 | } |
---|
81 | |
---|
82 | /** |
---|
83 | * Passing the focus request to the viewer's control. |
---|
84 | */ |
---|
85 | public void setFocus() { |
---|
86 | viewer.getControl().setFocus(); |
---|
87 | } |
---|
88 | } |
---|