org.openide.util.LookupEvent Java Examples

The following examples show how to use org.openide.util.LookupEvent. 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: MylynSupport.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private synchronized void ensureTaskListLoaded () throws CoreException {
    if (!taskListInitialized) {
        if (result == null) {
            LookupListener lookupListener = new LookupListener() {
                @Override
                public void resultChanged (LookupEvent ev) {
                    registerConnectors();
                }
            };
            result = Lookup.getDefault().lookupResult(RepositoryConnectorProvider.class);
            result.addLookupListener(lookupListener);
        }
        registerConnectors();
        try {
            if (taskListStorageFile.length() > 0) {
                taskListWriter.readTaskList(taskList, taskListStorageFile);
            }
        } catch (CoreException ex) {
            LOG.log(Level.INFO, null, ex);
            throw new CoreException(new Status(ex.getStatus().getSeverity(), ex.getStatus().getPlugin(), "Cannot deserialize tasklist"));
        } finally {
            taskListInitialized = true;
        }
    }
}
 
Example #2
Source File: MenuBaseAction.java    From constellation with Apache License 2.0 6 votes vote down vote up
@Override
public void resultChanged(final LookupEvent le) {
    if (currentGraphNode != null) {
        currentGraphNode.getGraph().removeGraphChangeListener(this);
        currentGraphNode = null;
    }

    if (this.getContext() != null) {
        currentGraphNode = this.getContext();
        currentGraphNode.getGraph().addGraphChangeListener(this);
        if (menuButton != null) {
            displayValue();
        }
        isEnabled();
    }
}
 
Example #3
Source File: MimeLookupLanguageProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public Language<?> findLanguage(String mimeType) {
    Lookup lookup = MimeLookup.getLookup(MimePath.parse(mimeType));
 
    //268649: add lookup listener for Language.class
    synchronized (LOCK) {
        Lookup.Result result = langLkpResultsMap.get(mimeType);
        if (result == null) {
            result = lookup.lookup(new Lookup.Template(Language.class));
            result.addLookupListener((LookupEvent evt) -> {
                firePropertyChange(PROP_LANGUAGE);
            });
            langLkpResultsMap.put(mimeType, result);
        }
    } 
    return (Language<?>)lookup.lookup(Language.class);
}
 
Example #4
Source File: LayoutMultiViewEditorElement.java    From NBANDROID-V2 with Apache License 2.0 6 votes vote down vote up
@Override
public void resultChanged(LookupEvent ev) {
    Collection<? extends AndroidClassPathProvider> allInstances = lookupResulClassPathProvider.allInstances();
    Collection<? extends BuildVariant> allInstances1 = lookupResulBuildVariant.allInstances();
    Collection<? extends AndroidProject> allInstances2 = lookupResultAndroidProject.allInstances();
    if (!allInstances2.isEmpty() && !allInstances.isEmpty() && androidClassPathProvider == null && !allInstances1.isEmpty()) {
        AndroidProject androidProject = allInstances2.iterator().next();
        Collection<File> resDirectories = androidProject.getDefaultConfig().getSourceProvider().getResDirectories();
        resFolderFile = resDirectories.iterator().next();
        androidClassPathProvider = allInstances.iterator().next();
        classPath = androidClassPathProvider.getCompilePath();
        classPath.addPropertyChangeListener(WeakListeners.create(PropertyChangeListener.class, this, classPath));
        roots = classPath.getRoots();
        buildVariant = allInstances1.iterator().next();
        loader = new Loader();
        buildVariant.addChangeListener(WeakListeners.change(loader, buildVariant));
        loader.stateChanged(null);
    }
}
 
Example #5
Source File: ProxyLookupEventIssue136866Test.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testAbstractLookupFiresEventWhenContentChanged() {
    InstanceContent ic = new InstanceContent();
    AbstractLookup al = new AbstractLookup(ic);

    final int[] counts = {0}; // Number of items observed upon a LookupEvent
    final Lookup.Result<String> result = al.lookupResult(String.class);

    result.addLookupListener(new LookupListener() {
        public void resultChanged(LookupEvent ev) {
            // this gets called as expected
            assertSame(result, ev.getSource());
            counts[0] = result.allInstances().size();
        }
    });
    
    ic.add("hello1");
    assertEquals(1, counts[0]);
}
 
