Search in sources :

Example 6 with C8oBrowser

use of com.twinsoft.convertigo.eclipse.swt.C8oBrowser in project convertigo by convertigo.

the class ComponentExplorerComposite method initialize.

/**
 * This method initializes this
 */
protected void initialize() {
    setLayout(new GridLayout(3, true));
    GridData gridData;
    gridData = new GridData();
    gridData.horizontalAlignment = GridData.FILL;
    gridData.horizontalSpan = 3;
    gridData.grabExcessHorizontalSpace = true;
    gridData.verticalAlignment = GridData.BEGINNING;
    Composite searchComposite = new Composite(this, SWT.NONE);
    searchComposite.setLayoutData(gridData);
    searchComposite.setLayout(new GridLayout(3, false));
    CLabel searchLabel = new CLabel(searchComposite, SWT.NONE);
    searchLabel.setText("Search:");
    Text searchText = new Text(searchComposite, SWT.LEFT | SWT.BORDER | SWT.SINGLE);
    searchText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    searchText.setText("");
    searchText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            search(searchText.getText());
        }
    });
    Button btnClear = new Button(searchComposite, SWT.NONE);
    btnClear.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            searchText.setText("");
            searchText.setFocus();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            searchText.setText("");
            searchText.setFocus();
        }
    });
    btnClear.setText("Clear");
    gridData = new GridData();
    gridData.horizontalAlignment = SWT.FILL;
    gridData.grabExcessHorizontalSpace = true;
    gridData.horizontalSpan = 2;
    gridData.verticalAlignment = SWT.TOP;
    gridData.grabExcessVerticalSpace = true;
    scrolledComposite = new ScrolledComposite(this, SWT.V_SCROLL);
    scrolledComposite.setLayoutData(gridData);
    bar = new ExpandBar(scrolledComposite, SWT.NONE);
    bar.setSpacing(8);
    bar.addExpandListener(new ExpandAdapter() {

        @Override
        public void itemExpanded(ExpandEvent e) {
            refresh();
        }

        @Override
        public void itemCollapsed(ExpandEvent e) {
            refresh();
        }
    });
    scrolledComposite.setContent(bar);
    scrolledComposite.setExpandVertical(true);
    scrolledComposite.setExpandHorizontal(true);
    scrolledComposite.addControlListener(new ControlAdapter() {

        @Override
        public void controlResized(ControlEvent e) {
            refresh();
        }
    });
    helpBrowser = new C8oBrowser(this, SWT.MULTI | SWT.WRAP);
    helpBrowser.setUseExternalBrowser(true);
    gridData = new GridData();
    gridData.horizontalAlignment = GridData.FILL;
    gridData.verticalAlignment = GridData.FILL;
    gridData.grabExcessVerticalSpace = true;
    gridData.grabExcessHorizontalSpace = true;
    helpBrowser.setLayoutData(gridData);
    ComponentManager.refresh();
    getDisplay().asyncExec(() -> {
        search("");
    });
}
Also used : CLabel(org.eclipse.swt.custom.CLabel) ExpandBar(org.eclipse.swt.widgets.ExpandBar) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ModifyListener(org.eclipse.swt.events.ModifyListener) ControlAdapter(org.eclipse.swt.events.ControlAdapter) C8oBrowser(com.twinsoft.convertigo.eclipse.swt.C8oBrowser) ExpandEvent(org.eclipse.swt.events.ExpandEvent) Text(org.eclipse.swt.widgets.Text) ExpandAdapter(org.eclipse.swt.events.ExpandAdapter) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ControlEvent(org.eclipse.swt.events.ControlEvent) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 7 with C8oBrowser

use of com.twinsoft.convertigo.eclipse.swt.C8oBrowser in project convertigo by convertigo.

the class CouchVariablesComposite method setPropertyDescriptor.

