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();
}
Aggregations