1 19 20 package org.netbeans.modules.editor.impl; 21 22 import java.util.ArrayList ; 23 import java.util.Collections ; 24 import java.util.List ; 25 import org.netbeans.api.editor.mimelookup.MimeLookup; 26 import org.netbeans.api.editor.mimelookup.MimePath; 27 import org.netbeans.spi.editor.mimelookup.Class2LayerFolder; 28 import org.netbeans.spi.editor.mimelookup.InstanceProvider; 29 import org.openide.filesystems.FileObject; 30 import org.openide.loaders.DataObject; 31 32 36 public final class ToolbarActionsProvider extends ActionsList implements Class2LayerFolder, InstanceProvider { 37 38 private static final String TOOLBAR_ACTIONS_FOLDER_NAME = "Toolbars/Default"; private static final String TEXT_BASE_PATH = "Editors/text/base/"; 41 public static List getToolbarItems(String mimeType) { 42 MimePath mimePath = MimePath.parse(mimeType); 43 ActionsList provider; 44 if (mimeType.equals("text/base")) { provider = MimeLookup.getLookup(mimePath).lookup(LegacyToolbarActionsProvider.class); 46 } else { 47 provider = MimeLookup.getLookup(mimePath).lookup(ToolbarActionsProvider.class); 48 } 49 return provider == null ? Collections.emptyList() : provider.getAllInstances(); 50 } 51 52 public ToolbarActionsProvider() { 53 super(null); 54 } 55 56 private ToolbarActionsProvider(List keys) { 57 super(keys, true); 58 } 59 60 public Class getClazz(){ 61 return ToolbarActionsProvider.class; 62 } 63 64 public String getLayerFolderName(){ 65 return TOOLBAR_ACTIONS_FOLDER_NAME; 66 } 67 68 public InstanceProvider getInstanceProvider() { 69 return new ToolbarActionsProvider(); 70 } 71 72 public Object createInstance(List fileObjectList) { 73 return new ToolbarActionsProvider(fileObjectList); 74 } 75 76 public static final class LegacyToolbarActionsProvider extends ActionsList implements Class2LayerFolder, InstanceProvider { 80 81 public LegacyToolbarActionsProvider() { 82 super(null); 83 } 84 85 private LegacyToolbarActionsProvider(List keys) { 86 super(keys); 87 } 88 89 public Class getClazz(){ 90 return LegacyToolbarActionsProvider.class; 91 } 92 93 public String getLayerFolderName(){ 94 return TOOLBAR_ACTIONS_FOLDER_NAME; 95 } 96 97 public InstanceProvider getInstanceProvider() { 98 return new LegacyToolbarActionsProvider(); 99 } 100 101 public Object createInstance(List fileObjectList) { 102 ArrayList <FileObject> textBaseFilesList = new ArrayList <FileObject>(); 103 104 for(Object o : fileObjectList) { 105 FileObject fileObject = null; 106 107 if (o instanceof DataObject) { 108 fileObject = ((DataObject) o).getPrimaryFile(); 109 } else if (o instanceof FileObject) { 110 fileObject = (FileObject) o; 111 } else { 112 continue; 113 } 114 115 String fullPath = fileObject.getPath(); 116 int idx = fullPath.lastIndexOf(TOOLBAR_ACTIONS_FOLDER_NAME); 117 assert idx != -1 : "Expecting files with '" + TOOLBAR_ACTIONS_FOLDER_NAME + "' in the path: " + fullPath; 119 String path = fullPath.substring(0, idx); 120 if (TEXT_BASE_PATH.equals(path)) { 121 textBaseFilesList.add(fileObject); 122 } 123 } 124 125 return new LegacyToolbarActionsProvider(textBaseFilesList); 126 } 127 } } 129 | Popular Tags |