This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 243265
Collapse All | Expand All

(-)a/openide.filesystems/apichanges.xml (+21 lines)
Lines 49-54 Link Here
49
        <apidef name="filesystems">Filesystems API</apidef>
49
        <apidef name="filesystems">Filesystems API</apidef>
50
    </apidefs>
50
    </apidefs>
51
    <changes>
51
    <changes>
52
        <change id="getActionsDeprecated">
53
            <api name="filesystems"/>
54
            <summary>Deprecating FileSystem.getActions</summary>
55
            <version major="8" minor="12"/>
56
            <date year="2014" month="5" day="14"/>
57
            <author login="jtulach"/>
58
            <compatibility addition="yes"/>
59
            <description>
60
                <p>
61
                    Deprecating <code>getActions</code> method in preparation
62
                    of splitting filesystems API into UI (e.g. depending
63
                    on Swing) and non-UI part (that can run on JDK8 compact
64
                    profile). Introducing general replacement <code>findExtrasFor</code>
65
                    instead...
66
                </p>
67
            </description>
68
            <class package="org.openide.filesystems" name="FileSystem"/>
69
            <class package="org.openide.filesystems" name="AbstractFileSystem"/>
70
            <class package="org.openide.filesystems" name="MultiFileSystem"/>
71
            <issue number="243265"/>
72
        </change>
52
        <change id="MultiFileObject.revealEntriesAttribute">
73
        <change id="MultiFileObject.revealEntriesAttribute">
53
            <api name="filesystems"/>
74
            <api name="filesystems"/>
54
            <summary>Allowed to reveal deleted files, or original files overriden by writable layer</summary>
75
            <summary>Allowed to reveal deleted files, or original files overriden by writable layer</summary>
(-)a/openide.filesystems/manifest.mf (-1 / +1 lines)
Lines 2-6 Link Here
2
OpenIDE-Module: org.openide.filesystems
2
OpenIDE-Module: org.openide.filesystems
3
OpenIDE-Module-Localizing-Bundle: org/openide/filesystems/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/openide/filesystems/Bundle.properties
4
OpenIDE-Module-Layer: org/openide/filesystems/resources/layer.xml
4
OpenIDE-Module-Layer: org/openide/filesystems/resources/layer.xml
5
OpenIDE-Module-Specification-Version: 8.11
5
OpenIDE-Module-Specification-Version: 8.12
6
6
(-)a/openide.filesystems/src/org/openide/filesystems/AbstractFileSystem.java (-1 / +3 lines)
Lines 273-280 Link Here
273
    /* Action for this filesystem.
273
    /* Action for this filesystem.
274
    *
274
    *
275
    * @return refresh action
275
    * @return refresh action
276
    * @deprecated actions should be provided by higher level parts of the
277
    *   system, not something as low level as filesystems
276
    */
278
    */
