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

The following examples show how to use org.openide.util.WeakListeners#propertyChange() . 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: FileMoveBreakpointsHandler.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void stateChanged(ChangeEvent e) {
    Object source = e.getSource();
    if (source instanceof Collection) {
        FileObject bfo = this.fo;
        if (bfo == null) {
            return ;
        }
        for (Object obj : ((Collection) source)) {
            DataObject dobj = (DataObject) obj;
            FileObject primary = dobj.getPrimaryFile();
            if (bfo.equals(primary)) {
                synchronized (this) {
                    dobjRef = new WeakReference<DataObject>(dobj);
                    dobjwl = WeakListeners.propertyChange(this, dobj);
                    dobj.addPropertyChangeListener(dobjwl);
                    if (registryListener != null) {
                        DataObject.getRegistry().removeChangeListener(registryListener);
                        registryListener = null;
                    }
                }
                break;
            }
        }
    }
}
 
Example 2
Source File: SchemaRootChildren.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Set a new source element to get information about children from.
* @param element the new element, or <code>null</code> to detach
*/
public void setElement (final SchemaElement element) {
    if (this.element != null)
        this.element.removePropertyChangeListener(wPropL);

    this.element = element;
    if (this.element != null) {
        if (wPropL == null) {
            propL = new DBElementListener();
            wPropL = WeakListeners.propertyChange(propL, this.element);
        }
        else {
            // #55249 - need to recreate the listener with the right element
            wPropL = WeakListeners.propertyChange(propL, this.element);
        }
        
        this.element.addPropertyChangeListener(wPropL);
    }
    
    // change element nodes according to the new element
    if (nodesInited)
        refreshKeys ();
}
 
Example 3
Source File: AnnotationViewDataImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void addListenersToMarkProviders() {
    for (MarkProvider provider : markProviders) {
        PropertyChangeListener weakL = WeakListeners.propertyChange(this, provider);
        provider.addPropertyChangeListener(weakL);
        statusProvidersWeakLs.add(weakL);
    }
}
 
Example 4
Source File: GeneralAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Constructs new action that is bound to given context and
 * listens for changes of <code>ActionMap</code> in order to delegate
 * to right action.
 */
protected BaseDelAction(Map map, Object key, Lookup actionContext, Action fallback, boolean surviveFocusChange, boolean async) {
    this.map = map;
    this.key = key;
    this.fallback = fallback;
    this.global = GlobalManager.findManager(actionContext, surviveFocusChange);
    this.weakL = WeakListeners.propertyChange(this, fallback);
    this.async = async;
    if (fallback != null) {
        LOG.log(Level.FINER, "Action {0}: Attaching propchange to {1}", new Object[] {
            this, fallback
        });
        fallback.addPropertyChangeListener(weakL);
    }
}
 
Example 5
Source File: CodeCompletionOptionsPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void setSelector(CodeCompletionOptionsSelector selector) {
    if (this.selector != null) {
        this.selector.removePropertyChangeListener(weakListener);
    }

    this.selector = selector;

    if (this.selector != null) {
        this.weakListener = WeakListeners.propertyChange(this, this.selector);
        this.selector.addPropertyChangeListener(weakListener);

        // Languages combobox model
        DefaultComboBoxModel model = new DefaultComboBoxModel();
        ArrayList<String> mimeTypes = new ArrayList<String>();
        mimeTypes.addAll(selector.getMimeTypes());
        Collections.sort(mimeTypes, new LanguagesComparator());

        for (String mimeType : mimeTypes) {
            model.addElement(mimeType);
        }
        cbLanguage.setModel(model);
        if (lastSelectedItem != null) {
            cbLanguage.setSelectedItem(lastSelectedItem);
        } else {
            cbLanguage.setSelectedIndex(0);
        }
    } else {
        if (cbLanguage.getSelectedItem() != null) {
            lastSelectedItem = cbLanguage.getSelectedItem();
        }
        cbLanguage.setModel(new DefaultComboBoxModel());
    }
}
 
