IDEA-105413 Remove filter from serialized form of Mantis project in settings

This commit is contained in:
Mikhail Golubev
2014-03-20 19:23:11 +04:00
parent e350d3b0c9
commit 730951b976
5 changed files with 49 additions and 33 deletions
@@ -9,10 +9,10 @@ import org.jetbrains.annotations.NotNull;
*/
public final class MantisFilter implements Comparable<MantisFilter> {
// Used for "[Last task] filter"
public static final int UNDEFINED_FILTER_ID = 0;
public static final int UNSPECIFIED_FILTER_ID = 0;
public static MantisFilter newUndefined() {
return new MantisFilter(0, "[Last tasks]");
return new MantisFilter(0, "-- all issues --");
}
private int id;
@@ -45,8 +45,8 @@ public final class MantisFilter implements Comparable<MantisFilter> {
this.name = name;
}
public final boolean isUndefined() {
return getId() == UNDEFINED_FILTER_ID;
public final boolean isUnspecified() {
return getId() == UNSPECIFIED_FILTER_ID;
}
@Override
@@ -1,9 +1,10 @@
package com.intellij.tasks.mantis;
import com.intellij.util.xmlb.annotations.AbstractCollection;
import com.intellij.util.xmlb.annotations.Attribute;
import com.intellij.util.xmlb.annotations.Transient;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -13,13 +14,13 @@ import java.util.List;
*/
public final class MantisProject {
// Used for "All projects" option in settings
public static final int UNDEFINED_PROJECT_ID = 0;
public static final int UNSPECIFIED_PROJECT_ID = 0;
public static MantisProject newUndefined() {
return new MantisProject(0, "All Projects");
return new MantisProject(0, "-- from all projects --");
}
private List<MantisFilter> myFilters;
private List<MantisFilter> myFilters = new ArrayList<MantisFilter>();
private int id;
private String name;
@@ -54,12 +55,18 @@ public final class MantisProject {
}
public final boolean isUndefined() {
return getId() == UNDEFINED_PROJECT_ID;
public final boolean isUnspecified() {
return getId() == UNSPECIFIED_PROJECT_ID;
}
//@OptionTag(tag = "filters", nameAttribute = "")
@AbstractCollection(surroundWithTag = false)
//@AbstractCollection(surroundWithTag = false)
/**
* Filters here are used only to simplify combo boxes management and are refreshed every time when settings
* are opened or user hit "Login" button. Thus they are not persisted in settings.
*/
@Transient
@NotNull
public List<MantisFilter> getFilters() {
return myFilters == null? Collections.<MantisFilter>emptyList() : myFilters;
@@ -102,17 +102,17 @@ public class MantisRepository extends BaseRepositoryImpl {
private List<Task> getIssuesFromPage(@NotNull MantisConnectPortType soap, int page, int pageSize) throws Exception {
List<IssueHeaderData> collectedHeaders = new ArrayList<IssueHeaderData>();
boolean isWorkaround = myCurrentProject.isUndefined() && !myAllProjectsAvailable;
boolean isWorkaround = myCurrentProject.isUnspecified() && !myAllProjectsAvailable;
// Projects to iterate over, actually needed only when "All Projects" pseudo-project is selected
// and is unsupported on server side.
List<MantisProject> projects = isWorkaround? myProjects : Collections.singletonList(myCurrentProject);
for (MantisProject project : projects) {
if (isWorkaround && project.isUndefined()) {
if (isWorkaround && project.isUnspecified()) {
continue;
}
assert !project.isUndefined() || myAllProjectsAvailable;
assert !project.isUnspecified() || myAllProjectsAvailable;
IssueHeaderData[] headers;
if (myCurrentFilter.isUndefined()) {
if (myCurrentFilter.isUnspecified()) {
headers = soap.mc_project_get_issue_headers(getUsername(), getPassword(),
bigInteger(project.getId()), bigInteger(page), bigInteger(pageSize));
}
@@ -143,7 +143,7 @@ public class MantisRepository extends BaseRepositoryImpl {
return new CancellableConnection() {
@Override
protected void doTest() throws Exception {
//refreshProjectsAndFilters();
//refreshProjects();
createSoap();
}
@@ -169,21 +169,22 @@ public class MantisRepository extends BaseRepositoryImpl {
return new MantisTask(data, this);
}
public List<MantisProject> fetchProjects() throws Exception {
@NotNull
public List<MantisProject> getProjects() throws Exception {
ensureProjectsRefreshed();
return myProjects;
return myProjects == null ? Collections.<MantisProject>emptyList() : myProjects;
}
private void ensureProjectsRefreshed() throws Exception {
if (myProjects == null) {
refreshProjectsAndFilters();
refreshProjects();
}
}
public void refreshProjectsAndFilters() throws Exception {
public void refreshProjects() throws Exception {
MantisConnectPortType soap = createSoap();
myAllProjectsAvailable = checkAllProjectsAvailable(soap);
myProjects = new ArrayList<MantisProject>();
ProjectData[] projectDatas = soap.mc_projects_get_user_accessible(getUsername(), getPassword());
List<MantisProject> projects =
new ArrayList<MantisProject>(ContainerUtil.map(projectDatas, new Function<ProjectData, MantisProject>() {
@@ -206,18 +207,19 @@ public class MantisRepository extends BaseRepositoryImpl {
projectFilters.add(0, MantisFilter.newUndefined());
project.setFilters(projectFilters);
myProjects.add(project);
}
// Explicitly add undefined project
Collections.sort(commonFilters);
commonFilters.add(0, MantisFilter.newUndefined());
MantisProject undefined = MantisProject.newUndefined();
undefined.setFilters(commonFilters);
myProjects.add(0, undefined);
projects.add(0, undefined);
myProjects = projects;
}
@NotNull
private MantisConnectPortType createSoap() throws Exception {
return new MantisConnectLocator().getMantisConnectPort(new URL(getUrl() + SOAP_API_LOCATION));
}
@@ -51,12 +51,12 @@ public class MantisRepositoryEditor extends BaseRepositoryEditor<MantisRepositor
myTestButton.setEnabled(myRepository.isConfigured());
// Fill comboboxes with current items if any
MantisProject currentProject = myRepository.getCurrentProject();
/* MantisProject currentProject = myRepository.getCurrentProject();
myProjectCombobox.addItem(currentProject);
if (currentProject != null) {
myFilterCombobox.setModel(new DefaultComboBoxModel(ArrayUtil.toObjectArray(currentProject.getFilters())));
myFilterCombobox.setSelectedItem(myRepository.getCurrentFilter());
}
}*/
// Populate filters list on project selection
myProjectCombobox.addItemListener(new ItemListener() {
@@ -66,12 +66,18 @@ public class MantisRepositoryEditor extends BaseRepositoryEditor<MantisRepositor
// equality check is needed to prevent resetting of combobox with filters
// on initial projects update
MantisProject project = (MantisProject)myProjectCombobox.getSelectedItem();
if (project != null && !project.equals(myRepository.getCurrentProject())) {
if (project != null) {
//noinspection unchecked
myFilterCombobox.setModel(new DefaultComboBoxModel(ArrayUtil.toObjectArray(project.getFilters())));
// "Last updated" filter should always be available
myFilterCombobox.setSelectedIndex(0);
doApply();
if (project.equals(myRepository.getCurrentProject())) {
// matters only on initialization
myFilterCombobox.setSelectedItem(myRepository.getCurrentFilter());
}
else {
// unspecified filter should always be available
myFilterCombobox.setSelectedIndex(0);
doApply();
}
}
}
}
@@ -136,7 +142,8 @@ public class MantisRepositoryEditor extends BaseRepositoryEditor<MantisRepositor
@NotNull
@Override
protected List<MantisProject> fetch(@NotNull ProgressIndicator indicator) throws Exception {
return myRepository.fetchProjects();
myRepository.refreshProjects();
return myRepository.getProjects();
}
@Nullable
@@ -20,8 +20,8 @@ public class MantisIntegrationTest extends TaskManagerTestCase {
mantisRepository.setUsername("deva");
mantisRepository.setPassword("deva");
assertTrue(mantisRepository.fetchProjects().size() >= 2);
final MantisProject mantisProject = mantisRepository.fetchProjects().get(1);
assertTrue(mantisRepository.getProjects().size() >= 2);
final MantisProject mantisProject = mantisRepository.getProjects().get(1);
assertEquals(mantisProject.getName(), "Mantis 1.2 project 1");
mantisRepository.setCurrentProject(mantisProject);