From 6c65e5096977f382ebc130e84428f8045f0aa61a Mon Sep 17 00:00:00 2001 From: Mikhail Golubev Date: Thu, 18 Dec 2014 15:43:10 +0300 Subject: [PATCH] IDEA-125176 Use helper classes from TaskUiUtil in TrelloRepositoryEditor Also I cleaned up a bit: added missing @Nullable annotations and final modifiers for local variables. Field `myMoved` in TrelloList is not persisted any more. --- .../com/intellij/tasks/impl/TaskUiUtil.java | 9 +- .../tasks/trello/TrelloRepository.java | 77 +++-- .../tasks/trello/TrelloRepositoryEditor.java | 312 +++++++----------- .../tasks/trello/model/TrelloList.java | 2 + 4 files changed, 171 insertions(+), 229 deletions(-) diff --git a/plugins/tasks/tasks-core/src/com/intellij/tasks/impl/TaskUiUtil.java b/plugins/tasks/tasks-core/src/com/intellij/tasks/impl/TaskUiUtil.java index 9f28f8868ae7..d24ed38c9819 100644 --- a/plugins/tasks/tasks-core/src/com/intellij/tasks/impl/TaskUiUtil.java +++ b/plugins/tasks/tasks-core/src/com/intellij/tasks/impl/TaskUiUtil.java @@ -56,7 +56,6 @@ public class TaskUiUtil { /** * {@link #onSuccess()} can't be used for this purpose, because it doesn't consider current modality state * which will prevent UI updating in modal dialog (e.g. in {@link com.intellij.tasks.config.TaskRepositoryEditor}). - * @return */ @Nullable @Override @@ -113,7 +112,7 @@ public class TaskUiUtil { protected void updateUI() { if (myResult != null) { myComboBox.setModel(new DefaultComboBoxModel(ArrayUtil.toObjectArray(myResult))); - T extra = getExtraItem(); + final T extra = getExtraItem(); if (extra != null) { myComboBox.insertItemAt(extra, 0); } @@ -121,8 +120,11 @@ public class TaskUiUtil { // is the same as the next selected myComboBox.setSelectedItem(null); - T selected = getSelectedItem(); + final T selected = getSelectedItem(); if (selected != null) { + if (!selected.equals(extra) && !myResult.contains(selected)) { + myComboBox.addItem(selected); + } myComboBox.setSelectedItem(selected); } else if (myComboBox.getItemCount() > 0) { @@ -130,7 +132,6 @@ public class TaskUiUtil { } } else { - // Some error occurred handleError(); } } diff --git a/plugins/tasks/tasks-core/src/com/intellij/tasks/trello/TrelloRepository.java b/plugins/tasks/tasks-core/src/com/intellij/tasks/trello/TrelloRepository.java index 8ea6b8618d71..fb06a7d8b288 100644 --- a/plugins/tasks/tasks-core/src/com/intellij/tasks/trello/TrelloRepository.java +++ b/plugins/tasks/tasks-core/src/com/intellij/tasks/trello/TrelloRepository.java @@ -52,7 +52,21 @@ import static com.intellij.tasks.trello.TrelloUtil.TRELLO_API_BASE_URL; @Tag("Trello") public final class TrelloRepository extends BaseRepositoryImpl { - private static final Logger LOG = Logger.getInstance("#com.intellij.tasks.trello.TrelloRepository"); + private static final Logger LOG = Logger.getInstance(TrelloRepository.class); + static final TrelloBoard UNSPECIFIED_BOARD = new TrelloBoard() { + @NotNull + @Override + public String getName() { + return "-- from all boards --"; + } + }; + final static TrelloList UNSPECIFIED_LIST = new TrelloList() { + @NotNull + @Override + public String getName() { + return "-- from all lists --"; + } + }; // User is actually needed only to check ownership of card (by its id) private TrelloUser myCurrentUser; @@ -92,13 +106,14 @@ public final class TrelloRepository extends BaseRepositoryImpl { public boolean equals(Object o) { if (!super.equals(o)) return false; if (o.getClass() != getClass()) return false; - TrelloRepository repository = (TrelloRepository)o; + final TrelloRepository repository = (TrelloRepository)o; if (!Comparing.equal(myCurrentUser, repository.myCurrentUser)) return false; if (!Comparing.equal(myCurrentBoard, repository.myCurrentBoard)) return false; if (!Comparing.equal(myCurrentList, repository.myCurrentList)) return false; return myIncludeAllCards == repository.myIncludeAllCards; } + @SuppressWarnings("CloneDoesntCallSuperClone") @NotNull @Override public BaseRepository clone() { @@ -107,7 +122,7 @@ public final class TrelloRepository extends BaseRepositoryImpl { @Override public Task[] getIssues(@Nullable String query, int offset, int limit, boolean withClosed) throws Exception { - List cards = fetchCards(offset + limit, withClosed); + final List cards = fetchCards(offset + limit, withClosed); return ContainerUtil.map2Array(cards, Task.class, new Function() { @Override public Task fun(TrelloCard card) { @@ -119,13 +134,13 @@ public final class TrelloRepository extends BaseRepositoryImpl { @Nullable @Override public Task findTask(@NotNull String id) throws Exception { - TrelloCard card = fetchCardById(id); + final TrelloCard card = fetchCardById(id); return card != null ? new TrelloTask(card, this) : null; } @Nullable public TrelloCard fetchCardById(@NotNull String id) throws Exception { - String url = TRELLO_API_BASE_URL + "/cards/" + id + "?actions=commentCard&fields=" + encodeUrl(TrelloCard.REQUIRED_FIELDS); + final String url = TRELLO_API_BASE_URL + "/cards/" + id + "?actions=commentCard&fields=" + encodeUrl(TrelloCard.REQUIRED_FIELDS); try { return makeRequestAndDeserializeJsonResponse(url, TrelloCard.class); } @@ -151,8 +166,8 @@ public final class TrelloRepository extends BaseRepositoryImpl { return myCurrentBoard; } - public void setCurrentBoard(TrelloBoard currentBoard) { - myCurrentBoard = currentBoard; + public void setCurrentBoard(@Nullable TrelloBoard board) { + myCurrentBoard = board != null && board.getId().equals(UNSPECIFIED_BOARD.getId()) ? UNSPECIFIED_BOARD : board; } @Nullable @@ -160,8 +175,8 @@ public final class TrelloRepository extends BaseRepositoryImpl { return myCurrentList; } - public void setCurrentList(TrelloList currentList) { - myCurrentList = currentList; + public void setCurrentList(@Nullable TrelloList list) { + myCurrentList = list != null && list.getId().equals(UNSPECIFIED_LIST.getId()) ? UNSPECIFIED_LIST : list; } /** @@ -172,11 +187,11 @@ public final class TrelloRepository extends BaseRepositoryImpl { if (StringUtil.isEmpty(myPassword)) { return; } - String params = EncodingUtil.formUrlEncode(new NameValuePair[]{ + final String params = EncodingUtil.formUrlEncode(new NameValuePair[]{ new NameValuePair("token", myPassword), new NameValuePair("key", TrelloRepositoryType.DEVELOPER_KEY) }, "utf-8"); - String oldParams = method.getQueryString(); + final String oldParams = method.getQueryString(); method.setQueryString(StringUtil.isEmpty(oldParams) ? params : oldParams + "&" + params); } @@ -192,7 +207,7 @@ public final class TrelloRepository extends BaseRepositoryImpl { @NotNull public TrelloUser fetchUserByToken() throws Exception { try { - String url = TRELLO_API_BASE_URL + "/members/me?fields=" + encodeUrl(TrelloUser.REQUIRED_FIELDS); + final String url = TRELLO_API_BASE_URL + "/members/me?fields=" + encodeUrl(TrelloUser.REQUIRED_FIELDS); return makeRequestAndDeserializeJsonResponse(url, TrelloUser.class); } catch (Exception e) { @@ -206,7 +221,7 @@ public final class TrelloRepository extends BaseRepositoryImpl { @NotNull public TrelloBoard fetchBoardById(@NotNull String id) throws Exception { - String url = TRELLO_API_BASE_URL + "/boards/" + id + "?fields=" + encodeUrl(TrelloBoard.REQUIRED_FIELDS); + final String url = TRELLO_API_BASE_URL + "/boards/" + id + "?fields=" + encodeUrl(TrelloBoard.REQUIRED_FIELDS); try { return makeRequestAndDeserializeJsonResponse(url, TrelloBoard.class); } @@ -218,7 +233,7 @@ public final class TrelloRepository extends BaseRepositoryImpl { @NotNull public TrelloList fetchListById(@NotNull String id) throws Exception { - String url = TRELLO_API_BASE_URL + "/lists/" + id + "?fields=" + encodeUrl(TrelloList.REQUIRED_FIELDS); + final String url = TRELLO_API_BASE_URL + "/lists/" + id + "?fields=" + encodeUrl(TrelloList.REQUIRED_FIELDS); try { return makeRequestAndDeserializeJsonResponse(url, TrelloList.class); } @@ -230,10 +245,10 @@ public final class TrelloRepository extends BaseRepositoryImpl { @NotNull public List fetchBoardLists() throws Exception { - if (myCurrentBoard == null) { + if (myCurrentBoard == null || myCurrentBoard == UNSPECIFIED_BOARD) { throw new IllegalStateException("Board not set"); } - String url = TRELLO_API_BASE_URL + "/boards/" + myCurrentBoard.getId() + "/lists?fields=" + encodeUrl(TrelloList.REQUIRED_FIELDS); + final String url = TRELLO_API_BASE_URL + "/boards/" + myCurrentBoard.getId() + "/lists?fields=" + encodeUrl(TrelloList.REQUIRED_FIELDS); return makeRequestAndDeserializeJsonResponse(url, TrelloUtil.LIST_OF_LISTS_TYPE); } @@ -242,7 +257,7 @@ public final class TrelloRepository extends BaseRepositoryImpl { if (myCurrentUser == null) { throw new IllegalStateException("User not set"); } - String url = TRELLO_API_BASE_URL + "/members/me/boards?filter=open&fields=" + encodeUrl(TrelloBoard.REQUIRED_FIELDS); + final String url = TRELLO_API_BASE_URL + "/members/me/boards?filter=open&fields=" + encodeUrl(TrelloBoard.REQUIRED_FIELDS); return makeRequestAndDeserializeJsonResponse(url, TrelloUtil.LIST_OF_BOARDS_TYPE); } @@ -251,11 +266,11 @@ public final class TrelloRepository extends BaseRepositoryImpl { boolean fromList = false; // choose most appropriate card provider String baseUrl; - if (myCurrentList != null) { + if (myCurrentList != null && myCurrentList != UNSPECIFIED_LIST) { baseUrl = TRELLO_API_BASE_URL + "/lists/" + myCurrentList.getId() + "/cards"; fromList = true; } - else if (myCurrentBoard != null) { + else if (myCurrentBoard != null && myCurrentBoard != UNSPECIFIED_BOARD) { baseUrl = TRELLO_API_BASE_URL + "/boards/" + myCurrentBoard.getId() + "/cards"; } else if (myCurrentUser != null) { @@ -288,10 +303,10 @@ public final class TrelloRepository extends BaseRepositoryImpl { // reflects only the card state and doesn't show state of parental list and board. // NOTE: According to Trello REST API "filter=visible" parameter may be used only when fetching cards for // particular board or user. - String visibleCardsUrl = baseUrl + "?filter=visible&fields=none"; - List visibleCards = makeRequestAndDeserializeJsonResponse(visibleCardsUrl, TrelloUtil.LIST_OF_CARDS_TYPE); + final String visibleCardsUrl = baseUrl + "?filter=visible&fields=none"; + final List visibleCards = makeRequestAndDeserializeJsonResponse(visibleCardsUrl, TrelloUtil.LIST_OF_CARDS_TYPE); LOG.debug("Total " + visibleCards.size() + " visible cards"); - Set visibleCardsIDs = ContainerUtil.map2Set(visibleCards, new Function() { + final Set visibleCardsIDs = ContainerUtil.map2Set(visibleCards, new Function() { @Override public String fun(TrelloCard card) { return card.getId(); @@ -309,18 +324,18 @@ public final class TrelloRepository extends BaseRepositoryImpl { */ @NotNull private String makeRequest(@NotNull String url) throws Exception { - HttpMethod method = new GetMethod(url); + final HttpMethod method = new GetMethod(url); configureHttpMethod(method); return executeMethod(method); } @NotNull private String executeMethod(@NotNull HttpMethod method) throws Exception { - HttpClient client = getHttpClient(); + final HttpClient client = getHttpClient(); client.executeMethod(method); - String entityContent = ResponseUtil.getResponseContentAsString(method); + final String entityContent = ResponseUtil.getResponseContentAsString(method); if (method.getStatusCode() != HttpStatus.SC_OK) { - Header header = method.getResponseHeader("Content-Type"); + final Header header = method.getResponseHeader("Content-Type"); if (header != null && header.getValue().startsWith("text/plain")) { throw new Exception(TaskBundle.message("failure.server.message", StringUtil.capitalize(entityContent))); } @@ -331,7 +346,7 @@ public final class TrelloRepository extends BaseRepositoryImpl { @NotNull private T makeRequestAndDeserializeJsonResponse(@NotNull String url, @NotNull Type type) throws Exception { - String entityStream = makeRequest(url); + final String entityStream = makeRequest(url); // javac 1.6.0_23 bug workaround // TrelloRepository.java:286: type parameters of T cannot be determined; no unique maximal instance exists for type variable T with upper bounds T,java.lang.Object //noinspection unchecked @@ -340,17 +355,17 @@ public final class TrelloRepository extends BaseRepositoryImpl { @NotNull private T makeRequestAndDeserializeJsonResponse(@NotNull String url, @NotNull Class cls) throws Exception { - String entityStream = makeRequest(url); + final String entityStream = makeRequest(url); return TrelloUtil.GSON.fromJson(entityStream, cls); } @Override public String getPresentableName() { String pseudoUrl = "trello.com"; - if (myCurrentBoard != null) { + if (myCurrentBoard != null && myCurrentBoard != UNSPECIFIED_BOARD) { pseudoUrl += "/" + myCurrentBoard.getName(); } - if (myCurrentList != null) { + if (myCurrentList != null && myCurrentList != UNSPECIFIED_LIST) { pseudoUrl += "/" + myCurrentList.getName(); } return pseudoUrl; @@ -367,7 +382,7 @@ public final class TrelloRepository extends BaseRepositoryImpl { @Nullable @Override public CancellableConnection createCancellableConnection() { - GetMethod method = new GetMethod(TRELLO_API_BASE_URL + "/members/me/cards?limit=1"); + final GetMethod method = new GetMethod(TRELLO_API_BASE_URL + "/members/me/cards?limit=1"); configureHttpMethod(method); return new HttpTestConnection(method) { @Override diff --git a/plugins/tasks/tasks-core/src/com/intellij/tasks/trello/TrelloRepositoryEditor.java b/plugins/tasks/tasks-core/src/com/intellij/tasks/trello/TrelloRepositoryEditor.java index 3ad4b12de380..0ea5905cbcb2 100644 --- a/plugins/tasks/tasks-core/src/com/intellij/tasks/trello/TrelloRepositoryEditor.java +++ b/plugins/tasks/tasks-core/src/com/intellij/tasks/trello/TrelloRepositoryEditor.java @@ -16,20 +16,20 @@ package com.intellij.tasks.trello; -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.ComboBox; import com.intellij.tasks.config.BaseRepositoryEditor; +import com.intellij.tasks.impl.TaskUiUtil; import com.intellij.tasks.trello.model.TrelloBoard; import com.intellij.tasks.trello.model.TrelloList; import com.intellij.ui.DocumentAdapter; -import com.intellij.ui.ListCellRendererWrapper; import com.intellij.ui.components.JBCheckBox; import com.intellij.ui.components.JBLabel; import com.intellij.util.Consumer; import com.intellij.util.ui.FormBuilder; +import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -45,22 +45,6 @@ import java.util.List; public class TrelloRepositoryEditor extends BaseRepositoryEditor { private static final Logger LOG = Logger.getInstance(TrelloRepositoryEditor.class); - private static final TrelloBoard UNSPECIFIED_BOARD = new TrelloBoard() { - @NotNull - @Override - public String getName() { - return "-- from all boards --"; - } - }; - - private final static TrelloList UNSPECIFIED_LIST = new TrelloList() { - @NotNull - @Override - public String getName() { - return "-- from all lists --"; - } - }; - private ComboBox myBoardComboBox; private ComboBox myListComboBox; private JBLabel myListLabel; @@ -82,19 +66,19 @@ public class TrelloRepositoryEditor extends BaseRepositoryEditor download() throws Exception { + @NotNull + protected List fetch(@NotNull ProgressIndicator indicator) throws Exception { myRepository.setCurrentUser(myRepository.fetchUserByToken()); - return super.download(); + return super.fetch(indicator); } - }.runOnPooledThread(); + }.queue(); doApply(); } }); @@ -102,13 +86,19 @@ public class TrelloRepositoryEditor extends BaseRepositoryEditor("Set token first") { + @NotNull + @Override + protected String getDescription(@NotNull TrelloBoard board) { + return board.isClosed() ? board.getName() + " (closed)" : board.getName(); + } + }); myListComboBox.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { // only selection event is considered if (e.getStateChange() == ItemEvent.SELECTED) { - TrelloList list = (TrelloList)e.getItem(); - myRepository.setCurrentList(list != UNSPECIFIED_LIST ? list : null); + final TrelloList list = (TrelloList)e.getItem(); + myRepository.setCurrentList(list); doApply(); } } }); - myListComboBox.setRenderer(new TrelloListRenderer("Select board first")); - - // Initial setup: - if (myRepository.getCurrentUser() != null) { - new BoardsDownloader(myRepository.getCurrentBoard()) { - @Override - protected List download() throws Exception { - LOG.debug("Updating information about boards available to user when repository setting are shown"); - List boards = super.download(); - if (myBoard == null) { - return boards; - } - int i = boards.indexOf(myBoard); - // update information about selected board - // if it's open and thus downloaded with other boards of user, take info from there, - // otherwise issue a separate request - myBoard = i >= 0 ? boards.get(i) : myRepository.fetchBoardById(myBoard.getId()); - myRepository.setCurrentBoard(myBoard); - return boards; + myListComboBox.setRenderer(new TaskUiUtil.SimpleComboBoxRenderer("Select board first") { + @NotNull + @Override + protected String getDescription(@NotNull TrelloList list) { + String text = list.getName(); + if (list.isClosed() && list.isMoved()) { + text += " (archived,moved)"; } - }.runOnPooledThread(); - } - - if (myRepository.getCurrentBoard() != null) { - new ListsDownloader(myRepository.getCurrentList()) { - @Override - protected List download() throws Exception { - LOG.debug("Updating information about lists of board " + myRepository.getCurrentBoard() + " when repository setting are shown"); - List lists = super.download(); - if (myList == null) { - return lists; - } - int i = lists.indexOf(myList); - myList = i >= 0 ? lists.get(i) : myRepository.fetchListById(myList.getId()); - TrelloBoard currentBoard = myRepository.getCurrentBoard(); - if (currentBoard != null && !myList.getIdBoard().equals(currentBoard.getId())) { - myList.setMoved(true); - } - myRepository.setCurrentList(myList); - return lists; + else if (list.isMoved()) { + text += " (moved)"; } - }.runOnPooledThread(); - } + else if (list.isClosed()) { + text += " (archived)"; + } + return text; + } + }); installListener(myAllCardsCheckBox); + + UIUtil.invokeLaterIfNeeded(new Runnable() { + public void run() { + initialize(); + } + }); + } + + private void initialize() { + if (myRepository.getCurrentUser() != null) { + new BoardsComboBoxUpdater() { + @Override + @NotNull + protected List fetch(@NotNull ProgressIndicator indicator) throws Exception { + final List boards = super.fetch(indicator); + TrelloBoard currentBoard = getSelectedItem(); + if (currentBoard != null && currentBoard != TrelloRepository.UNSPECIFIED_BOARD) { + final int i = boards.indexOf(currentBoard); + // update information about selected board + // if it's open and thus downloaded with other boards of user, take info from there, + // otherwise issue a separate request + currentBoard = i >= 0 ? boards.get(i) : myRepository.fetchBoardById(currentBoard.getId()); + myRepository.setCurrentBoard(currentBoard); + } + return boards; + } + }.queue(); + } + + if (myRepository.getCurrentBoard() != null && myRepository.getCurrentBoard() != TrelloRepository.UNSPECIFIED_BOARD) { + new ListsComboBoxUpdater() { + @Override + @NotNull + protected List fetch(@NotNull ProgressIndicator indicator) throws Exception { + final List lists = super.fetch(indicator); + TrelloList currentList = myRepository.getCurrentList(); + if (currentList != null && currentList != TrelloRepository.UNSPECIFIED_LIST) { + final int i = lists.indexOf(currentList); + currentList = i >= 0 ? lists.get(i) : myRepository.fetchListById(currentList.getId()); + final TrelloBoard currentBoard = myRepository.getCurrentBoard(); + if (currentBoard != null && !currentList.getIdBoard().equals(currentBoard.getId())) { + currentList.setMoved(true); + } + myRepository.setCurrentList(currentList); + } + return lists; + } + }.queue(); + } } @Nullable @@ -213,152 +232,57 @@ public class TrelloRepositoryEditor extends BaseRepositoryEditor implements Runnable { - - private final ModalityState myModalityState = ModalityState.current(); - - protected abstract T download() throws Exception; - - protected void updateUI(T result) { - // empty - } - - protected void handleException(Exception e) { - // empty + private class BoardsComboBoxUpdater extends TaskUiUtil.ComboBoxUpdater { + public BoardsComboBoxUpdater() { + super(TrelloRepositoryEditor.this.myProject, "Downloading Trello boards...", myBoardComboBox); } + @NotNull @Override - public void run() { - try { - final T result; - synchronized (myRepository) { - result = download(); - } - ApplicationManager.getApplication().invokeLater(new Runnable() { - @Override - public void run() { - updateUI(result); - } - }, myModalityState); - } - catch (final Exception e) { - LOG.warn(e); - ApplicationManager.getApplication().invokeLater(new Runnable() { - @Override - public void run() { - handleException(e); - } - }, myModalityState); - } - } - - public void runOnPooledThread() { - ApplicationManager.getApplication().executeOnPooledThread(this); - } - } - - private class BoardsDownloader extends Downloader> { - protected TrelloBoard myBoard; - - private BoardsDownloader(TrelloBoard selectedBoard) { - myBoard = selectedBoard; - } - - @Override - protected List download() throws Exception { + protected List fetch(@NotNull ProgressIndicator indicator) throws Exception { return myRepository.fetchUserBoards(); } - @SuppressWarnings("unchecked") + @Nullable @Override - protected void updateUI(List boards) { - myBoardComboBox.setModel(new DefaultComboBoxModel(boards.toArray())); - myBoardComboBox.insertItemAt(UNSPECIFIED_BOARD, 0); - // explicitly add missing closed board - if (!(myBoard == null || myBoard == UNSPECIFIED_BOARD) && !boards.contains(myBoard)) { - myBoardComboBox.addItem(myBoard); - } - myBoardComboBox.setSelectedItem(myBoard == null ? UNSPECIFIED_BOARD : myBoard); + public TrelloBoard getExtraItem() { + return TrelloRepository.UNSPECIFIED_BOARD; + } + + @Nullable + @Override + public TrelloBoard getSelectedItem() { + return myRepository.getCurrentBoard(); } @Override - protected void handleException(Exception e) { - myBoardComboBox.removeAllItems(); + protected void handleError() { + super.handleError(); myListComboBox.removeAllItems(); } } - private class ListsDownloader extends Downloader> { - protected TrelloList myList; - - private ListsDownloader(TrelloList selectedList) { - this.myList = selectedList; + private class ListsComboBoxUpdater extends TaskUiUtil.ComboBoxUpdater { + public ListsComboBoxUpdater() { + super(TrelloRepositoryEditor.this.myProject, "Downloading Trello lists...", myListComboBox); } + @NotNull @Override - protected List download() throws Exception { + protected List fetch(@NotNull ProgressIndicator indicator) throws Exception { return myRepository.fetchBoardLists(); } - @SuppressWarnings("unchecked") + @Nullable @Override - protected void updateUI(List lists) { - myListComboBox.setModel(new DefaultComboBoxModel(lists.toArray())); - myListComboBox.insertItemAt(UNSPECIFIED_LIST, 0); - // explicitly add moved or archived list to combobox: see IDEA-111819 for details - if (!(myList == null || myList == UNSPECIFIED_LIST) && !lists.contains(myList)) { - myListComboBox.addItem(myList); - } - myListComboBox.setSelectedItem(myList == null ? UNSPECIFIED_LIST : myList); + public TrelloList getExtraItem() { + return TrelloRepository.UNSPECIFIED_LIST; } + @Nullable @Override - protected void handleException(Exception e) { - myListComboBox.removeAllItems(); - } - } - - private static class TrelloBoardRenderer extends ListCellRendererWrapper { - private String myNullDescription; - - private TrelloBoardRenderer(String nullDescription) { - this.myNullDescription = nullDescription; - } - - @Override - public void customize(JList list, TrelloBoard board, int index, boolean selected, boolean hasFocus) { - if (board == null) { - setText(myNullDescription); - return; - } - setText(board.isClosed() ? board.getName() + " (closed)" : board.getName()); - } - } - - private static class TrelloListRenderer extends ListCellRendererWrapper { - private String myNullDescription; - - private TrelloListRenderer(String nullDescription) { - this.myNullDescription = nullDescription; - } - - @Override - public void customize(JList list, TrelloList trelloList, int index, boolean selected, boolean hasFocus) { - if (trelloList == null) { - setText(myNullDescription); - return; - } - String text = trelloList.getName(); - if (trelloList.isClosed() && trelloList.isMoved()) { - text += " (archived,moved)"; - } - else if (trelloList.isMoved()) { - text += " (moved)"; - } - else if (trelloList.isClosed()) { - text += " (archived)"; - } - setText(text); + public TrelloList getSelectedItem() { + return myRepository.getCurrentList(); } } } diff --git a/plugins/tasks/tasks-core/src/com/intellij/tasks/trello/model/TrelloList.java b/plugins/tasks/tasks-core/src/com/intellij/tasks/trello/model/TrelloList.java index 3f6b0d0fd941..8216ef6902ea 100644 --- a/plugins/tasks/tasks-core/src/com/intellij/tasks/trello/model/TrelloList.java +++ b/plugins/tasks/tasks-core/src/com/intellij/tasks/trello/model/TrelloList.java @@ -18,6 +18,7 @@ package com.intellij.tasks.trello.model; import com.intellij.util.xmlb.annotations.Attribute; import com.intellij.util.xmlb.annotations.Tag; +import com.intellij.util.xmlb.annotations.Transient; import org.jetbrains.annotations.NotNull; /** @@ -73,6 +74,7 @@ public class TrelloList extends TrelloModel { this.name = name; } + @Transient public boolean isMoved() { return myMoved; }