Example #6
Source File: ActiveBrowserAction.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public ActiveBrowserAction() {
    lookup = LastActivatedWindowLookup.INSTANCE;
    resultPrj = lookup.lookupResult(Project.class);
    resultDO = lookup.lookupResult(DataObject.class);
    resultFO = lookup.lookupResult(FileObject.class);
    resultPrj.addLookupListener(WeakListeners.create(LookupListener.class, this, resultPrj));
    resultDO.addLookupListener(WeakListeners.create(LookupListener.class, this, resultDO));
    resultFO.addLookupListener(WeakListeners.create(LookupListener.class, this, resultFO));
    currentBrowserProviderListener = new PropertyChangeListener() {
        public @Override void propertyChange(PropertyChangeEvent evt) {
            if (ProjectBrowserProvider.PROP_BROWSER_ACTIVE.equals(evt.getPropertyName())) {
                updateButton(ActiveBrowserAction.this.getBrowserProvider());
            }
        }
    };
    lookupListener = new LookupListener() {
        @Override
        public void resultChanged(LookupEvent ev) {
            refreshViewLater(true);
        }
    };

    refreshView(false);
}
 
Example #7
Source File: MultiViewTopComponentLookup.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void resultChanged(LookupEvent ev) {
    synchronized (listeners) {
        Collection current = allInstances();
        boolean equal = lastResults != null && current != null && current.containsAll(lastResults) && lastResults.containsAll(current);
        if (equal) {
            // the merged list is the same, ignore...
            return ;
        }
        lastResults = current;
    }
        
    LookupEvent ev2 = new LookupEvent(this);
    LookupListener[] ls;
    synchronized (listeners) {
        ls = (LookupListener[])listeners.toArray(new LookupListener[listeners.size()]);
    }
    for (int i = 0; i < ls.length; i++) {
        ls[i].resultChanged(ev2);
    }
}
 
Example #8
Source File: SelectDeviceAction.java    From NBANDROID-V2 with Apache License 2.0 6 votes vote down vote up
@Override
public void resultChanged(LookupEvent le) {
    Collection<? extends Node> allInstances = lookupResultNode.allInstances();
    if (!allInstances.isEmpty()) {
        Node abstractNode = allInstances.iterator().next();
        while (abstractNode != null) {
            NbAndroidProjectImpl project = abstractNode.getLookup().lookup(NbAndroidProjectImpl.class);
            if (project != null) {
                updateMenu(project);
                return;
            }
            abstractNode = abstractNode.getParentNode();
        }
    }
    Collection<? extends DataObject> allInstancesDob = lookupResultDob.allInstances();
    if (!allInstancesDob.isEmpty()) {
        Project owner = FileOwnerQuery.getOwner(allInstancesDob.iterator().next().getPrimaryFile());
        if (owner instanceof NbAndroidProjectImpl) {
            updateMenu((NbAndroidProjectImpl) owner);
            return;
        }
    }

    toolbarButton.setVisible(false);
}
 
Example #9
Source File: ExampleSelectionTopComponent.java    From snap-examples with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void resultChanged(LookupEvent lookupEvent) {
    Collection<?> selectedObjects = result.allInstances();
    if (!selectedObjects.isEmpty()) {
        Object[][] data = new Object[selectedObjects.size()][3];
        int i = 0;
        for (Object selectedObject : selectedObjects) {
            data[i][0] = i + 1;
            data[i][1] = selectedObject.getClass().getSimpleName();
            data[i][2] = String.valueOf(selectedObject);
            i++;
        }
        infoLabel.setText(selectedObjects.size() + " objects(s) selected:");
        infoTable.setModel(new DefaultTableModel(data, new String[]{"#", "Type", "Name"}));
        infoTable.getColumnModel().getColumn(0).setPreferredWidth(20);
        infoTable.getColumnModel().getColumn(1).setPreferredWidth(80);
    } else {
        infoLabel.setText("No objects selected.");
        infoTable.setModel(new DefaultTableModel());
    }
}
 
Example #10
Source File: DependencyViewTopComponent.java    From BART with MIT License 6 votes vote down vote up
@Override
public void resultChanged(LookupEvent ev) {
    Dependency tmp = Utilities.actionsGlobalContext().lookup(Dependency.class);
    if(tmp != null)   {
        if(dependency != null)  {
            if(dependency.equals(tmp))return;
        }
        dependency = tmp;
        EGTaskDataObjectDataObject dto = Utilities.actionsGlobalContext().lookup(EGTaskDataObjectDataObject.class);
        if(dto == null)return;
        EGTask egt = dto.getEgtask();
        ParseDependency parser = new ParseDependency(dependency);
        panel = new  DependencyOpenPanel();
        panel.getPanelDependecy().setTextLabelDependency(parser.parse());
        
        ParseVioGenQueries parseVGQ = new ParseVioGenQueries(parser.getVariablesColorMap(), dependency, egt);
        VioGenQueryTableModel model = new VioGenQueryTableModel(dto,parseVGQ.getVioGenQueriesData().getVioGQVector());
        model.addTableModelListener(new TableListener());
        panel.getPanelVioGenQueriesWPanel().bind(model);
        scrolDependency.setViewportView(panel);
        panel.getPanelDependecy().animateBackground();  
        panel.getPanelVioGenQueriesWPanel().fade();
    }
}
 
