SVN changes browser

This commit is contained in:
Olesya Smirnova
2005-03-17 23:23:57 +03:00
parent 52ac65a579
commit ba28fa884b
4 changed files with 354 additions and 1 deletions
@@ -10,7 +10,17 @@ import org.jdom.Element;
public class ChangeBrowserSettings implements ProjectComponent, JDOMExternalizable{
public float MAIN_SPLITTER_PROPORTION = 0.3f;
public float MESSAGES_SPLITTER_PROPORTION = 0.8f;
public float MESSAGES_SPLITTER_PROPORTION = 0.8f;
public boolean USE_DATE_BEFORE_FILTER = false;
public boolean USE_DATE_AFTER_FILTER = false;
public boolean USE_CHANGE_BEFORE_FILTER = false;
public boolean USE_CHANGE_AFTER_FILTER = false;
public String DATE_BEFORE = "";
public String DATE_AFTER = "";
public String CHANGE_BEFORE = "";
public String CHANGE_AFTER = "";
public static final ChangeBrowserSettings getSettings(Project project){
return project.getComponent(ChangeBrowserSettings.class);
@@ -0,0 +1,119 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.openapi.vcs.versionBrowser.StandardVersionFilterComponent">
<grid id="c8d20" binding="myPanel" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="18" y="16" width="366" height="101"/>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="cce22" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="0" y="0" width="366" height="48"/>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="1"/>
</constraints>
<properties/>
<border type="etched" title="Date"/>
<children>
<grid id="28216" row-count="1" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="6" y="20" width="354" height="22"/>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="970f2" class="javax.swing.JCheckBox" binding="myUseDateAfterFilter">
<constraints>
<xy x="0" y="0" width="51" height="22"/>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0"/>
</constraints>
<properties>
<text value="&amp;After"/>
</properties>
</component>
<component id="36ee9" class="com.intellij.openapi.ui.TextFieldWithBrowseButton" binding="myDateAfter">
<constraints>
<xy x="61" y="1" width="108" height="20"/>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="100" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="179e" class="javax.swing.JCheckBox" binding="myUseDateBeforeFilter">
<constraints>
<xy x="179" y="0" width="58" height="22"/>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0"/>
</constraints>
<properties>
<text value="&amp;Before"/>
</properties>
</component>
<component id="e98e3" class="com.intellij.openapi.ui.TextFieldWithBrowseButton" binding="myDateBefore">
<constraints>
<xy x="247" y="1" width="107" height="20"/>
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="100" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
</children>
</grid>
</children>
</grid>
<grid id="2ab92" row-count="1" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="0" y="53" width="366" height="48"/>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3"/>
</constraints>
<properties/>
<border type="etched" title="Change"/>
<children>
<component id="33df6" class="javax.swing.JCheckBox" binding="myUseNumAfterFilter">
<constraints>
<xy x="6" y="20" width="50" height="22"/>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0"/>
</constraints>
<properties>
<text value="&amp;From"/>
</properties>
</component>
<component id="7a847" class="javax.swing.JTextField" binding="myNumAfter">
<constraints>
<xy x="66" y="21" width="118" height="20"/>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="50" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="17476" class="javax.swing.JCheckBox" binding="myUseNumBeforeFilter">
<constraints>
<xy x="194" y="20" width="38" height="22"/>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0"/>
</constraints>
<properties>
<text value="&amp;To"/>
</properties>
</component>
<component id="76327" class="javax.swing.JTextField" binding="myNumBefore">
<constraints>
<xy x="242" y="21" width="118" height="20"/>
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="50" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
</children>
</grid>
</children>
</grid>
</form>
@@ -0,0 +1,223 @@
package com.intellij.openapi.vcs.versionBrowser;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
import com.intellij.util.ui.SelectDateDialog;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DateFormat;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
public class StandardVersionFilterComponent {
private JPanel myPanel;
public Component getStandardPanel() {
return myPanel;
}
public interface Filter {
boolean accepts(RepositoryVersion change);
}
private TextFieldWithBrowseButton myDateBefore;
private TextFieldWithBrowseButton myDateAfter;
private JCheckBox myUseDateBeforeFilter;
private JTextField myNumBefore;
private JCheckBox myUseDateAfterFilter;
private JCheckBox myUseNumBeforeFilter;
private JCheckBox myUseNumAfterFilter;
private JTextField myNumAfter;
private final Project myProject;
private final DateFormat myDateFormat;
public StandardVersionFilterComponent(Project project, DateFormat dateformat) {
myProject = project;
myDateFormat = dateformat;
}
protected void init(){
installBrowseDateActions();
installCheckBoxesListeners();
initValues();
updateAllEnabled(null);
}
private void installBrowseDateActions() {
myDateBefore.getButton().addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
final SelectDateDialog selectDateDialog = new SelectDateDialog(myProject);
selectDateDialog.show();
if (selectDateDialog.isOK()) {
myDateBefore.setText(myDateFormat.format(selectDateDialog.getDate()));
}
}
});
myDateAfter.getButton().addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
final SelectDateDialog selectDateDialog = new SelectDateDialog(myProject);
selectDateDialog.show();
if (selectDateDialog.isOK()) {
myDateAfter.setText(myDateFormat.format(selectDateDialog.getDate()));
}
}
});
}
private void installCheckBoxesListeners() {
final ActionListener filterListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
updateAllEnabled(e);
}
};
installCheckBoxListener(filterListener);
}
protected static void updatePair(JCheckBox checkBox, JComponent textField, ActionEvent e) {
textField.setEnabled(checkBox.isSelected());
if (e != null && e.getSource() instanceof JCheckBox && ((JCheckBox)e.getSource()).isSelected()) {
final Object source = e.getSource();
if (source == checkBox && checkBox.isSelected()) {
textField.requestFocus();
}
}
}
protected void updateAllEnabled(final ActionEvent e) {
updatePair(myUseDateBeforeFilter,myDateBefore, e);
updatePair(myUseDateAfterFilter,myDateAfter, e);
updatePair(myUseNumBeforeFilter,myNumBefore, e);
updatePair(myUseNumAfterFilter,myNumAfter, e);
}
protected void initValues() {
final ChangeBrowserSettings settings = ChangeBrowserSettings.getSettings(myProject);
myUseDateBeforeFilter.setSelected(settings.USE_DATE_BEFORE_FILTER);
myUseDateAfterFilter.setSelected(settings.USE_DATE_AFTER_FILTER);
myUseNumBeforeFilter.setSelected(settings.USE_CHANGE_BEFORE_FILTER);
myUseNumAfterFilter.setSelected(settings.USE_CHANGE_AFTER_FILTER);
myDateBefore.setText(settings.DATE_BEFORE);
myDateAfter.setText(settings.DATE_AFTER);
myNumBefore.setText(settings.CHANGE_BEFORE);
myNumAfter.setText(settings.CHANGE_AFTER);
}
public void saveValues() {
final ChangeBrowserSettings settings = ChangeBrowserSettings.getSettings(myProject);
settings.USE_DATE_BEFORE_FILTER = myUseDateBeforeFilter.isSelected();
settings.USE_DATE_AFTER_FILTER = myUseDateAfterFilter.isSelected();
settings.USE_CHANGE_BEFORE_FILTER = myUseNumBeforeFilter.isSelected();
settings.USE_CHANGE_AFTER_FILTER = myUseNumAfterFilter.isSelected();
settings.DATE_BEFORE = myDateBefore.getText();
settings.DATE_AFTER = myDateAfter.getText();
settings.CHANGE_BEFORE = myNumBefore.getText();
settings.CHANGE_AFTER = myNumAfter.getText();
}
protected void installCheckBoxListener(final ActionListener filterListener) {
myUseDateBeforeFilter.addActionListener(filterListener);
myUseDateAfterFilter.addActionListener(filterListener);
myUseNumBeforeFilter.addActionListener(filterListener);
myUseNumAfterFilter.addActionListener(filterListener);
}
protected List<Filter> createFilters() {
final ArrayList<Filter> result = new ArrayList<Filter>();
addDateFilter(myUseDateBeforeFilter, myDateBefore, result, true);
addDateFilter(myUseDateAfterFilter, myDateAfter, result, false);
if (myUseNumBeforeFilter.isSelected()) {
try {
final long numBefore = Long.parseLong(myNumBefore.getText());
result.add(new Filter() {
public boolean accepts(RepositoryVersion change) {
return change.getNumber() <= numBefore;
}
});
}
catch (NumberFormatException e) {
//ignore
}
}
if (myUseNumAfterFilter.isSelected()) {
try {
final long numBefore = Long.parseLong(myNumAfter.getText());
result.add(new Filter() {
public boolean accepts(RepositoryVersion change) {
return change.getNumber() >= numBefore;
}
});
}
catch (NumberFormatException e) {
//ignore
}
}
return result;
}
private void addDateFilter(final JCheckBox filter,
final TextFieldWithBrowseButton text,
final ArrayList<Filter> result,
final boolean before) {
if (filter.isSelected()) {
final String dateBefore = text.getText();
try {
final Date date = myDateFormat.parse(dateBefore);
result.add(new Filter() {
public boolean accepts(RepositoryVersion change) {
final Date changeDate = change.getDate();
if (changeDate == null) return false;
return before ? changeDate.before(date) : changeDate.after(date);
}
});
}
catch (ParseException e) {
//ignore
}
}
}
private Filter createFilter() {
final List<Filter> filters = createFilters();
return new Filter() {
public boolean accepts(RepositoryVersion change) {
for (Iterator<Filter> iterator = filters.iterator(); iterator.hasNext();) {
Filter filter = iterator.next();
if (!filter.accepts(change)) return false;
}
return true;
}
};
}
public void filterChanges(final List<RepositoryVersion> changeListInfos) {
Filter filter = createFilter();
for (Iterator<RepositoryVersion> iterator = changeListInfos.iterator(); iterator.hasNext();) {
RepositoryVersion changeListInfo = iterator.next();
if (!filter.accepts(changeListInfo)) {
iterator.remove();
}
}
}
}
+1
View File
@@ -53,6 +53,7 @@
</component>
<component>
<implementation-class>com.intellij.openapi.vcs.versionBrowser.ChangeBrowserSettings</implementation-class>
<option name="workspace" value="true"/>
</component>
</project-components>