java.awt.event.HierarchyBoundsListener#org.openide.util.lookup.ProxyLookup源码实例Demo

下面列出了java.awt.event.HierarchyBoundsListener#org.openide.util.lookup.ProxyLookup 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: netbeans   文件: PackageRootNode.java
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");
}
 
源代码2 项目: netbeans   文件: SettingsContextProvider.java
@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);
}
 
源代码3 项目: netbeans   文件: ContextProvider.java
@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);
}
 
源代码4 项目: netbeans   文件: ContextProvider.java
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);
}
 
源代码5 项目: netbeans   文件: FileUtil.java
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;
}
 
源代码6 项目: netbeans   文件: TabbedController.java
@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()]));
    }
}
 
源代码7 项目: netbeans   文件: DOMNode.java
@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()]);
}
 
源代码8 项目: netbeans   文件: BasicCustomizer.java
@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);
    }
}
 
源代码9 项目: netbeans   文件: TestDataDirsNodeFactory.java
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);
    }
}
 
源代码10 项目: netbeans   文件: WebBrowserImpl.java
/**
 * 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);
    }
}
 
源代码11 项目: netbeans   文件: LayerDataObject.java
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)));
}
 
源代码12 项目: netbeans   文件: BootCPNodeFactory.java
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];
                }
    };

}
 
源代码13 项目: netbeans   文件: JavaEEServerModule.java
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;
}
 
源代码14 项目: netbeans   文件: TreeRootNode.java
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));
}
 
源代码15 项目: netbeans   文件: PaletteItemNode.java
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);
}
 
源代码16 项目: netbeans   文件: DocumentServices.java
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;
}
 
源代码17 项目: netbeans   文件: TreeRootNode.java
private TreeRootNode (Node originalNode, DataFolder folder, SourceGroup g, boolean reduced) {
    super(originalNode, reduced ? Children.create(new ReducedChildren(folder, new GroupDataFilter(g), g), true) : new PackageFilterChildren(originalNode),
        new ProxyLookup(
            originalNode.getLookup(),
            Lookups.singleton(new PathFinder(g, reduced))
            // no need for explicit search info
        ));
    this.g = g;
    g.addPropertyChangeListener(WeakListeners.propertyChange(this, g));
}
 
源代码18 项目: netbeans   文件: ContextProvider.java
@NonNull
private static Iterable<? extends ContextProvider> getImpls() {
    Lookup.Result<ContextProvider> res = impls.get();
    if (res == null) {
        final Lookup lkp = new ProxyLookup(
            Lookup.getDefault(),
            Lookups.singleton(new DefaultContextProvider()));
        res = lkp.lookupResult(ContextProvider.class);
        if (!impls.compareAndSet(null, res)) {
            res = impls.get();
        }
    }
    return res.allInstances();
}
 
源代码19 项目: netbeans   文件: PlatformNode.java
private PlatformNode(PlatformProvider pp, ClassPathSupport cs) {
    super (new PlatformContentChildren (cs), new ProxyLookup(new Lookup[]{
        Lookups.fixed(new PlatformEditable(pp), new JavadocProvider(pp),  new PathFinder()),
                new PlatformFolderLookup(new InstanceContent(), pp)
        }));
    this.pp = pp;
    this.pp.addChangeListener(this);
    setIconBaseWithExtension(PLATFORM_ICON);
}
 
源代码20 项目: netbeans   文件: ActionFilterNode.java
private static Lookup createLookup(final Node original, Object... toAdd) {
    final Lookup lookup = original.getLookup();
    final org.netbeans.spi.project.ui.PathFinder pathFinder =
            lookup.lookup(org.netbeans.spi.project.ui.PathFinder.class);
    final Lookup lkp = new ProxyLookup(
            Lookups.exclude(lookup, org.netbeans.spi.project.ui.PathFinder.class),
            Lookups.fixed (toAdd),
            Lookups.singleton(new PathFinder(pathFinder)));
    return lkp;
}
 
源代码21 项目: netbeans   文件: SafeDeleteUI.java
/**
 * Creates a new instance of SafeDeleteUI
 * @param selectedFiles An array of selected FileObjects that need to be 
 * safely deleted
 * @param handles  
 */
