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.midp.components.displayables;
042:
043: import org.netbeans.modules.vmd.api.model.*;
044: import org.netbeans.modules.vmd.api.model.common.AcceptPresenter;
045: import org.netbeans.modules.vmd.api.model.common.AcceptSuggestion;
046: import org.netbeans.modules.vmd.midp.components.MidpDocumentSupport;
047: import org.netbeans.modules.vmd.midp.components.categories.CommandsCategoryCD;
048: import org.netbeans.modules.vmd.midp.components.commands.CommandCD;
049: import org.netbeans.modules.vmd.midp.components.sources.CommandEventSourceCD;
050:
051: /**
052: * @author David Kaspar
053: */
054: public class DisplayableAccept {
055:
056: static class DisplayableCommandsAcceptPresenter extends
057: AcceptPresenter {
058:
059: public DisplayableCommandsAcceptPresenter() {
060: super (Kind.COMPONENT_PRODUCER);
061: }
062:
063: @Override
064: public boolean isAcceptable(ComponentProducer producer,
065: AcceptSuggestion suggestion) {
066: if (getComponent().getComponentDescriptor()
067: .getPropertyDescriptor(DisplayableCD.PROP_COMMANDS)
068: .isReadOnly())
069: return false;
070: DescriptorRegistry registry = getComponent().getDocument()
071: .getDescriptorRegistry();
072: return registry.isInHierarchy(CommandCD.TYPEID, producer
073: .getMainComponentTypeID());
074: }
075:
076: @Override
077: public final ComponentProducer.Result accept(
078: ComponentProducer producer, AcceptSuggestion suggestion) {
079: DesignComponent displayable = getComponent();
080: DesignDocument document = displayable.getDocument();
081:
082: DesignComponent command = producer
083: .createComponent(document).getMainComponent();
084: MidpDocumentSupport.getCategoryComponent(document,
085: CommandsCategoryCD.TYPEID).addComponent(command);
086:
087: DesignComponent source = document
088: .createComponent(CommandEventSourceCD.TYPEID);
089: MidpDocumentSupport.addEventSource(displayable,
090: DisplayableCD.PROP_COMMANDS, source);
091:
092: source
093: .writeProperty(
094: CommandEventSourceCD.PROP_DISPLAYABLE,
095: PropertyValue
096: .createComponentReference(displayable));
097: source.writeProperty(CommandEventSourceCD.PROP_COMMAND,
098: PropertyValue.createComponentReference(command));
099:
100: return new ComponentProducer.Result(source);
101: }
102:
103: }
104:
105: // static class DisplayableCommandsEventHandlerAcceptPresenter extends AcceptPresenter {
106: //
107: // public boolean isAcceptable (ComponentProducer producer) {
108: // if (getComponent ().getComponentDescriptor ().getPropertyDescriptor (DisplayableCD.PROP_COMMANDS).isReadOnly ())
109: // return false;
110: // DescriptorRegistry registry = getComponent ().getDocument ().getDescriptorRegistry ();
111: // return registry.isInHierarchy (EventHandlerCD.TYPEID, producer.getMainComponentTypeID ());
112: // }
113: //
114: // public final void accept (ComponentProducer producer) {
115: // DesignComponent displayable = getComponent ();
116: // DesignDocument document = displayable.getDocument ();
117: //
118: // DesignComponent handler = producer.createComponent (document).getMainComponent ();
119: // if (handler == null)
120: // return;
121: //
122: // DesignComponent command = createBackCommand (document);
123: // MidpDocumentSupport.getCategoryComponent (document, CommandsCategoryCD.TYPEID).addComponent (command);
124: //
125: // DesignComponent source = document.createComponent (CommandEventSourceCD.TYPEID);
126: // MidpDocumentSupport.addEventSource (displayable, DisplayableCD.PROP_COMMANDS, source);
127: //
128: // source.writeProperty (CommandEventSourceCD.PROP_DISPLAYABLE, PropertyValue.createComponentReference (displayable));
129: // source.writeProperty (CommandEventSourceCD.PROP_COMMAND, PropertyValue.createComponentReference (command));
130: //
131: // MidpDocumentSupport.updateEventHandlerWithNew (source, handler);
132: // }
133: //
134: // private DesignComponent createBackCommand (DesignDocument document) {
135: // List<ComponentProducer> producers = document.getDescriptorRegistry ().getComponentProducers ();
136: // for (ComponentProducer producer : producers) {
137: // if (CommandProducer.PRODUCER_ID_BACK_COMMAND.equals (producer.getProducerID ()))
138: // return producer.createComponent (document).getMainComponent ();
139: // }
140: // return null;
141: // }
142: //
143: // }
144:
145: }
|