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

The following examples show how to use org.openide.util.WeakListeners#create() . 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: PortTypeOperationFaultPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Creates new form PortTypeOperationFaultPanel
 */
public PortTypeOperationFaultPanel(SectionView view, Fault fault){
    super(view);
    this.fault = fault;
    this.model = this.fault.getModel();
    initComponents();
    disableEnterKey();
    
    sync();
    addModifier(javaClassText);
    addModifier(defaultJavaClassCB);
    addValidatee(javaClassText);
    
    defaultListener = new DefaultItemListener();
    ItemListener il = (ItemListener)WeakListeners.create(ItemListener.class, defaultListener,
            defaultJavaClassCB);
    defaultJavaClassCB.addItemListener(il);
}
 
Example 2
Source File: ProjectLibraryProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public Set<ProjectLibraryArea> getOpenAreas() {
    synchronized (this) { // lazy init of OpenProjects-related stuff is better for unit testing
        if (apl == null) {
            apl = WeakListeners.create(AntProjectListener.class, this, null);
            OpenProjects.getDefault().addPropertyChangeListener(WeakListeners.propertyChange(this, OpenProjects.getDefault()));
        }
    }
    Set<ProjectLibraryArea> areas = new HashSet<ProjectLibraryArea>();
    for (Project p : OpenProjects.getDefault().getOpenProjects()) {
        AntProjectHelper helper = AntBasedProjectFactorySingleton.getHelperFor(p);
        if (helper == null) {
            // Not an Ant-based project; ignore.
            continue;
        }
        helper.removeAntProjectListener(apl);
        helper.addAntProjectListener(apl);
        Definitions def = findDefinitions(helper);
        if (def != null) {
            areas.add(new ProjectLibraryArea(def.mainPropertiesFile));
        }
    }
    return areas;
}
 
Example 3
Source File: ServiceProvidersTablePanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new instance of ServiceProvidersTablePanel
 */
public ServiceProvidersTablePanel(ServiceProvidersTableModel tablemodel, STSConfiguration stsConfig, ConfigVersion cfgVersion) {
    super(tablemodel);
    this.stsConfig = stsConfig;
    this.tablemodel = tablemodel;
    this.cfgVersion = cfgVersion;
    
    this.editButton.setVisible(true);

    addedProviders = new HashMap<String, ServiceProviderElement>();
    
    editActionListener = new EditActionListener();
    ActionListener editListener = WeakListeners.create(ActionListener.class,
            editActionListener, editButton);
    editButton.addActionListener(editListener);

    addActionListener = new AddActionListener();
    ActionListener addListener = WeakListeners.create(ActionListener.class,
            addActionListener, addButton);
    addButton.addActionListener(addListener);
    
    removeActionListener = new RemoveActionListener();
    ActionListener removeListener = WeakListeners.create(ActionListener.class,
            removeActionListener, removeButton);
    removeButton.addActionListener(removeListener);
}
 
Example 4
Source File: BindingPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Creates new form BindingPanel */
public BindingPanel(SectionView view, Binding binding, Definitions primaryDefinitions){
    super(view);
    this.binding = binding;
    this.primaryDefinitions = primaryDefinitions;
    this.model = this.binding.getModel();
    initComponents();
    
    sync();
    
    modelListener = new ModelChangeListener();
    WSDLModel primaryModel = primaryDefinitions.getModel();
    PropertyChangeListener pcl = WeakListeners.propertyChange(modelListener, primaryModel);
    primaryModel.addPropertyChangeListener(pcl);
    
    actionListener = new BindingActionListener();
    ActionListener al = (ActionListener)WeakListeners.create(ActionListener.class, actionListener,
            enableMIMEContentCB);
    enableMIMEContentCB.addActionListener(al);
}
 