277
    public SystemAction[] getActions() {
279
    @Deprecated public SystemAction[] getActions() {
278
        if (!isEnabledRefreshFolder()) {
280
        if (!isEnabledRefreshFolder()) {
279
            return NO_SYSTEM_ACTIONS;
281
            return NO_SYSTEM_ACTIONS;
280
        } else {
282
        } else {
(-)105dfa130720 (+78 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2014 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2014 Sun Microsystems, Inc.
41
 */
42
43
package org.openide.filesystems;
44
45
import java.util.Arrays;
46
import java.util.Set;
47
import javax.swing.Action;
48
import org.openide.util.lookup.AbstractLookup;
49
import org.openide.util.lookup.InstanceContent;
50
51
/**
52
 *
53
 * @author Jaroslav Tulach <jtulach@netbeans.org>
54
 */
55
final class FileExtrasLkp extends AbstractLookup {
56
    private final FileSystem fs;
57
    private final InstanceContent ic;
58
    private final Set<FileObject> set;
59
60
    public FileExtrasLkp(FileSystem fs, Set<FileObject> set) {
61
        this(fs, new InstanceContent(), set);
62
    }
63
    private FileExtrasLkp(FileSystem fs, InstanceContent content, Set<FileObject> set) {
64
        super(content);
65
        this.fs = fs;
66
        this.ic = content;
67
        this.set = set;
68
    }
69
70
    @Override @SuppressWarnings("deprecation")
71
    protected void beforeLookup(Template<?> template) {
72
        if (Action.class.isAssignableFrom(template.getType())) {
73
            ic.set(Arrays.asList(fs.getActions(set)), null);
74
        }
75
    }
76
    
77
    
78
}
(-)a/openide.filesystems/src/org/openide/filesystems/FileSystem.java (-13 / +45 lines)
Lines 467-494 Link Here
467
    public FileObject createTempFile(FileObject parent, String prefix, String suffix, boolean deleteOnExit) throws IOException {
467
    public FileObject createTempFile(FileObject parent, String prefix, String suffix, boolean deleteOnExit) throws IOException {
468
        throw new IOException("Unsupported operation"); // NOI18N
468
        throw new IOException("Unsupported operation"); // NOI18N
469
    }
469
    }
470
        
470
    
471
    /** Returns an array of actions that can be invoked on any file in
471
    /** 
472
    * this filesystem.
472
     * FileSystems and their implementation 
473
    * These actions should preferably
473
     * should stay UI independent. Should there be a UI related extensions
474
    * support the {@link org.openide.util.actions.Presenter.Menu Menu},
474
     * they can be communicated via {@link #findExtrasFor(java.util.Set)} method.
475
    * {@link org.openide.util.actions.Presenter.Popup Popup},
475
     * <p>
476
    * and {@link org.openide.util.actions.Presenter.Toolbar Toolbar} presenters.
476
     * Returns an array of actions that should somehow be applicable to 
477
    *
477
     * this file system. These actions should preferably
478
    * @return array of available actions
478
     * support the {@link org.openide.util.actions.Presenter.Menu Menu},
479
    */
479
     * {@link org.openide.util.actions.Presenter.Popup Popup},
480
    public abstract SystemAction[] getActions();
480
     * and {@link org.openide.util.actions.Presenter.Toolbar Toolbar} presenters.
481
     *
482
     * @return array of available actions
483
     * @deprecated Actions should be provided by higher level parts of the
484
     *   system, not directly by file system layer.
485
     */
486
    @Deprecated
487
    public SystemAction[] getActions() {
488
        return new SystemAction[0];
489
    }
481
490
482
    /**
491
    /** 
483
     * Get actions appropriate to a certain file selection.
492
     * FileSystems and their implementation 
493
     * should stay UI independent. Should there be a UI related extensions
494
     * they can be communicated via {@link #findExtrasFor(java.util.Set)} method.
495
     * In case of actions it should be enough to call:<pre>
496
     * actions = fs.{@link #findExtrasFor(java.util.Set) findUI}(foSet).{@link Lookup#lookupAll(java.lang.Class) lookupAll}({@link javax.swing.Action});
497
     * </pre>
498
     * Used to get actions appropriate to a certain file selection.
484
     * By default, returns the same list as {@link #getActions()}.
499
     * By default, returns the same list as {@link #getActions()}.
485
     * @param foSet one or more files which may be selected
500
     * @param foSet one or more files which may be selected
486
     * @return zero or more actions appropriate to those files
501
     * @return zero or more actions appropriate to those files
502
     * @deprecated Actions should be provided by higher level parts of the
503
     *   system, not directly by file system layer.
487
     */
504
     */
505
    @Deprecated
488
    public SystemAction[] getActions(Set<FileObject> foSet) {
506
    public SystemAction[] getActions(Set<FileObject> foSet) {
489
        return this.getActions();
507
        return this.getActions();
490
    }
508
    }
491
509
510
    /** Finds various extensions for set of file objects coming from
511
     * this file system.
512
     * For example actions should be obtainable as:<pre>
513
     * actions = fs.{@link #findExtrasFor(java.util.Set) findUI}(foSet).{@link Lookup#lookupAll(java.lang.Class) lookupAll}({@link javax.swing.Action});
514
     * </pre>
515
     * @param objects the set of objects
516
     * @return the lookup providing various extensions (usually visual) 
517
     * for these objects
518
     * @since 8.13
519
     */
520
    public Lookup findExtrasFor(Set<FileObject> objects) {
521
        return new FileExtrasLkp(this, objects);
522
    }
523
492
    /** Reads object from stream and creates listeners.
524
    /** Reads object from stream and creates listeners.
493
    * @param in the input stream to read from
525
    * @param in the input stream to read from
494
    * @exception IOException error during read
526
    * @exception IOException error during read
(-)a/openide.filesystems/src/org/openide/filesystems/MultiFileSystem.java (-1 / +11 lines)
Lines 288-294 Link Here
288
    }
288
    }
289
289
290
    /** Merge actions from all delegates.
290
    /** Merge actions from all delegates.
291
    */
291
     * @deprecated actions should be provided by higher level parts of the
292
     * system, not something as low level as filesystems
293
     */
294
    @Deprecated
292
    public @Override SystemAction[] getActions() {
295
    public @Override SystemAction[] getActions() {
293
        List<SystemAction> al = new ArrayList<SystemAction>(101); // randomly choosen constant
296
        List<SystemAction> al = new ArrayList<SystemAction>(101); // randomly choosen constant
294
        Set<SystemAction> uniq = new HashSet<SystemAction>(101); // not that randommly choosen
297
        Set<SystemAction> uniq = new HashSet<SystemAction>(101); // not that randommly choosen
Lines 312-317 Link Here
312
        return al.toArray(new SystemAction[al.size()]);
315
        return al.toArray(new SystemAction[al.size()]);
313
    }
316
    }
314
317
318
    /**
319
     * Merge actions from all delegates.
320
     *
321
     * @deprecated actions should be provided by higher level parts of the
322
     * system, not something as low level as filesystems
323
     */
324
    @Deprecated
315
    public @Override SystemAction[] getActions(final Set<FileObject> foSet) {
325
    public @Override SystemAction[] getActions(final Set<FileObject> foSet) {
316
        List<SystemAction> al = new ArrayList<SystemAction>(101); // randomly choosen constant
326
        List<SystemAction> al = new ArrayList<SystemAction>(101); // randomly choosen constant
317
        Set<SystemAction> uniq = new HashSet<SystemAction>(101); // not that randommly choosen
327
        Set<SystemAction> uniq = new HashSet<SystemAction>(101); // not that randommly choosen
(-)105dfa130720 (+116 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2014 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2014 Sun Microsystems, Inc.
41
 */
42
43
package org.openide.filesystems;
44
45
import java.io.File;
46
import java.util.Collection;
47
import java.util.Collections;
48
import java.util.Set;
49
import javax.swing.Action;
50
import org.netbeans.junit.NbTestCase;
51
import org.openide.util.HelpCtx;
52
import org.openide.util.Lookup;
53
import org.openide.util.actions.CallbackSystemAction;
54
import org.openide.util.actions.SystemAction;
55
56
/**
57
 *
58
 * @author Jaroslav Tulach <jtulach@netbeans.org>
59
 */
60
public class FileSystemTest extends NbTestCase {
61
    private ExtraFS fs;
62
    
63
    public FileSystemTest(String n) {
64
        super(n);
65
    }
66
67
    @Override
68
    protected void setUp() throws Exception {
69
        clearWorkDir();
70
        File f = new File(getWorkDir(), "test.txt");
71
        f.createNewFile();
72
        fs = new ExtraFS(getWorkDir());
73
    }
74
75
    public void testFindExtraUIForActions() {
76
        FileObject fo = fs.findResource("test.txt");
77
        assertNotNull("test.txt found", fo);
78
79
        final Set<FileObject> c = Collections.singleton(fo);
80
        Object[] actions = fs.getActions(c);
81
        assertNotNull(actions);
82
        assertEquals("One is provided", actions.length, 1);
83
        
84
        Lookup lkp = fs.findExtrasFor(c);
85
        assertNotNull(lkp);
86
        Collection<? extends Action> extraAct = lkp.lookupAll(Action.class);
87
        assertEquals("one action", extraAct.size(), 1);
88
        
89
        assertSame("The same action is returned", actions[0], extraAct.iterator().next());
90
    }
91
    
92
    private static final class ExtraFS extends LocalFileSystem {
93
        public ExtraFS(File f) throws Exception {
94
            setRootDirectory(f);
95
        }
96
97
        @Override
98
        public SystemAction[] getActions(Set<FileObject> foSet) {
99
            return new SystemAction[] {
100
                SystemAction.get(MyAction.class)
101
            };
102
        }
103
    }
104
    
105
    public static final class MyAction extends CallbackSystemAction {
106
        @Override
107
        public String getName() {
108
            return "My test";
109
        }
110
111
        @Override
112
        public HelpCtx getHelpCtx() {
113
            return HelpCtx.DEFAULT_HELP;
114
        }
115
    }
116
}
(-)a/openide.loaders/nbproject/project.xml (-1 / +1 lines)
Lines 122-128 Link Here
122
                    <build-prerequisite/>
122
                    <build-prerequisite/>
123
                    <compile-dependency/>
123
                    <compile-dependency/>
124
                    <run-dependency>
124
                    <run-dependency>
125
                        <specification-version>7.58</specification-version>
125
                        <specification-version>8.12</specification-version>
126
                    </run-dependency>
126
                    </run-dependency>
127
                </dependency>
127
                </dependency>
128
                <dependency>
128
                <dependency>
(-)a/openide.loaders/src/org/openide/actions/FileSystemAction.java (-2 / +2 lines)
Lines 130-136 Link Here
130
                return createMenu(Enumerations.<Action>empty(), popUp, lookup);
130
                return createMenu(Enumerations.<Action>empty(), popUp, lookup);
131
            }
131
            }
132
            
132
            
133
            List<SystemAction> result = new LinkedList<SystemAction>();
133
            List<Action> result = new LinkedList<Action>();
134
            Set<FileObject> backSet = new LinkedHashSet<FileObject>();
134
            Set<FileObject> backSet = new LinkedHashSet<FileObject>();
135
            for (Map.Entry<FileSystem,Set<FileObject>> entry : fsSet.entrySet()) {
135
            for (Map.Entry<FileSystem,Set<FileObject>> entry : fsSet.entrySet()) {
136
136
Lines 149-155 Link Here
149
                    }
149
                    }
150
                }                
150
                }                
151
                backSet.addAll(backupList);
151
                backSet.addAll(backupList);
152
                result.addAll(Arrays.asList(fs.getActions (backSet)));
152
                result.addAll(fs.findExtrasFor(backSet).lookupAll(Action.class));
153
            }
153
            }
154
154
155
            if (isManualRefresh()) {
155
            if (isManualRefresh()) {

Return to bug 243265