Java Code Examples for org.openide.util.WeakListeners#change()

The following examples show how to use org.openide.util.WeakListeners#change() . 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: ModuleNames.java    From netbeans with Apache License 2.0 6 votes vote down vote up
BinCacheLine(
        @NonNull final URL artefact,
        @NonNull final String modName,
        @NullAllowed final CompilerOptionsQuery.Result cops,
        @NullAllowed final BinaryForSourceQuery.Result res) {
    super(artefact, modName);
    this.cops = cops;
    this.res =  res;
    if (this.cops != null) {
        this.copsCl = WeakListeners.change(this, this.cops);
        this.cops.addChangeListener(copsCl);
    } else {
        this.copsCl = null;
    }
    if (this.res != null) {
        this.resCl = WeakListeners.change(this, this.res);
        this.res.addChangeListener(resCl);
    } else {
        this.resCl = null;
    }
}
 
Example 2
Source File: JavacParser.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void init(final Task task) {
    if (!initialized) {
        ClasspathInfo _tmpInfo = null;
        if (task instanceof ClasspathInfo.Provider &&
            (_tmpInfo = ((ClasspathInfo.Provider)task).getClasspathInfo()) != null) {
            if (cpInfo != null && weakCpListener != null) {
                cpInfo.removeChangeListener(weakCpListener);
                this.weakCpListener = null;
            }
            cpInfo = _tmpInfo;
            this.weakCpListener = WeakListeners.change(cpInfoListener, cpInfo);
            cpInfo.addChangeListener (this.weakCpListener);
            root = Optional.ofNullable(cpInfo.getClassPath(PathKind.SOURCE))
                    .map((cp)-> {
                        FileObject[] roots = cp.getRoots();
                        return roots.length > 0 ? roots[0] : null;
                    })
                    .orElse(null);
        } else {
            throw new IllegalArgumentException("No classpath provided by task: " + task);
        }
        initialized = true;
    }
}
 
Example 3
Source File: WhiteListQueryImplementationMerged.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private Iterable<WhiteListImplementation> getWhiteLists() {
    synchronized (this) {
        if (cache != null) {
            return cache.keySet();
        }
    }
    final Map<WhiteListImplementation,ChangeListener> map = new IdentityHashMap<WhiteListImplementation,ChangeListener>();
    for (WhiteListQueryImplementation wlq : lr.allInstances()) {
        final WhiteListImplementation wl = wlq.getWhiteList(file);
        if (wl != null) {
            final ChangeListener cl = WeakListeners.change(this, wl);
            wl.addChangeListener(cl);
            map.put(wl, cl);
        }
    }
    synchronized (this) {
        if (cache == null) {
            cache = map;
        }
        return cache.keySet();
    }
}
 
Example 4
Source File: BracesMatchHighlighting.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void propertyChange(PropertyChangeEvent evt) {
    if (evt.getPropertyName() == null || "caret".equals(evt.getPropertyName())) { //NOI18N
        if (caret != null) {
            caret.removeChangeListener(caretListener);
            caretListener = null;
        }
        
        caret = component.getCaret();
        
        if (caret != null) {
            caretListener = WeakListeners.change(this, caret);
            caret.addChangeListener(caretListener);
        }
        
        refresh();
    } else if (MasterMatcher.PROP_SEARCH_DIRECTION.equals(evt.getPropertyName()) ||
               MasterMatcher.PROP_CARET_BIAS.equals(evt.getPropertyName()) ||
               MasterMatcher.PROP_MAX_BACKWARD_LOOKAHEAD.equals(evt.getPropertyName()) ||
               MasterMatcher.PROP_MAX_FORWARD_LOOKAHEAD.equals(evt.getPropertyName())
    ) {
        refresh();
    }
}
 
Example 5
Source File: FolderChildren.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Initializes the children.
*/
@Override
protected void addNotify () {
    err.fine("addNotify begin");
    // add as a listener for changes on nodes
    folder.addPropertyChangeListener(listener);
    folder.getPrimaryFile().addFileChangeListener(fcListener);
    // add listener to the filter
    if ( filter instanceof ChangeableDataFilter ) {
        ChangeableDataFilter chF = (ChangeableDataFilter)filter;
        changeListener = WeakListeners.change(this, chF);
        chF.addChangeListener( changeListener );
    }
    // #159628, #189979: do not block EQ loading this folder's children.
    refreshChildren(RefreshMode.SHALLOW);
    err.fine("addNotify end");
}
 
