Search in sources :

Example 1 with WebQuerier

use of org.cytoscape.app.internal.net.WebQuerier in project cytoscape-impl by cytoscape.

the class InstallAppsPanel method installButtonActionPerformed.

private void installButtonActionPerformed(ActionEvent evt) {
    final WebQuerier webQuerier = appManager.getWebQuerier();
    taskManager.setExecutionContext(parent);
    taskManager.execute(new TaskIterator(new InstallAppsFromWebAppTask(Collections.singletonList(selectedApp), appManager, true)));
}
Also used : TaskIterator(org.cytoscape.work.TaskIterator) InstallAppsFromWebAppTask(org.cytoscape.app.internal.task.InstallAppsFromWebAppTask) WebQuerier(org.cytoscape.app.internal.net.WebQuerier)

Example 2 with WebQuerier

use of org.cytoscape.app.internal.net.WebQuerier in project cytoscape-impl by cytoscape.

the class InstallAppsPanel method initComponents.

private void initComponents() {
    searchAppsLabel = new JLabel("Search:");
    installFromFileButton = new JButton("Install from File...");
    filterTextField = new JTextField();
    descriptionSplitPane = new JSplitPane();
    tagsSplitPane = new JSplitPane();
    tagsScrollPane = new JScrollPane();
    tagsTree = new JTree();
    resultsScrollPane = new JScrollPane();
    resultsTree = new JTree();
    descriptionPanel = new JPanel();
    descriptionScrollPane = new JScrollPane();
    descriptionTextPane = new JTextPane();
    viewOnAppStoreButton = new JButton("View on App Store");
    installButton = new JButton("Install");
    downloadSiteLabel = new JLabel("Download Site:");
    downloadSiteComboBox = new JComboBox();
    manageSitesButton = new JButton("Manage Sites...");
    searchAppsLabel.setVisible(!LookAndFeelUtil.isAquaLAF());
    // Aqua LAF only
    filterTextField.putClientProperty("JTextField.variant", "search");
    filterTextField.setToolTipText("To search, start typing");
    installFromFileButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            installFromFileButtonActionPerformed(evt);
        }
    });
    descriptionSplitPane.setBorder(null);
    descriptionSplitPane.setDividerLocation(390);
    tagsSplitPane.setDividerLocation(175);
    tagsSplitPane.setBorder(null);
    DefaultMutableTreeNode treeNode1 = new DefaultMutableTreeNode("root");
    DefaultMutableTreeNode treeNode2 = new DefaultMutableTreeNode("all apps (0)");
    DefaultMutableTreeNode treeNode3 = new DefaultMutableTreeNode("collections (0)");
    DefaultMutableTreeNode treeNode4 = new DefaultMutableTreeNode("apps by tag");
    treeNode1.add(treeNode2);
    treeNode1.add(treeNode3);
    treeNode1.add(treeNode4);
    tagsTree.setModel(new DefaultTreeModel(treeNode1));
    tagsTree.setFocusable(false);
    tagsTree.setRootVisible(false);
    tagsTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tagsScrollPane.setViewportView(tagsTree);
    tagsSplitPane.setLeftComponent(tagsScrollPane);
    treeNode1 = new DefaultMutableTreeNode("root");
    resultsTree.setModel(new DefaultTreeModel(treeNode1));
    resultsTree.setFocusable(false);
    resultsTree.setRootVisible(false);
    resultsTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    resultsScrollPane.setViewportView(resultsTree);
    tagsSplitPane.setRightComponent(resultsScrollPane);
    descriptionSplitPane.setLeftComponent(tagsSplitPane);
    descriptionTextPane.setContentType("text/html");
    descriptionTextPane.setEditable(false);
    // descriptionTextPane.setText("<html>\n  <head>\n\n  </head>\n  <body>\n    <p style=\"margin-top: 0\">\n      App description is displayed here.\n    </p>\n  </body>\n</html>\n");
    descriptionTextPane.setText("");
    descriptionScrollPane.setViewportView(descriptionTextPane);
    final GroupLayout descriptionPanelLayout = new GroupLayout(descriptionPanel);
    descriptionPanel.setLayout(descriptionPanelLayout);
    descriptionPanelLayout.setHorizontalGroup(descriptionPanelLayout.createParallelGroup(Alignment.LEADING).addComponent(descriptionScrollPane, GroupLayout.DEFAULT_SIZE, 162, Short.MAX_VALUE));
    descriptionPanelLayout.setVerticalGroup(descriptionPanelLayout.createParallelGroup(Alignment.LEADING).addComponent(descriptionScrollPane, GroupLayout.DEFAULT_SIZE, 354, Short.MAX_VALUE));
    descriptionSplitPane.setRightComponent(descriptionPanel);
    viewOnAppStoreButton.setEnabled(false);
    viewOnAppStoreButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            viewOnAppStoreButtonActionPerformed(evt);
        }
    });
    installButton.setEnabled(false);
    installButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            installButtonActionPerformed(evt);
        }
    });
    downloadSiteComboBox.setModel(new DefaultComboBoxModel(new String[] { WebQuerier.DEFAULT_APP_STORE_URL }));
    downloadSiteComboBox.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent evt) {
            downloadSiteComboBoxItemStateChanged(evt);
        }
    });
    downloadSiteComboBox.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            downloadSiteComboBoxActionPerformed(evt);
        }
    });
    downloadSiteComboBox.addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent evt) {
            downloadSiteComboBoxKeyPressed(evt);
        }
    });
    manageSitesButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            manageSitesButtonActionPerformed(evt);
        }
    });
    LookAndFeelUtil.equalizeSize(installFromFileButton, viewOnAppStoreButton, installButton);
    final JSeparator sep = new JSeparator();
    final GroupLayout layout = new GroupLayout(this);
    this.setLayout(layout);
    layout.setAutoCreateContainerGaps(true);
    layout.setAutoCreateGaps(true);
    layout.setHorizontalGroup(layout.createParallelGroup(Alignment.LEADING).addGroup(layout.createSequentialGroup().addComponent(downloadSiteLabel).addComponent(downloadSiteComboBox, DEFAULT_SIZE, DEFAULT_SIZE, Short.MAX_VALUE).addComponent(manageSitesButton)).addComponent(sep, DEFAULT_SIZE, DEFAULT_SIZE, Short.MAX_VALUE).addGroup(layout.createSequentialGroup().addComponent(searchAppsLabel).addComponent(filterTextField, DEFAULT_SIZE, DEFAULT_SIZE, Short.MAX_VALUE)).addComponent(descriptionSplitPane).addGroup(layout.createSequentialGroup().addComponent(installFromFileButton).addPreferredGap(ComponentPlacement.RELATED, 80, Short.MAX_VALUE).addComponent(viewOnAppStoreButton).addComponent(installButton)));
    layout.setVerticalGroup(layout.createSequentialGroup().addGroup(layout.createParallelGroup(Alignment.BASELINE).addComponent(downloadSiteLabel).addComponent(downloadSiteComboBox, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE).addComponent(manageSitesButton, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE)).addComponent(sep, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE).addGroup(layout.createParallelGroup(Alignment.BASELINE).addComponent(searchAppsLabel).addComponent(filterTextField, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE)).addComponent(descriptionSplitPane, DEFAULT_SIZE, 360, Short.MAX_VALUE).addGroup(layout.createParallelGroup(Alignment.BASELINE).addComponent(installFromFileButton).addComponent(viewOnAppStoreButton).addComponent(installButton)));
    // Add a key listener to the download site combo box to listen for the enter key event
    final WebQuerier webQuerier = this.appManager.getWebQuerier();
    downloadSiteComboBox.getEditor().getEditorComponent().addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            final ComboBoxEditor editor = downloadSiteComboBox.getEditor();
            final Object selectedValue = editor.getItem();
            if (e.isActionKey() || e.getKeyCode() == KeyEvent.VK_ENTER) {
                if (downloadSiteComboBox.getModel() instanceof DefaultComboBoxModel && selectedValue != null) {
                    final DefaultComboBoxModel comboBoxModel = (DefaultComboBoxModel) downloadSiteComboBox.getModel();
                    SwingUtilities.invokeLater(new Runnable() {

                        @Override
                        public void run() {
                            boolean selectedAlreadyInList = false;
                            for (int i = 0; i < comboBoxModel.getSize(); i++) {
                                Object listElement = comboBoxModel.getElementAt(i);
                                if (listElement.equals(selectedValue)) {
                                    selectedAlreadyInList = true;
                                    break;
                                }
                            }
                            if (!selectedAlreadyInList) {
                                comboBoxModel.insertElementAt(selectedValue, 1);
                                editor.setItem(selectedValue);
                            }
                        }
                    });
                }
                if (webQuerier.getCurrentAppStoreUrl() != selectedValue.toString()) {
                    webQuerier.setCurrentAppStoreUrl(selectedValue.toString());
                    queryForApps();
                }
            }
        }
    });
    // Make the JTextPane render HTML using the default UI font
    Font font = UIManager.getFont("Label.font");
    String bodyRule = "body { font-family: " + font.getFamily() + "; " + "font-size: " + font.getSize() + "pt; }";
    ((HTMLDocument) descriptionTextPane.getDocument()).getStyleSheet().addRule(bodyRule);
    // Setup the TreeCellRenderer to make the app tags use the folder icon instead of the default leaf icon,
    // and have it use the opened folder icon when selected
    DefaultTreeCellRenderer tagsTreeCellRenderer = new DefaultTreeCellRenderer() {

        @Override
        public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
            super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
            // Make leaves use the open folder icon when selected
            if (selected && leaf)
                this.setIcon(getOpenIcon());
            return this;
        }
    };
    tagsTreeCellRenderer.setLeafIcon(tagsTreeCellRenderer.getDefaultClosedIcon());
    tagsTree.setCellRenderer(tagsTreeCellRenderer);
}
Also used : JPanel(javax.swing.JPanel) ItemEvent(java.awt.event.ItemEvent) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ActionEvent(java.awt.event.ActionEvent) KeyAdapter(java.awt.event.KeyAdapter) JButton(javax.swing.JButton) JTextField(javax.swing.JTextField) ComboBoxEditor(javax.swing.ComboBoxEditor) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer) JSeparator(javax.swing.JSeparator) Font(java.awt.Font) KeyEvent(java.awt.event.KeyEvent) JTextPane(javax.swing.JTextPane) GroupLayout(javax.swing.GroupLayout) JScrollPane(javax.swing.JScrollPane) JComboBox(javax.swing.JComboBox) JLabel(javax.swing.JLabel) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) JTree(javax.swing.JTree) ActionListener(java.awt.event.ActionListener) ItemListener(java.awt.event.ItemListener) JSplitPane(javax.swing.JSplitPane) WebQuerier(org.cytoscape.app.internal.net.WebQuerier)

