public void getData() { if (input.getTypeField() != null) wTypefield.setText(input.getTypeField()); for (int i = 0; i < input.getFieldName().length; i++) { TableItem item = wFields.table.getItem(i); if (input.getFieldName()[i] != null) item.setText(1, input.getFieldName()[i]); if (input.getFieldValue()[i] != null) item.setText(2, input.getFieldValue()[i]); if (input.getFieldNorm()[i] != null) item.setText(3, input.getFieldNorm()[i]); } wFields.setRowNums(); wFields.optWidth(true); wStepname.selectAll(); wStepname.setFocus(); }
private void ok() { if (Const.isEmpty(wStepname.getText())) return; stepname = wStepname.getText(); // return value input.setTypeField(wTypefield.getText()); int i; // Table table = wFields.table; int nrfields = wFields.nrNonEmpty(); input.allocate(nrfields); for (i = 0; i < nrfields; i++) { TableItem item = wFields.getNonEmpty(i); input.getFieldName()[i] = item.getText(1); input.getFieldValue()[i] = item.getText(2); input.getFieldNorm()[i] = item.getText(3); } dispose(); }
public String open() { Shell parent = getParent(); Display display = parent.getDisplay(); shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MAX | SWT.MIN); props.setLook(shell); setShellImage(shell, input); ModifyListener lsMod = new ModifyListener() { public void modifyText(ModifyEvent e) { input.setChanged(); } }; changed = input.hasChanged(); FormLayout formLayout = new FormLayout(); formLayout.marginWidth = Const.FORM_MARGIN; formLayout.marginHeight = Const.FORM_MARGIN; shell.setLayout(formLayout); shell.setText(BaseMessages.getString(PKG, "NormaliserDialog.Shell.Title")); int middle = props.getMiddlePct(); int margin = Const.MARGIN; // Stepname line wlStepname = new Label(shell, SWT.RIGHT); wlStepname.setText(BaseMessages.getString(PKG, "NormaliserDialog.Stepname.Label")); props.setLook(wlStepname); fdlStepname = new FormData(); fdlStepname.left = new FormAttachment(0, 0); fdlStepname.right = new FormAttachment(middle, -margin); fdlStepname.top = new FormAttachment(0, margin); wlStepname.setLayoutData(fdlStepname); wStepname = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); wStepname.setText(stepname); props.setLook(wStepname); wStepname.addModifyListener(lsMod); fdStepname = new FormData(); fdStepname.left = new FormAttachment(middle, 0); fdStepname.top = new FormAttachment(0, margin); fdStepname.right = new FormAttachment(100, 0); wStepname.setLayoutData(fdStepname); // Typefield line wlTypefield = new Label(shell, SWT.RIGHT); wlTypefield.setText(BaseMessages.getString(PKG, "NormaliserDialog.TypeField.Label")); props.setLook(wlTypefield); fdlTypefield = new FormData(); fdlTypefield.left = new FormAttachment(0, 0); fdlTypefield.right = new FormAttachment(middle, -margin); fdlTypefield.top = new FormAttachment(wStepname, margin); wlTypefield.setLayoutData(fdlTypefield); wTypefield = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); wTypefield.setText(""); props.setLook(wTypefield); wTypefield.addModifyListener(lsMod); fdTypefield = new FormData(); fdTypefield.left = new FormAttachment(middle, 0); fdTypefield.top = new FormAttachment(wStepname, margin); fdTypefield.right = new FormAttachment(100, 0); wTypefield.setLayoutData(fdTypefield); wlFields = new Label(shell, SWT.NONE); wlFields.setText(BaseMessages.getString(PKG, "NormaliserDialog.Fields.Label")); props.setLook(wlFields); fdlFields = new FormData(); fdlFields.left = new FormAttachment(0, 0); fdlFields.top = new FormAttachment(wTypefield, margin); wlFields.setLayoutData(fdlFields); wOK = new Button(shell, SWT.PUSH); wOK.setText(BaseMessages.getString(PKG, "System.Button.OK")); wGet = new Button(shell, SWT.PUSH); wGet.setText(BaseMessages.getString(PKG, "NormaliserDialog.GetFields.Button")); wCancel = new Button(shell, SWT.PUSH); wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel")); setButtonPositions(new Button[] {wOK, wCancel, wGet}, margin, null); final int FieldsCols = 3; final int FieldsRows = input.getFieldName().length; colinf = new ColumnInfo[FieldsCols]; colinf[0] = new ColumnInfo( BaseMessages.getString(PKG, "NormaliserDialog.ColumnInfo.Fieldname"), ColumnInfo.COLUMN_TYPE_CCOMBO, new String[] {""}, false); colinf[1] = new ColumnInfo( BaseMessages.getString(PKG, "NormaliserDialog.ColumnInfo.Type"), ColumnInfo.COLUMN_TYPE_TEXT, false); colinf[2] = new ColumnInfo( BaseMessages.getString(PKG, "NormaliserDialog.ColumnInfo.NewField"), ColumnInfo.COLUMN_TYPE_TEXT, false); wFields = new TableView( transMeta, shell, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI, colinf, FieldsRows, lsMod, props); fdFields = new FormData(); fdFields.left = new FormAttachment(0, 0); fdFields.top = new FormAttachment(wlFields, margin); fdFields.right = new FormAttachment(100, 0); fdFields.bottom = new FormAttachment(wOK, -2 * margin); wFields.setLayoutData(fdFields); // // Search the fields in the background final Runnable runnable = new Runnable() { public void run() { StepMeta stepMeta = transMeta.findStep(stepname); if (stepMeta != null) { try { RowMetaInterface row = transMeta.getPrevStepFields(stepMeta); // Remember these fields... for (int i = 0; i < row.size(); i++) { inputFields.put(row.getValueMeta(i).getName(), Integer.valueOf(i)); } setComboBoxes(); } catch (KettleException e) { logError(BaseMessages.getString(PKG, "System.Dialog.GetFieldsFailed.Message")); } } } }; new Thread(runnable).start(); // Add listeners lsOK = new Listener() { public void handleEvent(Event e) { ok(); } }; lsGet = new Listener() { public void handleEvent(Event e) { get(); } }; lsCancel = new Listener() { public void handleEvent(Event e) { cancel(); } }; wOK.addListener(SWT.Selection, lsOK); wGet.addListener(SWT.Selection, lsGet); wCancel.addListener(SWT.Selection, lsCancel); lsDef = new SelectionAdapter() { public void widgetDefaultSelected(SelectionEvent e) { ok(); } }; wStepname.addSelectionListener(lsDef); // Detect X or ALT-F4 or something that kills this window... shell.addShellListener( new ShellAdapter() { public void shellClosed(ShellEvent e) { cancel(); } }); // Set the shell size, based upon previous time... setSize(); getData(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } return stepname; }
private void cancel() { stepname = null; input.setChanged(changed); dispose(); }