Java Code Examples for org.openide.util.Lookup

The following examples show how to use org.openide.util.Lookup. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: netbeans   Source File: CustomizeProject.java    License: Apache License 2.0 6 votes vote down vote up
protected @Override void refresh(Lookup context, boolean immediate) {
 
    super.refresh(context, immediate);
    
    Project[] projects = ActionsUtil.getProjectsFromLookup( context, null );
                        
    if ( projects.length != 1 || projects[0].getLookup().lookup( CustomizerProvider.class ) == null ) {
        setEnabled( false );
        // setDisplayName( ActionsUtil.formatProjectSensitiveName( namePattern, new Project[0] ) );
    }
    else { 
        setEnabled( true );
        // setDisplayName( ActionsUtil.formatProjectSensitiveName( namePattern, projects ) );
    }
    
    
}
 
Example 2
Source Project: NBANDROID-V2   Source File: AndroidStyleable.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void render(Graphics g, Font defaultFont, Color defaultColor, Color backgroundColor, int width, int height, boolean selected) {
    ImageIcon icon = null;
    Collection<? extends StyleableIconProvider> iconProviders = Lookup.getDefault().lookupAll(StyleableIconProvider.class);
    Iterator<? extends StyleableIconProvider> iterator = iconProviders.iterator();
    while (iterator.hasNext()) {
        StyleableIconProvider iconProvider = iterator.next();
        try {
            icon = iconProvider.getIcon(fullClassName, androidStyleableType);
        } catch (Exception e) {
            Exceptions.printStackTrace(e);
        }
        if (icon != null) {
            break;
        }
    }
    CompletionUtilities.renderHtml(icon, getFullClassName(), getAndroidStyleableType().name(),
            g, defaultFont, defaultColor, width, height, selected);
    Completion c = Completion.get();
    c.hideDocumentation();
    c.showDocumentation();
}
 
Example 3
Source Project: netbeans   Source File: NavigatorController.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void beforeLookup(Template<?> template) {
    super.beforeLookup(template);

    Lookup[] curNodesLookups;

    synchronized (CUR_NODES_LOCK) {
        curNodesLookups = new Lookup[curNodes.size()];
        int i = 0;
        for (Iterator<? extends Node> it = curNodes.iterator(); it.hasNext(); i++) {
            curNodesLookups[i] = it.next().getLookup();
        }
    }

    setLookups(curNodesLookups);
}
 
Example 4
Source Project: netbeans   Source File: BuildArtifactMapperImpl.java    License: Apache License 2.0 6 votes vote down vote up
private static boolean protectAgainstErrors(URL targetFolder, FileObject[][] sources, Object context) throws MalformedURLException {
    Preferences pref = NbPreferences.forModule(BuildArtifactMapperImpl.class).node(BuildArtifactMapperImpl.class.getSimpleName());

    if (!pref.getBoolean(UIProvider.ASK_BEFORE_RUN_WITH_ERRORS, true)) {
        return true;
    }
    
    sources(targetFolder, sources);
    
    for (FileObject file : sources[0]) {
        if (ErrorsCache.isInError(file, true) && !alreadyWarned.contains(context)) {
            UIProvider uip = Lookup.getDefault().lookup(UIProvider.class);
            if (uip == null || uip.warnContainsErrors(pref)) {
                alreadyWarned.add(context);
                return true;
            }
            return false;
        }
    }

    return true;
}
 
Example 5
Source Project: netbeans   Source File: LafPanel.java    License: Apache License 2.0 6 votes vote down vote up
private void switchEditorColorsProfile() {
    if( !isChangeEditorColorsPossible() )
        return;
    String preferredProfile = getPreferredColorProfile();

    ClassLoader cl = Lookup.getDefault().lookup( ClassLoader.class );
    if( null == cl )
        cl = LafPanel.class.getClassLoader();
    try {
        Class klz = cl.loadClass( COLOR_MODEL_CLASS_NAME );
        Object colorModel = klz.newInstance();
        Method m = klz.getDeclaredMethod( "getAnnotations", String.class ); //NOI18N
        Object annotations = m.invoke( colorModel, preferredProfile );
        m = klz.getDeclaredMethod( "setAnnotations", String.class, Collection.class ); //NOI18N
        m.invoke( colorModel, preferredProfile, annotations );
        m = klz.getDeclaredMethod( "setCurrentProfile", String.class ); //NOI18N
        m.invoke( colorModel, preferredProfile );
    } catch( Exception ex ) {
        //ignore
        Logger.getLogger( LafPanel.class.getName() ).log( Level.INFO, "Cannot change editor colors profile.", ex ); //NOI18N
    }
}
 