Example 3 with WebQuerier

use of org.cytoscape.app.internal.net.WebQuerier in project cytoscape-impl by cytoscape.

the class InstallAppsPanel method queryForApps.

// Queries the currently set app store url for available apps.
private void queryForApps() {
    if (hasTagTreeBeenPopulated)
        return;
    final WebQuerier webQuerier = appManager.getWebQuerier();
    taskManager.execute(new TaskIterator(new Task() {

        // Obtain information for all available apps, then append tag information
        @Override
        public void run(TaskMonitor taskMonitor) throws Exception {
            taskMonitor.setTitle("Getting available apps");
            taskMonitor.setStatusMessage("Obtaining apps from: " + webQuerier.getCurrentAppStoreUrl());
            Set<WebApp> availableApps = webQuerier.getAllApps();
            if (availableApps == null)
                return;
            // Once the information is obtained, update the tree
            SwingUtilities.invokeLater(new Runnable() {

                @Override
                public void run() {
                    // populateTree(appManager.getWebQuerier().getAllApps());
                    buildTagsTree();
                    fillResultsTree(appManager.getWebQuerier().getAllApps());
                }
            });
        }

        @Override
        public void cancel() {
        }
    }));
}
Also used : Task(org.cytoscape.work.Task) InstallAppsFromFileTask(org.cytoscape.app.internal.task.InstallAppsFromFileTask) InstallAppsFromWebAppTask(org.cytoscape.app.internal.task.InstallAppsFromWebAppTask) ShowInstalledAppsIfChangedTask(org.cytoscape.app.internal.task.ShowInstalledAppsIfChangedTask) TaskIterator(org.cytoscape.work.TaskIterator) TaskMonitor(org.cytoscape.work.TaskMonitor) WebQuerier(org.cytoscape.app.internal.net.WebQuerier) WebApp(org.cytoscape.app.internal.net.WebApp)

