Search in sources :

Example 1 with Component

use of com.twinsoft.convertigo.beans.mobile.components.dynamic.Component in project convertigo by convertigo.

the class ComponentExplorerComposite method findDatabaseObjects.

protected void findDatabaseObjects(String searchText) {
    if (objectsMap.isEmpty()) {
        try {
            List<String> categories = ComponentManager.getGroups();
            List<Component> components = ComponentManager.getComponentsByGroup();
            handCursor = new Cursor(Display.getDefault(), SWT.CURSOR_HAND);
            // initialize composites.
            RowLayout rowLayout = new RowLayout();
            rowLayout.pack = false;
            int i = 0;
            Iterator<String> iterator = categories.iterator();
            composites = new Composite[categories.size()];
            items = new ExpandItem[categories.size()];
            while (iterator.hasNext()) {
                composites[i] = new Composite(bar, SWT.NONE);
                composites[i].setLayout(rowLayout);
                composites[i].setBackground(bar.getBackground());
                items[i] = new ExpandItem(bar, SWT.NONE, i);
                items[i].setControl(composites[i]);
                items[i].setExpanded(true);
                items[i].setText(iterator.next());
                i++;
            }
            boolean bSelected = true;
            for (Component c : components) {
                boolean isAllowed = isAllowed(c);
                boolean isMatching = searchText.isEmpty() || c.getLabel().toLowerCase().indexOf(searchText.toLowerCase()) != -1 || c.getTag().startsWith(searchText.toLowerCase());
                if (isAllowed && isMatching) {
                    addLabelEx(c, bSelected);
                    bSelected = false;
                }
            }
            for (ExpandItem expandItem : bar.getItems()) {
                Point size = expandItem.getControl().getSize();
                if (size.x == 0) {
                    // case of first time composite view is shown
                    size = expandItem.getControl().computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
                    size.x -= scrolledComposite.getVerticalBar().getSize().x;
                }
                Point size2 = expandItem.getControl().computeSize(size.x, SWT.DEFAULT);
                expandItem.setHeight(size2.y);
            }
            // We select by default the first item if no default dbo found.
            if (currentSelectedObject == null && composites[0].getChildren().length > 0) {
                currentSelectedObject = (CLabel) composites[0].getChildren()[0];
            }
            for (ExpandItem expandItem : bar.getItems()) {
                if (((Composite) expandItem.getControl()).getChildren().length == 0) {
                    expandItem.getControl().dispose();
                    expandItem.dispose();
                }
            }
            Component currentSelectedComponent = getCurrentSelectedComponent();
            if (currentSelectedComponent != null) {
                updateHelpText(currentSelectedComponent);
            }
            if (currentSelectedObject != null && !currentSelectedObject.isDisposed()) {
                currentSelectedObject.setForeground(FOREGROUND_SELECTED_COLOR);
                currentSelectedObject.setBackground(BACKGROUND_SELECTED_COLOR);
            }
        } catch (Exception e) {
            ConvertigoPlugin.logException(e, "Unable to load component objects.");
        }
    }
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) Point(org.eclipse.swt.graphics.Point) Cursor(org.eclipse.swt.graphics.Cursor) Point(org.eclipse.swt.graphics.Point) ExpandItem(org.eclipse.swt.widgets.ExpandItem) RowLayout(org.eclipse.swt.layout.RowLayout) Component(com.twinsoft.convertigo.beans.mobile.components.dynamic.Component)

Example 2 with Component

use of com.twinsoft.convertigo.beans.mobile.components.dynamic.Component in project convertigo by convertigo.

the class ComponentExplorerComposite method addLabelEx.

