Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.DS_Store
1 change: 1 addition & 0 deletions bugrap/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
/.settings/
/**/.DS_Store
/**/rebel.xml
/.vaadin-designer2/
32 changes: 32 additions & 0 deletions bugrap/.vaadin-designer2/designer-theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -12500,4 +12500,36 @@ div.v-layout.v-horizontal.v-widget {
display: inline-block;
width: 19px;
overflow: hidden;
}

.mytheme div.bar {
background-color: gray;
height: 20px;
width: 10px;
vertical-align: center;
}

.mytheme div.v-slot-removed-upload {
display: none;
}

.mytheme div.completed-upload div.v-button {
display: none;
}

.mytheme div.completed-upload:hover div.v-button {
display: inline-block;
}

.mytheme div.v-slot-completed-upload:hover {
color: #474747;
border-radius: 4px;
border: 1px solid #d5d5d5;
-webkit-box-shadow: 0 2px 3px rgba(0, 0, 0, 0.05);
box-shadow: 0 2px 3px rgba(0, 0, 0, 0.05);
}

.mytheme div.v-slot-completed-upload div {
margin-bottom: 5px;
margin-left: 5px;
}
2 changes: 1 addition & 1 deletion bugrap/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@
<goal>update-widgetset</goal>
<goal>compile</goal>
<!-- Comment out compile-theme goal to use on-the-fly theme compilation
<goal>compile-theme</goal>
-->
<goal>compile-theme</goal>
</goals>
</execution>
</executions>
Expand Down
117 changes: 60 additions & 57 deletions bugrap/src/main/java/org/vaadin/bugrap/ui/ReportDetailView.java
Original file line number Diff line number Diff line change
@@ -1,39 +1,33 @@
package org.vaadin.bugrap.ui;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.List;

import org.vaadin.bugrap.domain.entities.Comment;
import org.vaadin.bugrap.domain.entities.Report;
import org.vaadin.bugrap.ui.beans.FileUploadEvent;
import org.vaadin.bugrap.ui.generated.ReportDetailViewBase;
import org.vaadin.bugrap.util.IUploadedFileListener;

import com.vaadin.data.Binder;
import com.vaadin.server.FileDownloader;
import com.vaadin.server.FileResource;
import com.vaadin.ui.Component;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Link;
import com.vaadin.ui.Notification;
import com.vaadin.ui.Notification.Type;
import com.vaadin.ui.ProgressBar;
import com.vaadin.ui.Upload.ProgressListener;
import com.vaadin.ui.Upload.Receiver;
import com.vaadin.ui.Upload;
import com.vaadin.ui.Upload.FinishedEvent;
import com.vaadin.ui.Upload.FinishedListener;
import com.vaadin.ui.Upload.StartedEvent;
import com.vaadin.ui.Upload.StartedListener;
import com.vaadin.ui.Upload.SucceededEvent;
import com.vaadin.ui.Upload.SucceededListener;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;

