|
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.modules.xml.core.actions; import java.util.Iterator; import org.openide.nodes.Node; import org.openide.util.HelpCtx; import org.openide.util.actions.CookieAction; import org.openide.util.RequestProcessor; import org.netbeans.modules.xml.core.cookies.UpdateDocumentCookie; import org.openide.util.Lookup; import org.openide.util.actions.ActionPerformer; /** * Reinitialize internal structures. User has strong feeling that he changed * external state that is not authomatically monitored by given data object. * */ public final class XMLUpdateDocumentAction extends CookieAction { /** generated Serialized Version UID */ private static final long serialVersionUID = -235822666875674523L; /* @return the mode of action. */ protected int mode() { return MODE_ALL; } /* Human presentable name of the action. This should be * presented as an item in a menu. * @return the name of the action */ public String getName () { return Util.THIS.getString ("PROP_UpdateDocument"); } protected Class[] cookieClasses () { return new Class[] { UpdateDocumentCookie.class }; } /* Help context where to find more about the action. * @return the help context for this action */ public HelpCtx getHelpCtx () { return new HelpCtx (XMLUpdateDocumentAction.class); } // is called from a ModuleActions thread protected void performAction (final Node[] activatedNodes) { Lookup lookup = Lookup.getDefault(); Lookup.Template template = new Lookup.Template(Performer.class); final Lookup.Result result = lookup.lookup(template); RequestProcessor.getDefault().postRequest(new Runnable() { public void run() { for (int i = 0; i < activatedNodes.length; i++) { UpdateDocumentCookie rc = (UpdateDocumentCookie)activatedNodes[i].getCookie (UpdateDocumentCookie.class); if (rc != null) { rc.updateDocumentRoot(); } //??? unfortunatelly there can be only one cookie per node // use lookup to emulate N-cookies - performers // delegate to all registered performers Iterator it = result.allInstances().iterator(); while (it.hasNext()) { Performer next = (Performer) it.next(); next.perform(activatedNodes[i]); } } } }); } protected boolean asynchronous() { return false; } /** * To be somehow exposed via API, now XML module specifics. * It is registered at module layer. All registered performes are invoked. */ public static interface Performer { /** * Update internal state after possible change of external resources * (flush caches etc.). */ void perform(Node node); } } |
... 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.