public void setPropertyDescriptor(AbstractCouchDbTransaction couchDbTransaction, PropertyDescriptor[] propertyDescriptors, DatabaseObject parentObject) {
    cleanGroups();
    /* Fill the Group widget */
    for (PropertyDescriptor property : propertyDescriptors) {
        String name = property.getName();
        String description = property.getShortDescription();
        if (!parametersCouch.contains(name)) {
            if ((name.startsWith("q_") || name.startsWith("p_"))) {
                if (!parentObject.getClass().getCanonicalName().equals(property.getValue(MySimpleBeanInfo.BLACK_LIST_PARENT_CLASS))) {
                    Group choosenGroup = name.startsWith("q_") ? groupQueries : groupParameters;
                    description = description.replaceFirst("\\|", "<br/>\n");
                    addToComposite(choosenGroup, name, description, false);
                }
            }
        }
    }
    Collection<CouchExtraVariable> extraVariables = null;
    if (couchDbTransaction instanceof ICouchParametersExtra) {
        extraVariables = ((ICouchParametersExtra) couchDbTransaction).getCouchParametersExtra();
    }
    if (extraVariables != null) {
        for (CouchExtraVariable extraVariable : extraVariables) {
            String name = extraVariable.getVariableName();
            Group group = name.startsWith("q_") ? groupQueries : groupData;
            addToComposite(group, name, extraVariable.getVariableDescription(), extraVariable.isMultiValued());
        }
    }
    if (groupQueries.getChildren().length == 1) {
        groupQueries.dispose();
    }
    if (groupParameters.getChildren().length == 1) {
        groupParameters.dispose();
    }
    if (groupData.getChildren().length == 1) {
        groupData.dispose();
    }
    setContent(globalComposite);
    globalComposite.pack(true);
    // Fix text no displayed in C8oBrowser
    LinkedList<Control> controls = new LinkedList<>();
    controls.add(globalComposite);
    Control c;
    while ((c = controls.pollFirst()) != null) {
        if (c instanceof C8oBrowser) {
            ((C8oBrowser) c).reloadText();
        } else if (c instanceof Composite) {
            controls.addAll(Arrays.asList(((Composite) c).getChildren()));
        }
    }
}
Also used : Group(org.eclipse.swt.widgets.Group) CouchExtraVariable(com.twinsoft.convertigo.engine.enums.CouchExtraVariable) Control(org.eclipse.swt.widgets.Control) PropertyDescriptor(java.beans.PropertyDescriptor) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) C8oBrowser(com.twinsoft.convertigo.eclipse.swt.C8oBrowser) ICouchParametersExtra(com.twinsoft.convertigo.beans.transactions.couchdb.ICouchParametersExtra) LinkedList(java.util.LinkedList)

Example 8 with C8oBrowser

use of com.twinsoft.convertigo.eclipse.swt.C8oBrowser in project convertigo by convertigo.

the class CouchVariablesComposite method addToComposite.

