Split the description area of a change into a reusable block

This makes it easier to reuse this body within other screens, such
as when publishing comments or viewing a patch.

Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
Shawn O. Pearce
2009-01-15 16:05:37 -08:00
parent 1e3b033abb
commit e40b11ad5c
2 changed files with 59 additions and 36 deletions

View File

@@ -0,0 +1,54 @@
// Copyright 2008 Google Inc.
//
// 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.client.changes;
import com.google.gerrit.client.data.ChangeDetail;
import com.google.gerrit.client.ui.DomUtil;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DisclosurePanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
public class ChangeDescriptionBlock extends Composite {
private final DisclosurePanel descriptionPanel;
private final ChangeInfoBlock infoBlock;
private final HTML description;
public ChangeDescriptionBlock() {
infoBlock = new ChangeInfoBlock();
description = new HTML();
description.setStyleName("gerrit-ChangeScreen-Description");
descriptionPanel = new DisclosurePanel(Util.C.changeScreenDescription());
{
final Label glue = new Label();
final HorizontalPanel hp = new HorizontalPanel();
hp.add(description);
hp.add(glue);
hp.add(infoBlock);
hp.setCellWidth(glue, "15px;");
descriptionPanel.setContent(hp);
descriptionPanel.setWidth("100%");
}
initWidget(descriptionPanel);
}
public void display(final ChangeDetail detail) {
infoBlock.display(detail);
description.setHTML(DomUtil
.linkify(DomUtil.escape(detail.getDescription())));
descriptionPanel.setOpen(true);
}
}

View File

@@ -25,7 +25,6 @@ import com.google.gerrit.client.reviewdb.PatchSet;
import com.google.gerrit.client.rpc.Common;
import com.google.gerrit.client.rpc.ScreenLoadCallback;
import com.google.gerrit.client.ui.ComplexDisclosurePanel;
import com.google.gerrit.client.ui.DomUtil;
import com.google.gerrit.client.ui.ExpandAllCommand;
import com.google.gerrit.client.ui.LinkMenuBar;
import com.google.gerrit.client.ui.RefreshListener;
@@ -34,10 +33,7 @@ import com.google.gwt.i18n.client.LocaleInfo;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.DisclosurePanel;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.InlineLabel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.Widget;
@@ -50,10 +46,7 @@ public class ChangeScreen extends Screen {
private ChangeInfo changeInfo;
private boolean refreshOnSignIn;
private ChangeInfoBlock infoBlock;
private DisclosurePanel descriptionPanel;
private HTML description;
private ChangeDescriptionBlock descriptionBlock;
private DisclosurePanel dependenciesPanel;
private ChangeTable dependencies;
private ChangeTable.Section dependsOn;
@@ -102,7 +95,7 @@ public class ChangeScreen extends Screen {
@Override
public void onLoad() {
if (descriptionPanel == null) {
if (descriptionBlock == null) {
initUI();
}
@@ -127,23 +120,8 @@ public class ChangeScreen extends Screen {
private void initUI() {
addStyleName("gerrit-ChangeScreen");
infoBlock = new ChangeInfoBlock();
description = newDescriptionLabel();
descriptionPanel = new DisclosurePanel(Util.C.changeScreenDescription());
{
final Label glue = new Label();
final HorizontalPanel hp = new HorizontalPanel();
hp.add(description);
hp.add(glue);
hp.add(infoBlock);
hp.setCellWidth(glue, "100%");
add(hp);
descriptionPanel.setContent(hp);
descriptionPanel.setWidth("100%");
add(descriptionPanel);
}
descriptionBlock = new ChangeDescriptionBlock();
add(descriptionBlock);
dependencies = new ChangeTable();
dependsOn = new ChangeTable.Section(Util.C.changeScreenDependsOn());
@@ -198,9 +176,7 @@ public class ChangeScreen extends Screen {
dependencies.setAccountInfoCache(detail.getAccounts());
approvals.setAccountInfoCache(detail.getAccounts());
infoBlock.display(detail);
description.setHTML(DomUtil
.linkify(DomUtil.escape(detail.getDescription())));
descriptionBlock.display(detail);
dependsOn.display(detail.getDependsOn());
neededBy.display(detail.getNeededBy());
approvals.display(detail.getMissingApprovals(), detail.getApprovals());
@@ -221,7 +197,6 @@ public class ChangeScreen extends Screen {
}
}
descriptionPanel.setOpen(true);
dependenciesPanel.setOpen(depsOpen);
approvalsPanel.setOpen(true);
}
@@ -329,10 +304,4 @@ public class ChangeScreen extends Screen {
p.add(w);
return p;
}
private static HTML newDescriptionLabel() {
final HTML d = new HTML();
d.setStyleName("gerrit-ChangeScreen-Description");
return d;
}
}