@ -20,14 +20,18 @@ import com.fr.design.editor.editor.TextEditor;
import com.fr.design.file.HistoryTemplateListCache ;
import com.fr.design.file.HistoryTemplateListCache ;
import com.fr.design.gui.ilable.UILabel ;
import com.fr.design.gui.ilable.UILabel ;
import com.fr.design.layout.FRGUIPaneFactory ;
import com.fr.design.layout.FRGUIPaneFactory ;
import com.fr.stable.ParameterProvider ;
import com.fr.stable.ParameterProvider ;
import com.fr.stable.StringUtils ;
import com.fr.stable.StringUtils ;
import javax.swing.* ;
import javax.swing.BorderFactory ;
import javax.swing.JComponent ;
import javax.swing.JPanel ;
import javax.swing.JScrollPane ;
import javax.swing.SwingConstants ;
import javax.swing.event.ChangeEvent ;
import javax.swing.event.ChangeEvent ;
import javax.swing.event.ChangeListener ;
import javax.swing.event.ChangeListener ;
import java.awt.* ;
import java.awt.BorderLayout ;
import java.awt.Dimension ;
import java.util.ArrayList ;
import java.util.ArrayList ;
import java.util.Date ;
import java.util.Date ;
import java.util.Iterator ;
import java.util.Iterator ;
@ -37,31 +41,34 @@ import java.util.Map.Entry;
/ * *
/ * *
* The dialog used to input parameter .
* The dialog used to input parameter .
*
* @editor zhou
* @editor zhou
* @since 2012 - 3 - 26上午11 : 09 : 45
* @since 2012 - 3 - 26上午11 : 09 : 45
* /
* /
public class ParameterInputPane extends BasicPane {
public class ParameterInputPane extends BasicPane {
/ * *
/ * *
*
*
* /
* /
private static final long serialVersionUID = 1L ;
private static final long serialVersionUID = 1L ;
// alex:保存编辑器对应的参数的名字
private java . util . Map < ValueEditorPane , String > editorNameMap ; // Map<Editor, Name>
// alex:保存编辑器对应的参数的名字
private boolean allowBlank = true ;
private java . util . Map < ValueEditorPane , String > editorNameMap ; // Map<Editor, Name>
private boolean allowBlank = true ;
private FlowTableLayoutHelper flowTableLayoutHelper ;
/ * *
/ * *
* Constructor .
* Constructor .
* /
* /
public ParameterInputPane ( ParameterProvider [ ] parameters ) {
public ParameterInputPane ( ParameterProvider [ ] parameters ) {
this . initComponents ( parameters ) ;
this . initComponents ( parameters ) ;
}
}
public ParameterInputPane ( ParameterProvider [ ] parameters , boolean allowBlank ) {
public ParameterInputPane ( ParameterProvider [ ] parameters , boolean allowBlank ) {
this . allowBlank = allowBlank ;
this . allowBlank = allowBlank ;
this . initComponents ( parameters ) ;
this . initComponents ( parameters ) ;
}
}
private void initComponents ( ParameterProvider [ ] parameters ) {
private void initComponents ( ParameterProvider [ ] parameters ) {
this . setLayout ( new BorderLayout ( 0 , 4 ) ) ;
this . setLayout ( new BorderLayout ( 0 , 4 ) ) ;
@ -71,9 +78,9 @@ public class ParameterInputPane extends BasicPane {
this . add ( new JScrollPane ( contentPane ) , BorderLayout . CENTER ) ;
this . add ( new JScrollPane ( contentPane ) , BorderLayout . CENTER ) ;
contentPane . setBorder ( BorderFactory . createTitledBorder ( com . fr . design . i18n . Toolkit . i18nText ( "Fine-Design_Basic_Parameters" ) + ":" ) ) ;
contentPane . setBorder ( BorderFactory . createTitledBorder ( com . fr . design . i18n . Toolkit . i18nText ( "Fine-Design_Basic_Parameters" ) + ":" ) ) ;
FlowTableLayoutHelper flowTableLayoutHelper = new FlowTableLayoutHelper ( ) ;
flowTableLayoutHelper = new FlowTableLayoutHelper ( ) ;
editorNameMap = new java . util . HashMap < ValueEditorPane , String > ( ) ;
editorNameMap = new java . util . HashMap < ValueEditorPane , String > ( ) ;
//Parameter list.
//Parameter list.
java . util . List < String > nameAddedList = new java . util . ArrayList < String > ( ) ; // alex:已经加到界面中去的参数名
java . util . List < String > nameAddedList = new java . util . ArrayList < String > ( ) ; // alex:已经加到界面中去的参数名
@ -83,12 +90,12 @@ public class ParameterInputPane extends BasicPane {
// alex:已经在界面中的参数,不加了
// alex:已经在界面中的参数,不加了
if ( nameAddedList . contains ( parameter . getName ( ) ) ) {
if ( nameAddedList . contains ( parameter . getName ( ) ) ) {
continue ;
continue ;
}
}
if ( parameter instanceof StoreProcedureParameter
if ( parameter instanceof StoreProcedureParameter
& & ( ( StoreProcedureParameter ) parameter ) . getSchema ( ) = = StoreProcedureConstants . OUT ) {
& & ( ( StoreProcedureParameter ) parameter ) . getSchema ( ) = = StoreProcedureConstants . OUT ) {
continue ;
continue ;
}
}
final Object pv = parameter . getValue ( ) ;
final Object pv = parameter . getValue ( ) ;
Editor [ ] editors = makeEditorByValue ( pv ) ;
Editor [ ] editors = makeEditorByValue ( pv ) ;
@ -100,135 +107,140 @@ public class ParameterInputPane extends BasicPane {
editPane . setPreferredSize ( new Dimension ( 180 , editPane . getPreferredSize ( ) . height ) ) ;
editPane . setPreferredSize ( new Dimension ( 180 , editPane . getPreferredSize ( ) . height ) ) ;
String parameterDisplayName = parameter . getName ( ) ;
String parameterDisplayName = parameter . getName ( ) ;
if ( StringUtils . isNotBlank ( parameter . getName ( ) ) ) {
if ( StringUtils . isNotBlank ( parameter . getName ( ) ) ) {
parameterDisplayName = parameter . getName ( ) ;
parameterDisplayName = parameter . getName ( ) ;
}
}
contentPane . add ( flowTableLayoutHelper . createLabelFlowPane ( parameterDisplayName + ":" , editPane ) ) ;
contentPane . add ( flowTableLayoutHelper . createLabelFlowPane ( parameterDisplayName + ":" , editPane ) ) ;
//add editor to parameter hashtable.
//add editor to parameter hashtable.
initTextListener ( textF ) ;
initTextListener ( textF ) ;
this . editorNameMap . put ( textF , parameter . getName ( ) ) ;
this . editorNameMap . put ( textF , parameter . getName ( ) ) ;
nameAddedList . add ( parameter . getName ( ) ) ;
nameAddedList . add ( parameter . getName ( ) ) ;
}
}
}
}
}
@Override
public void addNotify ( ) {
super . addNotify ( ) ;
// windows 高DPI下,使用getPreferredSize必须在添加到容器之后,否则得到的数值不准确,因此先放到这调整大小
flowTableLayoutHelper . adjustLabelWidth ( ) ;
flowTableLayoutHelper . adjustLabelWidth ( ) ;
}
}
protected void initTextListener ( ValueEditorPane textF ) {
protected void initTextListener ( ValueEditorPane textF ) {
textF . getCurrentEditor ( ) . addChangeListener ( new ChangeListener ( ) {
textF . getCurrentEditor ( ) . addChangeListener ( new ChangeListener ( ) {
@Override
@Override
public void stateChanged ( ChangeEvent e ) {
public void stateChanged ( ChangeEvent e ) {
HistoryTemplateListCache . getInstance ( ) . getCurrentEditingTemplate ( ) . fireTargetModified ( ) ;
HistoryTemplateListCache . getInstance ( ) . getCurrentEditingTemplate ( ) . fireTargetModified ( ) ;
}
}
} ) ;
} ) ;
}
}
private Editor [ ] makeEditorByValue ( Object pv ) {
private Editor [ ] makeEditorByValue ( Object pv ) {
Editor [ ] editors = { null } ;
Editor [ ] editors = { null } ;
if ( pv instanceof Integer ) {
if ( pv instanceof Integer ) {
editors [ 0 ] = new IntegerEditor ( ) ;
editors [ 0 ] = new IntegerEditor ( ) ;
} else if ( pv instanceof Double | | pv instanceof Float ) {
} else if ( pv instanceof Double | | pv instanceof Float ) {
editors [ 0 ] = new DoubleEditor ( ) ;
editors [ 0 ] = new DoubleEditor ( ) ;
} else if ( pv instanceof Float ) {
} else if ( pv instanceof Float ) {
editors [ 0 ] = new FloatEditor ( ) ;
editors [ 0 ] = new FloatEditor ( ) ;
} else if ( pv instanceof Date ) {
} else if ( pv instanceof Date ) {
editors [ 0 ] = new DateEditor ( true , com . fr . design . i18n . Toolkit . i18nText ( "Fine-Design_Basic_Date" ) ) ;
editors [ 0 ] = new DateEditor ( true , com . fr . design . i18n . Toolkit . i18nText ( "Fine-Design_Basic_Date" ) ) ;
} else if ( pv instanceof Boolean ) {
} else if ( pv instanceof Boolean ) {
editors [ 0 ] = new BooleanEditor ( ) ;
editors [ 0 ] = new BooleanEditor ( ) ;
} else if ( pv instanceof BaseFormula ) {
} else if ( pv instanceof BaseFormula ) {
editors = ValueEditorPaneFactory . basicEditors ( ) ;
editors = ValueEditorPaneFactory . basicEditors ( ) ;
} else {
} else {
editors [ 0 ] = new TextEditor ( ) ;
editors [ 0 ] = new TextEditor ( ) ;
}
}
return editors ;
return editors ;
}
}
@Override
@Override
protected String title4PopupWindow ( ) {
protected String title4PopupWindow ( ) {
return com . fr . design . i18n . Toolkit . i18nText ( "Fine-Design_Basic_Parameters" ) ;
return com . fr . design . i18n . Toolkit . i18nText ( "Fine-Design_Basic_Parameters" ) ;
}
}
/ * *
/ * *
* Update
* Update
* /
* /
public Map < String , Object > update ( ) {
public Map < String , Object > update ( ) {
java . util . Map < String , Object > nameValueMap = new java . util . HashMap < String , Object > ( ) ;
java . util . Map < String , Object > nameValueMap = new java . util . HashMap < String , Object > ( ) ;
Iterator < Entry < ValueEditorPane , String > > entryIt = this . editorNameMap . entrySet ( ) . iterator ( ) ;
Iterator < Entry < ValueEditorPane , String > > entryIt = this . editorNameMap . entrySet ( ) . iterator ( ) ;
while ( entryIt . hasNext ( ) ) {
while ( entryIt . hasNext ( ) ) {
java . util . Map . Entry < ValueEditorPane , String > entry = entryIt . next ( ) ;
java . util . Map . Entry < ValueEditorPane , String > entry = entryIt . next ( ) ;
ValueEditorPane editor = entry . getKey ( ) ;
ValueEditorPane editor = entry . getKey ( ) ;
String parameterName = entry . getValue ( ) ;
String parameterName = entry . getValue ( ) ;
Object editorStringValue = editor . update ( ) ;
Object editorStringValue = editor . update ( ) ;
nameValueMap . put ( parameterName , editorStringValue ) ;
nameValueMap . put ( parameterName , editorStringValue ) ;
}
}
return nameValueMap ;
return nameValueMap ;
}
}
public void checkValid ( ) throws Exception {
public void checkValid ( ) throws Exception {
if ( ! allowBlank ) {
if ( ! allowBlank ) {
boolean valid = true ;
boolean valid = true ;
String error = "" ;
String error = "" ;
Iterator < Entry < ValueEditorPane , String > > entryIt = this . editorNameMap . entrySet ( ) . iterator ( ) ;
Iterator < Entry < ValueEditorPane , String > > entryIt = this . editorNameMap . entrySet ( ) . iterator ( ) ;
while ( entryIt . hasNext ( ) ) {
while ( entryIt . hasNext ( ) ) {
java . util . Map . Entry < ValueEditorPane , String > entry = entryIt . next ( ) ;
java . util . Map . Entry < ValueEditorPane , String > entry = entryIt . next ( ) ;
ValueEditorPane editor = entry . getKey ( ) ;
ValueEditorPane editor = entry . getKey ( ) ;
String parameterName = entry . getValue ( ) ;
String parameterName = entry . getValue ( ) ;
Object editorStringValue = editor . update ( ) ;
Object editorStringValue = editor . update ( ) ;
if ( editorStringValue = = null | | StringUtils . isEmpty ( Utils . objectToString ( editorStringValue ) ) ) {
if ( editorStringValue = = null | | StringUtils . isEmpty ( Utils . objectToString ( editorStringValue ) ) ) {
valid = false ;
valid = false ;
error + = parameterName + com . fr . design . i18n . Toolkit . i18nText ( "Fine-Design_Basic_Not_Null_Des" ) + "\n" ;
error + = parameterName + com . fr . design . i18n . Toolkit . i18nText ( "Fine-Design_Basic_Not_Null_Des" ) + "\n" ;
}
}
}
}
if ( ! valid ) {
if ( ! valid ) {
throw new Exception ( error ) ;
throw new Exception ( error ) ;
}
}
}
}
}
}
/ * *
/ * *
* The class help to flowlayout components
* The class help to flowlayout components
* /
* /
private static class FlowTableLayoutHelper {
private static class FlowTableLayoutHelper {
private List < UILabel > labelList = new ArrayList < UILabel > ( ) ;
private List < UILabel > labelList = new ArrayList < UILabel > ( ) ;
public FlowTableLayoutHelper ( ) {
public FlowTableLayoutHelper ( ) {
}
}
public JPanel createLabelFlowPane ( String text , JComponent comp ) {
public JPanel createLabelFlowPane ( String text , JComponent comp ) {
JPanel centerPane = FRGUIPaneFactory . createNormalFlowInnerContainer_S_Pane ( ) ;
JPanel centerPane = FRGUIPaneFactory . createNormalFlowInnerContainer_S_Pane ( ) ;
UILabel textLabel = new UILabel ( text ) ;
UILabel textLabel = new UILabel ( text ) ;
centerPane . add ( textLabel ) ;
centerPane . add ( textLabel ) ;
textLabel . setHorizontalAlignment ( SwingConstants . LEFT ) ;
textLabel . setHorizontalAlignment ( SwingConstants . LEFT ) ;
this . labelList . add ( textLabel ) ;
this . labelList . add ( textLabel ) ;
centerPane . add ( comp ) ;
centerPane . add ( comp ) ;
return centerPane ;
return centerPane ;
}
}
public void adjustLabelWidth ( ) {
public void adjustLabelWidth ( ) {
int maxWidth = 0 ;
int maxWidth = 0 ;
for ( int i = 0 ; i < labelList . size ( ) ; i + + ) {
for ( int i = 0 ; i < labelList . size ( ) ; i + + ) {
maxWidth = Math . max ( maxWidth , labelList . get ( i ) . getPreferredSize ( ) . width ) ;
maxWidth = Math . max ( maxWidth , labelList . get ( i ) . getPreferredSize ( ) . width ) ;
}
}
for ( int i = 0 ; i < labelList . size ( ) ; i + + ) {
for ( int i = 0 ; i < labelList . size ( ) ; i + + ) {
UILabel label = labelList . get ( i ) ;
UILabel label = labelList . get ( i ) ;
Dimension labelDim = new Dimension ( maxWidth , label . getPreferredSize ( ) . height ) ;
Dimension labelDim = new Dimension ( maxWidth , label . getPreferredSize ( ) . height ) ;
label . setPreferredSize ( labelDim ) ;
label . setPreferredSize ( labelDim ) ;
label . setSize ( labelDim ) ;
label . setSize ( labelDim ) ;
label . setMinimumSize ( labelDim ) ;
label . setMinimumSize ( labelDim ) ;
}
}
}
}
}
}
}
}