jdk/src/java.desktop/windows/classes/sun/awt/shell/Win32ShellFolderManager2.java
author pkbalakr
Wed, 30 Aug 2017 16:56:59 +0530
changeset 47190 8aff50fc76a5
parent 39515 5f9e9e8bf57b
permissions -rw-r--r--
8175015: FileSystemView.isDrive(File) memory leak on "C:\" file reference Reviewed-by: serb, psadhukhan Contributed-by: krishna.addepalli@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
31430
66b012d00bd3 8017487: filechooser in Windows-Libraries folder: columns are mixed up
ssadetsky
parents: 29922
diff changeset
     2
 * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5448
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5448
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5448
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5448
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5448
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.awt.shell;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
3978
b024e01b947a 6840086: JFileChooser lacks icons on top right when running on Windows 7
rupashka
parents: 3507
diff changeset
    28
import java.awt.*;
b024e01b947a 6840086: JFileChooser lacks icons on top right when running on Windows 7
rupashka
parents: 3507
diff changeset
    29
import java.awt.image.BufferedImage;
39515
5f9e9e8bf57b 8151385: [hidpi] JOptionPane-Icons only partially visible when using Windows 10 L&F
hschreiber
parents: 37550
diff changeset
    30
import java.awt.image.BaseMultiResolutionImage;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.io.FileNotFoundException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.security.AccessController;
2489
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 715
diff changeset
    36
import java.security.PrivilegedAction;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.*;
3978
b024e01b947a 6840086: JFileChooser lacks icons on top right when running on Windows 7
rupashka
parents: 3507
diff changeset
    38
import java.util.List;
2489
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 715
diff changeset
    39
import java.util.concurrent.*;
28546
47d9b4eb8fad 8055304: More boxing for DirectoryComboBoxModel
alexsch
parents: 25859
diff changeset
    40
import java.util.stream.Stream;
2489
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 715
diff changeset
    41
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import static sun.awt.shell.Win32ShellFolder2.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import sun.awt.OSInfo;
24520
e8afd90fcb69 8035169: Move ThreadGroupUtils from the sun.misc package
pchelko
parents: 23900
diff changeset
    44
import sun.awt.util.ThreadGroupUtils;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
// NOTE: This class supersedes Win32ShellFolderManager, which was removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
//       from distribution after version 1.4.2.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * @author Michael Martak
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * @author Leif Samuelsson
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * @author Kenneth Russell
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
25209
e9902dc8b9a0 8042094: Test javax/swing/JFileChooser/7036025/bug7036025.java fails with java.lang.NullPointerException on Windows x86
azvegint
parents: 25192
diff changeset
    55
