This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 57
/
GlossaryView.java
194 lines (160 loc) · 5.94 KB
/
GlossaryView.java
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
package org.zanata.webtrans.client.view;
import java.util.ArrayList;
import org.zanata.webtrans.client.presenter.GlossaryPresenter;
import org.zanata.webtrans.client.resources.UiMessages;
import org.zanata.webtrans.client.ui.EnumListBox;
import org.zanata.webtrans.client.ui.SearchTypeRenderer;
import org.zanata.webtrans.client.ui.table.column.CopyButtonColumn;
import org.zanata.webtrans.client.ui.table.column.HighlightingLabelColumn;
import org.zanata.webtrans.client.ui.table.column.SimilarityColumn;
import org.zanata.webtrans.shared.model.TranslationMemoryGlossaryItem;
import org.zanata.webtrans.shared.rpc.HasSearchType.SearchType;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.BlurEvent;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.FocusEvent;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.dom.client.KeyUpEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.cellview.client.CellTable;
import com.google.gwt.user.cellview.client.Column;
import com.google.gwt.user.cellview.client.HasKeyboardSelectionPolicy.KeyboardSelectionPolicy;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HasValue;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.ValueListBox;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.view.client.DefaultSelectionEventManager;
import com.google.gwt.view.client.ListDataProvider;
import com.google.gwt.view.client.NoSelectionModel;
import com.google.inject.Inject;
public class GlossaryView extends Composite implements GlossaryPresenter.Display
{
private static GlossaryViewUiBinder uiBinder = GWT.create(GlossaryViewUiBinder.class);
CellTable<TranslationMemoryGlossaryItem> glossaryTable;
private ListDataProvider<TranslationMemoryGlossaryItem> dataProvider;
interface GlossaryViewUiBinder extends UiBinder<Widget, GlossaryView>
{
}
@UiField
TextBox glossaryTextBox;
@UiField
Button searchButton;
@UiField
Label headerLabel;
@UiField(provided = true)
ValueListBox<SearchType> searchType;
@UiField
Button clearButton;
@UiField
ScrollPanel scrollPanel;
private final UiMessages messages;
private boolean isFocused;
@Inject
public GlossaryView(final UiMessages messages, SearchTypeRenderer searchTypeRenderer)
{
this.messages = messages;
searchType = new EnumListBox<SearchType>(SearchType.class, searchTypeRenderer);
dataProvider = new ListDataProvider<TranslationMemoryGlossaryItem>();
initWidget(uiBinder.createAndBindUi(this));
headerLabel.setText(messages.glossaryHeading());
clearButton.setText(messages.clearButtonLabel());
searchButton.setText(messages.searchButtonLabel());
}
@UiHandler("glossaryTextBox")
void onGlossaryTextBoxKeyUp(KeyUpEvent event)
{
if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER)
{
searchButton.click();
}
}
@UiHandler("glossaryTextBox")
public void onGlossaryTextBoxFocus(FocusEvent event)
{
isFocused = true;
}
@UiHandler("glossaryTextBox")
public void onGlossaryTextBoxBlur(BlurEvent event)
{
isFocused = false;
}
@UiHandler("clearButton")
void onClearButtonClicked(ClickEvent event)
{
glossaryTextBox.setText("");
dataProvider.getList().clear();
}
@Override
public Button getSearchButton()
{
return searchButton;
}
public TextBox getGlossaryTextBox()
{
return glossaryTextBox;
}
@Override
public Widget asWidget()
{
return this;
}
@Override
public void startProcessing()
{
dataProvider.getList().clear();
}
@Override
public boolean isFocused()
{
return isFocused;
}
@Override
public HasValue<SearchType> getSearchType()
{
return searchType;
}
private CopyButtonColumn copyColumn = new CopyButtonColumn();
private HighlightingLabelColumn sourceColumn = new HighlightingLabelColumn(true, false);
private HighlightingLabelColumn targetColumn = new HighlightingLabelColumn(false, true);
@Override
public void renderTable()
{
glossaryTable = new CellTable<TranslationMemoryGlossaryItem>();
glossaryTable.addStyleName("glossaryTable");
glossaryTable.addStyleName("southTable");
glossaryTable.addColumn(sourceColumn, messages.termLabel());
glossaryTable.addColumn(targetColumn, messages.suggestionLabel());
glossaryTable.addColumn(new SimilarityColumn(), messages.similarityLabel());
glossaryTable.addColumn(copyColumn);
final NoSelectionModel<TranslationMemoryGlossaryItem> selectionModel = new NoSelectionModel<TranslationMemoryGlossaryItem>();
final DefaultSelectionEventManager<TranslationMemoryGlossaryItem> manager = DefaultSelectionEventManager.createBlacklistManager(0, 1, 2);
glossaryTable.setSelectionModel(selectionModel, manager);
glossaryTable.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED);
dataProvider.addDataDisplay(glossaryTable);
scrollPanel.clear();
scrollPanel.add(glossaryTable);
}
@Override
public void reloadData(String query, ArrayList<TranslationMemoryGlossaryItem> glossaries)
{
glossaryTable.setVisibleRangeAndClearData(glossaryTable.getVisibleRange(), true);
dataProvider.getList().clear();
for (final TranslationMemoryGlossaryItem glossary : glossaries)
{
dataProvider.getList().add(glossary);
}
glossaryTable.setPageSize(dataProvider.getList().size());
dataProvider.refresh();
}
@Override
public Column<TranslationMemoryGlossaryItem, String> getCopyColumn()
{
return copyColumn;
}
}