use of com.mucommander.commons.file.connection.ConnectionHandler in project mucommander by mucommander.
the class ShowServerConnectionsDialog method actionPerformed.
public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
// Disconnects the selected connection
if (source == disconnectButton) {
int selectedIndex = connectionList.getSelectedIndex();
if (selectedIndex >= 0 && selectedIndex < connections.size()) {
final ConnectionHandler connHandler = connections.get(selectedIndex);
// Close connection in a separate thread as I/O can lock.
// Todo: Add a confirmation dialog if the connection is active as it will stop whatever the connection is currently doing
new Thread() {
@Override
public void run() {
connHandler.closeConnection();
}
}.start();
// Remove connection from the list
connections.remove(selectedIndex);
connectionList.setSelectedIndex(Math.min(selectedIndex, connections.size()));
connectionList.repaint();
// Disable contextual butons if there are no more connections
if (connections.size() == 0) {
disconnectButton.setEnabled(false);
goToButton.setEnabled(false);
}
}
} else // Goes to the selected connection
if (source == goToButton) {
// Dispose the dialog first
dispose();
int selectedIndex = connectionList.getSelectedIndex();
if (selectedIndex >= 0 && selectedIndex < connections.size())
mainFrame.getActivePanel().tryChangeCurrentFolder(connections.get(selectedIndex).getRealm());
} else // Dispose the dialog
if (source == closeButton) {
dispose();
}
}
Aggregations