Skip to content

LogView: Date column should be more fine grained #2963

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ public class LogEntry extends AbstractEntry {

public static final String SPACE = " "; //$NON-NLS-1$
public static final String F_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss.SSS"; //$NON-NLS-1$
private static final DateTimeFormatter GREGORIAN_SDF = DateTimeFormatter.ofPattern(F_DATE_FORMAT, Locale.ENGLISH)
static final DateTimeFormatter GREGORIAN_SDF = DateTimeFormatter.ofPattern(F_DATE_FORMAT, Locale.ENGLISH)
.withZone(ZoneId.systemDefault());
private static final DateTimeFormatter LOCAL_SDF = DateTimeFormatter.ofPattern(F_DATE_FORMAT)
static final DateTimeFormatter LOCAL_SDF = DateTimeFormatter.ofPattern(F_DATE_FORMAT)
.withZone(ZoneId.systemDefault());

private String pluginId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
*******************************************************************************/
package org.eclipse.ui.internal.views.log;

import static org.eclipse.ui.internal.views.log.LogEntry.GREGORIAN_SDF;
import static org.eclipse.ui.internal.views.log.LogEntry.LOCAL_SDF;

import java.io.PrintWriter;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.util.Date;

/**
Expand All @@ -31,8 +33,10 @@ public class LogSession extends Group {
* @since 3.5
*/
public static final String SESSION = "!SESSION"; //$NON-NLS-1$

private String sessionData;
private Date date;
private String fDateString;

public LogSession() {
super(Messages.LogViewLabelProvider_Session);
Expand All @@ -42,11 +46,30 @@ public Date getDate() {
return date;
}

/**
* Returns a pretty-print formatting for the date for this entry
*
* @return the formatted date for this entry
*/
public String getFormattedDate() {
if (fDateString == null) {
Date tmpdate = getDate();
if (tmpdate != null) {
fDateString = LOCAL_SDF.format(tmpdate.toInstant());
}
}
return fDateString;
}

public void setDate(String dateString) {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); //$NON-NLS-1$
try {
date = formatter.parse(dateString);
} catch (ParseException e) { // do nothing
Date parsed = Date.from(Instant.from(GREGORIAN_SDF.parse(dateString)));
if (parsed != null) {
this.date = parsed;
fDateString = LOCAL_SDF.format(parsed.toInstant());
}
} catch (Exception e) {
// do nothing
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*******************************************************************************/
package org.eclipse.ui.internal.views.log;

import java.text.DateFormat;
import java.util.ArrayList;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.resource.JFaceResources;
Expand All @@ -34,8 +33,6 @@ public class LogViewLabelProvider extends LabelProvider implements ITableLabelPr
private Image errorWithStackImage;
private Image hierarchicalImage;
ArrayList<Object> consumers = new ArrayList<>();
private DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);

private LogView logView;

public LogViewLabelProvider(LogView logView) {
Expand Down Expand Up @@ -81,7 +78,7 @@ public String getColumnText(Object element, int columnIndex) {
if (session.getDate() == null)
return ""; //$NON-NLS-1$

return dateFormat.format(session.getDate());
return session.getFormattedDate();
}

if ((element instanceof Group) && (columnIndex == 0)) {
Expand All @@ -106,7 +103,7 @@ public String getColumnText(Object element, int columnIndex) {
if (entry.getPluginId() != null)
return entry.getPluginId();
case 2 :
return dateFormat.format(entry.getDate());
return entry.getFormattedDate();
}
}

Expand Down
Loading