Example 6
Source Project: netbeans   Source File: NetigsoHandle.java    License: Apache License 2.0 6 votes vote down vote up
synchronized void classLoaderUp(NetigsoModule nm) throws IOException {
    if (toInit != null) {
        toInit.add(nm);
        return;
    }
    List<Module> clone;
    synchronized (toEnable) {
        @SuppressWarnings("unchecked")
        List<Module> cloneTmp = (List<Module>) toEnable.clone();
        clone = cloneTmp;
        toEnable.clear();
    }
    if (!clone.isEmpty()) {
        getDefault().prepare(Lookup.getDefault(), clone);
    }
    nm.start();
}
 
Example 7
Source Project: netbeans   Source File: TomcatInstanceNode.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Overrides the compatible XML DO behaviour for files without data objects
 * @param context
 * @return 
 */
@MIMEResolver.Registration(
    displayName="org.netbeans.modules.tomcat5.resources.Bundle#TomcatResolver",
    position=380,
    resource="../../resources/tomcat-mime-resolver.xml"
)
@MultiViewElement.Registration(
    displayName="org.netbeans.modules.tomcat5.ui.nodes.Bundle#CTL_SourceTabCaption",
    iconBase="org/netbeans/modules/tomcat5/resources/tomcat5.gif",
    persistenceType=TopComponent.PERSISTENCE_ONLY_OPENED,
    preferredID="xml.text",
    mimeType="text/tomcat5+xml",
    position=1
)
public static MultiViewEditorElement createMultiViewEditorElement(Lookup context) {
    return new MultiViewEditorElement(context);
}
 
Example 8
Source Project: netbeans   Source File: Loder.java    License: Apache License 2.0 5 votes vote down vote up
public static boolean foundNow() {
    for (ModuleInfo m : Lookup.getDefault().lookupAll(ModuleInfo.class)) {
        if (m.getCodeNameBase().equals("lookformyself")) {
            return true;
        }
    }
    return false;
}
 
Example 9
Source Project: netbeans   Source File: TasksPanel.java    License: Apache License 2.0 5 votes vote down vote up
@Messages({
    "LBL_PrivateTasks=Other Tasks"
})
@SuppressWarnings("OverridableMethodCallInConstructor")
public TaskGroupNode(String group, GradleBaseProject project) {
    super(Children.create(new TaskGroupChildren(group, project), true), Lookup.EMPTY);
    setName(group);
    String displayName = GradleBaseProject.PRIVATE_TASK_GROUP.equals(group)
            ? LBL_PrivateTasks()
            : Utils.capitalize(group);
    setDisplayName(displayName);
}
 
Example 10
@NbBundle.Messages("ClassesListController_AnalyzingClassesMsg=Analyzing classes...")
private static Collection getContextSubclasses(Heap heap, String className, Lookup.Provider project) {
    ProgressHandle pHandle = null;

    try {
        pHandle = ProgressHandle.createHandle(Bundle.ClassesListController_AnalyzingClassesMsg());
        pHandle.setInitialDelay(0);
        pHandle.start();

        HashSet subclasses = new HashSet();

        SourceClassInfo sci = ProfilerTypeUtils.resolveClass(className, project);
        Collection<SourceClassInfo> impls = sci != null ? sci.getSubclasses() : Collections.EMPTY_LIST;

        for (SourceClassInfo ci : impls) {
            JavaClass jClass = heap.getJavaClassByName(ci.getQualifiedName());

            if ((jClass != null) && subclasses.add(jClass)) { // instanceof approach rather than subclassof
                subclasses.addAll(jClass.getSubClasses());
            }
        }

        return subclasses;
    } finally {
        if (pHandle != null) {
            pHandle.finish();
        }
    }
}
 
Example 11
Source Project: netbeans   Source File: FolderNodeFactory.java    License: Apache License 2.0 5 votes vote down vote up
public Action createContextAwareInstance(Lookup selection) {
    final Project[] projects = selection.lookupAll(Project.class).toArray(new Project[0]);
    return new AbstractAction(SystemAction.get(OpenAction.class).getName()) {
        public void actionPerformed(ActionEvent ev) {
            OpenProjects.getDefault().open(projects, false);
        }
        @Override
        public boolean isEnabled() {
            return !Arrays.asList(OpenProjects.getDefault().getOpenProjects()).containsAll(Arrays.asList(projects));
        }
    };
}
 
