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 Wed May 07 06:27:35 2014 +0000
+++ a/openide.filesystems/src/org/openide/filesystems/FileSystem.java Wed May 07 14:39:28 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 a 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) findUI}(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.13
+ */
+ 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 Wed May 07 06:27:35 2014 +0000
+++ a/openide.filesystems/src/org/openide/filesystems/MultiFileSystem.java Wed May 07 14:39:28 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
+++ 105dfa130720 Wed May 07 14:39:28 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 extends Action> 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 Wed May 07 06:27:35 2014 +0000
+++ a/openide.loaders/nbproject/project.xml Wed May 07 14:39:28 2014 +0200
@@ -122,7 +122,7 @@
- 7.58
+ 8.12
--- a/openide.loaders/src/org/openide/actions/FileSystemAction.java Wed May 07 06:27:35 2014 +0000
+++ a/openide.loaders/src/org/openide/actions/FileSystemAction.java Wed May 07 14:39:28 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()) {