Introduce Gerrit gwtui common project

The new project hosts code that is reused between Gerrit core and GWT
based plugins.

Change-Id: I1a6e4352f681266c2ce664881a64d35bd2639299
This commit is contained in:
David Ostrovsky
2014-02-06 22:36:13 +01:00
parent ac2086d183
commit 520f8a9e23
13 changed files with 94 additions and 134 deletions

View File

@@ -15,6 +15,7 @@
-->
<module>
<inherits name="com.google.gwt.json.JSON"/>
<inherits name='com.google.gerrit.GerritGwtUICommon'/>
<define-linker name="gerrit_plugin" class="com.google.gerrit.plugin.linker.GerritPluginLinker"/>
<add-linker name="gerrit_plugin"/>

View File

@@ -1,54 +0,0 @@
// Copyright (C) 2013 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.plugin.client.rpc;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.user.client.rpc.AsyncCallback;
/** Wraps a String that was returned from a JSON API. */
public class NativeString extends JavaScriptObject {
private static final JavaScriptObject TYPE = init();
private static final native JavaScriptObject init()
/*-{ return $wnd.Gerrit.JsonString }-*/;
public final native String asString()
/*-{ return this; }-*/;
public static final
AsyncCallback<NativeString> unwrap(final AsyncCallback<String> cb) {
return new AsyncCallback<NativeString>() {
@Override
public void onSuccess(NativeString result) {
cb.onSuccess(result != null ? result.asString() : null);
}
@Override
public void onFailure(Throwable caught) {
cb.onFailure(caught);
}
};
}
public static final boolean is(JavaScriptObject o) {
return is(TYPE, o);
}
private static final native boolean is(JavaScriptObject T, JavaScriptObject o)
/*-{ return o instanceof T }-*/;
protected NativeString() {
}
}

View File

@@ -1,71 +0,0 @@
// Copyright (C) 2012 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.plugin.client.rpc;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsArray;
import com.google.gwt.json.client.JSONObject;
import java.util.AbstractList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
public class Natives {
/**
* Get the names of defined properties on the object. The returned set
* iterates in the native iteration order, which may match the source order.
*/
public static Set<String> keys(JavaScriptObject obj) {
if (obj != null) {
return new JSONObject(obj).keySet();
}
return Collections.emptySet();
}
public static <T extends JavaScriptObject> List<T> asList(
final JsArray<T> arr) {
if (arr == null) {
return null;
}
return new AbstractList<T>() {
@Override
public T set(int index, T element) {
T old = arr.get(index);
arr.set(index, element);
return old;
}
@Override
public T get(int index) {
return arr.get(index);
}
@Override
public int size() {
return arr.length();
}
};
}
public static <T extends JavaScriptObject> JsArray<T> arrayOf(T element) {
JsArray<T> arr = JavaScriptObject.createArray().cast();
arr.push(element);
return arr;
}
private Natives() {
}
}

View File

@@ -14,6 +14,7 @@
package com.google.gerrit.plugin.client.rpc;
import com.google.gerrit.client.rpc.NativeString;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.http.client.URL;
import com.google.gwt.user.client.rpc.AsyncCallback;