public class ReportDetailView extends ReportDetailViewBase
implements Receiver, SucceededListener, StartedListener, ProgressListener {
implements StartedListener, Component.Listener, IUploadedFileListener, FinishedListener {

private ReportsModel model;
private Binder<Report> binder = new Binder<Report>();
private ProgressBar uploadInProgress;
private int numOfOngoingUploads = 0;

public ReportDetailView(ReportsModel reportModel) {
model = reportModel;
Expand All @@ -55,11 +49,10 @@ private void initializeUIComponents() {
btnRevertReport.addClickListener(evt -> revertChanges());
btnDone.addClickListener(evt -> saveComment());
btnCancel.addClickListener(evt -> closeWindow());
btnUpload.setReceiver(this);
btnUpload.addStartedListener(this);
btnUpload.addSucceededListener(this);
btnUpload.addProgressListener(this);
txtComment.addValueChangeListener(evt -> commentsUpdated());
btnUpload.addFinishedListener(this);
txtComment.addValueChangeListener(evt -> setDoneButtonEnablement());
pnlAttachments.getContent().addListener(this);
}

private void init() {
Expand All @@ -73,7 +66,6 @@ private void init() {

private void cleanAttachments() {
((HorizontalLayout) pnlAttachments.getContent()).removeAllComponents();
pnlAttachments.setVisible(false);
}

private void initializeComboContents() {
Expand All @@ -95,8 +87,13 @@ private void fillComments() {
btnDone.setEnabled(false);
}

private void commentsUpdated() {
btnDone.setEnabled(true);
private void setDoneButtonEnablement() {
boolean isEnabled = false;
if (numOfOngoingUploads > 0)
isEnabled = false;
else
isEnabled = !txtComment.isEmpty() || model.hasFilesToSave();
btnDone.setEnabled(isEnabled);
}

private void saveReport() {
Expand All @@ -119,55 +116,61 @@ private void saveComment() {

@Override
public void uploadStarted(StartedEvent event) {
pnlAttachments.setVisible(true);
initiateUploadTracker(event);
addNewUpload();
numOfOngoingUploads++;
}

private void addNewUpload() {
HorizontalLayout layout = (HorizontalLayout) btnUpload.getParent();
Upload newUpload = new Upload();
newUpload.setButtonCaption("Attachments...");
newUpload.addStartedListener(this);
newUpload.addFinishedListener(this);
layout.addComponent(newUpload, layout.getComponentIndex(btnUpload));
btnUpload.setStyleName("removed-upload", true);
btnUpload = newUpload;
}

private void initiateUploadTracker(StartedEvent event) {
UploadTracker uploadTracker = new UploadTracker((Upload) event.getSource(), event.getFilename());
uploadTracker.setUploadedFileListener(this);
HorizontalLayout layout = (HorizontalLayout) pnlAttachments.getContent();
ProgressBar progress = new ProgressBar();
progress.setCaption(event.getFilename());
uploadInProgress = progress;
layout.addComponent(progress);
btnDone.setEnabled(false);//disable done button until upload completes
layout.addComponent(uploadTracker);
}

private void closeWindow() {
Window window = (Window) getParent();
window.close();
}

@Override
public void uploadSucceeded(SucceededEvent event) {
HorizontalLayout layout = (HorizontalLayout) pnlAttachments.getContent();
layout.removeComponent(uploadInProgress);
uploadInProgress = null;
FileResource file = new FileResource(new File(ReportsModel.FILEUPLOAD_PATH + event.getFilename()));
try {
model.attachFile(event.getFilename(), event.getMIMEType(), file.getStream());
} catch (IOException e) {
Notification.show("Error occurred while uploading the file", e.getMessage(), Type.ERROR_MESSAGE);
}
FileDownloader downloader = new FileDownloader(file);
Link link = new Link();
link.setCaption(event.getFilename());
link.setStyleName("tiny");
downloader.extend(link);
layout.addComponent(link);
commentsUpdated();
public void componentEvent(Event event) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is componentEvent method being used?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, since ReportDetailView implements Component.Listener, it is used whenever a component added or removed from the container

HorizontalLayout layout = (HorizontalLayout) event.getSource();
pnlAttachments.setVisible(layout.getComponentCount() > 0);
}

@Override
public OutputStream receiveUpload(String filename, String mimeType) {
FileOutputStream fos = null;
public void uploadedFileReceived(FileUploadEvent event) {
try {
fos = new FileOutputStream(ReportsModel.FILEUPLOAD_PATH + filename);
} catch (FileNotFoundException e) {
Notification.show("Error occurred while uploading the file", e.getMessage(), Type.ERROR_MESSAGE);
} finally {
return fos;
model.attachFile(event.getSource(), event.getFilename(), event.getFilename(), event.getStream());
setDoneButtonEnablement();
} catch (IOException e) {
Notification.show("Error uploading file : " + event.getFilename(),
"There was an error while uploading the file :" + e.getMessage(),
com.vaadin.ui.Notification.Type.ERROR_MESSAGE);
}
}

@Override
public void updateProgress(long readBytes, long contentLength) {
if (uploadInProgress != null)
uploadInProgress.setValue(((float) readBytes) / contentLength);
public void uploadFinished(FinishedEvent event) {
numOfOngoingUploads--;
setDoneButtonEnablement();
}

private void closeWindow() {
Window window = (Window) getParent();
window.close();
@Override
public void uploadedFileDeleted(Object source) {
model.removeAttachedFile(source);
setDoneButtonEnablement();
}
}
54 changes: 29 additions & 25 deletions bugrap/src/main/java/org/vaadin/bugrap/ui/ReportsModel.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package org.vaadin.bugrap.ui;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.vaadin.bugrap.BaseModel;
Expand All @@ -25,7 +28,6 @@

import com.vaadin.data.ValidationException;
import com.vaadin.navigator.Navigator;
import com.vaadin.server.DownloadStream;

public class ReportsModel extends BaseModel {

Expand All @@ -35,13 +37,11 @@ public class ReportsModel extends BaseModel {

public static final int ASSIGNEE_ME = 0;
public static final int ASSIGNEE_ALL = 1;

public static final int VERSIONID_ALL = 0;

public static final String FILEUPLOAD_PATH = "/Users/onuridrisoglu/Downloads/temp/";
public static final int VERSIONID_ALL = 0;

private List<Report> selectedReports = new ArrayList<Report>();
private List<Comment> uploadedFilesToSave = new ArrayList<Comment>();
private Map<Object, Comment> uploadedFilesToSave = new HashMap<Object, Comment>();
protected Report reportForEdit;

private int assigneeFilterMode = ASSIGNEE_ALL;
Expand Down Expand Up @@ -70,14 +70,6 @@ else if (selectedReports.size() == 1)
return SELECTIONMODE_MULTI;
}

public List<Comment> getUploadedFilesToSave() {
return uploadedFilesToSave;
}

public void setUploadedFilesToSave(List<Comment> uploadedFilesToSave) {
this.uploadedFilesToSave = uploadedFilesToSave;
}

public List<Project> findProjects() {
List<Project> projects = new ArrayList<Project>();
projects.addAll(getRepository().findProjects());
Expand All @@ -104,15 +96,15 @@ public Collection<Reporter> findReporters() {
public List<ProjectVersion> findProjectVersions() {
return findProjectVersions(reportForEdit.getProject());
}

public List<ProjectVersion> findProjectVersionsWithAllOption(Project project) {
List<ProjectVersion> projectVersions = findProjectVersions(project);

ProjectVersion allVersion = new ProjectVersion();
allVersion.setId(VERSIONID_ALL);
allVersion.setVersion("All Versions");
allVersion.setProject(project);

projectVersions.add(0, allVersion);
return projectVersions;
}
Expand All @@ -131,7 +123,7 @@ public Collection<Report> findReports(Project project, ProjectVersion version) {
query.projectVersion = version;
}
if (assigneeFilterMode == ASSIGNEE_ME) {
query.reportAssignee = getLoginUser();
query.reportAssignee = getLoginUser();
}
query.reportStatuses = statusFilters;
return getRepository().findReports(query);
Expand Down Expand Up @@ -192,35 +184,46 @@ public void saveComment(String commentTxt) {
getRepository().save(comment);
}

public Comment createComment(String filename, String mimeType, DownloadStream stream) throws IOException {
public Comment createComment(String filename, String mimeType, InputStream stream) throws IOException {
Comment comment = new Comment();
comment.setReport(reportForEdit);
comment.setAttachment(stream.getStream().readAllBytes());
comment.setAttachment(stream.readAllBytes());
comment.setAttachmentName(filename);
comment.setAuthor(getLoginUser());
comment.setTimestamp(new Date());
comment.setType(Comment.Type.ATTACHMENT);
return comment;
}

public void attachFile(String filename, String mimeType, DownloadStream stream) throws IOException {
public void attachFile(Object source, String filename, String mimeType, InputStream stream) throws IOException {
Comment attachmentComment = createComment(filename, mimeType, stream);
uploadedFilesToSave.add(attachmentComment);
uploadedFilesToSave.put(source, attachmentComment);
}

public void removeAttachedFile(Object source) {
uploadedFilesToSave.remove(source);
}

public void saveAttachments() {
for (Comment attachment : uploadedFilesToSave) {
for (Comment attachment : uploadedFilesToSave.values()) {
getRepository().save(attachment);
}
uploadedFilesToSave.clear();
}

public boolean hasFilesToSave() {
return uploadedFilesToSave.size() > 0;
}

public ReportDistribution getReportDistribution(ProjectVersion version) {
ReportDistribution distribution = new ReportDistribution();
boolean isAllVersions = version.getId() == VERSIONID_ALL;
distribution.setClosedReports(isAllVersions ? getRepository().countClosedReports(version.getProject()) : getRepository().countClosedReports(version));
distribution.setAssignedReports(isAllVersions ? getRepository().countOpenedReports(version.getProject()) : getRepository().countOpenedReports(version));
distribution.setUnassignedReports(isAllVersions ? getRepository().countUnassignedReports(version.getProject()) : getRepository().countUnassignedReports(version));
distribution.setClosedReports(isAllVersions ? getRepository().countClosedReports(version.getProject())
: getRepository().countClosedReports(version));
distribution.setAssignedReports(isAllVersions ? getRepository().countOpenedReports(version.getProject())
: getRepository().countOpenedReports(version));
distribution.setUnassignedReports(isAllVersions ? getRepository().countUnassignedReports(version.getProject())
: getRepository().countUnassignedReports(version));
return distribution;
}

Expand All @@ -247,4 +250,5 @@ public void changeStatusFilters(boolean isChecked, Status... status) {
else
statusFilters.removeAll(Arrays.asList(status));
}

}
Loading