org.openide.util.LookupListener Java Examples

The following examples show how to use org.openide.util.LookupListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NbEditorToolBar.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public NbEditorToolBar(JTextComponent component) {
        this.componentRef = new WeakReference(component);
        
        setFloatable(false);
        //mkleint - instead of here, assign the border in CloneableEditor and MultiView module.
//        // special border installed by core or no border if not available
//        Border b = (Border)UIManager.get("Nb.Editor.Toolbar.border"); //NOI18N
//        setBorder(b);
        addMouseListener(sharedMouseListener);

        installModulesInstallationListener();
        installNoOpActionMappings();
        
        lookupResult = MimeLookup.getLookup(DocumentUtilities.getMimeType(component)).lookupResult(KeyBindingSettings.class);
        lookupResult.addLookupListener(WeakListeners.create(LookupListener.class, keybindingsTracker, lookupResult));
        
        String mimeType = DocumentUtilities.getMimeType(component);
        preferences = MimeLookup.getLookup(mimeType == null ? MimePath.EMPTY : MimePath.parse(mimeType)).lookup(Preferences.class);
        preferences.addPreferenceChangeListener(WeakListeners.create(PreferenceChangeListener.class, prefsTracker, preferences));
        
        refreshToolbarButtons();
        setBorderPainted(true);
    }
 
Example #2
Source File: Selenium2Support.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #3
Source File: CodeFoldingSideBar.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #4
Source File: LookupSensitiveAction.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** 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;
    }
}
 
Example #5
Source File: ColoringMap.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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));
}
 
Example #6
Source File: SimpleProxyLookup.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Access to listeners. Initializes the listeners field if needed -
 * e.g. if adding a listener and listeners are <code>null</code>.
 *
 * @return the listeners
 */
private synchronized LookupListenerList getListeners(LookupListener toAdd, LookupListener toRemove) {
    if (toAdd == null && listeners == null) {
        return null;
    }
    if (listeners == null) {
        listeners = new LookupListenerList();
    }
    if (toAdd != null) {
        listeners.add(toAdd);
    }
    if (toRemove != null) {
        listeners.remove(toRemove);
    }
    return listeners;
}
 
Example #7
Source File: TaskGroupFactory.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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++ );
            }
        }
    }
}
 
Example #8
Source File: NodeRegistry.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Initialize the registry
 * @param folder the name of the xml layer folder to use
 * @param dataLookup the lookup to use when creating providers
 */
private void init(String folder, final Lookup dataLookup) {
    Lookup lookup = Lookups.forPath(PATH + folder + NODEPROVIDERS);
    lookupResult = lookup.lookupResult(NodeProviderFactory.class);

    initProviders(dataLookup);
    
    // listen for changes and re-init the providers when the lookup changes
    lookupResult.addLookupListener(WeakListeners.create(LookupListener.class,
        lookupListener = new LookupListener() {
            @Override
            public void resultChanged(LookupEvent ev) {
                initProviders(dataLookup);
                changeSupport.fireChange();
            }
        },
        lookupResult)
    );
}
 
Example #9
Source File: CodeFoldingSideBar.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #10
Source File: JavaSourceTaskFactoryManager.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** 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();
}
 
Example #11
Source File: LayoutMultiViewEditorElement.java    From NBANDROID-V2 with Apache License 2.0 6 votes vote down vote up
private void start() {
    Runnable runnable = new Runnable() {
        @Override
        public void run() {
            project = FileOwnerQuery.getOwner(dataObject.getPrimaryFile());
            lookupResultAndroidProject = project.getLookup().lookupResult(AndroidProject.class);
            lookupResulClassPathProvider = project.getLookup().lookupResult(AndroidClassPathProvider.class);
            lookupResulBuildVariant = project.getLookup().lookupResult(BuildVariant.class);
            lookupResultAndroidProject.addLookupListener(WeakListeners.create(LookupListener.class, LayoutMultiViewEditorElement.this, lookupResultAndroidProject));
            lookupResulClassPathProvider.addLookupListener(WeakListeners.create(LookupListener.class, LayoutMultiViewEditorElement.this, lookupResulClassPathProvider));
            lookupResulBuildVariant.addLookupListener(WeakListeners.create(LookupListener.class, LayoutMultiViewEditorElement.this, lookupResulBuildVariant));
            resultChanged(null);
        }
    };
    ProjectManager.mutex().postWriteRequest(runnable);
}
 
Example #12
Source File: AndroidClassPathProvider.java    From NBANDROID-V2 with Apache License 2.0 6 votes vote down vote up
public AndroidClassPathProvider(BuildVariant buildConfig, Project project) {
    this.buildConfig = Preconditions.checkNotNull(buildConfig);
    this.project = project;
    lookupResultProjectModel = project.getLookup().lookupResult(AndroidProject.class);
    lookupResultProjectModel.addLookupListener(WeakListeners.create(LookupListener.class, this, lookupResultProjectModel));
    buildConfig.addChangeListener(WeakListeners.change(this, buildConfig));
    source = createSource();
    test = createTest();
    compile = createCompile();
    boot = createBoot();
    execute = createExecute(compile);
    testCompile = createTestCompile(execute);
    register();
    resultChanged(null);

}
 