private SafeDeleteUI(FileObject[] selectedFiles, Collection<TreePathHandle> handles, boolean regulardelete) {
    this.elementsToDelete = selectedFiles;
    refactoring = new SafeDeleteRefactoring(new ProxyLookup(Lookups.fixed(elementsToDelete), Lookups.fixed(handles.toArray(new Object[handles.size()]))));
    refactoring.getContext().add(JavaRefactoringUtils.getClasspathInfoFor(selectedFiles));
    this.regulardelete = regulardelete;
}
 
源代码22 项目: netbeans   文件: RunToCursorActionProvider.java
private void debugProject(final Project p, LineBreakpoint newBreakpoint) {
    synchronized (projectBreakpoints) {
        projectBreakpoints.put(p, newBreakpoint);
    }
    ActionProgress progress = new ActionProgress() {

        @Override
        protected void started() {
        }

        @Override
        public void finished(boolean success) {
            LineBreakpoint lb;
            synchronized (projectBreakpoints) {
                lb = projectBreakpoints.remove(p);
            }
            if (lb != null) {
                removeBreakpoint(lb);
            }
            setEnabled (
                ActionsManager.ACTION_RUN_TO_CURSOR,
                shouldBeEnabled ()
            );
        }
    };
    p.getLookup ().lookup(ActionProvider.class).invokeAction (
            ActionProvider.COMMAND_DEBUG,
            new ProxyLookup(Lookups.fixed(progress), p.getLookup ())
        );
}
 
源代码23 项目: netbeans   文件: InspectAndTransformOpenerImpl.java
@Override
public void openIAT(final HintMetadata hm) {
    Node[] n = TopComponent.getRegistry().getActivatedNodes();
    final Lookup context = n.length > 0 ? n[0].getLookup():Lookup.EMPTY;
    org.netbeans.modules.java.hints.spiimpl.refactoring.Utilities.invokeAfterScanFinished(new Runnable() {
        @Override
        public void run() {
            InspectAndRefactorUI.openRefactoringUI(new ProxyLookup(context, Lookups.singleton(hm)));
        }
    }, Bundle.CTL_ApplyPatternAction());
}
 
源代码24 项目: netbeans   文件: ActionUtilsTest.java
private static Lookup context(Node[] sel) {
    Lookup[] delegates = new Lookup[sel.length + 1];
    for (int i = 0; i < sel.length; i++) {
        delegates[i] = sel[i].getLookup();
    }
    delegates[sel.length] = Lookups.fixed((Object[]) sel);
    return new ProxyLookup(delegates);
}
 
源代码25 项目: netbeans   文件: MockMimeLookup.java
/** You can call it, but it's probably not what you want. */
public @Override Lookup getLookup(MimePath mimePath) {
    synchronized (MAP) {
        List<String> paths = Collections.singletonList(mimePath.getPath());
        
        try {
            Method m = MimePath.class.getDeclaredMethod("getInheritedPaths", String.class, String.class); //NOI18N
            m.setAccessible(true);
            @SuppressWarnings("unchecked")
            List<String> ret = (List<String>) m.invoke(mimePath, null, null);
            paths = ret;
        } catch (Exception e) {
            throw new IllegalStateException("Can't call org.netbeans.api.editor.mimelookup.MimePath.getInheritedPaths method.", e); //NOI18N
        }

        List<Lookup> lookups = new ArrayList<Lookup>(paths.size());
        for(String path : paths) {
            MimePath mp = MimePath.parse(path);
            Lkp lookup = MAP.get(mp);
            if (lookup == null) {
                lookup = new Lkp();
                MAP.put(mp, lookup);
            }
            lookups.add(lookup);
        }
        
        return new ProxyLookup(lookups.toArray(new Lookup [lookups.size()]));
    }
}
 
源代码26 项目: netbeans   文件: DefaultEMLookup.java
/** Extracts activated nodes from a top component and
 * returns their lookups.
 */
