summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorilya.ivanov2011-02-02 12:18:29 (EST)
committer Chris Aniszczyk2011-02-16 12:32:54 (EST)
commita6beb8b28589dee21107692bf3c49e45cb8b700c (patch)
tree0aa9cd7e9e02c2a83c9fb5a5c15b86a6309c9b4b
parentefa109e21b6807d030f366b658c186e6b5a50ced (diff)
downloadegit-a6beb8b28589dee21107692bf3c49e45cb8b700c.zip
egit-a6beb8b28589dee21107692bf3c49e45cb8b700c.tar.gz
egit-a6beb8b28589dee21107692bf3c49e45cb8b700c.tar.bz2
[sync] configurable date format and change set labelsrefs/changes/56/2356/6
Added new preferances to Team->Git->Label Decorations->Other Bug: 336130 CQ: 4868 Change-Id: I56a1d4cd5078240a9bb518d7991d01f033a0fd51 Signed-off-by: Ilya Ivanov <ilya.ivanov@intland.com> Signed-off-by: Dariusz Luksza <dariusz@luksza.org> Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/synchronize/SynchronizeViewTest.java2
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/PluginPreferenceInitializer.java6
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIPreferences.java4
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java27
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/preferences/GitDecoratorPreferencePage.java496
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/mapping/GitChangeSetLabelProvider.java61
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties9
7 files changed, 479 insertions, 126 deletions
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/synchronize/SynchronizeViewTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/synchronize/SynchronizeViewTest.java
index 8da3a43..d4ed8f6 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/synchronize/SynchronizeViewTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/synchronize/SynchronizeViewTest.java
@@ -218,7 +218,7 @@ public class SynchronizeViewTest extends LocalRepositoryTestCase {
public boolean test() throws Exception {
for (SWTBotTreeItem item : tree.getAllItems())
- if (item.getText().startsWith(text))
+ if (item.getText().contains(text))
return true;
return false;
}
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 5719df5..8a42059 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
@@ -13,6 +13,7 @@ package org.eclipse.egit.ui;
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
import org.eclipse.egit.ui.internal.decorators.GitLightweightDecorator;
import org.eclipse.jface.dialogs.MessageDialogWithToggle;
+import org.eclipse.egit.ui.internal.synchronize.mapping.GitChangeSetLabelProvider;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jgit.util.FS;
@@ -73,6 +74,11 @@ public class PluginPreferenceInitializer extends AbstractPreferenceInitializer {
store.setDefault(UIPreferences.REBASE_HIDE_CONFIRM, false);
store.setDefault(UIPreferences.SHOW_INITIAL_CONFIG_DIALOG, true);
store.setDefault(UIPreferences.SHOW_HOME_DIR_WARNING, MessageDialogWithToggle.PROMPT);
+
+ store.setDefault(UIPreferences.SYNC_VIEW_CHANGESET_LABEL_FORMAT,
+ GitChangeSetLabelProvider.DEFAULT_CHANGESET_FORMAT);
+ store.setDefault(UIPreferences.DATE_FORMAT,
+ GitChangeSetLabelProvider.DEFAULT_DATE_FORMAT);
}
}
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 ac9ea12..0969545 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
@@ -92,6 +92,10 @@ public class UIPreferences {
/** */
public final static String DECORATOR_SHOW_DIRTY_ICON = "decorator_show_dirty_icon"; //$NON-NLS-1$
/** */
+ public final static String SYNC_VIEW_CHANGESET_LABEL_FORMAT = "sync_view_changeset_pattern"; //$NON-NLS-1$
+ /** */
+ public final static String DATE_FORMAT = "date_format"; //$NON-NLS-1$
+ /** */
public static final String REFESH_ON_INDEX_CHANGE = "refesh_on_index_change"; //$NON-NLS-1$
/** */
public static final String REFESH_ONLY_WHEN_ACTIVE = "refesh_only_when_active"; //$NON-NLS-1$
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java
index 05d3efa..a60b82c 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java
@@ -2287,9 +2287,36 @@ public class UIText extends NLS {
public static String DecoratorPreferencesPage_bindingStagedFlag;
/** */
+ public static String DecoratorPreferencesPage_bindingChangeSetAuthor;
+
+ /** */
+ public static String DecoratorPreferencesPage_bindingChangeSetCommitter;
+
+ /** */
+ public static String DecoratorPreferencesPage_bindingChangeSetDate;
+
+ /** */
+ 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;
/** */
+ public static String DecoratorPreferencesPage_otherDecorations;
+
+ /** */
+ public static String DecoratorPreferencesPage_changeSetLabelFormat;
+
+ /** */
public static String DecoratorPreferencesPage_textLabel;
/** */
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 3d40a25..f84b8fa 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
@@ -11,9 +11,11 @@
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;
+import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@@ -23,12 +25,14 @@ import java.util.Observer;
import org.eclipse.core.resources.IResource;
import org.eclipse.egit.ui.Activator;
+import org.eclipse.egit.ui.UIIcons;
import org.eclipse.egit.ui.UIPreferences;
import org.eclipse.egit.ui.UIText;
import org.eclipse.egit.ui.internal.SWTUtils;
-import org.eclipse.egit.ui.internal.decorators.IDecoratableResource;
import org.eclipse.egit.ui.internal.decorators.GitLightweightDecorator.DecorationHelper;
+import org.eclipse.egit.ui.internal.decorators.IDecoratableResource;
import org.eclipse.egit.ui.internal.decorators.IDecoratableResource.Staged;
+import org.eclipse.egit.ui.internal.synchronize.mapping.GitChangeSetLabelProvider;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.preference.IPersistentPreferenceStore;
import org.eclipse.jface.preference.IPreferenceStore;
@@ -95,7 +99,13 @@ public class GitDecoratorPreferencePage extends PreferencePage implements
private IconDecorationTab iconDecorationTab;
- private Preview preview;
+ private OtherDecorationTab otherDecorationTab;
+
+ private Preview navigatorPreview;
+
+ private Preview changeSetPreview;
+
+ private boolean tabsInitialized;
private static final Collection PREVIEW_FILESYSTEM_ROOT;
@@ -103,6 +113,8 @@ public class GitDecoratorPreferencePage extends PreferencePage implements
private static final Map<String, String> PROJECT_BINDINGS;
+ private static final Map<String, String> CHANGESET_LABEL_BINDINGS;
+
private static IPropertyChangeListener themeListener;
static {
@@ -165,6 +177,16 @@ public class GitDecoratorPreferencePage extends PreferencePage implements
UIText.GitDecoratorPreferencePage_bindingRepositoryNameFlag);
PROJECT_BINDINGS.put(DecorationHelper.BINDING_BRANCH_NAME,
UIText.DecoratorPreferencesPage_bindingBranchName);
+
+ CHANGESET_LABEL_BINDINGS = new HashMap<String, String>();
+ CHANGESET_LABEL_BINDINGS.put(removeBraces(GitChangeSetLabelProvider.BINDING_CHANGESET_AUTHOR),
+ UIText.DecoratorPreferencesPage_bindingChangeSetAuthor);
+ CHANGESET_LABEL_BINDINGS.put(removeBraces(GitChangeSetLabelProvider.BINDING_CHANGESET_DATE),
+ UIText.DecoratorPreferencesPage_bindingChangeSetDate);
+ CHANGESET_LABEL_BINDINGS.put(removeBraces(GitChangeSetLabelProvider.BINDING_CHANGESET_COMMITTER),
+ UIText.DecoratorPreferencesPage_bindingChangeSetCommitter);
+ CHANGESET_LABEL_BINDINGS.put(removeBraces(GitChangeSetLabelProvider.BINDING_CHANGESET_SHORT_MESSAGE),
+ UIText.DecoratorPreferencesPage_bindingChangeSetShortMessage);
}
/**
@@ -174,6 +196,11 @@ public class GitDecoratorPreferencePage extends PreferencePage implements
setDescription(UIText.DecoratorPreferencesPage_description);
}
+ private static String removeBraces(String string) {
+ return string.replaceAll("[}{]", ""); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+
/**
* @see PreferencePage#createContents(Composite)
*/
@@ -190,24 +217,49 @@ public class GitDecoratorPreferencePage extends PreferencePage implements
TabFolder tabFolder = new TabFolder(composite, SWT.NONE);
tabFolder.setLayoutData(SWTUtils.createHVFillGridData());
+ tabFolder.addSelectionListener(new SelectionAdapter() {
+
+ public void widgetSelected(SelectionEvent e) {
+ if (navigatorPreview != null && changeSetPreview != null) {
+ if (UIText.DecoratorPreferencesPage_otherDecorations.equals(e.item.getData())) {
+ navigatorPreview.hide();
+ changeSetPreview.show();
+ } else {
+ changeSetPreview.hide();
+ navigatorPreview.show();
+ }
+ }
+ }
+
+ });
+
+ changeSetPreview = new ChangeSetPreview(composite);
+ navigatorPreview = new NavigatorPreview(composite);
+
generalTab = new GeneralTab(tabFolder);
textDecorationTab = new TextDecorationTab(tabFolder);
iconDecorationTab = new IconDecorationTab(tabFolder);
+ otherDecorationTab = new OtherDecorationTab(tabFolder);
initializeValues();
- preview = new Preview(composite);
- preview.refresh();
+ changeSetPreview.hide();
+
+ changeSetPreview.refresh();
+ navigatorPreview.refresh();
+
+ generalTab.addObserver(navigatorPreview);
+ textDecorationTab.addObserver(navigatorPreview);
+ iconDecorationTab.addObserver(navigatorPreview);
- generalTab.addObserver(preview);
- textDecorationTab.addObserver(preview);
- iconDecorationTab.addObserver(preview);
+ otherDecorationTab.addObserver(changeSetPreview);
// TODO: Add help text for this preference page
themeListener = new IPropertyChangeListener() {
public void propertyChange(PropertyChangeEvent event) {
- preview.refresh();
+ navigatorPreview.refresh();
+ changeSetPreview.refresh();
}
};
PlatformUI.getWorkbench().getThemeManager().addPropertyChangeListener(
@@ -410,76 +462,156 @@ public class GitDecoratorPreferencePage extends PreferencePage implements
notifyObservers();
}
- private class FormatEditor extends SelectionAdapter {
- private final Text text;
+ }
- private final Map bindings;
+ private class OtherDecorationTab extends Tab implements ModifyListener {
- private final String key;
+ private final FormatEditor changeSetLabelFormat;
- public FormatEditor(Composite composite, String title,
- String buttonText, Map bindings, String key) {
+ private final Text dateFormat;
- this.key = key;
- this.bindings = bindings;
+ private final Label dateFormatPreview;
- final Label label = SWTUtils.createLabel(composite, title);
- label.setLayoutData(SWTUtils.createGridData(SWT.DEFAULT,
- SWT.DEFAULT, false, false));
+ private final Date exapmleDate = new Date();
- text = SWTUtils.createText(composite);
+ private boolean formatValid;
- final Button button = new Button(composite, SWT.NONE);
- button.setText(buttonText);
- button.setLayoutData(new GridData());
+ public OtherDecorationTab(TabFolder parent) {
+ Composite composite = SWTUtils.createHVFillComposite(parent,
+ SWTUtils.MARGINS_DEFAULT, 3);
+
+ changeSetLabelFormat = new FormatEditor(composite,
+ UIText.DecoratorPreferencesPage_changeSetLabelFormat,
+ UIText.DecoratorPreferencesPage_addVariablesAction3,
+ CHANGESET_LABEL_BINDINGS,
+ UIPreferences.SYNC_VIEW_CHANGESET_LABEL_FORMAT);
+
+ 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);
+ }
- button.addSelectionListener(this);
+ private void updateDateFormatPreview() {
+ SimpleDateFormat sdf;
+ try {
+ sdf = new SimpleDateFormat(dateFormat.getText());
+ dateFormatPreview.setText(sdf.format(exapmleDate));
+ formatValid = true;
+ } catch (Exception ex) {
+ dateFormatPreview.setText(UIText.DecoratorPreferencesPage_wrongDateFormat);
+ formatValid = false;
}
+ }
+
+ public void initializeValues(IPreferenceStore store) {
+ changeSetLabelFormat.initializeValue(store);
+ dateFormat.setText(store.getString(UIPreferences.DATE_FORMAT));
+ }
+
+ public void performDefaults(IPreferenceStore store) {
+ changeSetLabelFormat.performDefaults(store);
+ dateFormat.setText(store.getDefaultString(UIPreferences.DATE_FORMAT));
+ }
+
+ public void performOk(IPreferenceStore store) {
+ changeSetLabelFormat.performOk(store);
- public void addModifyListener(ModifyListener listener) {
- text.addModifyListener(listener);
+ if (formatValid) {
+ store.setValue(UIPreferences.DATE_FORMAT, dateFormat.getText());
}
+ }
- public void widgetSelected(SelectionEvent e) {
- final ILabelProvider labelProvider = new LabelProvider() {
- public String getText(Object element) {
- return ((Map.Entry) element).getKey()
- + " - " + ((Map.Entry) element).getValue(); //$NON-NLS-1$
- }
- };
+ public void modifyText(ModifyEvent e) {
+ updateDateFormatPreview();
+ setChanged();
+ notifyObservers();
+ }
+ }
+
+ private class FormatEditor extends SelectionAdapter {
+ private final Text text;
+
+ private final Map bindings;
+
+ private final String key;
- final IStructuredContentProvider contentsProvider = ArrayContentProvider.getInstance();
+ public FormatEditor(Composite composite, String title,
+ String buttonText, Map bindings, String key) {
- final ListSelectionDialog dialog = new ListSelectionDialog(text
- .getShell(), bindings.entrySet(), contentsProvider,
- labelProvider,
- UIText.DecoratorPreferencesPage_selectVariablesToAdd);
- dialog.setHelpAvailable(false);
- dialog
- .setTitle(UIText.DecoratorPreferencesPage_addVariablesTitle);
- if (dialog.open() != Window.OK)
- return;
+ this.key = key;
+ this.bindings = bindings;
- Object[] result = dialog.getResult();
+ final Label label = SWTUtils.createLabel(composite, title);
+ label.setLayoutData(SWTUtils.createGridData(SWT.DEFAULT,
+ SWT.DEFAULT, false, false));
- for (int i = 0; i < result.length; i++) {
- text.insert("{" + ((Map.Entry) result[i]).getKey() + "}"); //$NON-NLS-1$ //$NON-NLS-2$
+ text = SWTUtils.createText(composite);
+
+ final Button button = new Button(composite, SWT.NONE);
+ button.setText(buttonText);
+ button.setLayoutData(new GridData());
+
+ button.addSelectionListener(this);
+ }
+
+ public void addModifyListener(ModifyListener listener) {
+ text.addModifyListener(listener);
+ }
+
+ public void widgetSelected(SelectionEvent e) {
+ final ILabelProvider labelProvider = new LabelProvider() {
+ public String getText(Object element) {
+ return ((Map.Entry) element).getKey()
+ + " - " + ((Map.Entry) element).getValue(); //$NON-NLS-1$
}
- }
+ };
- public void performOk(IPreferenceStore store) {
- store.setValue(key, text.getText());
- }
+ final IStructuredContentProvider contentsProvider = ArrayContentProvider.getInstance();
- public void performDefaults(IPreferenceStore store) {
- store.setToDefault(key);
- text.setText(store.getDefaultString(key));
- }
+ final ListSelectionDialog dialog = new ListSelectionDialog(text
+ .getShell(), bindings.entrySet(), contentsProvider,
+ labelProvider,
+ UIText.DecoratorPreferencesPage_selectVariablesToAdd);
+ dialog.setHelpAvailable(false);
+ dialog
+ .setTitle(UIText.DecoratorPreferencesPage_addVariablesTitle);
+ if (dialog.open() != Window.OK)
+ return;
- public void initializeValue(IPreferenceStore store) {
- text.setText(store.getString(key));
+ Object[] result = dialog.getResult();
+
+ for (int i = 0; i < result.length; i++) {
+ text.insert("{" + ((Map.Entry) result[i]).getKey() + "}"); //$NON-NLS-1$ //$NON-NLS-2$
}
}
+
+ public void performOk(IPreferenceStore store) {
+ store.setValue(key, text.getText());
+ }
+
+ public void performDefaults(IPreferenceStore store) {
+ store.setToDefault(key);
+ text.setText(store.getDefaultString(key));
+ }
+
+ public void initializeValue(IPreferenceStore store) {
+ text.setText(store.getString(key));
+ }
}
/**
@@ -598,7 +730,9 @@ public class GitDecoratorPreferencePage extends PreferencePage implements
generalTab.initializeValues(store);
textDecorationTab.initializeValues(store);
iconDecorationTab.initializeValues(store);
+ otherDecorationTab.initializeValues(store);
setValid(true);
+ tabsInitialized = true;
}
/**
@@ -640,6 +774,7 @@ public class GitDecoratorPreferencePage extends PreferencePage implements
generalTab.performOk(store);
textDecorationTab.performOk(store);
iconDecorationTab.performOk(store);
+ otherDecorationTab.performOk(store);
return true;
}
@@ -652,12 +787,14 @@ public class GitDecoratorPreferencePage extends PreferencePage implements
generalTab.performDefaults(store);
textDecorationTab.performDefaults(store);
iconDecorationTab.performDefaults(store);
+ otherDecorationTab.performDefaults(store);
super.performDefaults();
- preview.refresh();
+ navigatorPreview.refresh();
+ changeSetPreview.refresh();
}
/**
- * Returns the preference store that belongs to the our plugin.
+ * Returns the preference store that belongs to our plugin.
*
* This is important because we want to store our preferences separately
* from the desktop.
@@ -679,39 +816,135 @@ public class GitDecoratorPreferencePage extends PreferencePage implements
super.dispose();
}
+ private abstract class Preview
+ implements Observer {
+
+ protected PreferenceStore store = new PreferenceStore();
+ protected final TreeViewer fViewer;
+ private Composite composite;
+ private Composite parent;
+
+ protected final ResourceManager fImageCache = new LocalResourceManager(
+ JFaceResources.getResources());
+
+ public Preview(Composite parent) {
+ this.parent = parent;
+ composite = SWTUtils.createHVFillComposite(parent, SWTUtils.MARGINS_NONE);
+
+ SWTUtils.createLabel(composite, UIText.DecoratorPreferencesPage_preview);
+
+ fViewer = new TreeViewer(composite);
+ fViewer.getControl().setLayoutData(SWTUtils.createHVFillGridData());
+ }
+
+ public void update(Observable o, Object arg) {
+ refresh();
+ }
+
+ public abstract void refresh();
+
+ public void dispose() {
+ fImageCache.dispose();
+ }
+
+ public void hide() {
+ ((GridData)composite.getLayoutData()).exclude = true; // ignore by layout
+ composite.setVisible(false);
+ composite.layout();
+ parent.layout();
+ }
+
+ public void show() {
+ ((GridData)composite.getLayoutData()).exclude = false; // ignore by layout
+ composite.setVisible(true);
+ composite.layout();
+ parent.layout();
+ }
+ }
+
+ private class ChangeSetPreview extends Preview
+ implements Observer, ITreeContentProvider {
+
+ public ChangeSetPreview(Composite composite) {
+ super(composite);
+ fViewer.setContentProvider(this);
+ fViewer.setLabelProvider(new LabelProvider() {
+
+ @Override
+ public Image getImage(Object element) {
+ if (element instanceof GitModelCommitMokeup)
+ return fImageCache.createImage(UIIcons.CHANGESET);
+
+ return super.getImage(element);
+ }
+
+ public String getText(Object element) {
+ if (element instanceof GitModelCommitMokeup) {
+ String format = store.getString(UIPreferences.SYNC_VIEW_CHANGESET_LABEL_FORMAT);
+ String dateFormat = store.getString(UIPreferences.DATE_FORMAT);
+ return ((GitModelCommitMokeup)element).getMokeupText(format, dateFormat);
+ }
+ return super.getText(element);
+ }
+ });
+ fViewer.setContentProvider(this);
+ fViewer.setInput(new GitModelCommitMokeup());
+ }
+
+ public Object[] getChildren(Object parentElement) {
+ return new Object[0];
+ }
+
+ public Object getParent(Object element) {
+ return null;
+ }
+
+ public boolean hasChildren(Object element) {
+ return false;
+ }
+
+ public Object[] getElements(Object inputElement) {
+ return new Object[] { inputElement };
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ // No-op
+ }
+
+ public void refresh() {
+ store = new PreferenceStore();
+ performOk(store);
+ fViewer.refresh(true);
+ }
+ }
+
+
/**
- * Preview control for showing how changes in the dialog will affect
+ * NavigatorPreview control for showing how changes in the dialog will affect
* decoration
*/
- private class Preview extends LabelProvider implements Observer,
- ITreeContentProvider {
-
- private final ResourceManager fImageCache;
-
- private final TreeViewer fViewer;
+ private class NavigatorPreview extends Preview
+ implements ITreeContentProvider {
private DecorationHelper fHelper;
- public Preview(Composite composite) {
+ public NavigatorPreview(Composite composite) {
+ super(composite);
// Has to happen before the tree control is constructed
reloadDecorationHelper();
- SWTUtils.createLabel(composite,
- UIText.DecoratorPreferencesPage_preview);
- fImageCache = new LocalResourceManager(JFaceResources
- .getResources());
- fViewer = new TreeViewer(composite);
- fViewer.getControl().setLayoutData(SWTUtils.createHVFillGridData());
fViewer.setContentProvider(this);
- fViewer.setLabelProvider(this);
+ fViewer.setLabelProvider(new ResLabelProvider());
fViewer.setInput(PREVIEW_FILESYSTEM_ROOT);
fViewer.expandAll();
fHelper = new DecorationHelper(new PreferenceStore());
}
private void reloadDecorationHelper() {
- PreferenceStore store = new PreferenceStore();
- performOk(store);
+ store = new PreferenceStore();
+ if (tabsInitialized)
+ performOk(store);
+
fHelper = new DecorationHelper(store);
}
@@ -731,10 +964,6 @@ public class GitDecoratorPreferencePage extends PreferencePage implements
}
}
- public void update(Observable o, Object arg) {
- refresh();
- }
-
public Object[] getChildren(Object parentElement) {
return ((PreviewResource) parentElement).children.toArray();
}
@@ -751,60 +980,79 @@ public class GitDecoratorPreferencePage extends PreferencePage implements
return ((Collection) inputElement).toArray();
}
- public void dispose() {
- fImageCache.dispose();
- }
-
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
// No-op
}
- public String getText(Object element) {
- final PreviewDecoration decoration = getDecoration(element);
- final StringBuilder buffer = new StringBuilder();
- final String prefix = decoration.getPrefix();
- if (prefix != null)
- buffer.append(prefix);
- buffer.append(((PreviewResource) element).getName());
- final String suffix = decoration.getSuffix();
- if (suffix != null)
- buffer.append(suffix);
- return buffer.toString();
- }
-
- public Image getImage(Object element) {
- final String s;
- switch (((PreviewResource) element).type) {
- case IResource.PROJECT:
- s = SharedImages.IMG_OBJ_PROJECT;
- break;
- case IResource.FOLDER:
- s = ISharedImages.IMG_OBJ_FOLDER;
- break;
- default:
- s = ISharedImages.IMG_OBJ_FILE;
- break;
- }
- final Image baseImage = PlatformUI.getWorkbench().getSharedImages()
- .getImage(s);
- final ImageDescriptor overlay = getDecoration(element).getOverlay();
- if (overlay == null)
- return baseImage;
- try {
- return fImageCache.createImage(new DecorationOverlayIcon(
- baseImage, overlay, IDecoration.BOTTOM_RIGHT));
- } catch (Exception e) {
- Activator.logError(e.getMessage(), e);
- }
-
- return null;
- }
-
private PreviewDecoration getDecoration(Object element) {
PreviewDecoration decoration = new PreviewDecoration();
fHelper.decorate(decoration, (PreviewResource) element);
return decoration;
}
+
+ private class ResLabelProvider extends LabelProvider {
+
+ public String getText(Object element) {
+ final PreviewDecoration decoration = getDecoration(element);
+ final StringBuilder buffer = new StringBuilder();
+ final String prefix = decoration.getPrefix();
+ if (prefix != null)
+ buffer.append(prefix);
+ buffer.append(((PreviewResource) element).getName());
+ final String suffix = decoration.getSuffix();
+ if (suffix != null)
+ buffer.append(suffix);
+ return buffer.toString();
+ }
+
+ public Image getImage(Object element) {
+ final String s;
+ switch (((PreviewResource) element).type) {
+ case IResource.PROJECT:
+ s = SharedImages.IMG_OBJ_PROJECT;
+ break;
+ case IResource.FOLDER:
+ s = ISharedImages.IMG_OBJ_FOLDER;
+ break;
+ default:
+ s = ISharedImages.IMG_OBJ_FILE;
+ break;
+ }
+ final Image baseImage = PlatformUI.getWorkbench().getSharedImages()
+ .getImage(s);
+ final ImageDescriptor overlay = getDecoration(element).getOverlay();
+ if (overlay == null)
+ return baseImage;
+ try {
+ return fImageCache.createImage(new DecorationOverlayIcon(
+ baseImage, overlay, IDecoration.BOTTOM_RIGHT));
+ } catch (Exception e) {
+ Activator.logError(e.getMessage(), e);
+ }
+
+ return null;
+ }
+ }
+ }
+
+ private static class GitModelCommitMokeup {
+
+ private static final String message = "Commit message text"; //$NON-NLS-1$
+ private static final String author = "Author Name"; //$NON-NLS-1$
+ 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);
+
+ Map<String, String> bindings = new HashMap<String, String>();
+ bindings.put(GitChangeSetLabelProvider.BINDING_CHANGESET_DATE, sdf.format(date));
+ bindings.put(GitChangeSetLabelProvider.BINDING_CHANGESET_AUTHOR, author);
+ bindings.put(GitChangeSetLabelProvider.BINDING_CHANGESET_COMMITTER, committer);
+ bindings.put(GitChangeSetLabelProvider.BINDING_CHANGESET_SHORT_MESSAGE, message);
+
+ return GitChangeSetLabelProvider.formatName(format, bindings);
+ }
}
private static class PreviewResource implements IDecoratableResource {
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/mapping/GitChangeSetLabelProvider.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/mapping/GitChangeSetLabelProvider.java
index 3f7d676..125cc5e 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/mapping/GitChangeSetLabelProvider.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/mapping/GitChangeSetLabelProvider.java
@@ -9,10 +9,15 @@
package org.eclipse.egit.ui.internal.synchronize.mapping;
import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
import org.eclipse.core.resources.IResource;
import org.eclipse.egit.core.Activator;
import org.eclipse.egit.ui.UIIcons;
+import org.eclipse.egit.ui.UIPreferences;
import org.eclipse.egit.ui.internal.synchronize.model.GitModelBlob;
import org.eclipse.egit.ui.internal.synchronize.model.GitModelCommit;
import org.eclipse.egit.ui.internal.synchronize.model.GitModelCache;
@@ -20,6 +25,7 @@ import org.eclipse.egit.ui.internal.synchronize.model.GitModelObject;
import org.eclipse.egit.ui.internal.synchronize.model.GitModelRepository;
import org.eclipse.egit.ui.internal.synchronize.model.GitModelTree;
import org.eclipse.egit.ui.internal.synchronize.model.GitModelWorkingTree;
+import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.resource.LocalResourceManager;
import org.eclipse.jface.resource.ResourceManager;
@@ -41,6 +47,32 @@ import org.eclipse.ui.model.WorkbenchLabelProvider;
public class GitChangeSetLabelProvider extends SynchronizationLabelProvider
implements IStyledLabelProvider {
+ /** */
+ public static final String BINDING_CHANGESET_SHORT_MESSAGE = "{short_message}"; //$NON-NLS-1$
+
+ /** */
+ public static final String BINDING_CHANGESET_COMMITTER = "{committer}"; //$NON-NLS-1$
+
+ /** */
+ public static final String BINDING_CHANGESET_AUTHOR = "{author}"; //$NON-NLS-1$
+
+ /** */
+ public static final String BINDING_CHANGESET_DATE = "{date}"; //$NON-NLS-1$
+
+ /** */
+ public static final String DEFAULT_CHANGESET_FORMAT = String.format("[%s] (%s) %s", //$NON-NLS-1$
+ BINDING_CHANGESET_AUTHOR,
+ BINDING_CHANGESET_DATE,
+ BINDING_CHANGESET_SHORT_MESSAGE);
+
+ /** */
+ public static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss"; //$NON-NLS-1$
+
+ private IPreferenceStore store = org.eclipse.egit.ui.Activator.getDefault().getPreferenceStore();
+
+ private final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat(
+ store.getString(UIPreferences.DATE_FORMAT));
+
private static final ILabelProvider workbenchLabelProvider = WorkbenchLabelProvider
.getDecoratingWorkbenchLabelProvider();
@@ -102,7 +134,8 @@ public class GitChangeSetLabelProvider extends SynchronizationLabelProvider
String rawText = getText(element);
// need to compare classes as everything is 'instanceof GitModelCommit'
if (element.getClass().equals(GitModelCommit.class)) {
- StyledString string = new StyledString(rawText);
+ String formattedName = createChangeSetLabel((GitModelCommit) element);
+ StyledString string = new StyledString(formattedName);
GitModelCommit commit = (GitModelCommit) element;
String format = " [" + getAbbreviatedId(commit) + "]"; //$NON-NLS-1$//$NON-NLS-2$
string.append(format, StyledString.DECORATIONS_STYLER);
@@ -112,6 +145,32 @@ public class GitChangeSetLabelProvider extends SynchronizationLabelProvider
return new StyledString(rawText);
}
+ private String createChangeSetLabel(GitModelCommit commit) {
+ String format = store.getString(UIPreferences.SYNC_VIEW_CHANGESET_LABEL_FORMAT);
+
+ RevCommit baseCommit = commit.getBaseCommit();
+ Map<String, String> bindings = new HashMap<String, String>();
+ bindings.put(BINDING_CHANGESET_DATE, DATE_FORMAT.format(baseCommit.getAuthorIdent().getWhen()));
+ bindings.put(BINDING_CHANGESET_AUTHOR, baseCommit.getAuthorIdent().getName());
+ bindings.put(BINDING_CHANGESET_COMMITTER, baseCommit.getCommitterIdent().getName());
+ bindings.put(BINDING_CHANGESET_SHORT_MESSAGE, baseCommit.getShortMessage());
+
+ return formatName(format, bindings);
+ }
+
+ /**
+ * @param format
+ * @param bindings
+ * @return formatted commit name
+ */
+ public static String formatName(final String format, Map<String, String> bindings) {
+ String result = format;
+ for (Entry<String, String> e : bindings.entrySet()) {
+ result = result.replace(e.getKey(), e.getValue());
+ }
+ return result;
+ }
+
private String getAbbreviatedId(GitModelCommit commit) {
RevCommit remoteCommit = commit.getBaseCommit();
ObjectReader reader = commit.getRepository().newObjectReader();
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties
index 293f68f..86fdfa8 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties
@@ -789,6 +789,15 @@ DecoratorPreferencesPage_iconsShowUntracked=Untracked resources
DecoratorPreferencesPage_iconsShowStaged=Staged resources
DecoratorPreferencesPage_iconsShowConflicts=Conflicting resources
DecoratorPreferencesPage_iconsShowAssumeValid=Assumed unchanged resources
+DecoratorPreferencesPage_changeSetLabelFormat=Change Sets:
+DecoratorPreferencesPage_otherDecorations=Other
+DecoratorPreferencesPage_dateFormat=Date Format:
+DecoratorPreferencesPage_dateFormatPreview=Date preview:
+DecoratorPreferencesPage_wrongDateFormat=#Incorrect date format#
+DecoratorPreferencesPage_bindingChangeSetAuthor=Change set author name;
+DecoratorPreferencesPage_bindingChangeSetCommitter=Change set committer name;
+DecoratorPreferencesPage_bindingChangeSetDate=Change set creation date (see Date Format setting);
+DecoratorPreferencesPage_bindingChangeSetShortMessage=First Line of commit message text;
Decorator_exceptionMessage=Errors occurred while applying Git decorations to resources.
DeleteBranchCommand_CannotDeleteCheckedOutBranch=Can not delete the currently checked out branch