diff --git a/src/main/java/com/crowdin/ui/panel/download/DownloadWindow.java b/src/main/java/com/crowdin/ui/panel/download/DownloadWindow.java index 0f66a12..9177edd 100644 --- a/src/main/java/com/crowdin/ui/panel/download/DownloadWindow.java +++ b/src/main/java/com/crowdin/ui/panel/download/DownloadWindow.java @@ -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; @@ -33,12 +34,23 @@ 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(); @@ -46,20 +58,11 @@ public DownloadWindow() { 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); } } }); @@ -103,15 +106,19 @@ public List getSelectedFiles() { } public void rebuildFileTree(String projectName, List 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); @@ -121,9 +128,21 @@ public void rebuildFileTree(String projectName, List files) { } public void rebuildBundlesTree(String projectName, List 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); @@ -131,9 +150,6 @@ public void rebuildBundlesTree(String projectName, List bundles, String 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(); } diff --git a/src/main/java/com/crowdin/ui/tree/CellData.java b/src/main/java/com/crowdin/ui/tree/CellData.java index ce97fb6..81f74c7 100644 --- a/src/main/java/com/crowdin/ui/tree/CellData.java +++ b/src/main/java/com/crowdin/ui/tree/CellData.java @@ -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) { @@ -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; } @@ -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{" + @@ -120,7 +105,6 @@ public String toString() { ", file='" + file + '\'' + ", bundle=" + bundle + ", isRoot=" + isRoot + - ", link='" + link + '\'' + '}'; } }