Search in sources :

Example 1 with Component

use of com.twinsoft.convertigo.beans.ngx.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.ngx.components.dynamic.Component)

Example 2 with Component

use of com.twinsoft.convertigo.beans.ngx.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.createBeanFromHint(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.ngx.components.dynamic.Component)

Aggregations

Component (com.twinsoft.convertigo.beans.ngx.components.dynamic.Component)2 Point (org.eclipse.swt.graphics.Point)2 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)1 PaletteSource (com.twinsoft.convertigo.eclipse.dnd.PaletteSource)1 PaletteSourceTransfer (com.twinsoft.convertigo.eclipse.dnd.PaletteSourceTransfer)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 MouseEvent (org.eclipse.swt.events.MouseEvent)1 Cursor (org.eclipse.swt.graphics.Cursor)1 Image (org.eclipse.swt.graphics.Image)1 RowData (org.eclipse.swt.layout.RowData)1 RowLayout (org.eclipse.swt.layout.RowLayout)1 Composite (org.eclipse.swt.widgets.Composite)1 ExpandItem (org.eclipse.swt.widgets.ExpandItem)1