--- a/masterfs/apichanges.xml Sat May 10 00:27:38 2014 +0000 +++ a/masterfs/apichanges.xml Mon May 12 15:56:04 2014 +0200 @@ -49,6 +49,23 @@ MasterFileSystem API + + + Deprecating actions(Set of FileObjects) + + + + + + Adding findExtrasFor method to replace + direct reference to javax.swing.Actions. + + + + A property to suspend native listeners --- a/masterfs/manifest.mf Sat May 10 00:27:38 2014 +0000 +++ a/masterfs/manifest.mf Mon May 12 15:56:04 2014 +0200 @@ -1,7 +1,7 @@ Manifest-Version: 1.0 OpenIDE-Module: org.netbeans.modules.masterfs/2 OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/masterfs/resources/Bundle.properties -OpenIDE-Module-Specification-Version: 2.47 +OpenIDE-Module-Specification-Version: 2.48 OpenIDE-Module-Recommends: org.netbeans.modules.masterfs.providers.Notifier OpenIDE-Module-Provides: org.openide.filesystems.FileUtil.toFileObject AutoUpdate-Show-In-Client: false --- a/masterfs/src/org/netbeans/modules/masterfs/filebasedfs/FileBasedFileSystem.java Sat May 10 00:27:38 2014 +0000 +++ a/masterfs/src/org/netbeans/modules/masterfs/filebasedfs/FileBasedFileSystem.java Mon May 12 15:56:04 2014 +0200 @@ -48,13 +48,14 @@ import java.io.IOException; import java.io.ObjectStreamException; import java.io.Serializable; +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.Iterator; +import java.util.List; import java.util.Map; import java.util.Set; -import java.util.logging.Level; import java.util.logging.Logger; import org.netbeans.modules.masterfs.ProvidedExtensionsProxy; import org.netbeans.modules.masterfs.filebasedfs.fileobjects.BaseFileObj; @@ -69,7 +70,7 @@ import org.openide.util.Exceptions; import org.openide.util.Lookup; import org.openide.util.Utilities; -import org.openide.util.actions.SystemAction; +import org.openide.util.lookup.ProxyLookup; /** * @author Radek Matous @@ -238,18 +239,8 @@ } @Override - public SystemAction[] getActions() { - return new SystemAction[] {}; - } - - @Override - public final SystemAction[] getActions(final Set foSet) { - SystemAction[] some = status.getActions (foSet); - if (some != null) { - return some; - } - return new SystemAction[] {}; - + public Lookup findExtrasFor(Set objects) { + return status.findExtrasFor(objects); } @Override @@ -313,25 +304,15 @@ previousProviders = now; } - public SystemAction[] getActions(Set foSet) { - - javax.swing.Action[] retVal = null; - java.util.Iterator it = annotationProviders.allInstances().iterator(); - while (retVal == null && it.hasNext()) { - AnnotationProvider ap = it.next(); - retVal = ap.actions(foSet); + public Lookup findExtrasFor(Set foSet) { + List arr = new ArrayList(); + for (AnnotationProvider ap : annotationProviders.allInstances()) { + final Lookup lkp = ap.findExtrasFor(foSet); + if (lkp != null) { + arr.add(lkp); + } } - if (retVal != null) { - // right now we handle just SystemAction, it can be changed if necessary - SystemAction[] ret = new SystemAction[retVal.length]; - for (int i = 0; i < retVal.length; i++) { - if (retVal[i] instanceof SystemAction) { - ret[i] = (SystemAction) retVal[i]; - } - } - return ret; - } - return null; + return new ProxyLookup(arr.toArray(new Lookup[0])); } @Override --- a/masterfs/src/org/netbeans/modules/masterfs/providers/AnnotationProvider.java Sat May 10 00:27:38 2014 +0000 +++ a/masterfs/src/org/netbeans/modules/masterfs/providers/AnnotationProvider.java Mon May 12 15:56:04 2014 +0200 @@ -51,6 +51,9 @@ import org.openide.filesystems.FileObject; import org.openide.filesystems.FileStatusEvent; import org.openide.filesystems.FileStatusListener; +import org.openide.filesystems.FileSystem; +import org.openide.util.Lookup; +import org.openide.util.lookup.Lookups; /** Can provide status and actions for FileObjects. Register it using {@link org.openide.util.lookup.ServiceProvider}. * @@ -110,8 +113,25 @@ /** Provides actions that should be added to given set of files. * @param files an immutable set of {@link FileObject}s belonging to this filesystem * @return null or array of actions for these files. + * @deprecated Will be deleted in the future. Overwrite {@link #findExtrasFor(java.util.Set)}. */ - public abstract javax.swing.Action[] actions(Set files); + public javax.swing.Action[] actions(Set files) { + return findExtrasFor(files).lookupAll(javax.swing.Action.class).toArray(new javax.swing.Action[0]); + } + + /** Provides various (usually UI related) information about + * the given set of files. + * + * @param files the files to + * @return lookup to be exposed as {@link FileSystem#findExtrasFor} + * - may return null + * @since 2.48 + */ + @SuppressWarnings("deprecated") + public Lookup findExtrasFor(Set files) { + Object[] arr = actions(files); + return arr == null ? null : Lookups.fixed((Object[]) arr); + } // // Listener support --- a/masterfs/src/org/netbeans/modules/masterfs/watcher/Watcher.java Sat May 10 00:27:38 2014 +0000 +++ a/masterfs/src/org/netbeans/modules/masterfs/watcher/Watcher.java Mon May 12 15:56:04 2014 +0200 @@ -51,13 +51,11 @@ import java.util.WeakHashMap; import java.util.logging.Level; import java.util.logging.Logger; -import javax.swing.Action; import org.netbeans.modules.masterfs.filebasedfs.fileobjects.FileObjectFactory; import org.netbeans.modules.masterfs.providers.InterceptionListener; import org.netbeans.modules.masterfs.providers.ProvidedExtensions; import org.openide.filesystems.FileObject; import org.netbeans.modules.masterfs.providers.AnnotationProvider; -import org.openide.util.Exceptions; import org.openide.util.Lookup; import org.openide.util.Lookup.Item; import org.openide.util.RequestProcessor; @@ -148,10 +146,12 @@ public @Override String annotateNameHtml(String name, Set files) { return null; } - public @Override Action[] actions(Set files) { + + @Override + public Lookup findExtrasFor(Set files) { return null; } - + public @Override InterceptionListener getInterceptionListener() { return ext; } --- a/openide.filesystems/apichanges.xml Sat May 10 00:27:38 2014 +0000 +++ a/openide.filesystems/apichanges.xml Mon May 12 15:56:04 2014 +0200 @@ -49,6 +49,28 @@ Filesystems API + + + Deprecating FileSystem.getActions + + + + + +

