类org.openide.util.LookupListener源码实例Demo

下面列出了怎么用org.openide.util.LookupListener的API类实例代码及写法,或者点击链接到github查看源代码。

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);
}
 
源代码2 项目: netbeans   文件: JavaSourceTaskFactoryManager.java
/** 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();
}
 
源代码3 项目: netbeans   文件: Selenium2Support.java
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);
}
 
源代码4 项目: netbeans   文件: NodeRegistry.java
/**
 * 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)
    );
}
 
源代码5 项目: netbeans   文件: LookupSensitiveAction.java
/** 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;
    }
}
 
源代码6 项目: netbeans   文件: CodeFoldingSideBar.java
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);
}
 
源代码7 项目: netbeans   文件: ColoringMap.java
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));
}
 
源代码8 项目: netbeans   文件: SimpleProxyLookup.java
/** 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;
}
 
源代码9 项目: netbeans   文件: TaskGroupFactory.java
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++ );
            }
        }
    }
}
 
源代码10 项目: netbeans   文件: CodeFoldingSideBar.java
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);
}
 
源代码11 项目: NBANDROID-V2   文件: AndroidClassPathProvider.java
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);

}
 
源代码12 项目: netbeans   文件: NbEditorToolBar.java
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);
    }
 
源代码13 项目: constellation   文件: SaveAsAction.java
private LookupListener createLookupListener() {
    return WeakListeners.create(LookupListener.class, new LookupListener() {
        @Override
        public void resultChanged(final LookupEvent ev) {
            isDirty = true;
        }
    }, lkpInfo);
}
 
源代码14 项目: snap-desktop   文件: LinearTodBAction.java
public LinearTodBAction(Lookup lkp) {
    this.lkp = lkp;
    Lookup.Result<ProductNode> lkpContext = lkp.lookupResult(ProductNode.class);
    lkpContext.addLookupListener(WeakListeners.create(LookupListener.class, this, lkpContext));
    setEnableState();

    putValue(NAME, Bundle.CTL_LinearTodBAction_Text());
    putValue(SHORT_DESCRIPTION, Bundle.CTL_LinearTodBAction_Description());
}
 
源代码15 项目: netbeans   文件: ComponentInspectorOperator.java
/** Changes context to show form hierarchy in navigator and prevents
 * other context changes while code in given Runnable is being executed.
 * @param runnable runnable to be executed
 */
public void freezeNavigatorAndRun(Runnable runnable) {
    new FormDesignerOperator(null).makeComponentVisible();
    Object navigatorController;
    Lookup.Result<Node> curNodesRes;
    Lookup.Result<Node> curHintsRes;
    try {
        // remove LookupListeners in NavigatorController
        Class navigatorTCClass = Class.forName("org.netbeans.modules.navigator.NavigatorTC", true, Thread.currentThread().getContextClassLoader());
        Method getControllerMethod = navigatorTCClass.getMethod("getController");
        navigatorController = getControllerMethod.invoke(getSource());
        Field curNodesResField = navigatorController.getClass().getDeclaredField("curNodesRes");
        curNodesResField.setAccessible(true);
        curNodesRes = (Lookup.Result<Node>) curNodesResField.get(navigatorController);
        curNodesRes.removeLookupListener((LookupListener) navigatorController);
        Field curHintsResField = navigatorController.getClass().getDeclaredField("curHintsRes");
        curHintsResField.setAccessible(true);
        curHintsRes = (Lookup.Result<Node>) curHintsResField.get(navigatorController);
        curHintsRes.removeLookupListener((LookupListener) navigatorController);
        // let pending postponed events proceed
        new EventTool().waitNoEvent(500);
    } catch (Exception e) {
        throw new JemmyException("Failed when freezing navigator.", e);
    }
    // run our code
    runnable.run();
    // add listeners back
    curNodesRes.addLookupListener((LookupListener) navigatorController);
    curHintsRes.addLookupListener((LookupListener) navigatorController);
}
 
源代码16 项目: netbeans   文件: RemoveSurroundingCodeAction.java
public RemoveSurroundingCodeAction(){
    // retrieve colors from fonts color settings
    Lookup lookup = MimeLookup.getLookup(JavaKit.JAVA_MIME_TYPE);
    result = lookup.lookupResult(FontColorSettings.class);
    result.addLookupListener(WeakListeners.create(LookupListener.class, this, result));
    resultChanged(null); // initial retrieval
}
 