Example #13
Source File: ProxyLookupResultListenerTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Test
public void testListener() {
    final AtomicReference<Boolean> refContainsTarget = new AtomicReference<Boolean>(null);
    final AccessibleProxyLookup proxy = new AccessibleProxyLookup(Lookup.EMPTY);
    final Lookup.Result<Serializable> lookupResult = proxy.lookupResult(Serializable.class);

    lookupResult.addLookupListener(new LookupListener() {

        @Override
        public void resultChanged(final LookupEvent le) {
            refContainsTarget.set(!lookupResult.allInstances().isEmpty());
        }
    });

    for (int i = 0; i < parameters.size(); i++) {
        final Params params = parameters.get(i);

        if (params.checkSize) {
            proxy.lookupAll(Serializable.class).size();
        }

        proxy.changeLookups(createLookup(params.addTargetType));

        final StringBuilder sb = new StringBuilder("LookupListener set the value to something unexpected.\n");

        for (int idx = 0; idx < parameters.size(); idx++) {
            sb.append('[').append(idx).append("] = ").append(parameters.get(idx)).append('\n');
        }

        sb.append("Failed at [").append(i).append("]");

        assertEquals(sb.toString(), params.expected, refContainsTarget.get());
    }
}
 
Example #14
Source File: PageInspectorListener.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
    lookupResult = Lookup.getDefault().lookupResult(PageInspector.class);
    lookupResult.addLookupListener(new LookupListener() {
        @Override
        public void resultChanged(LookupEvent ev) {
            refreshPageInspector();
        }
    });
    refreshPageInspector();
}
 
Example #15
Source File: AddLandCoverAction.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
public AddLandCoverAction(Lookup lkp) {
    super(Bundle.CTL_AddLandCoverAction_MenuText());
    this.lkp = lkp;
    Lookup.Result<ProductNode> lkpContext = lkp.lookupResult(ProductNode.class);
    lkpContext.addLookupListener(WeakListeners.create(LookupListener.class, this, lkpContext));
    setEnableState();
    putValue(Action.SHORT_DESCRIPTION, Bundle.CTL_AddLandCoverAction_ShortDescription());
}
 
Example #16
Source File: OpenImageViewAction.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
public OpenImageViewAction(Lookup lookup) {
    putValue(Action.NAME, Bundle.CTL_OpenImageViewActionName());
    this.lookup = lookup;
    Lookup.Result<RasterDataNode> rasterDataNodeResult = lookup.lookupResult(RasterDataNode.class);
    rasterDataNodeResult.addLookupListener(WeakListeners.create(LookupListener.class, this, rasterDataNodeResult));
    setEnabledState();
    setActionName();
}
 
Example #17
Source File: LookupListenerList.java    From netbeans with Apache License 2.0 5 votes vote down vote up
synchronized void remove(LookupListener l) {
    if (listeners == null) {
        return;
    } else if (listeners instanceof LookupListener) {
        if (listeners == l) {
            listeners = null;
        }
    } else {
        LookupListener[] arr = (LookupListener[]) listeners;
        LookupListener[] newArr = new LookupListener[arr.length - 1];
        int indx = 0;
        for (int i = 0; i < arr.length; i++) {
            if (l == arr[i]) {
                continue;
            }
            if (indx == newArr.length) {
                return;
            }
            newArr[indx++] = arr[i];
        }
        if (newArr.length == 0) {
            listeners = null;
        } else {
            listeners = newArr;
        }
    }
}
 
Example #18
Source File: AddElevationAction.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
public AddElevationAction(Lookup lkp) {
    super(Bundle.CTL_AddElevationAction_MenuText());
    this.lkp = lkp;
    Lookup.Result<ProductNode> lkpContext = lkp.lookupResult(ProductNode.class);
    lkpContext.addLookupListener(WeakListeners.create(LookupListener.class, this, lkpContext));
    setEnableState();
    putValue(Action.SHORT_DESCRIPTION, Bundle.CTL_AddElevationAction_ShortDescription());
}
 
Example #19
Source File: NbProjectInformationProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void annotatorsChanged() {
    synchronized (LOCK) {
        if (!annotatorsInitialized) {
            annotatorResult = Lookup.getDefault().lookupResult(ProjectIconAnnotator.class);
            annotatorResult.addLookupListener(WeakListeners.create(LookupListener.class, this, annotatorResult));
            annotatorsInitialized = true;
        }
        for (ProjectIconAnnotator pa : annotatorResult.allInstances()) {
            if (annotators.add(pa)) {
                pa.addChangeListener(WeakListeners.change(this, pa));
            }
        }
    }
}
 
