Search in sources :

Example 1 with DynamicHttpVariable

use of com.twinsoft.convertigo.engine.enums.DynamicHttpVariable in project convertigo by convertigo.

the class HttpTransactionVariablesComposite method applyProceed.

public void applyProceed() {
    for (Button check : checkboxes) {
        DynamicHttpVariable v = (DynamicHttpVariable) check.getData(DynamicHttpVariable.class.getName());
        Variable dboVar = httpTransaction.getVariable(v.name());
        if (check.getSelection() && dboVar == null) {
            try {
                RequestableHttpVariable newDboVar = new RequestableHttpVariable();
                newDboVar.setName(v.name());
                httpTransaction.addVariable(newDboVar);
            } catch (EngineException e) {
            }
        } else if (!check.getSelection() && dboVar != null) {
            httpTransaction.removeVariable((RequestableVariable) dboVar);
        }
    }
    for (Iterator<Text> i = customs.iterator(); i.hasNext(); ) {
        Text txtName = i.next();
        Text txtValue = i.next();
        if (txtName.getText().isBlank()) {
            continue;
        }
        DynamicHttpVariable v = (DynamicHttpVariable) txtName.getData(DynamicHttpVariable.class.getName());
        try {
            RequestableHttpVariable newDboVar = new RequestableHttpVariable();
            String name = v.prefix() + txtName.getText();
            String normalized = StringUtils.normalize(name);
            newDboVar.setName(normalized);
            if (!name.equals(normalized)) {
                newDboVar.setHttpName(txtName.getText());
            }
            if (v == DynamicHttpVariable.__POST_) {
                newDboVar.setHttpMethod("POST");
            }
            if (!txtValue.getText().isEmpty()) {
                newDboVar.setValueOrNull(txtValue.getText());
            }
            httpTransaction.addVariable(newDboVar);
        } catch (EngineException e) {
        }
    }
}
Also used : RequestableHttpVariable(com.twinsoft.convertigo.beans.variables.RequestableHttpVariable) DynamicHttpVariable(com.twinsoft.convertigo.engine.enums.DynamicHttpVariable) RequestableHttpVariable(com.twinsoft.convertigo.beans.variables.RequestableHttpVariable) Variable(com.twinsoft.convertigo.beans.core.Variable) RequestableVariable(com.twinsoft.convertigo.beans.variables.RequestableVariable) Button(org.eclipse.swt.widgets.Button) DynamicHttpVariable(com.twinsoft.convertigo.engine.enums.DynamicHttpVariable) EngineException(com.twinsoft.convertigo.engine.EngineException) RequestableVariable(com.twinsoft.convertigo.beans.variables.RequestableVariable) Text(org.eclipse.swt.widgets.Text)

Example 2 with DynamicHttpVariable

use of com.twinsoft.convertigo.engine.enums.DynamicHttpVariable in project convertigo by convertigo.

the class HttpTransactionVariablesComposite method build.

