Move Anchor creation to WebLinkInfo
Change-Id: Ia763de5f5e49df166ce549454d1a64d3d3c8c374
This commit is contained in:
@@ -15,6 +15,8 @@
|
||||
package com.google.gerrit.client;
|
||||
|
||||
import com.google.gwt.core.client.JavaScriptObject;
|
||||
import com.google.gwt.user.client.ui.Anchor;
|
||||
import com.google.gwt.user.client.ui.Image;
|
||||
|
||||
public class WebLinkInfo extends JavaScriptObject {
|
||||
|
||||
@@ -25,4 +27,22 @@ public class WebLinkInfo extends JavaScriptObject {
|
||||
|
||||
protected WebLinkInfo() {
|
||||
}
|
||||
|
||||
public final Anchor toAnchor() {
|
||||
Anchor a = new Anchor();
|
||||
a.setHref(url());
|
||||
if (target() != null && !target().isEmpty()) {
|
||||
a.setTarget(target());
|
||||
}
|
||||
if (imageUrl() != null && !imageUrl().isEmpty()) {
|
||||
Image img = new Image();
|
||||
img.setAltText(name());
|
||||
img.setUrl(imageUrl());
|
||||
img.setTitle(name());
|
||||
a.getElement().appendChild(img.getElement());
|
||||
} else {
|
||||
a.setText("(" + name() + ")");
|
||||
}
|
||||
return a;
|
||||
}
|
||||
}
|
||||
|
@@ -396,22 +396,8 @@ public class ProjectBranchesScreen extends ProjectScreen {
|
||||
c.toBranch(new Branch.NameKey(getProjectKey(), k.ref()))));
|
||||
}
|
||||
if (k.web_links() != null) {
|
||||
for (WebLinkInfo weblink : Natives.asList(k.web_links())) {
|
||||
Anchor a = new Anchor();
|
||||
a.setHref(weblink.url());
|
||||
if (weblink.target() != null && !weblink.target().isEmpty()) {
|
||||
a.setTarget(weblink.target());
|
||||
}
|
||||
if (weblink.imageUrl() != null && !weblink.imageUrl().isEmpty()) {
|
||||
Image img = new Image();
|
||||
img.setAltText(weblink.name());
|
||||
img.setUrl(weblink.imageUrl());
|
||||
img.setTitle(weblink.name());
|
||||
a.getElement().appendChild(img.getElement());
|
||||
} else {
|
||||
a.setText("(" + weblink.name() + ")");
|
||||
}
|
||||
actionsPanel.add(a);
|
||||
for (WebLinkInfo webLink : Natives.asList(k.web_links())) {
|
||||
actionsPanel.add(webLink.toAnchor());
|
||||
}
|
||||
}
|
||||
if (k.actions() != null) {
|
||||
|
@@ -238,21 +238,7 @@ public class ProjectListScreen extends Screen implements FilteredUserInterface {
|
||||
}
|
||||
|
||||
for (WebLinkInfo weblink : webLinks) {
|
||||
Anchor a = new Anchor();
|
||||
a.setHref(weblink.url());
|
||||
if (weblink.target() != null && !weblink.target().isEmpty()) {
|
||||
a.setTarget(weblink.target());
|
||||
}
|
||||
if (weblink.imageUrl() != null && !weblink.imageUrl().isEmpty()) {
|
||||
Image img = new Image();
|
||||
img.setAltText(weblink.name());
|
||||
img.setUrl(weblink.imageUrl());
|
||||
img.setTitle(weblink.name());
|
||||
a.getElement().appendChild(img.getElement());
|
||||
} else {
|
||||
a.setText("(" + weblink.name() + ")");
|
||||
}
|
||||
p.add(a);
|
||||
p.add(weblink.toAnchor());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -126,35 +126,22 @@ class CommitBox extends Composite {
|
||||
RevisionInfo revInfo) {
|
||||
GitwebLink gw = Gerrit.getGitwebLink();
|
||||
if (gw != null && gw.canLink(revInfo)) {
|
||||
addWebLink(gw.toRevision(change.project(), revision),
|
||||
gw.getLinkName(), null, null);
|
||||
toAnchor(gw.toRevision(change.project(), revision),
|
||||
gw.getLinkName());
|
||||
}
|
||||
|
||||
JsArray<WebLinkInfo> links = revInfo.web_links();
|
||||
if (links != null) {
|
||||
for (WebLinkInfo link : Natives.asList(links)) {
|
||||
addWebLink(link.url(), parenthesize(link.name()), link.imageUrl(),
|
||||
link.target());
|
||||
webLinkPanel.add(link.toAnchor());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addWebLink(String href, String name, String imageUrl,
|
||||
String target) {
|
||||
private void toAnchor(String href, String name) {
|
||||
Anchor a = new Anchor();
|
||||
a.setHref(href);
|
||||
if (target != null && !target.isEmpty()) {
|
||||
a.setTarget(target);
|
||||
}
|
||||
if (imageUrl != null && !imageUrl.isEmpty()) {
|
||||
Image img = new Image();
|
||||
img.setAltText(name);
|
||||
img.setUrl(imageUrl);
|
||||
img.setTitle(name);
|
||||
a.getElement().appendChild(img.getElement());
|
||||
} else {
|
||||
a.setText(name);
|
||||
}
|
||||
a.setText(name);
|
||||
webLinkPanel.add(a);
|
||||
}
|
||||
|
||||
@@ -198,14 +185,6 @@ class CommitBox extends Composite {
|
||||
date.setInnerText(FormatUtil.mediumFormat(person.date()));
|
||||
}
|
||||
|
||||
private static String parenthesize(String str) {
|
||||
return new StringBuilder()
|
||||
.append("(")
|
||||
.append(str)
|
||||
.append(")")
|
||||
.toString();
|
||||
}
|
||||
|
||||
private static String renderName(GitPerson person) {
|
||||
return person.name() + " <" + person.email() + ">";
|
||||
}
|
||||
|
@@ -123,22 +123,8 @@ class PatchSetSelectBox2 extends Composite {
|
||||
}
|
||||
List<WebLinkInfo> webLinks = Natives.asList(meta.web_links());
|
||||
if (webLinks != null) {
|
||||
for (WebLinkInfo weblink : webLinks) {
|
||||
Anchor a = new Anchor();
|
||||
a.setHref(weblink.url());
|
||||
if (weblink.target() != null && !weblink.target().isEmpty()) {
|
||||
a.setTarget(weblink.target());
|
||||
}
|
||||
if (weblink.imageUrl() != null && !weblink.imageUrl().isEmpty()) {
|
||||
Image img = new Image();
|
||||
img.setAltText(weblink.name());
|
||||
img.setUrl(weblink.imageUrl());
|
||||
img.setTitle(weblink.name());
|
||||
a.getElement().appendChild(img.getElement());
|
||||
} else {
|
||||
a.setText("(" + weblink.name() + ")");
|
||||
}
|
||||
linkPanel.add(a);
|
||||
for (WebLinkInfo webLink : webLinks) {
|
||||
linkPanel.add(webLink.toAnchor());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user