mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
send comments functionality
This commit is contained in:
@@ -136,7 +136,7 @@ public class DialogFactory {
|
||||
public LoginDialog createLoginDialog() {
|
||||
LoginDialog dialog = new LoginDialog(mainFrame);
|
||||
return dialog;
|
||||
}
|
||||
}
|
||||
|
||||
public UploadDialog createUploadDialog(IPlugInPort plugInPort, CloudPresenter cloudPresenter) {
|
||||
UploadDialog dialog = new UploadDialog(mainFrame, plugInPort, cloudPresenter);
|
||||
|
||||
@@ -0,0 +1,201 @@
|
||||
package org.diylc.swing.plugins.cloud.view;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.Insets;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JSeparator;
|
||||
import javax.swing.JTextArea;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.diylc.common.ITask;
|
||||
import org.diylc.core.IView;
|
||||
import org.diylc.plugins.cloud.model.CommentEntity;
|
||||
import org.diylc.plugins.cloud.model.ProjectEntity;
|
||||
import org.diylc.plugins.cloud.presenter.CloudException;
|
||||
import org.diylc.plugins.cloud.presenter.CloudPresenter;
|
||||
import org.diylc.swing.plugins.cloud.view.browser.CloudBrowserFrame;
|
||||
|
||||
public class CommentDialog extends JDialog {
|
||||
|
||||
private static final String JUST_NOW = "just now";
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(CommentDialog.class);
|
||||
|
||||
private ProjectEntity project;
|
||||
private List<CommentEntity> comments;
|
||||
private CloudPresenter presenter;
|
||||
|
||||
private JPanel mainPanel;
|
||||
private JPanel listPanel;
|
||||
private JTextArea replyArea;
|
||||
private JButton sendButton;
|
||||
|
||||
private int lastPosition = 0;
|
||||
|
||||
private CloudBrowserFrame owner;
|
||||
|
||||
public CommentDialog(CloudBrowserFrame owner, ProjectEntity project, List<CommentEntity> comments,
|
||||
CloudPresenter presenter) {
|
||||
super(owner, "Comments on " + project.getName());
|
||||
this.owner = owner;
|
||||
this.project = project;
|
||||
this.comments = comments;
|
||||
this.presenter = presenter;
|
||||
setMinimumSize(new Dimension(400, 600));
|
||||
setContentPane(getMainPanel());
|
||||
pack();
|
||||
setLocationRelativeTo(owner);
|
||||
setModal(true);
|
||||
if (!presenter.isLoggedIn()) {
|
||||
getReplyArea().setEnabled(false);
|
||||
getReplyArea().setText("Must be logged in to reply.");
|
||||
getSendButton().setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
private JPanel getListPanel() {
|
||||
if (listPanel == null) {
|
||||
listPanel = new JPanel(new GridBagLayout());
|
||||
listPanel.setBackground(Color.white);
|
||||
for (int i = 0; i < comments.size(); i++) {
|
||||
CommentEntity c = comments.get(i);
|
||||
addComment(c);
|
||||
|
||||
GridBagConstraints gbc = new GridBagConstraints();
|
||||
gbc.gridy = 10000;
|
||||
gbc.weighty = 1;
|
||||
listPanel.add(new JLabel(), gbc);
|
||||
}
|
||||
}
|
||||
return listPanel;
|
||||
}
|
||||
|
||||
private JPanel getMainPanel() {
|
||||
if (mainPanel == null) {
|
||||
mainPanel = new JPanel(new GridBagLayout());
|
||||
mainPanel.setBackground(Color.white);
|
||||
|
||||
GridBagConstraints gbc = new GridBagConstraints();
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = 0;
|
||||
gbc.weighty = 3;
|
||||
gbc.weightx = 1;
|
||||
gbc.fill = GridBagConstraints.BOTH;
|
||||
JScrollPane scroll = new JScrollPane(getListPanel());
|
||||
scroll.getVerticalScrollBar().setUnitIncrement(16);
|
||||
mainPanel.add(scroll, gbc);
|
||||
|
||||
// Add components to the bottom
|
||||
gbc.insets = new Insets(2, 2, 2, 2);
|
||||
gbc.gridy++;
|
||||
gbc.weighty = 0;
|
||||
gbc.fill = GridBagConstraints.NONE;
|
||||
gbc.anchor = GridBagConstraints.LINE_START;
|
||||
mainPanel.add(new JLabel("Write a reply:"), gbc);
|
||||
|
||||
gbc.gridy++;
|
||||
gbc.fill = GridBagConstraints.BOTH;
|
||||
gbc.weighty = 0.5;
|
||||
mainPanel.add(new JScrollPane(getReplyArea()), gbc);
|
||||
|
||||
gbc.gridy++;
|
||||
gbc.weighty = 0;
|
||||
gbc.fill = GridBagConstraints.NONE;
|
||||
gbc.anchor = GridBagConstraints.LINE_END;
|
||||
mainPanel.add(getSendButton(), gbc);
|
||||
}
|
||||
return mainPanel;
|
||||
}
|
||||
|
||||
private JTextArea getReplyArea() {
|
||||
if (replyArea == null) {
|
||||
replyArea = new JTextArea();
|
||||
replyArea.setFont(getSendButton().getFont());
|
||||
}
|
||||
return replyArea;
|
||||
}
|
||||
|
||||
private JButton getSendButton() {
|
||||
if (sendButton == null) {
|
||||
sendButton = new JButton("Send Reply");
|
||||
sendButton.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
final String comment = getReplyArea().getText().replace("\n", "<br>");
|
||||
if (comment.trim().length() == 0)
|
||||
owner.showMessage("Cannot post an empty comment.", "Cloud Error", IView.ERROR_MESSAGE);
|
||||
|
||||
owner.executeBackgroundTask(new ITask<Void>() {
|
||||
|
||||
@Override
|
||||
public Void doInBackground() throws Exception {
|
||||
presenter.postComment(project.getId(), comment);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failed(Exception e) {
|
||||
owner.showMessage("Error posting comment.", "Cloud Error", IView.ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void complete(Void result) {
|
||||
getReplyArea().setText("");
|
||||
CommentEntity newComment = new CommentEntity();
|
||||
newComment.setPostedAt(JUST_NOW);
|
||||
newComment.setUsername(presenter.getCurrentUsername());
|
||||
newComment.setComment(comment);
|
||||
addComment(newComment).requestFocusInWindow();
|
||||
getListPanel().revalidate();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
return sendButton;
|
||||
}
|
||||
|
||||
private JTextArea addComment(CommentEntity c) {
|
||||
GridBagConstraints gbc = new GridBagConstraints();
|
||||
gbc.fill = GridBagConstraints.NONE;
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = lastPosition++;
|
||||
gbc.insets = new Insets(2, 2, 2, 2);
|
||||
gbc.anchor = GridBagConstraints.LINE_START;
|
||||
gbc.weightx = 1;
|
||||
getListPanel().add(
|
||||
new JLabel("<html><b>" + c.getUsername() + "</b> wrote " + (c.getPostedAt().equals(JUST_NOW) ? "" : "on ")
|
||||
+ c.getPostedAt() + " </html>"), gbc);
|
||||
gbc.gridy = lastPosition++;
|
||||
|
||||
JTextArea commentArea = new JTextArea(c.getComment().replace("<br>", "\n"));
|
||||
commentArea.setEditable(false);
|
||||
commentArea.setFont(getSendButton().getFont());
|
||||
commentArea.setLineWrap(true);
|
||||
commentArea.setWrapStyleWord(true);
|
||||
// commentArea.setRequestFocusEnabled(false);
|
||||
commentArea.setForeground(Color.gray);
|
||||
// DefaultCaret caret = (DefaultCaret) commentArea.getCaret();
|
||||
// caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
|
||||
getListPanel().add(commentArea, gbc);
|
||||
gbc.gridy = lastPosition++;
|
||||
|
||||
gbc.fill = GridBagConstraints.HORIZONTAL;
|
||||
getListPanel().add(new JSeparator(), gbc);
|
||||
return commentArea;
|
||||
}
|
||||
}
|
||||
+26
-11
@@ -40,12 +40,13 @@ import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.common.ITask;
|
||||
import org.diylc.core.IView;
|
||||
import org.diylc.images.IconLoader;
|
||||
import org.diylc.plugins.cloud.model.CommentEntity;
|
||||
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;
|
||||
import org.diylc.swing.plugins.cloud.view.CommentDialog;
|
||||
import org.diylc.swing.plugins.file.FileFilterEnum;
|
||||
|
||||
public class ResultsScrollPanel extends JScrollPane {
|
||||
@@ -192,12 +193,26 @@ public class ResultsScrollPanel extends JScrollPane {
|
||||
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();
|
||||
}
|
||||
cloudUI.executeBackgroundTask(new ITask<List<CommentEntity>>() {
|
||||
|
||||
@Override
|
||||
public List<CommentEntity> doInBackground() throws Exception {
|
||||
return cloudPresenter.getComments(project.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failed(Exception e) {
|
||||
cloudUI.showMessage("Could not open file. Detailed message is in the logs.", "Cloud Error",
|
||||
IView.ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void complete(List<CommentEntity> result) {
|
||||
CommentDialog dialog = new CommentDialog(cloudUI, project, result, cloudPresenter);
|
||||
dialog.setVisible(true);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -262,7 +277,7 @@ public class ResultsScrollPanel extends JScrollPane {
|
||||
|
||||
@Override
|
||||
public void failed(Exception e) {
|
||||
mainUI.showMessage("Could not open file. Detailed message is in the logs", "Error",
|
||||
mainUI.showMessage("Could not open file. Detailed message is in the logs.", "Error",
|
||||
ISwingUI.ERROR_MESSAGE);
|
||||
}
|
||||
});
|
||||
@@ -271,7 +286,7 @@ public class ResultsScrollPanel extends JScrollPane {
|
||||
|
||||
@Override
|
||||
public void failed(Exception e) {
|
||||
cloudUI.showMessage("Could not save to file. Detailed message is in the logs", "Error",
|
||||
cloudUI.showMessage("Could not save to file. Detailed message is in the logs.", "Error",
|
||||
ISwingUI.ERROR_MESSAGE);
|
||||
}
|
||||
});
|
||||
@@ -388,8 +403,8 @@ public class ResultsScrollPanel extends JScrollPane {
|
||||
List<ProjectEntity> newResults = get();
|
||||
addData(newResults);
|
||||
} catch (Exception e) {
|
||||
cloudUI.showMessage("Search failed! Detailed message is in the logs. Please report to the author.",
|
||||
"Search Failed", IView.ERROR_MESSAGE);
|
||||
cloudUI.showMessage("Search failed! Detailed message is in the logs.", "Search Failed",
|
||||
IView.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user