public CopyPixelInfoToClipboardAction(Lookup lkp) {
    super(Bundle.CTL_CopyPixelInfoToClipboardAction_MenuText());
    putValue("popupText", Bundle.CTL_CopyPixelInfoToClipboardAction_PopupText());
    result = lkp.lookupResult(ProductSceneView.class);
    result.addLookupListener(WeakListeners.create(LookupListener.class, this, result));
    updateEnableState(getCurrentSceneView());
}
 
源代码18 项目: netbeans   文件: WhiteListCategoryPanelTest.java
public void testDeadlock203187() throws Exception {
    createWhiteListsFolder(Query1.class, Query2.class);
    final FileObject home = FileUtil.toFileObject(getWorkDir());
    final Project p = new MockProject(home);
    final Lookup lkp = WhiteListLookupProvider.getEnabledUserSelectableWhiteLists(p);
    assertNotNull(lkp);
    final Object lck = new Object();
    final CountDownLatch l1 = new CountDownLatch(1);
    final CountDownLatch l2 = new CountDownLatch(1);
    new Thread(new Runnable() {
        @Override
        public void run() {
            final Lookup.Result<? extends WhiteListQueryImplementation> res = lkp.lookupResult(WhiteListQueryImplementation.class);
            res.addLookupListener(new LookupListener() {
                @Override
                public void resultChanged(LookupEvent ev) {
                    l1.countDown();
                    try {
                        l2.await();
                    } catch (InterruptedException ex) {
                        Exceptions.printStackTrace(ex);
                    }
                    synchronized(lck) {
                        lkp.getClass();
                    }
                }
            });
            res.allInstances();
            WhiteListLookupProvider.enableWhiteListInProject(p, Query1.class.getSimpleName(), true);
        }
    }).start();
    synchronized (lck) {
        l1.await();
        l2.countDown();
        lkp.lookup(WhiteListQueryImplementation.class);
    }
}
 
源代码19 项目: netbeans   文件: CompilerOptionsQueryMerger.java
ResultImpl(
        @NonNull final FileObject artifact,
        @NonNull final Lookup lookup) {
    this.artifact = artifact;
    this.providers = lookup.lookupResult(CompilerOptionsQueryImplementation.class);
    this.listeners = new ChangeSupport(this);
    this.providers.addLookupListener(WeakListeners.create(LookupListener.class, this, providers));
    checkProviders();
}
 
源代码20 项目: snap-desktop   文件: ExportColorPaletteAction.java
public ExportColorPaletteAction(Lookup lookup) {
    super(Bundle.CTL_ExportColorPaletteAction_MenuText());
    putValue("popupText", Bundle.CTL_ExportColorPaletteAction_PopupText());
    result = lookup.lookupResult(ProductSceneView.class);
    result.addLookupListener(WeakListeners.create(LookupListener.class, this, result));
    setEnabled(false);
}
 
源代码21 项目: MikuMikuStudio   文件: VehicleEditorController.java
public VehicleEditorController(JmeSpatial jmeRootNode, BinaryModelDataObject currentFileObject) {
    this.jmeRootNode = jmeRootNode;
    this.currentFileObject = currentFileObject;
    rootNode = jmeRootNode.getLookup().lookup(Node.class);
    toolsNode = new Node("ToolsNode");
    toolController = new SceneToolController(toolsNode, currentFileObject.getLookup().lookup(ProjectAssetManager.class));
    toolController.setShowSelection(true);
    result = Utilities.actionsGlobalContext().lookupResult(JmeSpatial.class);
    result.addLookupListener(this);
    toolsNode.addLight(new DirectionalLight());
    Node track = (Node) new DesktopAssetManager(true).loadModel("Models/Racetrack/Raceway.j3o");
    track.getChild("Grass").getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(30, -1, 0));
    track.getChild("Grass").getControl(RigidBodyControl.class).setPhysicsRotation(new Quaternion().fromAngleAxis(FastMath.HALF_PI * 0.68f, Vector3f.UNIT_Y).toRotationMatrix());
    track.getChild("Road").getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(30, 0, 0));
    track.getChild("Road").getControl(RigidBodyControl.class).setPhysicsRotation(new Quaternion().fromAngleAxis(FastMath.HALF_PI * 0.68f, Vector3f.UNIT_Y).toRotationMatrix());
    toolsNode.attachChild(track);
    bulletState = new BulletAppState();

    result2 = Utilities.actionsGlobalContext().lookupResult(VehicleWheel.class);
    LookupListener listener = new LookupListener() {

        public void resultChanged(LookupEvent ev) {
            for (Iterator<? extends VehicleWheel> it = result2.allInstances().iterator(); it.hasNext();) {
                VehicleWheel wheel = it.next();
                toolController.updateSelection(wheel.getWheelSpatial());
            }
        }
    };
    result2.addLookupListener(listener);
}
 
