Search in sources :

Example 1 with MobileDebugView

use of com.twinsoft.convertigo.eclipse.views.mobile.MobileDebugView in project convertigo by convertigo.

the class ApplicationComponentEditor method createToolbar.

private void createToolbar(Composite parent) {
    toolbar = new ToolBar(parent, SWT.VERTICAL);
    GridData gd = new GridData(GridData.FILL, GridData.FILL, false, true);
    gd.verticalSpan = 2;
    gd.verticalIndent = 4;
    toolbar.setLayoutData(gd);
    ToolItem item = new ToolItem(toolbar, SWT.DROP_DOWN);
    item.setToolTipText("Select device viewport. Click to toggle the custom device bar.");
    item.setImage(new Image(parent.getDisplay(), getClass().getResourceAsStream("/com/twinsoft/convertigo/beans/core/images/mobiledevice_color_16x16.png")));
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (e.detail == SWT.ARROW) {
                ToolItem item = (ToolItem) e.widget;
                Rectangle rect = item.getBounds();
                Point pt = item.getParent().toDisplay(new Point(rect.x + 8, rect.y + 8));
                devicesMenu.setLocation(pt);
                devicesMenu.setVisible(true);
            } else {
                setDeviceBarVisible(!deviceBar.getVisible());
            }
        }
    });
    new ToolItem(toolbar, SWT.SEPARATOR);
    item = new ToolItem(toolbar, SWT.PUSH);
    item.setToolTipText("Change orientation");
    item.setImage(new Image(parent.getDisplay(), getClass().getResourceAsStream("/com/twinsoft/convertigo/beans/connectors/images/fullsyncconnector_color_16x16.png")));
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            String width = deviceWidth.getText();
            deviceWidth.setText(deviceHeight.getText());
            deviceHeight.setText(width);
            updateBrowserSize();
        }
    });
    new ToolItem(toolbar, SWT.SEPARATOR);
    item = new ToolItem(toolbar, SWT.PUSH);
    item.setToolTipText("Refresh");
    item.setImage(new Image(parent.getDisplay(), getClass().getResourceAsStream("/studio/refresh.gif")));
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            doReload();
        }
    });
    item = new ToolItem(toolbar, SWT.PUSH);
    item.setToolTipText("Back");
    item.setImage(new Image(parent.getDisplay(), getClass().getResourceAsStream("/studio/undo.gif")));
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            C8oBrowser.run(() -> {
                int index = c8oBrowser.getCurrentNavigationEntryIndex();
                if (index > 2) {
                    c8oBrowser.goBack();
                }
            });
        }
    });
    new ToolItem(toolbar, SWT.SEPARATOR);
    item = new ToolItem(toolbar, SWT.PUSH);
    item.setToolTipText("Remove highlight");
    item.setImage(new Image(parent.getDisplay(), getClass().getResourceAsStream("/studio/write_wait_zone.d.gif")));
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            exHighlightElement = null;
            exHighlightMobileComponent = null;
            C8oBrowser.run(() -> c8oBrowser.executeJavaScriptAndReturnValue("_c8o_remove_all_overlay()"));
        }
    });
    new ToolItem(toolbar, SWT.SEPARATOR);
    item = new ToolItem(toolbar, SWT.PUSH);
    item.setToolTipText("Show debug");
    item.setImage(new Image(parent.getDisplay(), getClass().getResourceAsStream("/studio/debug.gif")));
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            MobileDebugView view = ConvertigoPlugin.getDefault().getMobileDebugView(true);
            getSite().getPage().activate(view);
            view.onActivated(ApplicationComponentEditor.this);
        }
    });
    item = new ToolItem(toolbar, SWT.PUSH);
    item.setToolTipText("Open in default browser");
    item.setImage(new Image(parent.getDisplay(), getClass().getResourceAsStream("/com/twinsoft/convertigo/beans/statements/images/ContinueWithSiteClipperStatement_color_16x16.png")));
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            C8oBrowser.run(() -> {
                String url = c8oBrowser.getURL();
                if (url.startsWith("http")) {
                    org.eclipse.swt.program.Program.launch(url);
                }
            });
        }
    });
    new ToolItem(toolbar, SWT.SEPARATOR);
    item = new ToolItem(toolbar, SWT.CHECK);
    item.setToolTipText("Toggle auto build");
    item.setSelection(true);
    item.setImage(new Image(parent.getDisplay(), getClass().getResourceAsStream("/studio/accumulate.gif")));
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            MobileBuilder mb = applicationEditorInput.application.getProject().getMobileBuilder();
            mb.setAutoBuild(((ToolItem) e.widget).getSelection());
        }
    });
    item = new ToolItem(toolbar, SWT.PUSH);
    item.setToolTipText("Manage modules");
    item.setImage(new Image(parent.getDisplay(), getClass().getResourceAsStream("/studio/show_blocks.gif")));
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            MessageDialog dialog = new MessageDialog(null, "Node_module Update / Reinstall", null, "This will update or reinstall all your project's node_module dependencies. Update when you just " + "added a new dependency to your ionicTpl/package.json file, or re-install if you want clean all your node_modules and do a fresh install (takes more time).", MessageDialog.QUESTION, new String[] { "Update", "Re-install", "Cancel" }, 0);
            int result = dialog.open();
            if (result < 2) {
                launchBuilder(true, result == 1);
            }
        }
    });
    final ToolItem buildModeItem = item = new ToolItem(toolbar, SWT.DROP_DOWN);
    final Menu buildModeMenu = new Menu(parent.getShell());
    SelectionListener buildModeListener = new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            dialogBuild(buildModeItem, (MenuItem) e.widget);
        }
    };
    for (MobileBuilderBuildMode mode : MobileBuilderBuildMode.values()) {
        MenuItem menuItem = new MenuItem(buildModeMenu, SWT.NONE);
        menuItem.setText(mode.label());
        menuItem.setToolTipText(mode.description());
        menuItem.setData(mode);
        menuItem.setImage(new Image(parent.getDisplay(), getClass().getResourceAsStream(mode.icon())));
        menuItem.addSelectionListener(buildModeListener);
        if (mode.equals(buildMode)) {
            item.setImage(menuItem.getImage());
            item.setToolTipText(mode.description());
        }
    }
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (e.detail == SWT.ARROW) {
                ToolItem item = (ToolItem) e.widget;
                Rectangle rect = item.getBounds();
                Point pt = item.getParent().toDisplay(new Point(rect.x + 8, rect.y + 8));
                buildModeMenu.setLocation(pt);
                buildModeMenu.setVisible(true);
            } else {
                dialogBuild(buildMode);
            }
        }
    });
    new ToolItem(toolbar, SWT.SEPARATOR);
    item = new ToolItem(toolbar, SWT.DROP_DOWN);
    item.setToolTipText("Select dataset");
    item.setImage(new Image(parent.getDisplay(), getClass().getResourceAsStream("/studio/cvs_show_history.gif")));
    SelectionListener selectionListener = new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            setDataset(((MenuItem) e.widget).getText());
        }
    };
    Image iDataset = new Image(parent.getDisplay(), getClass().getResourceAsStream("/studio/cvs_checkin.gif"));
    Image iDatasetSelected = new Image(parent.getDisplay(), getClass().getResourceAsStream("/studio/cvs_checkout.gif"));
    final Menu mDataset = new Menu(toolbar);
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            for (MenuItem item : mDataset.getItems()) {
                item.dispose();
            }
            MenuItem menuItem = new MenuItem(mDataset, SWT.NONE);
            menuItem.setText("none");
            for (String fDataset : datasetDir.list()) {
                Matcher m = pDatasetFile.matcher(fDataset);
                if (m.matches()) {
                    menuItem = new MenuItem(mDataset, SWT.NONE);
                    menuItem.setText(m.group(1));
                }
            }
            for (MenuItem item : mDataset.getItems()) {
                if (item.getText().equals(dataset)) {
                    item.setImage(iDatasetSelected);
                } else {
                    item.setImage(iDataset);
                }
                item.addSelectionListener(selectionListener);
            }
            ToolItem item = (ToolItem) e.widget;
            Rectangle rect = item.getBounds();
            Point pt = item.getParent().toDisplay(new Point(rect.x, rect.y));
            mDataset.setLocation(pt);
            mDataset.setVisible(true);
        }
    });
    item = new ToolItem(toolbar, SWT.PUSH);
    item.setToolTipText("Save dataset");
    item.setImage(new Image(parent.getDisplay(), getClass().getResourceAsStream("/studio/cvs_add.gif")));
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            String[] name = { dataset.equals("none") ? "" : dataset };
            String extra = "";
            int response;
            do {
                MessageDialog dialog = new MessageDialog(null, "Dataset name", null, "What is the name of the dataset ?" + extra, MessageDialog.QUESTION, 0, new String[] { "Save", "Cancel" }) {

                    @Override
                    protected Control createCustomArea(Composite parent) {
                        Text t = new Text(parent, SWT.NONE);
                        t.setLayoutData(new GridData(GridData.FILL_BOTH));
                        t.setText(name[0]);
                        t.addModifyListener(new ModifyListener() {

                            @Override
                            public void modifyText(ModifyEvent e) {
                                name[0] = t.getText();
                            }
                        });
                        return t;
                    }
                };
                response = dialog.open();
                extra = "";
                if (response == 0) {
                    if (StringUtils.isBlank(name[0])) {
                        extra = " (cannot be empty)";
                    } else if (name[0].equals("none")) {
                        extra = " (cannot override 'none')";
                    }
                }
            } while (!extra.isEmpty());
            if (response == 0) {
                C8oBrowser.run(() -> {
                    String value = c8oBrowser.executeJavaScriptAndReturnValue("sessionStorage._c8ocafsession_storage_data");
                    try {
                        FileUtils.write(new File(datasetDir, name[0] + ".json"), new JSONArray(value).toString(2), "UTF-8");
                        toast("Dataset '" + name[0] + "' saved !");
                        dataset = name[0];
                    } catch (Exception e1) {
                        toast("Dataset '" + name[0] + "' NOT saved ! " + e1.getMessage());
                    }
                });
            }
        }
    });
    item = new ToolItem(toolbar, SWT.PUSH);
    item.setToolTipText("Remove dataset");
    item.setImage(new Image(parent.getDisplay(), getClass().getResourceAsStream("/studio/cvs_delete.gif")));
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (!dataset.equals("none")) {
                boolean ok = MessageDialog.openQuestion(null, "Delete '" + dataset + "' ?", "You really want delete'" + dataset + "' ?");
                if (ok) {
                    new File(datasetDir, dataset + ".json").delete();
                    toast("Dataset '" + dataset + "' removed !");
                    setDataset("none");
                }
            } else {
                toast("No dataset selected !");
            }
        }
    });
}
Also used : ModifyListener(org.eclipse.swt.events.ModifyListener) Matcher(java.util.regex.Matcher) Rectangle(org.eclipse.swt.graphics.Rectangle) Image(org.eclipse.swt.graphics.Image) Control(org.eclipse.swt.widgets.Control) ModifyEvent(org.eclipse.swt.events.ModifyEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) Menu(org.eclipse.swt.widgets.Menu) ToolItem(org.eclipse.swt.widgets.ToolItem) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) JSONArray(org.codehaus.jettison.json.JSONArray) MenuItem(org.eclipse.swt.widgets.MenuItem) Text(org.eclipse.swt.widgets.Text) Point(org.eclipse.swt.graphics.Point) MobileBuilderBuildMode(com.twinsoft.convertigo.engine.enums.MobileBuilderBuildMode) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) DatabaseObjectFoundException(com.twinsoft.convertigo.engine.DatabaseObjectFoundException) JSONException(org.codehaus.jettison.json.JSONException) MobileDebugView(com.twinsoft.convertigo.eclipse.views.mobile.MobileDebugView) MobileBuilder(com.twinsoft.convertigo.engine.mobile.MobileBuilder) ToolBar(org.eclipse.swt.widgets.ToolBar) GridData(org.eclipse.swt.layout.GridData) File(java.io.File) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 2 with MobileDebugView

