-
Notifications
You must be signed in to change notification settings - Fork 350
/
OrgAppsPage.java
151 lines (132 loc) · 4.56 KB
/
OrgAppsPage.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
/*
* Copyright 2014 JBoss 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 io.apiman.manager.ui.client.local.pages;
import io.apiman.manager.api.beans.idm.PermissionType;
import io.apiman.manager.api.beans.summary.ApplicationSummaryBean;
import io.apiman.manager.ui.client.local.AppMessages;
import io.apiman.manager.ui.client.local.pages.org.OrgApplicationList;
import io.apiman.manager.ui.client.local.services.rest.IRestInvokerCallback;
import io.apiman.manager.ui.client.local.widgets.SearchBox;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.enterprise.context.Dependent;
import javax.inject.Inject;
import org.jboss.errai.ui.nav.client.local.Page;
import org.jboss.errai.ui.nav.client.local.TransitionAnchor;
import org.jboss.errai.ui.shared.api.annotations.DataField;
import org.jboss.errai.ui.shared.api.annotations.Templated;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
/**
* The "Organization" page, with the Applications tab displayed.
*
* @author eric.wittmann@redhat.com
*/
@Templated("/io/apiman/manager/ui/client/local/site/org-apps.html#page")
@Page(path="org-apps")
@Dependent
public class OrgAppsPage extends AbstractOrgPage {
private List<ApplicationSummaryBean> apps;
@Inject @DataField
TransitionAnchor<NewAppPage> toNewApp;
@Inject @DataField
SearchBox appFilter;
@Inject @DataField
OrgApplicationList applications;
/**
* Constructor.
*/
public OrgAppsPage() {
}
/**
* @see io.apiman.manager.ui.client.local.pages.AbstractPage#isAuthorized()
*/
@Override
protected boolean isAuthorized() {
return hasPermission(PermissionType.appView);
}
/**
* Called after the bean is created.
*/
@PostConstruct
protected void postConstruct() {
appFilter.addValueChangeHandler(new ValueChangeHandler<String>() {
@Override
public void onValueChange(ValueChangeEvent<String> event) {
filterApps();
}
});
appFilter.setPlaceholder(i18n.format(AppMessages.ORG_APPS_FILTER_PLACEHOLDER));
}
/**
* @see io.apiman.manager.ui.client.local.pages.AbstractOrgPage#doLoadPageData()
*/
@Override
protected int doLoadPageData() {
int rval = super.doLoadPageData();
rest.getOrgApplications(org, new IRestInvokerCallback<List<ApplicationSummaryBean>>() {
@Override
public void onSuccess(List<ApplicationSummaryBean> response) {
apps = response;
dataPacketLoaded();
}
@Override
public void onError(Throwable error) {
dataPacketError(error);
}
});
return rval + 1;
}
/**
* @see io.apiman.manager.ui.client.local.pages.AbstractUserPage#renderPage()
*/
@Override
protected void renderPage() {
super.renderPage();
applications.setValue(apps);
}
/**
* Apply a filter to the list of applications.
*/
protected void filterApps() {
List<ApplicationSummaryBean> filtered = new ArrayList<ApplicationSummaryBean>();
for (ApplicationSummaryBean app : apps) {
if (matchesFilter(app)) {
filtered.add(app);
}
}
applications.setFilteredValue(filtered);
}
/**
* Returns true if the given app matches the current filter.
* @param app
*/
private boolean matchesFilter(ApplicationSummaryBean app) {
if (appFilter.getValue() == null || appFilter.getValue().trim().length() == 0)
return true;
if (app.getName().toUpperCase().contains(appFilter.getValue().toUpperCase()))
return true;
return false;
}
/**
* @see io.apiman.manager.ui.client.local.pages.AbstractPage#getPageTitle()
*/
@Override
protected String getPageTitle() {
return i18n.format(AppMessages.TITLE_ORG_APPS, organizationBean.getName());
}
}