1 package org.minetti.astrodevice.client.gui.menu;
2
3 import java.util.List;
4 import org.eclipse.swt.SWT;
5 import org.eclipse.swt.widgets.Event;
6 import org.eclipse.swt.widgets.Listener;
7 import org.eclipse.swt.widgets.Menu;
8 import org.eclipse.swt.widgets.MenuItem;
9 import org.eclipse.swt.widgets.Shell;
10 import org.minetti.astrodevice.client.business.process.ObservingSiteProcess;
11 import org.minetti.astrodevice.client.business.process.PlatformProcess;
12 import org.minetti.astrodevice.client.i18n.I18n;
13 import org.minetti.astrodevice.common.object.Entity;
14
15
16
17
18
19 public final class SwtObservingSiteMenu
20 {
21
22
23
24
25 protected final class ShowListener
26 implements Listener
27 {
28
29
30
31
32
33 public void handleEvent (final Event event)
34 {
35
36
37 for (final MenuItem menuItem : SwtObservingSiteMenu.this.subMenu.getItems ()) {
38 menuItem.dispose ();
39 }
40
41
42 final Long selectedObservingSiteId = SwtObservingSiteMenu.this.platformProcess.getObservingSiteId ();
43 final List<Entity> entityList = SwtObservingSiteMenu.this.observingSiteProcess.find ();
44 for (final Entity entity : entityList) {
45 final MenuItem menuItem = new MenuItem (SwtObservingSiteMenu.this.subMenu, SWT.RADIO);
46 menuItem.setText (entity.getName ());
47 menuItem.addListener (SWT.Selection, new ObservingSiteSelectionListener (entity));
48 menuItem.setSelection ((selectedObservingSiteId != null) && (selectedObservingSiteId.longValue () == entity.getId ()));
49 }
50
51
52 MenuItem menuItem;
53 if (entityList.size () > 0) {
54 menuItem = new MenuItem (SwtObservingSiteMenu.this.subMenu, SWT.SEPARATOR);
55 }
56
57
58 menuItem = new MenuItem (SwtObservingSiteMenu.this.subMenu, SWT.PUSH);
59 menuItem.setText (I18n.getGui ().getString ("menu.observingsite.gps.text"));
60 menuItem.addListener (SWT.Selection, new GpsSelectionListener ());
61
62 }
63
64 }
65
66
67
68
69 protected final class ObservingSiteSelectionListener
70 implements Listener
71 {
72
73
74
75
76 private final Entity entity;
77
78
79
80
81
82 protected ObservingSiteSelectionListener (final Entity entity)
83 {
84 super ();
85 this.entity = entity;
86 }
87
88
89
90
91
92 public void handleEvent (final Event event)
93 {
94 final MenuItem menuItem = (MenuItem) event.widget;
95 if (menuItem.getSelection ()) {
96 SwtObservingSiteMenu.this.platformProcess.setObservingSiteId (this.entity.getId ());
97 }
98 }
99
100 }
101
102
103
104
105 protected final class GpsSelectionListener
106 implements Listener
107 {
108
109
110
111
112
113 public void handleEvent (final Event event)
114 {
115
116 System.out.println ("Sélection GPS");
117
118
119 }
120
121 }
122
123
124
125
126 protected final PlatformProcess platformProcess = new PlatformProcess ();
127
128
129
130
131 protected final ObservingSiteProcess observingSiteProcess = new ObservingSiteProcess ();
132
133
134
135
136 protected Menu subMenu;
137
138
139
140
141
142
143 public void build (final Shell shell, final Menu contextMenu)
144 {
145 MenuItem menuItem = new MenuItem (contextMenu, SWT.CASCADE);
146 menuItem.setText (I18n.getGui ().getString ("menu.observingsite.text"));
147 this.subMenu = new Menu (shell, SWT.DROP_DOWN);
148 this.subMenu.addListener (SWT.Show, new ShowListener ());
149 menuItem.setMenu (this.subMenu);
150 }
151
152
153
154
155
156 @Override
157 public String toString ()
158 {
159 return "SwtObservingSiteMenu";
160 }
161
162 }