org.openide.util.lookup.ProxyLookup Java Examples

The following examples show how to use org.openide.util.lookup.ProxyLookup. 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: DOMNode.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public Action[] getActions(boolean context) {
    List<Action> actions = new ArrayList<Action>();
    actions.add(SystemAction.get(GoToNodeSourceAction.class));
    if (KnockoutTCController.isKnockoutUsed()) {
        actions.add(SystemAction.get(ShowKnockoutContextAction.class));
    }
    if (node.getNodeType() == org.w3c.dom.Node.ELEMENT_NODE) {
        for (Action action : org.openide.util.Utilities.actionsForPath(ACTIONS_PATH)) {
            if (action instanceof ContextAwareAction) {
                Lookup lookup = new ProxyLookup(Lookups.fixed(this), getLookup());
                action = ((ContextAwareAction)action).createContextAwareInstance(lookup);
            }
            actions.add(action);
        }
        actions.add(null);
        actions.add(SystemAction.get(PropertiesAction.class));
    }
    return actions.toArray(new Action[actions.size()]);
}
 
Example #2
Source File: JavaEEServerModule.java    From netbeans with Apache License 2.0 6 votes vote down vote up
JavaEEServerModule(Lookup instanceLookup, InstanceProperties ip) {
    instanceProperties = ip;
    logSupport = new LogHyperLinkSupport.AppServerLogSupport("", "/");

    // is this ok, can platform change ?
    ServerInstance inst = Deployment.getDefault().getServerInstance(
            instanceProperties.getProperty(InstanceProperties.URL_ATTR));
    J2eePlatform platform = null;
    try {
        platform = inst.getJ2eePlatform();
    } catch (InstanceRemovedException ex) {
    }
    lookup = platform != null
            ? new ProxyLookup(Lookups.fixed(platform, ip), Lookups.proxy(platform))
            : Lookup.EMPTY;
}
 
Example #3
Source File: BootCPNodeFactory.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static Node jarNode(SourceGroup sg) {
    final Node delegate = PackageView.createPackageView(sg);
    final PathFinder pathFinder = PathFinders.createDelegatingPathFinder(delegate.getLookup().lookup(PathFinder.class));
    final Lookup lkp = new ProxyLookup(
            Lookups.exclude(delegate.getLookup(), PathFinder.class),
            Lookups.singleton(pathFinder));
    return new FilterNode(
            delegate,
            null,
            lkp) {
                @Override
                public Action[] getActions(boolean context) {
                    return new Action[0];
                }
    };

}
 
Example #4
Source File: LayerDataObject.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public LayerDataObject(FileObject pf, MultiFileLoader loader) throws DataObjectExistsException, IOException {
    super(pf, loader);
    final CookieSet cookies = getCookieSet();
    final Lookup baseLookup = cookies.getLookup();
    lkp = new ProxyLookup(baseLookup) {
        final AtomicBoolean checked = new AtomicBoolean();
        protected @Override void beforeLookup(Template<?> template) {
            if (template.getType() == LayerHandle.class && checked.compareAndSet(false, true)) {
                FileObject xml = getPrimaryFile();
                Project p = FileOwnerQuery.getOwner(xml);
                if (p != null) {
                    setLookups(baseLookup, Lookups.singleton(new LayerHandle(p, xml)));
                }
            }
        }
    };
    registerEditor("text/x-netbeans-layer+xml", true);
    cookies.add(new ValidateXMLSupport(DataObjectAdapters.inputSource(this)));
}
 
Example #5
Source File: ContextProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void runTaskWithinContext(final Lookup context, final Task task) {
    JTextComponent component = context.lookup(JTextComponent.class);
    if (component != null) {
        try {
            JavaSource js = JavaSource.forDocument(component.getDocument());
            if (js != null) {
                final int caretOffset = component.getCaretPosition();
                js.runUserActionTask(new org.netbeans.api.java.source.Task<CompilationController>() {
                    public void run(CompilationController controller) throws Exception {
                        controller.toPhase(JavaSource.Phase.PARSED);
                        TreePath path = controller.getTreeUtilities().pathFor(caretOffset);
                        Lookup newContext = new ProxyLookup(context, Lookups.fixed(controller, path));
                        task.run(newContext);
                    }
                }, true);
                return;
            }
        } catch (IOException ioe) {
        }
    }
    task.run(context);
}
 
