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: */package org.netbeans.modules.vmd.midpnb.components;
041:
042: import org.netbeans.modules.vmd.api.io.DataObjectContext;
043: import org.netbeans.modules.vmd.api.io.serialization.ComponentElement;
044: import org.netbeans.modules.vmd.api.io.serialization.DocumentSerializationController;
045: import org.netbeans.modules.vmd.api.io.serialization.PropertyElement;
046: import org.netbeans.modules.vmd.api.model.DesignComponent;
047: import org.netbeans.modules.vmd.api.model.DesignDocument;
048: import org.netbeans.modules.vmd.api.model.TypeID;
049: import org.netbeans.modules.vmd.midp.components.MidpDocumentSerializationController;
050: import org.netbeans.modules.vmd.midp.components.MidpDocumentSupport;
051: import org.netbeans.modules.vmd.midpnb.components.svg.SVGAnimatorWrapperCD;
052: import org.netbeans.modules.vmd.midpnb.components.svg.SVGPlayerCD;
053: import org.netbeans.modules.vmd.midpnb.components.displayables.FileBrowserCD;
054: import org.netbeans.modules.vmd.midpnb.components.displayables.PIMBrowserCD;
055: import org.netbeans.modules.vmd.midpnb.components.displayables.SMSComposerCD;
056:
057: import java.util.ArrayList;
058: import java.util.Collection;
059: import org.netbeans.modules.vmd.api.io.serialization.DocumentErrorHandler;
060:
061: /**
062: * @author David Kaspar
063: */
064: public class MidpCustomDocumentSerializationController extends
065: DocumentSerializationController {
066:
067: private static TypeID TYPEID_OLD_FILE_BROWSER = new TypeID(
068: TypeID.Kind.COMPONENT,
069: "org.netbeans.microedition.lcdui.FileBrowser"); // NOI18N
070: private static TypeID TYPEID_OLD_PIM_BROWSER = new TypeID(
071: TypeID.Kind.COMPONENT,
072: "org.netbeans.microedition.lcdui.PIMBrowser"); // NOI18N
073: private static TypeID TYPEID_OLD_SMS_COMPOSER = new TypeID(
074: TypeID.Kind.COMPONENT,
075: "org.netbeans.microedition.lcdui.SMSComposer"); // NOI18N
076:
077: public void approveComponents(DataObjectContext context,
078: DesignDocument loadingDocument, String documentVersion,
079: Collection<ComponentElement> componentElements,
080: DocumentErrorHandler errorHandler) {
081: if (!MidpDocumentSupport.PROJECT_TYPE_MIDP.equals(context
082: .getProjectType())
083: || !MidpDocumentSerializationController.VERSION_1
084: .equals(documentVersion))
085: return;
086: ArrayList<ComponentElement> elementsToRemove = new ArrayList<ComponentElement>();
087: ArrayList<ComponentElement> elementsToAdd = new ArrayList<ComponentElement>();
088: for (ComponentElement element : componentElements) {
089: if (SVGAnimatorWrapperCD.TYPEID.equals(element.getTypeID())) {
090: elementsToRemove.add(element);
091: elementsToAdd.add(ComponentElement.create(element
092: .getParentUID(), element.getUID(),
093: SVGPlayerCD.TYPEID, element.getNode()));
094: } else if (TYPEID_OLD_FILE_BROWSER.equals(element
095: .getTypeID())) {
096: elementsToRemove.add(element);
097: elementsToAdd.add(ComponentElement.create(element
098: .getParentUID(), element.getUID(),
099: FileBrowserCD.TYPEID, element.getNode()));
100: } else if (TYPEID_OLD_PIM_BROWSER.equals(element
101: .getTypeID())) {
102: elementsToRemove.add(element);
103: elementsToAdd.add(ComponentElement.create(element
104: .getParentUID(), element.getUID(),
105: PIMBrowserCD.TYPEID, element.getNode()));
106: } else if (TYPEID_OLD_SMS_COMPOSER.equals(element
107: .getTypeID())) {
108: elementsToRemove.add(element);
109: elementsToAdd.add(ComponentElement.create(element
110: .getParentUID(), element.getUID(),
111: SMSComposerCD.TYPEID, element.getNode()));
112: }
113: }
114: componentElements.removeAll(elementsToRemove);
115: componentElements.addAll(elementsToAdd);
116: }
117:
118: public void approveProperties(DataObjectContext context,
119: DesignDocument loadingDocument, String documentVersion,
120: DesignComponent component,
121: Collection<PropertyElement> propertyElements,
122: DocumentErrorHandler errorHandler) {
123: if (!MidpDocumentSupport.PROJECT_TYPE_MIDP.equals(context
124: .getProjectType())
125: || !MidpDocumentSerializationController.VERSION_1
126: .equals(documentVersion))
127: return;
128: if (loadingDocument.getDescriptorRegistry().isInHierarchy(
129: SVGPlayerCD.TYPEID, component.getType())) {
130: ArrayList<PropertyElement> elementsToRemove = new ArrayList<PropertyElement>();
131: ArrayList<PropertyElement> elementsToAdd = new ArrayList<PropertyElement>();
132: for (PropertyElement propertyElement : propertyElements) {
133: if (SVGPlayerCD.PROP_OLD_START_ANIM_IMMEDIATELY
134: .equals(propertyElement.getPropertyName())) {
135: elementsToRemove.add(propertyElement);
136: elementsToAdd.add(PropertyElement.create(
137: SVGPlayerCD.PROP_START_ANIM_IMMEDIATELY,
138: propertyElement.getTypeID(),
139: propertyElement.getSerialized()));
140: break;
141: }
142: }
143: propertyElements.removeAll(elementsToRemove);
144: propertyElements.addAll(elementsToAdd);
145: }
146: }
147:
148: public void postValidateDocument(DataObjectContext context,
149: DesignDocument loadingDocument, String documentVersion,
150: DocumentErrorHandler errorHandler) {
151: }
152:
153: }
|