summaryrefslogtreecommitdiffstats
path: root/gerrit-gwtui/src/main/java/com/google/gerrit/client/patches/AbstractPatchScreen.java
blob: f779b86cf6df85ca560401040385c2c39e9d9b21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
//
// 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.patches;

import com.google.gerrit.client.changes.CommitMessageBlock;
import com.google.gerrit.client.changes.PatchTable;
import com.google.gerrit.client.ui.ListenableAccountDiffPreference;
import com.google.gerrit.client.ui.Screen;
import com.google.gerrit.common.data.PatchScript;
import com.google.gerrit.common.data.PatchSetDetail;
import com.google.gerrit.prettify.client.ClientSideFormatter;
import com.google.gerrit.prettify.common.PrettyFactory;
import com.google.gerrit.reviewdb.AccountDiffPreference;
import com.google.gerrit.reviewdb.Patch;
import com.google.gerrit.reviewdb.PatchSet;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.user.client.ui.DisclosurePanel;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.VerticalPanel;

public abstract class AbstractPatchScreen extends Screen implements
    CommentEditorContainer {
  static final PrettyFactory PRETTY = ClientSideFormatter.FACTORY;

  /**
   * How this patch should be displayed in the patch screen.
   */
  public static enum Type {
    UNIFIED, SIDE_BY_SIDE
  }

  // Which patch set id's are being diff'ed
  protected static PatchSet.Id diffSideA = null;
  protected static PatchSet.Id diffSideB = null;
  protected PatchSet.Id idSideA;
  protected PatchSet.Id idSideB;
  protected HistoryTable historyTable;
  protected FlowPanel topPanel;
  protected CommitMessageBlock commitMessageBlock;
  protected PatchSetDetail patchSetDetail;
  protected PatchTable fileList;
  protected Patch.Key patchKey;
  protected PatchScriptSettingsPanel settingsPanel;
  protected ListenableAccountDiffPreference prefs;
  protected PatchScript lastScript;

  public AbstractPatchScreen(final Patch.Key patchKey, final PatchSet.Id id,
      final PatchSetDetail patchSetDetail, final PatchTable patchTable) {
    this.patchKey = patchKey;
    this.patchSetDetail = patchSetDetail;
    fileList = patchTable;

    if (patchTable != null) {
      diffSideA = patchTable.getPatchSetIdToCompareWith();
    } else {
      diffSideA = null;
    }

    idSideA = diffSideA; // null here means we're diff'ing from the Base
    idSideB = diffSideB != null ? diffSideB : id;

    prefs = fileList != null ? fileList.getPreferences() :
      new ListenableAccountDiffPreference();
    prefs.addValueChangeHandler(
        new ValueChangeHandler<AccountDiffPreference>() {
          @Override
          public void onValueChange(ValueChangeEvent<AccountDiffPreference> event) {
            update(event.getValue());
          }
    });

    settingsPanel = new PatchScriptSettingsPanel(prefs);
  }

  @Override
  protected void onInitUI() {
    super.onInitUI();

    historyTable = new HistoryTable(this);
    commitMessageBlock = new CommitMessageBlock();

    // Pre-topview style top layout.
    VerticalPanel vp = new VerticalPanel();
    DisclosurePanel historyPanel =
      new DisclosurePanel(PatchUtil.C.patchHistoryTitle());
    historyPanel.add(historyTable);
    vp.add(historyPanel);
    vp.add(settingsPanel);

    HorizontalPanel hp = new HorizontalPanel();
    hp.setWidth("100%");
    hp.add(vp);
    hp.add(commitMessageBlock);

    add(hp);
  }

  PatchSet.Id getSideA() {
    return diffSideA;
  }

  void setSideA(PatchSet.Id id) {
    diffSideA = id;
    idSideA = id;
    if (fileList != null) {
      fileList.setPatchSetIdToCompareWith(id);
    }
  }

  PatchSet.Id getSideB() {
    return diffSideB;
  }

  void setSideB(PatchSet.Id id) {
    diffSideB = id;
    idSideB = id;
  }

  public Patch.Key getPatchKey() {
    return patchKey;
  }

  abstract void refresh(boolean first);
  abstract public AbstractPatchScreen.Type getPatchScreenType();
  abstract protected void update(AccountDiffPreference dp);

  public PatchSetDetail getPatchSetDetail() {
    return patchSetDetail;
  }
  public PatchTable getFileList() {
    return fileList;
  }
}