Example 12
public DrawRectangleToolAction(Lookup lookup) {
    super(lookup);
    putValue(NAME, Bundle.CTL_DrawRectangleToolActionText());
    putValue(SHORT_DESCRIPTION, Bundle.CTL_DrawRectangleToolActionDescription());
    putValue(SMALL_ICON, ImageUtilities.loadImageIcon("org/esa/snap/rcp/icons/DrawRectangleTool24.gif", false));
    Interactor interactor = new InsertRectangleFigureInteractor();
    interactor.addListener(new InsertFigureInteractorInterceptor());
    setInteractor(interactor);
}
 
Example 13
Source Project: netbeans   Source File: DOMConvertor.java    License: Apache License 2.0 5 votes vote down vote up
/** read an object from String using Convertor.read() */
private static Object readFromString(Convertor c, String s, Lookup ctx) throws IOException, ClassNotFoundException {
    java.io.Reader r = new java.io.StringReader(s);
    
    FileObject fo = (FileObject) ctx.lookup(FileObject.class);
    if (fo != null) {
        r = org.netbeans.modules.settings.ContextProvider.createReaderContextProvider(r, fo);
    }
    
    return c.read(r);
}
 
Example 14
Source Project: netbeans   Source File: SaasExplorerPanel.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void addNotify() {
    super.addNotify();
    manager.addPropertyChangeListener(this);
    SaasViewProvider saasView = Lookup.getDefault().lookup(SaasViewProvider.class);
    if (saasView != null) {
        Node saasRootNode = saasView.getSaasView();
        manager.setRootContext(saasRootNode);
    }
    
    descriptor.setValid(false);
}
 
Example 15
private void addSpatialUndo(final Node undoParent, final Spatial undoSpatial, final AbstractSceneExplorerNode parentNode) {
    //add undo
    if (undoParent != null && undoSpatial != null) {
        Lookup.getDefault().lookup(SceneUndoRedoManager.class).addEdit(this, new AbstractUndoableSceneEdit() {

            @Override
            public void sceneUndo() throws CannotUndoException {
                //undo stuff here
                undoSpatial.removeFromParent();
            }

            @Override
            public void sceneRedo() throws CannotRedoException {
                //redo stuff here
                undoParent.attachChild(undoSpatial);
            }

            @Override
            public void awtRedo() {
                if (parentNode != null) {
                    parentNode.refresh(true);
                }
            }

            @Override
            public void awtUndo() {
                if (parentNode != null) {
                    parentNode.refresh(true);
                }
            }
        });
    }
}
 
Example 16
Source Project: netbeans   Source File: JavaActionsImplementationFactory.java    License: Apache License 2.0 5 votes vote down vote up
public static void doIntroduceLocalExtension(Lookup lookup) {
    for (JavaActionsImplementationProvider rafi: implementations.allInstances()) {
        if (rafi.canIntroduceLocalExtension(lookup)) {
            rafi.doIntroduceLocalExtension(lookup);
            return;
        }
    }
}
 
Example 17
Source Project: netbeans   Source File: CallbackSystemActionTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testPropertyChangeListenersDetachedAtFinalizeIssue58100() throws Exception {
    
    class MyAction extends AbstractAction {
        public void actionPerformed(ActionEvent ev) {
        }
    }
    MyAction action = new MyAction();
    ActionMap map = new ActionMap();
    
    map.put("key", action);
    Lookup context = Lookups.singleton(map);
    ContextAwareAction systemaction = CallbackActionTest.callback("key", null, Utilities.actionsGlobalContext(), false);
    Action delegateaction = systemaction.createContextAwareInstance(context);
    
    assertEquals("Action is expected to have no listener", 0, action.getPropertyChangeListeners().length);
    
    Reference<Object> actionref = new WeakReference<Object>(systemaction);
    systemaction = null;
    delegateaction = null;
    assertGC("CallbackSystemAction is supposed to be GCed", actionref);
    
    assertEquals(
        "Action is expected to have no PropertyChangeListener attached:\n" + 
            Arrays.asList(action.getPropertyChangeListeners())
        , 0, 
        action.getPropertyChangeListeners().length
    );
}
 
