vcs: keep tree state + list state between data reset only if special flag says that

(example: in git log this component is reused but we shouldn't keep expansion/selection state)
in commit dialog we should keep expansion/selection state between data reset
This commit is contained in:
irengrig
2012-03-27 19:04:47 +04:00
parent 815a5489b0
commit 14488bbd0a
3 changed files with 22 additions and 10 deletions
@@ -268,6 +268,10 @@ public class ChangesBrowser extends JPanel implements TypeSafeDataProvider {
myViewer.setChangesToDisplay(getCurrentDisplayedChanges(), myToSelect);
}
public void setAlwayExpandList(final boolean value) {
myViewer.setAlwaysExpandList(value);
}
private JComponent createToolbar() {
DefaultActionGroup toolbarGroups = new DefaultActionGroup();
myToolBarGroup = new DefaultActionGroup();
@@ -75,6 +75,7 @@ public abstract class ChangesTreeList<T> extends JPanel {
private final Collection<T> myIncludedChanges;
private Runnable myDoubleClickHandler = EmptyRunnable.getInstance();
private boolean myAlwaysExpandList;
@NonNls private static final String TREE_CARD = "Tree";
@NonNls private static final String LIST_CARD = "List";
@@ -95,6 +96,7 @@ public abstract class ChangesTreeList<T> extends JPanel {
myInclusionListener = inclusionListener;
myChangeDecorator = decorator;
myIncludedChanges = new HashSet<T>(initiallyIncluded);
myAlwaysExpandList = true;
myCards = new CardLayout();
@@ -312,23 +314,24 @@ public abstract class ChangesTreeList<T> extends JPanel {
return sortedChanges.get(index);
}
});
final TIntArrayList indices = new TIntArrayList();
for (int i = 0; i < sortedChanges.size(); i++) {
T t = sortedChanges.get(i);
if (wasSelected.contains(t)) {
indices.add(i);
}
}
myList.setSelectedIndices(indices.toNativeArray());
final DefaultTreeModel model = buildTreeModel(changes, myChangeDecorator);
TreeState state = null;
if (! wasEmpty) {
if (! myAlwaysExpandList && ! wasEmpty) {
state = TreeState.createOn(myTree, (DefaultMutableTreeNode) myTree.getModel().getRoot());
}
myTree.setModel(model);
if (! wasEmpty) {
if (! myAlwaysExpandList && ! wasEmpty) {
state.applyTo(myTree, (DefaultMutableTreeNode) myTree.getModel().getRoot());
final TIntArrayList indices = new TIntArrayList();
for (int i = 0; i < sortedChanges.size(); i++) {
T t = sortedChanges.get(i);
if (wasSelected.contains(t)) {
indices.add(i);
}
}
myList.setSelectedIndices(indices.toNativeArray());
return;
}
@@ -860,4 +863,8 @@ public abstract class ChangesTreeList<T> extends JPanel {
public void enableSelection(final boolean value) {
myTree.setEnabled(value);
}
public void setAlwaysExpandList(boolean alwaysExpandList) {
myAlwaysExpandList = alwaysExpandList;
}
}
@@ -270,6 +270,7 @@ public class CommitChangeListDialog extends DialogWrapper implements CheckinProj
}
};
myBrowser = browser;
myBrowser.setAlwayExpandList(false);
myBrowserExtender = browser.getExtender();
}
myDiffDetails.setParent(myBrowser);