+ Deprecating getActions method in preparation + of splitting filesystems API into UI (e.g. depending + on Swing) and non-UI part (that can run on JDK8 compact + profile). Introducing general replacement + findExtrasFor + instead... +

+
+ + + + +
Allowed to reveal deleted files, or original files overriden by writable layer --- a/openide.filesystems/manifest.mf Sat May 10 00:27:38 2014 +0000 +++ a/openide.filesystems/manifest.mf Mon May 12 15:56:04 2014 +0200 @@ -2,5 +2,5 @@ OpenIDE-Module: org.openide.filesystems OpenIDE-Module-Localizing-Bundle: org/openide/filesystems/Bundle.properties OpenIDE-Module-Layer: org/openide/filesystems/resources/layer.xml -OpenIDE-Module-Specification-Version: 8.11 +OpenIDE-Module-Specification-Version: 8.12 --- a/openide.filesystems/src/org/openide/filesystems/AbstractFileSystem.java Sat May 10 00:27:38 2014 +0000 +++ a/openide.filesystems/src/org/openide/filesystems/AbstractFileSystem.java Mon May 12 15:56:04 2014 +0200 @@ -273,8 +273,10 @@ /* Action for this filesystem. * * @return refresh action + * @deprecated actions should be provided by higher level parts of the + * system, not something as low level as filesystems */ - public SystemAction[] getActions() { + @Deprecated public SystemAction[] getActions() { if (!isEnabledRefreshFolder()) { return NO_SYSTEM_ACTIONS; } else { --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ 24c4c4e990c9 Mon May 12 15:56:04 2014 +0200 @@ -0,0 +1,78 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2014 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2014 Sun Microsystems, Inc. + */ + +package org.openide.filesystems; + +import java.util.Arrays; +import java.util.Set; +import javax.swing.Action; +import org.openide.util.lookup.AbstractLookup; +import org.openide.util.lookup.InstanceContent; + +/** + * + * @author Jaroslav Tulach + */ +final class FileExtrasLkp extends AbstractLookup { + private final FileSystem fs; + private final InstanceContent ic; + private final Set set; + + public FileExtrasLkp(FileSystem fs, Set set) { + this(fs, new InstanceContent(), set); + } + private FileExtrasLkp(FileSystem fs, InstanceContent content, Set set) { + super(content); + this.fs = fs; + this.ic = content; + this.set = set; + } + + @Override @SuppressWarnings("deprecation") + protected void beforeLookup(Template template) { + if (Action.class.isAssignableFrom(template.getType())) { + ic.set(Arrays.asList(fs.getActions(set)), null); + } + } + + +} --- a/openide.filesystems/src/org/openide/filesystems/FileSystem.java Sat May 10 00:27:38 2014 +0000 +++ a/openide.filesystems/src/org/openide/filesystems/FileSystem.java Mon May 12 15:56:04 2014 +0200 @@ -467,28 +467,60 @@ public FileObject createTempFile(FileObject parent, String prefix, String suffix, boolean deleteOnExit) throws IOException { throw new IOException("Unsupported operation"); // NOI18N } - - /** Returns an array of actions that can be invoked on any file in - * this filesystem. - * These actions should preferably - * support the {@link org.openide.util.actions.Presenter.Menu Menu}, - * {@link org.openide.util.actions.Presenter.Popup Popup}, - * and {@link org.openide.util.actions.Presenter.Toolbar Toolbar} presenters. - * - * @return array of available actions - */ - public abstract SystemAction[] getActions(); + + /** + * FileSystems and their implementation + * should stay UI independent. Should there be a UI related extensions + * they can be communicated via {@link #findExtrasFor(java.util.Set)} method. + *

+ * Returns an array of actions that should somehow be applicable to + * this file system. These actions should preferably + * support the {@link org.openide.util.actions.Presenter.Menu Menu}, + * {@link org.openide.util.actions.Presenter.Popup Popup}, + * and {@link org.openide.util.actions.Presenter.Toolbar Toolbar} presenters. + * + * @return array of available actions + * @deprecated Actions should be provided by higher level parts of the + * system, not directly by file system layer. + */ + @Deprecated + public SystemAction[] getActions() { + return new SystemAction[0]; + } - /** - * Get actions appropriate to a certain file selection. + /** + * FileSystems and their implementation + * should stay UI independent. Should there be UI related extensions + * they can be communicated via {@link #findExtrasFor(java.util.Set)} method. + * In case of actions it should be enough to call:

+     * actions = fs.{@link #findExtrasFor(java.util.Set) findUI}(foSet).{@link Lookup#lookupAll(java.lang.Class) lookupAll}({@link javax.swing.Action});
+     * 
+ * Used to get actions appropriate to a certain file selection. * By default, returns the same list as {@link #getActions()}. * @param foSet one or more files which may be selected * @return zero or more actions appropriate to those files + * @deprecated Actions should be provided by higher level parts of the + * system, not directly by file system layer. */ + @Deprecated public SystemAction[] getActions(Set foSet) { return this.getActions(); } + /** Finds various extensions for set of file objects coming from + * this file system. + * For example actions should be obtainable as:
+     * actions = fs.{@link #findExtrasFor(java.util.Set) findExtrasFor}(foSet).{@link Lookup#lookupAll(java.lang.Class) lookupAll}({@link javax.swing.Action});
+     * 
+ * @param objects the set of objects + * @return the lookup providing various extensions (usually visual) + * for these objects + * @since 8.12 + */ + public Lookup findExtrasFor(Set objects) { + return new FileExtrasLkp(this, objects); + } + /** Reads object from stream and creates listeners. * @param in the input stream to read from * @exception IOException error during read --- a/openide.filesystems/src/org/openide/filesystems/MultiFileSystem.java Sat May 10 00:27:38 2014 +0000 +++ a/openide.filesystems/src/org/openide/filesystems/MultiFileSystem.java Mon May 12 15:56:04 2014 +0200 @@ -288,7 +288,10 @@ } /** Merge actions from all delegates. - */ + * @deprecated actions should be provided by higher level parts of the + * system, not something as low level as filesystems + */ + @Deprecated public @Override SystemAction[] getActions() { List al = new ArrayList(101); // randomly choosen constant Set uniq = new HashSet(101); // not that randommly choosen @@ -312,6 +315,13 @@ return al.toArray(new SystemAction[al.size()]); } + /** + * Merge actions from all delegates. + * + * @deprecated actions should be provided by higher level parts of the + * system, not something as low level as filesystems + */ + @Deprecated public @Override SystemAction[] getActions(final Set foSet) { List al = new ArrayList(101); // randomly choosen constant Set uniq = new HashSet(101); // not that randommly choosen --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ 24c4c4e990c9 Mon May 12 15:56:04 2014 +0200 @@ -0,0 +1,116 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2014 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2014 Sun Microsystems, Inc. + */ + +package org.openide.filesystems; + +import java.io.File; +import java.util.Collection; +import java.util.Collections; +import java.util.Set; +import javax.swing.Action; +import org.netbeans.junit.NbTestCase; +import org.openide.util.HelpCtx; +import org.openide.util.Lookup; +import org.openide.util.actions.CallbackSystemAction; +import org.openide.util.actions.SystemAction; + +/** + * + * @author Jaroslav Tulach + */ +public class FileSystemTest extends NbTestCase { + private ExtraFS fs; + + public FileSystemTest(String n) { + super(n); + } + + @Override + protected void setUp() throws Exception { + clearWorkDir(); + File f = new File(getWorkDir(), "test.txt"); + f.createNewFile(); + fs = new ExtraFS(getWorkDir()); + } + + public void testFindExtraUIForActions() { + FileObject fo = fs.findResource("test.txt"); + assertNotNull("test.txt found", fo); + + final Set c = Collections.singleton(fo); + Object[] actions = fs.getActions(c); + assertNotNull(actions); + assertEquals("One is provided", actions.length, 1); + + Lookup lkp = fs.findExtrasFor(c); + assertNotNull(lkp); + Collection extraAct = lkp.lookupAll(Action.class); + assertEquals("one action", extraAct.size(), 1); + + assertSame("The same action is returned", actions[0], extraAct.iterator().next()); + } + + private static final class ExtraFS extends LocalFileSystem { + public ExtraFS(File f) throws Exception { + setRootDirectory(f); + } + + @Override + public SystemAction[] getActions(Set foSet) { + return new SystemAction[] { + SystemAction.get(MyAction.class) + }; + } + } + + public static final class MyAction extends CallbackSystemAction { + @Override + public String getName() { + return "My test"; + } + + @Override + public HelpCtx getHelpCtx() { + return HelpCtx.DEFAULT_HELP; + } + } +} --- a/openide.loaders/nbproject/project.xml Sat May 10 00:27:38 2014 +0000 +++ a/openide.loaders/nbproject/project.xml Mon May 12 15:56:04 2014 +0200 @@ -122,7 +122,7 @@ - 7.58 + 8.12 --- a/openide.loaders/src/org/openide/actions/FileSystemAction.java Sat May 10 00:27:38 2014 +0000 +++ a/openide.loaders/src/org/openide/actions/FileSystemAction.java Mon May 12 15:56:04 2014 +0200 @@ -130,7 +130,7 @@ return createMenu(Enumerations.empty(), popUp, lookup); } - List result = new LinkedList(); + List result = new LinkedList(); Set backSet = new LinkedHashSet(); for (Map.Entry> entry : fsSet.entrySet()) { @@ -149,7 +149,7 @@ } } backSet.addAll(backupList); - result.addAll(Arrays.asList(fs.getActions (backSet))); + result.addAll(fs.findExtrasFor(backSet).lookupAll(Action.class)); } if (isManualRefresh()) { --- a/versioning.masterfs/nbproject/project.xml Sat May 10 00:27:38 2014 +0000 +++ a/versioning.masterfs/nbproject/project.xml Mon May 12 15:56:04 2014 +0200 @@ -11,7 +11,7 @@ 2 - 2.37 + 2.48 --- a/versioning.masterfs/src/org/netbeans/modules/versioning/masterfs/VersioningAnnotationProvider.java Sat May 10 00:27:38 2014 +0000 +++ a/versioning.masterfs/src/org/netbeans/modules/versioning/masterfs/VersioningAnnotationProvider.java Mon May 12 15:56:04 2014 +0200 @@ -43,15 +43,16 @@ */ package org.netbeans.modules.versioning.masterfs; +import java.awt.Image; +import java.util.*; +import javax.swing.*; +import org.netbeans.modules.masterfs.providers.AnnotationProvider; import org.netbeans.modules.masterfs.providers.InterceptionListener; -import org.netbeans.modules.masterfs.providers.AnnotationProvider; -import org.openide.filesystems.*; - -import javax.swing.*; -import java.util.*; -import java.awt.Image; import org.netbeans.modules.versioning.core.filesystems.VCSFilesystemInterceptor; import org.netbeans.modules.versioning.core.filesystems.VCSFilesystemInterceptor.VCSAnnotationEvent; +import org.openide.filesystems.*; +import org.openide.util.Lookup; +import org.openide.util.lookup.Lookups; /** * Plugs into IDE filesystem and delegates annotation work to registered versioning systems. @@ -76,8 +77,9 @@ } @Override - public Action[] actions(Set files) { - return VCSFilesystemInterceptor.actions(files); + public Lookup findExtrasFor(Set files) { + Action[] arr = VCSFilesystemInterceptor.actions(files); + return arr == null ? null : Lookups.fixed((Object[]) arr); } @Override