forked from fanruan/demo-tabledata-redis
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
123 lines
4.4 KiB
123 lines
4.4 KiB
package com.fr.plugin.db.redis.ui; |
|
|
|
import com.fr.design.border.UIRoundedBorder; |
|
import com.fr.design.constants.UIConstants; |
|
import com.fr.design.data.datapane.sqlpane.SQLEditPane; |
|
import com.fr.design.dialog.BasicPane; |
|
import com.fr.design.editor.ValueEditorPane; |
|
import com.fr.design.gui.ilable.ActionLabel; |
|
import com.fr.design.gui.ilable.UILabel; |
|
import com.fr.design.gui.itextarea.DescriptionTextArea; |
|
import com.fr.design.gui.syntax.ui.rsyntaxtextarea.RSyntaxTextArea; |
|
import com.fr.design.gui.syntax.ui.rsyntaxtextarea.SyntaxConstants; |
|
import com.fr.design.gui.syntax.ui.rtextarea.RTextScrollPane; |
|
import com.fr.design.i18n.Toolkit; |
|
import com.fr.design.layout.TableLayout; |
|
import com.fr.design.layout.TableLayoutHelper; |
|
import com.fr.design.utils.gui.GUICoreUtils; |
|
import com.fr.general.SiteCenter; |
|
import com.fr.log.FineLoggerFactory; |
|
import com.fr.plugin.db.redis.core.order.OrderValue; |
|
import com.fr.plugin.db.redis.ui.value.IndexValuePaneFactory; |
|
import ij.gui.MultiLineLabel; |
|
|
|
import java.awt.*; |
|
import java.awt.event.ActionEvent; |
|
import java.awt.event.ActionListener; |
|
import java.io.IOException; |
|
import java.net.URI; |
|
|
|
|
|
public class RedisQueryPane extends BasicPane { |
|
|
|
private SQLEditPane sqlTextPane; |
|
private ValueEditorPane dbIndexEditor; |
|
private RSyntaxTextArea scriptTextPane; |
|
|
|
public RedisQueryPane() { |
|
setLayout(new BorderLayout()); |
|
|
|
sqlTextPane = new SQLEditPane(); |
|
|
|
scriptTextPane = new RSyntaxTextArea(); |
|
|
|
dbIndexEditor = IndexValuePaneFactory.createValueEditorPane(); |
|
|
|
ActionLabel helpLabel = new ActionLabel(Toolkit.i18nText("Plugin-Redis_Help")); |
|
helpLabel.addActionListener(new ActionListener() { |
|
@Override |
|
public void actionPerformed(ActionEvent e) { |
|
try { |
|
Desktop.getDesktop().browse(URI.create(SiteCenter.getInstance().acquireUrlByKind("help.redis"))); |
|
} catch (IOException e1) { |
|
FineLoggerFactory.getLogger().error(e1.getMessage(), e1); |
|
} |
|
} |
|
}); |
|
|
|
DescriptionTextArea descriptionArea = new DescriptionTextArea(); |
|
descriptionArea.setWrapStyleWord(true); |
|
descriptionArea.setLineWrap(true); |
|
|
|
descriptionArea.setText(Toolkit.i18nText("Plugin-Redis_Script_Text_Description")); |
|
|
|
Component[][] coms = new Component[][]{ |
|
{new UILabel(Toolkit.i18nText("Plugin-Redis_DB_Index") + ":"), dbIndexEditor}, |
|
{GUICoreUtils.createBorderLayoutPane(new UILabel(Toolkit.i18nText("Plugin-Redis_Query_Condition") + ":"), BorderLayout.NORTH), createConditionTextPane(sqlTextPane, SyntaxConstants.SYNTAX_STYLE_SQL, 50)}, |
|
{GUICoreUtils.createBorderLayoutPane( |
|
new UILabel(Toolkit.i18nText("Plugin-Redis_Script_Text") + ":"), BorderLayout.NORTH), |
|
GUICoreUtils.createBorderLayoutPane( |
|
createConditionTextPane(scriptTextPane, SyntaxConstants.SYNTAX_STYLE_JAVASCRIPT, 200), BorderLayout.CENTER, |
|
descriptionArea, BorderLayout.SOUTH |
|
), |
|
|
|
}, |
|
}; |
|
|
|
double p = TableLayout.PREFERRED; |
|
double f = TableLayout.FILL; |
|
|
|
double[] rowSize = {p, p, p}; |
|
double[] columnSize = {p, f}; |
|
|
|
add(TableLayoutHelper.createTableLayoutPane(coms, rowSize, columnSize)); |
|
} |
|
|
|
private RTextScrollPane createConditionTextPane(RSyntaxTextArea editorPane, String type, int height) { |
|
editorPane.setSyntaxEditingStyle(type); |
|
RTextScrollPane sqlTextScrollPane = new RTextScrollPane(editorPane); |
|
sqlTextScrollPane.setBorder(new UIRoundedBorder(UIConstants.LINE_COLOR, 1, UIConstants.ARC)); |
|
sqlTextScrollPane.setPreferredSize(new Dimension(680, height)); |
|
sqlTextScrollPane.setLineNumbersEnabled(false); |
|
return sqlTextScrollPane; |
|
} |
|
|
|
@Override |
|
protected String title4PopupWindow() { |
|
return "Query"; |
|
} |
|
|
|
public String getQuery() { |
|
return sqlTextPane.getText(); |
|
} |
|
|
|
public void setQuery(String query) { |
|
sqlTextPane.setText(query); |
|
} |
|
|
|
public OrderValue getOrderValue() { |
|
return (OrderValue) dbIndexEditor.update(); |
|
} |
|
|
|
public void setOrderValue(OrderValue orderValue) { |
|
dbIndexEditor.populate(orderValue); |
|
} |
|
|
|
public String getScript() { |
|
return scriptTextPane.getText(); |
|
} |
|
|
|
public void setScript(String script) { |
|
scriptTextPane.setText(script); |
|
} |
|
} |