Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf2015-09-26 13:09:52 +0000
committerMatthias Sohn2015-10-04 22:04:58 +0000
commit76afd09ddd1e3e02c04830a10f01231a345af89e (patch)
tree7172fe9a260b9c0b4613c534a3de17e4d260ddda
parentb7dbf41b711a87b2e25aecfadb1de5c7ac58d2bd (diff)
downloadegit-76afd09ddd1e3e02c04830a10f01231a345af89e.tar.gz
egit-76afd09ddd1e3e02c04830a10f01231a345af89e.tar.xz
egit-76afd09ddd1e3e02c04830a10f01231a345af89e.zip
Configurable date format used consistently throughout EGit
Part 1: UI and use it in history view. * New DateFormatPreferencePage. * New UI preferences. * New PreferenceBasedDateFormatter. * Changed uses of GitDateFormatter and DateFormat to use the new PreferenceBasedDateFormatter. Some implementation notes: * The default format is the custom format (already existing DATE_FORMAT preference. Reasons: this is a reasonable (local) format, and if the user had configured something there, it will still be used. Keep surprises for the user at a minimum. * PreferenceBasedDateFormatter is a subtype of GitDateFormatter to keep changes at a minimum. It also helps in the views where the user can explicitly force RELATIVE dates. * The old date format (under "Label Decorations/Other/DateFormat") preference UI has been removed. * Where we use label providers, make those listen to preference changes related to their labels (dates, showing e-mails), not the viewers. The label providers fire an event when their state changes, users can just listen on those events. Limits the proliferation of checking specific preferences, and simplifies some code. * Otherwise, views or viewers refresh on date format preference changes. * This commit also fixes - bug 339797 (custom format for date column in history view), - bug 477151 (preference page silently ignores incorrect date formats) Bug: 339797 Bug: 477151 Bug: 477248 Change-Id: Icede623ca753c1c830920f5ef2e6b629d4ceafb4 Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
-rw-r--r--org.eclipse.egit.ui/plugin.properties2
-rw-r--r--org.eclipse.egit.ui/plugin.xml15
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/PluginPreferenceInitializer.java2
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIPreferences.java6
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/PreferenceBasedDateFormatter.java122
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java87
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CommitLabelProvider.java105
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CommitSelectDialog.java14
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/ResetTargetSelectionDialog.java9
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitGraphTable.java27
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitInfoBuilder.java18
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitMessageViewer.java17
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitSelectionDialog.java4
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java24
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GraphLabelProvider.java9
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/preferences/DateFormatPreferencePage.java292
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/preferences/GitDecoratorPreferencePage.java74
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties30
18 files changed, 725 insertions, 132 deletions
diff --git a/org.eclipse.egit.ui/plugin.properties b/org.eclipse.egit.ui/plugin.properties
index 0483621cbe..d82df2db2e 100644
--- a/org.eclipse.egit.ui/plugin.properties
+++ b/org.eclipse.egit.ui/plugin.properties
@@ -65,6 +65,7 @@ CompareWithRevisionAction_label=Histor&y...
GitKeyword_label = git egit
GitKeyword_Refresh_label = refresh
+GitKeyword_Date_label = date
GitActions_label=Git
GitActions_description = Git commands in workbench toolbar and menu
@@ -113,6 +114,7 @@ Theme_IgnoredResourceFont_description=The font used to display resources that ar
GitPreferences_name=Git
GitPreferences_WindowCachePreferencePage_name=Window Cache
+GitPreferences_DateFormatPreferencePage_name=Date Format
GitPreferences_DecoratorPreferencePage_name=Label Decorations
GitPreferences_CommittingPreferencePage_name=Committing
GitPreferences_StagingViewPreferencePage_name=Staging View
diff --git a/org.eclipse.egit.ui/plugin.xml b/org.eclipse.egit.ui/plugin.xml
index cf72591f65..6c5d416b9b 100644
--- a/org.eclipse.egit.ui/plugin.xml
+++ b/org.eclipse.egit.ui/plugin.xml
@@ -434,6 +434,17 @@
id="org.eclipse.egit.ui.keyword.git">
</keywordReference>
</page>
+ <page name="%GitPreferences_DateFormatPreferencePage_name"
+ category="org.eclipse.egit.ui.GitPreferences"
+ class="org.eclipse.egit.ui.internal.preferences.DateFormatPreferencePage"
+ id="org.eclipse.egit.ui.internal.preferences.DateFormatPreferencePage" >
+ <keywordReference
+ id="org.eclipse.egit.ui.keyword.git">
+ </keywordReference>
+ <keywordReference
+ id="org.eclipse.egit.ui.keyword.date">
+ </keywordReference>
+ </page>
<page name="%GitPreferences_DecoratorPreferencePage_name"
category="org.eclipse.egit.ui.GitPreferences"
class="org.eclipse.egit.ui.internal.preferences.GitDecoratorPreferencePage"
@@ -535,6 +546,10 @@
id="org.eclipse.egit.ui.keyword.refresh"
label="%GitKeyword_Refresh_label">
</keyword>
+ <keyword
+ id="org.eclipse.egit.ui.keyword.date"
+ label="%GitKeyword_Date_label">
+ </keyword>
</extension>
<extension point="org.eclipse.ui.decorators">
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/PluginPreferenceInitializer.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/PluginPreferenceInitializer.java
index 4f4abdcd1d..051f9951be 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/PluginPreferenceInitializer.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/PluginPreferenceInitializer.java
@@ -113,6 +113,8 @@ public class PluginPreferenceInitializer extends AbstractPreferenceInitializer {
store.setDefault(UIPreferences.SYNC_VIEW_FETCH_BEFORE_LAUNCH, true);
store.setDefault(UIPreferences.DATE_FORMAT,
UIPreferences.DEFAULT_DATE_FORMAT);
+ store.setDefault(UIPreferences.DATE_FORMAT_CHOICE,
+ UIPreferences.DEFAULT_DATE_FORMAT_CHOICE);
store.setDefault(UIPreferences.HISTORY_MAX_NUM_COMMITS, 10000);
store.setDefault(UIPreferences.HISTORY_SHOW_BRANCH_SEQUENCE, true);
store.setDefault(UIPreferences.HISTORY_SHOW_TAG_SEQUENCE, false);
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIPreferences.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIPreferences.java
index 5877f4366b..ed2d7fbc55 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIPreferences.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIPreferences.java
@@ -147,8 +147,14 @@ public class UIPreferences {
/** */
public final static String DATE_FORMAT = "date_format"; //$NON-NLS-1$
/** */
+ public final static String DATE_FORMAT_CHOICE = "date_format_choice"; //$NON-NLS-1$
+ /** */
+ public static final String DATE_FORMAT_CUSTOM = "CUSTOM"; //$NON-NLS-1$
+ /** */
public static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss"; //$NON-NLS-1$
/** */
+ public static final String DEFAULT_DATE_FORMAT_CHOICE = DATE_FORMAT_CUSTOM;
+ /** */
public static final String DEFAULT_CHANGESET_FORMAT = "[{author}] ({date}) {short_message}"; //$NON-NLS-1$
/** */
public static final String REFESH_ON_INDEX_CHANGE = "refesh_on_index_change"; //$NON-NLS-1$
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/PreferenceBasedDateFormatter.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/PreferenceBasedDateFormatter.java
new file mode 100644
index 0000000000..169fecce80
--- /dev/null
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/PreferenceBasedDateFormatter.java
@@ -0,0 +1,122 @@
+/*******************************************************************************
+ * Copyright (C) 2015 Thomas Wolf <thomas.wolf@paranor.ch>
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+package org.eclipse.egit.ui.internal;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.TimeZone;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.egit.ui.Activator;
+import org.eclipse.egit.ui.UIPreferences;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jgit.lib.PersonIdent;
+import org.eclipse.jgit.util.GitDateFormatter;
+
+/**
+ * A date formatter that formats dates according to the user's preferences.
+ *
+ * @see org.eclipse.egit.ui.internal.preferences.DateFormatPreferencePage
+ */
+public class PreferenceBasedDateFormatter extends GitDateFormatter {
+
+ private final SimpleDateFormat customFormat;
+
+ /**
+ * Creates a new {@link PreferenceBasedDateFormatter} that will format dates
+ * according to the date format preferences set at the time it was created.
+ *
+ * @return a new {@link PreferenceBasedDateFormatter}
+ */
+ public static @NonNull PreferenceBasedDateFormatter create() {
+ String choice = Activator.getDefault().getPreferenceStore()
+ .getString(UIPreferences.DATE_FORMAT_CHOICE);
+ GitDateFormatter.Format format = null;
+ try {
+ format = GitDateFormatter.Format.valueOf(choice);
+ } catch (IllegalArgumentException | NullPointerException e) {
+ // Custom format: ignore and leave at null
+ }
+ return new PreferenceBasedDateFormatter(format);
+ }
+
+ private PreferenceBasedDateFormatter(GitDateFormatter.Format gitFormat) {
+ super(gitFormat != null ? gitFormat : GitDateFormatter.Format.DEFAULT);
+ SimpleDateFormat format = null;
+ if (gitFormat == null) {
+ String pattern = Activator.getDefault().getPreferenceStore()
+ .getString(UIPreferences.DATE_FORMAT);
+ try {
+ format = new SimpleDateFormat(pattern);
+ } catch (IllegalArgumentException | NullPointerException e1) {
+ // Corrupted preferences?
+ Activator.logError("org.eclipse.egit.ui preference " //$NON-NLS-1$
+ + UIPreferences.DATE_FORMAT + " is invalid; ignoring", //$NON-NLS-1$
+ e1);
+ format = new SimpleDateFormat(
+ Activator.getDefault().getPreferenceStore()
+ .getDefaultString(UIPreferences.DATE_FORMAT));
+ }
+ }
+ this.customFormat = format;
+ }
+
+ /**
+ * Formats a {@link Date} using the default {@link TimeZone} according to
+ * the date format preferences set when this instance was created.
+ *
+ * @param date
+ * to format
+ * @return the string representation of the date, or the empty string if the
+ * date is {@code null}.
+ */
+ public String formatDate(Date date) {
+ if (date == null) {
+ return ""; //$NON-NLS-1$
+ }
+ TimeZone timeZone = TimeZone.getDefault();
+ Assert.isNotNull(timeZone);
+ return formatDate(date, timeZone);
+ }
+
+ /**
+ * Formats a {@link Date} using the given {@link TimeZone} according to the
+ * date format preferences set when this instance was created.
+ *
+ * @param date
+ * to format
+ * @param timeZone
+ * to use
+ * @return the string representation of the date
+ */
+ public String formatDate(@NonNull Date date, @NonNull TimeZone timeZone) {
+ return formatDate(new PersonIdent("", "", date, timeZone)); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Formats the date of a {@link PersonIdent} according to the date format
+ * preferences set when this instance was created.
+ *
+ * @param ident
+ * to format the date of
+ * @return the string representation of the date, or the empty string if
+ * {@code ident} is {@code null}.
+ */
+ @Override
+ public String formatDate(PersonIdent ident) {
+ if (ident == null) {
+ return ""; //$NON-NLS-1$
+ }
+ if (customFormat == null) {
+ return super.formatDate(ident);
+ }
+ return customFormat.format(ident.getWhen());
+ }
+
+}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java
index 19c2451efe..eef044eedc 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java
@@ -3221,6 +3221,84 @@ public class UIText extends NLS {
public static String CommittingPreferencePage_BlockCommitCombo;
/** */
+ public static String DateFormatPreferencePage_title;
+
+ /** */
+ public static String DateFormatPreferencePage_formatChooser_label;
+
+ /** */
+ public static String DateFormatPreferencePage_formatInput_label;
+
+ /** */
+ public static String DateFormatPreferencePage_invalidDateFormat_message;
+
+ /** */
+ public static String DateFormatPreferencePage_datePreview_label;
+
+ /** */
+ public static String DateFormatPreferencePage_choiceGitDefault_label;
+
+ /** */
+ public static String DateFormatPreferencePage_choiceGitLocal_label;
+
+ /** */
+ public static String DateFormatPreferencePage_choiceGitRelative_label;
+
+ /** */
+ public static String DateFormatPreferencePage_choiceGitIso_label;
+
+ /** */
+ public static String DateFormatPreferencePage_choiceGitRfc_label;
+
+ /** */
+ public static String DateFormatPreferencePage_choiceGitShort_label;
+
+ /** */
+ public static String DateFormatPreferencePage_choiceGitLocale_label;
+
+ /** */
+ public static String DateFormatPreferencePage_choiceGitLocaleLocal_label;
+
+ /** */
+ public static String DateFormatPreferencePage_choiceCustom_label;
+
+ /** */
+ public static String DateFormatPreferencePage_gitRelative_format_text;
+
+ /** */
+ public static String DateFormatPreferencePage_gitLocale_format_text;
+
+ /** */
+ public static String DateFormatPreferencePage_gitLocaleLocal_format_text;
+
+ /** */
+ public static String DateFormatPreferencePage_helpGitDefault_label;
+
+ /** */
+ public static String DateFormatPreferencePage_helpGitLocal_label;
+
+ /** */
+ public static String DateFormatPreferencePage_helpGitRelative_label;
+
+ /** */
+ public static String DateFormatPreferencePage_helpGitIso_label;
+
+ /** */
+ public static String DateFormatPreferencePage_helpGitRfc_label;
+
+ /** */
+ public static String DateFormatPreferencePage_helpGitShort_label;
+
+ /** */
+ public static String DateFormatPreferencePage_helpGitLocale_label;
+
+ /** */
+ public static String DateFormatPreferencePage_helpGitLocaleLocal_label;
+
+ /** */
+ public static String DateFormatPreferencePage_helpCustom_label;
+
+ /** */
public static String Decorator_exceptionMessage;
/** */
@@ -3290,15 +3368,6 @@ public class UIText extends NLS {
public static String DecoratorPreferencesPage_bindingChangeSetShortMessage;
/** */
- public static String DecoratorPreferencesPage_dateFormat;
-
- /** */
- public static String DecoratorPreferencesPage_dateFormatPreview;
-
- /** */
- public static String DecoratorPreferencesPage_wrongDateFormat;
-
- /** */
public static String DecoratorPreferencesPage_selectVariablesToAdd;
/** */
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CommitLabelProvider.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CommitLabelProvider.java
index 7a8cbb8d32..1b1549e62a 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CommitLabelProvider.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CommitLabelProvider.java
@@ -4,6 +4,7 @@
* Copyright (C) 2011, Matthias Sohn <matthias.sohn@sap.com>
* Copyright (C) 2011, IBM Corporation
* Copyright (C) 2012, Mathias Kinzler <mathias.kinzler@sap.com>
+ * Copyright (C) 2015, Thomas Wolf <thomas.wolf@paranor.ch>
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -12,20 +13,28 @@
*******************************************************************************/
package org.eclipse.egit.ui.internal.dialogs;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.eclipse.egit.ui.Activator;
+import org.eclipse.egit.ui.UIPreferences;
+import org.eclipse.egit.ui.internal.PreferenceBasedDateFormatter;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.jface.viewers.BaseLabelProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.LabelProviderChangedEvent;
import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.util.GitDateFormatter;
-import org.eclipse.jgit.util.GitDateFormatter.Format;
import org.eclipse.swt.graphics.Image;
/**
- * A Label Provider for Commits
+ * A Label provider for commits.
*/
public class CommitLabelProvider extends BaseLabelProvider implements
ITableLabelProvider {
- private GitDateFormatter dateFormatter;
+ private AtomicReference<GitDateFormatter> dateFormatter = new AtomicReference<>();
private boolean showEmail;
@@ -35,12 +44,64 @@ public class CommitLabelProvider extends BaseLabelProvider implements
private PersonIdent lastCommitter;
- private Format format = Format.LOCALELOCAL;
+ private IPropertyChangeListener uiPrefsListener;
+
+ private final IPreferenceStore store;
/**
* Default constructor
*/
public CommitLabelProvider() {
+ this(true);
+ }
+
+ /**
+ * Constructs a {@link CommitLabelProvider} that optionally does not react
+ * to the preference for showing e-mails.
+ *
+ * @param canShowEmailAddresses
+ * whether this label provider shall show E-Mail addresses if the
+ * corresponding preference is set
+ */
+ public CommitLabelProvider(final boolean canShowEmailAddresses) {
+ super();
+ store = Activator.getDefault().getPreferenceStore();
+ uiPrefsListener = new IPropertyChangeListener() {
+ @Override
+ public void propertyChange(PropertyChangeEvent event) {
+ String property = event.getProperty();
+ if ((UIPreferences.DATE_FORMAT.equals(property)
+ || UIPreferences.DATE_FORMAT_CHOICE.equals(property))
+ && (dateFormatter
+ .get() instanceof PreferenceBasedDateFormatter)) {
+ setDateFormatter(PreferenceBasedDateFormatter.create());
+ } else if (UIPreferences.RESOURCEHISTORY_SHOW_RELATIVE_DATE
+ .equals(property)) {
+ setRelativeDate(store.getBoolean(
+ UIPreferences.RESOURCEHISTORY_SHOW_RELATIVE_DATE));
+ } else if (canShowEmailAddresses
+ && UIPreferences.RESOURCEHISTORY_SHOW_EMAIL_ADDRESSES
+ .equals(property)) {
+ setShowEmailAddresses(store.getBoolean(
+ UIPreferences.RESOURCEHISTORY_SHOW_EMAIL_ADDRESSES));
+ }
+
+ }
+ };
+ if (store
+ .getBoolean(UIPreferences.RESOURCEHISTORY_SHOW_RELATIVE_DATE)) {
+ dateFormatter.set(
+ new GitDateFormatter(GitDateFormatter.Format.RELATIVE));
+ }
+ showEmail = canShowEmailAddresses && store
+ .getBoolean(UIPreferences.RESOURCEHISTORY_SHOW_EMAIL_ADDRESSES);
+ store.addPropertyChangeListener(uiPrefsListener);
+ }
+
+ @Override
+ public void dispose() {
+ store.removePropertyChangeListener(uiPrefsListener);
+ super.dispose();
}
@Override
@@ -83,9 +144,12 @@ public class CommitLabelProvider extends BaseLabelProvider implements
}
private GitDateFormatter getDateFormatter() {
- if (dateFormatter == null)
- dateFormatter = new GitDateFormatter(format);
- return dateFormatter;
+ GitDateFormatter result = dateFormatter.get();
+ if (result == null) {
+ result = PreferenceBasedDateFormatter.create();
+ dateFormatter.set(result);
+ }
+ return result;
}
private PersonIdent authorOf(final RevCommit c) {
@@ -114,18 +178,29 @@ public class CommitLabelProvider extends BaseLabelProvider implements
/**
* @param relative {@code true} if the date column should show relative dates
*/
- public void setRelativeDate(boolean relative) {
- dateFormatter = null;
- if (relative)
- format = Format.RELATIVE;
- else
- format = Format.LOCALELOCAL;
+ private void setRelativeDate(boolean relative) {
+ if (dateFormatter.get() instanceof PreferenceBasedDateFormatter) {
+ if (relative) {
+ setDateFormatter(
+ new GitDateFormatter(GitDateFormatter.Format.RELATIVE));
+ }
+ } else if (!relative) {
+ setDateFormatter(PreferenceBasedDateFormatter.create());
+ }
}
/**
* @param showEmail true to show e-mail addresses, false otherwise
*/
- public void setShowEmailAddresses(boolean showEmail) {
- this.showEmail = showEmail;
+ private void setShowEmailAddresses(boolean showEmail) {
+ if (showEmail != this.showEmail) {
+ this.showEmail = showEmail;
+ fireLabelProviderChanged(new LabelProviderChangedEvent(this));
+ }
+ }
+
+ private void setDateFormatter(GitDateFormatter formatter) {
+ dateFormatter.set(formatter);
+ fireLabelProviderChanged(new LabelProviderChangedEvent(this));
}
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CommitSelectDialog.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CommitSelectDialog.java
index 7270dc70e0..925b7e690a 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CommitSelectDialog.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CommitSelectDialog.java
@@ -19,8 +19,10 @@ import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.LabelProviderChangedEvent;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jgit.revwalk.RevCommit;
@@ -63,12 +65,20 @@ public class CommitSelectDialog extends TitleAreaDialog {
Composite main = new Composite(parent, SWT.NONE);
GridLayoutFactory.fillDefaults().applyTo(main);
GridDataFactory.fillDefaults().grab(true, true).applyTo(main);
- TableViewer tv = new TableViewer(main, SWT.SINGLE | SWT.BORDER
+ final TableViewer tv = new TableViewer(main,
+ SWT.SINGLE | SWT.BORDER
| SWT.FULL_SELECTION);
GridDataFactory.fillDefaults().grab(true, true)
.applyTo(tv.getControl());
tv.setContentProvider(ArrayContentProvider.getInstance());
- tv.setLabelProvider(new CommitLabelProvider());
+ CommitLabelProvider labelProvider = new CommitLabelProvider();
+ labelProvider.addListener(new ILabelProviderListener() {
+ @Override
+ public void labelProviderChanged(LabelProviderChangedEvent event) {
+ tv.refresh();
+ }
+ });
+ tv.setLabelProvider(labelProvider);
Table table = tv.getTable();
TableColumn c0 = new TableColumn(table, SWT.NONE);
c0.setWidth(70);
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/ResetTargetSelectionDialog.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/ResetTargetSelectionDialog.java
index 11a5cdef5a..782431c08a 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/ResetTargetSelectionDialog.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/ResetTargetSelectionDialog.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2013 SAP AG and others.
+ * Copyright (c) 2010, 2013, 2015 SAP AG and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -8,6 +8,7 @@
* Contributors:
* Stefan Lay (SAP AG) - initial implementation
* Mathias Kinzler (SAP AG) - use the abstract super class
+ * Thomas Wolf <thomas.wolf@paranor.ch> - Bug 477248
*******************************************************************************/
package org.eclipse.egit.ui.internal.dialogs;
@@ -15,6 +16,7 @@ import java.io.IOException;
import org.eclipse.egit.core.RepositoryUtil;
import org.eclipse.egit.ui.Activator;
+import org.eclipse.egit.ui.internal.PreferenceBasedDateFormatter;
import org.eclipse.egit.ui.internal.UIText;
import org.eclipse.jface.dialogs.IMessageProvider;
import org.eclipse.jface.dialogs.MessageDialog;
@@ -30,7 +32,6 @@ import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.util.GitDateFormatter;
-import org.eclipse.jgit.util.GitDateFormatter.Format;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.FocusEvent;
@@ -65,8 +66,8 @@ public class ResetTargetSelectionDialog extends AbstractBranchSelectionDialog {
private Label committer;
- private final GitDateFormatter gitDateFormatter = new GitDateFormatter(
- Format.LOCALE);
+ private final GitDateFormatter gitDateFormatter = PreferenceBasedDateFormatter
+ .create();
/**
* Construct a dialog to select a branch to reset to
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitGraphTable.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitGraphTable.java
index bf4b1dcd38..5841502114 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitGraphTable.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitGraphTable.java
@@ -49,12 +49,14 @@ import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.resource.ResourceManager;
import org.eclipse.jface.viewers.ColumnWeightData;
+import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.IOpenListener;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.LabelProviderChangedEvent;
import org.eclipse.jface.viewers.OpenEvent;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
@@ -153,8 +155,6 @@ class CommitGraphTable {
private RevCommit commitToShow;
- private GraphLabelProvider graphLabelProvider;
-
private final TableLoader tableLoader;
private boolean trace = GitTraceLocation.HISTORYVIEW.isActive();
@@ -163,6 +163,11 @@ class CommitGraphTable {
CommitGraphTable(Composite parent, final TableLoader loader,
final ResourceManager resources) {
+ this(parent, loader, resources, true);
+ }
+
+ CommitGraphTable(Composite parent, final TableLoader loader,
+ final ResourceManager resources, boolean canShowEmailAddresses) {
nFont = UIUtils.getFont(UIPreferences.THEME_CommitGraphNormalFont);
hFont = highlightFont();
tableLoader = loader;
@@ -205,8 +210,14 @@ class CommitGraphTable {
}
};
- graphLabelProvider = new GraphLabelProvider();
-
+ GraphLabelProvider graphLabelProvider = new GraphLabelProvider(
+ canShowEmailAddresses);
+ graphLabelProvider.addListener(new ILabelProviderListener() {
+ @Override
+ public void labelProviderChanged(LabelProviderChangedEvent event) {
+ table.refresh();
+ }
+ });
table.setLabelProvider(graphLabelProvider);
table.setContentProvider(new GraphContentProvider());
renderer = new SWTPlotRenderer(rawTable.getDisplay(), resources);
@@ -350,14 +361,6 @@ class CommitGraphTable {
table.removePostSelectionChangedListener(l);
}
- void setRelativeDate(boolean booleanValue) {
- graphLabelProvider.setRelativeDate(booleanValue);
- }
-
- void setShowEmailAddresses(boolean booleanValue) {
- graphLabelProvider.setShowEmailAddresses(booleanValue);
- }
-
private boolean canDoCopy() {
return !table.getSelection().isEmpty();
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitInfoBuilder.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitInfoBuilder.java
index 2378a8d32c..0dbe2ebfb1 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitInfoBuilder.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitInfoBuilder.java
@@ -15,8 +15,6 @@
package org.eclipse.egit.ui.internal.history;
import java.io.IOException;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
@@ -30,6 +28,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.UIPreferences;
+import org.eclipse.egit.ui.internal.PreferenceBasedDateFormatter;
import org.eclipse.egit.ui.internal.UIText;
import org.eclipse.egit.ui.internal.history.FormatJob.FormatResult;
import org.eclipse.egit.ui.internal.trace.GitTraceLocation;
@@ -57,8 +56,6 @@ public class CommitInfoBuilder {
private static final int MAXBRANCHES = 20;
- private final DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //$NON-NLS-1$
-
private static final Pattern FOOTER_PATTERN = Pattern
.compile("(?:\n(?:[A-Z](?:[A-Za-z]+-)*[A-Za-z]+:[^\n]*))+$"); //$NON-NLS-1$
@@ -70,6 +67,8 @@ public class CommitInfoBuilder {
private final Collection<Ref> allRefs;
+ private final PreferenceBasedDateFormatter dateFormatter;
+
/**
* @param db the repository
* @param commit the commit the info should be shown for
@@ -82,6 +81,7 @@ public class CommitInfoBuilder {
this.commit = commit;
this.fill = fill;
this.allRefs = allRefs;
+ this.dateFormatter = PreferenceBasedDateFormatter.create();
}
/**
@@ -209,13 +209,15 @@ public class CommitInfoBuilder {
private void addLink(StringBuilder d, String linkLabel,
Collection<GitCommitReference> hyperlinks, RevCommit to) {
- hyperlinks.add(
- new GitCommitReference(to, new Region(d.length(), linkLabel.length())));
+ if (to != null) {
+ hyperlinks.add(new GitCommitReference(to,
+ new Region(d.length(), linkLabel.length())));
+ }
d.append(linkLabel);
}
private void addLink(StringBuilder d, Collection<GitCommitReference> hyperlinks,
- RevCommit to) {
+ RevCommit to) {
addLink(d, to.getId().name(), hyperlinks, to);
}
@@ -225,7 +227,7 @@ public class CommitInfoBuilder {
d.append(label).append(": "); //$NON-NLS-1$
d.append(ident.getName().trim());
d.append(" <").append(ident.getEmailAddress().trim()).append("> "); //$NON-NLS-1$ //$NON-NLS-2$
- d.append(fmt.format(ident.getWhen()));
+ d.append(dateFormatter.formatDate(ident));
d.append(LF);
}
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitMessageViewer.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitMessageViewer.java
index 6084756c4a..59d08b0e96 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitMessageViewer.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitMessageViewer.java
@@ -129,16 +129,17 @@ class CommitMessageViewer extends HyperlinkSourceViewer {
@Override
public void propertyChange(PropertyChangeEvent event) {
String property = event.getProperty();
- if (property.equals(
- UIPreferences.RESOURCEHISTORY_SHOW_COMMENT_FILL)) {
+ if (UIPreferences.RESOURCEHISTORY_SHOW_COMMENT_FILL
+ .equals(property)) {
setFill(((Boolean) event.getNewValue()).booleanValue());
- return;
- }
- if (property.equals(UIPreferences.HISTORY_SHOW_TAG_SEQUENCE)
- || property.equals(
- UIPreferences.HISTORY_SHOW_BRANCH_SEQUENCE)) {
+ } else
+ if (UIPreferences.HISTORY_SHOW_TAG_SEQUENCE.equals(property)
+ || UIPreferences.HISTORY_SHOW_BRANCH_SEQUENCE
+ .equals(property)
+ || UIPreferences.DATE_FORMAT.equals(property)
+ || UIPreferences.DATE_FORMAT_CHOICE
+ .equals(property)) {
format();
- return;
}
}
};
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitSelectionDialog.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitSelectionDialog.java
index 36cf9680e0..475bae3898 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitSelectionDialog.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitSelectionDialog.java
@@ -107,8 +107,8 @@ public class CommitSelectionDialog extends TitleAreaDialog {
final ResourceManager resources = new LocalResourceManager(
JFaceResources.getResources());
UIUtils.hookDisposal(main, resources);
- table = new CommitGraphTable(main, null, resources);
- table.setRelativeDate(GitHistoryPage.isShowingRelativeDates());
+ // Table never shows e-mail addresses because it might get rather wide.
+ table = new CommitGraphTable(main, null, resources, false);
table.getTableView().addSelectionChangedListener(
new ISelectionChangedListener() {
@Override
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java
index f806148262..0955d7e788 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java
@@ -740,20 +740,6 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener,
@Override
public void propertyChange(PropertyChangeEvent event) {
final String prop = event.getProperty();
- if (UIPreferences.RESOURCEHISTORY_SHOW_RELATIVE_DATE.equals(prop)) {
- Object oldValue = event.getOldValue();
- if (oldValue == null || !oldValue.equals(event.getNewValue())) {
- graph.setRelativeDate(isShowingRelativeDates());
- graph.getTableView().refresh();
- }
- }
- if (UIPreferences.RESOURCEHISTORY_SHOW_EMAIL_ADDRESSES.equals(prop)) {
- Object oldValue = event.getOldValue();
- if (oldValue == null || !oldValue.equals(event.getNewValue())) {
- graph.setShowEmailAddresses(isShowingEmailAddresses());
- graph.getTableView().refresh();
- }
- }
if (UIPreferences.HISTORY_MAX_BRANCH_LENGTH.equals(prop)
|| UIPreferences.HISTORY_MAX_TAG_LENGTH.equals(prop))
graph.getTableView().refresh();
@@ -871,8 +857,6 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener,
graph = new CommitGraphTable(graphDetailSplit, getSite(), popupMgr,
this, resources);
- graph.setRelativeDate(isShowingRelativeDates());
- graph.setShowEmailAddresses(isShowingEmailAddresses());
Activator.getDefault().getPreferenceStore()
.addPropertyChangeListener(listener);
@@ -2366,14 +2350,6 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener,
}
}
- static boolean isShowingRelativeDates() {
- return Activator.getDefault().getPreferenceStore().getBoolean(UIPreferences.RESOURCEHISTORY_SHOW_RELATIVE_DATE);
- }
-
- private boolean isShowingEmailAddresses() {
- return Activator.getDefault().getPreferenceStore().getBoolean(UIPreferences.RESOURCEHISTORY_SHOW_EMAIL_ADDRESSES);
- }
-
@Override
public ShowInContext getShowInContext() {
if (fileViewer != null && fileViewer.getControl().isFocusControl())
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GraphLabelProvider.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GraphLabelProvider.java
index cad3c7ba86..33c62721ac 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GraphLabelProvider.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GraphLabelProvider.java
@@ -21,6 +21,15 @@ import org.eclipse.egit.ui.internal.dialogs.CommitLabelProvider;
* A Label Provider for Commits
*/
class GraphLabelProvider extends CommitLabelProvider {
+
+ public GraphLabelProvider() {
+ super();
+ }
+
+ public GraphLabelProvider(boolean canShowEmailAddresses) {
+ super(canShowEmailAddresses);
+ }
+
@Override
public String getColumnText(Object element, int columnIndex) {
if (element == null) {
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/preferences/DateFormatPreferencePage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/preferences/DateFormatPreferencePage.java
new file mode 100644
index 0000000000..bba036cea4
--- /dev/null
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/preferences/DateFormatPreferencePage.java
@@ -0,0 +1,292 @@
+/*******************************************************************************
+ * Copyright (C) 2015 Thomas Wolf <thomas.wolf@paranor.ch>
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+package org.eclipse.egit.ui.internal.preferences;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.TimeZone;
+
+import org.eclipse.egit.ui.Activator;
+import org.eclipse.egit.ui.UIPreferences;
+import org.eclipse.egit.ui.internal.SWTUtils;
+import org.eclipse.egit.ui.internal.UIText;
+import org.eclipse.jface.preference.ComboFieldEditor;
+import org.eclipse.jface.preference.FieldEditor;
+import org.eclipse.jface.preference.FieldEditorPreferencePage;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.preference.StringFieldEditor;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.jgit.lib.PersonIdent;
+import org.eclipse.jgit.util.GitDateFormatter;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+
+/** Preferences concerning date formats in EGit. */
+public class DateFormatPreferencePage extends FieldEditorPreferencePage
+ implements IWorkbenchPreferencePage {
+
+ private static final PersonIdent SAMPLE = new PersonIdent("", "", //$NON-NLS-1$ //$NON-NLS-2$
+ new Date(System.currentTimeMillis() - 24 * 3600 * 1000),
+ getDifferentTimeZone());
+
+ private static final Map<GitDateFormatter.Format, FormatInfo> DATA = initializeData();
+
+ private ComboFieldEditor formatChooser;
+
+ private StringFieldEditor dateFormat;
+
+ private Label dateFormatPreview;
+
+ private Label formatExplanation;
+
+ private String lastCustomValue;
+
+ /** Creates a new instance. */
+ public DateFormatPreferencePage() {
+ super(GRID);
+ initializeData();
+ setTitle(UIText.DateFormatPreferencePage_title);
+ }
+
+ @Override
+ public void init(IWorkbench workbench) {
+ // Nothing to do
+ }
+
+ @Override
+ protected IPreferenceStore doGetPreferenceStore() {
+ return Activator.getDefault().getPreferenceStore();
+ }
+
+ @Override
+ protected void createFieldEditors() {
+ String[][] values = new String[DATA.size()][2];
+ int i = 0;
+ for (Map.Entry<GitDateFormatter.Format, FormatInfo> entry : DATA
+ .entrySet()) {
+ values[i][0] = entry.getValue().name;
+ values[i][1] = entry.getKey() == null
+ ? UIPreferences.DATE_FORMAT_CUSTOM : entry.getKey().name();
+ i++;
+ }
+ final Composite pane = getFieldEditorParent();
+ formatChooser = new ComboFieldEditor(
+ UIPreferences.DATE_FORMAT_CHOICE,
+ UIText.DateFormatPreferencePage_formatChooser_label,
+ values,
+ pane);
+ addField(formatChooser);
+ dateFormat = new StringFieldEditor(
+ UIPreferences.DATE_FORMAT,
+ UIText.DateFormatPreferencePage_formatInput_label,
+ StringFieldEditor.UNLIMITED,
+ StringFieldEditor.VALIDATE_ON_KEY_STROKE, pane) {
+ @Override
+ protected boolean doCheckState() {
+ // Validate the contents. If we're disabled, we're showing some
+ // built-in format string, which we always consider as valid.
+ if (!getTextControl(pane).isEnabled()) {
+ return true;
+ }
+ try {
+ updatePreview(
+ new SimpleDateFormat(getStringValue().trim()));
+ return true;
+ } catch (IllegalArgumentException e) {
+ dateFormatPreview.setText(""); //$NON-NLS-1$
+ return false;
+ }
+ }
+
+ @Override
+ protected void doLoad() {
+ // Set explicitly below
+ }
+
+ @Override
+ protected void doStore() {
+ // Never store invalid values, or built-in values
+ if (getTextControl(pane).isEnabled() && doCheckState()) {
+ super.doStore();
+ }
+ }
+
+ @Override
+ public void setStringValue(String value) {
+ super.setStringValue(value);
+ refreshValidState();
+ }
+ };
+ dateFormat.setEmptyStringAllowed(false);
+ dateFormat.setErrorMessage(
+ UIText.DateFormatPreferencePage_invalidDateFormat_message);
+ addField(dateFormat);
+ // We know that the layout will have two columns
+ Label dpLabel = SWTUtils.createLabel(pane,
+ UIText.DateFormatPreferencePage_datePreview_label);
+ dpLabel.setLayoutData(SWTUtils.createGridData(SWT.DEFAULT, SWT.DEFAULT,
+ false, false));
+ dateFormatPreview = SWTUtils.createLabel(pane, null, 1);
+ Label dummyLabel = SWTUtils.createLabel(pane, ""); //$NON-NLS-1$
+ dummyLabel.setLayoutData(SWTUtils.createGridData(SWT.DEFAULT,
+ SWT.DEFAULT, false, false));
+ formatExplanation = new Label(pane, SWT.LEFT | SWT.WRAP);
+ GridData layout = SWTUtils.createGridData(SWT.DEFAULT, SWT.DEFAULT,
+ false, true);
+ formatExplanation.setLayoutData(layout);
+ // Setup based on initial values. We don't get any events by the editors
+ // on initial load!
+ lastCustomValue = getPreferenceStore()
+ .getString(UIPreferences.DATE_FORMAT);
+ String initialValue = getPreferenceStore()
+ .getString(UIPreferences.DATE_FORMAT_CHOICE);
+ GitDateFormatter.Format initialFormat = fromString(initialValue);
+ FormatInfo info = DATA.get(initialFormat);
+ dateFormat.setEnabled(initialFormat == null, pane);
+ dateFormat.setStringValue(
+ initialFormat == null ? lastCustomValue : info.format);
+ formatExplanation.setText(info.explanation);
+ }
+
+ @Override
+ protected void initialize() {
+ super.initialize();
+ // When the chooser's selection changes, update the dateFormat &
+ // enablement
+ formatChooser.setPropertyChangeListener(new IPropertyChangeListener() {
+ @Override
+ public void propertyChange(PropertyChangeEvent event) {
+ if (FieldEditor.VALUE.equals(event.getProperty())) {
+ GitDateFormatter.Format format = fromString(
+ (String) event.getOldValue());
+ if (format == null) {
+ lastCustomValue = dateFormat.getStringValue();
+ }
+ format = fromString((String) event.getNewValue());
+ FormatInfo info = DATA.get(format);
+ formatExplanation.setText(info.explanation);
+ if (format == null) {
+ dateFormat.getTextControl(getFieldEditorParent())
+ .setEnabled(true);
+ dateFormat.setStringValue(lastCustomValue);
+ } else {
+ dateFormat.getTextControl(getFieldEditorParent())
+ .setEnabled(false);
+ dateFormat.setStringValue(info.format);
+ updatePreview(format);
+ }
+ }
+ }
+ });
+ }
+
+ private GitDateFormatter.Format fromString(String value) {
+ try {
+ return GitDateFormatter.Format.valueOf(value);
+ } catch (IllegalArgumentException | NullPointerException e) {
+ return null;
+ }
+ }
+
+ private void updatePreview(SimpleDateFormat format) {
+ format.setTimeZone(SAMPLE.getTimeZone());
+ dateFormatPreview.setText(format.format(SAMPLE.getWhen()));
+ }
+
+ private void updatePreview(GitDateFormatter.Format format) {
+ dateFormatPreview
+ .setText(new GitDateFormatter(format).formatDate(SAMPLE));
+ }
+
+ private static Map<GitDateFormatter.Format, FormatInfo> initializeData() {
+ Map<GitDateFormatter.Format, FormatInfo> d = new LinkedHashMap<>();
+ d.put(GitDateFormatter.Format.DEFAULT,
+ new FormatInfo(
+ UIText.DateFormatPreferencePage_choiceGitDefault_label,
+ "EEE MMM dd HH:mm:ss yyyy Z", //$NON-NLS-1$
+ UIText.DateFormatPreferencePage_helpGitDefault_label));
+ d.put(GitDateFormatter.Format.LOCAL,
+ new FormatInfo(
+ UIText.DateFormatPreferencePage_choiceGitLocal_label,
+ "EEE MMM dd HH:mm:ss yyyy", //$NON-NLS-1$
+ UIText.DateFormatPreferencePage_helpGitLocal_label));
+ d.put(GitDateFormatter.Format.RELATIVE,
+ new FormatInfo(
+ UIText.DateFormatPreferencePage_choiceGitRelative_label,
+ UIText.DateFormatPreferencePage_gitRelative_format_text,
+ UIText.DateFormatPreferencePage_helpGitRelative_label));
+ d.put(GitDateFormatter.Format.ISO,
+ new FormatInfo(
+ UIText.DateFormatPreferencePage_choiceGitIso_label,
+ "yyyy-MM-dd HH:mm:ss Z", //$NON-NLS-1$
+ UIText.DateFormatPreferencePage_helpGitIso_label));
+ d.put(GitDateFormatter.Format.RFC,
+ new FormatInfo(
+ UIText.DateFormatPreferencePage_choiceGitRfc_label,
+ "EEE, dd MMM yyyy HH:mm:ss Z", //$NON-NLS-1$
+ UIText.DateFormatPreferencePage_helpGitRfc_label));
+ d.put(GitDateFormatter.Format.SHORT,
+ new FormatInfo(
+ UIText.DateFormatPreferencePage_choiceGitShort_label,
+ "yyyy-MM-dd", //$NON-NLS-1$
+ UIText.DateFormatPreferencePage_helpGitShort_label));
+ DateFormat systemFormat = DateFormat
+ .getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT);
+ String localeLocalFormat = (systemFormat instanceof SimpleDateFormat)
+ ? ((SimpleDateFormat) systemFormat).toPattern()
+ : UIText.DateFormatPreferencePage_gitLocaleLocal_format_text;
+ String localeFormat = (systemFormat instanceof SimpleDateFormat)
+ ? localeLocalFormat + " Z" //$NON-NLS-1$
+ : UIText.DateFormatPreferencePage_gitLocale_format_text;
+ d.put(GitDateFormatter.Format.LOCALE,
+ new FormatInfo(
+ UIText.DateFormatPreferencePage_choiceGitLocale_label,
+ localeFormat,
+ UIText.DateFormatPreferencePage_helpGitLocale_label));
+ d.put(GitDateFormatter.Format.LOCALELOCAL, new FormatInfo(
+ UIText.DateFormatPreferencePage_choiceGitLocaleLocal_label,
+ localeLocalFormat,
+ UIText.DateFormatPreferencePage_helpGitLocaleLocal_label));
+ d.put(null,
+ new FormatInfo(
+ UIText.DateFormatPreferencePage_choiceCustom_label, "", //$NON-NLS-1$
+ UIText.DateFormatPreferencePage_helpCustom_label));
+ return d;
+ }
+
+ private static TimeZone getDifferentTimeZone() {
+ TimeZone localTimeZone = TimeZone.getDefault();
+ int offset = (localTimeZone.getRawOffset() / 3600 / 1000 - 6) * 3600
+ * 1000; // 6h to the West, full hour
+ return TimeZone.getTimeZone(TimeZone.getAvailableIDs(offset)[0]);
+ }
+
+ private static final class FormatInfo {
+ private final String name;
+
+ private final String format;
+
+ private final String explanation;
+
+ public FormatInfo(String name, String dateFormat, String explanation) {
+ this.name = name;
+ this.format = dateFormat;
+ this.explanation = explanation;
+ }
+
+ }
+}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/preferences/GitDecoratorPreferencePage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/preferences/GitDecoratorPreferencePage.java
index 0aeadeec40..2890720adb 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/preferences/GitDecoratorPreferencePage.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/preferences/GitDecoratorPreferencePage.java
@@ -2,6 +2,7 @@
* Copyright (c) 2000, 2012 IBM Corporation and others.
* Copyright (C) 2009, Tor Arne Vestbø <torarnv@gmail.com>
* Copyright (C) 2010, Mathias Kinzler <mathias.kinzler@sap.com>
+ * Copyright (C) 2015, Thomas Wolf <thomas.wolf@paranor.ch>
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -11,7 +12,6 @@
package org.eclipse.egit.ui.internal.preferences;
import java.io.IOException;
-import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -25,6 +25,7 @@ import org.eclipse.core.resources.IResource;
import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.UIPreferences;
import org.eclipse.egit.ui.internal.GitLabelProvider;
+import org.eclipse.egit.ui.internal.PreferenceBasedDateFormatter;
import org.eclipse.egit.ui.internal.SWTUtils;
import org.eclipse.egit.ui.internal.UIText;
import org.eclipse.egit.ui.internal.decorators.GitLightweightDecorator.DecorationHelper;
@@ -106,7 +107,13 @@ public class GitDecoratorPreferencePage extends PreferencePage implements
private static final Map<String, String> CHANGESET_LABEL_BINDINGS;
- private static IPropertyChangeListener themeListener;
+ private IPropertyChangeListener themeListener;
+
+ /**
+ * Listens to changes in the date preferences and updates the
+ * changeSetPreview if the preferences change.
+ */
+ private IPropertyChangeListener uiPrefsListener;
static {
final PreviewResource project = new PreviewResource(
@@ -255,6 +262,18 @@ public class GitDecoratorPreferencePage extends PreferencePage implements
PlatformUI.getWorkbench().getThemeManager().addPropertyChangeListener(
themeListener);
+ uiPrefsListener = new IPropertyChangeListener() {
+ @Override
+ public void propertyChange(PropertyChangeEvent event) {
+ String property = event.getProperty();
+ if (UIPreferences.DATE_FORMAT.equals(property)
+ || UIPreferences.DATE_FORMAT_CHOICE.equals(property)) {
+ changeSetPreview.refresh();
+ }
+ }
+ };
+ getPreferenceStore().addPropertyChangeListener(uiPrefsListener);
+
Dialog.applyDialogFont(parent);
return tabFolder;
@@ -417,14 +436,6 @@ public class GitDecoratorPreferencePage extends PreferencePage implements
private final FormatEditor changeSetLabelFormat;
- private final Text dateFormat;
-
- private final Label dateFormatPreview;
-
- private final Date exampleDate = new Date();
-
- private boolean formatValid;
-
public OtherDecorationTab(TabFolder parent) {
Composite composite = SWTUtils.createHVFillComposite(parent,
SWTUtils.MARGINS_DEFAULT, 3);
@@ -437,60 +448,30 @@ public class GitDecoratorPreferencePage extends PreferencePage implements
final TabItem tabItem = new TabItem(parent, SWT.NONE);
- Label dfLabel = SWTUtils.createLabel(composite, UIText.DecoratorPreferencesPage_dateFormat);
- dfLabel.setLayoutData(SWTUtils.createGridData(SWT.DEFAULT,
- SWT.DEFAULT, false, false));
- dateFormat = SWTUtils.createText(composite, 2);
-
- Label dpLabel = SWTUtils.createLabel(composite, UIText.DecoratorPreferencesPage_dateFormatPreview);
- dpLabel.setLayoutData(SWTUtils.createGridData(SWT.DEFAULT,
- SWT.DEFAULT, false, false));
- dateFormatPreview = SWTUtils.createLabel(composite, null, 2);
-
tabItem.setText(UIText.DecoratorPreferencesPage_otherDecorations);
tabItem.setControl(composite);
tabItem.setData(UIText.DecoratorPreferencesPage_otherDecorations);
changeSetLabelFormat.addModifyListener(this);
- dateFormat.addModifyListener(this);
- }
-
- private void updateDateFormatPreview() {
- SimpleDateFormat sdf;
- try {
- sdf = new SimpleDateFormat(dateFormat.getText());
- dateFormatPreview.setText(sdf.format(exampleDate));
- formatValid = true;
- } catch (Exception ex) {
- dateFormatPreview.setText(UIText.DecoratorPreferencesPage_wrongDateFormat);
- formatValid = false;
- }
}
@Override
public void initializeValues(IPreferenceStore store) {
changeSetLabelFormat.initializeValue(store);
- dateFormat.setText(store.getString(UIPreferences.DATE_FORMAT));
}
@Override
public void performDefaults(IPreferenceStore store) {
changeSetLabelFormat.performDefaults(store);
- dateFormat.setText(store.getDefaultString(UIPreferences.DATE_FORMAT));
}
@Override
public void performOk(IPreferenceStore store) {
changeSetLabelFormat.performOk(store);
-
- if (formatValid) {
- store.setValue(UIPreferences.DATE_FORMAT, dateFormat.getText());
- }
}
@Override
public void modifyText(ModifyEvent e) {
- updateDateFormatPreview();
setChanged();
notifyObservers();
}
@@ -778,6 +759,7 @@ public class GitDecoratorPreferencePage extends PreferencePage implements
public void dispose() {
PlatformUI.getWorkbench().getThemeManager()
.removePropertyChangeListener(themeListener);
+ getPreferenceStore().removePropertyChangeListener(uiPrefsListener);
super.dispose();
}
@@ -848,8 +830,8 @@ public class GitDecoratorPreferencePage extends PreferencePage implements
public String getText(Object element) {
if (element instanceof GitModelCommitMockup) {
String format = store.getString(UIPreferences.SYNC_VIEW_CHANGESET_LABEL_FORMAT);
- String dateFormat = store.getString(UIPreferences.DATE_FORMAT);
- return ((GitModelCommitMockup)element).getMokeupText(format, dateFormat);
+ return ((GitModelCommitMockup) element)
+ .getMokeupText(format);
}
return super.getText(element);
}
@@ -1023,11 +1005,13 @@ public class GitDecoratorPreferencePage extends PreferencePage implements
private static final Date date = new Date();
private static final String committer = "Committer Name"; //$NON-NLS-1$
- public String getMokeupText(String format, String dateFormat) {
- SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
+ public String getMokeupText(String format) {
+ PreferenceBasedDateFormatter formatter = PreferenceBasedDateFormatter
+ .create();
Map<String, String> bindings = new HashMap<String, String>();
- bindings.put(GitChangeSetLabelProvider.BINDING_CHANGESET_DATE, sdf.format(date));
+ bindings.put(GitChangeSetLabelProvider.BINDING_CHANGESET_DATE,
+ formatter.formatDate(date));
bindings.put(GitChangeSetLabelProvider.BINDING_CHANGESET_AUTHOR, author);
bindings.put(GitChangeSetLabelProvider.BINDING_CHANGESET_COMMITTER, committer);
bindings.put(GitChangeSetLabelProvider.BINDING_CHANGESET_SHORT_MESSAGE, message);
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties
index ad757b8569..9fa22032d2 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties
@@ -1037,6 +1037,33 @@ CommittingPreferencePage_WarnBlock_WarningsAndErrors=Warnings and errors
CommittingPreferencePage_BlockCommit=Block commit button
CommittingPreferencePage_BlockCommitCombo=Block if there are:
+DateFormatPreferencePage_title=Date Format
+DateFormatPreferencePage_formatChooser_label=Format
+DateFormatPreferencePage_formatInput_label=Date format
+DateFormatPreferencePage_invalidDateFormat_message=Not a valid date format
+DateFormatPreferencePage_datePreview_label=Date preview
+DateFormatPreferencePage_choiceGitDefault_label=Git default format
+DateFormatPreferencePage_choiceGitLocal_label=Git local format
+DateFormatPreferencePage_choiceGitRelative_label=Git relative date format
+DateFormatPreferencePage_choiceGitIso_label=Git ISO 8601 format
+DateFormatPreferencePage_choiceGitRfc_label=Git RFC 2822 format
+DateFormatPreferencePage_choiceGitShort_label=Git short date format
+DateFormatPreferencePage_choiceGitLocale_label=System locale date format with time zone
+DateFormatPreferencePage_choiceGitLocaleLocal_label=System locale date format
+DateFormatPreferencePage_choiceCustom_label=User-defined format
+DateFormatPreferencePage_gitRelative_format_text=relative date
+DateFormatPreferencePage_gitLocale_format_text=system format with time zone
+DateFormatPreferencePage_gitLocaleLocal_format_text=system format
+DateFormatPreferencePage_helpGitDefault_label=Time of the commit in the committer's time zone, with time zone; with US day and month names.
+DateFormatPreferencePage_helpGitLocal_label=Time of the commit converted to your local time zone, without time zone; with US day and month names.
+DateFormatPreferencePage_helpGitRelative_label=Time of the commit relative to your local time.
+DateFormatPreferencePage_helpGitIso_label=Time of the commit in the committer's time zone in ISO 8601 format with time zone.
+DateFormatPreferencePage_helpGitRfc_label=Time of the commit in the committer's time zone in e-mail format RFC 2822 with time zone.
+DateFormatPreferencePage_helpGitShort_label=Date of the commit in the committer's time zone, without time; year-month-day.
+DateFormatPreferencePage_helpGitLocale_label=Time of the commit in the committer's time zone in your system format, with time zone.
+DateFormatPreferencePage_helpGitLocaleLocal_label=Time of the commit converted to your local time zone in your system format, without time zone.
+DateFormatPreferencePage_helpCustom_label=Time of the commit in the committer's time zone in the format specified.
+
BasicConfigurationDialog_ConfigLocationInfo=These settings will be stored in the Git configuration file in your home directory.
BasicConfigurationDialog_DialogMessage=When creating a commit, Git records name and e-mail of author and committer. Please fill in the information so that your commits are correctly attributed.
BasicConfigurationDialog_DialogTitle=Please identify yourself
@@ -1169,9 +1196,6 @@ DecoratorPreferencesPage_iconsShowConflicts=Conflicting resources
DecoratorPreferencesPage_iconsShowAssumeValid=Assumed unchanged resources
DecoratorPreferencesPage_changeSetLabelFormat=Commits:
DecoratorPreferencesPage_otherDecorations=Other
-DecoratorPreferencesPage_dateFormat=Date format:
-DecoratorPreferencesPage_dateFormatPreview=Date preview:
-DecoratorPreferencesPage_wrongDateFormat=#Incorrect date format#
DecoratorPreferencesPage_bindingChangeSetAuthor=Commit author name;
DecoratorPreferencesPage_bindingChangeSetCommitter=Commit committer name;
DecoratorPreferencesPage_bindingChangeSetDate=Commit creation date (see date format setting);

Back to the top