// setup layout
// profile section
StyledFlowPanel sectionProfile = new StyledFlowPanel("section");
StyledLabel profileLabel = new StyledLabel("grouplabel", uiText.Profile());
StyledLabel profileInstruction = new StyledLabel("instruction", "");
details.add(sectionProfile);
sectionProfile.add(profileLabel);
sectionProfile.add(profileInstruction);
sectionProfile.add(profile);
// followers section
StyledFlowPanel sectionFollowers = new StyledFlowPanel("section");
StyledLabel followersLabel = new StyledLabel("grouplabel", uiText.Followers());
final StyledLabel followersInstruction = new StyledLabel("instruction",
"");
details.add(sectionFollowers);
sectionFollowers.add(followersLabel);
sectionFollowers.add(followersInstruction);
sectionFollowers.add(followersPanel);
// following section
StyledFlowPanel sectionFollowing = new StyledFlowPanel("section");
StyledLabel followingLabel = new StyledLabel("grouplabel", uiText.FollowingPeople());
final StyledLabel followingInstruction = new StyledLabel("instruction",
"");
details.add(sectionFollowing);
sectionFollowing.add(followingLabel);
sectionFollowing.add(followingInstruction);
sectionFollowing.add(followingPanel);
profileInstruction.setVisible(false);
if (model != null && model.getFields().size() > 0) {
// show the profile
sectionProfile.setVisible(true);
if (model.hasField(FullNameField.NAME)) {
String displayname = model.getFullName();
if (displayname != null && displayname.length() > 0)
addHTMLLabelRow(profile, uiText.DisplayName(), displayname);
}
if (model.hasField(NameField.NAME)) {
String name = model.getName();
if (name != null && name.length() > 0)
addHTMLLabelRow(profile, uiText.FullName(), name);
}
if (model.hasField(BirthdayField.NAME)) {
Date birthday = model.getBirthday();
if (birthday != null) {
DateTimeFormat dtf = DateTimeFormat.getFormat("d MMMM yyyy");
String bday = dtf.format(birthday);
addHTMLLabelRow(profile, uiText.Birthday(), bday);
}
}
if (model.hasField(GenderField.NAME)) {
String value = new String("");
GenderField.Type gender = model.getGender();
if (gender.equals(GenderField.Type.MALE)) {
value = uiText.Male();
} else if (gender.equals(GenderField.Type.FEMALE)) {
value = uiText.Female();
} else if (gender.equals(GenderField.Type.NOTKNOWN)) {
value = uiText.NotKnown();
} else if (gender.equals(GenderField.Type.NOTAPPLICABLE)) {
value = uiText.NotApplicable();
}
if (gender != null)
addHTMLLabelRow(profile, uiText.Gender(), value);
}
if (model.hasField(NoteField.NAME)) {
String bio = model.getNote();
if (bio != null && bio.length() > 0)
addHTMLLabelRow(profile, uiText.Bio(), bio);
}
if (model.hasField(EmailField.NAME)) {
String email = model.getEmail();
if (email != null && email.length() > 0)
addHTMLLabelRow(profile, uiText.Email(), email);
}
if (model.hasField(TelField.NAME)) {
String tel = model.getTel();
if (tel != null && tel.length() > 0)
addHTMLLabelRow(profile, uiText.Telephone(), tel);
}
if (model.hasField(URLField.NAME)) {
String url = model.getUrl();
if (url != null && url.length() > 0)
addHTMLLabelRow(profile, uiText.Website(), url);
}
} else {
// if there are no results
// hide the profile table
profile.setVisible(false);
// show message
String msg = uiText.FailedToGetProfile();
profileInstruction.setText(msg);
profileInstruction.setVisible(true);
}
// get the followers of this person
final DefaultTaskInfo task1 = new DefaultTaskInfo(
uiText.FetchingFollowers(), false);
TaskMonitor.getInstance().addTask(task1);
OswServiceFactory.getService().getSubscribers(jid,
new RequestCallback<List<String>>() {
@Override
public void onFailure() {
// TODO Auto-generated method stub
task1.complete("", Status.failure);
}
@Override
public void onSuccess(List<String> result) {
task1.complete("", Status.succes);
// see if there are any results
if (result.size() > 0) {
// sort the list alphabetically
Collections.sort(result, new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
return o1.compareToIgnoreCase(o2);
}
});
// add all the jids to the list
for (final String jid : result) {
Label follower = new Label(jid);
follower.addStyleName("link");
follower.setTitle(uiText.ViewProfileOf() + " " + jid);
followersPanel.add(follower);
follower.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
// get the app instance from the session
// manager
AbstractApplication app = OswClient
.getInstance()
.getCurrentApplication();
ProfileWindow profileWindow = (ProfileWindow) app
.addWindow(ProfileWindow.class
.toString(), 1);
profileWindow.setJID(jid);
profileWindow.show();
}
});
}
} else {
// give a message if there are no followers
followersInstruction
.setText(uiText.NoFollowers());
}
}
});
// get the people who are being followed by this person
final DefaultTaskInfo task2 = new DefaultTaskInfo(
uiText.FetchingFollowing(), false);
TaskMonitor.getInstance().addTask(task2);
OswServiceFactory.getService().getSubscriptions(jid,
new RequestCallback<List<String>>() {
@Override
public void onFailure() {
// TODO Auto-generated method stub
task2.complete("", Status.failure);
}
@Override
public void onSuccess(List<String> result) {
task2.complete("", Status.succes);
// see if there are any results
if (result.size() > 0) {
// sort the list alphabetically
Collections.sort(result, new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
return o1.compareToIgnoreCase(o2);
}
});
// add all the jids to the list
for (final String jid : result) {
Label following = new Label(jid);
following.addStyleName("link");
following.setTitle(uiText.ViewProfileOf() + " " + jid);
followingPanel.add(following);
following.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
// get the app instance from the session
// manager
AbstractApplication app = OswClient
.getInstance()
.getCurrentApplication();
ProfileWindow profileWindow = (ProfileWindow) app
.addWindow(ProfileWindow.class
.toString(), 1);
profileWindow.setJID(jid);
profileWindow.show();
}
});
}
} else {
// give a message if no one is followed
followingInstruction
.setText(uiText.NoFollowing());
}
}