NBIFileAssosiations

Registering file assosiations

Typical example of registering file assosiation is shown below.

This code is to be placed in install() method of the logic. It will register ".css" extension with text/css mime type and will assosiate program, returned by getExecutable() as the non-default viewer and will add this program to the "open-with" list in the right-click menu:

    if (SystemUtils.isWindows()) {
            WindowsNativeUtils utils = (WindowsNativeUtils) SystemUtils.getNativeUtils();
            SystemApplication app = new SystemApplication(new File(installLocation, getExecutable()));
            app.setFriendlyName(getSystemDisplayName());
            app.setOpenWithList(true);
            app.setByDefault(false);
            FileExtension ext = new FileExtension("css");
            ext.setPerceivedType(PerceivedType.TEXT);
            ext.setMimeType("text/css");

            try {
                    utils.setFileAssociation(ext, app, getProduct().getProperties());  
                                
            } catch (NativeException e) {
                LogManager.log(e);
            }
        }


This code will remove the info the uninstall method():

if (SystemUtils.isWindows()) {
            WindowsNativeUtils utils = (WindowsNativeUtils) SystemUtils.getNativeUtils();
            SystemApplication app = new SystemApplication(new File(installLocation, getExecutable()));
            app.setFriendlyName(getSystemDisplayName());
            app.setOpenWithList(true);
            app.setByDefault(false);
            FileExtension ext = new FileExtension("css");
            ext.setPerceivedType(PerceivedType.TEXT);
            ext.setMimeType("text/css");

            try {
                    utils.removeFileAssociation(ext, app, getProduct().getProperties());  
                                
            } catch (NativeException e) {
                LogManager.log(e);
            }
        }
Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo