Java tutorial
/* * ??:Quickbundle.org --> ranminXmlGenerateCode * * ??: ranminXmlGenerateCode.wizards --> ConfigTableDialog.java * * ??: * * ?: 2005-12-3 1:25:18 1.0.0 (baixiaoyong) * */ package org.quickbundle.mda.gc; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.TreeMap; import org.dom4j.Attribute; import org.dom4j.Document; import org.dom4j.Element; import org.dom4j.Node; import org.eclipse.core.internal.resources.ResourceStatus; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.ErrorDialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.ScrolledComposite; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Canvas; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; import org.quickbundle.tools.helper.RmStringHelper; /** * This code was generated using CloudGarden's Jigloo SWT/Swing GUI Builder, * which is free for non-commercial use. If Jigloo is being used commercially * (ie, by a corporation, company or business for any purpose whatever) then you * should purchase a license for each developer using Jigloo. Please visit * www.cloudgarden.com for details. Use of Jigloo implies acceptance of these * licensing terms. ************************************* A COMMERCIAL LICENSE * HAS NOT BEEN PURCHASED for this machine, so Jigloo or this code cannot be * used legally for any corporate or commercial purpose. * ************************************* */ /** * ??BUG: * * @author ? * @version 1.0.0 * @see ??? * @since 1.0.0 */ public class ConfigTableDialog extends Dialog implements Listener { //? private Config1MainRuleWizardPage currentWizard; private GenerateCodeRule gcRule = null; //??? private String currentTable; // private Map mColumn = new TreeMap(); private Text tableNameDisplay; private Text tableFilterKeyword; private Text tableDirName; private Text tablePk; private Text statisticColumn; private Text keyColumn; private List<Button> lBCustomBundle = new ArrayList<Button>(); /** * The title of the dialog. */ private String title = ""; /** * Ok button widget. */ private Button okButton; /** * : * * @param parentShell * @param currentWizard * @param currentTable */ public ConfigTableDialog(Shell parentShell, Config1MainRuleWizardPage currentWizard, String currentTable, GenerateCodeRule gcRule) { super(parentShell); this.currentWizard = currentWizard; this.currentTable = currentTable; this.title = ": " + currentTable + ""; this.gcRule = gcRule; } protected void buttonPressed(int buttonId) { if (buttonId == IDialogConstants.OK_ID) { ((Attribute) gcRule.getTableDoc(currentTable).selectObject("/meta/tables/table[1]/@tableNameDisplay")) .setValue(tableNameDisplay.getText()); ((Attribute) gcRule.getTableDoc(currentTable).selectObject("/meta/tables/table[1]/@tableFilterKeyword")) .setValue(tableFilterKeyword.getText()); ((Attribute) gcRule.getTableDoc(currentTable).selectObject("/meta/tables/table[1]/@tableDirName")) .setValue(tableDirName.getText()); ((Attribute) gcRule.getTableDoc(currentTable).selectObject("/meta/tables/table[1]/@tablePk")) .setValue(tablePk.getText()); ((Attribute) gcRule.getTableDoc(currentTable).selectObject("/meta/tables/table[1]/@statisticColumn")) .setValue(statisticColumn.getText()); ((Attribute) gcRule.getTableDoc(currentTable).selectObject("/meta/tables/table[1]/@keyColumn")) .setValue(keyColumn.getText()); { //? String customBundleCode = ""; for (Button b : lBCustomBundle) { if (b.getSelection()) { if (customBundleCode.length() > 0) { customBundleCode += ","; } customBundleCode += b.getData().toString(); } } ((Attribute) gcRule.getTableDoc(currentTable) .selectObject("/meta/tables/table[1]/@customBundleCode")).setValue(customBundleCode); } for (Iterator itMColumn = mColumn.keySet().iterator(); itMColumn.hasNext();) { Object[] columnInfo = (Object[]) mColumn.get(itMColumn.next()); String columnName = String.valueOf(columnInfo[0]); Button isBuild = (Button) columnInfo[1]; Text columnNameDisplay = (Text) columnInfo[3]; Combo humanDisplayType = (Combo) columnInfo[5]; Text humanDisplayTypeKeyword = (Text) columnInfo[6]; Button isBuild_list = (Button) columnInfo[7]; Node node = (Node) gcRule.getTableDoc(currentTable) .selectObject("/meta/tables/table[1]/column[@columnName='" + columnName + "']"); ((Attribute) node.selectObject("@columnNameDisplay")).setValue(columnNameDisplay.getText()); ((Attribute) node.selectObject("@isBuild")).setValue(isBuild.getSelection() ? "true" : "false"); ((Attribute) node.selectObject("@humanDisplayType")).setValue(humanDisplayType.getText()); ((Attribute) node.selectObject("@humanDisplayTypeKeyword")) .setValue(humanDisplayTypeKeyword.getText()); ((Attribute) node.selectObject("@isBuild_list")) .setValue(isBuild_list.getSelection() ? "true" : "false"); } if (!validateAll()) { return; } } super.buttonPressed(buttonId); } private boolean validateAll() { return validateText(tableNameDisplay, "??") && validateText(tableFilterKeyword, "???") && validateText(tableDirName, "??") && validateText(tablePk, "") && validateText(statisticColumn, "") && validateText(keyColumn, "") && validateColumn(tablePk, "") && validateColumn(statisticColumn, "") && validateColumn(keyColumn, ""); } private boolean validateText(Text t, String name) { if (t.getText().trim().length() == 0) { alert(name + "?"); t.forceFocus(); return false; } return true; } private boolean validateColumn(Text t, String name) { if (gcRule.getTableDoc(currentTable) .selectNodes("/meta/tables/table/column[@columnName='" + t.getText() + "']").size() == 0) { alert(name + "?????"); t.forceFocus(); t.selectAll(); return false; } return true; } private void alert(String str) { ErrorDialog msgDialog = new ErrorDialog(this.getShell(), "", str, new ResourceStatus(1, ""), 1); msgDialog.create(); msgDialog.open(); } /* * (non-Javadoc) * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell) */ protected void configureShell(Shell shell) { super.configureShell(shell); if (title != null) shell.setText(title); } /* * (non-Javadoc) * * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite) */ protected void createButtonsForButtonBar(Composite parent) { // create OK and Cancel buttons by default okButton = createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false); } /* * (non-Javadoc) Method declared on Dialog. */ protected Control createDialogArea(Composite parent) { // create composite Composite containerParent = (Composite) super.createDialogArea(parent); containerParent.setLayout(new FillLayout(SWT.VERTICAL)); GridData gd = null; GridLayout layout = null; int columns = 7; // ScrolledComposite scroll = new ScrolledComposite(containerParent, SWT.NONE | SWT.V_SCROLL | SWT.H_SCROLL); scroll.setLayout(new FillLayout(SWT.VERTICAL)); Composite container = new Composite(scroll, SWT.NONE); gd = new GridData(GridData.FILL_VERTICAL); gd.horizontalAlignment = GridData.FILL; gd.verticalAlignment = GridData.FILL; container.setLayoutData(gd); layout = new GridLayout(); layout.numColumns = columns; layout.verticalSpacing = 1; container.setLayout(layout); scroll.setContent(container); createCustomTableHead(container, columns); createCustomBundleArea(container, columns); createCustomColumnArea(container, columns); container.setSize(container.computeSize(SWT.DEFAULT, SWT.DEFAULT)); container.layout(); initialize(); return container; } private void createCustomTableHead(Composite parent, int columns) { GridData gd = null; //? final Canvas container = new Canvas(parent, SWT.NONE); gd = new GridData(); gd.horizontalAlignment = GridData.FILL; gd.verticalAlignment = GridData.FILL; gd.grabExcessHorizontalSpace = true; gd.horizontalSpan = columns; container.setLayoutData(gd); GridLayout layoutCanvas = new GridLayout(); layoutCanvas.numColumns = 8; container.setLayout(layoutCanvas); //1?? new Label(container, SWT.NULL).setText("??:"); Text tableName = new Text(container, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY); gd = new GridData(GridData.VERTICAL_ALIGN_FILL); gd.widthHint = 150; tableName.setLayoutData(gd); tableName.setText(currentTable); //??? String tableNameDisplayDesc = "?????EMPLOYEE\"\""; Label label_tableNameDisplay = new Label(container, SWT.NONE); label_tableNameDisplay.setToolTipText(tableNameDisplayDesc); label_tableNameDisplay.setText("??:"); gd = new GridData(GridData.VERTICAL_ALIGN_FILL); gd.horizontalAlignment = GridData.END; label_tableNameDisplay.setLayoutData(gd); tableNameDisplay = new Text(container, SWT.BORDER | SWT.SINGLE); tableNameDisplay.setToolTipText(tableNameDisplayDesc); gd = new GridData(GridData.VERTICAL_ALIGN_FILL); gd.widthHint = 150; tableNameDisplay.setLayoutData(gd); String tableFilterKeywordDesc = "???????/??HR_EMPLOYEE_JOBHrEmployeeJob"; Label label_tableFilterKeyword = new Label(container, SWT.NONE); label_tableFilterKeyword.setText("???:"); label_tableFilterKeyword.setToolTipText(tableFilterKeywordDesc); gd = new GridData(GridData.VERTICAL_ALIGN_FILL); gd.horizontalAlignment = GridData.END; label_tableFilterKeyword.setLayoutData(gd); tableFilterKeyword = new Text(container, SWT.SINGLE | SWT.BORDER); tableFilterKeyword.setToolTipText(tableFilterKeywordDesc); gd = new GridData(GridData.VERTICAL_ALIGN_FILL); gd.widthHint = 150; tableFilterKeyword.setLayoutData(gd); String tableDirNameDesc = "??Java/Jsp??HR_EMPLOYEE??hremployee?employee"; Label label_tableDirName = new Label(container, SWT.NONE); label_tableDirName.setText("??:"); label_tableDirName.setToolTipText(tableDirNameDesc); gd = new GridData(GridData.VERTICAL_ALIGN_FILL); gd.horizontalAlignment = GridData.END; label_tableDirName.setLayoutData(gd); tableDirName = new Text(container, SWT.SINGLE | SWT.BORDER); tableDirName.setToolTipText(tableDirNameDesc); gd = new GridData(GridData.VERTICAL_ALIGN_FILL); gd.widthHint = 150; tableDirName.setLayoutData(gd); //?? String tablePkDesc = "????????"; Label labelTablePk = new Label(container, SWT.NULL); labelTablePk.setText(":"); labelTablePk.setToolTipText(tablePkDesc); tablePk = new Text(container, SWT.BORDER | SWT.SINGLE); tablePk.setToolTipText(tablePkDesc); gd = new GridData(GridData.VERTICAL_ALIGN_FILL); gd.widthHint = 150; tablePk.setLayoutData(gd); String statisticColumnDesc = "???grouy by?ID"; Label label_statisticColumn = new Label(container, SWT.NONE); label_statisticColumn.setText(":"); label_statisticColumn.setToolTipText(statisticColumnDesc); gd = new GridData(GridData.VERTICAL_ALIGN_FILL); gd.horizontalAlignment = GridData.END; label_statisticColumn.setLayoutData(gd); statisticColumn = new Text(container, SWT.SINGLE | SWT.BORDER); statisticColumn.setToolTipText(statisticColumnDesc); gd = new GridData(GridData.VERTICAL_ALIGN_FILL); gd.widthHint = 150; statisticColumn.setLayoutData(gd); String keyColumnDesc = "????????"; Label label_keyColumn = new Label(container, SWT.NONE); label_keyColumn.setText(":"); label_keyColumn.setToolTipText(keyColumnDesc); gd = new GridData(GridData.VERTICAL_ALIGN_FILL); gd.horizontalAlignment = GridData.END; label_keyColumn.setLayoutData(gd); keyColumn = new Text(container, SWT.SINGLE | SWT.BORDER); keyColumn.setToolTipText(keyColumnDesc); gd = new GridData(GridData.VERTICAL_ALIGN_FILL); gd.widthHint = 150; keyColumn.setLayoutData(gd); new Label(container, SWT.NULL).setText(""); new Label(container, SWT.NULL).setText(""); } private void createCustomBundleArea(Composite parent, int columns) { GridData gd = null; //? final Canvas container = new Canvas(parent, SWT.NONE); gd = new GridData(GridData.FILL_HORIZONTAL); gd.horizontalAlignment = GridData.FILL; gd.verticalAlignment = GridData.FILL; gd.grabExcessHorizontalSpace = true; gd.horizontalSpan = columns; container.setLayoutData(gd); GridLayout layoutCanvas = new GridLayout(30, false); container.setLayout(layoutCanvas); //?? Label label_customBundle = new Label(container, SWT.NULL); gd = new GridData(GridData.VERTICAL_ALIGN_FILL); gd.horizontalSpan = 1; gd.horizontalAlignment = SWT.END; gd.verticalAlignment = SWT.CENTER; label_customBundle.setLayoutData(gd); label_customBundle.setText("?:"); List<Element> lEle = gcRule.getMainRule().selectNodes("/rules/customBundleCode/bundle"); for (Element ele : lEle) { //? Button bCustomBundle = new Button(container, SWT.CHECK); gd = new GridData(SWT.BEGINNING, SWT.BEGINNING, true, true); gd.horizontalSpan = 1; gd.horizontalAlignment = SWT.END; bCustomBundle.setLayoutData(gd); if ("false".equals(ele.valueOf("@null"))) { bCustomBundle.setSelection(true); bCustomBundle.setEnabled(false); } bCustomBundle.setText(ele.valueOf("@name")); bCustomBundle.setData(ele.valueOf("@code")); bCustomBundle.setToolTipText(ele.valueOf("text()")); bCustomBundle.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { Button b = (Button) event.widget; String thisCode = b.getData().toString(); if (b.getSelection()) { String depend = gcRule.getMainRule() .valueOf("/rules/customBundleCode/bundle[@code='" + thisCode + "']/@depend"); if (depend != null && depend.length() > 0) { String[] aDepend = depend.split(","); for (Button but : lBCustomBundle) { if (RmStringHelper.arrayContainString(aDepend, but.getData().toString())) { but.setSelection(true); } } } } else { List<Element> lDependThis = gcRule.getMainRule() .selectNodes("/rules/customBundleCode/bundle"); List<String> toNotSelect = new ArrayList<String>(); for (Element eleDependThis : lDependThis) { if (RmStringHelper.arrayContainString(eleDependThis.valueOf("@depend").split(","), thisCode)) { toNotSelect.add(eleDependThis.valueOf("@code")); } } for (Button but : lBCustomBundle) { if (toNotSelect.contains(but.getData().toString())) { but.setSelection(false); } } } } }); lBCustomBundle.add(bCustomBundle); } } private void createCustomColumnArea(Composite container, int columns) { GridData gd = null; //1 Config1MainRuleWizardPage.createLine(container, columns); //? final Button isBuildHead = new Button(container, SWT.CHECK); gd = new GridData(); gd.horizontalSpan = 1; gd.horizontalAlignment = GridData.END; gd.grabExcessHorizontalSpace = true; isBuildHead.setLayoutData(gd); isBuildHead.setSelection(true); isBuildHead.setToolTipText(""); isBuildHead.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { for (Iterator itMColumn = mColumn.keySet().iterator(); itMColumn.hasNext();) { String index = (String) itMColumn.next(); Button tmpIsBuild = (Button) ((Object[]) mColumn.get(index))[1]; tmpIsBuild.setSelection(isBuildHead.getSelection()); } } }); Label isBuildHead_list = new Label(container, SWT.NONE); gd = new GridData(GridData.VERTICAL_ALIGN_FILL); gd.horizontalSpan = 1; gd.horizontalAlignment = GridData.END; gd.grabExcessHorizontalSpace = true; isBuildHead_list.setLayoutData(gd); isBuildHead_list.setText(""); isBuildHead_list.setToolTipText("?"); //???? Label label_columnName = new Label(container, SWT.NONE); label_columnName.setText("??"); gd = new GridData(GridData.VERTICAL_ALIGN_FILL); gd.horizontalSpan = 1; gd.horizontalAlignment = GridData.BEGINNING; gd.grabExcessHorizontalSpace = true; label_columnName.setLayoutData(gd); //????(???) Label label_columnNameDisplay = new Label(container, SWT.NONE); label_columnNameDisplay.setText("??"); gd = new GridData(GridData.VERTICAL_ALIGN_FILL); gd.horizontalSpan = 1; gd.horizontalAlignment = GridData.BEGINNING; gd.grabExcessHorizontalSpace = true; label_columnNameDisplay.setLayoutData(gd); //??java Label label_dataType = new Label(container, SWT.NONE); label_dataType.setText("java"); gd = new GridData(GridData.VERTICAL_ALIGN_FILL); gd.horizontalSpan = 1; gd.horizontalAlignment = GridData.BEGINNING; gd.grabExcessHorizontalSpace = true; label_dataType.setLayoutData(gd); //???? Label label_displayType = new Label(container, SWT.NONE); label_displayType.setText("?"); gd = new GridData(GridData.VERTICAL_ALIGN_FILL); gd.horizontalSpan = 1; gd.horizontalAlignment = GridData.BEGINNING; gd.grabExcessHorizontalSpace = true; label_displayType.setLayoutData(gd); //???? Label label_displayTypeKeyword = new Label(container, SWT.NONE); label_displayTypeKeyword.setText(""); gd = new GridData(GridData.VERTICAL_ALIGN_FILL); gd.horizontalSpan = 1; gd.horizontalAlignment = GridData.BEGINNING; gd.grabExcessHorizontalSpace = true; label_displayTypeKeyword.setLayoutData(gd); Document docTable = gcRule.getTableDoc(currentTable); java.util.List lColumn = docTable.selectNodes("/meta/tables/table[1]/column"); int indexColumn = 100; for (Iterator itLColumn = lColumn.iterator(); itLColumn.hasNext();) { Object[] columnInfo = new Object[8]; Node node = (Node) itLColumn.next(); columnInfo[0] = node.valueOf("@columnName"); //? Button isBuild = new Button(container, SWT.CHECK); gd = new GridData(GridData.VERTICAL_ALIGN_FILL); gd.horizontalSpan = 1; gd.horizontalAlignment = GridData.END; gd.grabExcessHorizontalSpace = true; isBuild.setLayoutData(gd); if ("true".equals(node.valueOf("@isBuild"))) { isBuild.setSelection(true); } else { isBuild.setSelection(false); } columnInfo[1] = isBuild; //?_list Button isBuild_list = new Button(container, SWT.CHECK); gd = new GridData(GridData.VERTICAL_ALIGN_FILL); gd.horizontalSpan = 1; gd.horizontalAlignment = GridData.END; gd.grabExcessHorizontalSpace = true; isBuild_list.setLayoutData(gd); if ("true".equals(node.valueOf("@isBuild_list"))) { isBuild_list.setSelection(true); } else { isBuild_list.setSelection(false); } columnInfo[7] = isBuild_list; //?? Text columnName = new Text(container, SWT.BORDER | SWT.READ_ONLY); columnName.setText(node.valueOf("@columnName")); gd = new GridData(GridData.VERTICAL_ALIGN_FILL); gd.widthHint = 150; gd.horizontalAlignment = GridData.BEGINNING; gd.grabExcessHorizontalSpace = true; columnName.setLayoutData(gd); columnInfo[2] = columnName; //??(???) Text columnNameDisplay = new Text(container, SWT.BORDER); columnNameDisplay.setText(node.valueOf("@columnNameDisplay")); gd = new GridData(GridData.VERTICAL_ALIGN_FILL); gd.widthHint = 150; gd.horizontalAlignment = GridData.BEGINNING; gd.grabExcessHorizontalSpace = true; columnNameDisplay.setLayoutData(gd); columnInfo[3] = columnNameDisplay; // columnNameDisplay = new Text(container, SWT.BORDER); // | SWT.READ_ONLY columnNameDisplay.setText(node.valueOf("@dataType")); gd = new GridData(GridData.VERTICAL_ALIGN_FILL); gd.widthHint = 150; gd.horizontalAlignment = GridData.BEGINNING; gd.grabExcessHorizontalSpace = true; columnNameDisplay.setLayoutData(gd); columnInfo[4] = columnNameDisplay; //? Combo humanDisplayType = new Combo(container, SWT.BORDER | SWT.READ_ONLY); gd = new GridData(GridData.VERTICAL_ALIGN_FILL); gd.horizontalAlignment = GridData.FILL; humanDisplayType.setLayoutData(gd); String[] xmlDisplayType = null; { Node[] tempNode = (Node[]) gcRule.getMainRule() .selectNodes("/rules/dataType/humanDisplayTypes/humanDisplayType/text()") .toArray(new Node[0]); xmlDisplayType = new String[tempNode.length]; for (int j = 0; j < tempNode.length; j++) { xmlDisplayType[j] = tempNode[j].getText(); } } humanDisplayType.setItems(xmlDisplayType); humanDisplayType.setText(node.valueOf("@humanDisplayType")); columnInfo[5] = humanDisplayType; //? Text humanDisplayTypeKeyword = new Text(container, SWT.BORDER); humanDisplayTypeKeyword.setText(node.valueOf("@humanDisplayTypeKeyword")); gd = new GridData(GridData.VERTICAL_ALIGN_FILL); gd.widthHint = 150; gd.horizontalAlignment = GridData.BEGINNING; gd.grabExcessHorizontalSpace = true; humanDisplayTypeKeyword.setLayoutData(gd); columnInfo[6] = humanDisplayTypeKeyword; mColumn.put(String.valueOf(indexColumn), columnInfo); indexColumn++; } } private void initialize() { tableNameDisplay .setText(gcRule.getTableDoc(currentTable).valueOf("/meta/tables/table[1]/@tableNameDisplay")); tableFilterKeyword .setText(gcRule.getTableDoc(currentTable).valueOf("/meta/tables/table[1]/@tableFilterKeyword")); tableDirName.setText(gcRule.getTableDoc(currentTable).valueOf("/meta/tables/table[1]/@tableDirName")); tablePk.setText(gcRule.getTableDoc(currentTable).valueOf("/meta/tables/table[1]/@tablePk")); statisticColumn.setText(gcRule.getTableDoc(currentTable).valueOf("/meta/tables/table[1]/@statisticColumn")); keyColumn.setText(gcRule.getTableDoc(currentTable).valueOf("/meta/tables/table[1]/@keyColumn")); // String customBundleCode = gcRule.getTableDoc(currentTable) .valueOf("/meta/tables/table[1]/@customBundleCode"); for (Button b : lBCustomBundle) { b.setSelection(customBundleCode.matches("^[\\w,]*" + b.getData().toString() + "[\\w,]*$")); } } /** * :? * * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event) * @param event */ public void handleEvent(Event event) { } }