Example 6
Source File: CloneableTopComponent.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Default constructor for creating empty reference.
*/
protected Ref() {
    // Fix for IZ#124647 - method selection in navigator focuses to wrong window
    myComponentSetListener = new PropertyChangeListener(){

        public void propertyChange( PropertyChangeEvent evt ) {
            Object activated = evt.getNewValue();
            Object deactivated = evt.getOldValue();
            boolean activatedInSet = false;
            synchronized (LOCK) {
                activatedInSet = componentSet.contains( activated )
                && componentSet.contains( deactivated );
            }
            if ( activatedInSet ){
                ((CloneableTopComponent)activated).setLastActivated();
                ((CloneableTopComponent)deactivated).unsetLastActivated();
            }
            
        }
        
    };
    PropertyChangeListener listener = WeakListeners.propertyChange( 
                myComponentSetListener , 
                WindowManager.getDefault().getRegistry());
    WindowManager.getDefault().getRegistry().addPropertyChangeListener( 
            listener );
}
 
Example 7
Source File: J2eePlatformNode.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private synchronized J2eePlatform getPlatform () {
    if (platformCache == null) {
        String j2eePlatformInstanceId = this.evaluator.getProperty(this.platformPropName);
        if (j2eePlatformInstanceId != null) {
            platformCache = Deployment.getDefault().getJ2eePlatform(j2eePlatformInstanceId);
        }
        if (platformCache != null) {
            weakPlatformListener = WeakListeners.propertyChange(platformListener, platformCache);
            platformCache.addPropertyChangeListener(weakPlatformListener);
            // the platform has likely changed, so force the node to display the new platform's icon
            this.fireIconChange();
        }
    }
    return platformCache;
}
 
Example 8
Source File: SaveAsAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private PropertyChangeListener createRegistryListener() {
    return WeakListeners.propertyChange( new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent evt) {
                isDirty = true;
            }
        }, TopComponent.getRegistry() );
}
 
Example 9
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 10
Source File: AbstractProjectSearchScope.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected AbstractProjectSearchScope(String interestingProperty) {
    super();
    this.interestingProperty = interestingProperty;
    OpenProjects openProjects = OpenProjects.getDefault();
    openProjectsWeakListener = WeakListeners.propertyChange(this,
            openProjects);
    openProjects.addPropertyChangeListener(openProjectsWeakListener);
}
 
Example 11
Source File: DefaultDataLoadersBridge.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * @param fo The file object to listen upon at DataObject level
 * @param fcl The FileChangeListener to be called when the DataObject has been invalidated
 * 
 * @throws org.openide.loaders.DataObjectNotFoundException
 */
public DataObjectListener(FileObject fo, FileChangeListener fcl) throws DataObjectNotFoundException {
    this.fobj = fo;
    this.flisten = fcl;
    this.dobj = DataObject.find(fo);
    wlistener = WeakListeners.propertyChange(this, dobj);
    this.dobj.addPropertyChangeListener(wlistener);
}
 
Example 12
Source File: TableChildren.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected void addNotify () {
    refreshAllKeys ();
    // listen to the changes in the class element
    if (wPropL == null) {
        propL = new DBElementListener();
        wPropL = WeakListeners.propertyChange (propL, element);
    }  
    
    element.addPropertyChangeListener (wPropL);
    nodesInited = true;
}
 
Example 13
Source File: DiffResultsView.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public DiffResultsView(SearchHistoryPanel parent, List<RepositoryRevision> results) {
    this.parent = parent;
    this.results = results;
    treeView = new DiffTreeTable(parent);
    treeView.setResults(results);
    treeView.addAncestorListener(this);

    diffView = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    diffView.setTopComponent(treeView);
    setBottomComponent(new NoContentPanel(NbBundle.getMessage(DiffResultsView.class, "MSG_DiffPanel_NoRevisions"))); // NOI18N
    list = WeakListeners.propertyChange(this, null);
}
 
Example 14
Source File: MultiModuleFileBuiltQueryImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@NonNull
private FileBuiltQueryImplementation getDelegate() {
    FileBuiltQueryImplementation res;
    synchronized (this) {
         res = delegate;
    }
    if (res == null) {
        final List<String> from = new ArrayList<>();
        final List<String> to = new ArrayList<>();
        final Set<ClassPath> classpaths = Collections.newSetFromMap(new IdentityHashMap<>());
        collectRoots(sourceModules, ProjectProperties.BUILD_MODULES_DIR, from, to, classpaths);
        collectRoots(testModules, ProjectProperties.BUILD_TEST_MODULES_DIR, from, to, classpaths);
        res = helper.createGlobFileBuiltQuery(
                eval,
                from.toArray(new String[from.size()]),
                to.toArray(new String[to.size()]));
        synchronized (this) {
            if (delegate == null) {
                for (Pair<ClassPath,PropertyChangeListener> cplp : currentPaths) {
                    cplp.first().removePropertyChangeListener(cplp.second());
                }
                currentPaths.clear();
                for (ClassPath scp : classpaths) {
                    final PropertyChangeListener l = WeakListeners.propertyChange(this, scp);
                    scp.addPropertyChangeListener(l);
                    currentPaths.add(Pair.of(scp, l));
                }
                delegate = res;
            } else {
                res = delegate;
            }
        }
    }
    return res;
}
 
