+ Initial version of Knockout Integration API published. +
+This document lists changes made to the Knockout Integration API.
+ + +@FOOTER@
+ + ++ Java model class + to describe JSON-like Knockout bindings and register + a provider + used by the editor infrastructure to query for the model. +
++ There are some unit tests. The integration with editor is then tested + manually. +
++ Let's offer this API for 8.1 release. +
++This is the code to register a sample provider: +
++{@code @}ServiceProvider(service = BindingsProvider.class) +public class SampleBindingsProvider implements {@link org.netbeans.spi.knockout.BindingsProvider} { + {@code @Override} + public void findBindings(FileObject htmlFile, Response r) { + Bindings tweet = Bindings.create("Tweet"). + stringProperty("from_user", false). + intProperty("from_user_id", false); + + Bindings tweeters = Bindings.create("Tweeters"). + stringProperty("name", false). + stringProperty("userNames", true); + + Bindings twitterClient = Bindings.create("TwitterClient"); + twitterClient. + stringProperty("activeTweetersName", false). + stringProperty("activeTweeters", true). + stringProperty("userNameToAdd", false). + booleanProperty("loading", false). + modelProperty("currentTweets", tweet, true). + modelProperty("savedLists", tweeters, true); + + r.applyBindings(twitterClient); + } +} ++ +
+This sample has been used when testing the module. +
++ XXX no answer for compat-deprecation +
++ XXX no answer for compat-i18n +
++ XXX no answer for compat-standards +
++ XXX no answer for compat-version +
++ XXX no answer for dep-jre +
++ XXX no answer for dep-jrejdk +
++ XXX no answer for dep-non-nb +
++ XXX no answer for dep-platform +
++ XXX no answer for deploy-dependencies +
++ XXX no answer for deploy-jar +
++ XXX no answer for deploy-nbm +
++ XXX no answer for deploy-packages +
++ XXX no answer for deploy-shared +
++ XXX no answer for exec-ant-tasks +
++ XXX no answer for exec-classloader +
++ XXX no answer for exec-component +
++ XXX no answer for exec-introspection +
++ XXX no answer for exec-privateaccess +
++ XXX no answer for exec-process +
++ XXX no answer for exec-property +
++ XXX no answer for exec-reflection +
++ XXX no answer for exec-threading +
++ XXX no answer for format-clipboard +
++ XXX no answer for format-dnd +
++ XXX no answer for format-types +
++ XXX no answer for lookup-lookup +
++ XXX no answer for lookup-register +
++ XXX no answer for lookup-remove +
++ XXX no answer for perf-exit +
++ XXX no answer for perf-huge_dialogs +
++ XXX no answer for perf-limit +
++ XXX no answer for perf-mem +
++ XXX no answer for perf-menus +
++ XXX no answer for perf-progress +
++ XXX no answer for perf-scale +
++ XXX no answer for perf-spi +
++ XXX no answer for perf-startup +
++ XXX no answer for perf-wakeup +
++ XXX no answer for resources-file +
++ XXX no answer for resources-layer +
++ XXX no answer for resources-mask +
++ XXX no answer for resources-preferences +
++ XXX no answer for resources-read +
++ XXX no answer for security-grant +
++ XXX no answer for security-policy +
+ko.applyBindings
parameter.
+ * Register as {@link BindingsProvider}. When called build description of JSON
+ * types using methods like {@link #stringProperty(java.lang.String, boolean)}
+ * and then pass the result into
+ * {@link Response#applyBindings(org.netbeans.spi.knockout.Bindings)} method.
+ *
+ * @author Jaroslav Tulach true
) into the JSON
+ * class.
+ *
+ * @param name name of variable (must be valid JavaScript identifier)
+ * @param array should this property be an array of just a single value
+ * @return this object
+ */
+ public final Bindings booleanProperty(String name, boolean array) {
+ addProp(name, array, "true");
+ return this;
+ }
+
+ /**
+ * Generates a string property (with value ''
) into the JSON
+ * class.
+ *
+ * @param name name of variable (must be valid JavaScript identifier)
+ * @param array should this property be an array of just a single value
+ * @return this object
+ */
+ public final Bindings stringProperty(String name, boolean array) {
+ addProp(name, array, "''");
+ return this;
+ }
+
+ /**
+ * Generates a integer property (with value 0
) into the JSON
+ * class.
+ *
+ * @param name name of variable (must be valid JavaScript identifier)
+ * @param array should this property be an array of just a single value
+ * @return this object
+ */
+ public final Bindings intProperty(String name, boolean array) {
+ addProp(name, array, "0");
+ return this;
+ }
+
+ /**
+ * Generates a floating point property (with value 0.1
) into
+ * the JSON class.
+ *
+ * @param name name of variable (must be valid JavaScript identifier)
+ * @param array should this property be an array of just a single value
+ * @return this object
+ */
+ public final Bindings doubleProperty(String name, boolean array) {
+ addProp(name, array, "0.1");
+ return this;
+ }
+
+ /**
+ * Generates complex subtype based on another {@link Bindings} class.
+ *
+ * @param name name of variable (must be valid JavaScript identifier)
+ * @param binding another description of a JSON like object
+ * @param array should this property be an array of just a single value
+ * @return this object
+ */
+ public final Bindings modelProperty(String name, Bindings binding, boolean array) {
+ subBindings.add(binding);
+ addProp(name, array, binding.name);
+ return this;
+ }
+
+ final String generate() {
+ StringBuilder sb = new StringBuilder();
+ //sb.append("(function() {\n");
+ HashSet1
for now.
+ * @return either null
if no provider or format has been
+ * found for given file or a JavaScript code formated accordingly
+ */
+ public static String findBindings(FileObject htmlFile, int versionOfFormat) {
+ if (versionOfFormat != 1) {
+ return null;
+ }
+ Response r = new Response();
+ for (BindingsProvider p : Lookup.getDefault().lookupAll(BindingsProvider.class)) {
+ p.findBindings(htmlFile, r);
+ if (r.bindings != null) {
+ return r.bindings.generate();
+ }
+ }
+ return null;
+ }
+}
diff -r 236501ac78c6 api.knockout/src/org/netbeans/spi/knockout/BindingsProvider.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/api.knockout/src/org/netbeans/spi/knockout/BindingsProvider.java Fri Dec 19 11:53:20 2014 +0100
@@ -0,0 +1,103 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2013 Oracle and/or its affiliates. All rights reserved.
+ *
+ * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
+ * Other names may be trademarks of their respective owners.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common
+ * Development and Distribution License("CDDL") (collectively, the
+ * "License"). You may not use this file except in compliance with the
+ * License. You can obtain a copy of the License at
+ * http://www.netbeans.org/cddl-gplv2.html
+ * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
+ * specific language governing permissions and limitations under the
+ * License. When distributing the software, include this License Header
+ * Notice in each file and include the License file at
+ * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the
+ * License Header, with the fields enclosed by brackets [] replaced by
+ * your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ *
+ * If you wish your version of this file to be governed by only the CDDL
+ * or only the GPL Version 2, indicate your decision by adding
+ * "[Contributor] elects to include this software in this distribution
+ * under the [CDDL or GPL Version 2] license." If you do not indicate a
+ * single choice of license, a recipient has the option to distribute
+ * your version of this file under either the CDDL, the GPL Version 2 or
+ * to extend the choice of license to its licensees as provided above.
+ * However, if you add GPL Version 2 code and therefore, elected the GPL
+ * Version 2 license, then the option applies only if the new code is
+ * made subject to such option by the copyright holder.
+ *
+ * Contributor(s):
+ *
+ * Portions Copyrighted 2013 Sun Microsystems, Inc.
+ */
+package org.netbeans.spi.knockout;
+
+import org.openide.filesystems.FileObject;
+import org.openide.util.lookup.ServiceProvider;
+
+/** A provider that knows more about structure of Knockout bindings
+ * in an HTML page.
+ * Providers should be registered by {@link ServiceProvider} annotation
+ * so they can be found for a particular HTML file. Their {@link #findBindings(org.openide.filesystems.FileObject, org.netbeans.spi.knockout.BindingsProvider.Response) findBindings}
+ * method is called when a knockout code completion is about to be shown
+ * in the HTML editor and then can generate a JSON like description of
+ * the structure of knockout context via {@link Bindings} methods.
+ *
+ * @author Jaroslav Tulach