private void createButtonPanel(Composite pageContent) { Composite buttonPanel = new Composite(pageContent, SWT.NONE); GridLayout layout = new GridLayout(); layout.numColumns = 1; buttonPanel.setLayout(layout); GridData gridData = new GridData(); gridData.grabExcessHorizontalSpace = false; gridData.grabExcessVerticalSpace = true; gridData.verticalAlignment = GridData.CENTER; gridData.horizontalAlignment = GridData.CENTER; buttonPanel.setLayoutData(gridData); addButton = new Button(buttonPanel, SWT.PUSH); addButton.setText(Messages._UI_ADD_BUTTON); gridData = new GridData(); gridData.horizontalAlignment = GridData.FILL; gridData.verticalAlignment = GridData.CENTER; addButton.setLayoutData(gridData); addButton.addSelectionListener(new ButtonSelectListener()); addButton.setToolTipText(Messages._UI_ADD_BUTTON_TOOL_TIP); addButton.setEnabled(false); removeButton = new Button(buttonPanel, SWT.PUSH); removeButton.setText(Messages._UI_REMOVE_BUTTON); gridData = new GridData(); gridData.horizontalAlignment = GridData.FILL; gridData.verticalAlignment = GridData.CENTER; removeButton.setLayoutData(gridData); removeButton.addSelectionListener(new ButtonSelectListener()); removeButton.setToolTipText(Messages._UI_REMOVE_BUTTON_TOOL_TIP); removeButton.setEnabled(false); removeAllButton = new Button(buttonPanel, SWT.PUSH); removeAllButton.setText(Messages._UI_REMOVE_ALL_BUTTON); gridData = new GridData(); gridData.horizontalAlignment = GridData.FILL; gridData.verticalAlignment = GridData.CENTER; removeAllButton.setLayoutData(gridData); removeAllButton.addSelectionListener(new ButtonSelectListener()); removeAllButton.setToolTipText(Messages._UI_REMOVE_ALL_BUTTON_TOOL_TIP); removeAllButton.setEnabled(false); }
void createImportButton(Composite parent) { importButton = new Button(parent, SWT.PUSH); importButton.setText(Messages._UI_IMPORT_BUTTON); GridData gridData = new GridData(); gridData.horizontalAlignment = GridData.CENTER; importButton.setLayoutData(gridData); importButton.addSelectionListener( new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) {} public void widgetSelected(SelectionEvent e) { FileSystemImportWizard importWizard = new FileSystemImportWizard(); importWizard.init(workbench, selection); Shell shell = Display.getCurrent().getActiveShell(); WizardDialog wizardDialog = new WizardDialog(shell, importWizard); wizardDialog.create(); wizardDialog.open(); sourceFileViewer.refresh(); } }); importButton.setToolTipText(Messages._UI_IMPORT_BUTTON_TOOL_TIP); }
/** * This method is called by Spoon when the user opens the settings dialog of the step. It should * open the dialog and return only once the dialog has been closed by the user. * * <p>If the user confirms the dialog, the meta object (passed in the constructor) must be updated * to reflect the new step settings. The changed flag of the meta object must reflect whether the * step configuration was changed by the dialog. * * <p>If the user cancels the dialog, the meta object must not be updated, and its changed flag * must remain unaltered. * * <p>The open() method must return the name of the step after the user has confirmed the dialog, * or null if the user cancelled the dialog. */ public String open() { // store some convenient SWT variables Shell parent = getParent(); Display display = parent.getDisplay(); // SWT code for preparing the dialog shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MIN | SWT.MAX); props.setLook(shell); setShellImage(shell, meta); // Save the value of the changed flag on the meta object. If the user cancels // the dialog, it will be restored to this saved value. // The "changed" variable is inherited from BaseStepDialog changed = meta.hasChanged(); // The ModifyListener used on all controls. It will update the meta object to // indicate that changes are being made. ModifyListener lsMod = new ModifyListener() { public void modifyText(ModifyEvent e) { meta.setChanged(); } }; // ------------------------------------------------------- // // SWT code for building the actual settings dialog // // ------------------------------------------------------- // FormLayout formLayout = new FormLayout(); formLayout.marginWidth = Const.FORM_MARGIN; formLayout.marginHeight = Const.FORM_MARGIN; shell.setLayout(formLayout); shell.setText(BaseMessages.getString(PKG, "UniqueListStep.Shell.Title")); int middle = props.getMiddlePct(); int margin = Const.MARGIN; // Stepname line wlStepname = new Label(shell, SWT.RIGHT); wlStepname.setText(BaseMessages.getString(PKG, "System.Label.StepName")); 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); // Treat Consecutive Delimiters as One // wlRemoveBlanks = new Label(shell, SWT.RIGHT); wlRemoveBlanks.setText("Treat Consecutive Delims as One"); wlRemoveBlanks.setToolTipText( "Multiple delimiters in a row will be condensed. Essentially removes blank spaces"); props.setLook(wlRemoveBlanks); fdlRemoveBlanks = new FormData(); fdlRemoveBlanks.left = new FormAttachment(0, 0); fdlRemoveBlanks.top = new FormAttachment(wStepname, margin); fdlRemoveBlanks.right = new FormAttachment(middle, -margin); wlRemoveBlanks.setLayoutData(fdlRemoveBlanks); wRemoveBlanks = new Button(shell, SWT.CHECK); wRemoveBlanks.setToolTipText( "Multiple delimiters in a row will be condensed. Essentially removes blank spaces"); props.setLook(wRemoveBlanks); wRemoveBlanks.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { meta.setChanged(); } }); fdRemoveBlanks = new FormData(); fdRemoveBlanks.left = new FormAttachment(middle, 0); fdRemoveBlanks.top = new FormAttachment(wStepname, margin); fdRemoveBlanks.right = new FormAttachment(100, 0); wRemoveBlanks.setLayoutData(fdRemoveBlanks); // OK and cancel buttons wOK = new Button(shell, SWT.PUSH); wOK.setText(BaseMessages.getString(PKG, "System.Button.OK")); wGet = new Button(shell, SWT.PUSH); wGet.setText("Get"); wCancel = new Button(shell, SWT.PUSH); wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel")); setButtonPositions(new Button[] {wOK, wGet, wCancel}, margin, null); wlGroup = new Label(shell, SWT.NONE); wlGroup.setText("Fields"); props.setLook(wlGroup); fdlGroup = new FormData(); fdlGroup.left = new FormAttachment(0, 0); fdlGroup.top = new FormAttachment(wlRemoveBlanks, margin); wlGroup.setLayoutData(fdlGroup); // Fields colinf = new ColumnInfo[] { new ColumnInfo("Field Name", ColumnInfo.COLUMN_TYPE_CCOMBO, new String[] {""}, false), new ColumnInfo("Current Delimiter", ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo("Output Field Name (Optional)", ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo("Output Delimiter (Optional)", ColumnInfo.COLUMN_TYPE_TEXT, false) }; int nrRows = (meta.getSourceFields() != null ? meta.getSourceFields().length : 1); wGroup = new TableView( transMeta, shell, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL, colinf, nrRows, lsMod, props); fdGroup = new FormData(); fdGroup.left = new FormAttachment(0, 0); fdGroup.top = new FormAttachment(wlGroup, margin); fdGroup.right = new FormAttachment(100, 0); fdGroup.bottom = new FormAttachment(wGet, -margin); wGroup.setLayoutData(fdGroup); 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(), i); } setComboBoxes(); } catch (KettleException e) { logError(BaseMessages.getString(PKG, "System.Dialog.GetFieldsFailed.Message")); } } } }; new Thread(runnable).start(); // Add listeners for cancel and OK lsCancel = new Listener() { public void handleEvent(Event e) { cancel(); } }; lsOK = new Listener() { public void handleEvent(Event e) { ok(); } }; lsGet = new Listener() { public void handleEvent(Event event) { get(); } }; wCancel.addListener(SWT.Selection, lsCancel); wOK.addListener(SWT.Selection, lsOK); wGet.addListener(SWT.Selection, lsGet); // default listener (for hitting "enter") lsDef = new SelectionAdapter() { public void widgetDefaultSelected(SelectionEvent e) { ok(); } }; wStepname.addSelectionListener(lsDef); // Detect X or ALT-F4 or something that kills this window and cancel the dialog properly shell.addShellListener( new ShellAdapter() { public void shellClosed(ShellEvent e) { cancel(); } }); // Set/Restore the dialog size based on last position on screen // The setSize() method is inherited from BaseStepDialog setSize(); // populate the dialog with the values from the meta object populateDialog(); // restore the changed flag to original value, as the modify listeners fire during dialog // population meta.setChanged(changed); // open dialog and enter event loop shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } // at this point the dialog has closed, so either ok() or cancel() have been executed // The "stepname" variable is inherited from BaseStepDialog return stepname; }