Example 15
Source File: JSLineBreakpoint.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void setLineHandler(EditorLineHandler line) {
    dispose();
    EditorLineHandler oldLine = this.line;
    this.line = line;
    lineChangesWeak = WeakListeners.propertyChange(lineChangeslistener, line);
    line.addPropertyChangeListener(lineChangesWeak);
    FileObject fileObject = line.getFileObject();
    if (fileObject != null) {
        myWeakListener = WeakListeners.create(
                FileChangeListener.class, myListener, fileObject);
        fileObject.addFileChangeListener(myWeakListener);
    }
    firePropertyChange(PROP_FILE, oldLine.getFileObject(), line.getFileObject());
    firePropertyChange(PROP_LINE_NUMBER, oldLine.getLineNumber(), line.getLineNumber());
}
 
Example 16
Source File: BreakpointsTreeModel.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** 
 *
 * @return groups and breakpoints contained in this group of breakpoints
 */
public Object[] getChildren (Object parent, int from, int to)
throws UnknownTypeException {
    if (parent == ROOT) {
        if (listener == null) {
            listener = new Listener (this);
        }
        if (pchl == null) {
            pchl = new PropertyChangeListener() {
                public void propertyChange(PropertyChangeEvent evt) {
                    fireTreeChanged();
                }
            };
            bpProperties.addPropertyChangeListener(WeakListeners.propertyChange(pchl, bpProperties));
        }
        boolean openProjectsOnly = bpProperties.getBoolean(BreakpointGroup.PROP_FROM_OPEN_PROJECTS, true);
        if (openProjectsOnly) {
            oppchl = WeakListeners.propertyChange(pchl, OpenProjects.getDefault());
            OpenProjects.getDefault().addPropertyChangeListener(oppchl);
        } else {
            if (oppchl != null) {
                OpenProjects.getDefault().removePropertyChangeListener(oppchl);
            }
            oppchl = null;
        }
        Object[] groupsAndBreakpoints;
        synchronized (lastGroupsAndBreakpointsLock) {
            groupsAndBreakpoints = lastGroupsAndBreakpoints.get();
        }
        if (groupsAndBreakpoints == null) {
            Set<Breakpoint> cpb = new IdentityHashSet<>();
            groupsAndBreakpoints = BreakpointGroup.createGroups(bpProperties, cpb);
            synchronized (lastGroupsAndBreakpointsLock) {
                lastGroupsAndBreakpoints = new SoftReference<Object[]>(groupsAndBreakpoints);
                closedProjectsBreakpoints.clear();
                closedProjectsBreakpoints.addAll(cpb);
            }
        }
        if (to == 0 || to >= groupsAndBreakpoints.length && from == 0) {
            return groupsAndBreakpoints;
        } else {
            int n = groupsAndBreakpoints.length;
            to = Math.min(n, to);
            from = Math.min(n, from);
            Object[] r = new Object[to - from];
            System.arraycopy(groupsAndBreakpoints, from, r, 0, r.length);
            return r;
        }
    } else if (parent instanceof BreakpointGroup) {
        return ((BreakpointGroup) parent).getGroupsAndBreakpoints();
    } else
    throw new UnknownTypeException (parent);
}
 
Example 17
Source File: KeyNode.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** Constructor.
 * @param propStructure structure of .properties file to work with
 * @param itemKey key value of item in properties structure
 */
