KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > texteditor > rulers > RulerColumnPlacement


1 /*******************************************************************************
2  * Copyright (c) 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.internal.texteditor.rulers;
12
13 import java.util.Collections JavaDoc;
14 import java.util.LinkedHashSet JavaDoc;
15 import java.util.Set JavaDoc;
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 /**
25  * Describes the placement specification of a contribution to the
26  * <code>org.eclipse.ui.texteditor.rulerColumns</code> extension point.
27  *
28  * @since 3.3
29  */

30 public final class RulerColumnPlacement {
31     /** The extension schema name of the id attribute. */
32     private static final String JavaDoc ID= "id"; //$NON-NLS-1$
33
/** The extension schema name of the optional gravity attribute. */
34     private static final String JavaDoc GRAVITY= "gravity"; //$NON-NLS-1$
35
/** The extension schema name of the before element. */
36     private static final String JavaDoc BEFORE= "before"; //$NON-NLS-1$
37
/** The extension schema name of the after element. */
38     private static final String JavaDoc AFTER= "after"; //$NON-NLS-1$
39

40     /** The placement gravity. */
41     private final float fGravity;
42     /** The placement constraints (element type: {@link RulerColumnPlacementConstraint}). */
43     private final Set JavaDoc 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 JavaDoc readIds(ILog log, IConfigurationElement[] children) {
62         Set JavaDoc constraints= new LinkedHashSet JavaDoc((int) (children.length / 0.75) + 1, 0.75f);
63         for (int i= 0; i < children.length; i++) {
64             IConfigurationElement child= children[i];
65             String JavaDoc 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     /**
82      * The gravity of the placement specification, a float in the range <code>[0, 1]</code>.
83      *
84      * @return the gravity of the placement specification
85      */

86     public float getGravity() {
87         return fGravity;
88     }
89
90     /**
91      * Returns the placement constraints in the order that they appear in the extension declaration.
92      *
93      * @return the unmodifiable set of placement constraints in the order that they appear in the
94      * extension declaration
95      */

96     public Set JavaDoc getConstraints() {
97         return fConstraints;
98     }
99 }
100
Popular Tags