public void build(AbstractHttpTransaction httpTransaction) {
    this.httpTransaction = httpTransaction;
    checkboxes.clear();
    customs.clear();
    Composite parent = getParent();
    ScrolledComposite scrolledComposite = this;
    for (Control c : this.getChildren()) {
        c.dispose();
    }
    Composite composite = new Composite(scrolledComposite, SWT.NONE);
    scrolledComposite.addListener(SWT.Resize, new Listener() {

        @Override
        public void handleEvent(Event event) {
            composite.setSize(scrolledComposite.getSize().x, composite.getSize().y);
        }
    });
    scrolledComposite.setExpandHorizontal(true);
    GridLayout gl = new GridLayout(3, false);
    gl.marginLeft = 10;
    gl.marginRight = 10;
    gl.horizontalSpacing = 20;
    composite.setLayout(gl);
    Label title = new Label(composite, SWT.NONE);
    title.setText("Add or remove dynamic variables for this '" + httpTransaction.getName() + "' HTTP Transaction.");
    title.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 3, 1));
    for (DynamicHttpVariable v : DynamicHttpVariable.values()) {
        if (!v.can(httpTransaction) || v.prefix() != null) {
            continue;
        }
        Button checkBtn = new Button(composite, SWT.CHECK);
        checkboxes.add(checkBtn);
        checkBtn.setSelection(httpTransaction.getVariable(v.name()) != null);
        checkBtn.setData(DynamicHttpVariable.class.getName(), v);
        checkBtn.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
        Label labelName = new Label(composite, SWT.NONE);
        labelName.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
        FontData fontData = labelName.getFont().getFontData()[0];
        Font font = new Font(parent.getDisplay(), new FontData(fontData.getName(), fontData.getHeight(), SWT.BOLD));
        labelName.setFont(font);
        labelName.setText(v.display());
        C8oBrowser browserDescription = new C8oBrowser(composite, SWT.MULTI | SWT.WRAP);
        GridData gd = new GridData(SWT.FILL, SWT.FILL, true, false);
        gd.heightHint = 60;
        browserDescription.setLayoutData(gd);
        browserDescription.setUseExternalBrowser(true);
        if (SwtUtils.isDark()) {
            browserDescription.setBackground(parent.getBackground());
        }
        browserDescription.setText("<html>" + "<head>" + "<script type=\"text/javascript\">" + "document.oncontextmenu = new Function(\"return false\");" + "</script>" + "<style type=\"text/css\">" + "body {" + "margin: auto;" + "height: 60px;" + "display: table-cell;" + "vertical-align: middle;" + "font-family: Tahoma new, sans-serif;" + "font-size: 0.7em;" + "overflow-y: auto;" + "color: $foreground$;" + "background-color: $background$ } \n" + "a { color: $link$; }" + "</style></head><body>" + v.description() + "</body></html>");
    }
    for (DynamicHttpVariable v : DynamicHttpVariable.values()) {
        if (!v.can(httpTransaction) || v.prefix() == null) {
            continue;
        }
        Button checkBtn = new Button(composite, SWT.NONE);
        checkBtn.setText("Add");
        checkBtn.setSelection(httpTransaction.getVariable(v.name()) != null);
        checkBtn.setData(DynamicHttpVariable.class.getName(), v);
        checkBtn.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
        Label labelName = new Label(composite, SWT.NONE);
        labelName.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
        FontData fontData = labelName.getFont().getFontData()[0];
        Font font = new Font(parent.getDisplay(), new FontData(fontData.getName(), fontData.getHeight(), SWT.BOLD));
        labelName.setFont(font);
        labelName.setText(v.display());
        C8oBrowser browserDescription = new C8oBrowser(composite, SWT.MULTI | SWT.WRAP);
        GridData gd = new GridData(SWT.FILL, SWT.FILL, true, false);
        gd.heightHint = 60;
        browserDescription.setLayoutData(gd);
        browserDescription.setUseExternalBrowser(true);
        if (SwtUtils.isDark()) {
            browserDescription.setBackground(parent.getBackground());
        }
        browserDescription.setText("<html>" + "<head>" + "<script type=\"text/javascript\">" + "document.oncontextmenu = new Function(\"return false\");" + "</script>" + "<style type=\"text/css\">" + "body {" + "margin: auto;" + "height: 60px;" + "display: table-cell;" + "vertical-align: middle;" + "font-family: Tahoma new, sans-serif;" + "font-size: 0.7em;" + "overflow-y: auto;" + "color: $foreground$;" + "background-color: $background$ } \n" + "a { color: $link$; }" + "</style></head><body>" + v.description() + "</body></html>");
        Composite addComposite = new Composite(composite, SWT.NONE);
        addComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 3, 1));
        FillLayout fl = new FillLayout(SWT.VERTICAL);
        fl.spacing = 5;
        addComposite.setLayout(fl);
        checkBtn.addSelectionListener(new SelectionListener() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                Composite line = new Composite(addComposite, SWT.NONE);
                line.setLayout(new GridLayout(4, false));
                new Label(line, SWT.NONE).setText("Name:");
                Text txt = new Text(line, SWT.BORDER);
                txt.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
                txt.setData(DynamicHttpVariable.class.getName(), v);
                txt.setToolTipText("set the variable name (empty is ignored)");
                customs.add(txt);
                new Label(line, SWT.NONE).setText(" Value:");
                txt = new Text(line, SWT.BORDER);
                txt.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
                txt.setToolTipText("set the variable default value (empty is the null value)");
                customs.add(txt);
                scrolledComposite.setContent(composite);
                composite.pack();
            }

            @Override
            public void widgetDefaultSelected(SelectionEvent e) {
            }
        });
    }
    scrolledComposite.setContent(composite);
    composite.pack();
}
Also used : Listener(org.eclipse.swt.widgets.Listener) SelectionListener(org.eclipse.swt.events.SelectionListener) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) C8oBrowser(com.twinsoft.convertigo.eclipse.swt.C8oBrowser) FontData(org.eclipse.swt.graphics.FontData) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) FillLayout(org.eclipse.swt.layout.FillLayout) Font(org.eclipse.swt.graphics.Font) Control(org.eclipse.swt.widgets.Control) GridLayout(org.eclipse.swt.layout.GridLayout) DynamicHttpVariable(com.twinsoft.convertigo.engine.enums.DynamicHttpVariable) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

DynamicHttpVariable (com.twinsoft.convertigo.engine.enums.DynamicHttpVariable)2 Button (org.eclipse.swt.widgets.Button)2 Text (org.eclipse.swt.widgets.Text)2 Variable (com.twinsoft.convertigo.beans.core.Variable)1 RequestableHttpVariable (com.twinsoft.convertigo.beans.variables.RequestableHttpVariable)1 RequestableVariable (com.twinsoft.convertigo.beans.variables.RequestableVariable)1 C8oBrowser (com.twinsoft.convertigo.eclipse.swt.C8oBrowser)1 EngineException (com.twinsoft.convertigo.engine.EngineException)1 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 SelectionListener (org.eclipse.swt.events.SelectionListener)1 Font (org.eclipse.swt.graphics.Font)1 FontData (org.eclipse.swt.graphics.FontData)1 FillLayout (org.eclipse.swt.layout.FillLayout)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Composite (org.eclipse.swt.widgets.Composite)1 Control (org.eclipse.swt.widgets.Control)1 Event (org.eclipse.swt.widgets.Event)1 Label (org.eclipse.swt.widgets.Label)1