Example 6
Source File: CaretBasedBlockHighlighting.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void propertyChange(PropertyChangeEvent evt) {
    if (evt.getPropertyName() == null || "caret".equals(evt.getPropertyName())) { //NOI18N
        if (caret != null) {
            caret.removeChangeListener(caretListener);
            caretListener = null;
        }
        
        caret = component.getCaret();
        
        if (caret != null) {
            caretListener = WeakListeners.change(this, caret);
            caret.addChangeListener(caretListener);
        }
        
        updateLineInfo(true);
    }
}
 
Example 7
Source File: ToggleBookmarkAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void rebuild() {
    // Hookup the bookmark list
    BookmarkList newBookmarks = BookmarkList.get(component.getDocument());
    if (newBookmarks != bookmarks) {
        if (bookmarksListener != null) {
            bookmarks.removePropertyChangeListener (bookmarksListener);
            bookmarksListener = null;
        }

        bookmarks = newBookmarks;

        if (bookmarks != null) {
            bookmarksListener = WeakListeners.propertyChange(this, bookmarks);
            bookmarks.addPropertyChangeListener (bookmarksListener);
        }
    }
    
    // Hookup the caret
    Caret newCaret = component.getCaret();
    if (newCaret != caret) {
        if (caretListener != null) {
            caret.removeChangeListener(caretListener);
            caretListener = null;
        }

        caret = newCaret;

        if (caret != null) {
            caretListener = WeakListeners.change(this, caret);
            caret.addChangeListener(caretListener);
        }
    }
    
    lastCurrentLineStartOffset = -1;
    updateState();
}
 
Example 8
Source File: PackageViewChildren.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void run() {
    computeKeys();
    refreshKeys();
    try { 
        FileSystem fs = root.getFileSystem();
        wfcl = FileUtil.weakFileChangeListener(this, fs);
        fs.addFileChangeListener( wfcl );
    }
    catch ( FileStateInvalidException e ) {
        Exceptions.printStackTrace(e);
    }
    wvqcl = WeakListeners.change( this, VisibilityQuery.getDefault() );
    VisibilityQuery.getDefault().addChangeListener( wvqcl );
}
 
Example 9
Source File: DiffViewModeSwitcher.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void setupMode (DiffController view) {
    JTabbedPane tabPane = findTabbedPane(view.getJComponent());
    if (tabPane != null) {
        if (!handledViews.containsKey(tabPane)) {
            ChangeListener list = WeakListeners.change(this, tabPane);
            handledViews.put(tabPane, list);
            tabPane.addChangeListener(list);
        }
        if (tabPane.getTabCount() > diffViewMode) {
            tabPane.setSelectedIndex(diffViewMode);
        }
    }
}
 
Example 10
Source File: ProjectsRootNode.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void setProjectFiles(Project project) {
    Sources sources = ProjectUtils.getSources(project);  // returns singleton
    if (sourcesListener == null) {
        sourcesListener = WeakListeners.change(this, sources);
        sources.addChangeListener(sourcesListener);
    }
    setGroups(Arrays.asList(sources.getSourceGroups(Sources.TYPE_GENERIC)), project.getProjectDirectory());
}
 
Example 11
Source File: CaretBasedBlockHighlighting.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void init() {
    this.component.addPropertyChangeListener(WeakListeners.propertyChange(this, this.component));

    // Hook up the caret
    this.caret = component.getCaret();
    if (this.caret != null) {
        this.caretListener = WeakListeners.change(this, this.caret);
        this.caret.addChangeListener(caretListener);
    }

    // Calculate the current line position
    updateLineInfo(false);
}
 
Example 12
Source File: ConfFilesNodeFactory.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected void setProjectFiles(Project project) {
    Sources sources = ProjectUtils.getSources(project); // returns singleton
    if (sourcesListener == null) {
        sourcesListener = WeakListeners.change(this, sources);
        sources.addChangeListener(sourcesListener);
    }
    setGroups(Arrays.asList(sources.getSourceGroups(Sources.TYPE_GENERIC)));
}
 
Example 13
Source File: ProjectWebServiceNodeFactory.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void addNotify() {
    initView();
    weakL = WeakListeners.change(this, view);
    view.addChangeListener(weakL, ProjectWebServiceView.ViewType.SERVICE);
    view.addChangeListener(weakL, ProjectWebServiceView.ViewType.CLIENT);
    view.addNotify();
}
 
Example 14
Source File: FeatureProjectFactory.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public FeatureNonProject(
    FileObject dir, FeatureInfo info,
    ProjectState state, List<FeatureInfo> additional
) {
    this.delegate = new FeatureDelegate(dir, this);
    this.info = info;
    this.additional = additional.toArray(new FeatureInfo[0]);
    this.lookup = Lookups.proxy(delegate);
    this.state = state;
    this.weakL = WeakListeners.change(this, FeatureManager.getInstance());
    FeatureManager.getInstance().addChangeListener(weakL);
}
 
