~berthold-daum/zora/trunk

« back to all changes in this revision

Viewing changes to com.bdaum.zoom.gps/src/com/bdaum/zoom/gps/internal/views/MapView.java

  • Committer: bdaum
  • Date: 2015-12-26 10:21:51 UTC
  • Revision ID: berthold.daum@bdaum.de-20151226102151-44f1j5113167thb9
VersionĀ 2.4.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
import org.eclipse.jface.action.Action;
23
23
import org.eclipse.jface.action.ControlContribution;
24
24
import org.eclipse.jface.action.IAction;
 
25
import org.eclipse.jface.action.IMenuManager;
25
26
import org.eclipse.jface.action.IToolBarManager;
 
27
import org.eclipse.jface.action.Separator;
26
28
import org.eclipse.jface.viewers.ArrayContentProvider;
27
29
import org.eclipse.jface.viewers.ComboViewer;
28
30
import org.eclipse.jface.viewers.IElementComparer;
52
54
import com.bdaum.zoom.gps.CoordinatesListener;
53
55
import com.bdaum.zoom.gps.MaptypeChangedListener;
54
56
import com.bdaum.zoom.gps.geonames.Place;
 
57
import com.bdaum.zoom.gps.internal.GeoService;
55
58
import com.bdaum.zoom.gps.internal.GpsActivator;
56
59
import com.bdaum.zoom.gps.internal.GpsConfiguration;
57
60
import com.bdaum.zoom.gps.internal.HelpContextIds;
142
145
        private static final String LAST_LONGITUDE = "lastLongitude"; //$NON-NLS-1$
143
146
        private static final String LAST_LATITUDE = "lastLatitude"; //$NON-NLS-1$
144
147
        public static final String ID = "com.bdaum.zoom.gps.MapView"; //$NON-NLS-1$
 
148
        private static final String LAST_ZOOM = "lastZoom"; //$NON-NLS-1$
145
149
        private Action lockAction;
146
150
        protected boolean locked = true;
147
151
        private double lastLongitude = Double.NaN;
155
159
        private ComboContributionItem comboContributionItem;
156
160
        private Composite viewParent;
157
161
        private boolean clientClustering = false;
 
162
        private Action webAction;
 
163
        protected int lastZoom;
 
164
        private IConfigurationElement currentConf;
158
165
 
159
166
        @Override
160
167
        public void init(IViewSite site, IMemento memento) throws PartInitException {
166
173
                                lastLatitude = lat.floatValue();
167
174
                                lastLongitude = lon.floatValue();
168
175
                        }
 
176
                        Integer zoom = memento.getInteger(LAST_ZOOM);
 
177
                        if (zoom != null)
 
178
                                lastZoom = zoom.intValue();
169
179
                }
170
180
        }
171
181
 
175
185
                                && !Double.isNaN(lastLongitude)) {
176
186
                        memento.putFloat(LAST_LATITUDE, (float) lastLatitude);
177
187
                        memento.putFloat(LAST_LONGITUDE, (float) lastLongitude);
 
188
                        memento.putInteger(LAST_ZOOM, lastZoom);
178
189
                }
179
190
                super.saveState(memento);
180
191
        }
206
217
                                assetsChanged(navigationHistory.getSelectedAssets());
207
218
                        }
208
219
                });
 
220
                updateActions();
209
221
        }
210
222
 
