|
|
|
package com.fr.plugin.db.redis.ui;
|
|
|
|
|
|
|
|
import com.fanruan.api.design.work.ConnectionComboBoxPanel;
|
|
|
|
import com.fr.data.impl.Connection;
|
|
|
|
import com.fr.data.operator.DataOperator;
|
|
|
|
import com.fanruan.api.design.ui.component.UIButton;
|
|
|
|
import com.fanruan.api.design.ui.component.UIPlaceholderTextField;
|
|
|
|
import com.fanruan.api.design.DesignKit;
|
|
|
|
import com.fanruan.api.data.ConnectionKit;
|
|
|
|
import com.fr.plugin.db.redis.core.RedisDatabaseConnection;
|
|
|
|
import com.fr.plugin.db.redis.ui.event.DataLoadedListener;
|
|
|
|
import com.fanruan.api.util.ArrayKit;
|
|
|
|
import com.fanruan.api.util.StringKit;
|
|
|
|
import com.fanruan.api.log.LogKit;
|
|
|
|
import com.fanruan.api.design.ui.container.BasicPane;
|
|
|
|
import com.fanruan.api.design.util.GUICoreKit;
|
|
|
|
|
|
|
|
import javax.swing.*;
|
|
|
|
import java.awt.*;
|
|
|
|
import java.awt.event.ActionEvent;
|
|
|
|
import java.awt.event.ActionListener;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
public class RedisDBConnectionChosePane extends BasicPane {
|
|
|
|
|
|
|
|
private ConnectionComboBoxPanel connectionComboBoxPanel;
|
|
|
|
private DefaultListModel listModel = new DefaultListModel();
|
|
|
|
private List<DataLoadedListener> listeners = new ArrayList<DataLoadedListener>();
|
|
|
|
private UIPlaceholderTextField keysPatternTextField;
|
|
|
|
|
|
|
|
public RedisDBConnectionChosePane() {
|
|
|
|
setLayout(new BorderLayout(4, 4));
|
|
|
|
connectionComboBoxPanel = new ConnectionComboBoxPanel(Connection.class) {
|
|
|
|
|
|
|
|
protected void filterConnection(Connection connection, String conName, List<String> nameList) {
|
|
|
|
connection.addConnection(nameList, conName, new Class[]{RedisDatabaseConnection.class});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
add(connectionComboBoxPanel, BorderLayout.NORTH);
|
|
|
|
connectionComboBoxPanel.addComboBoxActionListener(new ActionListener() {
|
|
|
|
@Override
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
|
loadKeys();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
JList list = new JList(listModel);
|
|
|
|
|
|
|
|
keysPatternTextField = new UIPlaceholderTextField(10);
|
|
|
|
keysPatternTextField.setPlaceholder(DesignKit.i18nText("Plugin-Redis_Keys_Pattern"));
|
|
|
|
|
|
|
|
JPanel centerPane = new JPanel(new BorderLayout());
|
|
|
|
|
|
|
|
UIButton searchButton = new UIButton(DesignKit.i18nText("Plugin-Redis_Keys_Pattern_Search"));
|
|
|
|
searchButton.addActionListener(new ActionListener() {
|
|
|
|
@Override
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
|
loadKeys();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
centerPane.add(GUICoreKit.createBorderLayoutPane(
|
|
|
|
keysPatternTextField, BorderLayout.CENTER,
|
|
|
|
searchButton, BorderLayout.EAST), BorderLayout.NORTH);
|
|
|
|
|
|
|
|
centerPane.add(list, BorderLayout.CENTER);
|
|
|
|
|
|
|
|
add(centerPane, BorderLayout.CENTER);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void loadKeys() {
|
|
|
|
String name = getSelectRedisConnectionName();
|
|
|
|
if (StringKit.isEmpty(name)) {
|
|
|
|
clearList();
|
|
|
|
fireDataLoaded(ArrayKit.EMPTY_STRING_ARRAY);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
RedisDatabaseConnection connection = ConnectionKit.getConnection(name, RedisDatabaseConnection.class);
|
|
|
|
if (connection != null) {
|
|
|
|
listMatchedPatternKeys(connection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void clearList() {
|
|
|
|
listModel.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void listMatchedPatternKeys(final RedisDatabaseConnection connection) {
|
|
|
|
clearList();
|
|
|
|
new SwingWorker<String[], Void>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected String[] doInBackground() throws Exception {
|
|
|
|
String keysPattern = keysPatternTextField.getText();
|
|
|
|
if (StringKit.isEmpty(keysPattern)) {
|
|
|
|
return ArrayKit.EMPTY_STRING_ARRAY;
|
|
|
|
} else {
|
|
|
|
return DataOperator.getInstance().getTableSummary(connection, keysPattern);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void done() {
|
|
|
|
try {
|
|
|
|
String[] keys = get();
|
|
|
|
for (String name : keys) {
|
|
|
|
listModel.addElement(name);
|
|
|
|
}
|
|
|
|
fireDataLoaded(keys);
|
|
|
|
} catch (Exception e) {
|
|
|
|
LogKit.error(e.getMessage(), e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}.execute();
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getSelectRedisConnectionName() {
|
|
|
|
return connectionComboBoxPanel.getSelectedItem();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void populateConnection(Connection connection) {
|
|
|
|
connectionComboBoxPanel.populate(connection);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void addDataLoadedListener(DataLoadedListener listener) {
|
|
|
|
listeners.add(listener);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void fireDataLoaded(String[] data) {
|
|
|
|
for (DataLoadedListener listener : listeners) {
|
|
|
|
listener.fireEvent(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected String title4PopupWindow() {
|
|
|
|
return "Choose";
|
|
|
|
}
|
|
|
|
}
|