Search in sources :

Example 1 with PaletteSource

use of com.twinsoft.convertigo.eclipse.dnd.PaletteSource 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)

Example 2 with PaletteSource

use of com.twinsoft.convertigo.eclipse.dnd.PaletteSource 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)

Aggregations

DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)2 PaletteSource (com.twinsoft.convertigo.eclipse.dnd.PaletteSource)2 PaletteSourceTransfer (com.twinsoft.convertigo.eclipse.dnd.PaletteSourceTransfer)2 CLabel (org.eclipse.swt.custom.CLabel)2 DragSource (org.eclipse.swt.dnd.DragSource)2 DragSourceAdapter (org.eclipse.swt.dnd.DragSourceAdapter)2 DragSourceEvent (org.eclipse.swt.dnd.DragSourceEvent)2 Transfer (org.eclipse.swt.dnd.Transfer)2 MouseAdapter (org.eclipse.swt.events.MouseAdapter)2 MouseEvent (org.eclipse.swt.events.MouseEvent)2 Image (org.eclipse.swt.graphics.Image)2 Point (org.eclipse.swt.graphics.Point)2 RowData (org.eclipse.swt.layout.RowData)2 Component (com.twinsoft.convertigo.beans.mobile.components.dynamic.Component)1 Component (com.twinsoft.convertigo.beans.ngx.components.dynamic.Component)1