Example 5
Source File: AXIComponent.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private PropertyChangeListener getWeakListener(AXIComponent proxy, boolean remove) {
    if(listenerMap == null) {
        listenerMap = new WeakHashMap<AXIComponent, PropertyChangeListener>();
    }
    if(remove)
        return listenerMap.remove(proxy);
    
    if(proxy.getComponentType() != ComponentType.PROXY) {
        Set<AXIComponent> keySet = listenerMap.keySet();
        for(AXIComponent key : keySet) {
            if(key.getPeer() == proxy.getPeer())
                return null;
        }
    }
    
    PropertyChangeListener listener = listenerMap.get(proxy);
    if(listener == null) {
        listener = (PropertyChangeListener)WeakListeners.
                create(PropertyChangeListener.class, proxy, this);
        listenerMap.put(proxy, listener);
        return listener;
    }
    
    //if exists, return null.
    return null;
}
 
Example 6
Source File: AnnotationViewDataImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void register(BaseDocument document) {
    this.document = document;
    
    JTextComponent pane = paneRef.get();
    if (pane != null) {
        gatherProviders(pane);
    }
    
    if (document != null) {
        if (weakL == null) {
            weakL = WeakListeners.create(Annotations.AnnotationsListener.class, this, document.getAnnotations());
            document.getAnnotations().addAnnotationsListener(weakL);
        }
    }
    
    clear();
}
 
Example 7
Source File: AbbrevDetection.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void propertyChange(PropertyChangeEvent evt) {
    if ("document".equals(evt.getPropertyName())) { //NOI18N
        if (doc != null && weakDocL != null) {
            doc.removeDocumentListener(weakDocL);
            weakDocL = null;
        }
        
        doc = component.getDocument();
        if (doc != null) {
            listenOnDoc();
        }

        // unregister and destroy the old preferences (if we have any)
        if (prefs != null) {
            prefs.removePreferenceChangeListener(weakPrefsListener);
            prefs = null;
            weakPrefsListener = null;
            mimePath = null;
        }
        
        // load and hook up to preferences for the new mime type
        String mimeType = DocumentUtilities.getMimeType(component);
        if (mimeType != null) {
            mimePath = MimePath.parse(mimeType);
            prefs = MimeLookup.getLookup(mimePath).lookup(Preferences.class);
            weakPrefsListener = WeakListeners.create(PreferenceChangeListener.class, this, prefs);
            prefs.addPreferenceChangeListener(weakPrefsListener);
        }
        
        // reload the settings
        preferenceChange(null);
    }
}
 
Example 8
Source File: SaveableSectionInnerPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected void disableEnterKey() {
    Component[] components = this.getComponents();
    listener = new EnterKeyListener();
    for (int i = 0; i < components.length; i++) {
        Component component = components[i];
        if (component.isFocusable() && !(component instanceof JLabel)) {
            KeyListener kl = (KeyListener) WeakListeners.create(KeyListener.class, listener,
                    component);
            component.addKeyListener(kl);
        }
    }
}
 
Example 9
Source File: PortPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Creates new form PortPanel */
public PortPanel(SectionView view, Port port,
        Node node) {
    super(view);
    this.port = port;
    this.model = this.port.getModel();
    this.node = node;
    initComponents();
    disableEnterKey();
    sync();
    
    defaultListener = new DefaultItemListener();
    ItemListener itemListener = WeakListeners.create(ItemListener.class, defaultListener,
            defaultMethodCB);
    defaultMethodCB.addItemListener(itemListener);
    
    if(!isClient(node)){
        providerActionListener = new ProviderActionListener();
        ActionListener providerListener = WeakListeners.create(ActionListener.class,
                providerActionListener, providerCB);
        providerCB.addActionListener(providerListener);
    } else{
        providerCB.setVisible(false);
    }
    
    addModifier(portAccessMethodText);
    addModifier(defaultMethodCB);
    addValidatee(portAccessMethodText);
}
 
