From d1279ccc9aabc5d435c5ef226421e9f0e573f95a Mon Sep 17 00:00:00 2001 From: bancika Date: Thu, 27 Oct 2016 13:07:23 +0200 Subject: [PATCH] added comment support --- .../plugins/cloud/model/CommentEntity.java | 98 +++++++++++++++++++ .../plugins/cloud/model/IServiceAPI.java | 9 ++ .../cloud/presenter/CloudPresenter.java | 19 ++++ .../cloud/view/browser/CloudBrowserFrame.java | 2 +- .../view/browser/ResultsScrollPanel.java | 19 +++- 5 files changed, 145 insertions(+), 2 deletions(-) create mode 100644 diylc/diylc-core/src/org/diylc/plugins/cloud/model/CommentEntity.java diff --git a/diylc/diylc-core/src/org/diylc/plugins/cloud/model/CommentEntity.java b/diylc/diylc-core/src/org/diylc/plugins/cloud/model/CommentEntity.java new file mode 100644 index 00000000..5a7e5a03 --- /dev/null +++ b/diylc/diylc-core/src/org/diylc/plugins/cloud/model/CommentEntity.java @@ -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 + "]"; + } +} diff --git a/diylc/diylc-core/src/org/diylc/plugins/cloud/model/IServiceAPI.java b/diylc/diylc-core/src/org/diylc/plugins/cloud/model/IServiceAPI.java index fc91180f..306b57f4 100644 --- a/diylc/diylc-core/src/org/diylc/plugins/cloud/model/IServiceAPI.java +++ b/diylc/diylc-core/src/org/diylc/plugins/cloud/model/IServiceAPI.java @@ -133,4 +133,13 @@ public interface IServiceAPI { * @return a {@link List} of available sortings. */ List 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); } diff --git a/diylc/diylc-core/src/org/diylc/plugins/cloud/presenter/CloudPresenter.java b/diylc/diylc-core/src/org/diylc/plugins/cloud/presenter/CloudPresenter.java index cc15b33e..2fcacb2c 100644 --- a/diylc/diylc-core/src/org/diylc/plugins/cloud/presenter/CloudPresenter.java +++ b/diylc/diylc-core/src/org/diylc/plugins/cloud/presenter/CloudPresenter.java @@ -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 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 comments = (List) 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 { diff --git a/diylc/diylc-swing/src/org/diylc/swing/plugins/cloud/view/browser/CloudBrowserFrame.java b/diylc/diylc-swing/src/org/diylc/swing/plugins/cloud/view/browser/CloudBrowserFrame.java index 9c322f9c..221df020 100644 --- a/diylc/diylc-swing/src/org/diylc/swing/plugins/cloud/view/browser/CloudBrowserFrame.java +++ b/diylc/diylc-swing/src/org/diylc/swing/plugins/cloud/view/browser/CloudBrowserFrame.java @@ -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; } diff --git a/diylc/diylc-swing/src/org/diylc/swing/plugins/cloud/view/browser/ResultsScrollPanel.java b/diylc/diylc-swing/src/org/diylc/swing/plugins/cloud/view/browser/ResultsScrollPanel.java index cb67636c..65b0bf90 100644 --- a/diylc/diylc-swing/src/org/diylc/swing/plugins/cloud/view/browser/ResultsScrollPanel.java +++ b/diylc/diylc-swing/src/org/diylc/swing/plugins/cloud/view/browser/ResultsScrollPanel.java @@ -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);