Example #6
Source File: FileUtil.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static Iterable<? extends ArchiveRootProvider> getArchiveRootProviders() {
    if (archiveRootProviderCache == null) {
        Lookup.Result<ArchiveRootProvider> res = archiveRootProviders.get();
        if (res == null) {
            res = new ProxyLookup(
                Lookups.singleton(new JarArchiveRootProvider()),
                Lookup.getDefault()).lookupResult(ArchiveRootProvider.class);
            if (archiveRootProviders.compareAndSet(null, res)) {
                res = archiveRootProviders.get();
                res.addLookupListener((ev) -> {
                    archiveRootProviderCache = null;
                });
            }
        }
        archiveRootProviderCache = new LinkedList<>(res.allInstances());
    }
    return archiveRootProviderCache;
}
 
Example #7
Source File: WebBrowserImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes popup-menu of the web-browser component.
 *
 * @param browserComponent component whose popup-menu should be initialized.
 */
private void initComponentPopupMenu(JComponent browserComponent) {
    if (PageInspector.getDefault() != null) {
        // Web-page inspection support is available in the IDE
        // => add a menu item that triggers page inspection.
        String inspectPage = NbBundle.getMessage(WebBrowserImpl.class, "WebBrowserImpl.inspectPage"); // NOI18N
        JPopupMenu menu = new JPopupMenu();
        menu.add(new AbstractAction(inspectPage) {
            @Override
            public void actionPerformed(ActionEvent e) {
                PageInspector inspector = PageInspector.getDefault();
                if (inspector == null) {
                    Logger logger = Logger.getLogger(WebBrowserImpl.class.getName());
                    logger.log(Level.INFO, "No PageInspector found: ignoring the request for page inspection!"); // NOI18N
                } else {
                    inspector.inspectPage(new ProxyLookup(getLookup(), projectContext));
                }
            }
        });
        browserComponent.setComponentPopupMenu(menu);
    }
}
 
Example #8
Source File: TabbedController.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public Lookup getLookup() {
    List<Lookup> lookups = new ArrayList<Lookup>();
    for (OptionsPanelController controller : getControllers()) {
        Lookup lookup = controller.getLookup();
        if (lookup != null && lookup != Lookup.EMPTY) {
            lookups.add(lookup);
        }
        if (lookup == null) {
            LOGGER.log(Level.WARNING, "{0}.getLookup() should never return null. Please, see Bug #194736.", controller.getClass().getName()); // NOI18N
            throw new NullPointerException(controller.getClass().getName() + ".getLookup() should never return null. Please, see Bug #194736."); // NOI18N
        }
    }
    if (lookups.isEmpty()) {
        return Lookup.EMPTY;
    } else {
        return new ProxyLookup(lookups.toArray(new Lookup[lookups.size()]));
    }
}
 
Example #9
Source File: TestDataDirsNodeFactory.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public Node node(final SourceGroup key) {
    try {
        Node nodeDelegate = DataObject.find(key.getRootFolder()).getNodeDelegate();
        return new FilterNode(nodeDelegate,
                null, new ProxyLookup(nodeDelegate.getLookup(), Lookups.singleton(new PathFinder(key)))) {
            @Override
            public String getName() {
                return key.getName();
            }
            @Override
            public String getDisplayName() {
                return key.getDisplayName();
            }
        };
    } catch (DataObjectNotFoundException ex) {
        throw new AssertionError(ex);
    }
}
 
Example #10
Source File: TreeRootNode.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private TreeRootNode(Node originalNode, SourceGroup group, GrailsProject project, Type type) {
    super(originalNode, new PackageFilterChildren(originalNode),
            new ProxyLookup(
            originalNode.getLookup(),
            Lookups.fixed(  new PathFinder(group),  // no need for explicit search info
                            // Adding TemplatesImpl to Node's lookup to narrow-down
                            // number of displayed templates with the NewFile action.
                            // see # 122942
                            new TemplatesImpl(project, group)
                            )
            ));
    String pathName = group.getName();
    setShortDescription(pathName.substring(project.getProjectDirectory().getPath().length() + 1));
    this.group = group;
    this.visualType = type;
    group.addPropertyChangeListener(WeakListeners.propertyChange(this, group));
}
 
