Index: core/test/unit/src/org/netbeans/core/LoaderPoolNodeTest.java =================================================================== RCS file: core/test/unit/src/org/netbeans/core/LoaderPoolNodeTest.java diff -N core/test/unit/src/org/netbeans/core/LoaderPoolNodeTest.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ core/test/unit/src/org/netbeans/core/LoaderPoolNodeTest.java 8 Nov 2004 08:23:51 -0000 @@ -0,0 +1,108 @@ +/* + * 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-2004 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.core; + +import java.io.*; +import java.util.*; +import org.openide.filesystems.*; +import org.openide.actions.*; +import org.openide.util.actions.SystemAction; + + +/** + * + * @author Jaroslav Tulach + */ +public class LoaderPoolNodeTest extends org.netbeans.junit.NbTestCase { + private OldStyleLoader oldL; + private NewStyleLoader newL; + + public LoaderPoolNodeTest (String testName) { + super (testName); + } + + protected void setUp () throws java.lang.Exception { + oldL = (OldStyleLoader)OldStyleLoader.getLoader (OldStyleLoader.class); + newL = (NewStyleLoader)NewStyleLoader.getLoader (NewStyleLoader.class); + LoaderPoolNode.doAdd (oldL, null); + LoaderPoolNode.doAdd (newL, null); + } + + protected void tearDown () throws java.lang.Exception { + LoaderPoolNode.remove (oldL); + LoaderPoolNode.remove (newL); + } + + public void testOldLoaderThatChangesActionsBecomesModified () throws Exception { + assertFalse ("Not modified at begining", LoaderPoolNode.isModified (oldL)); + Object actions = oldL.getActions (); + assertNotNull ("Some actions there", actions); + assertTrue ("Default actions called", oldL.defaultActionsCalled); + assertFalse ("Still not modified", LoaderPoolNode.isModified (oldL)); + + ArrayList list = new ArrayList (); + list.add (OpenAction.get (OpenAction.class)); + list.add (NewAction.get (NewAction.class)); + oldL.setActions ((SystemAction[])list.toArray (new SystemAction[0])); + + assertTrue ("Now it is modified", LoaderPoolNode.isModified (oldL)); + List l = Arrays.asList (oldL.getActions ()); + assertEquals ("Actions are the same", list, l); + } + + public void testNewLoaderThatChangesActionsBecomesModified () throws Exception { + assertFalse ("Not modified at begining", LoaderPoolNode.isModified (newL)); + Object actions = newL.getActions (); + assertNotNull ("Some actions there", actions); + assertTrue ("Default actions called", newL.defaultActionsCalled); + assertFalse ("Still not modified", LoaderPoolNode.isModified (newL)); + + ArrayList list = new ArrayList (); + list.add (OpenAction.get (OpenAction.class)); + list.add (NewAction.get (NewAction.class)); + newL.setActions ((SystemAction[])list.toArray (new SystemAction[0])); + + assertFalse ("Even if we changed actions, it is not modified", LoaderPoolNode.isModified (newL)); + List l = Arrays.asList (newL.getActions ()); + assertEquals ("But actions are changed", list, l); + } + + public static class OldStyleLoader extends org.openide.loaders.UniFileLoader { + boolean defaultActionsCalled; + + public OldStyleLoader () { + super (org.openide.loaders.MultiDataObject.class); + } + + protected org.openide.loaders.MultiDataObject createMultiObject (FileObject fo) throws IOException { + throw new IOException ("Not implemented"); + } + + protected SystemAction[] defaultActions () { + defaultActionsCalled = true; + SystemAction[] retValue; + + retValue = super.defaultActions(); + return retValue; + } + + + } + + public static final class NewStyleLoader extends OldStyleLoader { + protected String actionsContext () { + return "Loaders/IamTheNewBeggining"; + } + } +} Index: core/src/org/netbeans/core/LoaderPoolNode.java =================================================================== RCS file: /cvs/core/src/org/netbeans/core/LoaderPoolNode.java,v retrieving revision 1.76 diff -u -r1.76 LoaderPoolNode.java --- core/src/org/netbeans/core/LoaderPoolNode.java 20 Aug 2004 14:56:17 -0000 1.76 +++ core/src/org/netbeans/core/LoaderPoolNode.java 8 Nov 2004 08:23:52 -0000 @@ -144,8 +144,8 @@ /** Really adds the loader. */ - private static synchronized void doAdd (DataLoader l, ManifestSection.LoaderSection s) throws Exception { - if (err.isLoggable(ErrorManager.INFORMATIONAL)) { + static synchronized void doAdd (DataLoader l, ManifestSection.LoaderSection s) throws Exception { + if (err.isLoggable(ErrorManager.INFORMATIONAL) && s != null) { List before = s.getInstallBefore() == null ? null : Arrays.asList(s.getInstallBefore()); List after = s.getInstallAfter() == null ? null : Arrays.asList(s.getInstallAfter()); err.log("add: " + l + " repclass: " + l.getRepresentationClass().getName() + " before: " + before + " after: " + after); @@ -165,10 +165,12 @@ String cname = c.getName(); names2Loaders.put(cname, l); repNames2Loaders.put(l.getRepresentationClassName(), l); - String[] ib = s.getInstallBefore(); - if (ib != null) installBefores.put(cname, ib); - String[] ia = s.getInstallAfter(); - if (ia != null) installAfters.put(cname, ia); + if (s != null) { + String[] ib = s.getInstallBefore(); + if (ib != null) installBefores.put(cname, ib); + String[] ia = s.getInstallAfter(); + if (ia != null) installAfters.put(cname, ia); + } if (updatingBatch) { updatingBatchUsed = true; } else { @@ -279,6 +281,13 @@ myChildren.update (); } } + + /** Checks whether a loader is modified. E.g. whether the loader + * considers it to be modified and necessary to be saved. + */ + static synchronized boolean isModified (DataLoader l) { + return modifiedLoaders.contains (l); + } /** Stores all the objects into stream. * @param oos object output stream to write to @@ -298,7 +307,7 @@ while (it.hasNext ()) { DataLoader l = (DataLoader)it.next (); - if (!modifiedLoaders.contains(l)) { + if (!isModified (l)) { // #27190 - no real need to write this in detail. String c = l.getClass().getName(); if (err.isLoggable(ErrorManager.INFORMATIONAL)) err.log ("writing unmodified " + c); @@ -355,7 +364,7 @@ while (e.hasMoreElements ()) { DataLoader l = (DataLoader) e.nextElement (); if (loaders.contains (l)) continue; - if (!modifiedLoaders.contains(l)) { + if (!isModified (l)) { // #27190 again. No need to write anything String c = l.getClass().getName(); if (err.isLoggable(ErrorManager.INFORMATIONAL)) err.log ("skipping unmodified " + c); @@ -813,8 +822,12 @@ */ public void propertyChange (PropertyChangeEvent ev) { DataLoader l = (DataLoader)ev.getSource(); - modifiedLoaders.add(l); String prop = ev.getPropertyName (); + if (DataLoader.PROP_ACTIONS.equals (prop) && ev.getNewValue () == null) { + // skip this change as this means the loader is using new storage mechanism + return; + } + modifiedLoaders.add(l); if (err.isLoggable(ErrorManager.INFORMATIONAL)) err.log("Got change in " + l.getClass().getName() + "." + prop); if (DataLoader.PROP_ACTIONS.equals (prop) || DataLoader.PROP_DISPLAY_NAME.equals (prop)) return; // these are not important to the pool, i.e. to file recognition Index: core/ui/src/org/netbeans/core/ui/resources/layer.xml =================================================================== RCS file: /cvs/core/ui/src/org/netbeans/core/ui/resources/layer.xml,v retrieving revision 1.82 diff -u -r1.82 layer.xml --- core/ui/src/org/netbeans/core/ui/resources/layer.xml 19 Oct 2004 11:22:14 -0000 1.82 +++ core/ui/src/org/netbeans/core/ui/resources/layer.xml 8 Nov 2004 08:23:52 -0000 @@ -487,5 +487,67 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Index: java/project/manifest.mf =================================================================== RCS file: /cvs/java/project/manifest.mf,v retrieving revision 1.8 diff -u -r1.8 manifest.mf --- java/project/manifest.mf 14 Oct 2004 17:42:14 -0000 1.8 +++ java/project/manifest.mf 8 Nov 2004 08:23:52 -0000 @@ -1,6 +1,6 @@ Manifest-Version: 1.0 OpenIDE-Module: org.netbeans.modules.java.project/0 -OpenIDE-Module-Install: org/netbeans/modules/java/project/JavaProjectModule.class +no_install_OpenIDE-Module-Install: org/netbeans/modules/java/project/JavaProjectModule.class OpenIDE-Module-Layer: org/netbeans/modules/java/project/layer.xml OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/java/project/Bundle.properties OpenIDE-Module-Specification-Version: 1.1 Index: java/project/src/org/netbeans/modules/java/project/JavaProjectModule.java =================================================================== RCS file: /cvs/java/project/src/org/netbeans/modules/java/project/JavaProjectModule.java,v retrieving revision 1.4 diff -u -r1.4 JavaProjectModule.java --- java/project/src/org/netbeans/modules/java/project/JavaProjectModule.java 30 Sep 2004 11:14:37 -0000 1.4 +++ java/project/src/org/netbeans/modules/java/project/JavaProjectModule.java 8 Nov 2004 08:23:52 -0000 @@ -42,7 +42,7 @@ * @author Petr Hrebejk */ public class JavaProjectModule extends ModuleInstall { - + /* public void restored() { // Hack JavaDataLoader actions @@ -81,6 +81,7 @@ } } + */ public static class ActionWrapper extends CallableSystemAction implements ContextAwareAction, PropertyChangeListener { Index: java/project/src/org/netbeans/modules/java/project/layer.xml =================================================================== RCS file: /cvs/java/project/src/org/netbeans/modules/java/project/layer.xml,v retrieving revision 1.13 diff -u -r1.13 layer.xml --- java/project/src/org/netbeans/modules/java/project/layer.xml 20 Jun 2004 20:44:13 -0000 1.13 +++ java/project/src/org/netbeans/modules/java/project/layer.xml 8 Nov 2004 08:23:52 -0000 @@ -68,5 +68,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Index: java/src/org/netbeans/modules/java/JavaDataLoader.java =================================================================== RCS file: /cvs/java/src/org/netbeans/modules/java/JavaDataLoader.java,v retrieving revision 1.72 diff -u -r1.72 JavaDataLoader.java --- java/src/org/netbeans/modules/java/JavaDataLoader.java 7 Oct 2004 11:25:34 -0000 1.72 +++ java/src/org/netbeans/modules/java/JavaDataLoader.java 8 Nov 2004 08:23:52 -0000 @@ -75,6 +75,11 @@ super(recognizedObject); } + protected String actionsContext () { + return "Loaders/text/x-java/Actions/"; // NOI18N + } + + // XXX JST: Can be deleted? Replaced by actionsContext. private SystemAction[] createDefaultActions() { return new SystemAction[] { SystemAction.get(OpenAction.class), @@ -101,6 +106,7 @@ static SystemAction[] standardActions; + // XXX JST: Can be deleted? Replaced by actionsContext. protected SystemAction[] defaultActions() { if (standardActions != null) return standardActions; Index: java/src/org/netbeans/modules/java/resources/mf-layer.xml =================================================================== RCS file: /cvs/java/src/org/netbeans/modules/java/resources/mf-layer.xml,v retrieving revision 1.51 diff -u -r1.51 mf-layer.xml --- java/src/org/netbeans/modules/java/resources/mf-layer.xml 8 Sep 2004 17:09:09 -0000 1.51 +++ java/src/org/netbeans/modules/java/resources/mf-layer.xml 8 Nov 2004 08:23:52 -0000 @@ -150,6 +150,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Index: openide/loaders/src/org/openide/loaders/DataLdrActions.java =================================================================== RCS file: openide/loaders/src/org/openide/loaders/DataLdrActions.java diff -N openide/loaders/src/org/openide/loaders/DataLdrActions.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openide/loaders/src/org/openide/loaders/DataLdrActions.java 8 Nov 2004 08:23:52 -0000 @@ -0,0 +1,184 @@ +/* + * 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-2000 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.openide.loaders; + +import java.beans.*; +import java.io.*; +import java.util.*; + +import org.openide.ErrorManager; +import org.openide.cookies.InstanceCookie; +import org.openide.filesystems.*; +import org.openide.nodes.NodeOp; +import org.openide.util.Lookup; +import org.openide.util.NbBundle; +import org.openide.util.SharedClassObject; +import org.openide.util.Utilities; +import org.openide.util.actions.SystemAction; +import org.openide.util.io.SafeException; + +/** Manages actions read and write for a given loader. + * + * @author Jaroslav Tulach + */ +final class DataLdrActions extends FolderInstance { + /** Reference to know for what loader we work */ + private java.lang.ref.Reference ref; + /** last creating task */ + private org.openide.util.Task creation; + /** processor to use */ + private static org.openide.util.RequestProcessor RP = new org.openide.util.RequestProcessor ("Loader Actions"); + + public DataLdrActions (DataFolder f, DataLoader l) { + super (f); + + this.ref = new java.lang.ref.WeakReference (l); + } + + /** Asks the manager to store these actions to disk. Provided for + * backward compatibility. + */ + public synchronized void setActions (final SystemAction[] arr) { + class DoTheWork implements Runnable, FileSystem.AtomicAction { + private int state; + + /** The goal of this method is to make sure that all actions + * will really be stored on the disk. + */ + private void work () throws IOException { + DataObject[] now = folder.getChildren (); + HashMap nowToObj = new HashMap (); + LinkedList sepObjs = new LinkedList (); + for (int i = 0; i < now.length; i++) { + InstanceCookie ic = (InstanceCookie)now[i].getCookie (InstanceCookie.class); + if (ic != null) { + try { + Object instance = ic.instanceCreate (); + if (instance instanceof javax.swing.Action) { + nowToObj.put (instance, now[i]); + continue; + } + if (instance instanceof javax.swing.JSeparator) { + sepObjs.add (now[i]); + continue; + } + } catch (ClassNotFoundException ex) { + ErrorManager.getDefault ().notify (ex); + } + } + } + + ArrayList order = new ArrayList (); + + for (int i = 0; i < arr.length; i++) { + DataObject obj = (DataObject)nowToObj.remove (arr[i]); + if (obj == null) { + if (arr[i] != null) { + obj = InstanceDataObject.create (folder, null, arr[i].getClass ()); + } else { + if (!sepObjs.isEmpty ()) { + obj = (DataObject)sepObjs.removeFirst (); + } else { + obj = InstanceDataObject.create (folder, "Separator" + order.size (), javax.swing.JSeparator.class); + } + } + } + order.add (obj); + } + + // these were there but are not there anymore + for (Iterator it = nowToObj.values ().iterator (); it.hasNext (); ) { + DataObject obj = (DataObject)it.next (); + obj.delete (); + } + for (Iterator it = sepObjs.iterator (); it.hasNext (); ) { + DataObject obj = (DataObject)it.next (); + obj.delete (); + } + + folder.setOrder ((DataObject[])order.toArray (new DataObject[0])); + } + + public void run () { + try { + switch (state) { + case 0: + state = 1; + folder.getPrimaryFile ().getFileSystem ().runAtomicAction (this); + break; + case 1: + work (); + break; + } + } catch (IOException ex) { + ErrorManager.getDefault ().notify (ex); + } + } + } + + DoTheWork dtw = new DoTheWork (); + creation = RP.post (dtw); + } + + + /** Creates the actions and notifies the loader. + */ + protected Object createInstance (org.openide.cookies.InstanceCookie[] cookies) throws java.io.IOException, ClassNotFoundException { + ArrayList list = new ArrayList (); + for (int i = 0; i < cookies.length; i++) { + Class clazz = cookies[i].instanceClass (); + if (javax.swing.JSeparator.class.isAssignableFrom (clazz)) { + list.add (null); + continue; + } + + Object action = cookies[i].instanceCreate (); + if (action instanceof javax.swing.Action) { + list.add (action); + continue; + } + } + + DataLoader l = (DataLoader)ref.get (); + if (l != null) { + l.setSwingActions (list); + } + + return list.toArray (new javax.swing.Action[0]); + } + + /** Currently not recursive */ + protected org.openide.cookies.InstanceCookie acceptFolder (DataFolder df) { + return null; + } + + /** Creation in our own thread, so we can exclude storage modifications */ + protected org.openide.util.Task postCreationTask (Runnable run) { + return RP.post (run); + } + + public void waitFinished () { + org.openide.util.Task t; + synchronized (this) { + t = creation; + } + + if (t != null) { + t.waitFinished (); + } + + super.waitFinished (); + } + +} Index: openide/loaders/src/org/openide/loaders/DataLoader.java =================================================================== RCS file: /cvs/openide/loaders/src/org/openide/loaders/DataLoader.java,v retrieving revision 1.5 diff -u -r1.5 DataLoader.java --- openide/loaders/src/org/openide/loaders/DataLoader.java 13 Oct 2004 12:28:13 -0000 1.5 +++ openide/loaders/src/org/openide/loaders/DataLoader.java 8 Nov 2004 08:23:52 -0000 @@ -49,6 +49,8 @@ public static final String PROP_ACTIONS = "actions"; // NOI18N /** property name of list of default actions */ private static final String PROP_DEF_ACTIONS = "defaultActions"; // NOI18N + /** key to hold reference to out action manager */ + private static final Object ACTION_MANAGER = new Object (); /** representation class, not public property */ private static final Object PROP_REPRESENTATION_CLASS = new Object (); /** representation class name, not public property */ @@ -133,17 +135,69 @@ * actions */ public final SystemAction[] getActions () { - SystemAction[] actions = (SystemAction[])getProperty (PROP_ACTIONS); - if ( actions == null ) { - actions = (SystemAction[])getProperty (PROP_DEF_ACTIONS); + javax.swing.Action[] arr = getSwingActions (); + + ArrayList list = new ArrayList (); + for (int i = 0; i < arr.length; i++) { + if (arr[i] instanceof SystemAction || arr[i] == null) { + list.add (arr[i]); + } + } + + return (SystemAction[])list.toArray (new SystemAction[0]); + } + + /** Swing actions getter, used from DataNode */ + final javax.swing.Action[] getSwingActions () { + DataLdrActions mgr = findManager (); + if (mgr != null) { + Object actions; + try { + actions = mgr.instanceCreate (); + } catch (IOException ex) { + ErrorManager.getDefault ().notify (ex); + actions = null; + } catch (ClassNotFoundException ex) { + ErrorManager.getDefault ().notify (ex); + actions = null; + } + if (actions == null) { + return new javax.swing.Action[0]; + } + + return (javax.swing.Action[])actions; + } else { + // old behaviour, that stores actions in properties + SystemAction[] actions = (SystemAction[])getProperty (PROP_ACTIONS); if ( actions == null ) { - actions = defaultActions(); - putProperty (PROP_DEF_ACTIONS, actions, false); - } + actions = (SystemAction[])getProperty (PROP_DEF_ACTIONS); + if ( actions == null ) { + actions = defaultActions(); + putProperty (PROP_DEF_ACTIONS, actions, false); + } + } + return actions; } - return actions; } - + + + /** Identifies the name of context in layer files where the + * loader wishes to store its own actions and also read them. + * In principle any {@link javax.swing.Action} instance can be registered + * in the context and it will be visible in the default DataNode + * for data object created by this loader. Only SystemAction can however + * be manipulated from DataLoader getActions/setActions methods. + *

+ * The default implementation returns null to indicate that no + * layer reading should be used + * + * @return the string name of the context on layer files to read/write acitons to + * @since JST-PENDING + */ + protected String actionsContext () { + return null; + } + /** Get default actions. * @return array of default system actions or null if this loader * does not have any actions. @@ -160,6 +214,57 @@ return actions; } + /** Actions manager. + */ + private final DataLdrActions findManager () { + Object manager = getProperty (ACTION_MANAGER); + if (manager instanceof Class) { + return null; + } + DataLdrActions mgr = (DataLdrActions)manager; + boolean newlyCreated = false; + if (mgr == null) { + String context = actionsContext (); + if (context == null) { + // mark we have no context + putProperty (ACTION_MANAGER, getClass ()); + return null; + } + + FileObject fo = Repository.getDefault ().getDefaultFileSystem ().findResource (context); + if (fo == null) { + fo = Repository.getDefault ().getDefaultFileSystem ().getRoot (); + try { + fo = FileUtil.createFolder (fo, context); + + } catch (IOException ex) { + ErrorManager.getDefault ().notify (ex); + } + newlyCreated = true; + } + + mgr = new DataLdrActions (DataFolder.findFolder (fo), this); + if (newlyCreated) { + SystemAction[] arr = defaultActions (); + if (arr != null) { + mgr.setActions (arr); + } + } + putProperty (ACTION_MANAGER, mgr); + } + return mgr; + } + + /** Allows the friend code (package and tests) to wait while actions + * are synchronized with the state of disk. + */ + final void waitForActions () { + DataLdrActions mgr = findManager (); + if (mgr != null) { + mgr.waitFinished (); + } + } + /** Set actions. *

Note that this method is public, not protected, so it is possible for anyone * to modify the loader's popup actions externally (after finding the loader @@ -172,7 +277,19 @@ * @see #getActions */ public final void setActions (SystemAction[] actions) { - putProperty (PROP_ACTIONS, actions, true); + DataLdrActions mgr = findManager (); + if (mgr != null) { + mgr.setActions (actions); + } else { + putProperty (PROP_ACTIONS, actions, true); + } + } + + /** Assigns this loader new array of swing actions. + * @param arr List + */ + final void setSwingActions (List/**/ arr) { + firePropertyChange (PROP_ACTIONS, null, null); } /** Get the current display name of this loader. @@ -345,10 +462,14 @@ } try { + ClassLoader loader = (ClassLoader)Lookup.getDefault().lookup(ClassLoader.class); + if (loader == null) { + loader = getClass ().getClassLoader (); + } Class c = Class.forName ( Utilities.translate((String)arr[i]), false, // why resolve?? --jglick - (ClassLoader)Lookup.getDefault().lookup(ClassLoader.class) + loader ); SystemAction ac = SystemAction.get (c); Index: openide/loaders/src/org/openide/loaders/DataLoaderPool.java =================================================================== RCS file: /cvs/openide/loaders/src/org/openide/loaders/DataLoaderPool.java,v retrieving revision 1.15 diff -u -r1.15 DataLoaderPool.java --- openide/loaders/src/org/openide/loaders/DataLoaderPool.java 20 Oct 2004 08:38:28 -0000 1.15 +++ openide/loaders/src/org/openide/loaders/DataLoaderPool.java 8 Nov 2004 08:23:52 -0000 @@ -897,28 +897,8 @@ // super (DataFolder.class); } - /** Get default actions. - * @return array of default system actions or null if this loader does not have any - * actions - */ - protected SystemAction[] defaultActions () { - return new SystemAction[] { - SystemAction.get (org.openide.actions.NewTemplateAction.class), - null, - // SystemAction.get (org.openide.actions.OpenLocalExplorerAction.class), - SystemAction.get (org.openide.actions.FileSystemAction.class), - SystemAction.get (org.openide.actions.FindAction.class), - null, - SystemAction.get (org.openide.actions.CutAction.class), - SystemAction.get (org.openide.actions.CopyAction.class), - SystemAction.get (org.openide.actions.PasteAction.class), - null, - SystemAction.get (org.openide.actions.DeleteAction.class), - SystemAction.get (org.openide.actions.RenameAction.class), - null, - SystemAction.get (org.openide.actions.ToolsAction.class), - SystemAction.get (org.openide.actions.PropertiesAction.class) - }; + protected String actionsContext () { + return "Loaders/folder/any/Actions"; // NOI18N } /** Get the default display name of this loader. Index: openide/loaders/src/org/openide/loaders/DataNode.java =================================================================== RCS file: /cvs/openide/loaders/src/org/openide/loaders/DataNode.java,v retrieving revision 1.16 diff -u -r1.16 DataNode.java --- openide/loaders/src/org/openide/loaders/DataNode.java 6 Oct 2004 13:22:57 -0000 1.16 +++ openide/loaders/src/org/openide/loaders/DataNode.java 8 Nov 2004 08:23:52 -0000 @@ -302,6 +302,22 @@ * @see DataLoader#getActions * @return array of actions or null */ + public Action[] getActions (boolean context) { + if (systemActions == null) { + systemActions = createActions (); + } + + if (systemActions != null) { + return systemActions; + } + + return obj.getLoader ().getSwingActions (); + } + + /** Get actions for this data object. + * @deprecated Use getActions(boolean) + * @return array of actions or null + */ public SystemAction[] getActions () { if (systemActions == null) { systemActions = createActions (); @@ -314,6 +330,7 @@ return obj.getLoader ().getActions (); } + /** Get default action. In the current implementation the *null is returned in case the underlying data * object is a template. The templates should not have any default Index: openide/test/unit/src/org/openide/loaders/DataLoaderGetActionsCompatibilityTest.java =================================================================== RCS file: openide/test/unit/src/org/openide/loaders/DataLoaderGetActionsCompatibilityTest.java diff -N openide/test/unit/src/org/openide/loaders/DataLoaderGetActionsCompatibilityTest.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openide/test/unit/src/org/openide/loaders/DataLoaderGetActionsCompatibilityTest.java 8 Nov 2004 08:23:52 -0000 @@ -0,0 +1,260 @@ +/* + * 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-2001 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.openide.loaders; + +import junit.textui.TestRunner; + +import org.openide.filesystems.*; +import org.openide.util.Lookup; +import java.io.IOException; +import java.util.*; +import org.netbeans.junit.*; +import java.beans.PropertyChangeListener; +import javax.swing.Action; +import org.openide.util.io.NbMarshalledObject; + +/** Check how the default behaviour of DataLoader without overriden + * actionsContext works. + * + * @author Jaroslav Tulach + */ +public class DataLoaderGetActionsCompatibilityTest extends NbTestCase { + /** sample data object */ + private DataObject obj; + /** its node */ + private org.openide.nodes.Node node; + /** monitor sfs */ + private PCL sfs; + + public DataLoaderGetActionsCompatibilityTest (String name) { + super(name); + } + + public static void main(String[] args) { + if (args.length == 1) { + TestRunner.run (new DataLoaderGetActionsCompatibilityTest (args[0])); + } else { + TestRunner.run(new NbTestSuite(DataLoaderGetActionsCompatibilityTest.class)); + } + } + + /** + * Sets up the testing environment by creating testing folders + * on the system file system. + */ + protected void setUp () throws Exception { + System.setProperty ("org.openide.util.Lookup", "org.openide.loaders.DataLoaderGetActionsCompatibilityTest$Lkp"); + assertEquals ("Our lookup is installed", Lookup.getDefault ().getClass (), Lkp.class); + + MyDL loader = (MyDL)MyDL.getLoader (MyDL.class); + + FileSystem dfs = Repository.getDefault().getDefaultFileSystem(); + dfs.refresh (true); + + FileObject fo = FileUtil.createData (dfs.getRoot (), "a.txt"); + obj = DataObject.find (fo); + + assertEquals ("The correct loader", loader, obj.getLoader ()); + + node = obj.getNodeDelegate (); + + sfs = new PCL (); + dfs.addFileChangeListener (sfs); + } + + /** + * Deletes the folders created in method setUp(). + */ + protected void tearDown() throws Exception { + obj.getLoader ().setActions (new org.openide.util.actions.SystemAction[0]); + + int l = node.getActions (false).length; + if (l != 0) { + fail ("Not empty actions at the end!!!"); + } + Repository.getDefault ().getDefaultFileSystem ().removeFileChangeListener (sfs); + + // no suspicious activity on getDefaultFileSystem + sfs.assertEvent (0, null); + } + + public void testDefaultActionContextReturnsNull () { + assertNull (obj.getLoader ().actionsContext ()); + } + + public void testDefaultActionsUsedWhenCreatedForTheFirstTime () throws Exception { + SndDL loader = (SndDL)SndDL.getLoader (SndDL.class); + + org.openide.util.actions.SystemAction[] arr = loader.getActions (); + + assertEquals ( + "Arrays of actions are the same", + java.util.Arrays.asList (loader.defaultActions ()), + java.util.Arrays.asList (arr) + ); + } + + /** Test to check that the deserialization of actions works as expected. + */ + public void testNoDeserializationOfActions () throws Exception { + assertEquals("No actions at the start", 0, node.getActions(false).length); + + PCL pcl = new PCL (); + obj.getLoader ().addPropertyChangeListener (pcl); + + obj.getLoader ().setActions (new org.openide.util.actions.SystemAction[] { + org.openide.util.actions.SystemAction.get (org.openide.actions.PropertiesAction.class) + }); + + pcl.assertEvent (1, "actions"); + + Action [] res = node.getActions(false); + assertEquals("There should be exactly one action.", 1, res.length); + + NbMarshalledObject m = new NbMarshalledObject (obj.getLoader ()); + + obj.getLoader ().setActions (new org.openide.util.actions.SystemAction[0]); + + pcl.assertEvent (2, "actions"); + assertEquals("No actions after setting empty array", 0, node.getActions(false).length); + + assertEquals ("Loader deserialized", obj.getLoader (), m.get ()); + res = node.getActions(false); + assertEquals("One action", 1, res.length); + assertEquals ( + "and that is the property action", + org.openide.util.actions.SystemAction.get (org.openide.actions.PropertiesAction.class), + res[0] + ); + + obj.getLoader ().removePropertyChangeListener (pcl); + } + + /** Loader that does not override the actionsContext. + */ + private static class MyDL extends UniFileLoader { + public MyDL () { + super ("org.openide.loaders.DataObject"); + getExtensions ().addExtension ("txt"); + } + + protected org.openide.loaders.MultiDataObject createMultiObject (FileObject primaryFile) throws org.openide.loaders.DataObjectExistsException, IOException { + + + + return new MultiDataObject (primaryFile, this); + } + + protected org.openide.util.actions.SystemAction[] defaultActions () { + return new org.openide.util.actions.SystemAction[0]; + } + + } // end of MyDL + + // + // Our fake lookup + // + public static final class Lkp extends org.openide.util.lookup.AbstractLookup { + public Lkp () throws Exception { + this (new org.openide.util.lookup.InstanceContent ()); + } + + private Lkp (org.openide.util.lookup.InstanceContent ic) throws Exception { + super (ic); + + TestUtilHid.destroyLocalFileSystem (Lkp.class.getName ()); + ic.add (new Repository (TestUtilHid.createLocalFileSystem (Lkp.class.getName (), new String[0]))); + ic.add (new Pool ()); +// ic.add (new EM ()); + } + } + + + private static final class Pool extends DataLoaderPool { + + protected java.util.Enumeration loaders () { + return org.openide.util.Enumerations.singleton ( + DataLoader.getLoader(MyDL.class) + ); + } + + } // end of Pool + + private final class PCL implements org.openide.filesystems.FileChangeListener, java.beans.PropertyChangeListener { + int cnt; + String name; + + public void propertyChange (java.beans.PropertyChangeEvent ev) { + name = ev.getPropertyName(); + cnt++; + } + + public void assertEvent (int cnt, String name) { + obj.getLoader ().waitForActions (); + + if (cnt != this.cnt) { + fail ("Excepted more changes then we got: expected: " + cnt + " we got: " + this.cnt + " with name: " + this.name); + } + } + + public void fileAttributeChanged(org.openide.filesystems.FileAttributeEvent fe) { + cnt++; + name = "fileAttributeChanged"; + } + + public void fileChanged(org.openide.filesystems.FileEvent fe) { + cnt++; + name = "fileChanged"; + } + + public void fileDataCreated(org.openide.filesystems.FileEvent fe) { + cnt++; + name = "fileDataCreated"; + } + + public void fileDeleted(org.openide.filesystems.FileEvent fe) { + cnt++; + name = "fileDeleted"; + } + + public void fileFolderCreated(org.openide.filesystems.FileEvent fe) { + cnt++; + name = "fileFolderCreated"; + } + + public void fileRenamed(org.openide.filesystems.FileRenameEvent fe) { + cnt++; + name = "fileRenamed"; + } + } // end of PCL + + public static final class SndDL extends MyDL { + public SndDL () { + getExtensions ().addExtension ("bla"); + } + + protected org.openide.util.actions.SystemAction[] defaultActions () { + return new org.openide.util.actions.SystemAction[] { + org.openide.util.actions.SystemAction.get (org.openide.actions.CutAction.class), + null, + org.openide.util.actions.SystemAction.get (org.openide.actions.CopyAction.class), + null, + org.openide.util.actions.SystemAction.get (org.openide.actions.DeleteAction.class), + + }; + } + + } + +} Index: openide/test/unit/src/org/openide/loaders/DataLoaderGetActionsTest.java =================================================================== RCS file: openide/test/unit/src/org/openide/loaders/DataLoaderGetActionsTest.java diff -N openide/test/unit/src/org/openide/loaders/DataLoaderGetActionsTest.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openide/test/unit/src/org/openide/loaders/DataLoaderGetActionsTest.java 8 Nov 2004 08:23:52 -0000 @@ -0,0 +1,347 @@ +/* + * 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-2001 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.openide.loaders; + +import junit.textui.TestRunner; + +import org.openide.filesystems.*; +import org.openide.util.Lookup; +import java.io.IOException; +import java.util.*; +import org.netbeans.junit.*; +import java.beans.PropertyChangeListener; +import javax.swing.Action; +import org.openide.util.io.NbMarshalledObject; + +/** Tests the proposed behaviour of DataLoader.getActions that is going + * to read its values from layer. + * + * @author Jaroslav Tulach (taken from openidex/enode by David Strupl) + */ +public class DataLoaderGetActionsTest extends NbTestCase { + /** root folder FileObject */ + private FileObject root; + /** sample data object */ + private DataObject obj; + /** its node */ + private org.openide.nodes.Node node; + + public DataLoaderGetActionsTest (String name) { + super(name); + } + + public static void main(String[] args) { + if (args.length == 1) { + TestRunner.run (new DataLoaderGetActionsTest (args[0])); + } else { + TestRunner.run(new NbTestSuite(DataLoaderGetActionsTest.class)); + } + } + + /** + * Sets up the testing environment by creating testing folders + * on the system file system. + */ + protected void setUp () throws Exception { + System.setProperty ("org.openide.util.Lookup", "org.openide.loaders.DataLoaderGetActionsTest$Lkp"); + assertEquals ("Our lookup is installed", Lookup.getDefault ().getClass (), Lkp.class); + + MyDL loader = (MyDL)MyDL.getLoader (MyDL.class); + + FileSystem dfs = Repository.getDefault().getDefaultFileSystem(); + dfs.refresh (true); + root = FileUtil.createFolder (dfs.getRoot (), loader.actionsContext ()); + + + FileObject fo = FileUtil.createData (dfs.getRoot (), "a.txt"); + obj = DataObject.find (fo); + + assertEquals ("The correct loader", loader, obj.getLoader ()); + + node = obj.getNodeDelegate (); + } + + /** + * Deletes the folders created in method setUp(). + */ + protected void tearDown() throws Exception { + FileObject[] arr = root.getChildren (); + for (int i = 0; i < arr.length; i++) { + arr[i].delete(); + } + int l = node.getActions (false).length; + if (l != 0) { + System.err.println("Not empty actions at the end!!!"); + } + } + + /** + * This test tests the presence of declarative actions from + * system file system without the hierarchical flag set (the ExtensibleNode + * instance is created with constructor ExtensibleNode("test", false). + * The tests performs following steps: + *

  1. Create an instance of ExtensibleNode with folder set to "test" + *
  2. No actions should be returned by getActions since the "test" folder + * is not there + *
  3. Create one action in the testing folder + *
  4. The action should be visible in the result of getActions + *
  5. After deleting the action from the folder the action should + * not be returned from getActions(). + *
+ */ + public void testCreateAndDeleteAction() throws Exception { + assertEquals("No actions at the start", 0, node.getActions(false).length); + FileObject test = root; + + PCL pcl = new PCL (); + obj.getLoader ().addPropertyChangeListener (pcl); + + FileObject a1 = test.createData("org-openide-actions-PropertiesAction.instance"); + + pcl.assertEvent (1, "actions"); + + Action [] res = node.getActions(false); + assertEquals("There should be exactly one action.", 1, res.length); + a1.delete(); + + pcl.assertEvent (2, "actions"); + assertEquals("No actions after deleting", 0, node.getActions(false).length); + + obj.getLoader ().removePropertyChangeListener (pcl); + } + + /** + * An attempt to create a simple stress test. Just calls + * the testCreateAndDeleteAction 100 times. + */ + public void testRepetitiveDeleting() throws Exception { + for (int i = 0; i < 10; i++) { + testCreateAndDeleteAction(); + } + } + + /** + * This test should test behaviour of the getActions method when + * there is some alien object specified in the configuration folder. + * The testing object is of type Integer (instead of javax.swing.Action). + */ + public void testWrongActionObjectInConfig() throws Exception { + assertEquals("No actions at the start", 0, node.getActions(false).length); + FileObject test = root; + FileObject a1 = test.createData("java-lang-String.instance"); + Action [] res = node.getActions(false); + assertEquals("There should be zero actions.", 0, res.length); + } + + /** + * This test checks whether the JSeparator added from the configuration + * file is reflected in the resulting popup. + * The tests performs following steps: + *
  1. Create an instance of ExtensibleNode with folder set to "test" + *
  2. No actions should be returned by getActions since the "test" folder + * is not there + *
  3. Create two actions in the testing folder separated by JSeparator + *
  4. getActions should return 3 elements - null element for the separator + *
  5. Popup is created from the actions array - the null element + * should be replaced by a JSeparator again + *
+ */ + public void testAddingSeparators() throws Exception { + org.openide.nodes.Node en1 = node; + assertEquals("No actions at the start", 0, en1.getActions(false).length); + FileObject test = root; + FileObject a1 = test.createData("1[org-openide-actions-PropertiesAction].instance"); + FileObject sep = test.createData("2[javax-swing-JSeparator].instance"); + FileObject a2 = test.createData("3[org-openide-actions-CutAction].instance"); + javax.swing.Action[] actions = en1.getActions(false); + assertEquals("Actions array should contain 3 elements", 3, actions.length); + assertNull("separator should create null element in the array", actions[1]); + javax.swing.JPopupMenu jp = org.openide.util.Utilities.actionsToPopup(actions, org.openide.util.lookup.Lookups.singleton(en1)); + assertEquals("Popup should contain 3 components", 3, jp.getComponentCount()); + assertTrue("Separator should be second", jp.getComponent(1) instanceof javax.swing.JSeparator); + } + + /** Test to see whether a compatibility behaviour is still kept. E.g. + * if one adds actions using DataLoader.setActions they really will be + * there. + */ + public void testCompatibilityIsPropagatedToDisk () throws Exception { + assertEquals("No actions at the start", 0, node.getActions(false).length); + FileObject test = root; + + PCL pcl = new PCL (); + obj.getLoader ().addPropertyChangeListener (pcl); + + obj.getLoader ().setActions (new org.openide.util.actions.SystemAction[] { + org.openide.util.actions.SystemAction.get (org.openide.actions.PropertiesAction.class) + }); + + pcl.assertEvent (1, "actions"); + + Action [] res = node.getActions(false); + assertEquals("There should be exactly one action.", 1, res.length); + assertEquals("One file created", 1, test.getChildren ().length); + + obj.getLoader ().setActions (new org.openide.util.actions.SystemAction[0]); + + pcl.assertEvent (2, "actions"); + assertEquals("No actions after deleting", 0, node.getActions(false).length); + + assertEquals("file disappeared", 0, test.getChildren ().length); + obj.getLoader ().removePropertyChangeListener (pcl); + } + + /** Test to check that the deserialization of actions is completely ignored. + */ + public void testNoDeserializationOfActions () throws Exception { + assertEquals("No actions at the start", 0, node.getActions(false).length); + FileObject test = root; + + PCL pcl = new PCL (); + obj.getLoader ().addPropertyChangeListener (pcl); + + obj.getLoader ().setActions (new org.openide.util.actions.SystemAction[] { + org.openide.util.actions.SystemAction.get (org.openide.actions.PropertiesAction.class) + }); + + pcl.assertEvent (1, "actions"); + + Action [] res = node.getActions(false); + assertEquals("There should be exactly one action.", 1, res.length); + assertEquals("One file created", 1, test.getChildren ().length); + + NbMarshalledObject m = new NbMarshalledObject (obj.getLoader ()); + + obj.getLoader ().setActions (new org.openide.util.actions.SystemAction[0]); + + pcl.assertEvent (2, "actions"); + assertEquals("No actions after deleting", 0, node.getActions(false).length); + + assertEquals("file disappeared", 0, test.getChildren ().length); + + assertEquals ("Loader deserialized", obj.getLoader (), m.get ()); + assertEquals("Still no actions", 0, node.getActions(false).length); + + obj.getLoader ().removePropertyChangeListener (pcl); + } + + public void testDefaultActionsUsedWhenCreatedForTheFirstTime () throws Exception { + SndDL loader = (SndDL)SndDL.getLoader (SndDL.class); + + org.openide.util.actions.SystemAction[] arr = loader.getActions (); + + assertEquals ( + "Arrays of actions are the same", + java.util.Arrays.asList (loader.defaultActions ()), + java.util.Arrays.asList (arr) + ); + } + + private static class MyDL extends UniFileLoader { + public MyDL () { + super ("org.openide.loaders.DataObject"); + getExtensions ().addExtension ("txt"); + } + + /** Returns the name of the folder to read the actions from + */ + protected String actionsContext () { + return "test"; + } + + protected org.openide.loaders.MultiDataObject createMultiObject (FileObject primaryFile) throws org.openide.loaders.DataObjectExistsException, IOException { + + + + return new MultiDataObject (primaryFile, this); + } + + protected org.openide.util.actions.SystemAction[] defaultActions () { + return new org.openide.util.actions.SystemAction[0]; + } + + } // end of MyDL + + // + // Our fake lookup + // + public static final class Lkp extends org.openide.util.lookup.AbstractLookup { + public Lkp () throws Exception { + this (new org.openide.util.lookup.InstanceContent ()); + } + + private Lkp (org.openide.util.lookup.InstanceContent ic) throws Exception { + super (ic); + + TestUtilHid.destroyLocalFileSystem (Lkp.class.getName ()); + ic.add (new Repository (TestUtilHid.createLocalFileSystem (Lkp.class.getName (), new String[0]))); + ic.add (new Pool ()); +// ic.add (new EM ()); + } + } + + + private static final class Pool extends DataLoaderPool { + + protected java.util.Enumeration loaders () { + return new org.openide.util.enum.SingletonEnumeration ( + DataLoader.getLoader(MyDL.class) + ); + } + + } // end of Pool + + private final class PCL + implements java.beans.PropertyChangeListener { + int cnt; + String name; + + public void propertyChange (java.beans.PropertyChangeEvent ev) { + name = ev.getPropertyName(); + cnt++; + } + + public void assertEvent (int cnt, String name) { + obj.getLoader ().waitForActions (); + + if (cnt > this.cnt) { + fail ("Excepted more changes then we got: expected: " + cnt + " we got: " + this.cnt); + } + assertEquals ("same name", name, this.name); + } + } // end of PCL + + public static final class SndDL extends MyDL { + public SndDL () { + getExtensions ().addExtension ("bla"); + } + + protected org.openide.util.actions.SystemAction[] defaultActions () { + return new org.openide.util.actions.SystemAction[] { + org.openide.util.actions.SystemAction.get (org.openide.actions.CutAction.class), + null, + org.openide.util.actions.SystemAction.get (org.openide.actions.CopyAction.class), + null, + org.openide.util.actions.SystemAction.get (org.openide.actions.DeleteAction.class), + + }; + } + + protected String actionsContext () { + return "2ndtestdir"; + } + + } + +} Index: openide/src/org/openide/explorer/propertysheet/PropertySheet.java =================================================================== RCS file: /cvs/openide/src/org/openide/explorer/propertysheet/PropertySheet.java,v retrieving revision 1.165 diff -u -r1.165 PropertySheet.java --- openide/src/org/openide/explorer/propertysheet/PropertySheet.java 16 Aug 2004 12:59:47 -0000 1.165 +++ openide/src/org/openide/explorer/propertysheet/PropertySheet.java 8 Nov 2004 08:23:52 -0000 @@ -1016,35 +1016,39 @@ private final class PCL implements PropertyChangeListener { /** Receives property change events directed to PropertyChangeListeners, * not NodeListeners */ - public void propertyChange(PropertyChangeEvent evt) { - String nm = evt.getPropertyName(); - if (Node.PROP_COOKIE.equals(nm) || - //weed out frequently abused property changes - Node.PROP_ICON.equals(nm) || - Node.PROP_PARENT_NODE.equals(nm) || - Node.PROP_OPENED_ICON.equals(nm) || - Node.PROP_LEAF.equals(nm)) { - ErrorManager.getDefault().log (ErrorManager.WARNING, - "Recived bogus property change " + nm + " from " + - evt.getSource() + ". This should ony be fired to" + - "NodeListeners, not general property change listeners"); //NOI18N - } else if (isDescriptionVisible() && ( - Node.PROP_DISPLAY_NAME.equals(nm) || - Node.PROP_SHORT_DESCRIPTION.equals(nm))) { - Node n = (Node) evt.getSource(); - /* - fallbackTitle = n.getDisplayName(); - fallbackDescription = n.getShortDescription(); - if (infoPanel != null) { - table.fireChange(); - infoPanel.getBottomComponent().repaint(); + public void propertyChange(final PropertyChangeEvent evt) { + javax.swing.SwingUtilities.invokeLater (new Runnable () { + public void run () { + String nm = evt.getPropertyName(); + if (Node.PROP_COOKIE.equals(nm) || + //weed out frequently abused property changes + Node.PROP_ICON.equals(nm) || + Node.PROP_PARENT_NODE.equals(nm) || + Node.PROP_OPENED_ICON.equals(nm) || + Node.PROP_LEAF.equals(nm)) { + ErrorManager.getDefault().log (ErrorManager.WARNING, + "Recived bogus property change " + nm + " from " + + evt.getSource() + ". This should ony be fired to" + + "NodeListeners, not general property change listeners"); //NOI18N + } else if (isDescriptionVisible() && ( + Node.PROP_DISPLAY_NAME.equals(nm) || + Node.PROP_SHORT_DESCRIPTION.equals(nm))) { + Node n = (Node) evt.getSource(); + /* + fallbackTitle = n.getDisplayName(); + fallbackDescription = n.getShortDescription(); + if (infoPanel != null) { + table.fireChange(); + infoPanel.getBottomComponent().repaint(); + } + */ + } else if (nm == null) { + setCurrentNode(currNode); + } else { + table.repaintProperty(nm); + } } - */ - } else if (nm == null) { - setCurrentNode(currNode); - } else { - table.repaintProperty(nm); - } + }); } } } Index: openide/test/unit/src/org/openide/options/SystemOptionTest.java =================================================================== RCS file: /cvs/openide/test/unit/src/org/openide/options/SystemOptionTest.java,v retrieving revision 1.4 diff -u -r1.4 SystemOptionTest.java --- openide/test/unit/src/org/openide/options/SystemOptionTest.java 8 Sep 2004 11:37:49 -0000 1.4 +++ openide/test/unit/src/org/openide/options/SystemOptionTest.java 8 Nov 2004 08:23:52 -0000 @@ -155,6 +155,24 @@ } + public void testTheProblemWithI18NOptions () throws Exception { + I18NLikeOption s = (I18NLikeOption)I18NLikeOption.findObject (I18NLikeOption.class, true); + + assertFalse ("Not set by default", s.isAdvancedWizard ()); + s.setAdvancedWizard (true); + assertTrue ("Changes to true", s.isAdvancedWizard ()); + s.reset (); + + assertFalse ("Is cleared", s.isAdvancedWizard ()); + + s.setAdvancedWizard (true); + assertTrue ("yes again", s.isAdvancedWizard ()); + s.setAdvancedWizard (false); + assertFalse ("no again", s.isAdvancedWizard ()); + s.reset (); + assertFalse ("still no", s.isAdvancedWizard ()); + } + // XXX test that serialization works and matches deserialization // (hint: use MaskingURLClassLoader from SharedClassObjectTest) @@ -293,5 +311,29 @@ putProperty("z", new Cell(z.toString(), saveNatural)); } } - + + public static class I18NLikeOption extends SystemOption { + public static final String PROP_ADVANCED_WIZARD = "advancedWizard"; + + /** Implements superclass abstract method. */ + public String displayName() { + return "I18NLikeOption"; + } + + /** Getter for init advanced wizard property. */ + public boolean isAdvancedWizard() { + // Lazy init. + if(getProperty(PROP_ADVANCED_WIZARD) == null) + return false; + + return ((Boolean)getProperty(PROP_ADVANCED_WIZARD)).booleanValue(); + } + + /** Setter for init advanced wizard property. */ + public void setAdvancedWizard(boolean generateField) { + // Stores in class-wide state and fires property changes if needed: + putProperty(PROP_ADVANCED_WIZARD, generateField ? Boolean.TRUE : Boolean.FALSE, true); + } + + } } Index: projects/projectui/src/org/netbeans/modules/project/ui/Hacks.java =================================================================== RCS file: /cvs/projects/projectui/src/org/netbeans/modules/project/ui/Hacks.java,v retrieving revision 1.15 diff -u -r1.15 Hacks.java --- projects/projectui/src/org/netbeans/modules/project/ui/Hacks.java 31 Aug 2004 12:28:51 -0000 1.15 +++ projects/projectui/src/org/netbeans/modules/project/ui/Hacks.java 8 Nov 2004 08:23:52 -0000 @@ -38,7 +38,7 @@ /** @author Petr Hrebejk */ static void hackFolderActions() { - + /* DataLoaderPool dataLoaderPool = (DataLoaderPool) Lookup.getDefault().lookup(DataLoaderPool.class); DataLoader folderLoader = dataLoaderPool.firstProducerOf(DataFolder.class); @@ -48,7 +48,7 @@ actions.set(index , SystemAction.get(Actions.SystemNewFile.class)); folderLoader.setActions((SystemAction[])actions.toArray(new SystemAction[actions.size()])); } - +*/ } private static Object windowSystemImpl = null; Index: projects/projectui/src/org/netbeans/modules/project/ui/resources/layer.xml =================================================================== RCS file: /cvs/projects/projectui/src/org/netbeans/modules/project/ui/resources/layer.xml,v retrieving revision 1.41 diff -u -r1.41 layer.xml --- projects/projectui/src/org/netbeans/modules/project/ui/resources/layer.xml 20 Oct 2004 13:43:36 -0000 1.41 +++ projects/projectui/src/org/netbeans/modules/project/ui/resources/layer.xml 8 Nov 2004 08:23:52 -0000 @@ -593,5 +593,19 @@
+ + + + + + + + + + + + + + Index: refactoring/src/org/netbeans/modules/refactoring/RefactoringModule.java =================================================================== RCS file: /cvs/refactoring/src/org/netbeans/modules/refactoring/RefactoringModule.java,v retrieving revision 1.4 diff -u -r1.4 RefactoringModule.java --- refactoring/src/org/netbeans/modules/refactoring/RefactoringModule.java 19 Aug 2004 15:35:19 -0000 1.4 +++ refactoring/src/org/netbeans/modules/refactoring/RefactoringModule.java 8 Nov 2004 08:23:52 -0000 @@ -34,19 +34,19 @@ public class RefactoringModule extends ModuleInstall { public void restored() { - addFolderAction(); - addJDOActions(); + //addFolderAction(); + //addJDOActions(); RefactoringOperationListener.addOperationalListener(); } public void uninstalled() { - removeFolderAction(); + // removeFolderAction(); } /** add refactoring submenu for data folders * this should be probably done somewhere in layers * anyway - this will be obsolate with the new build system - */ + * private void addFolderAction() { DataLoaderPool dataLoaderPool = (DataLoaderPool) Lookup.getDefault().lookup(DataLoaderPool.class); @@ -59,7 +59,8 @@ folderLoader.setActions((SystemAction[])actions.toArray(new SystemAction[actions.size()])); } } - + */ + /* private void addJDOActions() { DataLoader javaLoader = DataLoader.getLoader(JavaDataLoader.class); @@ -72,7 +73,8 @@ actions.add(index + 2, null); javaLoader.setActions((SystemAction[])actions.toArray(new SystemAction[actions.size()])); } - + */ + /* private void removeFolderAction() { DataLoaderPool dataLoaderPool = (DataLoaderPool) Lookup.getDefault().lookup(DataLoaderPool.class); DataLoader folderLoader = dataLoaderPool.firstProducerOf(DataFolder.class); @@ -82,5 +84,5 @@ folderLoader.setActions((SystemAction[])actions.toArray(new SystemAction[actions.size()])); } - + */ } Index: refactoring/src/org/netbeans/modules/refactoring/resources/mf-layer.xml =================================================================== RCS file: /cvs/refactoring/src/org/netbeans/modules/refactoring/resources/mf-layer.xml,v retrieving revision 1.14 diff -u -r1.14 mf-layer.xml --- refactoring/src/org/netbeans/modules/refactoring/resources/mf-layer.xml 9 Oct 2004 13:05:54 -0000 1.14 +++ refactoring/src/org/netbeans/modules/refactoring/resources/mf-layer.xml 8 Nov 2004 08:23:52 -0000 @@ -179,5 +179,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +