private void watchOpenedTCs() { ArrayList<TopComponent> windowsToWatch = findShowingTCs(); ArrayList<TopComponent> toAddListeners = new ArrayList<>(windowsToWatch); toAddListeners.removeAll(watchedLkpResults.keySet()); ArrayList<TopComponent> toRemoveListeners = new ArrayList<>(watchedLkpResults.keySet()); toRemoveListeners.removeAll(windowsToWatch); toRemoveListeners .stream() .forEach( (tc) -> { Lookup.Result res = watchedLkpResults.get(tc); if (null != res) { res.removeLookupListener(this); watchedLkpResults.remove(tc); } }); toAddListeners .stream() .forEach( (tc) -> { Lookup.Result res = tc.getLookup().lookupResult(LayoutScene.class); res.addLookupListener(this); res.allItems(); watchedLkpResults.put(tc, res); }); }
@Override public void resultChanged(LookupEvent ev) { if (!res.allInstances().isEmpty()) { if (scene != null) { // remove listener on previous scene scene.removeSceneListener(this); } scene = res.allInstances().iterator().next(); scene.addSceneListener(this); Lookup.Result<StrategicZoom> strategies = scene.getLookup().lookupResult(StrategicZoom.class); if (!strategies.allInstances().isEmpty()) { // set the flag bahwa sekarang ini mau ganti model. // by default, setModel akan trigger setItem dari first item di model // jadi kalo first item nya toFit, tiap kali pindah tab, bakal jadi toFit lagiPindahModel = true; zoomlist.setModel(new DefaultComboBoxModel(strategies.allInstances().toArray())); lagiPindahModel = false; } else { zoomlist.setModel(new DefaultComboBoxModel()); } ((ZoomComboBoxEditor) zoomlist.getEditor()).setZoomText(getCalibratedZoomFactor()); } else { if (scene != null) { // remove listener on previous scene scene.removeSceneListener(this); } } setEnabled(!res.allItems().isEmpty()); }
/** * multiview components do not fire events when switching their inner tabs so we have to listen to * changes in lookup contents */ private void switchLookupListener() { TopComponent active = TopComponent.getRegistry().getActivated(); if (null != lookupRes) { lookupRes.removeLookupListener(SatelliteViewSwitch.this); lookupRes = null; } if (null != active) { lookupRes = active.getLookup().lookupResult(LayoutScene.class); lookupRes.addLookupListener(SatelliteViewSwitch.this); lookupRes.allItems(); } }
static { resultContext = Utilities.actionsGlobalContext().lookupResult(GISContextDataObject.class); resultContext.addLookupListener( new LookupListener() { @Override public void resultChanged(LookupEvent lookupEvent) { final Lookup.Result r = (Lookup.Result) lookupEvent.getSource(); final Collection c = r.allInstances(); if (!c.isEmpty()) { new Thread() { @Override public void run() { final Iterator ite = c.iterator(); while (ite.hasNext()) { final GISContextDataObject da = (GISContextDataObject) ite.next(); final MapContext candidate = da.getContext(); updateName(candidate); } } }.start(); } } }); resultContext.allItems(); resultViews = Utilities.actionsGlobalContext().lookupResult(ViewComponent.class); resultViews.addLookupListener( new LookupListener() { @Override public void resultChanged(LookupEvent lookupEvent) { final Lookup.Result r = (Lookup.Result) lookupEvent.getSource(); final Collection c = r.allInstances(); if (!c.isEmpty()) { new Thread() { @Override public void run() { final Iterator ite = c.iterator(); while (ite.hasNext()) { final ViewComponent da = (ViewComponent) ite.next(); final Map2D map = da.getMapView(); for (TreePopupItem tpi : getContextTree().controls()) { System.out.println(tpi); tpi.setMapView(map); } final MapContext candidate = da.getContext(); updateName(candidate); } } }.start(); } } }); resultViews.allItems(); resultGISViews = Utilities.actionsGlobalContext().lookupResult(GISView.class); resultGISViews.addLookupListener( new LookupListener() { @Override public void resultChanged(LookupEvent lookupEvent) { final Lookup.Result r = (Lookup.Result) lookupEvent.getSource(); final Collection c = r.allInstances(); if (!c.isEmpty()) { new Thread() { @Override public void run() { final Iterator ite = c.iterator(); while (ite.hasNext()) { final GISView da = (GISView) ite.next(); final MapContext candidate = da.getContext().getContext(); updateName(candidate); } } }.start(); } } }); resultGISViews.allItems(); }