use of com.twinsoft.convertigo.eclipse.views.mobile.MobileDebugView in project convertigo by convertigo.

the class ApplicationComponentEditor method doLoad.

private void doLoad() {
    String url = getPageUrl();
    if (url != null) {
        C8oBrowser.run(() -> {
            String currentUrl = c8oBrowser.getURL();
            if (headlessBuild) {
                c8oBrowser.setUseExternalBrowser(true);
                c8oBrowser.executeFunctionAndReturnValue("_c8o_doLoad", url);
            } else if (!currentUrl.equals(url)) {
                c8oBrowser.setUseExternalBrowser(false);
                boolean done = false;
                if (pagePath != null) {
                    try {
                        c8oBrowser.executeFunctionAndReturnValue("_c8o_remove_all_overlay");
                        done = "done".equals(c8oBrowser.executeFunctionAndReturnValue("_c8o_changePage", pagePath));
                    } catch (Exception e) {
                    }
                }
                if (!done) {
                    c8oBrowser.loadURL(url);
                }
            }
        });
        c8oBrowser.getDisplay().asyncExec(() -> {
            MobileDebugView view = ConvertigoPlugin.getDefault().getMobileDebugView(false);
            if (view != null) {
                view.onActivated(ApplicationComponentEditor.this);
            }
        });
    }
}
Also used : MobileDebugView(com.twinsoft.convertigo.eclipse.views.mobile.MobileDebugView) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) DatabaseObjectFoundException(com.twinsoft.convertigo.engine.DatabaseObjectFoundException) JSONException(org.codehaus.jettison.json.JSONException)