Example 15
Source File: SourcesNodeFactory.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private SourceChildrenList(PhpProject project) {
    this.project = project;
    projectSources = ProjectUtils.getSources(project);
    changeListener = WeakListeners.change(this, projectSources);
}
 
Example 16
Source File: FodDataObjectFactory.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private Cookies(FileObject fo, MultiFileLoader loader) throws DataObjectExistsException {
    super(fo, loader);
    this.fo = fo;
    this.weakL = WeakListeners.change(this, FeatureManager.getInstance());
    FeatureManager.getInstance().addChangeListener(weakL);
}
 
Example 17
Source File: ContextAction.java    From netbeans with Apache License 2.0 4 votes vote down vote up
void startListeners() {
    if (enabler != null) {
        weakEnableListener = WeakListeners.change(this, enabler);
        enabler.addChangeListener(weakEnableListener);
    }
}
 
Example 18
Source File: PropertyMonitor.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void addListeners(Object data) {
    if (weakListener != null || listenerType == NONE) {
        return;
    }
    initListenerReflection();
    synchronized (this) {
        if (listeners == null) {
            return;
        }
    }
    PropertyChangeListener pcl;
    ChangeListener chl;
    LOG.log(Level.FINER, "{0}: adding listener to {1}", new Object[] { this, data });
    try {
        switch (listenerType) {
            case PROPERTY_NAME:
                weakListener = pcl = WeakListeners.propertyChange(this, property, data);
                refAddListener.invoke(data, property, pcl);
                break;
            case PROPERTY_ALL:
                weakListener = pcl = WeakListeners.propertyChange(this, data);
                refAddListener.invoke(data, pcl);
                break;
            case CHANGE:
                weakListener = chl = WeakListeners.change(this, data);
                refAddListener.invoke(data, chl);
                break;
            case NONE:
                return;
            case CUSTOM: {
                ProxyListener pl = new ProxyListener(data, methodName, refRemoveListener, this);
                Object o = Proxy.newProxyInstance(listenerInterface.getClassLoader(), new Class[] { listenerInterface, EventListener.class }, pl);
                pl.proxy = weakListener = (EventListener)o;
                refAddListener.invoke(data, weakListener);
                break;
            }
                
            default:
                throw new IllegalStateException();
        }
    } catch (ReflectiveOperationException | IllegalArgumentException ex) {
        listenerType = NONE;
    }

    if (actionMonitor != null) {
        actionMonitor.addChangeListener(this);
    }
}
 
Example 19
Source File: MMKnowledgeSources.java    From netbeans-mmd-plugin with Apache License 2.0 4 votes vote down vote up
public MMKnowledgeSources(final Project project) {
  this.project = project;
  this.projectSources = ProjectUtils.getSources(project);
  this.changeListener = WeakListeners.change(this, this.projectSources);
}
 
Example 20
Source File: RunScriptAction.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private RunScriptAction(Lookup context, JTextComponent editor, FileObject scriptOrFolder, 
        String name, String description) {
    this();
    this.context = context;
    this.editor = editor;
    this.storage = PersistentSnippetsSupport.create(context);
    this.scriptFile = scriptOrFolder;
    putValue(NAME, name);
    if (scriptFile == null) {
        putValue(SHORT_DESCRIPTION, Bundle.DESC_RunSavedScript());
        putValue(SMALL_ICON, ImageUtilities.loadImageIcon(RESOURCE_ICON, false));
    } else {
        putValue(SHORT_DESCRIPTION, description);
    }
    
    if (storage == null) {
        setEnabled(false);
        return;
    }
    
    boolean enabled = true;
    
    
    if (scriptOrFolder == null || scriptOrFolder.isFolder()) {
        if (scriptOrFolder == null) {
            popup = new JPopupMenu() {
                @Override
                public int getComponentCount() {
                    refresh();
                    return super.getComponentCount();
                }
            };
        } else {
            subMenu = new JMenu() {
                @Override
                public int getMenuComponentCount() {
                    refresh();
                    return super.getMenuComponentCount();
                }
            };
            subMenu.setText(name);
            subMenu.setToolTipText(description);
        }
        if (storage.getSavedClasses(null).isEmpty()) {
            setEnabled(false);
        }
        invalidate();
        if (scriptOrFolder != null) {
            FileChangeListener fcl = WeakListeners.create(FileChangeListener.class, listen, scriptOrFolder);
            scriptOrFolder.addFileChangeListener(fcl);
            weakListen = fcl;
        } else {
            ChangeListener cl = WeakListeners.change(listen, storage);
            storage.addChangeListener(cl);
            weakListen = cl;
        }
    }
}