/
AbstractListView.java
177 lines (140 loc) · 5.54 KB
/
AbstractListView.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
/*
* Copyright 2014 JBoss by Red Hat.
*
* 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 org.jbpm.console.ng.gc.client.list.base;
import javax.enterprise.event.Event;
import javax.inject.Inject;
import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.constants.IconType;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.cellview.client.Column;
import com.google.gwt.user.cellview.client.RowStyles;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.user.client.ui.RequiresResize;
import com.google.gwt.view.client.DefaultSelectionEventManager;
import com.google.gwt.view.client.NoSelectionModel;
import org.jboss.errai.common.client.api.Caller;
import org.jboss.errai.common.client.api.RemoteCallback;
import org.jboss.errai.security.shared.api.identity.User;
import org.jbpm.console.ng.ga.model.GenericSummary;
import org.jbpm.console.ng.gc.client.experimental.grid.base.ExtendedPagedTable;
import org.uberfire.ext.widgets.common.client.common.BusyPopup;
import org.uberfire.ext.services.shared.preferences.GridGlobalPreferences;
import org.uberfire.ext.services.shared.preferences.GridPreferencesStore;
import org.uberfire.ext.services.shared.preferences.UserDataGridPreferencesService;
import org.uberfire.client.mvp.PlaceManager;
import org.uberfire.client.mvp.UberView;
import org.uberfire.workbench.events.NotificationEvent;
/**
* @param <T>
* @param <V>
* @author salaboy
*/
public abstract class AbstractListView<T extends GenericSummary, V extends AbstractListPresenter>
extends Composite implements RequiresResize {
@Inject
public User identity;
@Inject
protected Event<NotificationEvent> notification;
@Inject
protected PlaceManager placeManager;
@Inject
private Caller<UserDataGridPreferencesService> preferencesService;
protected V presenter;
protected ExtendedPagedTable<T> listGrid;
protected RowStyles<T> selectedStyles = new RowStyles<T>() {
@Override
public String getStyleNames( T row,
int rowIndex ) {
if ( rowIndex == selectedRow ) {
return "selected";
}
return null;
}
};
protected NoSelectionModel<T> selectionModel;
protected T selectedItem;
protected int selectedRow = -1;
protected Column actionsColumn;
protected DefaultSelectionEventManager<T> noActionColumnManager;
public interface BasicListView<T extends GenericSummary> extends IsWidget {
void showBusyIndicator( String message );
void hideBusyIndicator();
void displayNotification( String text );
ExtendedPagedTable<T> getListGrid();
}
public interface ListView<T extends GenericSummary, V> extends BasicListView<T>,
UberView<V> {
}
public void init( V presenter,
final GridGlobalPreferences preferences ) {
this.presenter = presenter;
listGrid = new ExtendedPagedTable<T>( 10, preferences );
initWidget( listGrid );
presenter.addDataDisplay( listGrid );
preferencesService.call( new RemoteCallback<GridPreferencesStore>() {
@Override
public void callback( GridPreferencesStore preferencesStore ) {
listGrid.setPreferencesService( preferencesService );
if ( preferencesStore == null ) {
listGrid.setGridPreferencesStore( new GridPreferencesStore( preferences ) );
} else {
listGrid.setGridPreferencesStore( preferencesStore );
}
initColumns();
initGenericToolBar();
}
} ).loadGridPreferences( preferences.getKey() );
}
@Override
public void onResize() {
}
public void displayNotification( String text ) {
notification.fire( new NotificationEvent( text ) );
}
/*
* By default all the tables will have a refresh button
*/
public void initGenericToolBar() {
Button refreshButton = new Button();
refreshButton.setIcon( IconType.REFRESH );
refreshButton.addClickHandler( new ClickHandler() {
@Override
public void onClick( ClickEvent event ) {
presenter.refreshGrid();
}
} );
listGrid.getRightToolbar().add( refreshButton );
}
public ExtendedPagedTable<T> getListGrid() {
return listGrid;
}
public void showBusyIndicator( final String message ) {
BusyPopup.showMessage( message );
}
public void hideBusyIndicator() {
BusyPopup.close();
}
/*
* For each specific implementation define the
* DataGrid columns and how they must be initialized
*/
public abstract void initColumns();
public void setListGrid(ExtendedPagedTable newListGrid){
this.listGrid = newListGrid;
}
}