public void testDontCallMeUnderLock() throws Exception { final Lookup l = getTestedLookup(c2); ProxyLookup pl = new ProxyLookup(l) { @Override void beforeLookup(boolean call, Template<?> template) { super.beforeLookup(call, template); assertFalse("Don't hold MetaInfServicesLookup lock", Thread.holdsLock(l)); } }; Class<?> xface = c1.loadClass("org.foo.Interface"); Result<?> res = pl.lookupResult(Object.class); res.addLookupListener(new LookupListener() { @Override public void resultChanged(LookupEvent ev) { } }); assertTrue("Empty now", res.allItems().isEmpty()); Object first = l.lookup(xface); assertEquals(first, l.lookupAll(xface).iterator().next()); Object second = pl.lookup(xface); assertEquals(first, second); }
private Coloring getColoring() { if (attribs == null) { if (fcsLookupResult == null) { fcsLookupResult = MimeLookup.getLookup(org.netbeans.lib.editor.util.swing.DocumentUtilities.getMimeType(component)) .lookupResult(FontColorSettings.class); fcsLookupResult.addLookupListener(WeakListeners.create(LookupListener.class, fcsTracker, fcsLookupResult)); } FontColorSettings fcs = fcsLookupResult.allInstances().iterator().next(); AttributeSet attr = fcs.getFontColors(FontColorNames.CODE_FOLDING_BAR_COLORING); specificAttrs = attr; if (attr == null) { attr = fcs.getFontColors(FontColorNames.DEFAULT_COLORING); } else { attr = AttributesUtilities.createComposite( attr, fcs.getFontColors(FontColorNames.DEFAULT_COLORING)); } attribs = attr; } return Coloring.fromAttributeSet(attribs); }
private ColoringMap( List<String> legacyNonTokenColoringNames, Language<?> lexerLanguage, List<? extends TokenContext> syntaxLanguages, Lookup.Result<FontColorSettings> lookupResult ) { this.legacyNonTokenColoringNames = legacyNonTokenColoringNames; this.lexerLanguage = lexerLanguage; this.syntaxLanguages = syntaxLanguages; this.lookupResult = lookupResult; this.map = loadTheMap( legacyNonTokenColoringNames, lexerLanguage, syntaxLanguages, lookupResult.allInstances() ); this.lookupResult.addLookupListener(WeakListeners.create(LookupListener.class, lookupListener, this.lookupResult)); }
private Coloring getColoring() { if (attribs == null) { if (fcsLookupResult == null) { fcsLookupResult = MimeLookup.getLookup(org.netbeans.lib.editor.util.swing.DocumentUtilities.getMimeType(getComponent())) .lookupResult(FontColorSettings.class); fcsLookupResult.addLookupListener(WeakListeners.create(LookupListener.class, fcsTracker, fcsLookupResult)); } FontColorSettings fcs = fcsLookupResult.allInstances().iterator().next(); AttributeSet attr = fcs.getFontColors(FontColorNames.CODE_FOLDING_COLORING); if (attr == null) { attr = fcs.getFontColors(FontColorNames.DEFAULT_COLORING); } else { attr = AttributesUtilities.createComposite(attr, fcs.getFontColors(FontColorNames.DEFAULT_COLORING)); } attribs = attr; } return Coloring.fromAttributeSet(attribs); }
private Coloring getColoring() { if (attribs == null) { if (fcsLookupResult == null) { fcsLookupResult = MimeLookup.getLookup(org.netbeans.lib.editor.util.swing.DocumentUtilities.getMimeType(component)) .lookupResult(FontColorSettings.class); fcsLookupResult.addLookupListener(WeakListeners.create(LookupListener.class, fcsTracker, fcsLookupResult)); } FontColorSettings fcs = fcsLookupResult.allInstances().iterator().next(); AttributeSet attr = fcs.getFontColors(FontColorNames.CODE_FOLDING_BAR_COLORING); if (attr == null) { attr = fcs.getFontColors(FontColorNames.DEFAULT_COLORING); } else { attr = AttributesUtilities.createComposite(attr, fcs.getFontColors(FontColorNames.DEFAULT_COLORING)); } attribs = attr; } return Coloring.fromAttributeSet(attribs); }
public ComponentBreakpointActionProvider() { final Result<Node> nodeLookupResult = Utilities.actionsGlobalContext().lookupResult(Node.class); LookupListener ll = new LookupListener() { @Override public void resultChanged(LookupEvent ev) { Collection<? extends Node> nodeInstances = nodeLookupResult.allInstances(); for (Node n : nodeInstances) { JavaComponentInfo ci = n.getLookup().lookup(JavaComponentInfo.class); if (ci != null) { setEnabled(ActionsManager.ACTION_TOGGLE_BREAKPOINT, true); return ; } } setEnabled(ActionsManager.ACTION_TOGGLE_BREAKPOINT, false); } }; nodeLookupResult.addLookupListener(ll); ll.resultChanged(null); // To initialize }
/** Creates a new instance of JavaSourceTaskFactoryManager */ private JavaSourceTaskFactoryManager() { final RequestProcessor.Task updateTask = new RequestProcessor("JavaSourceTaskFactoryManager Worker", 1).create(new Runnable() { public void run() { update(); } }); factories = Lookup.getDefault().lookupResult(JavaSourceTaskFactory.class); factories.addLookupListener(new LookupListener() { public void resultChanged(LookupEvent ev) { updateTask.schedule(0); } }); update(); }
/** Called when there may be a need for initialization. * * @return true if subclasses shall initialize themselves */ protected boolean init () { synchronized (RESULTS_LOCK) {//synchronized == issue 215335 if (initialized) { return false; } this.results = new Lookup.Result[watch.length]; // Needs to listen on changes in results for ( int i = 0; i < watch.length; i++ ) { results[i] = lookup.lookupResult(watch[i]); results[i].allItems(); LookupListener resultListener = WeakListeners.create(LookupListener.class, this, results[i]); results[i].addLookupListener( resultListener ); } initialized = true; return true; } }
/** Get all available help sets. * Pay attention to {@link #helpSetsChanged} to see * when this set will change. * @return a collection of HelpSet */ protected final Collection<? extends HelpSet> getHelpSets() { if (helpsets == null) { Installer.log.fine("searching for instances of HelpSet..."); helpsets = Lookup.getDefault().lookupResult(HelpSet.class); helpsets.addLookupListener(new LookupListener() { public void resultChanged(LookupEvent ev) { helpSetsChanged(); } }); fireChangeEvent(); // since someone may be listening to whether they are ready } Collection<? extends HelpSet> c = helpsets.allInstances(); if (Installer.log.isLoggable(Level.FINE)) { List<String> l = new ArrayList<String>(Math.min(1, c.size())); for (HelpSet hs: c) { l.add(hs.getTitle()); } Installer.log.fine("listing helpsets: " + l); } return c; }
private static synchronized List<Selenium2SupportImpl> getImplementations() { if (implementations == null) { implementations = Lookup.getDefault().lookupResult(Selenium2SupportImpl.class); implementations.addLookupListener(new LookupListener() { @Override public void resultChanged(LookupEvent ev) { synchronized (Selenium2Support.class) { cache = null; } } }); } if (cache == null) { cache = new ArrayList<Selenium2SupportImpl>(implementations.allInstances()); } return Collections.unmodifiableList(cache); }
private synchronized void ensureTaskListLoaded () throws CoreException { if (!taskListInitialized) { if (result == null) { LookupListener lookupListener = new LookupListener() { @Override public void resultChanged (LookupEvent ev) { registerConnectors(); } }; result = Lookup.getDefault().lookupResult(RepositoryConnectorProvider.class); result.addLookupListener(lookupListener); } registerConnectors(); try { if (taskListStorageFile.length() > 0) { taskListWriter.readTaskList(taskList, taskListStorageFile); } } catch (CoreException ex) { LOG.log(Level.INFO, null, ex); throw new CoreException(new Status(ex.getStatus().getSeverity(), ex.getStatus().getPlugin(), "Cannot deserialize tasklist")); } finally { taskListInitialized = true; } } }
/** Prepares settings. */ private void prepareSettings() { if (prepared) return; prepared = true; // Set listening on changes of settings. fontsColors = MimeLookup.getLookup(PropertiesKit.PROPERTIES_MIME_TYPE).lookupResult(FontColorSettings.class); fontsColors.addLookupListener(WeakListeners.create(LookupListener.class, fontsColorsTracker, fontsColors)); keybindings = MimeLookup.getLookup(PropertiesKit.PROPERTIES_MIME_TYPE).lookupResult(KeyBindingSettings.class); keybindings.addLookupListener(WeakListeners.create(LookupListener.class, keybindingsTracker, keybindings)); // Init settings. updateColors(); updateKeyStrokes(); }
private void initCategories() { synchronized (this) { if (null == name2category) { if (null == lookupRes) { lookupRes = initLookup(); lookupRes.addLookupListener(new LookupListener() { @Override public void resultChanged(LookupEvent ev) { synchronized (NotificationCategoryFactory.this) { name2category = null; categories = null; } } }); } int index = 0; categories = new ArrayList<Category>(Category.getDefaultCategories()); categories.addAll(lookupRes.allInstances()); name2category = new HashMap<String, Category>(categories.size()); for (Category c : categories) { name2category.put(c.getName(), c); c.setIndex(index++); } } } }
private Lookup.Result<ModuleInfo> getModulesResult() { synchronized (this) { if (modulesResult == null) { Lookup lookup = getModuleLookup(); modulesResult = lookup. lookup(new Lookup.Template<ModuleInfo>(ModuleInfo.class)); modulesResult.addLookupListener(new LookupListener() { public void resultChanged(LookupEvent ev) { Collection<? extends ModuleInfo> l = getModulesResult().allInstances(); XMLSettingsSupport.err.fine("Modules changed: " + l); // NOI18N List reloaded; synchronized (this) { fillModules(l); reloaded = replaceReloadedModules(); XMLSettingsSupport.err.fine("Reloaded modules: " + reloaded); // NOI18N } notifyReloads(reloaded); } }); } return modulesResult; } }
private void initGroups() { synchronized( this ) { if( null == name2group ) { if( null == lookupRes ) { lookupRes = initLookup(); lookupRes.addLookupListener( new LookupListener() { public void resultChanged(LookupEvent ev) { synchronized( TaskGroupFactory.this ) { name2group = null; groups = null; } } }); } int index = 0; groups = new ArrayList<TaskGroup>( lookupRes.allInstances() ); name2group = new HashMap<String,TaskGroup>(groups.size()); for( TaskGroup tg : groups) { name2group.put( tg.getName(), tg ); tg.setIndex( index++ ); } } } }
@Override public void resultChanged(LookupEvent ev) { synchronized (PathLookupResult.this) { items = null; } List<LookupListener> lls; synchronized (listeners) { if (listeners.isEmpty()) { return; } else { lls = new ArrayList<LookupListener>(listeners); } } LookupEvent lev = new LookupEvent(PathLookupResult.this); for (LookupListener ll : lls) { ll.resultChanged(lev); } }
public void testProxyLookupFailsToFireEventWhenProxiedLookupChanged() { InstanceContent ic = new InstanceContent(); // AbstractLookup al = new AbstractLookup(ic); Lookup proxy = new AbstractLookup(ic); final int[] counts = {0}; // Number of items observed upon a LookupEvent final Lookup.Result<String> result = proxy.lookupResult(String.class); result.addLookupListener(new LookupListener() { public void resultChanged(LookupEvent ev) { // this should be called but never is assertSame(result, ev.getSource()); counts[0] = result.allInstances().size(); } }); ic.add("hello1"); assertEquals(1, counts[0]); }
private List<URL> defaultJavadoc(final boolean listen) { final JavaPlatform safePlatform = new ForwardingJavaPlatform(this) { @Override public List<URL> getJavadocFolders() { return Collections.<URL>emptyList(); } }; final Set<URI> roots = new LinkedHashSet<>(); final Lookup.Result<? extends J2SEPlatformDefaultJavadoc> res = getJ2SEPlatformDefaultJavadoc(); if (listen) { synchronized (this) { if (jdocListener == null) { jdocListener = new LookupListener[2]; jdocListener[0] = new LookupListener() { @Override public void resultChanged(LookupEvent ev) { javadoc = null; } }; jdocListener[1] = WeakListeners.create(LookupListener.class, jdocListener[0], res); res.addLookupListener(jdocListener[1]); } } } for (J2SEPlatformDefaultJavadoc jdoc : res.allInstances()) { roots.addAll(jdoc.getDefaultJavadoc(safePlatform)); } final List<URL> result = new ArrayList<>(roots.size()); for (URI root : roots) { try { result.add(root.toURL()); } catch (MalformedURLException ex) { Exceptions.printStackTrace(ex); } } return Collections.unmodifiableList(result); }
@NonNull private List<URL> defaultSources(final boolean listen) { final JavaPlatform safePlatform = new ForwardingJavaPlatform(this) { @Override public List<URL> getJavadocFolders() { return Collections.<URL>emptyList(); } }; final Set<URI> roots = new LinkedHashSet<>(); final Lookup.Result<? extends J2SEPlatformDefaultSources> res = getJ2SEPlatformDefaultSources(); if (listen) { synchronized (this) { if (sourcesListener == null) { sourcesListener = new LookupListener[2]; sourcesListener[0] = new LookupListener() { @Override public void resultChanged(LookupEvent ev) { sources = null; } }; sourcesListener[1] = WeakListeners.create(LookupListener.class, sourcesListener[0], res); res.addLookupListener(sourcesListener[1]); } } } for (J2SEPlatformDefaultSources src : res.allInstances()) { roots.addAll(src.getDefaultSources(safePlatform)); } final List<URL> result = new ArrayList<>(roots.size()); for (URI root : roots) { try { result.add(root.toURL()); } catch (MalformedURLException ex) { Exceptions.printStackTrace(ex); } } return Collections.unmodifiableList(result); }
public void removeLookupListener(LookupListener l) { boolean remove; synchronized (this) { listeners = AbstractLookup.modifyListenerList(false, l, listeners); remove = listeners == null; } if (remove) { result.removeLookupListener(weak); } }
public void addLookupListener(LookupListener l) { synchronized (listeners) { if (listeners.isEmpty()) { if (lastResults == null) { lastResults = allInstances(); } delegate.addLookupListener(this); } listeners.add(l); } }
public FoldViewFactory(View documentView) { super(documentView); foldHierarchy = FoldHierarchy.get(textComponent()); // the view factory may get eventually GCed, but the FoldHierarchy can survive, snce it is tied to the component. weakL = WeakListeners.create(FoldHierarchyListener.class, this, foldHierarchy); foldHierarchy.addFoldHierarchyListener(weakL); // Go through folds and search for collapsed fold. foldHierarchy.lock(); try { @SuppressWarnings("unchecked") Iterator<Fold> it = FoldUtilities.collapsedFoldIterator(foldHierarchy, 0, Integer.MAX_VALUE); collapsedFoldEncountered = it.hasNext(); } finally { foldHierarchy.unlock(); } displayAllFoldsExpanded = Boolean.TRUE.equals(textComponent().getClientProperty(DISPLAY_ALL_FOLDS_EXPANDED_PROPERTY)); String mime = DocumentUtilities.getMimeType(document()); Lookup lkp = MimeLookup.getLookup(mime); colorSource = lkp.lookupResult(FontColorSettings.class); colorSource.addLookupListener(WeakListeners.create(LookupListener.class, this, colorSource)); colorSettings = (FontColorSettings)colorSource.allInstances().iterator().next(); prefs = lkp.lookup(Preferences.class); prefs.addPreferenceChangeListener(WeakListeners.create(PreferenceChangeListener.class, this, prefs)); initViewFlags(); }
public void testEventDeliveredAsynchronously() throws Exception { class L implements LookupListener { int change; Object id = new Object(); @Override public synchronized void resultChanged(LookupEvent ev) { change++; notifyAll(); } public synchronized void createSavable() { assertEquals("No changes yet", 0, change); Savable s = new DoSave(id, null, null); assertEquals("The first", s, Savable.REGISTRY.lookup(Savable.class)); assertEquals("Still no changes", 0, change); } public synchronized void waitForChange() throws InterruptedException { while (change == 0) { wait(); } assertEquals("One change delivered", 1, change); } } L listener = new L(); Result<Savable> res = Savable.REGISTRY.lookupResult(Savable.class); try { res.addLookupListener(listener); listener.createSavable(); listener.waitForChange(); } finally { res.removeLookupListener(listener); } }
/** Adds itself as a listener for changes in current ActionMap. * If the lookup is null then it means to listen on TopComponent * otherwise to listen on the lookup itself. * * @param lookup lookup to listen on or null */ private void attachListenerToChangesInMap(Lookup lookup) { if (lookup == null) { TopComponent.getRegistry().addPropertyChangeListener(WeakListeners.propertyChange(this, TopComponent.getRegistry())); } else { result = lookup.lookupResult(ActionMap.class); weakLookup = WeakListeners.create(LookupListener.class, this, result); result.addLookupListener(weakLookup); } checkStateChanged(false); }
/** * @param innerLanguage * @param mimePath note it may start with mimeTypeForOptions */ public FCSInfo(String mimePath, Language<T> innerLanguage) { this.innerLanguage = innerLanguage; this.mimePath = mimePath; this.listeners = new ListenerList<ChangeListener>(); Lookup lookup = MimeLookup.getLookup(MimePath.parse(mimePath)); result = lookup.lookupResult(FontColorSettings.class); // Do not listen on font color settings changes in tests // since "random" lookup events translate into highlight change events // that are monitored by tests and so the tests may then fail if (TEST_FALLBACK_COLORING == null) { result.addLookupListener(WeakListeners.create(LookupListener.class, this, result)); } updateFCS(); }
WhitespaceHighlighting(JTextComponent c) { // Upon doc change all layers become recreated by infrastructure (no need to listen for doc change) this.doc = c.getDocument(); this.docText = DocumentUtilities.getText(doc); doc.addDocumentListener(this); String mimeType = (String) doc.getProperty("mimeType"); //NOI18N if (mimeType == null) { mimeType = ""; } Lookup lookup = MimeLookup.getLookup(mimeType); result = lookup.lookupResult(FontColorSettings.class); result.addLookupListener(WeakListeners.create(LookupListener.class, this, result)); resultChanged(null); // Update attrs }
EmbeddingHighlightsContainer(Document document) { this.document = document; lookupResult = MimeLookup.getLookup(HTML_MIME_TYPE).lookupResult(FontColorSettings.class); lookupResult.addLookupListener(WeakListeners.create(LookupListener.class, lookupListener = new LookupListener() { @Override public void resultChanged(LookupEvent ev) { refreshColorings(); } }, lookupResult)); refreshColorings(); }
/** * Adds PropertyChangeListener on list of open library managers. * The listener is notified when list of open library managers changes via * {@link #PROP_OPEN_LIBRARY_MANAGERS}. * @param listener to be notified */ public static synchronized void addOpenManagersPropertyChangeListener (PropertyChangeListener listener) { Parameters.notNull("listener", listener); //NOI18N if (areaProvidersLookupResult == null) { areaProvidersLookupResult = Lookup.getDefault().lookupResult(ArealLibraryProvider.class); attachListeners(areaProvidersLookupResult.allInstances()); areaProvidersLookupResult.addLookupListener(new LookupListener() { public void resultChanged(LookupEvent ev) { attachListeners(areaProvidersLookupResult.allInstances()); } }); } openLibraryManagerListListeners.addPropertyChangeListener (listener); }
/** Creates the lookup. * @param tc component to work on * @param map action map to add to the lookup */ public DefaultEMLookup(ExplorerManager tc, javax.swing.ActionMap map) { super(); this.tc = tc; this.listener = WeakListeners.create(LookupListener.class, this, null); this.actionMap = Lookups.singleton(map); tc.addPropertyChangeListener(WeakListeners.propertyChange(this, tc)); updateLookups(tc.getSelectedNodes()); }
public void removeLookupListener(LookupListener l) { synchronized (listeners) { listeners.remove(l); if (listeners.isEmpty()) { delegate.removeLookupListener(this); } } }
@Messages("CAP_Opening_Projects=Opening Projects") @SuppressWarnings("LeakingThisInConstructor") public LoadOpenProjects(int a) { action = a; currentFiles = Utilities.actionsGlobalContext().lookupResult(FileObject.class); currentFiles.addLookupListener(WeakListeners.create(LookupListener.class, this, currentFiles)); progress = ProgressHandleFactory.createHandle(CAP_Opening_Projects()); }
@SuppressWarnings("LeakingThisInConstructor") public ActiveConfigAction() { super(); putValue("noIconInMenu", true); // NOI18N EventQueue.invokeLater(new Runnable() { public @Override void run() { initConfigListCombo(); } }); lst = new PropertyChangeListener() { public @Override void propertyChange(PropertyChangeEvent evt) { ProjectConfigurationProvider<?> _pcp; synchronized (ActiveConfigAction.this) { _pcp = pcp; } if (ProjectConfigurationProvider.PROP_CONFIGURATIONS.equals(evt.getPropertyName())) { configurationsListChanged(_pcp != null ? getConfigurations(_pcp) : null); } else if (ProjectConfigurationProvider.PROP_CONFIGURATION_ACTIVE.equals(evt.getPropertyName())) { activeConfigurationChanged(_pcp != null ? getActiveConfiguration(_pcp) : null); } } }; looklst = new LookupListener() { public @Override void resultChanged(LookupEvent ev) { activeProjectProviderChanged(); } }; OpenProjectList.getDefault().addPropertyChangeListener(WeakListeners.propertyChange(this, OpenProjectList.getDefault())); lookup = LookupSensitiveAction.LastActivatedWindowLookup.INSTANCE; Lookup.Result<Project> resultPrj = lookup.lookupResult(Project.class); Lookup.Result<DataObject> resultDO = lookup.lookupResult(DataObject.class); resultPrj.addLookupListener(WeakListeners.create(LookupListener.class, this, resultPrj)); resultDO.addLookupListener(WeakListeners.create(LookupListener.class, this, resultDO)); refreshView(lookup); }
public void testRemoveWrongListener() { class LL implements LookupListener { @Override public void resultChanged(LookupEvent ev) { } } LL l1 = new LL(); LL l2 = new LL(); Object list = AbstractLookup.modifyListenerList(true, l1, null); Object newList = AbstractLookup.modifyListenerList(false, l2, list); assertSame("No change when removing l2 instead of l1", list, newList); }
/** * @return All the registered implementations. */ public static Collection<? extends KeymapManager> getKeymapManagerInstances() { if (managers != null) { return managers; } final Lookup.Result r = Lookup.getDefault().lookupResult(KeymapManager.class); ArrayList<KeymapManager> al = new ArrayList<KeymapManager>(r.allInstances()); al.trimToSize(); if (LOG.isLoggable(Level.FINE)) { LOG.fine("Dumping registered KeymapManagers: "); for (KeymapManager m : al) { LOG.fine(" KeymapManager: " + s2s(m)); } LOG.fine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); } synchronized (KeymapModel.class) { if (managers == null) { managers = al; r.addLookupListener(new LookupListener() { @Override public void resultChanged(LookupEvent ev) { synchronized (KeymapModel.class) { managers = null; r.removeLookupListener(this); } if (INSTANCE != null) { INSTANCE.refreshActions(); } } }); } } return al; }
/** * Issues of changes in layer */ public void testForChangeInLayer() throws IOException{ // issue #63338 // http://www.netbeans.org/issues/show_bug.cgi?id=63338 // Subj: deadlock during showing annotations // fix: deadlock occured in after inproper firing of lookup changed event. // event was fired even in cases, the lookup listener should be quiet. MimeLookup lookup = MimeLookup.getMimeLookup("text/jsp"); //NOI18N Result result = lookup.lookup(new Template(TestLookupObject.class)); result.allInstances().size(); // remove this line if issue #60010 is fixed LookupListener listener = new LookupListener(){ public void resultChanged(LookupEvent ev){ resultChangedCount[0]++; } }; result.addLookupListener(listener); //simulate module installation, new file will be added createFile("Editors/text/jsp/testLookup/org-openide-actions-PasteAction.instance"); //NOI18N checkResultChange(0); TestUtilities.deleteFile(getWorkDir(), "Editors/text/jsp/testLookup/org-netbeans-modules-editor-mimelookup-impl-TestLookupObject.instance"); checkResultChange(1); result.removeLookupListener(listener); resultChangedCount[0] = 0; // end of issue #63338 ------------------------------------------------ }
@Override public void resultChanged(LookupEvent ev) { if (ev.getSource() == nodes) { Collection<? extends Item<Provider>> arr = nodes.allItems(); if (arr.size() == 1 && arr.iterator().next().getInstance() == null) { return; } initValues(); return; } final LookupEvent mev = new LookupEvent(this); for (LookupListener ll : listeners) { ll.resultChanged(mev); } }
private void listenOnModules() { Lookup.Result<ModuleInfo> modules = modulesResult.get(); if (modules == null) { modules = Lookup.getDefault().lookupResult(ModuleInfo.class); if (modulesResult.compareAndSet(null, modules)) { modules.addLookupListener(WeakListeners.create(LookupListener.class, this, modules)); } } }
private static InstalledFileLocator[] getInstances() { synchronized (LOCK) { if (instances != null) { return instances; } } Lookup.Result<InstalledFileLocator> _result; synchronized (LOCK) { _result = result; } if (_result == null) { _result = Lookup.getDefault().lookupResult(InstalledFileLocator.class); _result.addLookupListener(new LookupListener() { public @Override void resultChanged(LookupEvent e) { synchronized (LOCK) { instances = null; } } }); synchronized (LOCK) { result = _result; } } Collection<? extends InstalledFileLocator> c = _result.allInstances(); synchronized (LOCK) { return instances = c.toArray(new InstalledFileLocator[c.size()]); } }
ProjectInfo( @NonNull final Project project, @NonNull final ProjectConvertor.Result result) { Parameters.notNull("project", project); //NOI18N Parameters.notNull("result", result); //NOI18N this.project = project; this.result = result; this.pcs = new PropertyChangeSupport(this); this.eventSource = project.getLookup().lookupResult(ProjectInformation.class); this.eventSource.addLookupListener(WeakListeners.create(LookupListener.class, this, eventSource)); }
@SuppressWarnings("LeakingThisInConstructor") public BraceMatchingSidebarComponent(JTextComponent editor) { this.editor = editor; this.mimeType = DocumentUtilities.getMimeType(editor); this.prefs = MimeLookup.getLookup(MimePath.EMPTY).lookup(Preferences.class); final Lookup.Result r = MimeLookup.getLookup(org.netbeans.lib.editor.util.swing.DocumentUtilities.getMimeType(editor)).lookupResult( FontColorSettings.class); prefListenerGC = new PrefListener(); this.colorResult = r; r.addLookupListener(WeakListeners.create(LookupListener.class, this , r)); prefs.addPreferenceChangeListener(WeakListeners.create(PreferenceChangeListener.class, prefListenerGC, prefs)); loadPreferences(); editorPane = findEditorPane(editor); Component parent = editor.getParent(); if (parent instanceof JLayeredPane) { parent = parent.getParent(); } if (parent instanceof JViewport) { this.viewport = (JViewport)parent; // see #219015; need to listen on viewport change to show/hide the tooltip viewport.addChangeListener(WeakListeners.change(this, viewport)); } TextUI ui = editor.getUI(); if (ui instanceof BaseTextUI) { baseUI = (BaseTextUI)ui; MasterMatcher.get(editor).addMatchListener(this); } else { baseUI = null; } setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE)); updatePreferredSize(); }