Example #11
Source File: GraphStatusLine.java    From constellation with Apache License 2.0 6 votes vote down vote up
@Override
public void resultChanged(final LookupEvent ev) {
    if (graph != null) {
        graph.removeGraphChangeListener(this);
    }

    final Node[] activatedNodes = TopComponent.getRegistry().getActivatedNodes();
    if (activatedNodes.length > 0 && activatedNodes[0] instanceof GraphNode) {
        final GraphNode gnode = (GraphNode) activatedNodes[0];
        graph = gnode.getGraph();
        graph.addGraphChangeListener(this);
    } else {
        graph = null;
    }

    graphChanged(null);
}
 
Example #12
Source File: FindTopComponent.java    From constellation with Apache License 2.0 5 votes vote down vote up
@Override
public void resultChanged(final LookupEvent lev) {
    final Node[] activatedNodes = TopComponent.getRegistry().getActivatedNodes();
    if (activatedNodes != null && activatedNodes.length == 1
            && activatedNodes[0] instanceof GraphNode) {
        final GraphNode gnode = ((GraphNode) activatedNodes[0]);

        if (gnode != graphNode) {
            setNode(gnode);
        }
    } else {
        setNode(null);
    }
}
 
Example #13
Source File: ControlFlowTopComponent.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public void resultChanged(LookupEvent lookupEvent) {

        final InputGraphProvider p = Lookup.getDefault().lookup(InputGraphProvider.class);
        if (p != null) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
            InputGraph g = p.getGraph();
            if (g != null) {
                scene.setGraph(g);
            }
        }
            });
        }
    }
 
Example #14
Source File: FolderLookupTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void resultChanged(LookupEvent ev) {
    if (threadName.length() == 0) {
        threadName = Thread.currentThread().getName();
    } else {
        threadName = threadName + ", " + Thread.currentThread().getName();
    }
}
 
Example #15
Source File: ContextAction.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void resultChanged(LookupEvent e) {
    if (result.allItems().size() != 0) {
        update(result.allInstances().iterator().next());
    } else {
        update(null);
    }
}
 
Example #16
Source File: J2SEPlatformImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private List<URL> defaultJavadoc(final boolean listen) {
    final JavaPlatform safePlatform = new ForwardingJavaPlatform(this) {
        @Override
        public List<URL> getJavadocFolders() {
            return Collections.<URL>emptyList();
        }
    };
    final Set<URI> roots = new LinkedHashSet<>();
    final Lookup.Result<? extends J2SEPlatformDefaultJavadoc> res = getJ2SEPlatformDefaultJavadoc();
    if (listen) {
        synchronized (this) {
            if (jdocListener == null) {
                jdocListener = new LookupListener[2];
                jdocListener[0] = new LookupListener() {
                    @Override
                    public void resultChanged(LookupEvent ev) {
                        javadoc = null;
                    }
                };
                jdocListener[1] = WeakListeners.create(LookupListener.class, jdocListener[0], res);
                res.addLookupListener(jdocListener[1]);
            }
        }
    }
    for (J2SEPlatformDefaultJavadoc jdoc : res.allInstances()) {
        roots.addAll(jdoc.getDefaultJavadoc(safePlatform));
    }
    final List<URL> result = new ArrayList<>(roots.size());
    for (URI root : roots) {
        try {
            result.add(root.toURL());
        } catch (MalformedURLException ex) {
            Exceptions.printStackTrace(ex);
        }
    }
    return Collections.unmodifiableList(result);
}
 
Example #17
Source File: HtmlPlugins.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example #18
Source File: ControlFlowTopComponent.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void resultChanged(LookupEvent lookupEvent) {

        final InputGraphProvider p = Lookup.getDefault().lookup(InputGraphProvider.class);
        if (p != null) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
            InputGraph g = p.getGraph();
            if (g != null) {
                scene.setGraph(g);
            }
        }
            });
        }
    }
 
Example #19
Source File: ConnectionList.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private ConnectionList() {
    // issue 75204: forces the DataObject's corresponding to the DatabaseConnection's
    // to be initialized and held strongly so the same DatabaseConnection is
    // returns as long as it is held strongly
    result.allInstances();

    result.addLookupListener(new LookupListener() {
        public void resultChanged(LookupEvent e) {
            fireListeners();
        }
    });
}
 