Example 3 with MobileDebugView

use of com.twinsoft.convertigo.eclipse.views.mobile.MobileDebugView in project convertigo by convertigo.

the class ApplicationComponentEditor method createToolbar.

private void createToolbar(Composite parent) {
    toolbar = new ToolBar(parent, SWT.VERTICAL);
    GridData gd = new GridData(GridData.FILL, GridData.FILL, false, true);
    gd.verticalSpan = 2;
    gd.verticalIndent = 4;
    toolbar.setLayoutData(gd);
    ToolItem item = new ToolItem(toolbar, SWT.DROP_DOWN);
    item.setToolTipText("Select device viewport. Click to toggle the custom device bar.");
    item.setImage(new Image(parent.getDisplay(), getClass().getResourceAsStream("/com/twinsoft/convertigo/beans/core/images/mobiledevice_color_16x16.png")));
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (e.detail == SWT.ARROW) {
                ToolItem item = (ToolItem) e.widget;
                Rectangle rect = item.getBounds();
                Point pt = item.getParent().toDisplay(new Point(rect.x + 8, rect.y + 8));
                devicesMenu.setLocation(pt);
                devicesMenu.setVisible(true);
            } else {
                setDeviceBarVisible(!deviceBar.getVisible());
            }
        }
    });
    new ToolItem(toolbar, SWT.SEPARATOR);
    item = new ToolItem(toolbar, SWT.PUSH);
    item.setToolTipText("Change orientation");
    item.setImage(new Image(parent.getDisplay(), getClass().getResourceAsStream("/com/twinsoft/convertigo/beans/connectors/images/fullsyncconnector_color_16x16.png")));
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            String width = deviceWidth.getText();
            deviceWidth.setText(deviceHeight.getText());
            deviceHeight.setText(width);
            updateBrowserSize();
        }
    });
    new ToolItem(toolbar, SWT.SEPARATOR);
    item = new ToolItem(toolbar, SWT.PUSH);
    item.setToolTipText("Refresh");
    item.setImage(new Image(parent.getDisplay(), getClass().getResourceAsStream("/studio/refresh.gif")));
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            doReload();
        }
    });
    item = new ToolItem(toolbar, SWT.PUSH);
    item.setToolTipText("Back");
    item.setImage(new Image(parent.getDisplay(), getClass().getResourceAsStream("/studio/undo.gif")));
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            C8oBrowser.run(() -> {
                int index = c8oBrowser.getCurrentNavigationEntryIndex();
                if (index > 2) {
                    c8oBrowser.goBack();
                }
            });
        }
    });
    new ToolItem(toolbar, SWT.SEPARATOR);
    item = new ToolItem(toolbar, SWT.PUSH);
    item.setToolTipText("Remove highlight");
    item.setImage(new Image(parent.getDisplay(), getClass().getResourceAsStream("/studio/write_wait_zone.d.gif")));
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            exHighlightElement = null;
            exHighlightMobileComponent = null;
            C8oBrowser.run(() -> c8oBrowser.executeJavaScriptAndReturnValue("_c8o_remove_all_overlay()"));
        }
    });
    new ToolItem(toolbar, SWT.SEPARATOR);
    item = new ToolItem(toolbar, SWT.PUSH);
    item.setToolTipText("Show debug");
    item.setImage(new Image(parent.getDisplay(), getClass().getResourceAsStream("/studio/debug.gif")));
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            MobileDebugView view = ConvertigoPlugin.getDefault().getMobileDebugView(true);
            getSite().getPage().activate(view);
            view.onActivated(ApplicationComponentEditor.this);
        }
    });
    item = new ToolItem(toolbar, SWT.PUSH);
    item.setToolTipText("Open in default browser");
    item.setImage(new Image(parent.getDisplay(), getClass().getResourceAsStream("/com/twinsoft/convertigo/beans/statements/images/ContinueWithSiteClipperStatement_color_16x16.png")));
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            C8oBrowser.run(() -> {
                String url = headlessBuild ? getPageUrl() : c8oBrowser.getURL();
                if (url.startsWith("http")) {
                    org.eclipse.swt.program.Program.launch(url);
                }
            });
        }
    });
    item = new ToolItem(toolbar, SWT.CHECK);
    item.setToolTipText("Headless build");
    item.setImage(new Image(parent.getDisplay(), getClass().getResourceAsStream("/com/twinsoft/convertigo/beans/statements/images/invokebrowserjs_16x16.png")));
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            headlessBuild = ((ToolItem) e.widget).getSelection();
            try {
                JSONObject device = new JSONObject(FileUtils.readFileToString(devicePref, "UTF-8"));
                device.put("headlessBuild", headlessBuild);
                FileUtils.write(devicePref, device.toString(4), "UTF-8");
            } catch (Exception ex) {
            // TODO: handle exception
            }
            if (headlessBuild) {
                initLoader();
            }
            doLoad();
        }
    });
    item.setSelection(headlessBuild);
    final Menu mBuild = new Menu(toolbar);
    for (NgxBuilderBuildMode mode : NgxBuilderBuildMode.values()) {
        MenuItem menuItem = new MenuItem(mBuild, SWT.NONE);
        menuItem.setText(mode.label());
        menuItem.setToolTipText(mode.description());
        menuItem.setData(mode);
        menuItem.setImage(new Image(parent.getDisplay(), getClass().getResourceAsStream(mode.icon())));
        menuItem.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                buildItem.setSelection(true);
                buildMode = (NgxBuilderBuildMode) e.widget.getData();
                handleProdBuild();
            }
        });
    }
    buildItem = item = new ToolItem(toolbar, SWT.CHECK);
    item.setToolTipText("Build locally");
    item.setImage(new Image(parent.getDisplay(), getClass().getResourceAsStream("/studio/build_prod_b.png")));
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            boolean selected = ((ToolItem) e.widget).getSelection();
            if (!selected) {
                buildMode = null;
                handleProdBuild();
            } else {
                ToolItem item = (ToolItem) e.widget;
                Rectangle rect = item.getBounds();
                Point pt = item.getParent().toDisplay(new Point(rect.x, rect.y));
                mBuild.setLocation(pt);
                mBuild.setVisible(true);
                buildItem.setSelection(false);
            }
        }
    });
    new ToolItem(toolbar, SWT.SEPARATOR);
    item = new ToolItem(toolbar, SWT.CHECK);
    item.setToolTipText("Toggle auto build");
    item.setSelection(true);
    item.setImage(new Image(parent.getDisplay(), getClass().getResourceAsStream("/studio/accumulate.gif")));
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            MobileBuilder mb = applicationEditorInput.application.getProject().getMobileBuilder();
            mb.setAutoBuild(((ToolItem) e.widget).getSelection());
        }
    });
    item = new ToolItem(toolbar, SWT.PUSH);
    item.setToolTipText("Manage modules");
    item.setImage(new Image(parent.getDisplay(), getClass().getResourceAsStream("/studio/show_blocks.gif")));
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            MessageDialog dialog = new MessageDialog(null, "Node_module Update / Reinstall", null, "This will update or reinstall all your project's node_module dependencies. Update when you just " + "added a new dependency to your ionicTpl/package.json file, or re-install if you want clean all your node_modules and do a fresh install (takes more time).", MessageDialog.QUESTION, new String[] { "Update", "Re-install", "Cancel" }, 0);
            int result = dialog.open();
            if (result < 2) {
                launchBuilder(true, result == 1);
            }
        }
    });
    // final ToolItem buildModeItem = item = new ToolItem(toolbar, SWT.DROP_DOWN);
    // final Menu buildModeMenu = new Menu(parent.getShell());
    // SelectionListener buildModeListener = new SelectionAdapter() {
    // 
    // @Override
    // public void widgetSelected(SelectionEvent e) {
    // dialogBuild(buildModeItem, (MenuItem) e.widget);
    // }
    // 
    // };
    // 
    // for (MobileBuilderBuildMode mode: MobileBuilderBuildMode.values()) {
    // MenuItem menuItem = new MenuItem(buildModeMenu, SWT.NONE);
    // menuItem.setText(mode.label());
    // menuItem.setToolTipText(mode.description());
    // menuItem.setData(mode);
    // menuItem.setImage(new Image(parent.getDisplay(), getClass().getResourceAsStream(mode.icon())));
    // menuItem.addSelectionListener(buildModeListener);
    // if (mode.equals(buildMode)) {
    // item.setImage(menuItem.getImage());
    // item.setToolTipText(mode.description());
    // }
    // }
    // 
    // item.addSelectionListener(new SelectionAdapter() {
    // 
    // @Override
    // public void widgetSelected(SelectionEvent e) {
    // if (e.detail == SWT.ARROW) {
    // ToolItem item = (ToolItem) e.widget;
    // Rectangle rect = item.getBounds();
    // Point pt = item.getParent().toDisplay(new Point(rect.x + 8, rect.y + 8));
    // buildModeMenu.setLocation(pt);
    // buildModeMenu.setVisible(true);
    // } else {
    // dialogBuild(buildMode);
    // }
    // }
    // 
    // });
    new ToolItem(toolbar, SWT.SEPARATOR);
    item = new ToolItem(toolbar, SWT.DROP_DOWN);
    item.setToolTipText("Select dataset");
    item.setImage(new Image(parent.getDisplay(), getClass().getResourceAsStream("/studio/cvs_show_history.gif")));
    SelectionListener selectionListener = new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            setDataset(((MenuItem) e.widget).getText());
        }
    };
    Image iDataset = new Image(parent.getDisplay(), getClass().getResourceAsStream("/studio/cvs_checkin.gif"));
    Image iDatasetSelected = new Image(parent.getDisplay(), getClass().getResourceAsStream("/studio/cvs_checkout.gif"));
    final Menu mDataset = new Menu(toolbar);
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            for (MenuItem item : mDataset.getItems()) {
                item.dispose();
            }
            MenuItem menuItem = new MenuItem(mDataset, SWT.NONE);
            menuItem.setText("none");
            for (String fDataset : datasetDir.list()) {
                Matcher m = pDatasetFile.matcher(fDataset);
                if (m.matches()) {
                    menuItem = new MenuItem(mDataset, SWT.NONE);
                    menuItem.setText(m.group(1));
                }
            }
            for (MenuItem item : mDataset.getItems()) {
                if (item.getText().equals(dataset)) {
                    item.setImage(iDatasetSelected);
                } else {
                    item.setImage(iDataset);
                }
                item.addSelectionListener(selectionListener);
            }
            ToolItem item = (ToolItem) e.widget;
            Rectangle rect = item.getBounds();
            Point pt = item.getParent().toDisplay(new Point(rect.x, rect.y));
            mDataset.setLocation(pt);
            mDataset.setVisible(true);
        }
    });
    item = new ToolItem(toolbar, SWT.PUSH);
    item.setToolTipText("Save dataset");
    item.setImage(new Image(parent.getDisplay(), getClass().getResourceAsStream("/studio/cvs_add.gif")));
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            String[] name = { dataset.equals("none") ? "" : dataset };
            String extra = "";
            int response;
            do {
                MessageDialog dialog = new MessageDialog(null, "Dataset name", null, "What is the name of the dataset ?" + extra, MessageDialog.QUESTION, 0, new String[] { "Save", "Cancel" }) {

                    @Override
                    protected Control createCustomArea(Composite parent) {
                        Text t = new Text(parent, SWT.NONE);
                        t.setLayoutData(new GridData(GridData.FILL_BOTH));
                        t.setText(name[0]);
                        t.addModifyListener(new ModifyListener() {

                            @Override
                            public void modifyText(ModifyEvent e) {
                                name[0] = t.getText();
                            }
                        });
                        return t;
                    }
                };
                response = dialog.open();
                extra = "";
                if (response == 0) {
                    if (StringUtils.isBlank(name[0])) {
                        extra = " (cannot be empty)";
                    } else if (name[0].equals("none")) {
                        extra = " (cannot override 'none')";
                    }
                }
            } while (!extra.isEmpty());
            if (response == 0) {
                C8oBrowser.run(() -> {
                    String value = c8oBrowser.executeJavaScriptAndReturnValue("sessionStorage._c8ocafsession_storage_data");
                    try {
                        FileUtils.write(new File(datasetDir, name[0] + ".json"), new JSONArray(value).toString(2), "UTF-8");
                        toast("Dataset '" + name[0] + "' saved !");
                        dataset = name[0];
                    } catch (Exception e1) {
                        toast("Dataset '" + name[0] + "' NOT saved ! " + e1.getMessage());
                    }
                });
            }
        }
    });
    item = new ToolItem(toolbar, SWT.PUSH);
    item.setToolTipText("Remove dataset");
    item.setImage(new Image(parent.getDisplay(), getClass().getResourceAsStream("/studio/cvs_delete.gif")));
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (!dataset.equals("none")) {
                boolean ok = MessageDialog.openQuestion(null, "Delete '" + dataset + "' ?", "You really want delete'" + dataset + "' ?");
                if (ok) {
                    new File(datasetDir, dataset + ".json").delete();
                    toast("Dataset '" + dataset + "' removed !");
                    setDataset("none");
                }
            } else {
                toast("No dataset selected !");
            }
        }
    });
    showGrids = item = new ToolItem(toolbar, SWT.CHECK);
    item.setToolTipText("Show all grids or current selected");
    item.setImage(new Image(parent.getDisplay(), getClass().getResourceAsStream("/studio/grid_color_16x16.png")));
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            boolean showGrid = ((ToolItem) e.widget).getSelection();
            C8oBrowser.run(() -> c8oBrowser.executeJavaScriptAndReturnValue("_c8o_showGrids(" + (showGrid ? "true" : "false") + ")"));
        }
    });
}
Also used : ModifyListener(org.eclipse.swt.events.ModifyListener) Matcher(java.util.regex.Matcher) Rectangle(org.eclipse.swt.graphics.Rectangle) Image(org.eclipse.swt.graphics.Image) Control(org.eclipse.swt.widgets.Control) ModifyEvent(org.eclipse.swt.events.ModifyEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Menu(org.eclipse.swt.widgets.Menu) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) ToolItem(org.eclipse.swt.widgets.ToolItem) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) JSONArray(org.codehaus.jettison.json.JSONArray) MenuItem(org.eclipse.swt.widgets.MenuItem) Text(org.eclipse.swt.widgets.Text) Point(org.eclipse.swt.graphics.Point) NgxBuilderBuildMode(com.twinsoft.convertigo.engine.enums.NgxBuilderBuildMode) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) DatabaseObjectFoundException(com.twinsoft.convertigo.engine.DatabaseObjectFoundException) JSONException(org.codehaus.jettison.json.JSONException) MobileDebugView(com.twinsoft.convertigo.eclipse.views.mobile.MobileDebugView) JSONObject(org.codehaus.jettison.json.JSONObject) MobileBuilder(com.twinsoft.convertigo.engine.mobile.MobileBuilder) ToolBar(org.eclipse.swt.widgets.ToolBar) GridData(org.eclipse.swt.layout.GridData) File(java.io.File) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 4 with MobileDebugView