Example 18
Source Project: netbeans   Source File: AdditionalAntBasedTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testIfAntBasedProjectInstalled() throws Exception {
    FileObject fo = FileUtil.getConfigFile("Menu/Edit");
    assertNull("Default layer is on and Edit is hidden", fo);

    Result<AntBasedType> res = Lookup.getDefault().lookupResult(AntBasedType.class);
    assertEquals("no ant project types: " + res.allInstances(), 0, res.allInstances().size());
    res.addLookupListener(this);

    LOG.info("creating AntBasedType registration on disk");
    FileUtil.createData(FileUtil.getConfigRoot(), 
        "Services/" + AntBasedType.class.getName().replace('.', '-') + ".instance"
    );
    LOG.info("registration created");
    AntBasedType f = Lookup.getDefault().lookup(AntBasedType.class);
    LOG.info("looking up the result " + f);
    synchronized (this) {
        while (!delivered) {
            wait();
        }
    }

    assertNotNull("Ant found", f);
    LOG.info("waiting for FoDFileSystem to be updated");
    FoDLayersProvider.getInstance().waitFinished();
    LOG.info("waiting for FoDFileSystem to be waitFinished is over");

    for (int cnt = 0; cnt < 5; cnt++) {
        fo = FileUtil.getConfigFile("Menu/Edit");
        if (fo != null) {
            break;
        }
        Thread.sleep(500);
    }
    LOG.info("Edit found: " + fo);
    LOG.info("Menu items: " + Arrays.toString(FileUtil.getConfigFile("Menu").getChildren()));
    assertNotNull("Default layer is off and Edit is visible", fo);
}
 
Example 19
Source Project: netbeans   Source File: MetaInfServicesLookupTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testStability() throws Exception {
    Lookup l = getTestedLookup(c2);
    Class<?> xface = c1.loadClass("org.foo.Interface");
    Object first = l.lookup(xface);
    assertEquals(first, l.lookupAll(xface).iterator().next());
    l = getTestedLookup(c2a);
    Object second = l.lookup(xface);
    assertEquals(first, second);
}
 
Example 20
Source Project: netbeans   Source File: NodeJsActionProvider.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean isActionEnabled(String command, Lookup context) {
    Command runCommand = commands.get(command);
    if (runCommand == null) {
        return false;
    }
    return runCommand.isEnabled(context);
}
 
Example 21
Source Project: netbeans   Source File: Mercurial.java    License: Apache License 2.0 5 votes vote down vote up
/**
 *
 * @return registered hyperlink providers
 */
public List<VCSHyperlinkProvider> getHyperlinkProviders() {
    if (hpResult == null) {
        hpResult = (Result<? extends VCSHyperlinkProvider>) Lookup.getDefault().lookupResult(VCSHyperlinkProvider.class);
    }
    if (hpResult == null) {
        return Collections.<VCSHyperlinkProvider>emptyList();
    }
    Collection<? extends VCSHyperlinkProvider> providersCol = hpResult.allInstances();
    List<VCSHyperlinkProvider> providersList = new ArrayList<VCSHyperlinkProvider>(providersCol.size());
    providersList.addAll(providersCol);
    return Collections.unmodifiableList(providersList);
}
 
Example 22
Source Project: netbeans   Source File: DriverNodeProvider.java    License: Apache License 2.0 5 votes vote down vote up
private DriverNodeProvider(Lookup lookup) {
    super(lookup, driverComparator);
    
    JDBCDriverManager mgr = JDBCDriverManager.getDefault();
    mgr.addDriverListener(
        new JDBCDriverListener() {
            @Override
            public void driversChanged() {
                initialize();
            }
        }
    );
}
 
Example 23
Source Project: NBANDROID-V2   Source File: AndroidJavaPlatformProvider8.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected AndroidJavaPlatform createPlatform(List<JavaPlatform> tmp, AndroidPlatformInfo pkg) {
    AndroidJavaPlatform javaPlatform = new AndroidJavaPlatform(pkg, "1.8");
    tmp.add(javaPlatform);
    //add ReadOnlyURLMapper as listener, to avoid lookup chaos when addPropertyChangeListener called directly from ReadOnlyURLMapper
    addPropertyChangeListener(Lookup.getDefault().lookup(ReadOnlyURLMapper.class));
    return javaPlatform;
}
 
Example 24
Source Project: netbeans   Source File: URLMapper.java    License: Apache License 2.0 5 votes vote down vote up
/** Reset cache, for use from unit tests. */
static void reset() {
    cache = null;
    result = Lookup.getDefault().lookupResult(URLMapper.class);
    result.addLookupListener(
        new LookupListener() {
            public void resultChanged(LookupEvent ev) {
                synchronized (URLMapper.class) {
                    cache = null;
                }
            }
        }
    );
}
 
