Commented GUIWire
[Mograsim.git] / net.mograsim.rcp / src / net / mograsim / rcp / parts / SamplePart.java
1 package net.mograsim.rcp.parts;
2
3 import java.util.Arrays;
4 import java.util.List;
5
6 import javax.annotation.PostConstruct;
7 import javax.inject.Inject;
8
9 import org.eclipse.e4.core.services.nls.Translation;
10 import org.eclipse.e4.ui.di.Focus;
11 import org.eclipse.e4.ui.di.Persist;
12 import org.eclipse.e4.ui.model.application.ui.basic.MPart;
13 import org.eclipse.jface.viewers.ArrayContentProvider;
14 import org.eclipse.jface.viewers.TableViewer;
15 import org.eclipse.swt.SWT;
16 import org.eclipse.swt.layout.GridData;
17 import org.eclipse.swt.layout.GridLayout;
18 import org.eclipse.swt.widgets.Composite;
19 import org.eclipse.swt.widgets.Text;
20
21 import net.mograsim.rcp.i18n.Messages;
22
23 public class SamplePart
24 {
25
26         private TableViewer tableViewer;
27         private Text txtInput;
28
29         @Inject
30         private MPart part;
31
32         @PostConstruct
33         public void createComposite(Composite parent)
34         {
35                 parent.setLayout(new GridLayout(1, false));
36
37                 txtInput = new Text(parent, SWT.BORDER);
38                 txtInput.setMessage("Enter text to mark part as dirty");
39                 txtInput.addModifyListener(e -> part.setDirty(true));
40                 txtInput.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
41
42                 tableViewer = new TableViewer(parent);
43
44                 tableViewer.setContentProvider(ArrayContentProvider.getInstance());
45                 tableViewer.setInput(createInitialDataModel());
46                 tableViewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
47         }
48
49         @Focus
50         public void setFocus()
51         {
52                 tableViewer.getTable().setFocus();
53         }
54
55         @Persist
56         public void save()
57         {
58                 part.setDirty(false);
59         }
60
61         private static List<String> createInitialDataModel()
62         {
63                 return Arrays.asList("Sample item 1", "Sample item 2", "Sample item 3", "Sample item 4", "Sample item 5");
64         }
65
66         @Inject
67         public void translate(@Translation Messages m)
68         {
69                 if (txtInput != null && !txtInput.isDisposed())
70                         txtInput.setMessage(m.sample_part_input_hint);
71         }
72 }