1 11 package org.eclipse.pde.internal.ui.editor.plugin; 12 13 import java.util.HashMap ; 14 import java.util.Map ; 15 import java.util.Set ; 16 17 import org.eclipse.jface.text.BadLocationException; 18 import org.eclipse.jface.text.IDocument; 19 import org.eclipse.jface.text.Position; 20 import org.eclipse.pde.internal.core.ibundle.IBundle; 21 import org.eclipse.pde.internal.core.ibundle.IManifestHeader; 22 import org.eclipse.pde.internal.core.text.IEditingModel; 23 import org.eclipse.pde.internal.core.text.bundle.BundleModel; 24 import org.eclipse.pde.internal.ui.editor.AbstractFoldingStructureProvider; 25 import org.eclipse.pde.internal.ui.editor.PDESourcePage; 26 import org.osgi.framework.Constants; 27 28 public class BundleFoldingStructureProvider extends 29 AbstractFoldingStructureProvider { 30 31 private Map fPositionToElement = new HashMap (); 32 33 public BundleFoldingStructureProvider(PDESourcePage editor, IEditingModel model) { 34 super(editor, model); 35 } 36 37 public void addFoldingRegions(Set currentRegions, IEditingModel model) 38 throws BadLocationException { 39 IBundle bundle = ((BundleModel) model).getBundle(); 40 41 IManifestHeader importPackageHeader = bundle.getManifestHeader(Constants.IMPORT_PACKAGE); 42 IManifestHeader exportPackageHeader = bundle.getManifestHeader(Constants.EXPORT_PACKAGE); 43 IManifestHeader requireBundleHeader = bundle.getManifestHeader(Constants.REQUIRE_BUNDLE); 44 45 try { 46 addFoldingRegions(currentRegions, importPackageHeader, model.getDocument()); 47 addFoldingRegions(currentRegions, exportPackageHeader, model.getDocument()); 48 addFoldingRegions(currentRegions, requireBundleHeader, model.getDocument()); 49 } catch (BadLocationException e) {} 50 51 } 52 53 private void addFoldingRegions(Set regions, IManifestHeader header, IDocument document) throws BadLocationException { 54 if(header == null) return; 55 int startLine = document.getLineOfOffset(header.getOffset()); 56 int endLine = document.getLineOfOffset(header.getOffset() + header.getLength() - 1); 57 if (startLine < endLine) { 58 int start = document.getLineOffset(startLine); 59 int end = document.getLineOffset(endLine) + document.getLineLength(endLine); 60 Position position = new Position(start, end - start); 61 regions.add(position); 62 fPositionToElement.put(position, header); 63 } 64 } 65 66 } 67 | Popular Tags |