private void addLabelEx(Component component, boolean bSelected) {
    String category = component.getGroup();
    if ("".equals(category)) {
        composite = composites[0];
    } else {
        for (int i = 0; i < items.length; i++) {
            if (items[i].getText().equals(category)) {
                composite = composites[i];
            }
        }
    }
    final CLabel label = new CLabel(composite, SWT.NONE);
    Image image = null;
    try {
        image = ConvertigoPlugin.getDefault().getIconFromPath(component.getImagePath(), BeanInfo.ICON_COLOR_32x32);
    } catch (Exception e) {
    }
    label.setImage(image);
    label.setText(component.getLabel());
    label.setAlignment(SWT.LEFT);
    label.setToolTipText(RegexpUtils.removeTag.matcher(getShortDescription(component)).replaceAll(""));
    label.setCursor(handCursor);
    label.setLayoutData(new RowData());
    objectsMap.put(label, component);
    if (bSelected) {
        currentSelectedObject = label;
    }
    // DND support for Mobile palette
    if (wizardPage == null) {
        Transfer[] types = new Transfer[] { PaletteSourceTransfer.getInstance() };
        int operations = DND.DROP_COPY | DND.DROP_MOVE;
        DragSource source = new DragSource(label, operations);
        source.setTransfer(types);
        source.addDragListener(new DragSourceAdapter() {

            @Override
            public void dragStart(DragSourceEvent event) {
                try {
                    if (currentSelectedObject != null && !currentSelectedObject.isDisposed()) {
                        currentSelectedObject.setForeground(label.getForeground());
                        currentSelectedObject.setBackground(label.getBackground());
                    }
                    currentSelectedObject = label;
                    currentSelectedObject.setForeground(FOREGROUND_SELECTED_COLOR);
                    currentSelectedObject.setBackground(BACKGROUND_SELECTED_COLOR);
                    Component c = (Component) objectsMap.get(label);
                    DatabaseObject dbo = ComponentManager.createBean(c);
                    if (dbo != null) {
                        String sXml = ClipboardAction.dnd.copy(dbo);
                        if (sXml != null) {
                            event.doit = true;
                            PaletteSourceTransfer.getInstance().setPaletteSource(new PaletteSource(sXml));
                        }
                    } else {
                        throw new Exception("Invalid database object : null");
                    }
                } catch (Exception e) {
                    ConvertigoPlugin.logException(e, "Cannot drag");
                }
            }
        });
    }
    label.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseUp(MouseEvent e) {
            CLabel label = (CLabel) e.getSource();
            if (currentSelectedObject == label)
                return;
            if (currentSelectedObject != null && !currentSelectedObject.isDisposed()) {
                currentSelectedObject.setForeground(label.getForeground());
                currentSelectedObject.setBackground(label.getBackground());
            }
            currentSelectedObject = (CLabel) e.getSource();
            ConvertigoPlugin.logDebug("currentSelectedObject: '" + currentSelectedObject.getText() + "'.");
            currentSelectedObject.setForeground(FOREGROUND_SELECTED_COLOR);
            currentSelectedObject.setBackground(BACKGROUND_SELECTED_COLOR);
            Component currentSelectedComponent = getCurrentSelectedComponent();
            if (currentSelectedComponent != null) {
                updateHelpText(currentSelectedComponent);
            }
        }

        @Override
        public void mouseDoubleClick(MouseEvent e) {
            currentSelectedObject = (CLabel) e.getSource();
            if (wizardPage != null) {
                wizardPage.setPageComplete(true);
                ((ComponentExplorerWizardPage) wizardPage).showNextPage();
            }
        }
    });
    ConvertigoPlugin.logDebug("Loaded '" + component.getLabel() + "'.");
}
Also used : CLabel(org.eclipse.swt.custom.CLabel) DragSourceAdapter(org.eclipse.swt.dnd.DragSourceAdapter) MouseEvent(org.eclipse.swt.events.MouseEvent) MouseAdapter(org.eclipse.swt.events.MouseAdapter) DragSource(org.eclipse.swt.dnd.DragSource) Image(org.eclipse.swt.graphics.Image) Point(org.eclipse.swt.graphics.Point) DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) RowData(org.eclipse.swt.layout.RowData) Transfer(org.eclipse.swt.dnd.Transfer) PaletteSourceTransfer(com.twinsoft.convertigo.eclipse.dnd.PaletteSourceTransfer) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) PaletteSource(com.twinsoft.convertigo.eclipse.dnd.PaletteSource) Component(com.twinsoft.convertigo.beans.mobile.components.dynamic.Component)

Example 3 with Component

use of com.twinsoft.convertigo.beans.mobile.components.dynamic.Component in project convertigo by convertigo.

the class BeansDoc method generateMobileComponentsMd.