Example 4 with WebQuerier

use of org.cytoscape.app.internal.net.WebQuerier in project cytoscape-impl by cytoscape.

the class InstallAppsPanel method buildTagsTree.

private void buildTagsTree() {
    WebQuerier webQuerier = appManager.getWebQuerier();
    // Get all available apps and tags
    Set<WebApp> availableApps = webQuerier.getAllApps();
    Set<WebQuerier.AppTag> availableTags = webQuerier.getAllTags();
    if (availableApps == null || availableTags == null)
        return;
    List<WebQuerier.AppTag> sortedTags = new LinkedList<WebQuerier.AppTag>(availableTags);
    Collections.sort(sortedTags, new Comparator<WebQuerier.AppTag>() {

        @Override
        public int compare(AppTag tag, AppTag other) {
            return other.getCount() - tag.getCount();
        }
    });
    DefaultMutableTreeNode root = new DefaultMutableTreeNode("root");
    DefaultMutableTreeNode allAppsTreeNode = new DefaultMutableTreeNode("all apps" + " (" + availableApps.size() + ")");
    root.add(allAppsTreeNode);
    DefaultMutableTreeNode collectionsTreeNode = new DefaultMutableTreeNode("collections (0)");
    DefaultMutableTreeNode appsByTagTreeNode = new DefaultMutableTreeNode("apps by tag");
    for (final WebQuerier.AppTag appTag : sortedTags) {
        if (appTag.getName().equals("collections"))
            collectionsTreeNode.setUserObject(appTag);
        else
            appsByTagTreeNode.add(new DefaultMutableTreeNode(appTag));
    }
    root.add(collectionsTreeNode);
    root.add(appsByTagTreeNode);
    tagsTree.setModel(new DefaultTreeModel(root));
    // tagsTree.expandRow(2);
    currentSelectedAppTag = null;
    hasTagTreeBeenPopulated = true;
}
Also used : AppTag(org.cytoscape.app.internal.net.WebQuerier.AppTag) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) AppTag(org.cytoscape.app.internal.net.WebQuerier.AppTag) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) WebQuerier(org.cytoscape.app.internal.net.WebQuerier) LinkedList(java.util.LinkedList) WebApp(org.cytoscape.app.internal.net.WebApp)