Example #11
Source File: ContextProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void runTaskWithinContext(Lookup context, Task task) {
    JTextComponent component = context.lookup(JTextComponent.class);
    if (component != null) {
        DataObject dobj = NbEditorUtilities.getDataObject(component.getDocument());
        if (dobj != null) {
            FileObject fo = dobj.getPrimaryFile();
            ModelSource ms = Utilities.createModelSource(fo);
            if (ms.isEditable()) {
                POMModel model = POMModelFactory.getDefault().getModel(ms);
                if (model != null) {
                    Lookup newContext = new ProxyLookup(context, Lookups.fixed(model));
                    task.run(newContext);
                    return;
                }
            }
        }
    }
    task.run(context);
}
 
Example #12
Source File: SettingsContextProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void runTaskWithinContext(Lookup context, Task task) {
    JTextComponent component = context.lookup(JTextComponent.class);
    if (component != null) {
        DataObject dobj = NbEditorUtilities.getDataObject(component.getDocument());
        if (dobj != null) {
            FileObject fo = dobj.getPrimaryFile();
            ModelSource ms = Utilities.createModelSource(fo);
            SettingsModel model = SettingsModelFactory.getDefault().getModel(ms);
            if (model != null) {
                Lookup newContext = new ProxyLookup(context, Lookups.fixed(model));
                task.run(newContext);
                return;
            }
        }
    }
    task.run(context);
}
 
Example #13
Source File: DocumentServices.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private Lookup.Result<DocumentServiceFactory<?>> initDocumentFactories(Class<?> c) {
    List<Lookup> lkps = new ArrayList<Lookup>(5);
    do {
        String cn = c.getCanonicalName();
        if (cn != null) {
            lkps.add(Lookups.forPath("Editors/Documents/" + cn)); // NOI18N
        }
        c = c.getSuperclass();
    } while (c != null && c != java.lang.Object.class);
    Lookup[] arr = lkps.toArray(new Lookup[lkps.size()]);
    @SuppressWarnings("rawtypes")
    Lookup.Result lookupResult = new ProxyLookup(arr).lookupResult(DocumentServiceFactory.class);
    @SuppressWarnings("unchecked")
    Lookup.Result<DocumentServiceFactory<?>> res = (Lookup.Result<DocumentServiceFactory<?>>) lookupResult;
    return res;
}
 
Example #14
Source File: PaletteItemNode.java    From netbeans with Apache License 2.0 6 votes vote down vote up
PaletteItemNode(DataNode original, 
                String name, 
                String bundleName, 
                String displayNameKey, 
                String className, 
                String tooltipKey, 
                String icon16URL, 
                String icon32URL, 
                InstanceContent content) 
{
    super(original, Children.LEAF, new ProxyLookup(( new Lookup[] {new AbstractLookup(content), original.getLookup()})));
    
    content.add( this );
    this.name = name;
    this.bundleName = bundleName; 
    this.displayNameKey = displayNameKey;
    this.className = className;
    this.tooltipKey = tooltipKey;
    this.icon16URL = icon16URL;
    this.icon32URL = icon32URL;
    
    this.originalDO = original.getLookup().lookup(DataObject.class);
}
 
Example #15
Source File: PackageRootNode.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private PackageRootNode( SourceGroup group, Children ch) {
    super(ch, new ProxyLookup(createLookup(group), Lookups.singleton(
            SearchInfoDefinitionFactory.createSearchInfoBySubnodes(ch))));
    this.group = group;
    file = group.getRootFolder();
    files = Collections.singleton(file);
    try {
        FileSystem fs = file.getFileSystem();
        fileSystemListener = FileUtil.weakFileStatusListener(this, fs);
        fs.addFileStatusListener(fileSystemListener);
    } catch (FileStateInvalidException e) {            
        Exceptions.printStackTrace(Exceptions.attachMessage(e,"Can not get " + file + " filesystem, ignoring...")); //NOI18N
    }
    setName( group.getName() );
    setDisplayName( group.getDisplayName() );        
    // setIconBase("org/netbeans/modules/java/j2seproject/ui/resources/packageRoot");
}
 
