에 DateChooserCombo와 텍스트 상자를 교체 콤보
Label2이 : TextBox1에
LABEL3 : TextBox2를이 가진 GridData를 사용하여 SWT에 내가 대화 상자가 만들어 낸 org.eclipse.swt.layout.GridData
확인란 1 레이블 4
checkbox2 Label5
ComoBox에서 선택한 값을 기준으로 TextBox2를 DateChooserCombo 또는 DateChooserCombo를 TextBox2로 바꿔야합니다.
다음은 대화 상자를로드 할 때 TextBox2를 만드는 createTextBox 메서드를 사용하여 구현 한 클래스입니다. ComboBox 값 변경시 setDatePicker가 호출되었습니다. 어떻게 달성 할 수 있는지에 대한 아래의 클래스 구현에 대한 도움을주십시오. 미리 감사드립니다.
public class ConfgElementInsertDialog extends DialogEx {
private Text typeName;
private Text defaultValueText;
private Combo templateType;
private Button isKeyCheckBox;
private Button isEditableCheckBox;
private Button toDisplayCheckBox;
private Button okButton;
private boolean isInstanceConfig;
private List<String> configElementName;
private boolean isKey = false;
private boolean toDisplay = false;
private boolean isEditable = false;
private String label;
private String name;
private String defaultVal;
private boolean isEdit;
private Text configElementNameText;
private List<String> dateItem = Arrays.asList("effectiveDate", "endDate", "premiumEffectiveDate ","premiumEndDate");
private boolean isDatePicker;
private Date defaulDatetVal;
DateChooserCombo enumDateChooser;
Group templateTypeGroup;
public ConfgElementInsertDialog (Shell shell) {
super(shell);
setShellStyle(getShellStyle() | SWT.RESIZE);
}
public ConfgElementInsertDialog (Shell shell, boolean isInstanceconfig,
boolean isEdit) {
super(shell);
this.isInstanceConfig = isInstanceconfig;
this.isEdit = isEdit;
setShellStyle(getShellStyle() | SWT.RESIZE);
}
protected void configureShell(Shell shell) {
super.configureShell(shell);
shell.setSize(300, 300);
if (!isEdit)
shell.setText(TableTemplateConfigConstants.ADD_CONFIG_DIALOG);
else
shell.setText(TableTemplateConfigConstants.EDIT_CONFIG_DIALOG);
}
protected Control createDialogArea(Composite parent) {
Composite child = new Composite(parent, SWT.FILL);
child.setLayout(new GridLayout(1, false));
child.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
templateTypeGroup = new Group(child, SWT.FILL);
templateTypeGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
true));
templateTypeGroup.setLayout(new GridLayout(3, false));
GridData data = new GridData(SWT.None, SWT.FILL, false, false, 2, 1);
data.widthHint = 100;
if(isInstanceConfig)
templateTypeGroup.setText(TableTemplateConfigConstants.ADD_CONFIG_GROUP_INSTANCE_TEXT);
else
templateTypeGroup.setText(TableTemplateConfigConstants.ADD_CONFIG_GROUP_TEMPLATE_TEXT);
Label label1 = new Label(templateTypeGroup, SWT.NULL);
label1.setText(TableTemplateConfigConstants.NAME_LABEL);
if (!isEdit) {
templateType = new Combo(templateTypeGroup, SWT.V_SCROLL);
templateType.setLayoutData(data);
templateType.setItems(getConfigElementName().toArray(
new String[getConfigElementName().size()]));
templateType.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (templateType.getSelection() != null
&& !templateType.getItem(templateType.getSelectionIndex()).isEmpty()) {
setName(templateType.getItem(templateType.getSelectionIndex()));
setDatePicker(templateType.getItem(templateType.getSelectionIndex()),templateTypeGroup);
okButton.setEnabled(true);
} else
okButton.setEnabled(false);
}
});
} else {
configElementNameText = new Text(templateTypeGroup, SWT.BORDER);
configElementNameText.setLayoutData(data);
configElementNameText.setEnabled(false);
if(getName()!=null){
configElementNameText.setText(getName());
setName(getName());
setDatePicker(getName(),templateTypeGroup);
}
}
Label label = new Label(templateTypeGroup, SWT.NULL);
label.setText(TableTemplateConfigConstants.LABEL_TEXT);
typeName = new Text(templateTypeGroup, SWT.BORDER);
typeName.setLayoutData(data);
typeName.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
setLabel(typeName.getText());
}
});
createTextBox(templateTypeGroup, data);
// }
isKeyCheckBox = new Button(templateTypeGroup, SWT.CHECK);
isKeyCheckBox.setText(TableTemplateConfigConstants.REQUIRED_LABEL);
isKeyCheckBox.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
true, 1, 1));
isKeyCheckBox.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (isKeyCheckBox.getSelection())
setKey(true);
else
setKey(false);
}
});
isEditableCheckBox = new Button(templateTypeGroup, SWT.CHECK);
isEditableCheckBox.setSelection(true);
if (!isEdit)
setEditable(true);
if(getDefaultVal()==null || getDefaultVal().isEmpty())
{isEditableCheckBox.setEnabled(false);
}
isEditableCheckBox.setText(TableTemplateConfigConstants.EDITABLE_LABEL);
isEditableCheckBox.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
true, 1, 1));
isEditableCheckBox.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (isEditableCheckBox.getSelection())
setEditable(true);
else
setEditable(false);
}
});
if (!isInstanceConfig) {
toDisplayCheckBox = new Button(templateTypeGroup, SWT.CHECK);
toDisplayCheckBox.setSelection(true);
if(getDefaultVal()==null || getDefaultVal().isEmpty())
toDisplayCheckBox.setEnabled(false);
toDisplayCheckBox.setText(TableTemplateConfigConstants.DISPLAY_LABEL);
toDisplayCheckBox.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
true, true, 1, 1));
toDisplayCheckBox.setSelection(true);
if (!isEdit)
setToDisplay(true);
toDisplayCheckBox.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (toDisplayCheckBox.getSelection())
setToDisplay(true);
else
setToDisplay(false);
}
});
if (isEdit) {
toDisplayCheckBox.setSelection(isToDisplay());
}
}
if (isEdit) {
isKeyCheckBox.setSelection(isKey());
if(getLabel()!=null)
typeName.setText(getLabel());
if(getDefaultVal()!=null)
defaultValueText.setText(getDefaultVal());
isEditableCheckBox.setSelection(isEditable());
}
return child;
}
protected void createButtonsForButtonBar(Composite parent) {
super.createButtonsForButtonBar(parent);
okButton = getButton(IDialogConstants.OK_ID);
if(isEdit)
okButton.setEnabled(true);
else
okButton.setEnabled(false);
}
public List<String> getConfigElementName() {
return configElementName;
}
public void setConfigElementName(List<String> configElementName) {
this.configElementName = configElementName;
}
public boolean isKey() {
return isKey;
}
public void setKey(boolean isKey) {
this.isKey = isKey;
}
public boolean isToDisplay() {
return toDisplay;
}
public void setToDisplay(boolean toDisplay) {
this.toDisplay = toDisplay;
}
public boolean isEditable() {
return isEditable;
}
public void setEditable(boolean isEditable) {
this.isEditable = isEditable;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDefaultVal() {
return defaultVal;
}
public void setDefaultVal(String defaultVal) {
this.defaultVal = defaultVal;
}
public List<String> getListForDatePickere() {
return dateItem;
}
public void setDatePicker(String value, Group templateTypeGroup) {
if(dateItem.contains(value) && null != defaultValueText){
Object grd = defaultValueText.getLayoutData();
defaultValueText.dispose();
defaultValueText = null;
createDateControl(templateTypeGroup,grd);
}else if(!dateItem.contains(value) && null != enumDateChooser){
Object grd = enumDateChooser.getLayoutData();
enumDateChooser.dispose();
enumDateChooser = null;
createTextBox(templateTypeGroup,enumDateChooser.getLayoutData());
}
}
/**
* @return the defaulDatetVal
*/
public Date getDefaulDatetVal() {
return defaulDatetVal;
}
/**
* @param defaulDatetVal the defaulDatetVal to set
*/
public void setDefaulDatetVal(Date defaulDatetVal) {
this.defaulDatetVal = defaulDatetVal;
}
public void createTextBox(Composite templateTypeGroup, Object data){
Label defaultLabel = new Label(templateTypeGroup, SWT.NULL);
defaultLabel.setText(TableTemplateConfigConstants.DEFAULT_VAL_TEXT);
defaultValueText = new Text(templateTypeGroup, SWT.BORDER);
defaultValueText.setLayoutData(data);
defaultValueText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
setDefaultVal(defaultValueText.getText());
if(!isEdit && (defaultValueText.getText()==null || defaultValueText.getText().isEmpty()))
{
setToDisplay(true);
toDisplayCheckBox.setSelection(true);
toDisplayCheckBox.setEnabled(false);
setEditable(true);
isEditableCheckBox.setSelection(true);
isEditableCheckBox.setEnabled(false);
}
if(!isEdit && (defaultValueText.getText()!=null && !defaultValueText.getText().isEmpty()))
{
isEditableCheckBox.setEnabled(true);
toDisplayCheckBox.setEnabled(true);
}
}
});
}
public void createDateControl(Composite templateTypeGroup, Object data){
Label defaultLbl = new Label(templateTypeGroup, SWT.NULL);
defaultLbl.setText(TableTemplateConfigConstants.DEFAULT_VAL_TEXT);
enumDateChooser = new DateChooserCombo(
templateTypeGroup, SWT.BORDER | CDT.DROP_DOWN
| CDT.DATE_SHORT);
enumDateChooser.setFormatter(new DateFormatter(
ITableDataConstants.DATE_FORMAT_TABLE_VIEWER));
enumDateChooser.setValue(new Date(System.currentTimeMillis()));
enumDateChooser.setLayoutData((GridData)data);
enumDateChooser.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
setDefaulDatetVal(enumDateChooser.getValue());
if(!isEdit && (enumDateChooser.getValue()==null))
{
setToDisplay(true);
toDisplayCheckBox.setSelection(true);
toDisplayCheckBox.setEnabled(false);
setEditable(true);
isEditableCheckBox.setSelection(true);
isEditableCheckBox.setEnabled(false);
}
if(!isEdit && (defaultValueText.getText()!=null && !defaultValueText.getText().isEmpty()))
{
isEditableCheckBox.setEnabled(true);
toDisplayCheckBox.setEnabled(true);
}
}
});
}
}
그리고 지금 막 가지고있는 코드로는 어떻게 작동하지 않습니까? – Baz
위 코드에서 TextBox2를 DateChooserCombo 또는 DateChooserCombo로 TextBox2로 대체 할 수있는 방법을 구현하고자합니다. 위 코드는 적절한 대체 작업을 수행하지 않습니다. 나는 POC를 거의하지 않았으며 올바른 결과를 얻은 것으로 보인다. 나는 곧 당신과 함께 나눌 것입니다. – Mohammed