summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Sawicki2011-04-14 18:28:01 (EDT)
committerChris Aniszczyk2011-04-15 11:08:46 (EDT)
commit0dccbf11c3f681f0558c8b8f197462bf5d94101c (patch)
tree9062d9c7baf42c8e61de55f5118d26438664c6e9
parent1ea5ffc1d7badbab238e6500f30c7f9888039171 (diff)
downloadegit-github-0dccbf11c3f681f0558c8b8f197462bf5d94101c.zip
egit-github-0dccbf11c3f681f0558c8b8f197462bf5d94101c.tar.gz
egit-github-0dccbf11c3f681f0558c8b8f197462bf5d94101c.tar.bz2
Add generated summary text with file and size summaryrefs/changes/30/3130/3
Change-Id: Iedc49bdb6d8638b6e42e0df2c7f4ff0061deef37 Signed-off-by: Kevin Sawicki <kevin@github.com> Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
-rw-r--r--org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistTaskDataHandler.java40
-rw-r--r--org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/Messages.java24
-rw-r--r--org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/messages.properties8
3 files changed, 71 insertions, 1 deletions
diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistTaskDataHandler.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistTaskDataHandler.java
index da9e3a3..5ae7ef6 100644
--- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistTaskDataHandler.java
+++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistTaskDataHandler.java
@@ -11,6 +11,8 @@
package org.eclipse.mylyn.internal.github.core.gist;
import java.io.IOException;
+import java.text.DecimalFormat;
+import java.text.MessageFormat;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -131,9 +133,13 @@ public class GistTaskDataHandler extends AbstractTaskDataHandler {
}
Map<String, GistFile> files = gist.getFiles();
+ int fileCount = 0;
+ long sizeCount = 0;
if (files != null && !files.isEmpty()) {
int count = 1;
for (GistFile file : files.values()) {
+ fileCount++;
+ sizeCount += file.getSize();
TaskAttachmentMapper attachmentMapper = new TaskAttachmentMapper();
attachmentMapper.setFileName(file.getFilename());
attachmentMapper.setReplaceExisting(true);
@@ -153,9 +159,41 @@ public class GistTaskDataHandler extends AbstractTaskDataHandler {
GistAttribute.COMMENT_NEW.create(data);
+ TaskAttribute summary = GistAttribute.SUMMARY.create(data);
+ mapper.setValue(summary, generateSummary(fileCount, sizeCount));
+
return data;
}
+ private String generateSummary(int files, long size) {
+ StringBuilder summaryText = new StringBuilder();
+ if (files != 1)
+ summaryText.append(MessageFormat.format(
+ Messages.GistTaskDataHandler_FilesMultiple, files));
+ else
+ summaryText.append(Messages.GistTaskDataHandler_FilesSingle);
+ summaryText.append(',').append(' ').append(formatSize(size));
+ return summaryText.toString();
+ }
+
+ private String formatSize(long size) {
+ if (size == 1) {
+ return Messages.GistTaskDataHandler_SizeByte;
+ } else if (size < 1024) {
+ return new DecimalFormat(Messages.GistTaskDataHandler_SizeBytes)
+ .format(size);
+ } else if (size >= 1024 && size <= 1048575) {
+ return new DecimalFormat(Messages.GistTaskDataHandler_SizeKilobytes)
+ .format(size / 1024.0);
+ } else if (size >= 1048576 && size <= 1073741823) {
+ return new DecimalFormat(Messages.GistTaskDataHandler_SizeMegabytes)
+ .format(size / 1048576.0);
+ } else {
+ return new DecimalFormat(Messages.GistTaskDataHandler_SizeGigabytes)
+ .format(size / 1073741824.0);
+ }
+ }
+
/**
* @see org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler#postTaskData(org.eclipse.mylyn.tasks.core.TaskRepository,
* org.eclipse.mylyn.tasks.core.data.TaskData, java.util.Set,
@@ -219,7 +257,7 @@ public class GistTaskDataHandler extends AbstractTaskDataHandler {
TaskAttributeMapper mapper = data.getAttributeMapper();
TaskAttribute summary = GistAttribute.SUMMARY.create(data);
- mapper.setValue(summary, "New Gist");
+ mapper.setValue(summary, Messages.GistTaskDataHandler_SummaryNewGist);
GistAttribute.DESCRIPTION.create(data);
return true;
diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/Messages.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/Messages.java
index 4ba2416..30dba4e 100644
--- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/Messages.java
+++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/Messages.java
@@ -49,6 +49,30 @@ public class Messages extends NLS {
/** */
public static String GistConnector_LabelConnector;
+ /** */
+ public static String GistTaskDataHandler_FilesMultiple;
+
+ /** */
+ public static String GistTaskDataHandler_FilesSingle;
+
+ /** */
+ public static String GistTaskDataHandler_SizeByte;
+
+ /** */
+ public static String GistTaskDataHandler_SizeBytes;
+
+ /** */
+ public static String GistTaskDataHandler_SizeGigabytes;
+
+ /** */
+ public static String GistTaskDataHandler_SizeKilobytes;
+
+ /** */
+ public static String GistTaskDataHandler_SizeMegabytes;
+
+ /** */
+ public static String GistTaskDataHandler_SummaryNewGist;
+
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/messages.properties b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/messages.properties
index 3d78850..53b40d8 100644
--- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/messages.properties
+++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/messages.properties
@@ -8,3 +8,11 @@ GistAttribute_LabelNewComment=New Comment
GistAttribute_LabelSummary=Summary
GistAttribute_LabelUrl=Url
GistConnector_LabelConnector=Github Gists
+GistTaskDataHandler_FilesMultiple={0} files
+GistTaskDataHandler_FilesSingle=1 file
+GistTaskDataHandler_SizeByte=1 byte
+GistTaskDataHandler_SizeBytes=0 bytes
+GistTaskDataHandler_SizeGigabytes=0.00 GB
+GistTaskDataHandler_SizeKilobytes=0.00 KB
+GistTaskDataHandler_SizeMegabytes=0.00 MB
+GistTaskDataHandler_SummaryNewGist=New Gist