Example 10
Source File: PortTypePanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Creates new form PortTypePanel */
public PortTypePanel(SectionView view, PortType portType,
        Node node, Definitions primaryDefinitions) {
    super(view);
    this.portType = portType;
    this.primaryDefinitions = primaryDefinitions;
    this.model = this.portType.getModel();
    initComponents();
    disableEnterKey();
    if(!isClient(node)){
        enableAsyncMappingCB.setVisible(false);
    }
    enableAsyncMappingCB.setToolTipText(NbBundle.getMessage(DefinitionsPanel.class, "TOOLTIP_ENABLE_ASYNC"));
    enableWrapperStyleCB.setToolTipText(NbBundle.getMessage(DefinitionsPanel.class, "TOOLTIP_ENABLE_WRAPPER"));
    javaClassText.setToolTipText(NbBundle.getMessage(PortTypePanel.class, "TOOLTIP_PORTTYPE_CLASS"));
    
    syncButtons();
    syncJavaClass();
    
    defaultItemListener = new DefaultItemListener();
    ItemListener il = (ItemListener)WeakListeners.create(ItemListener.class, defaultItemListener, defaultJavaClassCB);
    defaultJavaClassCB.addItemListener(il);
    
    modelListener = new ModelChangeListener();
    WSDLModel primaryModel = primaryDefinitions.getModel();
    PropertyChangeListener pcl = WeakListeners.propertyChange(modelListener, primaryModel);
    primaryModel.addPropertyChangeListener(pcl);
    
    listener = new PortTypeActionListener();
    ActionListener eamListener = (ActionListener)WeakListeners.create(ActionListener.class,
            listener, enableAsyncMappingCB);
    enableAsyncMappingCB.addActionListener(eamListener);
    ActionListener ewsListener = (ActionListener)WeakListeners.create(ActionListener.class,
            listener, enableWrapperStyleCB);
    enableWrapperStyleCB.addActionListener(ewsListener);
    
    addModifier(javaClassText);
    addModifier(defaultJavaClassCB);
    addValidatee(javaClassText);
}
 
Example 11
Source File: BaseDocument.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void setMimeType(String mimeType) {
        if (!this.mimeType.equals(mimeType)) {
//            String oldMimeType = this.mimeType;
            this.mimeType = mimeType;

//            new Throwable("~~~ setMimeType: '" + oldMimeType + "' -> '" + mimeType + "'").printStackTrace(System.out);
//
            if (prefs != null && weakPrefsListener != null) {
                try {
                    prefs.removePreferenceChangeListener(weakPrefsListener);
//                    System.out.println("~~~ setMimeType: " + s2s(prefs) + " removing " + s2s(weakPrefsListener));
                } catch (IllegalArgumentException e) {
//                    System.out.println("~~~ IAE: doc=" + s2s(this) + ", '" + oldMimeType + "' -> '" + this.mimeType + "', prefs=" + s2s(prefs) + ", wpl=" + s2s(weakPrefsListener));
                }
                weakPrefsListener = null;
            }
            prefs = MimeLookup.getLookup(this.mimeType).lookup(Preferences.class);
            prefsListener.preferenceChange(null);
//            System.out.println("~~~ setMimeType: '" + this.mimeType + "' -> " + s2s(prefs));

            // reinitialize the document
            EditorKit kit = getEditorKit();
            if (kit instanceof BaseKit) {
                // careful here!! some kits set document's mime type from initDocument
                // even worse, the new mime type can be different from the one passed to the constructor,
                // which will result in recursive call to this method
                ((BaseKit) kit).initDocument(this);
            }

            if (weakPrefsListener == null) {
                weakPrefsListener = WeakListeners.create(PreferenceChangeListener.class, prefsListener, prefs);
                prefs.addPreferenceChangeListener(weakPrefsListener);
//                System.out.println("~~~ setMimeType: " + s2s(prefs) + " adding " + s2s(weakPrefsListener));
            }
        }
    }
 
Example 12
Source File: SaveAsAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private LookupListener createLookupListener() {
    return WeakListeners.create(LookupListener.class, new LookupListener() {
            public void resultChanged(LookupEvent ev) {
                isDirty = true;
            }
        }, lkpInfo);
}
 