Example 5 with WebQuerier

use of org.cytoscape.app.internal.net.WebQuerier in project cytoscape-impl by cytoscape.

the class CheckForUpdatesPanel method checkUpdates.

private void checkUpdates() {
    final Set<App> appsToCheckUpdates = appManager.getInstalledApps();
    taskManager.execute(new TaskIterator(new Task() {

        @Override
        public void run(TaskMonitor taskMonitor) throws Exception {
            taskMonitor.setTitle("Checking for updates");
            WebQuerier webQuerier = appManager.getWebQuerier();
            String siteName, siteUrl;
            double progress = 0.0;
            // Obtain apps listing from each site if not done so
            for (DownloadSite downloadSite : downloadSitesManager.getDownloadSites()) {
                siteName = downloadSite.getSiteName();
                siteUrl = downloadSite.getSiteUrl();
                taskMonitor.setStatusMessage("Obtaining apps listing from " + siteName + "(" + siteUrl + ") ...");
                taskMonitor.setProgress(progress);
                progress += 1.0 / (downloadSitesManager.getDownloadSites().size() + 1);
                webQuerier.setCurrentAppStoreUrl(siteUrl);
                Set<WebApp> webApps = webQuerier.getAllApps();
            }
            taskMonitor.setStatusMessage("Reading listings for new versions");
            // We're 98% done.
            taskMonitor.setProgress(0.98);
            updateManager.checkForUpdates(appsToCheckUpdates);
        }

        @Override
        public void cancel() {
        // TODO Auto-generated method stub
        }
    }));
}
Also used : App(org.cytoscape.app.internal.manager.App) WebApp(org.cytoscape.app.internal.net.WebApp) Task(org.cytoscape.work.Task) InstallUpdatesTask(org.cytoscape.app.internal.task.InstallUpdatesTask) InstallAppsFromWebAppTask(org.cytoscape.app.internal.task.InstallAppsFromWebAppTask) ObservableTask(org.cytoscape.work.ObservableTask) TaskIterator(org.cytoscape.work.TaskIterator) TaskMonitor(org.cytoscape.work.TaskMonitor) DownloadSite(org.cytoscape.app.internal.ui.downloadsites.DownloadSite) WebQuerier(org.cytoscape.app.internal.net.WebQuerier) WebApp(org.cytoscape.app.internal.net.WebApp)

Aggregations

WebQuerier (org.cytoscape.app.internal.net.WebQuerier)7 WebApp (org.cytoscape.app.internal.net.WebApp)3 InstallAppsFromWebAppTask (org.cytoscape.app.internal.task.InstallAppsFromWebAppTask)3 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)2 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)2 App (org.cytoscape.app.internal.manager.App)2 TaskIterator (org.cytoscape.work.TaskIterator)2 Font (java.awt.Font)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 ItemEvent (java.awt.event.ItemEvent)1 ItemListener (java.awt.event.ItemListener)1 KeyAdapter (java.awt.event.KeyAdapter)1 KeyEvent (java.awt.event.KeyEvent)1 LinkedList (java.util.LinkedList)1 Properties (java.util.Properties)1 ComboBoxEditor (javax.swing.ComboBoxEditor)1 DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)1 GroupLayout (javax.swing.GroupLayout)1 JButton (javax.swing.JButton)1