源代码22 项目: netbeans   文件: HtmlPlugins.java
private HtmlPlugins() {
    Lookup lookup = MimeLookup.getLookup("text/html");
    lookupResult = lookup.lookupResult(HtmlLexerPlugin.class);
    lookupResult.addLookupListener(new LookupListener() {

        @Override
        public void resultChanged(LookupEvent ev) {
            refresh();
        }
    });
    
    refresh();
}
 
源代码23 项目: netbeans   文件: MetaInfServicesLookupTest.java
private void doTestSuperTypes(Lookup l) throws Exception {
    final Class<?> xface = c1.loadClass("org.foo.Interface");
    final Lookup.Result<Object> res = l.lookupResult(Object.class);
    assertEquals("Nothing yet", 0, res.allInstances().size());
    final AtomicBoolean event = new AtomicBoolean();
    final Thread here = Thread.currentThread();
    res.addLookupListener(new LookupListener() {
        public void resultChanged(LookupEvent ev) {
            if (Thread.currentThread() == here) {
                event.set(true);
            }
        }
    });
    assertNotNull("Interface found", l.lookup(xface));
    assertFalse(event.get());
    class W implements Runnable {
        boolean ok;
        public synchronized void run() {
            ok = true;
            notifyAll();
        }

        public synchronized void await() throws Exception {
            while (!ok) {
                wait();
            }
        }
    }
    W w = new W();
    MetaInfServicesLookup.getRP().execute(w);
    w.await();
    assertEquals("Now two", 2, res.allInstances().size());
}
 
源代码24 项目: netbeans   文件: CallbackSystemAction.java
public DelegateAction(CallbackSystemAction a, Lookup actionContext) {
    this.delegate = a;
    this.weakL = org.openide.util.WeakListeners.propertyChange(this, null);
    this.enabled = a.getActionPerformer() != null;

    this.result = actionContext.lookup(new Lookup.Template<ActionMap>(ActionMap.class));
    this.result.addLookupListener(WeakListeners.create(LookupListener.class, this, this.result));
    resultChanged(null);
}
 
源代码25 项目: netbeans   文件: DefaultEMLookup.java
public void addLookupListener(LookupListener l) {
    synchronized (listeners) {
        if (listeners.isEmpty()) {
            delegate.addLookupListener(this);
        }

        listeners.add(l);
    }
}
 
源代码26 项目: netbeans   文件: WhitespaceHighlighting.java
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
}
 
源代码27 项目: netbeans   文件: SearchScopeNodeSelection.java
public SearchScopeNodeSelection() {
    Lookup lookup = Utilities.actionsGlobalContext();
    lookupResult = lookup.lookupResult(Node.class);
    lookupListener = WeakListeners.create(LookupListener.class,
            this,
            lookupResult);
    lookupResult.addLookupListener(lookupListener);
}
 
源代码28 项目: snap-desktop   文件: CreateVectorDataNodeAction.java
public CreateVectorDataNodeAction(Lookup lkp) {
    super(Bundle.CTL_CreateVectorDataNodeActionText());
    this.lkp = lkp;
    result = this.lkp.lookupResult(ProductNode.class);
    result.addLookupListener(WeakListeners.create(LookupListener.class, this, result));
    putValue(Action.LARGE_ICON_KEY, ImageUtilities.loadImageIcon("org/esa/snap/rcp/icons/NewVectorDataNode16.gif", false));
    putValue(Action.SMALL_ICON, ImageUtilities.loadImageIcon("org/esa/snap/rcp/icons/NewVectorDataNode24.gif", false));
    setEnabled(false);
}
 
源代码29 项目: netbeans   文件: IssuesTest.java
/** 
 * 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 ------------------------------------------------
    
    
    
}
 
源代码30 项目: snap-desktop   文件: ToolAction.java
protected ToolAction(Lookup lookup, Interactor interactor) {
    putValue(ACTION_COMMAND_KEY, getClass().getName());
    putValue(SELECTED_KEY, false);
    interactorListener = new InternalInteractorListener();
    setInteractor(interactor);
    this.lookup = lookup != null ? lookup : Utilities.actionsGlobalContext();
    this.viewResult = this.lookup.lookupResult(ProductSceneView.class);
    this.viewResult.addLookupListener(WeakListeners.create(LookupListener.class, this, viewResult));
    updateEnabledState();
}