Example 13
Source File: ProxyPreferences.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private ProxyPreferences(ProxyPreferences parent, MemoryPreferences memoryPref, Preferences delegate) {
    this.parent = parent;
    this.delegateRoot = memoryPref;
    this.delegate = delegate == null ? memoryPref.getPreferences() : delegate;
    weakPrefListener = WeakListeners.create(PreferenceChangeListener.class, this, delegate);
    this.delegate.addPreferenceChangeListener(weakPrefListener);
    weakNodeListener = WeakListeners.create(NodeChangeListener.class, this, delegate);
    this.delegate.addNodeChangeListener(weakNodeListener);
}
 
Example 14
Source File: ExplorerActionsImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void registerListener() {
    if (flavL == null) {
        Clipboard c = getClipboard();
        if (c != null) {
            flavL = WeakListeners.create(FlavorListener.class, this, c);
            c.addFlavorListener(flavL);
        }
    }
}
 
Example 15
Source File: WebServicesHintsProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void initServiceMetadata(TypeElement javaClass) {
    if (service == null) {
        Project owner = FileOwnerQuery.getOwner(file);
        if(owner!=null) {
            JaxWsModel jaxwsModel = owner.getLookup().lookup(JaxWsModel.class);
            if (jaxwsModel != null) {
                service = jaxwsModel.findServiceByImplementationClass(javaClass.getQualifiedName().toString());
            }
        }
    }
    if (service != null && service.getLocalWsdlFile()!=null) {
        JAXWSSupport jaxwsSupport = JAXWSSupport.getJAXWSSupport(file);
        if(jaxwsSupport!=null) {
            FileObject wsdlFolder = jaxwsSupport.getLocalWsdlFolderForService(service.getName(), false);
            if(wsdlFolder!=null) {
                FileObject wsdlFo = wsdlFolder.getFileObject(service.getLocalWsdlFile());
                if ( wsdlFo == null ){
                    return;
                }
                WSDLModel tmpModel = WSDLModelFactory.getDefault().getModel(
                        Utilities.getModelSource(wsdlFo, true));
                if(tmpModel!=wsdlModel) {
                    if(wsdlModel!=null) {
                        if(changeListener!=null) {
                            wsdlModel.removeComponentListener(changeListener);
                            changeListener = null;
                        }
                    }
                    wsdlModel = tmpModel;
                    if(wsdlModel!=null) {
                        if(changeListener==null) 
                            changeListener = WeakListeners.create(ComponentListener.class,
                                    new WsdlModelListener(file), wsdlModel);
                        wsdlModel.addComponentListener(changeListener);
                    }
                }
            }
        }
    }
}
 
Example 16
Source File: FoldViewFactory.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example 17
Source File: ConnectionAction.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
public DatabaseConnectionModel() {
    listener = WeakListeners.create (ConnectionListener.class, this, ConnectionManager.getDefault());
    ConnectionManager.getDefault().addConnectionListener(listener);
    RP.post(connectionUpdate);
}
 
Example 18
Source File: BaseCaret.java    From netbeans with Apache License 2.0 4 votes vote down vote up
protected void modelChanged(BaseDocument oldDoc, BaseDocument newDoc) {
    if (oldDoc != null) {
        // ideally the oldDoc param shouldn't exist and only listenDoc should be used
        assert (oldDoc == listenDoc);

        DocumentUtilities.removeDocumentListener(
                oldDoc, this, DocumentListenerPriority.CARET_UPDATE);
        oldDoc.removeAtomicLockListener(this);

        caretPos = null;
        markPos = null;

        listenDoc = null;
        if (prefs != null && weakPrefsListener != null) {
            prefs.removePreferenceChangeListener(weakPrefsListener);
        }
    }


    if (newDoc != null) {

        DocumentUtilities.addDocumentListener(
                newDoc, this, DocumentListenerPriority.CARET_UPDATE);
        listenDoc = newDoc;
        newDoc.addAtomicLockListener(this);

        // Leave caretPos and markPos null => offset==0
        prefs = MimeLookup.getLookup(DocumentUtilities.getMimeType(newDoc)).lookup(Preferences.class);
        if (prefs != null) {
            weakPrefsListener = WeakListeners.create(PreferenceChangeListener.class, prefsListener, prefs);
            prefs.addPreferenceChangeListener(weakPrefsListener);
        }
        
        Utilities.runInEventDispatchThread(
            new Runnable() {
                public @Override void run() {
                    updateType();
                }
            }
        );
    }
}
 