use of com.twinsoft.convertigo.eclipse.views.mobile.MobileDebugView in project convertigo by convertigo.

the class ApplicationComponentEditor method doLoad.

private void doLoad() {
    if (baseUrl != null) {
        C8oBrowser.run(() -> {
            String url = baseUrl;
            if (pagePath != null) {
                url += "#/" + pagePath;
            }
            if (!c8oBrowser.getURL().equals(url)) {
                c8oBrowser.loadURL(url);
            }
        });
        c8oBrowser.getDisplay().asyncExec(() -> {
            MobileDebugView view = ConvertigoPlugin.getDefault().getMobileDebugView(false);
            if (view != null) {
                view.onActivated(ApplicationComponentEditor.this);
            }
        });
    }
}
Also used : MobileDebugView(com.twinsoft.convertigo.eclipse.views.mobile.MobileDebugView)

Aggregations

MobileDebugView (com.twinsoft.convertigo.eclipse.views.mobile.MobileDebugView)4 DatabaseObjectFoundException (com.twinsoft.convertigo.engine.DatabaseObjectFoundException)3 JSONException (org.codehaus.jettison.json.JSONException)3 CoreException (org.eclipse.core.runtime.CoreException)3 PartInitException (org.eclipse.ui.PartInitException)3 MobileBuilder (com.twinsoft.convertigo.engine.mobile.MobileBuilder)2 File (java.io.File)2 Matcher (java.util.regex.Matcher)2 JSONArray (org.codehaus.jettison.json.JSONArray)2 MessageDialog (org.eclipse.jface.dialogs.MessageDialog)2 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)2 ModifyEvent (org.eclipse.swt.events.ModifyEvent)2 ModifyListener (org.eclipse.swt.events.ModifyListener)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 SelectionListener (org.eclipse.swt.events.SelectionListener)2 Image (org.eclipse.swt.graphics.Image)2 Point (org.eclipse.swt.graphics.Point)2 Rectangle (org.eclipse.swt.graphics.Rectangle)2 GridData (org.eclipse.swt.layout.GridData)2