public void updateLookups(Node[] arr) {
    if (arr == null) {
        arr = new Node[0];
    }

    Lookup[] lookups = new Lookup[arr.length];

    Map<Lookup, Lookup.Result> copy;

    synchronized (this) {
        if (attachedTo == null) {
            copy = Collections.<Lookup, Lookup.Result>emptyMap();
        } else {
            copy = new HashMap<Lookup, Lookup.Result>(attachedTo);
        }
    }

    for (int i = 0; i < arr.length; i++) {
        lookups[i] = arr[i].getLookup();

        if (copy != null) {
            // node arr[i] remains there, so do not remove it
            copy.remove(arr[i]);
        }
    }

    for (Iterator<Lookup.Result> it = copy.values().iterator(); it.hasNext();) {
        Lookup.Result res = it.next();
        res.removeLookupListener(listener);
    }

    synchronized (this) {
        attachedTo = null;
    }

    setLookups(new Lookup[] { new NoNodeLookup(new ProxyLookup(lookups), arr), Lookups.fixed((Object[])arr), actionMap, });
}
 
源代码27 项目: netbeans   文件: FileBasedFileSystem.java
public Lookup findExtrasFor(Set<FileObject> foSet) {
    List<Lookup> arr = new ArrayList<Lookup>();
    for (BaseAnnotationProvider ap : annotationProviders.allInstances()) {
        final Lookup lkp = ap.findExtrasFor(foSet);
        if (lkp != null) {
            arr.add(lkp);
        }
    }
    return new ProxyLookup(arr.toArray(new Lookup[arr.size()]));
}
 
源代码28 项目: netbeans   文件: NodeOp.java
/**
 * Computes a common popup menu for the specified nodes.
 * Provides only those actions supplied by all nodes in the list.
 * <p>Component action maps are not taken into consideration.
 * {@link Utilities#actionsToPopup(Action[], Component)} is a better choice
 * if you want to use actions such as "Paste" which look at action maps.
* @param nodes the nodes
* @return the menu for all nodes
*/
public static JPopupMenu findContextMenu(Node[] nodes) {
    Action[] arr = findActions(nodes);

    // prepare lookup representing all the selected nodes
    List<Lookup> allLookups = new ArrayList<Lookup>();

    for (Node n : nodes) {
        allLookups.add(n.getLookup());
    }

    Lookup lookup = new ProxyLookup(allLookups.toArray(new Lookup[allLookups.size()]));

    return Utilities.actionsToPopup(arr, lookup);
}
 
源代码29 项目: netbeans   文件: FilterNodeTest.java
public void testAdditionalLookupCloned() {
    Integer v1 = 42;
    Double v2 = Math.PI;

    // just create a base Node
    Node x = new AbstractNode(Children.LEAF, Lookups.singleton(v1));
    // create a copy of base with changed Lookup
    Node y = new FilterNode(x, null, new ProxyLookup(x.getLookup(), Lookups.singleton(v2)));
    // create another copy of the changed-Lookup-Node.
    Node z = y.cloneNode();

    // Integer object should be in all lookups
    Integer lookupIntX = x.getLookup().lookup(Integer.class);
    assertNotNull(lookupIntX);
    Integer lookupIntY = y.getLookup().lookup(Integer.class);
    assertNotNull(lookupIntY);
    Integer lookupIntZ = z.getLookup().lookup(Integer.class);
    assertNotNull(lookupIntZ);

    Double lookupDoubleX = x.getLookup().lookup(Double.class);
    assertNull("lookupDoubleX should be null, because Double is not in lookup of X", lookupDoubleX);

    Double lookupDoubleY = y.getLookup().lookup(Double.class);
    assertNotNull("lookupDoubleY should be NOT null, because Double is in lookup of Y", lookupDoubleY);

    Double lookupDoubleZ = z.getLookup().lookup(Double.class);
    assertNotNull("lookupDoubleZ should be NOT null, because Z is cloned from Y and Double is in lookup of Y",lookupDoubleZ);
}
 
源代码30 项目: netbeans   文件: Model.java
Lookup getLookup () {
    List<Lookup> lookups = new ArrayList<Lookup> ();
    Iterator<OptionsPanelController> it = categoryToController.values ().iterator ();
    while (it.hasNext ())
        lookups.add (it.next ().getLookup ());
    return new ProxyLookup 
        (lookups.toArray (new Lookup [lookups.size ()]));
}