Search in sources :

Example 11 with C8oBrowser

use of com.twinsoft.convertigo.eclipse.swt.C8oBrowser 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

C8oBrowser (com.twinsoft.convertigo.eclipse.swt.C8oBrowser)11 GridData (org.eclipse.swt.layout.GridData)9 GridLayout (org.eclipse.swt.layout.GridLayout)8 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)7 Composite (org.eclipse.swt.widgets.Composite)7 SelectionEvent (org.eclipse.swt.events.SelectionEvent)4 Button (org.eclipse.swt.widgets.Button)4 ControlAdapter (org.eclipse.swt.events.ControlAdapter)3 ControlEvent (org.eclipse.swt.events.ControlEvent)3 SelectionListener (org.eclipse.swt.events.SelectionListener)3 Control (org.eclipse.swt.widgets.Control)3 Event (org.eclipse.swt.widgets.Event)3 Text (org.eclipse.swt.widgets.Text)3 PartInitException (org.eclipse.ui.PartInitException)3 Frame (com.teamdev.jxbrowser.frame.Frame)2 JsObject (com.teamdev.jxbrowser.js.JsObject)2 DatabaseObjectFoundException (com.twinsoft.convertigo.engine.DatabaseObjectFoundException)2 File (java.io.File)2 JSONException (org.codehaus.jettison.json.JSONException)2 CoreException (org.eclipse.core.runtime.CoreException)2