Example #16
Source File: BasicCustomizer.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Messages({
    "PROGRESS_loading_data=Loading project information",
    "# {0} - project display name", "LBL_CustomizerTitle=Project Properties - {0}"
})
public void showCustomizer(String preselectedCategory, final String preselectedSubCategory) {
    if (dialog != null) {
        dialog.setVisible(true);
    } else {
        final String category = (preselectedCategory != null) ? preselectedCategory : lastSelectedCategory;
        final AtomicReference<Lookup> context = new AtomicReference<Lookup>();
        ProgressUtils.runOffEventDispatchThread(new Runnable() {
            @Override public void run() {
                context.set(new ProxyLookup(prepareData(), Lookups.fixed(new SubCategoryProvider(category, preselectedSubCategory))));
            }
        }, PROGRESS_loading_data(), /* currently unused */new AtomicBoolean(), false);
        if (context.get() == null) { // canceled
            return;
        }
        OptionListener listener = new OptionListener();
        dialog = ProjectCustomizer.createCustomizerDialog(layerPath, context.get(), category, listener, null);
        dialog.addWindowListener(listener);
        dialog.setTitle(LBL_CustomizerTitle(ProjectUtils.getInformation(getProject()).getDisplayName()));
        dialog.setVisible(true);
    }
}
 
Example #17
Source File: BridgingServerInstance.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Lookup getLookup() {
    // FIXME why is the platform written in such strange way ?
    J2eePlatform platform = Deployment.getDefault().getJ2eePlatform(instance.getUrl());

    if (platform == null) { // can happen when J2EE is activated and J2SE is not !?@#
        return Lookups.singleton(instance.getInstanceProperties());
    } else {
        return new ProxyLookup(Lookups.fixed(platform, instance.getInstanceProperties()), Lookups.proxy(platform));
    }
}
 
Example #18
Source File: HistoryComponent.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public HistoryComponent() {
    activatedNodesContent = new InstanceContent();
    lookup = new ProxyLookup(new Lookup[] {
        new AbstractLookup(activatedNodesContent)
    });
    init();
}
 
Example #19
Source File: PhpDeleteRefactoringUI.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public PhpDeleteRefactoringUI(SafeDeleteSupport support, boolean regularDelete) {
    Collection<Object> lookupContent = new ArrayList<>();
    lookupContent.add(support);
    this.refactoring = new SafeDeleteRefactoring(new ProxyLookup(Lookups.fixed(support.getFile()), Lookups.fixed(lookupContent.toArray())));
    this.file = support.getFile();
    this.regulardelete = regularDelete;
}
 
Example #20
Source File: FolderBasedController.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized JComponent getComponent(Lookup masterLookup) {
    if (panel == null) {
        this.masterLookup = masterLookup;
        for (Entry<String, OptionsPanelController> e : getMimeType2delegates ().entrySet()) {
            OptionsFilter f = OptionsFilter.create(filterDocument, new FilteringUsedCallback(e.getKey()));
            Lookup innerLookup = new ProxyLookup(masterLookup, Lookups.singleton(f));
            OptionsPanelController controller = e.getValue();
            controller.getComponent(innerLookup);
            controller.addPropertyChangeListener(this);
        }
        panel = new FolderBasedOptionPanel(this, filterDocument, allowFiltering);
    }
    return panel;
}
 
Example #21
Source File: SafeDeleteAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected Lookup getLookup(Node[] n) {
    Lookup l = super.getLookup(n);
    if (regularDelete) {
        ExplorerContext con = l.lookup(ExplorerContext.class);
        if (con != null) {
            con.setDelete(true);
        } else {
            con = new ExplorerContext();
            con.setDelete(true);
            return new ProxyLookup(l, Lookups.singleton(con));
        }
    }
    return l;
}
 
Example #22
Source File: NbAndroidProjectImpl.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
public ProjectNode(Node node)
        throws DataObjectNotFoundException {
    super(node,
            new ProjectNodes(),
            new ProxyLookup(
                    new Lookup[]{
                        Lookups.singleton(NbAndroidProjectImpl.this),
                        node.getLookup(), Lookups.singleton(new RootGoalsNavigatorHint()),
                        lookupModels
                    }));
}
 