private void addToComposite(Group choosenGroup, final String name, final String description, final boolean isMultiValued) {
    boolean isNotChecked = true;
    if (allVariables != null) {
        isNotChecked = !isChecked(allVariables, name);
    }
    if (isNotChecked) {
        final Button checkBtn = new Button(choosenGroup, SWT.CHECK);
        checkBtn.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event event) {
                if (checkBtn.getSelection()) {
                    selectedVariable.add(new CouchVariable(name, description, isMultiValued));
                } else {
                    selectedVariable.remove(getIndex(name, selectedVariable));
                }
            }
        });
        Label labelName = new Label(choosenGroup, SWT.NONE);
        FontData fontData = labelName.getFont().getFontData()[0];
        Font font = new Font(this.getDisplay(), new FontData(fontData.getName(), fontData.getHeight(), SWT.BOLD));
        labelName.setFont(font);
        String label = name;
        if (label.startsWith("p_") || label.startsWith("q_")) {
            label = name.substring(2);
        }
        if (isMultiValued) {
            label += " [ ]";
        }
        labelName.setText(label);
        C8oBrowser browserDescription = new C8oBrowser(choosenGroup, SWT.MULTI | SWT.WRAP);
        browserDescription.setUseExternalBrowser(true);
        if (SwtUtils.isDark()) {
            browserDescription.setBackground(getParent().getBackground());
        }
        GridData gd = new GridData(GridData.FILL, GridData.CENTER, true, true);
        gd.minimumHeight = 60;
        browserDescription.setLayoutData(gd);
        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>" + description + "</body></html>");
        parametersCouch.add(name);
        Control[] children = choosenGroup.getChildren();
        for (int i = 0; i < children.length; i++) {
            if (children[i] instanceof Label) {
                String lab = ((Label) children[i]).getText();
                if (label.compareTo(lab) < 0) {
                    labelName.moveAbove(children[i - 1]);
                    checkBtn.moveAbove(labelName);
                    browserDescription.moveBelow(labelName);
                    break;
                }
            }
        }
    }
}
Also used : CouchVariable(com.twinsoft.convertigo.beans.transactions.couchdb.CouchVariable) Listener(org.eclipse.swt.widgets.Listener) C8oBrowser(com.twinsoft.convertigo.eclipse.swt.C8oBrowser) FontData(org.eclipse.swt.graphics.FontData) Label(org.eclipse.swt.widgets.Label) Font(org.eclipse.swt.graphics.Font) Control(org.eclipse.swt.widgets.Control) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) Event(org.eclipse.swt.widgets.Event)

Example 9 with C8oBrowser

use of com.twinsoft.convertigo.eclipse.swt.C8oBrowser in project convertigo by convertigo.

the class FlowViewerEditor method createPartControl.

@Override
public void createPartControl(Composite parent) {
    FlowViewerInput si = (FlowViewerInput) getEditorInput();
    parent.setLayout(new GridLayout(1, true));
    ;
    c8oBrowser = new C8oBrowser(parent, SWT.NONE);
    c8oBrowser.setLayoutData(new GridData(GridData.FILL_BOTH));
    c8oBrowser.setUseExternalBrowser(false);
    // c8oBrowser.getBrowser().set(InjectJsCallback.class, params -> {
    // String url = params.frame().browser().url();
    // System.out.println("url=" + url);
    // try {
    // Frame frame = params.frame();
    // frame.executeJavaScript(
    // "navigator.__defineGetter__('userAgent', function(){ return 'Android'});\n"
    // );
    // //					params.frame().document().get().
    // } catch (Exception e) {
    // e.printStackTrace();
    // }
    // //			browser.setZoomLevel(zoomFactor.zoomLevel());
    // return Response.proceed();
    // });
    Engine.logStudio.debug("(FlowViwer) Browser debug url: " + c8oBrowser.getDebugUrl());
    String url = EnginePropertiesManager.getProperty(PropertyName.APPLICATION_SERVER_CONVERTIGO_URL);
    if (!"false".equals(ConvertigoPlugin.getProperty(ConvertigoPlugin.PREFERENCE_USE_SYSTEM_FLOWVIEWER))) {
        url += "/system";
    }
    ;
    url += "/projects/lib_FlowViewer/DisplayObjects/mobile/?qname=" + si.sequence.getFullQName();
    c8oBrowser.setUrl(url);
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) C8oBrowser(com.twinsoft.convertigo.eclipse.swt.C8oBrowser) GridData(org.eclipse.swt.layout.GridData)

Example 10 with C8oBrowser

use of com.twinsoft.convertigo.eclipse.swt.C8oBrowser in project convertigo by convertigo.

the class StartupEditor method createPartControl.

