Search in sources :

Example 1 with UpdatesChangedListener

use of org.cytoscape.app.internal.event.UpdatesChangedListener in project cytoscape-impl by cytoscape.

the class CheckForUpdatesPanel method initComponents.

private void initComponents() {
    updatesAvailableLabel = new JLabel("0 updates available.");
    installSelectedButton = new JButton("Update Selected");
    installAllButton = new JButton("Update All");
    updatesScrollPane = new JScrollPane();
    updatesTable = new JTable();
    lastCheckForUpdatesLabel = new JLabel("Last check for updates:");
    updateCheckTimeLabel = new JLabel("Today, at 6:00 pm");
    descriptionLabel = new JLabel("Update Description:");
    descriptionScrollPane = new JScrollPane();
    descriptionTextArea = new JTextArea();
    manageUpdateSites = new JButton("Manage Sites...");
    installSelectedButton.setEnabled(false);
    installSelectedButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            installUpdates(getSelectedUpdates());
        }
    });
    installAllButton.setEnabled(false);
    installAllButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            installUpdates(updateManager.getUpdates());
        }
    });
    updatesTable.setModel(new DefaultTableModel(new Object[][] {}, new String[] { "App Name", "Version" }) {

        boolean[] canEdit = new boolean[] { false, false };

        @Override
        public boolean isCellEditable(int rowIndex, int columnIndex) {
            return canEdit[columnIndex];
        }
    });
    updatesScrollPane.setViewportView(updatesTable);
    descriptionTextArea.setEditable(false);
    descriptionTextArea.setLineWrap(true);
    descriptionTextArea.setWrapStyleWord(true);
    descriptionTextArea.setFocusable(false);
    descriptionScrollPane.setViewportView(descriptionTextArea);
    manageUpdateSites.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            manageUpdateSitesActionPerformed(evt);
        }
    });
    LookAndFeelUtil.equalizeSize(installSelectedButton, installAllButton);
    final GroupLayout layout = new GroupLayout(this);
    setLayout(layout);
    layout.setAutoCreateContainerGaps(true);
    layout.setAutoCreateGaps(true);
    layout.setHorizontalGroup(layout.createParallelGroup(Alignment.LEADING).addGroup(layout.createSequentialGroup().addComponent(updatesAvailableLabel).addGap(10, 20, Short.MAX_VALUE).addComponent(lastCheckForUpdatesLabel).addComponent(updateCheckTimeLabel)).addComponent(updatesScrollPane, DEFAULT_SIZE, 652, Short.MAX_VALUE).addComponent(descriptionLabel).addComponent(descriptionScrollPane).addGroup(layout.createSequentialGroup().addComponent(installSelectedButton).addComponent(installAllButton).addGap(10, 20, Short.MAX_VALUE).addComponent(manageUpdateSites)));
    layout.setVerticalGroup(layout.createSequentialGroup().addGroup(layout.createParallelGroup(Alignment.CENTER, false).addComponent(updatesAvailableLabel).addComponent(lastCheckForUpdatesLabel).addComponent(updateCheckTimeLabel)).addComponent(updatesScrollPane, DEFAULT_SIZE, 327, Short.MAX_VALUE).addComponent(descriptionLabel, PREFERRED_SIZE, 16, PREFERRED_SIZE).addComponent(descriptionScrollPane, PREFERRED_SIZE, 106, PREFERRED_SIZE).addGroup(layout.createParallelGroup(Alignment.CENTER, false).addComponent(installSelectedButton).addComponent(installAllButton).addComponent(manageUpdateSites)));
    updateManager.addUpdatesChangedListener(new UpdatesChangedListener() {

        @Override
        public void updatesChanged(UpdatesChangedEvent event) {
            int updateCount = updateManager.getUpdates().size();
            updatesAvailableLabel.setText(updateCount + " " + (updateCount == 1 ? "update" : "updates") + " available.");
            Calendar lastUpdateCheckTime = updateManager.getLastUpdateCheckTime();
            int minute = lastUpdateCheckTime.get(Calendar.MINUTE);
            updateCheckTimeLabel.setText("Today, at " + (lastUpdateCheckTime.get(Calendar.HOUR) == 0 ? "12" : lastUpdateCheckTime.get(Calendar.HOUR)) + ":" + (minute < 10 ? "0" : "") + minute + " " + (lastUpdateCheckTime.get(Calendar.AM_PM) == Calendar.AM ? "am" : "pm"));
            repopulateUpdatesTable();
            // Enable/disable the update all button depending on update availability
            if (event.getSource().getUpdates().size() > 0) {
                if (!installAllButton.isEnabled()) {
                    installAllButton.setEnabled(true);
                }
            } else {
                if (installAllButton.isEnabled()) {
                    installAllButton.setEnabled(false);
                }
            }
        }
    });
    installAllButton.setEnabled(true);
    this.addComponentListener(new ComponentAdapter() {

        @Override
        public void componentShown(ComponentEvent e) {
            checkUpdates();
        }
    });
    setupDescriptionListener();
}
Also used : JScrollPane(javax.swing.JScrollPane) JTextArea(javax.swing.JTextArea) ActionEvent(java.awt.event.ActionEvent) DefaultTableModel(javax.swing.table.DefaultTableModel) Calendar(java.util.Calendar) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) UpdatesChangedListener(org.cytoscape.app.internal.event.UpdatesChangedListener) ActionListener(java.awt.event.ActionListener) UpdatesChangedEvent(org.cytoscape.app.internal.event.UpdatesChangedEvent) JTable(javax.swing.JTable) GroupLayout(javax.swing.GroupLayout) ComponentEvent(java.awt.event.ComponentEvent) ComponentAdapter(java.awt.event.ComponentAdapter)

Aggregations

ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 ComponentAdapter (java.awt.event.ComponentAdapter)1 ComponentEvent (java.awt.event.ComponentEvent)1 Calendar (java.util.Calendar)1 GroupLayout (javax.swing.GroupLayout)1 JButton (javax.swing.JButton)1 JLabel (javax.swing.JLabel)1 JScrollPane (javax.swing.JScrollPane)1 JTable (javax.swing.JTable)1 JTextArea (javax.swing.JTextArea)1 DefaultTableModel (javax.swing.table.DefaultTableModel)1 UpdatesChangedEvent (org.cytoscape.app.internal.event.UpdatesChangedEvent)1 UpdatesChangedListener (org.cytoscape.app.internal.event.UpdatesChangedListener)1