Browse Source
* commit 'fb9d62e5300c2753c87c810e9412b09f512d3f50': REPORT-139288 feat: JNDI设计器入口和逻辑删除fbp/feature
superman
3 weeks ago
4 changed files with 12 additions and 319 deletions
@ -1,264 +0,0 @@
|
||||
package com.fr.design.data.datapane.connect; |
||||
|
||||
import java.awt.BorderLayout; |
||||
import java.awt.Dimension; |
||||
import java.awt.event.ActionEvent; |
||||
import java.awt.event.ActionListener; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
import java.util.Properties; |
||||
|
||||
import javax.naming.Context; |
||||
import javax.swing.JDialog; |
||||
|
||||
import com.fine.theme.utils.FineUIScale; |
||||
import com.formdev.flatlaf.util.ScaledEmptyBorder; |
||||
import com.fr.design.constants.LayoutConstants; |
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import javax.swing.JPanel; |
||||
import javax.swing.JScrollPane; |
||||
import javax.swing.SwingUtilities; |
||||
|
||||
import com.fr.data.impl.JNDIDatabaseConnection; |
||||
import com.fr.design.gui.icombobox.UIComboBox; |
||||
import com.fr.design.gui.itextfield.UITextField; |
||||
import com.fr.design.gui.ilable.ActionLabel; |
||||
import com.fr.design.gui.ilable.FRExplainLabel; |
||||
import com.fr.design.layout.FRGUIPaneFactory; |
||||
import com.fr.design.dialog.BasicPane; |
||||
import com.fr.general.ComparatorUtils; |
||||
|
||||
import com.fr.stable.StringUtils; |
||||
|
||||
import static com.fine.swing.ui.layout.Layouts.cell; |
||||
import static com.fine.swing.ui.layout.Layouts.column; |
||||
import static com.fine.swing.ui.layout.Layouts.row; |
||||
import static com.fine.theme.utils.FineUIUtils.wrapComponentWithTitle; |
||||
|
||||
public class JNDIDefPane extends JPanel { |
||||
private static Map<String, String> jndiMap = new HashMap<String, String>(); |
||||
|
||||
static { |
||||
jndiMap.put("weblogic.jndi.WLInitialContextFactory", "t3://localhost:7001"); |
||||
jndiMap.put("com.ibm.websphere.naming.WsnInitialContextFactory", "iiop://localhost:2809"); |
||||
jndiMap.put("org.jboss.naming.HttpNamingContextFactory", "http://jboss_server_address:8080/invoker/JNDIFactory"); |
||||
jndiMap.put("org.jnp.interfaces.NamingContextFactory", "localhost:1099"); |
||||
jndiMap.put("com.caucho.burlap.BurlapContextFactory", "http://localhost:8080/hello/burlap"); |
||||
} |
||||
|
||||
private UITextField jndiNameTextField; |
||||
|
||||
private UIComboBox JNDIFactoryComboBox; |
||||
private ContextTextField PROVIDER_URL_TF = new ContextTextField(Context.PROVIDER_URL); |
||||
private ContextTextField SECURITY_PRINCIPAL_TF = new ContextTextField(Context.SECURITY_PRINCIPAL); |
||||
private ContextTextField SECURITY_CREDENTIALS_TF = new ContextTextField(Context.SECURITY_CREDENTIALS); |
||||
|
||||
private ContextTextField OBJECT_FACTORIES_TF = new ContextTextField(Context.OBJECT_FACTORIES); |
||||
private ContextTextField STATE_FACTORIES_TF = new ContextTextField(Context.STATE_FACTORIES); |
||||
private ContextTextField URL_PKG_PREFIXES_TF = new ContextTextField(Context.URL_PKG_PREFIXES); |
||||
private ContextTextField DNS_URL_TF = new ContextTextField(Context.DNS_URL); |
||||
private ContextTextField AUTHORITATIVE_TF = new ContextTextField(Context.AUTHORITATIVE); |
||||
private ContextTextField BATCHSIZE_TF = new ContextTextField(Context.BATCHSIZE); |
||||
private ContextTextField REFERRAL_TF = new ContextTextField(Context.REFERRAL); |
||||
private ContextTextField SECURITY_PROTOCOL_TF = new ContextTextField(Context.SECURITY_PROTOCOL); |
||||
private ContextTextField SECURITY_AUTHENTICATION_TF = new ContextTextField(Context.SECURITY_AUTHENTICATION); |
||||
private ContextTextField LANGUAGE_TF = new ContextTextField(Context.LANGUAGE); |
||||
private ContextTextField APPLET_TF = new ContextTextField(Context.APPLET); |
||||
|
||||
private JDialog otherAttrDialog; |
||||
|
||||
public JNDIDefPane() { |
||||
this.setLayout(new BorderLayout()); |
||||
|
||||
jndiNameTextField = new UITextField(20); |
||||
JNDIFactoryComboBox = new UIComboBox(new String[] { "", "weblogic.jndi.WLInitialContextFactory", "com.ibm.websphere.naming.WsnInitialContextFactory", |
||||
"org.jboss.naming.HttpNamingContextFactory", "org.jnp.interfaces.NamingContextFactory", "com.caucho.burlap.BurlapContextFactory", }); |
||||
JNDIFactoryComboBox.setEditable(true); |
||||
JNDIFactoryComboBox.addActionListener(jndiListener); |
||||
JNDIFactoryComboBox.setPreferredSize(new Dimension(FineUIScale.scale(30), JNDIFactoryComboBox.getPreferredSize().height + FineUIScale.scale(2))); |
||||
|
||||
// 上下文
|
||||
JPanel contextPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
||||
contextPane.add(column(LayoutConstants.VERTICAL_GAP, |
||||
row(LayoutConstants.HORIZONTAL_GAP, cell(new UILabel("INITIAL_CONTEXT_FACTORY")).weight(0.35), cell(JNDIFactoryComboBox).weight(0.65)), |
||||
row(LayoutConstants.HORIZONTAL_GAP,cell(new UILabel("PROVIDER_URL")).weight(0.35), cell(PROVIDER_URL_TF).weight(0.65)), |
||||
row(LayoutConstants.HORIZONTAL_GAP,cell(new UILabel("SECURITY_PRINCIPAL")).weight(0.35), cell(SECURITY_PRINCIPAL_TF).weight(0.65)), |
||||
row(LayoutConstants.HORIZONTAL_GAP,cell(new UILabel("SECURITY_CREDENTIALS")).weight(0.35), cell(SECURITY_CREDENTIALS_TF).weight(0.65)) |
||||
).getComponent()); |
||||
|
||||
//其他属性
|
||||
JPanel otherAttributePanel = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
||||
ActionLabel actionLabel = new ActionLabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Datasource_Other_Attributes")); |
||||
actionLabel.addActionListener(new ActionListener() { |
||||
public void actionPerformed(ActionEvent evt) { |
||||
//其他属性弹窗
|
||||
JDialog wDialog = createJDialog(); |
||||
wDialog.setVisible(true); |
||||
} |
||||
}); |
||||
otherAttributePanel.add(actionLabel, BorderLayout.EAST); |
||||
//注意描述
|
||||
JPanel jndiDesPanel = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
||||
jndiDesPanel.add(new JScrollPane(new FRExplainLabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Datasource_JNDI_DES"))), BorderLayout.WEST); |
||||
//JNDI面板
|
||||
JPanel centerPanel = column(LayoutConstants.VERTICAL_GAP, |
||||
row(cell(new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Datasource_JNDI_Name"))).weight(0.15), cell(jndiNameTextField).weight(0.85)), |
||||
row(cell(getTopAlignLabelPane(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Datasource_Context"))).weight(0.15), cell(contextPane).weight(0.85)), |
||||
cell(otherAttributePanel), |
||||
cell(jndiDesPanel) |
||||
).getComponent(); |
||||
this.add(wrapComponentWithTitle(centerPanel,"JNDI")); |
||||
} |
||||
|
||||
private JPanel getTopAlignLabelPane(String labelText) { |
||||
return column(LayoutConstants.VERTICAL_GAP, cell(new UILabel(labelText))) |
||||
.with(it -> it.setBorder(new ScaledEmptyBorder(2,0,0,0))).getComponent(); |
||||
} |
||||
|
||||
public void populate(JNDIDatabaseConnection jndiDatabase) { |
||||
if (jndiDatabase == null) { |
||||
jndiDatabase = new JNDIDatabaseConnection(); |
||||
} |
||||
|
||||
// Properties.
|
||||
Map<String, String> contextHashtable = jndiDatabase.getContextHashtable(); |
||||
Object INITIAL_CONTEXT_FACTORY = contextHashtable.get(Context.INITIAL_CONTEXT_FACTORY); |
||||
|
||||
this.JNDIFactoryComboBox.setSelectedItem(INITIAL_CONTEXT_FACTORY == null ? "" : INITIAL_CONTEXT_FACTORY); |
||||
this.jndiNameTextField.setText(jndiDatabase.getJNDIName() == null ? "" : jndiDatabase.getJNDIName()); |
||||
populateContextAttributes(contextHashtable, this.PROVIDER_URL_TF, Context.PROVIDER_URL); |
||||
populateContextAttributes(contextHashtable, this.SECURITY_PRINCIPAL_TF, Context.SECURITY_PRINCIPAL); |
||||
populateContextAttributes(contextHashtable, this.SECURITY_CREDENTIALS_TF, Context.SECURITY_CREDENTIALS); |
||||
|
||||
populateContextAttributes(contextHashtable, this.OBJECT_FACTORIES_TF, Context.OBJECT_FACTORIES); |
||||
populateContextAttributes(contextHashtable, this.STATE_FACTORIES_TF, Context.STATE_FACTORIES); |
||||
populateContextAttributes(contextHashtable, this.URL_PKG_PREFIXES_TF, Context.URL_PKG_PREFIXES); |
||||
|
||||
populateContextAttributes(contextHashtable, this.DNS_URL_TF, Context.DNS_URL); |
||||
populateContextAttributes(contextHashtable, this.AUTHORITATIVE_TF, Context.AUTHORITATIVE); |
||||
populateContextAttributes(contextHashtable, this.BATCHSIZE_TF, Context.BATCHSIZE); |
||||
populateContextAttributes(contextHashtable, this.REFERRAL_TF, Context.REFERRAL); |
||||
populateContextAttributes(contextHashtable, this.SECURITY_PROTOCOL_TF, Context.SECURITY_PROTOCOL); |
||||
populateContextAttributes(contextHashtable, this.SECURITY_AUTHENTICATION_TF, Context.SECURITY_AUTHENTICATION); |
||||
populateContextAttributes(contextHashtable, this.LANGUAGE_TF, Context.LANGUAGE); |
||||
populateContextAttributes(contextHashtable, this.APPLET_TF, Context.APPLET); |
||||
} |
||||
|
||||
private void populateContextAttributes(Map<String, String> properties, UITextField textField, String contextAttr) { |
||||
String PROVIDER_URL = properties.get(contextAttr); |
||||
if (PROVIDER_URL != null) { |
||||
textField.setText(PROVIDER_URL); |
||||
} |
||||
} |
||||
|
||||
public JNDIDatabaseConnection update() { |
||||
JNDIDatabaseConnection jndiDatabase = new JNDIDatabaseConnection(); |
||||
|
||||
jndiDatabase.setJNDIName(this.jndiNameTextField.getText()); |
||||
|
||||
Map<String, String> contextHashtable = jndiDatabase.getContextHashtable(); |
||||
|
||||
String factoryString = (String)this.JNDIFactoryComboBox.getEditor().getItem(); |
||||
if (factoryString != null && factoryString.trim().length() > 0) { |
||||
contextHashtable.put(Context.INITIAL_CONTEXT_FACTORY, factoryString); |
||||
} |
||||
updateContextAttributes(contextHashtable, this.PROVIDER_URL_TF, Context.PROVIDER_URL); |
||||
updateContextAttributes(contextHashtable, this.SECURITY_PRINCIPAL_TF, Context.SECURITY_PRINCIPAL); |
||||
updateContextAttributes(contextHashtable, this.SECURITY_CREDENTIALS_TF, Context.SECURITY_CREDENTIALS); |
||||
|
||||
updateContextAttributes(contextHashtable, this.OBJECT_FACTORIES_TF, Context.OBJECT_FACTORIES); |
||||
updateContextAttributes(contextHashtable, this.STATE_FACTORIES_TF, Context.STATE_FACTORIES); |
||||
updateContextAttributes(contextHashtable, this.URL_PKG_PREFIXES_TF, Context.URL_PKG_PREFIXES); |
||||
|
||||
updateContextAttributes(contextHashtable, this.DNS_URL_TF, Context.DNS_URL); |
||||
updateContextAttributes(contextHashtable, this.AUTHORITATIVE_TF, Context.AUTHORITATIVE); |
||||
updateContextAttributes(contextHashtable, this.BATCHSIZE_TF, Context.BATCHSIZE); |
||||
updateContextAttributes(contextHashtable, this.REFERRAL_TF, Context.REFERRAL); |
||||
updateContextAttributes(contextHashtable, this.SECURITY_PROTOCOL_TF, Context.SECURITY_PROTOCOL); |
||||
updateContextAttributes(contextHashtable, this.SECURITY_AUTHENTICATION_TF, Context.SECURITY_AUTHENTICATION); |
||||
updateContextAttributes(contextHashtable, this.LANGUAGE_TF, Context.LANGUAGE); |
||||
updateContextAttributes(contextHashtable, this.APPLET_TF, Context.APPLET); |
||||
|
||||
return jndiDatabase; |
||||
} |
||||
|
||||
private void updateContextAttributes(Map<String, String> contextHashtable, UITextField textField, String contextAttr) { |
||||
String tValue = textField.getText(); |
||||
if (tValue != null && tValue.trim().length() > 0) { |
||||
contextHashtable.put(contextAttr, tValue); |
||||
} |
||||
} |
||||
|
||||
ActionListener jndiListener = new ActionListener() { |
||||
public void actionPerformed(ActionEvent e) { |
||||
Object o = JNDIFactoryComboBox.getSelectedItem(); |
||||
if (o == null || ComparatorUtils.equals(o, StringUtils.EMPTY)) { |
||||
PROVIDER_URL_TF.setText(""); |
||||
return; |
||||
} |
||||
PROVIDER_URL_TF.setText(jndiMap.get(o)); |
||||
} |
||||
|
||||
}; |
||||
|
||||
private JDialog createJDialog() { |
||||
if (this.otherAttrDialog == null) { |
||||
this.otherAttrDialog = new OtherAttrPane().showWindow(SwingUtilities.getWindowAncestor(JNDIDefPane.this)); |
||||
} |
||||
|
||||
return this.otherAttrDialog; |
||||
} |
||||
|
||||
class OtherAttrPane extends BasicPane { |
||||
public OtherAttrPane() { |
||||
// JPanel northFlowPane
|
||||
JPanel northFlowPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
||||
northFlowPane.setBorder(new ScaledEmptyBorder(10,10,10,10)); |
||||
// ContextPane
|
||||
northFlowPane.add(column(LayoutConstants.VERTICAL_GAP, |
||||
row(LayoutConstants.HORIZONTAL_GAP, cell(new UILabel("OBJECT_FACTORIES")).weight(0.35), cell(OBJECT_FACTORIES_TF)).weight(0.65), |
||||
row(LayoutConstants.HORIZONTAL_GAP, cell(new UILabel("STATE_FACTORIES")).weight(0.35), cell(STATE_FACTORIES_TF)).weight(0.65), |
||||
row(LayoutConstants.HORIZONTAL_GAP, cell(new UILabel("URL_PKG_PREFIXES")).weight(0.35), cell(URL_PKG_PREFIXES_TF)).weight(0.65), |
||||
row(LayoutConstants.HORIZONTAL_GAP, cell(new UILabel("DNS_URL")).weight(0.35), cell(DNS_URL_TF)).weight(0.65), |
||||
row(LayoutConstants.HORIZONTAL_GAP, cell(new UILabel("AUTHORITATIVE")).weight(0.35), cell(AUTHORITATIVE_TF)).weight(0.65), |
||||
row(LayoutConstants.HORIZONTAL_GAP, cell(new UILabel("BATCHSIZE")).weight(0.35), cell(BATCHSIZE_TF)).weight(0.65), |
||||
row(LayoutConstants.HORIZONTAL_GAP, cell(new UILabel("REFERRAL")).weight(0.35), cell(REFERRAL_TF)).weight(0.65), |
||||
row(LayoutConstants.HORIZONTAL_GAP, cell(new UILabel("SECURITY_PROTOCOL")).weight(0.35), cell(SECURITY_PROTOCOL_TF)).weight(0.65), |
||||
row(LayoutConstants.HORIZONTAL_GAP, cell(new UILabel("SECURITY_AUTHENTICATION")).weight(0.35), cell(SECURITY_AUTHENTICATION_TF)).weight(0.65), |
||||
row(LayoutConstants.HORIZONTAL_GAP, cell(new UILabel("LANGUAGE")).weight(0.35), cell(LANGUAGE_TF)).weight(0.65), |
||||
row(LayoutConstants.HORIZONTAL_GAP, cell(new UILabel("APPLET")).weight(0.35), cell(APPLET_TF)).weight(0.65) |
||||
).getComponent()); |
||||
this.add(northFlowPane, BorderLayout.NORTH); |
||||
} |
||||
|
||||
@Override |
||||
protected String title4PopupWindow() { |
||||
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Datasource_Other_Attributes"); |
||||
} |
||||
} |
||||
|
||||
// 主力Context属性
|
||||
class ContextTextField extends UITextField { |
||||
private String contextName; |
||||
|
||||
public ContextTextField(String contextName) { |
||||
this.setContextName(contextName); |
||||
this.setColumns(24); |
||||
} |
||||
|
||||
public String getContextName() { |
||||
return contextName; |
||||
} |
||||
|
||||
public void setContextName(String contextName) { |
||||
this.contextName = contextName; |
||||
} |
||||
|
||||
/* |
||||
* 更新Properties. |
||||
*/ |
||||
public void applyProperties(Properties properties) { |
||||
properties.put(contextName, this.getText()); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue