Skip to content

Commit

Permalink
empty state for bundles
Browse files Browse the repository at this point in the history
  • Loading branch information
yevheniyJ committed Feb 12, 2024
1 parent 375cf56 commit c7db96f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 42 deletions.
58 changes: 37 additions & 21 deletions src/main/java/com/crowdin/ui/panel/download/DownloadWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;
import javax.swing.tree.TreeSelectionModel;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.List;
Expand All @@ -33,33 +34,35 @@ public class DownloadWindow implements ContentTab {
private boolean isBundlesMode = false;
private DefaultMutableTreeNode selectedElement;
private final JBLabel placeholder = new JBLabel("Tree loading", SwingConstants.CENTER);
private final JBLabel placeholder2 = new JBLabel("", SwingConstants.CENTER);

private final JPanel placeholderPanel = new JPanel(new BorderLayout());

private String link;

public DownloadWindow() {
this.placeholder.setComponentStyle(UIUtil.ComponentStyle.LARGE);
this.placeholder2.setComponentStyle(UIUtil.ComponentStyle.LARGE);
this.placeholder2.setCursor(new Cursor(Cursor.HAND_CURSOR));
this.placeholder2.setForeground(new Color(0, 102, 204));
this.placeholderPanel.add(placeholder, BorderLayout.CENTER);
this.placeholderPanel.add(placeholder2, BorderLayout.PAGE_END);

this.panel = FormBuilder
.createFormBuilder()
.addComponent(placeholder)
.addComponent(placeholderPanel)
.addComponent(new JBScrollPane(tree))
.getPanel();

this.tree.setCellRenderer(new CellRenderer());
this.tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
this.tree.setVisible(false);

this.tree.addMouseListener(new MouseAdapter() {
this.placeholder2.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
int selRow = tree.getRowForLocation(e.getX(), e.getY());
TreePath selPath = tree.getPathForLocation(e.getX(), e.getY());
if (selRow != -1) {
if (e.getClickCount() == 2) {
Optional
.ofNullable(selPath.getLastPathComponent())
.filter(DefaultMutableTreeNode.class::isInstance)
.map(CellRenderer::getData)
.filter(CellData::isLink)
.ifPresent(cell -> BrowserUtil.browse(cell.getLink()));
}
if (link != null) {
BrowserUtil.browse(link);
}
}
});
Expand Down Expand Up @@ -103,15 +106,19 @@ public List<String> getSelectedFiles() {
}

public void rebuildFileTree(String projectName, List<String> files) {
this.link = null;
this.isBundlesMode = false;
this.selectedElement = null;

if (files.isEmpty()) {
tree.setVisible(false);
placeholder.setText("No files found matching your configuration");
placeholder.setVisible(true);
this.tree.setVisible(false);
this.placeholder.setText("No files found matching your configuration");
this.placeholder2.setVisible(false);
this.placeholderPanel.setVisible(true);
return;
}
this.placeholder.setVisible(false);

this.placeholderPanel.setVisible(false);
this.tree.setVisible(true);

CrowdinPanelWindowFactory.updateToolbar(DOWNLOAD_SOURCES_ACTION, "Download Sources", true, true);
Expand All @@ -121,19 +128,28 @@ public void rebuildFileTree(String projectName, List<String> files) {
}

public void rebuildBundlesTree(String projectName, List<Bundle> bundles, String bundleInfoUrl) {
this.link = bundleInfoUrl;
this.isBundlesMode = true;
this.selectedElement = null;
this.placeholder.setVisible(false);

if (bundles.isEmpty()) {
this.tree.setVisible(false);
this.placeholder.setText("No bundles found.");
this.placeholder2.setText("Manage bundles.");
this.placeholder2.setVisible(true);
this.placeholder.setVisible(true);
this.placeholderPanel.setVisible(true);
return;
}

this.placeholderPanel.setVisible(false);
this.tree.setVisible(true);

CrowdinPanelWindowFactory.updateToolbar(DOWNLOAD_SOURCES_ACTION, "", false, false);
CrowdinPanelWindowFactory.updateToolbar(DOWNLOAD_TRANSLATIONS_ACTION, "Select bundle to download", true, false);

DefaultMutableTreeNode root = new DefaultMutableTreeNode(CellData.root(projectName));
bundles.forEach(bundle -> root.add(new DefaultMutableTreeNode(CellData.bundle(bundle))));
if (bundles.isEmpty()) {
root.add(new DefaultMutableTreeNode(CellData.link("Check how to create bundle", bundleInfoUrl)));
}
this.tree.setModel(new DefaultTreeModel(root));
expandAll();
}
Expand Down
26 changes: 5 additions & 21 deletions src/main/java/com/crowdin/ui/tree/CellData.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,14 @@ public class CellData {

private final boolean isRoot;

private final String link;

private final JBColor color;

public static CellData root(String text) {
return new CellData(true, text, LOGO, null, null, null, null);
return new CellData(true, text, LOGO, null, null, null);
}

public static CellData folder(String text) {
return new CellData(false, text, AllIcons.Nodes.Folder, null, null, null, null);
return new CellData(false, text, AllIcons.Nodes.Folder, null, null, null);
}

public static CellData file(String text, String file, boolean duplicate) {
Expand All @@ -51,24 +49,19 @@ public static CellData file(String text, String file, boolean duplicate) {
.filter(FILES_TYPES_ICONS::containsKey)
.map(FILES_TYPES_ICONS::get)
.orElse(AllIcons.FileTypes.Text);
return new CellData(false, text, icon, file, null, null, duplicate ? JBColor.RED : null);
return new CellData(false, text, icon, file, null, duplicate ? JBColor.RED : null);
}

public static CellData bundle(Bundle bundle) {
return new CellData(false, bundle.getName(), AllIcons.FileTypes.Archive, null, bundle, null, null);
}

public static CellData link(String text, String link) {
return new CellData(false, text, AllIcons.Ide.Link, null, null, link, null);
return new CellData(false, bundle.getName(), AllIcons.FileTypes.Archive, null, bundle, null);
}

private CellData(boolean isRoot, String text, Icon icon, String file, Bundle bundle, String link, JBColor color) {
private CellData(boolean isRoot, String text, Icon icon, String file, Bundle bundle, JBColor color) {
this.isRoot = isRoot;
this.text = text;
this.icon = icon;
this.file = file;
this.bundle = bundle;
this.link = link;
this.color = color;
}

Expand Down Expand Up @@ -104,14 +97,6 @@ public Bundle getBundle() {
return bundle;
}

public boolean isLink() {
return link != null;
}

public String getLink() {
return link;
}

@Override
public String toString() {
return "CellData{" +
Expand All @@ -120,7 +105,6 @@ public String toString() {
", file='" + file + '\'' +
", bundle=" + bundle +
", isRoot=" + isRoot +
", link='" + link + '\'' +
'}';
}
}

0 comments on commit c7db96f

Please sign in to comment.