final class Win32ShellFolderManager2 extends ShellFolderManager {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        // Load library here
23691
475a42c428e0 8035171: KSS: sun.awt.shell.Win32ShellFolderManager2
malenkov
parents: 23010
diff changeset
    59
        sun.awt.windows.WToolkit.loadLibraries();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    public ShellFolder createShellFolder(File file) throws FileNotFoundException {
3346
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
    63
        try {
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
    64
            return createShellFolder(getDesktop(), file);
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
    65
        } catch (InterruptedException e) {
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
    66
            throw new FileNotFoundException("Execution was interrupted");
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
    67
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
3346
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
    70
    static Win32ShellFolder2 createShellFolder(Win32ShellFolder2 parent, File file)
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
    71
            throws FileNotFoundException, InterruptedException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        long pIDL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            pIDL = parent.parseDisplayName(file.getCanonicalPath());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        } catch (IOException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            pIDL = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        if (pIDL == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            // Shouldn't happen but watch for it anyway
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            throw new FileNotFoundException("File " + file.getAbsolutePath() + " not found");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        }
4275
4c3444f1b9d8 6621569: Win32ShellFolder2 and Win32ShellFolderManager2 may leak native resources
rupashka
parents: 4271
diff changeset
    82
4c3444f1b9d8 6621569: Win32ShellFolder2 and Win32ShellFolderManager2 may leak native resources
rupashka
parents: 4271
diff changeset
    83
        try {
4c3444f1b9d8 6621569: Win32ShellFolder2 and Win32ShellFolderManager2 may leak native resources
rupashka
parents: 4271
diff changeset
    84
            return createShellFolderFromRelativePIDL(parent, pIDL);
4c3444f1b9d8 6621569: Win32ShellFolder2 and Win32ShellFolderManager2 may leak native resources
rupashka
parents: 4271
diff changeset
    85
        } finally {
4c3444f1b9d8 6621569: Win32ShellFolder2 and Win32ShellFolderManager2 may leak native resources
rupashka
parents: 4271
diff changeset
    86
            Win32ShellFolder2.releasePIDL(pIDL);
4c3444f1b9d8 6621569: Win32ShellFolder2 and Win32ShellFolderManager2 may leak native resources
rupashka
parents: 4271
diff changeset
    87
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
3346
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
    90
    static Win32ShellFolder2 createShellFolderFromRelativePIDL(Win32ShellFolder2 parent, long pIDL)
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
    91
            throws InterruptedException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        // Walk down this relative pIDL, creating new nodes for each of the entries
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        while (pIDL != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            long curPIDL = Win32ShellFolder2.copyFirstPIDLEntry(pIDL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            if (curPIDL != 0) {
31430
66b012d00bd3 8017487: filechooser in Windows-Libraries folder: columns are mixed up
ssadetsky
parents: 29922
diff changeset
    96
                parent = Win32ShellFolder2.createShellFolder(parent, curPIDL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                pIDL = Win32ShellFolder2.getNextPIDLEntry(pIDL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                // The list is empty if the parent is Desktop and pIDL is a shortcut to Desktop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        return parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
3978
b024e01b947a 6840086: JFileChooser lacks icons on top right when running on Windows 7
rupashka
parents: 3507
diff changeset
   106
    private static final int VIEW_LIST = 2;
b024e01b947a 6840086: JFileChooser lacks icons on top right when running on Windows 7
rupashka
parents: 3507
diff changeset
   107
    private static final int VIEW_DETAILS = 3;
b024e01b947a 6840086: JFileChooser lacks icons on top right when running on Windows 7
rupashka
parents: 3507
diff changeset
   108
    private static final int VIEW_PARENTFOLDER = 8;
b024e01b947a 6840086: JFileChooser lacks icons on top right when running on Windows 7
rupashka
parents: 3507
diff changeset
   109
    private static final int VIEW_NEWFOLDER = 11;
b024e01b947a 6840086: JFileChooser lacks icons on top right when running on Windows 7
rupashka
parents: 3507
diff changeset
   110
b024e01b947a 6840086: JFileChooser lacks icons on top right when running on Windows 7
rupashka
parents: 3507
diff changeset
   111
    private static final Image[] STANDARD_VIEW_BUTTONS = new Image[12];
b024e01b947a 6840086: JFileChooser lacks icons on top right when running on Windows 7
rupashka
parents: 3507
diff changeset
   112
b024e01b947a 6840086: JFileChooser lacks icons on top right when running on Windows 7
rupashka
parents: 3507
diff changeset
   113
    private static Image getStandardViewButton(int iconIndex) {
b024e01b947a 6840086: JFileChooser lacks icons on top right when running on Windows 7
rupashka
parents: 3507
diff changeset
   114
        Image result = STANDARD_VIEW_BUTTONS[iconIndex];
b024e01b947a 6840086: JFileChooser lacks icons on top right when running on Windows 7
rupashka
parents: 3507
diff changeset
   115
b024e01b947a 6840086: JFileChooser lacks icons on top right when running on Windows 7
rupashka
parents: 3507
diff changeset
   116
        if (result != null) {
b024e01b947a 6840086: JFileChooser lacks icons on top right when running on Windows 7
rupashka
parents: 3507
diff changeset
   117
            return result;
b024e01b947a 6840086: JFileChooser lacks icons on top right when running on Windows 7
rupashka
parents: 3507
diff changeset
   118
        }
b024e01b947a 6840086: JFileChooser lacks icons on top right when running on Windows 7
rupashka
parents: 3507
diff changeset
   119
39515
5f9e9e8bf57b 8151385: [hidpi] JOptionPane-Icons only partially visible when using Windows 10 L&F
hschreiber
parents: 37550
diff changeset
   120
        final int[] iconBits = Win32ShellFolder2
5f9e9e8bf57b 8151385: [hidpi] JOptionPane-Icons only partially visible when using Windows 10 L&F
hschreiber
parents: 37550
diff changeset
   121
                .getStandardViewButton0(iconIndex, true);
5f9e9e8bf57b 8151385: [hidpi] JOptionPane-Icons only partially visible when using Windows 10 L&F
hschreiber
parents: 37550
diff changeset
   122
        if (iconBits != null) {
5f9e9e8bf57b 8151385: [hidpi] JOptionPane-Icons only partially visible when using Windows 10 L&F
hschreiber
parents: 37550
diff changeset
   123
            // icons are always square
5f9e9e8bf57b 8151385: [hidpi] JOptionPane-Icons only partially visible when using Windows 10 L&F
hschreiber
parents: 37550
diff changeset
   124
            final int size = (int) Math.sqrt(iconBits.length);
5f9e9e8bf57b 8151385: [hidpi] JOptionPane-Icons only partially visible when using Windows 10 L&F
hschreiber
parents: 37550
diff changeset
   125
            final BufferedImage img =
5f9e9e8bf57b 8151385: [hidpi] JOptionPane-Icons only partially visible when using Windows 10 L&F
hschreiber
parents: 37550
diff changeset
   126
                    new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
5f9e9e8bf57b 8151385: [hidpi] JOptionPane-Icons only partially visible when using Windows 10 L&F
hschreiber
parents: 37550
diff changeset
   127
            img.setRGB(0, 0, size, size, iconBits, 0, size);
3978
b024e01b947a 6840086: JFileChooser lacks icons on top right when running on Windows 7
rupashka
parents: 3507
diff changeset
   128
39515
5f9e9e8bf57b 8151385: [hidpi] JOptionPane-Icons only partially visible when using Windows 10 L&F
hschreiber
parents: 37550
diff changeset
   129
            STANDARD_VIEW_BUTTONS[iconIndex] = (size == 16)
5f9e9e8bf57b 8151385: [hidpi] JOptionPane-Icons only partially visible when using Windows 10 L&F
hschreiber
parents: 37550
diff changeset
   130
                    ? img
5f9e9e8bf57b 8151385: [hidpi] JOptionPane-Icons only partially visible when using Windows 10 L&F
hschreiber
parents: 37550
diff changeset
   131
                    : new MultiResolutionIconImage(16, img);
5f9e9e8bf57b 8151385: [hidpi] JOptionPane-Icons only partially visible when using Windows 10 L&F
hschreiber
parents: 37550
diff changeset
   132
        }
3978
b024e01b947a 6840086: JFileChooser lacks icons on top right when running on Windows 7
rupashka
parents: 3507
diff changeset
   133
39515
5f9e9e8bf57b 8151385: [hidpi] JOptionPane-Icons only partially visible when using Windows 10 L&F
hschreiber
parents: 37550
diff changeset
   134
        return STANDARD_VIEW_BUTTONS[iconIndex];
3978
b024e01b947a 6840086: JFileChooser lacks icons on top right when running on Windows 7
rupashka
parents: 3507
diff changeset
   135
    }
b024e01b947a 6840086: JFileChooser lacks icons on top right when running on Windows 7
rupashka
parents: 3507
diff changeset
   136
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    // Special folders
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    private static Win32ShellFolder2 desktop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    private static Win32ShellFolder2 drives;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    private static Win32ShellFolder2 recent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    private static Win32ShellFolder2 network;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    private static Win32ShellFolder2 personal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    static Win32ShellFolder2 getDesktop() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        if (desktop == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                desktop = new Win32ShellFolder2(DESKTOP);
25536
a1ba79d447e0 8035699: File choosers should be choosier
malenkov
parents: 25209
diff changeset
   148
            } catch (SecurityException e) {
a1ba79d447e0 8035699: File choosers should be choosier
malenkov
parents: 25209
diff changeset
   149
                // Ignore error
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            } catch (IOException e) {
3346
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
   151
                // Ignore error
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
   152
            } catch (InterruptedException e) {
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
   153
                // Ignore error
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        return desktop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    static Win32ShellFolder2 getDrives() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        if (drives == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                drives = new Win32ShellFolder2(DRIVES);
25536
a1ba79d447e0 8035699: File choosers should be choosier
malenkov
parents: 25209
diff changeset
   163
            } catch (SecurityException e) {
a1ba79d447e0 8035699: File choosers should be choosier
malenkov
parents: 25209
diff changeset
   164
                // Ignore error
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            } catch (IOException e) {
3346
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
   166
                // Ignore error
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
   167
            } catch (InterruptedException e) {
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
   168
                // Ignore error
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        return drives;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    static Win32ShellFolder2 getRecent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        if (recent == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                String path = Win32ShellFolder2.getFileSystemPath(RECENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                if (path != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                    recent = createShellFolder(getDesktop(), new File(path));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                }
25536
a1ba79d447e0 8035699: File choosers should be choosier
malenkov
parents: 25209
diff changeset
   181
            } catch (SecurityException e) {
a1ba79d447e0 8035699: File choosers should be choosier
malenkov
parents: 25209
diff changeset
   182
                // Ignore error
3346
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
   183
            } catch (InterruptedException e) {
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
   184
                // Ignore error
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            } catch (IOException e) {
3346
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
   186
                // Ignore error
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        return recent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    static Win32ShellFolder2 getNetwork() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        if (network == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                network = new Win32ShellFolder2(NETWORK);
25536
a1ba79d447e0 8035699: File choosers should be choosier
malenkov
parents: 25209
diff changeset
   196
            } catch (SecurityException e) {
a1ba79d447e0 8035699: File choosers should be choosier
malenkov
parents: 25209
diff changeset
   197
                // Ignore error
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            } catch (IOException e) {
3346
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
   199
                // Ignore error
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
   200
            } catch (InterruptedException e) {
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
   201
                // Ignore error
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        return network;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    static Win32ShellFolder2 getPersonal() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        if (personal == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                String path = Win32ShellFolder2.getFileSystemPath(PERSONAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                if (path != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                    Win32ShellFolder2 desktop = getDesktop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                    personal = desktop.getChildByPath(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                    if (personal == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                        personal = createShellFolder(getDesktop(), new File(path));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                    if (personal != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                        personal.setIsPersonal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                }
25536
a1ba79d447e0 8035699: File choosers should be choosier
malenkov
parents: 25209
diff changeset
   221
            } catch (SecurityException e) {
a1ba79d447e0 8035699: File choosers should be choosier
malenkov
parents: 25209
diff changeset
   222
                // Ignore error
3346
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
   223
            } catch (InterruptedException e) {
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
   224
                // Ignore error
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            } catch (IOException e) {
3346
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
   226
                // Ignore error
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        return personal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    private static File[] roots;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 31653
diff changeset
   236
     * @param key a {@code String}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     *  "fileChooserDefaultFolder":
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 31653
diff changeset
   238
     *    Returns a {@code File} - the default shellfolder for a new filechooser
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     *  "roots":
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 31653
diff changeset
   240
     *    Returns a {@code File[]} - containing the root(s) of the displayable hierarchy
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     *  "fileChooserComboBoxFolders":
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 31653
diff changeset
   242
     *    Returns a {@code File[]} - an array of shellfolders representing the list to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     *    show by default in the file chooser's combobox
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     *   "fileChooserShortcutPanelFolders":
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 31653
diff changeset
   245
     *    Returns a {@code File[]} - an array of shellfolders representing well-known
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     *    folders, such as Desktop, Documents, History, Network, Home, etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     *    This is used in the shortcut panel of the filechooser on Windows 2000
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     *    and Windows Me.
3978
b024e01b947a 6840086: JFileChooser lacks icons on top right when running on Windows 7
rupashka
parents: 3507
diff changeset
   249
     *  "fileChooserIcon <icon>":
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 31653
diff changeset
   250
     *    Returns an {@code Image} - icon can be ListView, DetailsView, UpFolder, NewFolder or
3978
b024e01b947a 6840086: JFileChooser lacks icons on top right when running on Windows 7
rupashka
parents: 3507
diff changeset
   251
     *    ViewMenu (Windows only).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     *  "optionPaneIcon iconName":
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 31653
diff changeset
   253
     *    Returns an {@code Image} - icon from the system icon list
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * @return An Object matching the key string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    public Object get(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        if (key.equals("fileChooserDefaultFolder")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            File file = getPersonal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            if (file == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                file = getDesktop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            }
28546
47d9b4eb8fad 8055304: More boxing for DirectoryComboBoxModel
alexsch
parents: 25859
diff changeset
   263
            return checkFile(file);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        } else if (key.equals("roots")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            // Should be "History" and "Desktop" ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            if (roots == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                File desktop = getDesktop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                if (desktop != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                    roots = new File[] { desktop };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                    roots = (File[])super.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            }
28546
47d9b4eb8fad 8055304: More boxing for DirectoryComboBoxModel
alexsch
parents: 25859
diff changeset
   274
            return checkFiles(roots);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        } else if (key.equals("fileChooserComboBoxFolders")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            Win32ShellFolder2 desktop = getDesktop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
28546
47d9b4eb8fad 8055304: More boxing for DirectoryComboBoxModel
alexsch
parents: 25859
diff changeset
   278
            if (desktop != null && checkFile(desktop) != null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                ArrayList<File> folders = new ArrayList<File>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                Win32ShellFolder2 drives = getDrives();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                Win32ShellFolder2 recentFolder = getRecent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                if (recentFolder != null && OSInfo.getWindowsVersion().compareTo(OSInfo.WINDOWS_2000) >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                    folders.add(recentFolder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                folders.add(desktop);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                // Add all second level folders
28556
cebfefd140cc 8062561: Test bug8055304 fails if file system default directory has read access
alexsch
parents: 28546
diff changeset
   289
                File[] secondLevelFolders = checkFiles(desktop.listFiles());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                Arrays.sort(secondLevelFolders);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                for (File secondLevelFolder : secondLevelFolders) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                    Win32ShellFolder2 folder = (Win32ShellFolder2) secondLevelFolder;
4271
35fc7add4925 6550546: Win LAF: JFileChooser -> Look in Drop down should not display any shortcuts created on desktop
rupashka
parents: 3978
diff changeset
   293
                    if (!folder.isFileSystem() || (folder.isDirectory() && !folder.isLink())) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                        folders.add(folder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                        // Add third level for "My Computer"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                        if (folder.equals(drives)) {
28556
cebfefd140cc 8062561: Test bug8055304 fails if file system default directory has read access
alexsch
parents: 28546
diff changeset
   297
                            File[] thirdLevelFolders = checkFiles(folder.listFiles());
678
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 454
diff changeset
   298
                            if (thirdLevelFolders != null && thirdLevelFolders.length > 0) {
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 454
diff changeset
   299
                                List<File> thirdLevelFoldersList = Arrays.asList(thirdLevelFolders);
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 454
diff changeset
   300
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 454
diff changeset
   301
                                folder.sortChildren(thirdLevelFoldersList);
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 454
diff changeset
   302
                                folders.addAll(thirdLevelFoldersList);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                }
28546
47d9b4eb8fad 8055304: More boxing for DirectoryComboBoxModel
alexsch
parents: 25859
diff changeset
   307
                return checkFiles(folders);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                return super.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        } else if (key.equals("fileChooserShortcutPanelFolders")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            Toolkit toolkit = Toolkit.getDefaultToolkit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            ArrayList<File> folders = new ArrayList<File>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            int i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            Object value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                value = toolkit.getDesktopProperty("win.comdlg.placesBarPlace" + i++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                    if (value instanceof Integer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                        // A CSIDL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                        folders.add(new Win32ShellFolder2((Integer)value));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                    } else if (value instanceof String) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                        // A path
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                        folders.add(createShellFolder(new File((String)value)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                    // Skip this value
3346
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
   328
                } catch (InterruptedException e) {
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
   329
                    // Return empty result
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
   330
                    return new File[0];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            } while (value != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            if (folders.size() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                // Use default list of places
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                for (File f : new File[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                    getRecent(), getDesktop(), getPersonal(), getDrives(), getNetwork()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                }) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                    if (f != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                        folders.add(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            }
28546
47d9b4eb8fad 8055304: More boxing for DirectoryComboBoxModel
alexsch
parents: 25859
diff changeset
   344
            return checkFiles(folders);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        } else if (key.startsWith("fileChooserIcon ")) {
3978
b024e01b947a 6840086: JFileChooser lacks icons on top right when running on Windows 7
rupashka
parents: 3507
diff changeset
   346
            String name = key.substring(key.indexOf(" ") + 1);
b024e01b947a 6840086: JFileChooser lacks icons on top right when running on Windows 7
rupashka
parents: 3507
diff changeset
   347
b024e01b947a 6840086: JFileChooser lacks icons on top right when running on Windows 7
rupashka
parents: 3507
diff changeset
   348
            int iconIndex;
b024e01b947a 6840086: JFileChooser lacks icons on top right when running on Windows 7
rupashka
parents: 3507
diff changeset
   349
b024e01b947a 6840086: JFileChooser lacks icons on top right when running on Windows 7
rupashka
parents: 3507
diff changeset
   350
            if (name.equals("ListView") || name.equals("ViewMenu")) {
b024e01b947a 6840086: JFileChooser lacks icons on top right when running on Windows 7
rupashka
parents: 3507
diff changeset
   351
                iconIndex = VIEW_LIST;
b024e01b947a 6840086: JFileChooser lacks icons on top right when running on Windows 7
rupashka
parents: 3507
diff changeset
   352
            } else if (name.equals("DetailsView")) {
b024e01b947a 6840086: JFileChooser lacks icons on top right when running on Windows 7
rupashka
parents: 3507
diff changeset
   353
                iconIndex = VIEW_DETAILS;
b024e01b947a 6840086: JFileChooser lacks icons on top right when running on Windows 7
rupashka
parents: 3507
diff changeset
   354
            } else if (name.equals("UpFolder")) {
b024e01b947a 6840086: JFileChooser lacks icons on top right when running on Windows 7
rupashka
parents: 3507
diff changeset
   355
                iconIndex = VIEW_PARENTFOLDER;
b024e01b947a 6840086: JFileChooser lacks icons on top right when running on Windows 7
rupashka
parents: 3507
diff changeset
   356
            } else if (name.equals("NewFolder")) {
b024e01b947a 6840086: JFileChooser lacks icons on top right when running on Windows 7
rupashka
parents: 3507
diff changeset
   357
                iconIndex = VIEW_NEWFOLDER;
b024e01b947a 6840086: JFileChooser lacks icons on top right when running on Windows 7
rupashka
parents: 3507
diff changeset
   358
            } else {
b024e01b947a 6840086: JFileChooser lacks icons on top right when running on Windows 7
rupashka
parents: 3507
diff changeset
   359
                return null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            }
3978
b024e01b947a 6840086: JFileChooser lacks icons on top right when running on Windows 7
rupashka
parents: 3507
diff changeset
   361
b024e01b947a 6840086: JFileChooser lacks icons on top right when running on Windows 7
rupashka
parents: 3507
diff changeset
   362
            return getStandardViewButton(iconIndex);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        } else if (key.startsWith("optionPaneIcon ")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            Win32ShellFolder2.SystemIcon iconType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            if (key == "optionPaneIcon Error") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                iconType = Win32ShellFolder2.SystemIcon.IDI_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            } else if (key == "optionPaneIcon Information") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                iconType = Win32ShellFolder2.SystemIcon.IDI_INFORMATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            } else if (key == "optionPaneIcon Question") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                iconType = Win32ShellFolder2.SystemIcon.IDI_QUESTION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            } else if (key == "optionPaneIcon Warning") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                iconType = Win32ShellFolder2.SystemIcon.IDI_EXCLAMATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            return Win32ShellFolder2.getSystemIcon(iconType);
454
2f4f4fef8880 6210674: FileChooser fails to load custom harddrive icon and gets NullPointerException
rupashka
parents: 2
diff changeset
   377
        } else if (key.startsWith("shell32Icon ") || key.startsWith("shell32LargeIcon ")) {
2f4f4fef8880 6210674: FileChooser fails to load custom harddrive icon and gets NullPointerException
rupashka
parents: 2
diff changeset
   378
            String name = key.substring(key.indexOf(" ") + 1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            try {
454
2f4f4fef8880 6210674: FileChooser fails to load custom harddrive icon and gets NullPointerException
rupashka
parents: 2
diff changeset
   380
                int i = Integer.parseInt(name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                if (i >= 0) {
454
2f4f4fef8880 6210674: FileChooser fails to load custom harddrive icon and gets NullPointerException
rupashka
parents: 2
diff changeset
   382
                    return Win32ShellFolder2.getShell32Icon(i, key.startsWith("shell32LargeIcon "));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            } catch (NumberFormatException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
28546
47d9b4eb8fad 8055304: More boxing for DirectoryComboBoxModel
alexsch
parents: 25859
diff changeset
   390
    private File checkFile(File file) {
47d9b4eb8fad 8055304: More boxing for DirectoryComboBoxModel
alexsch
parents: 25859
diff changeset
   391
        SecurityManager sm = System.getSecurityManager();
47d9b4eb8fad 8055304: More boxing for DirectoryComboBoxModel
alexsch
parents: 25859
diff changeset
   392
        return (sm == null || file == null) ? file : checkFile(file, sm);
47d9b4eb8fad 8055304: More boxing for DirectoryComboBoxModel
alexsch
parents: 25859
diff changeset
   393
    }
47d9b4eb8fad 8055304: More boxing for DirectoryComboBoxModel
alexsch
parents: 25859
diff changeset
   394
47d9b4eb8fad 8055304: More boxing for DirectoryComboBoxModel
alexsch
parents: 25859
diff changeset
   395
    private File checkFile(File file, SecurityManager sm) {
47d9b4eb8fad 8055304: More boxing for DirectoryComboBoxModel
alexsch
parents: 25859
diff changeset
   396
        try {
47d9b4eb8fad 8055304: More boxing for DirectoryComboBoxModel
alexsch
parents: 25859
diff changeset
   397
            sm.checkRead(file.getPath());
47d9b4eb8fad 8055304: More boxing for DirectoryComboBoxModel
alexsch
parents: 25859
diff changeset
   398
            return file;
47d9b4eb8fad 8055304: More boxing for DirectoryComboBoxModel
alexsch
parents: 25859
diff changeset
   399
        } catch (SecurityException se) {
47d9b4eb8fad 8055304: More boxing for DirectoryComboBoxModel
alexsch
parents: 25859
diff changeset
   400
            return null;
47d9b4eb8fad 8055304: More boxing for DirectoryComboBoxModel
alexsch
parents: 25859
diff changeset
   401
        }
47d9b4eb8fad 8055304: More boxing for DirectoryComboBoxModel
alexsch
parents: 25859
diff changeset
   402
    }
47d9b4eb8fad 8055304: More boxing for DirectoryComboBoxModel
alexsch
parents: 25859
diff changeset
   403
47d9b4eb8fad 8055304: More boxing for DirectoryComboBoxModel
alexsch
parents: 25859
diff changeset
   404
    private File[] checkFiles(File[] files) {
47d9b4eb8fad 8055304: More boxing for DirectoryComboBoxModel
alexsch
parents: 25859
diff changeset
   405
        SecurityManager sm = System.getSecurityManager();
47d9b4eb8fad 8055304: More boxing for DirectoryComboBoxModel
alexsch
parents: 25859
diff changeset
   406
        if (sm == null || files == null || files.length == 0) {
47d9b4eb8fad 8055304: More boxing for DirectoryComboBoxModel
alexsch
parents: 25859
diff changeset
   407
            return files;
47d9b4eb8fad 8055304: More boxing for DirectoryComboBoxModel
alexsch
parents: 25859
diff changeset
   408
        }
47d9b4eb8fad 8055304: More boxing for DirectoryComboBoxModel
alexsch
parents: 25859
diff changeset
   409
        return checkFiles(Arrays.stream(files), sm);
47d9b4eb8fad 8055304: More boxing for DirectoryComboBoxModel
alexsch
parents: 25859
diff changeset
   410
    }
47d9b4eb8fad 8055304: More boxing for DirectoryComboBoxModel
alexsch
parents: 25859
diff changeset
   411
47d9b4eb8fad 8055304: More boxing for DirectoryComboBoxModel
alexsch
parents: 25859
diff changeset
   412
    private File[] checkFiles(List<File> files) {
47d9b4eb8fad 8055304: More boxing for DirectoryComboBoxModel
alexsch
parents: 25859
diff changeset
   413
        SecurityManager sm = System.getSecurityManager();
47d9b4eb8fad 8055304: More boxing for DirectoryComboBoxModel
alexsch
parents: 25859
diff changeset
   414
        if (sm == null || files.isEmpty()) {
47d9b4eb8fad 8055304: More boxing for DirectoryComboBoxModel
alexsch
parents: 25859
diff changeset
   415
            return files.toArray(new File[files.size()]);
47d9b4eb8fad 8055304: More boxing for DirectoryComboBoxModel
alexsch
parents: 25859
diff changeset
   416
        }
47d9b4eb8fad 8055304: More boxing for DirectoryComboBoxModel
alexsch
parents: 25859
diff changeset
   417
        return checkFiles(files.stream(), sm);
47d9b4eb8fad 8055304: More boxing for DirectoryComboBoxModel
alexsch
parents: 25859
diff changeset
   418
    }
47d9b4eb8fad 8055304: More boxing for DirectoryComboBoxModel
alexsch
parents: 25859
diff changeset
   419
47d9b4eb8fad 8055304: More boxing for DirectoryComboBoxModel
alexsch
parents: 25859
diff changeset
   420
    private File[] checkFiles(Stream<File> filesStream, SecurityManager sm) {
47d9b4eb8fad 8055304: More boxing for DirectoryComboBoxModel
alexsch
parents: 25859
diff changeset
   421
        return filesStream.filter((file) -> checkFile(file, sm) != null)
47d9b4eb8fad 8055304: More boxing for DirectoryComboBoxModel
alexsch
parents: 25859
diff changeset
   422
                .toArray(File[]::new);
47d9b4eb8fad 8055304: More boxing for DirectoryComboBoxModel
alexsch
parents: 25859
diff changeset
   423
    }
47d9b4eb8fad 8055304: More boxing for DirectoryComboBoxModel
alexsch
parents: 25859
diff changeset
   424
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 31653
diff changeset
   426
     * Does {@code dir} represent a "computer" such as a node on the network, or
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * "My Computer" on the desktop.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     */
3507
1610d6f5a0e3 6461173: One JCK test([NewFolderAction0001]) failed on Windows due to lack of PropertyPermission(s)
rupashka
parents: 3346
diff changeset
   429
    public boolean isComputerNode(final File dir) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        if (dir != null && dir == getDrives()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        } else {
3507
1610d6f5a0e3 6461173: One JCK test([NewFolderAction0001]) failed on Windows due to lack of PropertyPermission(s)
rupashka
parents: 3346
diff changeset
   433
            String path = AccessController.doPrivileged(new PrivilegedAction<String>() {
1610d6f5a0e3 6461173: One JCK test([NewFolderAction0001]) failed on Windows due to lack of PropertyPermission(s)
rupashka
parents: 3346
diff changeset
   434
                public String run() {
1610d6f5a0e3 6461173: One JCK test([NewFolderAction0001]) failed on Windows due to lack of PropertyPermission(s)
rupashka
parents: 3346
diff changeset
   435
                    return dir.getAbsolutePath();
1610d6f5a0e3 6461173: One JCK test([NewFolderAction0001]) failed on Windows due to lack of PropertyPermission(s)
rupashka
parents: 3346
diff changeset
   436
                }
1610d6f5a0e3 6461173: One JCK test([NewFolderAction0001]) failed on Windows due to lack of PropertyPermission(s)
rupashka
parents: 3346
diff changeset
   437
            });
1610d6f5a0e3 6461173: One JCK test([NewFolderAction0001]) failed on Windows due to lack of PropertyPermission(s)
rupashka
parents: 3346
diff changeset
   438
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            return (path.startsWith("\\\\") && path.indexOf("\\", 2) < 0);      //Network path
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    public boolean isFileSystemRoot(File dir) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        //Note: Removable drives don't "exist" but are listed in "My Computer"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        if (dir != null) {
47190
8aff50fc76a5 8175015: FileSystemView.isDrive(File) memory leak on "C:\" file reference
pkbalakr
parents: 39515
diff changeset
   446
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            if (dir instanceof Win32ShellFolder2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                Win32ShellFolder2 sf = (Win32ShellFolder2)dir;
47190
8aff50fc76a5 8175015: FileSystemView.isDrive(File) memory leak on "C:\" file reference
pkbalakr
parents: 39515
diff changeset
   449
8aff50fc76a5 8175015: FileSystemView.isDrive(File) memory leak on "C:\" file reference
pkbalakr
parents: 39515
diff changeset
   450
                return (sf.isFileSystem() && sf.parent != null &&
8aff50fc76a5 8175015: FileSystemView.isDrive(File) memory leak on "C:\" file reference
pkbalakr
parents: 39515
diff changeset
   451
                        sf.parent.equals(Win32ShellFolder2.listRoots()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            String path = dir.getPath();
5448
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents: 4275
diff changeset
   454
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents: 4275
diff changeset
   455
            if (path.length() != 3 || path.charAt(1) != ':') {
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents: 4275
diff changeset
   456
                return false;
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents: 4275
diff changeset
   457
            }
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents: 4275
diff changeset
   458
47190
8aff50fc76a5 8175015: FileSystemView.isDrive(File) memory leak on "C:\" file reference
pkbalakr
parents: 39515
diff changeset
   459
            File[] roots = Win32ShellFolder2.listRoots();
5448
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents: 4275
diff changeset
   460
47190
8aff50fc76a5 8175015: FileSystemView.isDrive(File) memory leak on "C:\" file reference
pkbalakr
parents: 39515
diff changeset
   461
            return roots != null && Arrays.asList(roots).contains(dir);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
25192
4e2dc0f8702d 8044551: Fix raw and unchecked lint warnings in platform-specific sun.awt files
henryjen
parents: 24520
diff changeset
   466
    private static List<Win32ShellFolder2> topFolderList = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    static int compareShellFolders(Win32ShellFolder2 sf1, Win32ShellFolder2 sf2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        boolean special1 = sf1.isSpecial();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        boolean special2 = sf2.isSpecial();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        if (special1 || special2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            if (topFolderList == null) {
25192
4e2dc0f8702d 8044551: Fix raw and unchecked lint warnings in platform-specific sun.awt files
henryjen
parents: 24520
diff changeset
   473
                ArrayList<Win32ShellFolder2> tmpTopFolderList = new ArrayList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                tmpTopFolderList.add(Win32ShellFolderManager2.getPersonal());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                tmpTopFolderList.add(Win32ShellFolderManager2.getDesktop());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                tmpTopFolderList.add(Win32ShellFolderManager2.getDrives());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                tmpTopFolderList.add(Win32ShellFolderManager2.getNetwork());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                topFolderList = tmpTopFolderList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            int i1 = topFolderList.indexOf(sf1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            int i2 = topFolderList.indexOf(sf2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            if (i1 >= 0 && i2 >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                return (i1 - i2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            } else if (i1 >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            } else if (i2 >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        // Non-file shellfolders sort before files
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        if (special1 && !special2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        } else if (special2 && !special1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            return  1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        return compareNames(sf1.getAbsolutePath(), sf2.getAbsolutePath());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    static int compareNames(String name1, String name2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        // First ignore case when comparing
678
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 454
diff changeset
   503
        int diff = name1.compareToIgnoreCase(name2);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        if (diff != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            return diff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            // May differ in case (e.g. "mail" vs. "Mail")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
            // We need this test for consistent sorting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            return name1.compareTo(name2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    }
2489
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 715
diff changeset
   512
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 715
diff changeset
   513
    @Override
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 715
diff changeset
   514
    protected Invoker createInvoker() {
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 715
diff changeset
   515
        return new ComInvoker();
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 715
diff changeset
   516
    }
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 715
diff changeset
   517
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 715
diff changeset
   518
    private static class ComInvoker extends ThreadPoolExecutor implements ThreadFactory, ShellFolder.Invoker {
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 715
diff changeset
   519
        private static Thread comThread;
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 715
diff changeset
   520
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 715
diff changeset
   521
        private ComInvoker() {
29922
7b9c1e1532cf 8027771: Enhance thread contexts
serb
parents: 28556
diff changeset
   522
            super(1, 1, 0, TimeUnit.DAYS, new LinkedBlockingQueue<>());
2489
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 715
diff changeset
   523
            allowCoreThreadTimeOut(false);
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 715
diff changeset
   524
            setThreadFactory(this);
29922
7b9c1e1532cf 8027771: Enhance thread contexts
serb
parents: 28556
diff changeset
   525
            final Runnable shutdownHook = () -> AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
7b9c1e1532cf 8027771: Enhance thread contexts
serb
parents: 28556
diff changeset
   526
                shutdownNow();
7b9c1e1532cf 8027771: Enhance thread contexts
serb
parents: 28556
diff changeset
   527
                return null;
7b9c1e1532cf 8027771: Enhance thread contexts
serb
parents: 28556
diff changeset
   528
            });
7b9c1e1532cf 8027771: Enhance thread contexts
serb
parents: 28556
diff changeset
   529
            AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
37550
c8252b8fea3d 8147544: Remove sun.misc.ManagedLocalsThread from java.desktop
prr
parents: 35667
diff changeset
   530
                Thread t = new Thread(
c8252b8fea3d 8147544: Remove sun.misc.ManagedLocalsThread from java.desktop
prr
parents: 35667
diff changeset
   531
                        ThreadGroupUtils.getRootThreadGroup(), shutdownHook,
c8252b8fea3d 8147544: Remove sun.misc.ManagedLocalsThread from java.desktop
prr
parents: 35667
diff changeset
   532
                        "ShellFolder", 0, false);
29922
7b9c1e1532cf 8027771: Enhance thread contexts
serb
parents: 28556
diff changeset
   533
                Runtime.getRuntime().addShutdownHook(t);
7b9c1e1532cf 8027771: Enhance thread contexts
serb
parents: 28556
diff changeset
   534
                return null;
2489
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 715
diff changeset
   535
            });
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 715
diff changeset
   536
        }
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 715
diff changeset
   537
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 715
diff changeset
   538
        public synchronized Thread newThread(final Runnable task) {
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 715
diff changeset
   539
            final Runnable comRun = new Runnable() {
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 715
diff changeset
   540
                public void run() {
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 715
diff changeset
   541
                    try {
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 715
diff changeset
   542
                        initializeCom();
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 715
diff changeset
   543
                        task.run();
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 715
diff changeset
   544
                    } finally {
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 715
diff changeset
   545
                        uninitializeCom();
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 715
diff changeset
   546
                    }
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 715
diff changeset
   547
                }
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 715
diff changeset
   548
            };
29922
7b9c1e1532cf 8027771: Enhance thread contexts
serb
parents: 28556
diff changeset
   549
            comThread = AccessController.doPrivileged((PrivilegedAction<Thread>) () -> {
7b9c1e1532cf 8027771: Enhance thread contexts
serb
parents: 28556
diff changeset
   550
                String name = "Swing-Shell";
31653
d88ff422c7fb 8080405: Exception in thread "AWT-EventQueue-1" java.security.AccessControlException
serb
parents: 31430
diff changeset
   551
                 /* The thread must be a member of a thread group
d88ff422c7fb 8080405: Exception in thread "AWT-EventQueue-1" java.security.AccessControlException
serb
parents: 31430
diff changeset
   552
                  * which will not get GCed before VM exit.
d88ff422c7fb 8080405: Exception in thread "AWT-EventQueue-1" java.security.AccessControlException
serb
parents: 31430
diff changeset
   553
                  * Make its parent the top-level thread group.
d88ff422c7fb 8080405: Exception in thread "AWT-EventQueue-1" java.security.AccessControlException
serb
parents: 31430
diff changeset
   554
                  */
37550
c8252b8fea3d 8147544: Remove sun.misc.ManagedLocalsThread from java.desktop
prr
parents: 35667
diff changeset
   555
                Thread thread = new Thread(
c8252b8fea3d 8147544: Remove sun.misc.ManagedLocalsThread from java.desktop
prr
parents: 35667
diff changeset
   556
                        ThreadGroupUtils.getRootThreadGroup(), comRun, name,
c8252b8fea3d 8147544: Remove sun.misc.ManagedLocalsThread from java.desktop
prr
parents: 35667
diff changeset
   557
                        0, false);
29922
7b9c1e1532cf 8027771: Enhance thread contexts
serb
parents: 28556
diff changeset
   558
                thread.setDaemon(true);
47190
8aff50fc76a5 8175015: FileSystemView.isDrive(File) memory leak on "C:\" file reference
pkbalakr
parents: 39515
diff changeset
   559
                /* This is important, since this thread running at lower priority
8aff50fc76a5 8175015: FileSystemView.isDrive(File) memory leak on "C:\" file reference
pkbalakr
parents: 39515
diff changeset
   560
                   leads to memory consumption when listDrives() function is called
8aff50fc76a5 8175015: FileSystemView.isDrive(File) memory leak on "C:\" file reference
pkbalakr
parents: 39515
diff changeset
   561
                   repeatedly.
8aff50fc76a5 8175015: FileSystemView.isDrive(File) memory leak on "C:\" file reference
pkbalakr
parents: 39515
diff changeset
   562
                 */
8aff50fc76a5 8175015: FileSystemView.isDrive(File) memory leak on "C:\" file reference
pkbalakr
parents: 39515
diff changeset
   563
                thread.setPriority(Thread.MAX_PRIORITY);
29922
7b9c1e1532cf 8027771: Enhance thread contexts
serb
parents: 28556
diff changeset
   564
                return thread;
7b9c1e1532cf 8027771: Enhance thread contexts
serb
parents: 28556
diff changeset
   565
            });
2489
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 715
diff changeset
   566
            return comThread;
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 715
diff changeset
   567
        }
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 715
diff changeset
   568
3346
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
   569
        public <T> T invoke(Callable<T> task) throws Exception {
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
   570
            if (Thread.currentThread() == comThread) {
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
   571
                // if it's already called from the COM
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
   572
                // thread, we don't need to delegate the task
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
   573
                return task.call();
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
   574
            } else {
3507
1610d6f5a0e3 6461173: One JCK test([NewFolderAction0001]) failed on Windows due to lack of PropertyPermission(s)
rupashka
parents: 3346
diff changeset
   575
                final Future<T> future;
3346
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
   576
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
   577
                try {
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
   578
                    future = submit(task);
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
   579
                } catch (RejectedExecutionException e) {
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
   580
                    throw new InterruptedException(e.getMessage());
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
   581
                }
2817
f171f2417978 6713352: Deadlock in JFileChooser with synchronized custom FileSystemView
rupashka
parents: 2489
diff changeset
   582
3346
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
   583
                try {
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
   584
                    return future.get();
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
   585
                } catch (InterruptedException e) {
3507
1610d6f5a0e3 6461173: One JCK test([NewFolderAction0001]) failed on Windows due to lack of PropertyPermission(s)
rupashka
parents: 3346
diff changeset
   586
                    AccessController.doPrivileged(new PrivilegedAction<Void>() {
1610d6f5a0e3 6461173: One JCK test([NewFolderAction0001]) failed on Windows due to lack of PropertyPermission(s)
rupashka
parents: 3346
diff changeset
   587
                        public Void run() {
1610d6f5a0e3 6461173: One JCK test([NewFolderAction0001]) failed on Windows due to lack of PropertyPermission(s)
rupashka
parents: 3346
diff changeset
   588
                            future.cancel(true);
1610d6f5a0e3 6461173: One JCK test([NewFolderAction0001]) failed on Windows due to lack of PropertyPermission(s)
rupashka
parents: 3346
diff changeset
   589
1610d6f5a0e3 6461173: One JCK test([NewFolderAction0001]) failed on Windows due to lack of PropertyPermission(s)
rupashka
parents: 3346
diff changeset
   590
                            return null;
1610d6f5a0e3 6461173: One JCK test([NewFolderAction0001]) failed on Windows due to lack of PropertyPermission(s)
rupashka
parents: 3346
diff changeset
   591
                        }
1610d6f5a0e3 6461173: One JCK test([NewFolderAction0001]) failed on Windows due to lack of PropertyPermission(s)
rupashka
parents: 3346
diff changeset
   592
                    });
3346
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
   593
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
   594
                    throw e;
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
   595
                } catch (ExecutionException e) {
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
   596
                    Throwable cause = e.getCause();
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
   597
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
   598
                    if (cause instanceof Exception) {
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
   599
                        throw (Exception) cause;
2489
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 715
diff changeset
   600
                    }
3346
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
   601
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
   602
                    if (cause instanceof Error) {
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
   603
                        throw (Error) cause;
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
   604
                    }
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
   605
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
   606
                    throw new RuntimeException("Unexpected error", cause);
2489
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 715
diff changeset
   607
                }
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 715
diff changeset
   608
            }
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 715
diff changeset
   609
        }
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 715
diff changeset
   610
    }
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 715
diff changeset
   611
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 715
diff changeset
   612
    static native void initializeCom();
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 715
diff changeset
   613
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 715
diff changeset
   614
    static native void uninitializeCom();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
}