001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.vmd.api.model;
042:
043: /**
044: * This class is designed for a privilege access to component. Each component could have a set of presenters attached to it.
045: * The presenters are created by ComponentDescriptor.createPresenters method on behalf of a component. The createPresenters
046: * method is called when a descriptor is reassigned to a component or a new component is created. The creation of a presenter
047: * basically means nothing and should be as fast as possible.
048: * <p>
049: * If you want to have a presenter that will react on changes in document, you should use DynamicPresenter.
050: *
051: * @author David Kaspar
052: */
053: public abstract class Presenter {
054:
055: private DesignComponent component;
056:
057: /**
058: * Creates a new presenter
059: */
060: protected Presenter() {
061: }
062:
063: /**
064: * Returns a component where the presenter is attached to.
065: * @return the component, null if not attached
066: */
067: protected final DesignComponent getComponent() {
068: return component;
069: }
070:
071: void setNotifyAttached(DesignComponent component) {
072: assert Debug.isFriend(ListenerManager.class,
073: "addComponentDescriptorChanged")
074: || Debug.isFriend(DynamicPresenter.class,
075: "setNotifyAttached"); // NOI18N
076: assert this .component == null && component != null;
077: this .component = component;
078: }
079:
080: void setNotifyDetached(DesignComponent component) {
081: assert Debug.isFriend(ListenerManager.class, "fireEventCore")
082: || Debug.isFriend(DynamicPresenter.class,
083: "setNotifyDetached"); // NOI18N
084: assert this .component == component;
085: this .component = null;
086: }
087:
088: /**
089: /**
090: * Returns string identification of the presenter.
091: * @return the string
092: */
093: @Override
094: public String toString() {
095: return (component != null ? component.toString()
096: : "<unassigned>")
097: + "#" + getClass().getSimpleName(); // NOI18N
098: }
099:
100: }
|