mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-27179 (Repository view of Changes shows wrong dates)
This commit is contained in:
+31
-6
@@ -22,36 +22,54 @@ import org.jetbrains.annotations.NonNls;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
*/
|
||||
public interface ChangeListGroupingStrategy {
|
||||
void beforeStart();
|
||||
boolean changedSinceApply();
|
||||
String getGroupName(CommittedChangeList changeList);
|
||||
Comparator<CommittedChangeList> getComparator();
|
||||
|
||||
ChangeListGroupingStrategy DATE = new ChangeListGroupingStrategy() {
|
||||
class DateChangeListGroupingStrategy implements ChangeListGroupingStrategy {
|
||||
@NonNls private final SimpleDateFormat myWeekdayFormat = new SimpleDateFormat("EEEE", Locale.ENGLISH);
|
||||
@NonNls private final SimpleDateFormat myMonthFormat = new SimpleDateFormat("MMMM", Locale.ENGLISH);
|
||||
@NonNls private final SimpleDateFormat myMonthYearFormat = new SimpleDateFormat("MMMM yyyy", Locale.ENGLISH);
|
||||
private long myTimeToRecalculateAfter;
|
||||
private Calendar myCurrentCalendar;
|
||||
|
||||
public String toString() {
|
||||
return VcsBundle.message("date.group.title");
|
||||
}
|
||||
|
||||
public boolean changedSinceApply() {
|
||||
return System.currentTimeMillis() > myTimeToRecalculateAfter;
|
||||
}
|
||||
|
||||
public void beforeStart() {
|
||||
myCurrentCalendar = Calendar.getInstance();
|
||||
// +- seconds etc
|
||||
myCurrentCalendar.set(Calendar.HOUR, 0);
|
||||
myCurrentCalendar.set(Calendar.MINUTE, 0);
|
||||
|
||||
myTimeToRecalculateAfter = myCurrentCalendar.getTimeInMillis() + 24 * 60 * 60 * 1000;
|
||||
myCurrentCalendar.setTime(new Date());
|
||||
}
|
||||
|
||||
public String getGroupName(final CommittedChangeList list) {
|
||||
Calendar curCal = Calendar.getInstance();
|
||||
Calendar clCal = Calendar.getInstance();
|
||||
clCal.setTime(list.getCommitDate());
|
||||
if (curCal.get(Calendar.YEAR) == clCal.get(Calendar.YEAR)) {
|
||||
if (curCal.get(Calendar.DAY_OF_YEAR) == clCal.get(Calendar.DAY_OF_YEAR)) {
|
||||
if (myCurrentCalendar.get(Calendar.YEAR) == clCal.get(Calendar.YEAR)) {
|
||||
if (myCurrentCalendar.get(Calendar.DAY_OF_YEAR) == clCal.get(Calendar.DAY_OF_YEAR)) {
|
||||
return VcsBundle.message("date.group.today");
|
||||
}
|
||||
if (curCal.get(Calendar.WEEK_OF_YEAR) == clCal.get(Calendar.WEEK_OF_YEAR)) {
|
||||
if (myCurrentCalendar.get(Calendar.WEEK_OF_YEAR) == clCal.get(Calendar.WEEK_OF_YEAR)) {
|
||||
return myWeekdayFormat.format(list.getCommitDate());
|
||||
}
|
||||
if (curCal.get(Calendar.WEEK_OF_YEAR) == clCal.get(Calendar.WEEK_OF_YEAR)+1) {
|
||||
if (myCurrentCalendar.get(Calendar.WEEK_OF_YEAR) == clCal.get(Calendar.WEEK_OF_YEAR)+1) {
|
||||
return VcsBundle.message("date.group.last.week");
|
||||
}
|
||||
return myMonthFormat.format(list.getCommitDate());
|
||||
@@ -77,6 +95,13 @@ public interface ChangeListGroupingStrategy {
|
||||
return changeList.getCommitterName();
|
||||
}
|
||||
|
||||
public void beforeStart() {
|
||||
}
|
||||
|
||||
public boolean changedSinceApply() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Comparator<CommittedChangeList> getComparator() {
|
||||
return new Comparator<CommittedChangeList>() {
|
||||
public int compare(final CommittedChangeList o1, final CommittedChangeList o2) {
|
||||
|
||||
+2
@@ -785,6 +785,8 @@ public class CommittedChangesCache implements PersistentStateComponent<Committed
|
||||
public void receivedChanges(List<CommittedChangeList> changes) {
|
||||
if (changes.size() > 0) {
|
||||
notifyReloadIncomingChanges();
|
||||
} else {
|
||||
myProject.getMessageBus().syncPublisher(CommittedChangesTreeBrowser.ITEMS_RELOADED).emptyRefresh();
|
||||
}
|
||||
checkDone();
|
||||
}
|
||||
|
||||
+32
-3
@@ -12,6 +12,7 @@ import com.intellij.ide.ui.SplitterProportionsDataImpl;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.actionSystem.*;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.ModalityState;
|
||||
import com.intellij.openapi.keymap.KeymapManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.Splitter;
|
||||
@@ -36,6 +37,7 @@ import com.intellij.ui.SimpleTextAttributes;
|
||||
import com.intellij.ui.TreeCopyProvider;
|
||||
import com.intellij.ui.treeStructure.actions.CollapseAllAction;
|
||||
import com.intellij.ui.treeStructure.actions.ExpandAllAction;
|
||||
import com.intellij.util.messages.MessageBusConnection;
|
||||
import com.intellij.util.messages.Topic;
|
||||
import com.intellij.util.ui.TreeWithEmptyText;
|
||||
import com.intellij.util.ui.tree.TreeUtil;
|
||||
@@ -71,7 +73,7 @@ public class CommittedChangesTreeBrowser extends JPanel implements TypeSafeDataP
|
||||
private final RepositoryChangesBrowser myChangesView;
|
||||
private List<CommittedChangeList> myChangeLists;
|
||||
private List<CommittedChangeList> mySelectedChangeLists;
|
||||
private ChangeListGroupingStrategy myGroupingStrategy = ChangeListGroupingStrategy.DATE;
|
||||
private ChangeListGroupingStrategy myGroupingStrategy = new ChangeListGroupingStrategy.DateChangeListGroupingStrategy();
|
||||
private final CompositeChangeListFilteringStrategy myFilteringStrategy = new CompositeChangeListFilteringStrategy();
|
||||
private final Splitter myFilterSplitter;
|
||||
private final JPanel myLeftPanel;
|
||||
@@ -82,13 +84,14 @@ public class CommittedChangesTreeBrowser extends JPanel implements TypeSafeDataP
|
||||
private final TreeExpander myTreeExpander;
|
||||
private String myHelpId;
|
||||
|
||||
public static final Topic<Runnable> ITEMS_RELOADED = new Topic<Runnable>("ITEMS_RELOADED", Runnable.class);
|
||||
public static final Topic<CommittedChangesReloadListener> ITEMS_RELOADED = new Topic<CommittedChangesReloadListener>("ITEMS_RELOADED", CommittedChangesReloadListener.class);
|
||||
|
||||
private final List<CommittedChangeListDecorator> myDecorators;
|
||||
|
||||
@NonNls public static final String ourHelpId = "reference.changesToolWindow.incoming";
|
||||
|
||||
private final WiseSplitter myInnerSplitter;
|
||||
private MessageBusConnection myConnection;
|
||||
|
||||
public CommittedChangesTreeBrowser(final Project project, final List<CommittedChangeList> changeLists) {
|
||||
super(new BorderLayout());
|
||||
@@ -149,6 +152,25 @@ public class CommittedChangesTreeBrowser extends JPanel implements TypeSafeDataP
|
||||
myHelpId = ourHelpId;
|
||||
|
||||
myChangesView.getDiffAction().registerCustomShortcutSet(CommonShortcuts.getDiff(), myChangesTree);
|
||||
|
||||
myConnection = myProject.getMessageBus().connect();
|
||||
myConnection.subscribe(ITEMS_RELOADED, new CommittedChangesReloadListener() {
|
||||
public void itemsReloaded() {
|
||||
}
|
||||
public void emptyRefresh() {
|
||||
updateGrouping();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void updateGrouping() {
|
||||
if (myGroupingStrategy.changedSinceApply()) {
|
||||
ApplicationManager.getApplication().invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
updateModel();
|
||||
}
|
||||
}, ModalityState.NON_MODAL);
|
||||
}
|
||||
}
|
||||
|
||||
private TreeModel buildTreeModel() {
|
||||
@@ -158,6 +180,7 @@ public class CommittedChangesTreeBrowser extends JPanel implements TypeSafeDataP
|
||||
DefaultMutableTreeNode lastGroupNode = null;
|
||||
String lastGroupName = null;
|
||||
Collections.sort(filteredChangeLists, myGroupingStrategy.getComparator());
|
||||
myGroupingStrategy.beforeStart();
|
||||
for(CommittedChangeList list: filteredChangeLists) {
|
||||
String groupName = myGroupingStrategy.getGroupName(list);
|
||||
if (!Comparing.equal(groupName, lastGroupName)) {
|
||||
@@ -196,6 +219,7 @@ public class CommittedChangesTreeBrowser extends JPanel implements TypeSafeDataP
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
myConnection.disconnect();
|
||||
mySplitterProportionsData.saveSplitterProportions(this);
|
||||
mySplitterProportionsData.externalizeToDimensionService("CommittedChanges.SplitterProportions");
|
||||
myChangesView.dispose();
|
||||
@@ -207,7 +231,7 @@ public class CommittedChangesTreeBrowser extends JPanel implements TypeSafeDataP
|
||||
if (!keepFilter) {
|
||||
myFilteringStrategy.setFilterBase(items);
|
||||
}
|
||||
ApplicationManager.getApplication().getMessageBus().syncPublisher(ITEMS_RELOADED).run();
|
||||
myProject.getMessageBus().syncPublisher(ITEMS_RELOADED).itemsReloaded();
|
||||
updateModel();
|
||||
}
|
||||
|
||||
@@ -658,4 +682,9 @@ public class CommittedChangesTreeBrowser extends JPanel implements TypeSafeDataP
|
||||
myInnerSplitter.setInnerComponent(last);
|
||||
}
|
||||
}
|
||||
|
||||
public interface CommittedChangesReloadListener {
|
||||
void itemsReloaded();
|
||||
void emptyRefresh();
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -33,6 +33,6 @@ public class SelectGroupingAction extends LabeledComboBoxAction {
|
||||
}
|
||||
|
||||
protected ComboBoxModel createModel() {
|
||||
return new DefaultComboBoxModel(new Object[] { ChangeListGroupingStrategy.DATE, ChangeListGroupingStrategy.USER });
|
||||
return new DefaultComboBoxModel(new Object[] { new ChangeListGroupingStrategy.DateChangeListGroupingStrategy(), ChangeListGroupingStrategy.USER });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,7 +74,13 @@ public class MergeInfoUpdatesListener {
|
||||
}
|
||||
});
|
||||
|
||||
myConnection.subscribe(CommittedChangesTreeBrowser.ITEMS_RELOADED, reloadRunnable);
|
||||
myConnection.subscribe(CommittedChangesTreeBrowser.ITEMS_RELOADED, new CommittedChangesTreeBrowser.CommittedChangesReloadListener() {
|
||||
public void itemsReloaded() {
|
||||
reloadRunnable.run();
|
||||
}
|
||||
public void emptyRefresh() {
|
||||
}
|
||||
});
|
||||
|
||||
myConnection.subscribe(SvnMergeInfoCache.SVN_MERGE_INFO_CACHE, new SvnMergeInfoCache.SvnMergeInfoCacheListener() {
|
||||
public void copyRevisionUpdated() {
|
||||
|
||||
Reference in New Issue
Block a user