|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.examples.modules.minicomposer.registryutils; import org.netbeans.api.registry.*; import org.netbeans.spi.looks.DefaultLook; import org.netbeans.spi.looks.Look; import org.openide.util.Lookup; import org.openide.util.Mutex; import java.util.ArrayList; import java.util.Iterator; import java.util.List; /** * Look representing a context with some typed items in it. * The children are just the items. */ public class DefaultContextLook extends DefaultLook implements ContextListener { private final String title; private final Class type; public DefaultContextLook(String title, Class type) { super("DefaultContextLook"); this.type = type; this.title = title; } public String getDisplayName() { return title; } public void attachTo(Object o) { ((Context) o).addContextListener(this); } public void detachFrom(Object o) { ((Context) o).removeContextListener(this); } public String getDisplayName(Object o, Lookup l) { // XXX I18N? return "Choosing " + type.getName() + "'s"; } public boolean isLeaf(Object o, Lookup l) { return false; } public List getChildObjects(Object o, Lookup l) { List items = new ArrayList(((Context) o).getOrderedObjects()); Iterator it = items.iterator(); while (it.hasNext()) { if (acceptChild(it.next())) { it.remove(); } } return items; } protected final boolean acceptChild(Object o) { return !type.isInstance(o); } public void bindingChanged(BindingEvent evt) { final Context c = evt.getContext(); Mutex.EVENT.writeAccess(new Runnable() { public void run() { fireChange(c, Look.GET_CHILD_OBJECTS); } }); } public void subcontextChanged(SubcontextEvent evt) { // Ignore } public void attributeChanged(AttributeEvent evt) { // Ignore } } |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.