Example #20
Source File: LookupListenerList.java    From netbeans with Apache License 2.0 5 votes vote down vote up
synchronized int getListenerCount() {
    if (listeners == null) {
        return 0;
    } else if (listeners instanceof LookupListener) {
        return 1;
    } else {
        return ((LookupListener[])listeners).length;
    }
}
 
Example #21
Source File: ExportMaskPixelsAction.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
public ExportMaskPixelsAction(Lookup lkp) {
    super(Bundle.CTL_ExportMaskPixelsAction_MenuText());
    putValue("popupText", Bundle.CTL_ExportMaskPixelsAction_PopupText());
    result = lkp.lookupResult(ProductSceneView.class);
    result.addLookupListener(WeakListeners.create(LookupListener.class, this, result));
    setEnabled(false);
}
 
Example #22
Source File: DefaultTopComponentLookup.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void resultChanged(LookupEvent ev) {
    LookupEvent ev2 = new LookupEvent(this);
    LookupListener[] ls;

    synchronized (listeners) {
        ls = listeners.toArray(new LookupListener[listeners.size()]);
    }

    for (int i = 0; i < ls.length; i++) {
        ls[i].resultChanged(ev2);
    }
}
 
Example #23
Source File: ExportGeometryAction.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
public ExportGeometryAction(Lookup lookup) {
    super(Bundle.CTL_ExportGeometryAction_MenuText());
    this.lookup = lookup;
    result = lookup.lookupResult(VectorDataNode.class);
    result.addLookupListener(WeakListeners.create(LookupListener.class, this, result));
    vectorDataNode = lookup.lookup(VectorDataNode.class);
    setEnabled(vectorDataNode != null);
}
 
Example #24
Source File: SyntaxHighlighting.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * @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();
}
 
Example #25
Source File: ExtProjectConvertorServices.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
LogicalView(@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.support = new ChangeSupport(this);
    this.eventSource = project.getLookup().lookupResult(LogicalViewProvider.class);
    this.eventSource.addLookupListener(WeakListeners.create(LookupListener.class, this, this.eventSource));
}
 
Example #26
Source File: DefaultSelectionSupport.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private LookupListener createLookupListener() {
    return ev -> {
        Collection<? extends T> allItems = itemResult.allInstances();


        Stream<? extends T> deselectedStream = currentlySelectedItems.stream().filter((Predicate<T>) (o) -> !allItems.contains(o));
        T[] allDeselected = deselectedStream.toArray(value -> (T[]) Array.newInstance(type, value));
        T firstDeselected = null;
        if (allDeselected.length > 0) {
            firstDeselected = allDeselected[0];
        }

        Stream<? extends T> newlySelectedStream = allItems.stream().filter((Predicate<T>) (o) -> !currentlySelectedItems.contains(o));
        T[] allNewlySelected = newlySelectedStream.toArray(value -> (T[]) Array.newInstance(type, value));
        T firstSelected = null;
        if (allNewlySelected.length > 0) {
            firstSelected = allNewlySelected[0];
        }

        currentlySelectedItems = allItems;

        // todo check if implementation is correct - ASAP!

        for (Handler<T> handler : handlerList) {
            handler.selectionChange(firstDeselected, firstSelected);
        }
    };
}
 
Example #27
Source File: LibraryManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #28
Source File: ImportVectorDataNodeFromShapefileAction.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
public ImportVectorDataNodeFromShapefileAction(Lookup lookup) {
    this.lookup = lookup;
    result = lookup.lookupResult(Product.class);
    result.addLookupListener(
            WeakListeners.create(LookupListener.class, this, result));
    setEnableState();
    setHelpId(Bundle.CTL_ImportVectorDataNodeFromShapefileActionHelp());
    putValue(Action.NAME, Bundle.CTL_ImportVectorDataNodeFromShapefileActionText());
    putValue(Action.SHORT_DESCRIPTION, Bundle.CTL_ImportVectorDataNodeFromShapefileActionDescription());
}
 
Example #29
Source File: TabbedController.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Creates new instance
 * @param tabFolder layer folder where subpanels (AdvancedOption instances) reside
 */
public TabbedController(String tabFolder) {
    this.tabFolder = tabFolder;
    tabTitle2Option = Collections.synchronizedMap(new LinkedHashMap<String, AdvancedOption>());
    readPanels();
    options.addLookupListener(WeakListeners.create(LookupListener.class, lookupListener, options));
}
 
Example #30
Source File: ExportMetadataAction.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
public ExportMetadataAction(Lookup lookup) {
    super(Bundle.CTL_ExportMetadataAction_MenuText());
    this.lookup = lookup;
    result = lookup.lookupResult(MetadataElement.class);
    result.addLookupListener(WeakListeners.create(LookupListener.class, this, result));
    setEnabled(false);
}