private void generateMobileComponentsMd(File outputDirectory) {
    List<Component> grpBeans = ComponentManager.getComponentsByGroup();
    Map<String, IonBean> map = ComponentManager.getIonBeans();
    for (Component beanMB : grpBeans) {
        String grpName = beanMB.getGroup();
        String objName = beanMB.getName();
        String objLabel = beanMB.getLabel();
        String imgPath = beanMB.getImagePath();
        String imgPathNormalized = imgPath.replaceFirst("/com/twinsoft/convertigo/beans/", "");
        // We are changing it if the bean is not an IonBean just below
        String classPathNormalized = "ion_objects.json";
        String grpNameNormalized = grpName;
        Boolean isIonBean = false;
        // If it is we set isIonBean to true;
        for (Map.Entry<String, IonBean> ionbean : map.entrySet()) {
            if (objName == ionbean.getKey()) {
                isIonBean = true;
            }
        }
        // If this bean is not an IonBean we simply add this class
        if (isIonBean == false) {
            classPathNormalized = "com.twinsoft.convertigo.beans.mobile.components.res." + objName;
        }
        if (!grpName.contains("Components")) {
            grpNameNormalized = grpName.concat(" Components");
        }
        grpNameNormalized = mbNormalize(grpNameNormalized);
        String objLabelNormalized = mbNormalize(objLabel);
        String path = "/mobile-application/components/" + grpNameNormalized + "/";
        String permalink = "reference-manual/convertigo-objects" + path + objLabelNormalized + "/";
        String metadesc = beanMB.getDescription();
        metadesc = metadesc.replaceAll("<[a-zA-Z]*>|<\\/[a-zA-Z]*>|<br\\/>", " ");
        metadesc = metadesc.replaceAll(":", " ");
        metadesc = metadesc.replaceAll("\\|", " ");
        if (metadesc.length() >= 150)
            metadesc = metadesc.substring(0, 150);
        StringBuilder sb = new StringBuilder();
        sb.append("---\n" + "layout: page\n" + "title: " + objLabel + "\n" + "sidebar: c8o_sidebar\n" + "permalink: " + permalink + "\n" + "metadesc: " + metadesc + "\n" + "ObjGroup: " + grpName + "\n" + "ObjCatName: " + grpNameNormalized + "\n" + "ObjName: " + objName + "\n" + "ObjClass: " + classPathNormalized + "\n" + "ObjIcon: /images/beans/" + imgPathNormalized + "\n" + "topnav: topnavobj" + "\n" + "---\n");
        String description = beanMB.getDescription();
        description = description.replaceAll("\\|", "<br/>\n");
        description = description.replaceAll("<br\\/>", "<br/>\n");
        description = description.replaceAll("Defines| Defines", "##### Defines");
        sb.append(description + "\n\n");
        // Prepare properties to create a markdown table
        String properties = beanMB.getPropertiesDescription();
        properties = properties.replaceAll("</i></br>", " | ");
        properties = properties.replaceAll("<ul>|</ul>", "");
        properties = properties.replaceAll("<li><i>", "");
        properties = properties.replaceAll("</li>", "\n");
        if (!properties.isEmpty()) {
            sb.append("Name | Description \n");
            sb.append("--- | ---\n");
            sb.append(properties + "\n");
        }
        String toWrite = sb.toString();
        if (!"\n".equals(System.lineSeparator())) {
            toWrite = toWrite.replace("\n", System.lineSeparator());
        }
        try (InputStream is = getClass().getResourceAsStream(imgPath)) {
            System.out.println("imgPath : " + imgPath);
            String imgPathModified = imgPath.replaceFirst(".*\\w\\/beans", "");
            FileUtils.copyInputStreamToFile(is, new File(imageDirectory, imgPathModified));
            System.out.println("Image generated at : " + imageDirectory + imgPathModified);
        } catch (Exception e) {
            System.out.println("Unable to copy the image file");
        }
        try {
            FileUtils.write(new File(outputDirectory, path + objLabelNormalized + ".md"), toWrite, "UTF-8");
            System.out.println("Generated md for : " + objLabel);
        } catch (IOException e) {
            System.out.println("Unable to write the file");
        }
    }
}
Also used : IonBean(com.twinsoft.convertigo.beans.mobile.components.dynamic.IonBean) InputStream(java.io.InputStream) IOException(java.io.IOException) IOException(java.io.IOException) Component(com.twinsoft.convertigo.beans.mobile.components.dynamic.Component) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap) File(java.io.File)

Aggregations

Component (com.twinsoft.convertigo.beans.mobile.components.dynamic.Component)3 Point (org.eclipse.swt.graphics.Point)2 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)1 IonBean (com.twinsoft.convertigo.beans.mobile.components.dynamic.IonBean)1 PaletteSource (com.twinsoft.convertigo.eclipse.dnd.PaletteSource)1 PaletteSourceTransfer (com.twinsoft.convertigo.eclipse.dnd.PaletteSourceTransfer)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1 CLabel (org.eclipse.swt.custom.CLabel)1 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)1 DragSource (org.eclipse.swt.dnd.DragSource)1 DragSourceAdapter (org.eclipse.swt.dnd.DragSourceAdapter)1 DragSourceEvent (org.eclipse.swt.dnd.DragSourceEvent)1 Transfer (org.eclipse.swt.dnd.Transfer)1 MouseAdapter (org.eclipse.swt.events.MouseAdapter)1