Merge "Enhance plugin extension panels to allow ordering per a config"
This commit is contained in:
@@ -100,9 +100,9 @@ public class ApiGlue {
|
||||
var s = new SettingsScreenDefinition(p,m,c);
|
||||
(this.settingsScreens[n] || (this.settingsScreens[n]=[])).push(s);
|
||||
},
|
||||
panel: function(i,c){this._panel(this.getPluginName(),i,c)},
|
||||
_panel: function(n,i,c){
|
||||
var p = new PanelDefinition(n,c);
|
||||
panel: function(i,c,n){this._panel(this.getPluginName(),i,c,n)},
|
||||
_panel: function(n,i,c,x){
|
||||
var p = new PanelDefinition(n,c,x);
|
||||
(this.panels[i] || (this.panels[i]=[])).push(p);
|
||||
},
|
||||
|
||||
|
||||
@@ -22,7 +22,10 @@ import com.google.gwt.dom.client.Element;
|
||||
import com.google.gwt.user.client.ui.FlowPanel;
|
||||
import com.google.gwt.user.client.ui.SimplePanel;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@@ -32,13 +35,18 @@ public class ExtensionPanel extends FlowPanel {
|
||||
private final List<Context> contexts;
|
||||
|
||||
public ExtensionPanel(GerritUiExtensionPoint extensionPoint) {
|
||||
this.extensionPoint = extensionPoint;
|
||||
this.contexts = create();
|
||||
this(extensionPoint, new ArrayList<String>());
|
||||
}
|
||||
|
||||
private List<Context> create() {
|
||||
List<Context> contexts = new ArrayList<>();
|
||||
for (Definition def : Natives.asList(Definition.get(extensionPoint.name()))) {
|
||||
public ExtensionPanel(GerritUiExtensionPoint extensionPoint,
|
||||
List<String> panelNames) {
|
||||
this.extensionPoint = extensionPoint;
|
||||
this.contexts = create(panelNames);
|
||||
}
|
||||
|
||||
private List<Context> create(List<String> panelNames) {
|
||||
List<Context> contexts = new ArrayList<Context>();
|
||||
for (Definition def : getOrderedDefs(panelNames)) {
|
||||
SimplePanel p = new SimplePanel();
|
||||
add(p);
|
||||
contexts.add(Context.create(def, p));
|
||||
@@ -46,6 +54,45 @@ public class ExtensionPanel extends FlowPanel {
|
||||
return contexts;
|
||||
}
|
||||
|
||||
private List<Definition> getOrderedDefs(List<String> panelNames) {
|
||||
if (panelNames == null) {
|
||||
panelNames = Collections.emptyList();
|
||||
}
|
||||
Map<String, List<Definition>> defsOrderedByName =
|
||||
new LinkedHashMap<String, List<Definition>>();
|
||||
for (String name : panelNames) {
|
||||
defsOrderedByName.put(name, new ArrayList<Definition>());
|
||||
}
|
||||
for (Definition def : Natives.asList(
|
||||
Definition.get(extensionPoint.name()))) {
|
||||
addDef(def, defsOrderedByName);
|
||||
}
|
||||
List<Definition> orderedDefs = new ArrayList<Definition>();
|
||||
for (List<Definition> defList : defsOrderedByName.values()) {
|
||||
orderedDefs.addAll(defList);
|
||||
}
|
||||
return orderedDefs;
|
||||
}
|
||||
|
||||
private static void addDef(Definition def,
|
||||
Map<String, List<Definition>> defsOrderedByName) {
|
||||
String panelName = def.getPanelName();
|
||||
if (panelName.equals(def.getPluginName() + ".undefined")) {
|
||||
/* Handle a partially undefined panel name from the
|
||||
javascript layer by generating a random panel name.
|
||||
This maintains support for panels that do not provide a name. */
|
||||
panelName = def.getPluginName() + "." + Long.toHexString(
|
||||
Double.doubleToLongBits(Math.random()));
|
||||
}
|
||||
if (defsOrderedByName.containsKey(panelName)) {
|
||||
defsOrderedByName.get(panelName).add(def);
|
||||
} else if (defsOrderedByName.containsKey(def.getPluginName())) {
|
||||
defsOrderedByName.get(def.getPluginName()).add(def);
|
||||
} else {
|
||||
defsOrderedByName.put(panelName, Collections.singletonList(def));
|
||||
}
|
||||
}
|
||||
|
||||
public void put(GerritUiExtensionPoint.Key key, String value) {
|
||||
for (Context ctx : contexts) {
|
||||
ctx.put(key.name(), value);
|
||||
@@ -103,9 +150,10 @@ public class ExtensionPanel extends FlowPanel {
|
||||
static final JavaScriptObject TYPE = init();
|
||||
|
||||
private static native JavaScriptObject init() /*-{
|
||||
function PanelDefinition(n, c) {
|
||||
function PanelDefinition(n, c, x) {
|
||||
this.pluginName = n;
|
||||
this.onLoad = c;
|
||||
this.name = x;
|
||||
};
|
||||
return PanelDefinition;
|
||||
}-*/;
|
||||
@@ -113,6 +161,9 @@ public class ExtensionPanel extends FlowPanel {
|
||||
static native JsArray<Definition> get(String i) /*-{ return $wnd.Gerrit.panels[i] || [] }-*/;
|
||||
|
||||
protected Definition() {}
|
||||
|
||||
public final native String getPanelName() /*-{ return this.pluginName + "." + this.name; }-*/;
|
||||
public final native String getPluginName() /*-{ return this.pluginName; }-*/;
|
||||
}
|
||||
|
||||
static class Context extends JavaScriptObject {
|
||||
|
||||
@@ -68,7 +68,7 @@ final class Plugin extends JavaScriptObject {
|
||||
onAction: function(t,n,c){G._onAction(this.name,t,n,c)},
|
||||
screen: function(p,c){G._screen(this.name,p,c)},
|
||||
settingsScreen: function(p,m,c){G._settingsScreen(this.name,p,m,c)},
|
||||
panel: function(i,c){G._panel(this.name,i,c)},
|
||||
panel: function(i,c,n){G._panel(this.name,i,c,n)},
|
||||
|
||||
url: function (u){return G.url(this._url(u))},
|
||||
get: function(u,b){@com.google.gerrit.client.api.ActionContext::get(
|
||||
|
||||
Reference in New Issue
Block a user