Example 19
Source File: HighlightingManager.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private synchronized void rebuildAll() {
    // Get the new set of mime path
    MimePath [] mimePaths = getAllDocumentMimePath();

    Document lastKnownDocument = lastKnownDocumentRef == null ? null : lastKnownDocumentRef.get();

    // Recalculate factories and all containers if needed
    if (!Utilities.compareObjects(lastKnownDocument, pane.getDocument()) ||
        !Arrays.equals(lastKnownMimePaths, mimePaths)
    ) {
        if (LOG.isLoggable(Level.FINE)) {
            LOG.fine("rebuildAll: lastKnownDocument = " + simpleToString(lastKnownDocument) + //NOI18N
                    ", document = " + simpleToString(pane.getDocument()) + //NOI18N
                    ", lastKnownMimePaths = " + mimePathsToString(lastKnownMimePaths) + //NOI18N
                    ", mimePaths = " + mimePathsToString(mimePaths) + "\n"); //NOI18N
        }
        
        // Unregister listeners
        if (factories != null && weakFactoriesTracker != null) {
            factories.removeLookupListener(weakFactoriesTracker);
            weakFactoriesTracker = null;
        }
        if (settings != null && weakSettingsTracker != null) {
            settings.removeLookupListener(weakSettingsTracker);
            weakSettingsTracker = null;
        }

        if (mimePaths != null) {
            ArrayList<Lookup> lookups = new ArrayList<Lookup>();
            for(MimePath mimePath : mimePaths) {
                lookups.add(MimeLookup.getLookup(mimePath));
            }

            ProxyLookup lookup = new ProxyLookup(lookups.toArray(new Lookup[lookups.size()]));
            factories = lookup.lookup(new Lookup.Template<HighlightsLayerFactory>(HighlightsLayerFactory.class));
            settings = lookup.lookup(new Lookup.Template<FontColorSettings>(FontColorSettings.class));
        } else {
            factories = null;
            settings = null;
        }
        
        // Start listening again
        if (factories != null) {
            weakFactoriesTracker = WeakListeners.create(LookupListener.class, factoriesTracker, factories);
            factories.addLookupListener(weakFactoriesTracker);
            factories.allItems(); // otherwise we won't get any events at all
        }
        if (settings != null) {
            weakSettingsTracker = WeakListeners.create(LookupListener.class, settingsTracker, settings);
            settings.addLookupListener(weakSettingsTracker);
            settings.allItems(); // otherwise we won't get any events at all
        }

        lastKnownDocument = pane.getDocument();
        lastKnownMimePaths = mimePaths;
        
        rebuildAllLayers();
    }
}
 
Example 20
Source File: FileUtil.java    From netbeans with Apache License 2.0 2 votes vote down vote up
/** Creates a weak implementation of FileStatusListener.
 *
 * @param l the listener to delegate to
 * @param source the source that the listener should detach from when
 *     listener <CODE>l</CODE> is freed, can be <CODE>null</CODE>
 * @return a FileChangeListener delegating to <CODE>l</CODE>.
 * @since 4.10
 */
public static FileStatusListener weakFileStatusListener(FileStatusListener l, Object source) {
    return WeakListeners.create(FileStatusListener.class, l, source);
}