@Override
public void createPartControl(Composite parent) {
    SwtUtils.refreshTheme();
    StartupInput si = (StartupInput) getEditorInput();
    parent.setLayout(new GridLayout(1, true));
    ToolBar tb = new ToolBar(parent, SWT.FLAT | SWT.WRAP | SWT.RIGHT);
    tb.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    tb.setVisible(false);
    browser = new C8oBrowser(parent, SWT.NONE);
    browser.setLayoutData(new GridData(GridData.FILL_BOTH));
    browser.setUseExternalBrowser(true);
    ToolItem ti = new ToolItem(tb, SWT.NONE);
    ti.setImage(new Image(Display.getCurrent(), getClass().getResourceAsStream("/com/twinsoft/convertigo/eclipse/editors/images/statement.png")));
    ti.setText("View with your external browser");
    ti.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            Program.launch(browser.getURL().replaceFirst("\\?user=.*", ""));
        }
    });
    ti = new ToolItem(tb, SWT.SEPARATOR);
    ToolItem[] tic = { null };
    if (si.autoClose) {
        tic[0] = new ToolItem(tb, SWT.CHECK);
        tic[0].setImage(new Image(Display.getCurrent(), getClass().getResourceAsStream("/com/twinsoft/convertigo/eclipse/editors/images/stop.png")));
        tic[0].setText("Auto close");
        tic[0].addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                if (tic[0].getSelection()) {
                    ConvertigoPlugin.setProperty(ConvertigoPlugin.PREFERENCE_IGNORE_NEWS, "true");
                    boolean[] s = { true };
                    int[] remains = { 10 };
                    tic[0].setText("Auto close in " + remains[0] + "s");
                    Engine.execute(() -> {
                        try {
                            while (--remains[0] >= 0 && s[0]) {
                                Thread.sleep(1000);
                                tic[0].getDisplay().syncExec(() -> {
                                    if (!tic[0].isDisposed()) {
                                        if (s[0] = tic[0].getSelection()) {
                                            tic[0].setText("Auto close in " + remains[0] + "s");
                                        }
                                    }
                                });
                            }
                            if (s[0]) {
                                tic[0].getDisplay().asyncExec(() -> {
                                    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().closeEditor(StartupEditor.this, false);
                                });
                            }
                        } catch (Exception e2) {
                        }
                    });
                } else {
                    tic[0].setText("Auto close");
                    ConvertigoPlugin.setProperty(ConvertigoPlugin.PREFERENCE_IGNORE_NEWS, "false");
                }
            }
        });
    }
    String url = STARTUP_URL;
    url += "?" + URLUtils.encodePart("user", si.user);
    url += "&" + URLUtils.encodePart("site", si.site);
    url += "&" + URLUtils.encodePart("version", ProductVersion.fullProductVersion);
    browser.addProgressListener(new ProgressAdapter() {

        @Override
        public void completed(ProgressEvent event) {
            if (!tb.isDisposed()) {
                tb.getDisplay().asyncExec(() -> {
                    tb.setVisible(true);
                    if (ConvertigoPlugin.getProperty(ConvertigoPlugin.PREFERENCE_IGNORE_NEWS).equalsIgnoreCase("true")) {
                        if (tic[0] != null && !tic[0].isDisposed()) {
                            tic[0].setSelection(true);
                            tic[0].notifyListeners(SWT.Selection, new Event());
                        }
                    }
                });
            }
        }
    });
    browser.setUrl(url);
}
Also used : C8oBrowser(com.twinsoft.convertigo.eclipse.swt.C8oBrowser) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Image(org.eclipse.swt.graphics.Image) ProgressEvent(org.eclipse.swt.browser.ProgressEvent) PartInitException(org.eclipse.ui.PartInitException) GridLayout(org.eclipse.swt.layout.GridLayout) ToolBar(org.eclipse.swt.widgets.ToolBar) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Event(org.eclipse.swt.widgets.Event) ProgressEvent(org.eclipse.swt.browser.ProgressEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ProgressAdapter(org.eclipse.swt.browser.ProgressAdapter) ToolItem(org.eclipse.swt.widgets.ToolItem)

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