added comment support

This commit is contained in:
bancika
2016-10-27 13:07:23 +02:00
parent 0da4375857
commit d1279ccc9a
5 changed files with 145 additions and 2 deletions
@@ -0,0 +1,98 @@
package org.diylc.plugins.cloud.model;
public class CommentEntity {
private int id;
private int userId;
private String username;
private String comment;
private String postedAt;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getComment() {
return comment;
}
public void setComment(String comment) {
this.comment = comment;
}
public String getDate() {
return postedAt;
}
public void setDate(String date) {
this.postedAt = date;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((comment == null) ? 0 : comment.hashCode());
result = prime * result + ((postedAt == null) ? 0 : postedAt.hashCode());
result = prime * result + id;
result = prime * result + userId;
result = prime * result + ((username == null) ? 0 : username.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
CommentEntity other = (CommentEntity) obj;
if (comment == null) {
if (other.comment != null)
return false;
} else if (!comment.equals(other.comment))
return false;
if (postedAt == null) {
if (other.postedAt != null)
return false;
} else if (!postedAt.equals(other.postedAt))
return false;
if (id != other.id)
return false;
if (userId != other.userId)
return false;
if (username == null) {
if (other.username != null)
return false;
} else if (!username.equals(other.username))
return false;
return true;
}
@Override
public String toString() {
return "CommentEntity [id=" + id + ", username=" + username + ", date=" + postedAt + "]";
}
}
@@ -133,4 +133,13 @@ public interface IServiceAPI {
* @return a {@link List} of available sortings.
*/
List<String> getSortings();
/**
* Returns all available comments for the given projectId.
*
* @param projectId
* @return string with error message if the error occurred or a list of {@link CommentEntity}
* objects.
*/
Object getComments(@ParamName("projectId") int projectId);
}
@@ -12,6 +12,7 @@ import java.util.List;
import org.apache.log4j.Logger;
import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.plugins.cloud.model.CommentEntity;
import org.diylc.plugins.cloud.model.IServiceAPI;
import org.diylc.plugins.cloud.model.ProjectEntity;
import org.diylc.plugins.cloud.model.UserEntity;
@@ -254,6 +255,24 @@ public class CloudPresenter {
}
}
public List<CommentEntity> GetComments(int projectId) throws CloudException {
try {
Object res = service.getComments(projectId);
if (res == null)
throw new CloudException("Failed to retreive search results.");
if (res instanceof String)
throw new CloudException(res.toString());
if (res instanceof List<?>) {
@SuppressWarnings("unchecked")
List<CommentEntity> comments = (List<CommentEntity>) res;
return comments;
}
throw new CloudException("Unexpected server response received for comments: " + res.getClass().getName());
} catch (Exception e) {
throw new CloudException(e);
}
}
private String getMachineId() {
if (machineId == null) {
try {
@@ -147,7 +147,7 @@ public class CloudBrowserFrame extends JFrame {
private ResultsScrollPanel getResultsScrollPane() {
if (resultsScrollPane == null) {
resultsScrollPane = new ResultsScrollPanel(swingUI, this, plugInPort, pagingProvider);
resultsScrollPane = new ResultsScrollPanel(swingUI, this, plugInPort, pagingProvider, cloudPresenter);
}
return resultsScrollPane;
}
@@ -41,6 +41,8 @@ import org.diylc.common.ITask;
import org.diylc.core.IView;
import org.diylc.images.IconLoader;
import org.diylc.plugins.cloud.model.ProjectEntity;
import org.diylc.plugins.cloud.presenter.CloudException;
import org.diylc.plugins.cloud.presenter.CloudPresenter;
import org.diylc.plugins.cloud.presenter.PagingProvider;
import org.diylc.swing.ISwingUI;
import org.diylc.swing.gui.DialogFactory;
@@ -73,14 +75,18 @@ public class ResultsScrollPanel extends JScrollPane {
private boolean armed;
private PagingProvider provider;
private CloudPresenter cloudPresenter;
private Icon spinnerIcon = IconLoader.Spinning.getIcon();
public ResultsScrollPanel(ISwingUI mainUI, CloudBrowserFrame cloudUI, IPlugInPort plugInPort, PagingProvider provider) {
public ResultsScrollPanel(ISwingUI mainUI, CloudBrowserFrame cloudUI, IPlugInPort plugInPort,
PagingProvider provider, CloudPresenter cloudPresenter) {
super();
this.mainUI = mainUI;
this.cloudUI = cloudUI;
this.plugInPort = plugInPort;
this.provider = provider;
this.cloudPresenter = cloudPresenter;
this.getVerticalScrollBar().setUnitIncrement(16);
this.setBorder(null);
@@ -183,6 +189,17 @@ public class ResultsScrollPanel extends JScrollPane {
new JLabel(Integer.toString(project.getCommentCount()), IconLoader.Messages.getIcon(), SwingConstants.LEFT);
commentLabel.setToolTipText("Click to see and add public comments");
commentLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
commentLabel.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
try {
cloudUI.showMessage(cloudPresenter.GetComments(project.getId()).toString(), "Comments", IView.INFORMATION_MESSAGE);
} catch (CloudException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
JLabel viewLabel =
new JLabel(Integer.toString(project.getViewCount()), IconLoader.Eye.getIcon(), SwingConstants.LEFT);