public String open()

in kettle-plugin/src/main/java/com/aliyun/pentaho/di/ui/trans/steps/odpsinput/OdpsInputDialog.java [94:392]


    public String open() {

        Shell parent = getParent();
        Display display = parent.getDisplay();

        shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MIN | SWT.MAX);

        props.setLook(shell);
        setShellImage(shell, meta);

        ModifyListener lsMod = new ModifyListener() {
            public void modifyText(ModifyEvent e) {
                meta.setChanged();
            }
        };
        changed = meta.hasChanged();

        FormLayout formLayout = new FormLayout();
        formLayout.marginWidth = Const.FORM_MARGIN;
        formLayout.marginHeight = Const.FORM_MARGIN;

        shell.setLayout(formLayout);
        shell.setText(BaseMessages.getString(PKG, "ODPS.Shell.Input.Title", new String[0]));

        int middle = props.getMiddlePct();
        int margin = Const.MARGIN;

        wlStepname = new Label(shell, SWT.RIGHT);
        wlStepname.setText(BaseMessages.getString(PKG, "ODPS.Shell.Step.Name"));
        props.setLook(wlStepname);
        FormData fd = new FormData();
        fd.left = new FormAttachment(0, 0);
        fd.right = new FormAttachment(middle, -margin);
        fd.top = new FormAttachment(0, margin);
        wlStepname.setLayoutData(fd);

        wStepname = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
        wStepname.setText(stepname);
        props.setLook(wStepname);
        wStepname.addModifyListener(lsMod);
        fd = new FormData();
        fd.left = new FormAttachment(middle, 0);
        fd.top = new FormAttachment(0, margin);
        fd.right = new FormAttachment(100, 0);
        wStepname.setLayoutData(fd);

        //ODPS connection group
        Group gConnect = new Group(shell, SWT.SHADOW_ETCHED_IN);
        gConnect.setText(BaseMessages.getString(PKG, "ODPS.ConfigTab.TabTitle"));
        FormLayout gConnectLayout = new FormLayout();
        gConnectLayout.marginWidth = 3;
        gConnectLayout.marginHeight = 3;
        gConnect.setLayout(gConnectLayout);
        props.setLook(gConnect);

        //endpoint
        Label wlEndpoint = new Label(gConnect, SWT.RIGHT);
        wlEndpoint.setText(BaseMessages.getString(PKG, "ODPS.Endpoint.Label"));
        props.setLook(wlEndpoint);
        FormData fdlEndpoint = new FormData();
        fdlEndpoint.left = new FormAttachment(0, 0);
        fdlEndpoint.right = new FormAttachment(middle, -margin);
        fdlEndpoint.top = new FormAttachment(0, margin);
        wlEndpoint.setLayoutData(fdlEndpoint);

        m_wEndpoint = new Text(gConnect, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
        props.setLook(m_wEndpoint);
        m_wEndpoint.addModifyListener(lsMod);
        FormData fdEndpoint = new FormData();
        fdEndpoint.left = new FormAttachment(middle, 0);
        fdEndpoint.right = new FormAttachment(100, 0);
        fdEndpoint.top = new FormAttachment(0, margin);
        m_wEndpoint.setLayoutData(fdEndpoint);
        Control lastControl = m_wEndpoint;

        //tunnel endpoint
		Label wlTunnelEndpoint = new Label(gConnect, SWT.RIGHT);
		wlTunnelEndpoint.setText(BaseMessages.getString(PKG, "ODPS.TunnelEndpoint.Label"));
		props.setLook(wlTunnelEndpoint);
		FormData fdlTunnelEndpoint = new FormData();
		fdlTunnelEndpoint.left = new FormAttachment(0, 0);
		fdlTunnelEndpoint.right = new FormAttachment(middle, -margin);
		fdlTunnelEndpoint.top = new FormAttachment(lastControl, margin);
		wlTunnelEndpoint.setLayoutData(fdlTunnelEndpoint);

		m_wTunnelEndpoint = new Text(gConnect, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
		props.setLook(m_wTunnelEndpoint);
		m_wTunnelEndpoint.addModifyListener(lsMod);
		FormData fdTunnelEndpoint = new FormData();
		fdTunnelEndpoint.left = new FormAttachment(middle, 0);
		fdTunnelEndpoint.right = new FormAttachment(100, 0);
		fdTunnelEndpoint.top = new FormAttachment(lastControl, margin);
		m_wTunnelEndpoint.setLayoutData(fdTunnelEndpoint);
		lastControl = m_wTunnelEndpoint;

        //accessId
        Label wlAccessId = new Label(gConnect, SWT.RIGHT);
        wlAccessId.setText(BaseMessages.getString(PKG, "ODPS.AccessId.Label"));
        props.setLook(wlAccessId);
        FormData fdlAccessId = new FormData();
        fdlAccessId.left = new FormAttachment(0, 0);
        fdlAccessId.right = new FormAttachment(middle, -margin);
        fdlAccessId.top = new FormAttachment(lastControl, margin);
        wlAccessId.setLayoutData(fdlAccessId);

        m_wAccessId = new Text(gConnect, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
        props.setLook(m_wAccessId);
        m_wAccessId.addModifyListener(lsMod);
        FormData fdAccessId = new FormData();
        fdAccessId.left = new FormAttachment(middle, 0);
        fdAccessId.right = new FormAttachment(100, 0);
        fdAccessId.top = new FormAttachment(lastControl, margin);
        m_wAccessId.setLayoutData(fdAccessId);
        lastControl = m_wAccessId;

        //accessKey
        Label wlAccessKey = new Label(gConnect, SWT.RIGHT);
        wlAccessKey.setText(BaseMessages.getString(PKG, "ODPS.AccessKey.Label"));
        props.setLook(wlAccessKey);
        FormData fdlAccessKey = new FormData();
        fdlAccessKey.left = new FormAttachment(0, 0);
        fdlAccessKey.right = new FormAttachment(middle, -margin);
        fdlAccessKey.top = new FormAttachment(lastControl, margin);
        wlAccessKey.setLayoutData(fdlAccessKey);

        m_wAccessKey = new Text(gConnect, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
        props.setLook(m_wAccessKey);
        m_wAccessKey.addModifyListener(lsMod);
        FormData fdAccessKey = new FormData();
        fdAccessKey.left = new FormAttachment(middle, 0);
        fdAccessKey.right = new FormAttachment(100, 0);
        fdAccessKey.top = new FormAttachment(lastControl, margin);
        m_wAccessKey.setLayoutData(fdAccessKey);
        lastControl = m_wAccessKey;

        //project name
        Label wlProjectName = new Label(gConnect, SWT.RIGHT);
        wlProjectName.setText(BaseMessages.getString(PKG, "ODPS.ProjectName.Label"));
        props.setLook(wlProjectName);
        FormData fdlProjectName = new FormData();
        fdlProjectName.left = new FormAttachment(0, 0);
        fdlProjectName.right = new FormAttachment(middle, -margin);
        fdlProjectName.top = new FormAttachment(lastControl, margin);
        wlProjectName.setLayoutData(fdlProjectName);

        m_wProjectName = new Text(gConnect, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
        props.setLook(m_wProjectName);
        m_wProjectName.addModifyListener(lsMod);
        FormData fdProjectName = new FormData();
        fdProjectName.left = new FormAttachment(middle, 0);
        fdProjectName.right = new FormAttachment(100, 0);
        fdProjectName.top = new FormAttachment(lastControl, margin);
        m_wProjectName.setLayoutData(fdProjectName);
        lastControl = m_wProjectName;

        //table name
        Label wlTableName = new Label(gConnect, SWT.RIGHT);
        wlTableName.setText(BaseMessages.getString(PKG, "ODPS.TableName.Label"));
        props.setLook(wlTableName);
        FormData fdlTableName = new FormData();
        fdlTableName.left = new FormAttachment(0, 0);
        fdlTableName.right = new FormAttachment(middle, -margin);
        fdlTableName.top = new FormAttachment(lastControl, margin);
        wlTableName.setLayoutData(fdlTableName);

        m_wTableName = new Text(gConnect, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
        props.setLook(m_wTableName);
        m_wTableName.addModifyListener(lsMod);
        FormData fdTableName = new FormData();
        fdTableName.left = new FormAttachment(middle, 0);
        fdTableName.right = new FormAttachment(100, 0);
        fdTableName.top = new FormAttachment(lastControl, margin);
        m_wTableName.setLayoutData(fdTableName);
        lastControl = m_wTableName;

        //parition
        Label wlPartition = new Label(gConnect, SWT.RIGHT);
        wlPartition.setText(BaseMessages.getString(PKG, "ODPS.Partition.Label"));
        props.setLook(wlPartition);
        FormData fdlPartition = new FormData();
        fdlPartition.left = new FormAttachment(0, 0);
        fdlPartition.right = new FormAttachment(middle, -margin);
        fdlPartition.top = new FormAttachment(lastControl, margin);
        wlPartition.setLayoutData(fdlPartition);

        m_wPartition = new Text(gConnect, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
        props.setLook(m_wPartition);
        m_wPartition.addModifyListener(lsMod);
        FormData fdPartition = new FormData();
        fdPartition.left = new FormAttachment(middle, 0);
        fdPartition.right = new FormAttachment(100, 0);
        fdPartition.top = new FormAttachment(lastControl, margin);
        m_wPartition.setLayoutData(fdPartition);
        lastControl = m_wPartition;

        fd = new FormData();
        fd.left = new FormAttachment(0, 0);
        fd.right = new FormAttachment(100, 0);
        fd.top = new FormAttachment(wStepname, margin);
        gConnect.setLayoutData(fd);

        //fields
        Label wlFields = new Label(shell, SWT.NONE);
        wlFields.setText(BaseMessages.getString(PKG, "ODPS.Table.Fields.Label"));
        props.setLook(wlFields);
        FormData fdlFields = new FormData();
        fdlFields.left = new FormAttachment(0, 0);
        fdlFields.top = new FormAttachment(gConnect, margin);
        wlFields.setLayoutData(fdlFields);

        int keyWidgetCols = 1; //3;
        int keyWidgetRows = meta.getOdpsFields() == null ? 1 : meta.getOdpsFields().size();
        ColumnInfo[] ciFields = new ColumnInfo[keyWidgetCols];
        ciFields[0] = new ColumnInfo(BaseMessages.getString(PKG, "ODPS.ColumnInfo.FieldName"),
            ColumnInfo.COLUMN_TYPE_CCOMBO, new String[] {""}, true);
        tableFieldColumns.add(ciFields[0]);

        m_wFieldsTable = new TableView(transMeta, shell,
            SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL, ciFields,
            keyWidgetRows, lsMod, props);

        FormData 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(100, -50);
        m_wFieldsTable.setLayoutData(fdFields);

        // get fields button
        wGet = new Button(shell, SWT.PUSH);
        wGet.setText(BaseMessages.getString(PKG, "System.Button.GetFields"));
        wGet.addSelectionListener(new SelectionAdapter() {
            @Override public void widgetSelected(SelectionEvent e) {
                setTableFieldCombo();
            }
        });

        // OK and cancel buttons
        wOK = new Button(shell, SWT.PUSH);
        wOK.setText(BaseMessages.getString(PKG, "System.Button.OK"));
        wCancel = new Button(shell, SWT.PUSH);
        wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));

        setButtonPositions(new Button[] {wGet, wOK, wCancel}, margin, m_wFieldsTable);

        // Add listeners for cancel and OK
        lsCancel = new Listener() {
            public void handleEvent(Event e) {
                cancel();
            }
        };
        lsOK = new Listener() {
            public void handleEvent(Event e) {
                ok();
            }
        };

        wCancel.addListener(SWT.Selection, lsCancel);
        wOK.addListener(SWT.Selection, lsOK);

        // default listener (for hitting "enter")
        lsDef = new SelectionAdapter() {
            public void widgetDefaultSelected(SelectionEvent e) {
                ok();
            }
        };
        wStepname.addSelectionListener(lsDef);
        m_wEndpoint.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();

        setTableFieldCombo();

        // 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;
    }