alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 *
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 *
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

package org.netbeans.modules.editor.fold;

import java.lang.reflect.Constructor;
import java.util.Collections;
import java.util.List;
import org.netbeans.api.editor.fold.FoldHierarchy;
import org.openide.ErrorManager;

/**
 * Provides list of fold factories that produce fold managers
 * for the given fold hierarchy.
 *
 * 

* The default implementation NbFoldManagerFactoryProvider * in fact first obtains a mime-type by using * hierarchySpi.getComponent().getEditorKit().getContentType() * and then inspects the contents of the following folder in the system FS:

 *     Editors//FoldManager
 * 
* * @author Miloslav Metelka * @version 1.00 */ public abstract class FoldManagerFactoryProvider { private static FoldManagerFactoryProvider defaultProvider; private static FoldManagerFactoryProvider emptyProvider; private static boolean forceCustom; /** * Get the default provider used to produce the managers. *
* This method gets called by FoldHierarchyExecution * when rebuilding the managers. */ public static synchronized FoldManagerFactoryProvider getDefault() { if (defaultProvider == null) { defaultProvider = findDefault(); } return defaultProvider; } /** * Return provider that provides empty list of factories. *
* This method may be used e.g. by FoldHierarchyExecution * if the code folding is disabled in editor options. */ public static FoldManagerFactoryProvider getEmpty() { if (emptyProvider == null) { // Multiple EmptyProvider can be created as method is not synced // but should be no harm emptyProvider = new EmptyProvider(); } return emptyProvider; } /** * This method enforces the use of custom provider * instead of the default layer-based provider. *
* It can be used e.g. for testing purposes. * * @param forceCustomProvider whether the instance * of the {@link CustomProvider} should be used forcibly. */ public static synchronized void setForceCustomProvider(boolean forceCustomProvider) { if (!forceCustom) { defaultProvider = null; } forceCustom = forceCustomProvider; } private static FoldManagerFactoryProvider findDefault() { FoldManagerFactoryProvider provider = null; // By default use layer-based fold manager factory registrations. // In case of standalone editor the custom provider // will be used allowing custom fold manager factories registrations // (public packages restrictions should not apply). if (!forceCustom) { try { org.openide.filesystems.Repository repository = org.openide.filesystems.Repository.getDefault(); if (repository != null && repository.getDefaultFileSystem() != null) { provider = new LayerProvider(); } } catch (Throwable t) { // FileObject class not found -> use layer } } if (provider == null) { provider = new CustomProvider(); } return provider; } /** * Get fold managers appropriate for the given fold hierarchy. * * @param hierarchy fold hierarchy for which the fold managers * are being created. * @return list of FoldManagerFactorys to be used * for the given hierarchy. *
* The order of the factories in the returned list defines * priority of the folds produced by the corresponding manager * (manager produced by the factory being first in the list * produces the most important folds). *
* The list must not be modified by the clients. */ public abstract List getFactoryList(FoldHierarchy hierarchy); /** * Provider giving empty list of factories. */ private static final class EmptyProvider extends FoldManagerFactoryProvider { public List getFactoryList(FoldHierarchy hierarchy) { return java.util.Collections.EMPTY_LIST; } } }
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.