Example #20
Source File: MultiViewProcessorTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public final void resultChanged(LookupEvent ev) {
    Collection<? extends Image> all = res.allInstances();
    if (all.isEmpty()) {
        getComponent().setIcon(null);
    } else {
        getComponent().setIcon(all.iterator().next());
    }
}
 
Example #21
Source File: ProxyLookupTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testProxyWithLiveResultCanBeCollected() {
    Lookup layer0 = Lookups.singleton("Hello");
    Lookup layer1 = new ProxyLookup(new Lookup[] { layer0 });
    Lookup layer2 = new ProxyLookup(new Lookup[] { layer1 });
    Lookup.Result result1 = layer1.lookup(new Lookup.Template(String.class));

    assertEquals("One instance", 1, result1.allInstances().size());

    // this will create ProxyLookup$R which listens on origResult
    Lookup.Result result2 = layer2.lookup(new Lookup.Template(String.class));
    
    // this line is necessary. W/o actually querying the result,
    // it will nether compute it nor attach the listener.
    assertEquals("One instance", 1, result2.allInstances().size());
    
    result2.addLookupListener(new LookupListener() {
        public void resultChanged(LookupEvent ev) {}
    });
    
    Reference ref = new WeakReference(layer2);
    layer2 = null;
    result2 = null;
    try {
        holder = result1;
        assertGC ("The proxy lookup not been garbage collected!", ref);
    } finally {
        holder = null;
    }
}
 
Example #22
Source File: WhiteListQueryImplementationMerged.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void resultChanged(LookupEvent ev) {
    synchronized(this) {
        cache = null;
    }
    this.changeSupport.fireChange();
}
 
Example #23
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 #24
Source File: CompletionImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void resultChanged(LookupEvent ev) {
    Utilities.runInEventDispatchThread(new Runnable(){
        public void run(){
            installKeybindings();
        }
    });
}
 
Example #25
Source File: GradleAndroidManifest.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
@Override
public void resultChanged(LookupEvent ev) {
    Collection<? extends AndroidProject> allInstances = lookupResult.allInstances();
    if (!allInstances.isEmpty()) {
        androidProjectModel = allInstances.iterator().next();
        cs.fireChange();
    } else {
        androidProjectModel = null;
    }
}
 
Example #26
Source File: GraphManager.java    From constellation with Apache License 2.0 5 votes vote down vote up
@Override
public void resultChanged(final LookupEvent lev) {
    final Node[] activatedNodes = TopComponent.getRegistry().getActivatedNodes();
    if (activatedNodes != null && activatedNodes.length == 1
            && activatedNodes[0] instanceof GraphNode) {
        final GraphNode gnode = ((GraphNode) activatedNodes[0]);

        if (gnode != graphNode) {
            setNode(gnode);
        }
    } else {
        setNode(null);
    }
}
 
Example #27
Source File: ModelExtender.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static synchronized ModelExtender getDefault() {
    if (instance == null) {
        instance = new ModelExtender();
        MODEL_INTERCEPTORS.addLookupListener(new LookupListener() {

            @Override
            public void resultChanged(LookupEvent ev) {
                synchronized (instance) {
                    instance.extendingObjects = null;
                }
            }
        });
    }
    return instance;
}
 
Example #28
Source File: JSBreakpointsInfoManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private JSBreakpointsInfoManager(final Lookup.Result<JSBreakpointsInfo> lookupResult,
                                 JSBreakpointsInfo[] activeServices) {
    lookupResult.addLookupListener(new LookupListener() {
        @Override
        public void resultChanged(LookupEvent ev) {
             updateServices(lookupResult.allInstances().toArray(new JSBreakpointsInfo[]{}));
        }
    });
    initServices(activeServices);
}
 
Example #29
Source File: AbstractLookupBaseHid.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void resultChanged(LookupEvent ev) {
            if (changesIn != null) {
                assertEquals("Changes in the same thread", changesIn, Thread.currentThread());
            } else {
                changesIn = Thread.currentThread();
            }
            ++count;
            if (source != null) {
                assertSame ("Source is the same", source, ev.getSource ());
//                assertSame ("Result is the same", source, ev.getResult ());
            }
        }
 
Example #30
Source File: ControlFlowTopComponent.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public void resultChanged(LookupEvent lookupEvent) {

        final InputGraphProvider p = Lookup.getDefault().lookup(InputGraphProvider.class);
        if (p != null) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
            InputGraph g = p.getGraph();
            if (g != null) {
                scene.setGraph(g);
            }
        }
            });
        }
    }