Example #23
Source File: RootNode.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private RootNode( Node originalRoot, InstanceContent content, Lookup lkp ) {
    super( originalRoot, 
            new Children( originalRoot, lkp ),
            new ProxyLookup( new Lookup[] { lkp, new AbstractLookup( content ), originalRoot.getLookup() } ) );
    DataFolder df = (DataFolder)getOriginal().getCookie( DataFolder.class );
    if( null != df ) {
        content.add( new DataFolder.Index( df, this ) );
    }
    content.add( this );
    setDisplayName(Utils.getBundleString("CTL_Component_palette")); // NOI18N
}
 
Example #24
Source File: CategoryNode.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private CategoryNode( Node originalNode, InstanceContent content, Lookup lkp ) {
    super( originalNode, 
           new Children( originalNode, lkp ),
           new ProxyLookup( new Lookup[] { lkp, new AbstractLookup(content), originalNode.getLookup() } ) );
    
    DataFolder folder = (DataFolder)originalNode.getCookie( DataFolder.class );
    if( null != folder ) {
        content.add( new DataFolder.Index( folder, this ) );
        FileObject fob = folder.getPrimaryFile();
        Object catName = fob.getAttribute( CAT_NAME );
        if (catName instanceof String)
            setDisplayName((String)catName);
    }
    content.add( this );
}
 
Example #25
Source File: NbAndroidRootProjectImpl.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
public ProjectNode(Node node)
        throws DataObjectNotFoundException {
    super(node,
            new ProjectNodes(),
            new ProxyLookup(
                    new Lookup[]{
                        Lookups.singleton(NbAndroidRootProjectImpl.this),
                        node.getLookup(), Lookups.singleton(new RootGoalsNavigatorHint()),
                        lookupModels
                    }));
}
 
Example #26
Source File: CodeAnalysis.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static void open(WarningDescription wd) {
    Node[] n = TopComponent.getRegistry().getActivatedNodes();
    final Lookup context = n.length > 0 ? n[0].getLookup():Lookup.EMPTY;
    RunAnalysis.showDialogAndRunAnalysis(
            new ProxyLookup(Utilities.actionsGlobalContext(), 
                    context), DialogState.from(wd));
}
 
Example #27
Source File: ActionProviderImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
private CustomAction(Project project, String name, ActionMapping mapping, Lookup context, boolean showUI) {
    super(name);
    this.mapping = mapping;
    this.showUI = showUI;
    this.context = new ProxyLookup(context, Lookups.singleton(this));
    this.project = project;
}
 
Example #28
Source File: BaseParserResult.java    From netbeans with Apache License 2.0 5 votes vote down vote up
BaseParserResult(
        Snapshot snapshot,
        boolean success,
        @NonNull final Lookup additionalLkp) {
    super(snapshot);
    errors = Collections.emptyList();
    this.success = success;
    embedded = isEmbedded(snapshot);
    final Lookup baseLkp = Lookups.fixed(this, modelContainer, documentationContainer);
    lookup = new ProxyLookup(baseLkp, additionalLkp);
}
 
Example #29
Source File: FeatureProjectFactory.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public FeatureDelegate(FileObject dir, FeatureNonProject feature) {
    this.dir = dir;
    this.hook = feature.new FeatureOpenHook();
    ic.add(UILookupMergerSupport.createProjectOpenHookMerger(hook));
    this.delegate = new ProxyLookup(
        Lookups.fixed(feature, this),
        LookupProviderSupport.createCompositeLookup(
            hooks, "../nonsence" // NOI18N
        )
    );
    this.support = new PropertyChangeSupport(this);
}
 
Example #30
Source File: UnitTestLibrariesNode.java    From netbeans with Apache License 2.0 5 votes vote down vote up
LibraryDependencyNode(final TestModuleDependency dep,
        String testType,
        final NbModuleProject project, final Node original) {
    super(original, null, new ProxyLookup(new Lookup[] {
        original.getLookup(),
        Lookups.fixed(new Object[] { dep, project, testType })
    }));
    this.dep = dep;
    this.testType = testType;
    this.project = project;
}