1 11 package org.eclipse.ui.internal.texteditor.rulers; 12 13 import java.util.Collections ; 14 import java.util.LinkedHashSet ; 15 import java.util.Set ; 16 17 import org.eclipse.core.runtime.Assert; 18 import org.eclipse.core.runtime.IConfigurationElement; 19 import org.eclipse.core.runtime.ILog; 20 import org.eclipse.core.runtime.InvalidRegistryObjectException; 21 22 import org.eclipse.ui.internal.texteditor.TextEditorPlugin; 23 24 30 public final class RulerColumnPlacement { 31 32 private static final String ID= "id"; 34 private static final String GRAVITY= "gravity"; 36 private static final String BEFORE= "before"; 38 private static final String AFTER= "after"; 40 41 private final float fGravity; 42 43 private final Set fConstraints; 44 45 public RulerColumnPlacement() { 46 fGravity= 1f; 47 fConstraints= Collections.EMPTY_SET; 48 } 49 50 public RulerColumnPlacement(IConfigurationElement element) throws InvalidRegistryObjectException { 51 Assert.isLegal(element != null); 52 ILog log= TextEditorPlugin.getDefault().getLog(); 53 ExtensionPointHelper helper= new ExtensionPointHelper(element, log); 54 55 fGravity= helper.getDefaultAttribute(GRAVITY, 1f); 56 if (fGravity < 0 || fGravity > 1) 57 helper.fail(RulerColumnMessages.RulerColumnPlacement_illegal_gravity_msg); 58 fConstraints= readIds(log, element.getChildren()); 59 } 60 61 private Set readIds(ILog log, IConfigurationElement[] children) { 62 Set constraints= new LinkedHashSet ((int) (children.length / 0.75) + 1, 0.75f); 63 for (int i= 0; i < children.length; i++) { 64 IConfigurationElement child= children[i]; 65 String name= child.getName(); 66 ExtensionPointHelper childHelper= new ExtensionPointHelper(child, log); 67 boolean before; 68 if (AFTER.equals(name)) 69 before= false; 70 else if (BEFORE.equals(name)) 71 before= true; 72 else { 73 childHelper.fail(RulerColumnMessages.RulerColumnPlacement_illegal_child_msg); 74 continue; 75 } 76 constraints.add(new RulerColumnPlacementConstraint(childHelper.getNonNullAttribute(ID), before)); 77 } 78 return Collections.unmodifiableSet(constraints); 79 } 80 81 86 public float getGravity() { 87 return fGravity; 88 } 89 90 96 public Set getConstraints() { 97 return fConstraints; 98 } 99 } 100 | Popular Tags |