Example 25
Source Project: netbeans   Source File: ContextAction.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public boolean enabled(List<? extends Object> data, Lookup.Provider everything) {
    Object o = delegate.get("enabler"); // NOI18N
    if (o == null) {
        return true;
    }

    if (o instanceof ContextActionEnabler) {
        ContextActionEnabler<Object> en = (ContextActionEnabler<Object>)o;
        return en.enabled(data);
    }

    GeneralAction.LOG.warning("Wrong enabler for " + delegate + ":" + o);
    return false;
}
 
Example 26
Source Project: netbeans   Source File: JsonParserResult.java    License: Apache License 2.0 5 votes vote down vote up
@NonNull
private static Lookup createAdditionalLookup(
        @NullAllowed final org.netbeans.modules.javascript2.json.parser.JsonParser.JsonContext parseTree) {
    return parseTree == null ?
            Lookup.EMPTY :
            Lookups.singleton(parseTree);
}
 
Example 27
Source Project: netbeans   Source File: JFXProjectProperties.java    License: Apache License 2.0 5 votes vote down vote up
/** Creates a new instance of JFXProjectProperties */
private JFXProjectProperties(Lookup context) {
    
    //defaultInstance = provider.getJFXProjectProperties();
    project = context.lookup(Project.class);
    
    if (project != null) {
        j2sePropEval = project.getLookup().lookup(J2SEPropertyEvaluator.class);
        evaluator = j2sePropEval.evaluator();
        
        // Packaging
        binaryEncodeCSS = fxPropGroup.createToggleButtonModel(evaluator, JAVAFX_BINARY_ENCODE_CSS); // set true by default in JFXProjectGenerator

        // Deployment
        allowOfflineModel = fxPropGroup.createToggleButtonModel(evaluator, ALLOW_OFFLINE); // set true by default in JFXProjectGenerator            
        backgroundUpdateCheck = fxPropGroup.createToggleButtonModel(evaluator, UPDATE_MODE_BACKGROUND); // set true by default in JFXProjectGenerator
        installPermanently = fxPropGroup.createToggleButtonModel(evaluator, INSTALL_PERMANENTLY);
        addDesktopShortcut = fxPropGroup.createToggleButtonModel(evaluator, ADD_DESKTOP_SHORTCUT);
        addStartMenuShortcut = fxPropGroup.createToggleButtonModel(evaluator, ADD_STARTMENU_SHORTCUT);
        disableProxy = fxPropGroup.createToggleButtonModel(evaluator, DISABLE_PROXY);
        
        // CustomizerRun
        CONFIGS = new JFXConfigs();
        CONFIGS.read();
        initPreloaderArtifacts(project, CONFIGS);
        CONFIGS.setActive(evaluator.getProperty(ProjectProperties.PROP_PROJECT_CONFIGURATION_CONFIG));
        preloaderClassModel = new PreloaderClassComboBoxModel();

        initVersion(evaluator);
        initIcons(evaluator);
        initSigning(evaluator);
        initNativeBundling(evaluator);
        initResources(evaluator, project, CONFIGS);
        initJSCallbacks(evaluator);
        initRest(evaluator);
    }
}
 
Example 28
Source Project: netbeans   Source File: CustomizationTest.java    License: Apache License 2.0 5 votes vote down vote up
private WSDLModel getModel(){
    WSDLModel model = null;
   
    try{
         Document doc = this.getResourceAsDocument(TEST_WSDL);
         Lookup l = Lookups.fixed(new Object[] { doc });
         ModelSource source = new ModelSource(l, true);
         model = new WSDLModelImpl(source);
         model.sync();
    } catch(Exception e){
        System.out.println("Exception class: " + e.getClass().getName());
        System.out.println("Unable to load model: " + e.getMessage());
    }
    return model;
}
 
Example 29
Source Project: constellation   Source File: SchemaConceptUtilities.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Get the highest priority (ie. lowest {@link ServiceProvider} 'position'
 * value) SchemaConcept using {@link Lookup}.
 *
 * @return The highest priority SchemaConcept.
 */
public static final SchemaConcept getDefaultConcept() {
    if (DEFAULT_CONCEPT == null) {
        DEFAULT_CONCEPT = Lookup.getDefault().lookup(SchemaConcept.class);
    }
    return DEFAULT_CONCEPT;
}
 
Example 30
Source Project: netbeans   Source File: NodesRegistrationSupport.java    License: Apache License 2.0 5 votes vote down vote up
AbstractRegistrator(Class cls) {
    this.cls = cls;
    init();
    lookupResult = Lookup.getDefault().lookupResult(cls);
    register();
    lookupResult.addLookupListener(this);
}