211
223
        private void createMapComponent(Composite parent, IConfigurationElement conf) {
212
224
                mapComponent = GpsActivator.getMapComponent(conf);
213
225
                if (mapComponent != null) {
 
226
                        currentConf = conf;
214
227
                        clientClustering = Boolean.parseBoolean(conf
215
228
                                        .getAttribute("clientClustering")); //$NON-NLS-1$
216
 
                        mapComponent.createComponent(parent);
 
229
                        mapComponent.createComponent(parent, true);
217
230
                        mapComponent.addCoordinatesListener(new CoordinatesListener() {
218
 
 
219
 
                                public void setCoordinates(double latitude, double longitude) {
 
231
                                public void setCoordinates(double latitude, double longitude, int zoom) {
220
232
                                        updateGeoPosition(latitude, longitude);
221
233
                                        lastLatitude = latitude;
222
234
                                        lastLongitude = longitude;
 
235
                                        lastZoom = zoom;
223
236
                                }
224
237
                        });
225
238
                        mapComponent.addMaptypeListener(new MaptypeChangedListener() {
226
 
 
227
239
                                public void setMaptype(String maptype) {
228
240
                                        IStructuredSelection sel = comboContributionItem
229
241
                                                        .getSelection();
250
262
                GpsActivator.setCurrentMappingSystem(conf);
251
263
                disposeMapComponent();
252
264
                createMapComponent(viewParent, conf);
 
265
                updateActions();
253
266
                viewParent.layout();
254
267
                showMap();
255
268
        }
279
292
                        for (Asset asset : lastSelection)
280
293
                                assetIds[i++] = asset.getStringId();
281
294
                        OperationJob.executeOperation(new GeotagOperation(
282
 
                                        new Trackpoint[] { new Trackpoint(latitude, longitude) },
 
295
                                        new Trackpoint[] { new Trackpoint(latitude, longitude, false) },
283
296
                                        assetIds, gpsConfig), this);
284
297
                        isDirty = true;
285
298
                }
290
303
                IActionBars bars = viewSite.getActionBars();
291
304
                IToolBarManager toolBarManager = bars.getToolBarManager();
292
305
                fillLocalToolBar(toolBarManager);
 
306
                IMenuManager menuManager = bars.getMenuManager();
 
307
                fillLocalPullDown(menuManager);
293
308
                toolBarManager.update(true);
 
309
                menuManager.update(true);
 
310
        }
 
311
 
 
312
        protected void fillLocalPullDown(IMenuManager menuManager) {
 
313
                menuManager.add(webAction);
 
314
                menuManager.add(lockAction);
294
315
        }
295
316
 
296
317
        protected void fillLocalToolBar(IToolBarManager manager) {
 
318
                if (comboContributionItem != null) {
 
319
                        manager.add(comboContributionItem);
 
320
                        manager.add(new Separator());
 
321
                }
 
322
                manager.add(webAction);
297
323
                manager.add(lockAction);
298
 
                if (comboContributionItem != null)
299
 
                        manager.add(comboContributionItem);
300
324
        }
301
325
 
302
326
        @Override
303
327
        protected void makeActions() {
304
 
                lockAction = new Action(Messages.MapView_0, IAction.AS_CHECK_BOX) {
305
 
 
 
328
                lockAction = new Action(Messages.MapView_lock_locked, IAction.AS_CHECK_BOX) {
306
329
                        @Override
307
330
                        public void run() {
308
331
                                locked = !locked;
309
332
                                lockAction.setChecked(locked);
310
333
                                lockAction.setImageDescriptor((locked ? Icons.closedlock
311
334
                                                : Icons.openlock).getDescriptor());
 
335
                                lockAction.setToolTipText(locked ? Messages.MapView_click_to_unlock : Messages.MapView_click_to_lock );
 
336
                                lockAction.setText(locked ? Messages.MapView_lock_locked : Messages.MapView_lock_unlocked );
312
337
                                AssetSelection selectedAssets = lastSelection;
313
338
                                lastSelection = null;
314
339
                                if (assetsChanged(selectedAssets))
317
342
                };
318
343
                lockAction.setImageDescriptor(Icons.closedlock.getDescriptor());
319
344
                lockAction.setChecked(true);
 
345
                lockAction.setToolTipText(Messages.MapView_click_to_unlock);
 
346
 
 
347
                webAction = new Action(Messages.MapView_show_in_web, IAction.AS_PUSH_BUTTON) {
 
348
                        @Override
 
349
                        public void run() {
 
350
                                try {
 
351
                                        GeoService.showInWebbrowser(lastLatitude, lastLongitude, lastZoom);
 
352
                                } catch (Exception e) {
 
353
                                        // do nothing
 
354
                                }
 
355
                        }
 
356
                };
 
357
                webAction.setImageDescriptor(Icons.external.getDescriptor());
 
358
 
320
359
                createComboContributionItem();
321
360
        }
322
361
 
394
433
                case 1:
395
434
                        Collection<Place> values = placeMap.values();
396
435
                        mapPosition = values.toArray(new Place[values.size()])[0];
397
 
                        initialZoomLevel = 14;
 
436
                        initialZoomLevel = 12;
398
437
                        mode = IMapComponent.ONE;
399
438
                        break;
400
439
                default:
409
448
        private void showMap(Place[] markerPositions, int mode) {
410
449
                if (mapComponent != null) {
411
450
                        mapComponent.setInput(mapPosition, initialZoomLevel,
412
 
                                        markerPositions, dbIsReadonly() ? IMapComponent.LOCATION
 
451
                                        markerPositions, null, dbIsReadonly() ? IMapComponent.LOCATION
413
452
                                                        : mode);
414
453
                        if (!Double.isNaN(mapPosition.getLat())
415
454
                                        && !Double.isNaN(mapPosition.getLon())) {
527
566
 
528
567
        @Override
529
568
        public void updateActions() {
530
 
                // do nothing
 
569
                String query = currentConf == null ? null : currentConf.getAttribute("query"); //$NON-NLS-1$
 
570
                webAction.setEnabled(query != null);
531
571
        }
532
572
 
533
573
        @Override