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:
042: package org.netbeans.modules.vmd.midpnb.producers;
043:
044: import org.netbeans.modules.vmd.api.model.*;
045: import org.netbeans.modules.vmd.midp.components.MidpDocumentSupport;
046: import org.netbeans.modules.vmd.midp.java.MidpJavaSupport;
047: import org.netbeans.modules.vmd.midp.components.categories.ResourcesCategoryCD;
048: import org.netbeans.modules.vmd.midp.components.displayables.DisplayableCD;
049: import org.netbeans.modules.vmd.midp.components.sources.CommandEventSourceCD;
050: import org.netbeans.modules.vmd.midp.producers.MidpComponentProducer;
051: import org.netbeans.modules.vmd.midpnb.components.commands.SVGWaitScreenFailureCommandCD;
052: import org.netbeans.modules.vmd.midpnb.components.commands.SVGWaitScreenSuccessCommandCD;
053: import org.netbeans.modules.vmd.midpnb.components.resources.SimpleCancellableTaskCD;
054: import org.netbeans.modules.vmd.midpnb.components.sources.SVGWaitScreenFailureCommandEventSourceCD;
055: import org.netbeans.modules.vmd.midpnb.components.sources.SVGWaitScreenSuccessCommandEventSourceCD;
056: import org.netbeans.modules.vmd.midpnb.components.svg.SVGWaitScreenCD;
057: import org.netbeans.modules.vmd.midpnb.palette.MidpNbPaletteProvider;
058: import org.openide.util.NbBundle;
059:
060: /**
061: *
062: * @author Anton Chechel
063: */
064: public class SVGWaitScreenProducer extends MidpComponentProducer {
065:
066: public SVGWaitScreenProducer() {
067: super (SVGWaitScreenCD.TYPEID, new PaletteDescriptor(
068: MidpNbPaletteProvider.CATEGORY_SVG, NbBundle
069: .getMessage(SVGWaitScreenProducer.class,
070: "DISP_SVG_Wait_Screen"), NbBundle
071: .getMessage(SVGWaitScreenProducer.class,
072: "TTIP_SVG_Wait_Screen"),
073: SVGWaitScreenCD.ICON_PATH,
074: SVGWaitScreenCD.ICON_LARGE_PATH)); // NOI18N
075: }
076:
077: @Override
078: public Result postInitialize(DesignDocument document,
079: DesignComponent waitScreen) {
080: return produceSVGWaitScreen(document, waitScreen, true);
081: }
082:
083: public static Result produceSVGWaitScreen(DesignDocument document,
084: DesignComponent waitScreen, boolean createTask) {
085: DesignComponent successCommand = MidpDocumentSupport
086: .getSingletonCommand(document,
087: SVGWaitScreenSuccessCommandCD.TYPEID);
088: DesignComponent failureCommand = MidpDocumentSupport
089: .getSingletonCommand(document,
090: SVGWaitScreenFailureCommandCD.TYPEID);
091:
092: DesignComponent successEventSource = document
093: .createComponent(SVGWaitScreenSuccessCommandEventSourceCD.TYPEID);
094: DesignComponent failureEventSource = document
095: .createComponent(SVGWaitScreenFailureCommandEventSourceCD.TYPEID);
096:
097: successEventSource.writeProperty(
098: CommandEventSourceCD.PROP_DISPLAYABLE, PropertyValue
099: .createComponentReference(waitScreen));
100: successEventSource.writeProperty(
101: CommandEventSourceCD.PROP_COMMAND, PropertyValue
102: .createComponentReference(successCommand));
103:
104: failureEventSource.writeProperty(
105: CommandEventSourceCD.PROP_DISPLAYABLE, PropertyValue
106: .createComponentReference(waitScreen));
107: failureEventSource.writeProperty(
108: CommandEventSourceCD.PROP_COMMAND, PropertyValue
109: .createComponentReference(failureCommand));
110:
111: MidpDocumentSupport.addEventSource(waitScreen,
112: DisplayableCD.PROP_COMMANDS, successEventSource);
113: MidpDocumentSupport.addEventSource(waitScreen,
114: DisplayableCD.PROP_COMMANDS, failureEventSource);
115:
116: if (createTask) {
117: DesignComponent task = document
118: .createComponent(SimpleCancellableTaskCD.TYPEID);
119: MidpDocumentSupport.getCategoryComponent(document,
120: ResourcesCategoryCD.TYPEID).addComponent(task);
121: waitScreen.writeProperty(SVGWaitScreenCD.PROP_TASK,
122: PropertyValue.createComponentReference(task));
123:
124: return new Result(waitScreen, successCommand,
125: failureCommand, successEventSource,
126: failureEventSource, task);
127: } else
128: return new Result(waitScreen, successCommand,
129: failureCommand, successEventSource,
130: failureEventSource);
131: }
132:
133: @Override
134: public Boolean checkValidity(DesignDocument document,
135: boolean useCachedValue) {
136: Boolean isValid1;
137: Boolean isValid2;
138: if (useCachedValue) {
139: isValid1 = MidpJavaSupport.getCache(document)
140: .checkValidityCached(
141: "javax.microedition.m2g.SVGImage"); // NOI18N
142: isValid2 = MidpJavaSupport.getCache(document)
143: .checkValidityCached(
144: "javax.microedition.lcdui.Canvas"); // NOI18N
145: } else {
146: isValid1 = MidpJavaSupport.checkValidity(document,
147: "javax.microedition.m2g.SVGImage"); // NOI18N
148: isValid2 = MidpJavaSupport.checkValidity(document,
149: "javax.microedition.lcdui.Canvas"); // NOI18N
150: }
151:
152: return isValid1 != null && isValid2 != null ? isValid1
153: && isValid2 : null;
154: }
155:
156: }
|