public KeyNode (PropertiesStructure propStructure, String itemKey) {
    super(Children.LEAF);
    
    this.propStructure = propStructure;
    this.itemKey = itemKey;
    
    super.setName(itemKey);
    
    setActions(
        new SystemAction[] {
            SystemAction.get(EditAction.class),
            SystemAction.get(OpenAction.class),
            SystemAction.get(FileSystemAction.class),
            null,
            SystemAction.get(CutAction.class),
            SystemAction.get(CopyAction.class),
            null,
            SystemAction.get(DeleteAction.class),
            SystemAction.get(RenameAction.class),
            null,
            SystemAction.get(ToolsAction.class),
            SystemAction.get(PropertiesAction.class)
        }
    );
    
    setIconBaseWithExtension("org/netbeans/modules/properties/propertiesKey.gif"); // NOI18N

    // Sets short description.
    updateShortDescription();

    // Sets cookies (Open and Edit).
    PropertiesDataObject pdo = ((PropertiesDataObject)propStructure.getParent().getEntry().getDataObject());

    getCookieSet().add(pdo.getOpenSupport().new PropertiesOpenAt(propStructure.getParent().getEntry(), itemKey));
    getCookieSet().add(propStructure.getParent().getEntry().getPropertiesEditor().new PropertiesEditAt(itemKey));

    Element.ItemElem item = getItem();
    PropertyChangeListener pcl = WeakListeners.propertyChange(this, item);
    item.addPropertyChangeListener(pcl);
}
 
Example 18
Source File: FormattingPanel.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void setSelector(CustomizerSelector selector) {
    if (selector == null) {
        storedMimeType = (String)languageCombo.getSelectedItem();
        Object o = categoryCombo.getSelectedItem();
        if (o instanceof PreferencesCustomizer) {
            storedCategory = ((PreferencesCustomizer)o).getId();
        }
    }
    
    if (this.selector != null) {
        this.selector.removePropertyChangeListener(weakListener);
    }

    this.selector = selector;

    if (this.selector != null) {
        // Languages combobox model
        DefaultComboBoxModel<String> model = new DefaultComboBoxModel<>();
        ArrayList<String> mimeTypes = new ArrayList<String>();
        mimeTypes.addAll(selector.getMimeTypes());
        Collections.sort(mimeTypes, new LanguagesComparator());

        String preSelectMimeType = null;
        for (String mimeType : mimeTypes) {
            model.addElement(mimeType);
            if (mimeType.equals(storedMimeType)) {
                preSelectMimeType = mimeType;
            }
        }
        languageCombo.setModel(model);

        // Pre-select a language
        if (preSelectMimeType == null) {
            JTextComponent pane = EditorRegistry.lastFocusedComponent();
            preSelectMimeType = pane != null ? (String)pane.getDocument().getProperty("mimeType") : ""; // NOI18N
        }
        languageCombo.setSelectedItem(preSelectMimeType);
        if (!preSelectMimeType.equals(languageCombo.getSelectedItem())) {
            languageCombo.setSelectedIndex(0);
        }

        this.weakListener = WeakListeners.propertyChange(this, this.selector);
        this.selector.addPropertyChangeListener(weakListener);
        this.propertyChange(new PropertyChangeEvent(this.selector, CustomizerSelector.PROP_MIMETYPE, null, null));
    } else {
        languageCombo.setModel(new DefaultComboBoxModel());
    }
}
 
Example 19
Source File: SaveAsAction.java    From constellation with Apache License 2.0 4 votes vote down vote up
private PropertyChangeListener createRegistryListener() {
    return WeakListeners.propertyChange(evt -> isDirty = true, TopComponent.getRegistry());
}
 
Example 20
Source File: DocumentUtilities.java    From netbeans with Apache License 2.0 3 votes vote down vote up
/**
 * Adds a weak <code>PropertyChangeListener</code> to a document.
 *
 * <p>In general, document properties are key-value pairs where both the key
 * and the value can be any <code>Object</code>. Contrary to that <code>PropertyChangeListener</code>s
 * can only handle named properties that can have an arbitrary value, but have <code>String</code> names.
 * Therefore the listenera attached to a document will only ever recieve document
 * properties, which keys are of <code>java.lang.String</code> type.
 *
 * <p>Additionally, the list of document properties that clients can listen on
 * is not part of this contract.
 *
 * @param doc The document to add the listener to.
 * @param listenerImplementation The listener to be added weakly to the document.
 * @return the created weak listener - only the returned listener can be
 * used with {@link #removePropertyChangeListener}. If the document does not
 * support {@code PropertyChangeLister} {@code null} is returned.
 *
 * @since 1.68
 */
public static PropertyChangeListener addWeakPropertyChangeListener(Document doc, PropertyChangeListener listenerImplementation) {
    PropertyChangeSupport pcs = (PropertyChangeSupport) doc.getProperty(PropertyChangeSupport.class);
    PropertyChangeListener weakListener = null;
    if (pcs != null) {
        weakListener = WeakListeners.propertyChange(listenerImplementation, pcs);
        pcs.addPropertyChangeListener(weakListener);
    }
    return weakListener;
}