KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > intro > impl > model > AbstractBaseIntroElement


1 /*******************************************************************************
2  * Copyright (c) 2004, 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
12 package org.eclipse.ui.internal.intro.impl.model;
13
14 import org.eclipse.core.runtime.IConfigurationElement;
15 import org.osgi.framework.Bundle;
16 import org.w3c.dom.Element JavaDoc;
17
18
19 /**
20  * An Intro Config component that has an id attribute and a style-id attribute.
21  * It also has the notion of filtering. Only model elements that have meaning in
22  * the UI, and that are targettable can be filtered. HEAD, for example, only
23  * applied to HTML presentation, and so, it does not need filtering. When model
24  * is first loaded, all elements are not filtered. When the UI is created, and
25  * we know which presentation we are using, the filter state is computed
26  * dynamically. Also, in the SWT presentation, when style manager picks
27  * elements, it may alter the filter state of a given element to prevent it from
28  * appearing twice in the ui. eg: title appearing as a title of the form, and as
29  * a title child text.
30  */

31 public abstract class AbstractBaseIntroElement extends AbstractIntroIdElement {
32
33     protected static final String JavaDoc ATT_STYLE_ID = "style-id"; //$NON-NLS-1$
34
protected static final String JavaDoc ATT_FILTERED_FROM = "filteredFrom"; //$NON-NLS-1$
35

36     protected String JavaDoc style_id;
37     protected String JavaDoc filteredFrom;
38     private boolean isFiltered;
39
40     AbstractBaseIntroElement(IConfigurationElement element) {
41         super(element);
42         style_id = element.getAttribute(ATT_STYLE_ID);
43         filteredFrom = element.getAttribute(ATT_FILTERED_FROM);
44     }
45
46     AbstractBaseIntroElement(Element element, Bundle bundle) {
47         super(element, bundle);
48         style_id = getAttribute(element, ATT_STYLE_ID);
49         filteredFrom = getAttribute(element, ATT_FILTERED_FROM);
50     }
51
52     /**
53      * Filter this element out based on the presentation kind.
54      *
55      */

56     private boolean checkFilterState() {
57         if (this.isOfType(AbstractIntroElement.MODEL_ROOT))
58             // root element is not filtered.
59
return false;
60         IntroModelRoot root = (IntroModelRoot) getParentPage().getParent();
61         return root.getPresentation().getImplementationKind().equals(
62             filteredFrom) ? true : false;
63     }
64
65
66     /**
67      * @return Returns the class id.
68      */

69     public String JavaDoc getStyleId() {
70         return style_id;
71     }
72     
73     protected void loadFromParent() {
74         style_id = getAttribute(getElement(), ATT_STYLE_ID);
75         filteredFrom = getAttribute(getElement(), ATT_FILTERED_FROM);
76     }
77
78     /**
79      * @return Returns the filter_kind.
80      */

81     public String JavaDoc getFilteredFrom() {
82         return filteredFrom;
83     }
84
85     /**
86      * Return the filter state of this intro element. We need to do this when
87      * this element has been added to the model, and it has a parent. Also, this
88      * method will not be valid if the UI has not been loaded yet because it it
89      * the creation of the UI that determines the presentation details.
90      *
91      * @return Returns the isFiltered.
92      */

93     public boolean isFiltered() {
94         return checkFilterState() || isFiltered;
95     }
96
97     public void setFilterState(boolean state) {
98         isFiltered = state;
99     }
100
101
102
103 }
104
Popular Tags