Skip to content

Commit

Permalink
#537 Choose right language for news
Browse files Browse the repository at this point in the history
  • Loading branch information
jaakkonakaza committed Nov 12, 2021
1 parent 7b12f04 commit 71e4ca8
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ private static BannerView createBannerView(@NotNull Project project,
@NotNull JComponent bottomComponent) {
var bannerView = new BannerView(bottomComponent);

var mainViewModel =PluginSettings.getInstance()
var mainViewModel = PluginSettings.getInstance()
.getMainViewModel(project);
mainViewModel.bannerViewModel
mainViewModel.bannerViewModel
.addValueObserver(bannerView, BannerView::viewModelChanged);

return bannerView;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package fi.aalto.cs.apluscourses.presentation.news;

import static fi.aalto.cs.apluscourses.utils.PluginResourceBundle.getText;

import fi.aalto.cs.apluscourses.model.NewsTree;
import fi.aalto.cs.apluscourses.presentation.MainViewModel;
import fi.aalto.cs.apluscourses.presentation.base.BaseTreeViewModel;
Expand All @@ -18,4 +20,10 @@ public NewsTreeViewModel(@NotNull NewsTree newsTree, @NotNull MainViewModel main
.map(news -> new NewsTitleViewModel(news, mainViewModel))
.collect(Collectors.toList()));
}

@NotNull
public String getTitle() {
var unread = getModel().getNews().stream().filter(news -> !news.isRead()).count();
return getText("ui.toolWindow.subTab.news.name") + ((unread > 0) ? " [" + unread + " unread]" : "");
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fi.aalto.cs.apluscourses.ui.exercise;

import static fi.aalto.cs.apluscourses.utils.PluginResourceBundle.getText;
import static fi.aalto.cs.apluscourses.utils.TreeRendererUtil.isIrrelevantNode;

import com.intellij.ui.ColoredTreeCellRenderer;
import com.intellij.ui.SimpleTextAttributes;
Expand All @@ -12,7 +13,6 @@
import icons.PluginIcons;
import javax.swing.Icon;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import org.jetbrains.annotations.NotNull;

public class ExercisesTreeRenderer extends ColoredTreeCellRenderer {
Expand Down Expand Up @@ -91,18 +91,4 @@ public void customizeCellRenderer(@NotNull JTree tree,
setToolTipText(getText("ui.exercise.ExercisesTreeRenderer.doubleClickToOpenBrowser"));
}
}

/**
* Sometimes {@code customizeCellRenderer} is called with a value
* that is just some placeholder object for tree root.
* This method recognizes such cases.
*
* @param value A parameter passed to {@code customizeCellRenderer}
* @return True, if node is irrelevant and should be ignored, otherwise false.
*/
private boolean isIrrelevantNode(Object value) {
// That irrelevant root has no parent
return value instanceof DefaultMutableTreeNode
&& ((DefaultMutableTreeNode) value).getParent() == null;
}
}
3 changes: 1 addition & 2 deletions src/main/java/fi/aalto/cs/apluscourses/ui/news/NewsView.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ public void viewModelChanged(@Nullable NewsTreeViewModel viewModel) {
return;
}

var unread = viewModel.getModel().getNews().stream().filter(news -> !news.isRead()).count();
title.setText(getTitle() + ((unread > 0) ? " [" + unread + " unread]" : ""));
title.setText(viewModel.getTitle());

}, ModalityState.any()
);
Expand Down

0 comments on commit 71e4ca8

Please sign in to comment.