Search in sources :

Example 1 with MobileSmartSourcePropertyDescriptor

use of com.twinsoft.convertigo.eclipse.property_editors.MobileSmartSourcePropertyDescriptor in project convertigo by convertigo.

the class TreeDropAdapter method performDrop.

private void performDrop(Object data, final ProjectExplorerView explorerView, TreeObject targetTreeObject) throws EngineException, IOException {
    boolean needReload = false;
    final DatabaseObject dbo;
    if (data instanceof String) {
        String source = data.toString();
        if (targetTreeObject instanceof ObjectsFolderTreeObject) {
            ObjectsFolderTreeObject folderTreeObject = (ObjectsFolderTreeObject) targetTreeObject;
            dbo = (DatabaseObject) folderTreeObject.getParent().getObject();
            switch(folderTreeObject.folderType) {
                case ObjectsFolderTreeObject.FOLDER_TYPE_CRITERIAS:
                    if (dbo instanceof HtmlScreenClass) {
                        // Creates a XPath criteria for this screen class
                        if (!dbo.equals(((HtmlConnector) dbo.getConnector()).getDefaultScreenClass())) {
                            ((HtmlScreenClass) dbo).addCriteria(createXPath(source));
                            needReload = true;
                        }
                    }
                    break;
                case ObjectsFolderTreeObject.FOLDER_TYPE_INHERITED_SCREEN_CLASSES:
                    if (dbo instanceof HtmlScreenClass) {
                        // Creates an inherited screen class with an XPath criteria for this screen class
                        HtmlScreenClass newSc = createHtmlScreenClass(dbo.priority + 1);
                        ((HtmlScreenClass) dbo).addInheritedScreenClass(newSc);
                        newSc.addCriteria(createXPath(source));
                        needReload = true;
                    }
                    break;
                case ObjectsFolderTreeObject.FOLDER_TYPE_EXTRACTION_RULES:
                    if (dbo instanceof HtmlScreenClass) {
                        NewObjectWizard newObjectWizard = new NewObjectWizard(dbo, "com.twinsoft.convertigo.beans.core.ExtractionRule", source, null);
                        WizardDialog wzdlg = new WizardDialog(Display.getDefault().getActiveShell(), newObjectWizard);
                        wzdlg.setPageSize(850, 650);
                        wzdlg.open();
                        needReload = true;
                    }
                    break;
                default:
                    break;
            }
            if (needReload)
                reloadTreeObject(explorerView, folderTreeObject.getParent());
        } else if (targetTreeObject instanceof DatabaseObjectTreeObject) {
            DatabaseObjectTreeObject databaseObjectTreeObject = (DatabaseObjectTreeObject) targetTreeObject;
            dbo = (DatabaseObject) targetTreeObject.getObject();
            if (databaseObjectTreeObject instanceof ScreenClassTreeObject) {
                if (dbo instanceof HtmlScreenClass) {
                    // Creates an inherited screen class with an XPath criteria for this screen class
                    HtmlScreenClass newSc = createHtmlScreenClass(dbo.priority + 1);
                    ((HtmlScreenClass) dbo).addInheritedScreenClass(newSc);
                    newSc.addCriteria(createXPath(source));
                    needReload = true;
                }
            } else if (dbo instanceof IXPathable) {
                // Set XPath property
                if (dbo instanceof XpathableStatement)
                    ((XpathableStatement) dbo).setPureXpath(source);
                else
                    ((IXPathable) dbo).setXpath(source);
                ((DatabaseObject) dbo).hasChanged = true;
                needReload = true;
            }
            if (needReload)
                reloadTreeObject(explorerView, databaseObjectTreeObject);
        } else if (targetTreeObject instanceof IPropertyTreeObject) {
            IPropertyTreeObject pto = null;
            if (detail == DND.DROP_MOVE) {
                // Set XPath property
                if (targetTreeObject instanceof IXPathable) {
                    ((IXPathable) targetTreeObject).setXpath("." + source);
                    needReload = true;
                } else // Add new row with xpath
                if (targetTreeObject instanceof PropertyTableTreeObject) {
                    // // See Ticket #679 : Drag and drop without Control
                    // PropertyTableTreeObject description = (PropertyTableTreeObject)targetTreeObject;
                    // pto = description.addNewRow();
                    // needReload = true;
                    // if ((pto != null) && (pto instanceof IXPathable)) {
                    // ((IXPathable)pto).setXpath("."+source);
                    // }
                    String label = ((PropertyTableTreeObject) targetTreeObject).getRowDefaultLabel().toLowerCase();
                    throw new EngineException("Please hold on the 'Ctrl' key while dragging to create a new " + label);
                }
            } else if (detail == DND.DROP_COPY) {
                // Add new row with xpath
                if (targetTreeObject instanceof PropertyTableTreeObject) {
                    PropertyTableTreeObject description = (PropertyTableTreeObject) targetTreeObject;
                    pto = description.addNewRow();
                    needReload = true;
                    if ((pto != null) && (pto instanceof IXPathable)) {
                        ((IXPathable) pto).setXpath("." + source);
                    }
                } else // Add new column with xpath
                if (targetTreeObject instanceof PropertyTableRowTreeObject) {
                    PropertyTableRowTreeObject row = (PropertyTableRowTreeObject) targetTreeObject;
                    pto = row.addNewColumn();
                    needReload = true;
                    if ((pto != null) && (pto instanceof IXPathable)) {
                        ((IXPathable) pto).setXpath("." + source);
                    }
                }
            }
            if (needReload) {
                pto = (pto == null) ? (IPropertyTreeObject) targetTreeObject : pto;
                targetTreeObject = ((IPropertyTreeObject) targetTreeObject).getTreeObjectOwner();
                if (targetTreeObject instanceof DatabaseObjectTreeObject) {
                    // reloadTreeObject(explorerView, targetTreeObject);
                    TreeParent treeParent = targetTreeObject.getParent();
                    if (treeParent instanceof FolderTreeObject)
                        treeParent = treeParent.getParent();
                    explorerView.objectChanged(new CompositeEvent(treeParent.getObject(), pto.getPath()));
                }
            }
        }
    } else if (data instanceof StepSource) {
        if (targetTreeObject instanceof DatabaseObjectTreeObject) {
            final DatabaseObjectTreeObject databaseObjectTreeObject = (DatabaseObjectTreeObject) targetTreeObject;
            dbo = (DatabaseObject) targetTreeObject.getObject();
            final Set<PropertyDescriptor> propertyDescriptors = new TreeSet<PropertyDescriptor>(new Comparator<PropertyDescriptor>() {

                @Override
                public int compare(PropertyDescriptor o1, PropertyDescriptor o2) {
                    return o1.getDisplayName().compareTo(o2.getDisplayName());
                }
            });
            propertyDescriptors.addAll(CachedIntrospector.getPropertyDescriptors(dbo, Property.smartType));
            propertyDescriptors.addAll(CachedIntrospector.getPropertyDescriptors(dbo, Property.sourceDefinition));
            propertyDescriptors.addAll(CachedIntrospector.getPropertyDescriptors(dbo, Property.sourcesDefinition));
            if (!propertyDescriptors.isEmpty()) {
                // Retrieve Source definition
                final XMLVector<String> sourceDefinition = new XMLVector<String>(2);
                sourceDefinition.add(((StepSource) data).getPriority());
                sourceDefinition.add(((StepSource) data).getXpath());
                SelectionListener selectionListener = new SelectionListener() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        PropertyDescriptor propertyDescriptor = (e == null) ? propertyDescriptors.iterator().next() : (PropertyDescriptor) e.widget.getData();
                        String propertyName = propertyDescriptor.getName();
                        if (propertyDescriptor.getPropertyType().isAssignableFrom(SmartType.class)) {
                            SmartType smartType = new SmartType();
                            smartType.setMode(Mode.SOURCE);
                            smartType.setSourceDefinition(sourceDefinition);
                            databaseObjectTreeObject.setPropertyValue(propertyDescriptor.getName(), smartType);
                        } else if (propertyName.equals("sourceDefinition")) {
                            // Use setPropertyValue in order to set object's value and fire necessary events
                            databaseObjectTreeObject.setPropertyValue(propertyDescriptor.getName(), sourceDefinition);
                        } else if (propertyName.equals("sourcesDefinition")) {
                            try {
                                XMLVector<XMLVector<Object>> sourcesDefinition = GenericUtils.cast(propertyDescriptor.getReadMethod().invoke(dbo));
                                // make a copy to make a property change
                                sourcesDefinition = new XMLVector<XMLVector<Object>>(sourcesDefinition);
                                XMLVector<Object> row = new XMLVector<Object>();
                                row.add("");
                                row.add(sourceDefinition);
                                row.add("");
                                sourcesDefinition.add(row);
                                databaseObjectTreeObject.setPropertyValue(propertyName, sourcesDefinition);
                            } catch (Exception ex) {
                                ConvertigoPlugin.logError("failed to add to sourcesDefinition of " + dbo.getName());
                            }
                        }
                        // Properties view needs to be refreshed
                        refreshPropertiesView(explorerView, databaseObjectTreeObject);
                    }

                    @Override
                    public void widgetDefaultSelected(SelectionEvent e) {
                    }
                };
                if (propertyDescriptors.size() == 1) {
                    selectionListener.widgetSelected(null);
                } else {
                    Shell shell = ConvertigoPlugin.getMainShell();
                    Menu dropMenu = new Menu(shell, SWT.POP_UP);
                    shell.setMenu(dropMenu);
                    for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
                        MenuItem itemCheck = new MenuItem(dropMenu, SWT.NONE);
                        itemCheck.setText(propertyDescriptor.getDisplayName());
                        itemCheck.setData(propertyDescriptor);
                        itemCheck.addSelectionListener(selectionListener);
                    }
                    dropMenu.setVisible(true);
                }
            }
        }
    } else if (data instanceof PaletteSource) {
        try {
            if (targetTreeObject instanceof ObjectsFolderTreeObject) {
                ObjectsFolderTreeObject folderTreeObject = (ObjectsFolderTreeObject) targetTreeObject;
                targetTreeObject = folderTreeObject.getParent();
            }
            if (targetTreeObject instanceof DatabaseObjectTreeObject) {
                DatabaseObject parent = (DatabaseObject) targetTreeObject.getObject();
                String xmlData = ((PaletteSource) data).getXmlData();
                Document document = XMLUtils.getDefaultDocumentBuilder().parse(new InputSource(new StringReader(xmlData)));
                Element rootElement = document.getDocumentElement();
                NodeList nodeList = rootElement.getChildNodes();
                int len = nodeList.getLength();
                Node node;
                // Special objects move from palette
                if (detail == DND.DROP_MOVE) {
                    for (int i = 0; i < len; i++) {
                        node = (Node) nodeList.item(i);
                        if (node.getNodeType() != Node.TEXT_NODE) {
                            if (paste(node, parent, true) == null) {
                                throw new Exception();
                            }
                        }
                    }
                    reloadTreeObject(explorerView, targetTreeObject);
                }
            } else {
                throw new Exception();
            }
        } catch (Exception ex) {
            ConvertigoPlugin.logError("failed to add from palette");
        }
    } else if (data instanceof MobileSource) {
        try {
            String jsonString = ((MobileSource) data).getJsonString();
            if (targetTreeObject instanceof MobileUIComponentTreeObject) {
                Shell shell = ConvertigoPlugin.getMainShell();
                Menu dropMenu = new Menu(shell, SWT.POP_UP);
                shell.setMenu(dropMenu);
                MobileUIComponentTreeObject mcto = GenericUtils.cast(targetTreeObject);
                for (IPropertyDescriptor descriptor : mcto.getPropertyDescriptors()) {
                    if (descriptor instanceof MobileSmartSourcePropertyDescriptor) {
                        MobileSmartSourcePropertyDescriptor cspd = GenericUtils.cast(descriptor);
                        if (!cspd.isReadOnly()) {
                            String propertyName = (String) cspd.getId();
                            String propertyLabel = (String) cspd.getDisplayName();
                            MenuItem itemCheck = new MenuItem(dropMenu, SWT.NONE);
                            itemCheck.setText(propertyLabel);
                            itemCheck.addSelectionListener(new SelectionListener() {

                                @Override
                                public void widgetSelected(SelectionEvent e) {
                                    com.twinsoft.convertigo.beans.mobile.components.MobileSmartSourceType cst = new com.twinsoft.convertigo.beans.mobile.components.MobileSmartSourceType();
                                    cst.setMode(com.twinsoft.convertigo.beans.mobile.components.MobileSmartSourceType.Mode.SOURCE);
                                    cst.setSmartValue(jsonString);
                                    mcto.setPropertyValue(propertyName, cst);
                                    refreshPropertiesView(explorerView, mcto);
                                }

                                @Override
                                public void widgetDefaultSelected(SelectionEvent e) {
                                }
                            });
                        }
                    }
                }
                dropMenu.setVisible(true);
            }
            if (targetTreeObject instanceof NgxUIComponentTreeObject) {
                Shell shell = ConvertigoPlugin.getMainShell();
                Menu dropMenu = new Menu(shell, SWT.POP_UP);
                shell.setMenu(dropMenu);
                NgxUIComponentTreeObject mcto = GenericUtils.cast(targetTreeObject);
                for (IPropertyDescriptor descriptor : mcto.getPropertyDescriptors()) {
                    if (descriptor instanceof NgxSmartSourcePropertyDescriptor) {
                        NgxSmartSourcePropertyDescriptor cspd = GenericUtils.cast(descriptor);
                        if (!cspd.isReadOnly()) {
                            String propertyName = (String) cspd.getId();
                            String propertyLabel = (String) cspd.getDisplayName();
                            MenuItem itemCheck = new MenuItem(dropMenu, SWT.NONE);
                            itemCheck.setText(propertyLabel);
                            itemCheck.addSelectionListener(new SelectionListener() {

                                @Override
                                public void widgetSelected(SelectionEvent e) {
                                    com.twinsoft.convertigo.beans.ngx.components.MobileSmartSourceType cst = new com.twinsoft.convertigo.beans.ngx.components.MobileSmartSourceType();
                                    cst.setMode(com.twinsoft.convertigo.beans.ngx.components.MobileSmartSourceType.Mode.SOURCE);
                                    cst.setSmartValue(jsonString);
                                    mcto.setPropertyValue(propertyName, cst);
                                    refreshPropertiesView(explorerView, mcto);
                                }

                                @Override
                                public void widgetDefaultSelected(SelectionEvent e) {
                                }
                            });
                        }
                    }
                }
                dropMenu.setVisible(true);
            } else {
                throw new Exception();
            }
        } catch (Exception ex) {
            ConvertigoPlugin.logError("failed to add mobile source");
        }
    }
}
Also used : PropertyTableRowTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.PropertyTableRowTreeObject) NgxUIComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.NgxUIComponentTreeObject) InputSource(org.xml.sax.InputSource) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) XMLVector(com.twinsoft.convertigo.beans.common.XMLVector) Node(org.w3c.dom.Node) EngineException(com.twinsoft.convertigo.engine.EngineException) Document(org.w3c.dom.Document) Comparator(java.util.Comparator) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) HtmlScreenClass(com.twinsoft.convertigo.beans.screenclasses.HtmlScreenClass) IXPathable(com.twinsoft.convertigo.beans.core.IXPathable) NodeList(org.w3c.dom.NodeList) MobileUIComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileUIComponentTreeObject) PropertyTableRowTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.PropertyTableRowTreeObject) NgxComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.NgxComponentTreeObject) IOrderableTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IOrderableTreeObject) FolderTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.FolderTreeObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) ObjectsFolderTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ObjectsFolderTreeObject) NgxUIComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.NgxUIComponentTreeObject) MobileUIComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileUIComponentTreeObject) IPropertyTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IPropertyTreeObject) RequestableObject(com.twinsoft.convertigo.beans.core.RequestableObject) PropertyTableTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.PropertyTableTreeObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) ScreenClassTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ScreenClassTreeObject) MobileComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileComponentTreeObject) SelectionListener(org.eclipse.swt.events.SelectionListener) Set(java.util.Set) TreeSet(java.util.TreeSet) MobileSmartSourcePropertyDescriptor(com.twinsoft.convertigo.eclipse.property_editors.MobileSmartSourcePropertyDescriptor) TreeParent(com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeParent) Element(org.w3c.dom.Element) NgxSmartSourcePropertyDescriptor(com.twinsoft.convertigo.eclipse.property_editors.NgxSmartSourcePropertyDescriptor) ObjectsFolderTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ObjectsFolderTreeObject) NewObjectWizard(com.twinsoft.convertigo.eclipse.wizards.new_object.NewObjectWizard) Shell(org.eclipse.swt.widgets.Shell) StringReader(java.io.StringReader) Menu(org.eclipse.swt.widgets.Menu) SmartType(com.twinsoft.convertigo.beans.steps.SmartType) CompositeEvent(com.twinsoft.convertigo.eclipse.editors.CompositeEvent) XpathableStatement(com.twinsoft.convertigo.beans.statements.XpathableStatement) HtmlConnector(com.twinsoft.convertigo.beans.connectors.HtmlConnector) PropertyDescriptor(java.beans.PropertyDescriptor) NgxSmartSourcePropertyDescriptor(com.twinsoft.convertigo.eclipse.property_editors.NgxSmartSourcePropertyDescriptor) MobileSmartSourcePropertyDescriptor(com.twinsoft.convertigo.eclipse.property_editors.MobileSmartSourcePropertyDescriptor) IPropertyDescriptor(org.eclipse.ui.views.properties.IPropertyDescriptor) MenuItem(org.eclipse.swt.widgets.MenuItem) IOException(java.io.IOException) ObjectWithSameNameException(com.twinsoft.convertigo.engine.ObjectWithSameNameException) SAXException(org.xml.sax.SAXException) EngineException(com.twinsoft.convertigo.engine.EngineException) InvalidOperationException(com.twinsoft.convertigo.engine.InvalidOperationException) ScreenClassTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ScreenClassTreeObject) IPropertyDescriptor(org.eclipse.ui.views.properties.IPropertyDescriptor) FolderTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.FolderTreeObject) ObjectsFolderTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ObjectsFolderTreeObject) WizardDialog(org.eclipse.jface.wizard.WizardDialog) PropertyTableTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.PropertyTableTreeObject) IPropertyTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IPropertyTreeObject)

Example 2 with MobileSmartSourcePropertyDescriptor

use of com.twinsoft.convertigo.eclipse.property_editors.MobileSmartSourcePropertyDescriptor in project convertigo by convertigo.

the class MobileUIComponentTreeObject method getDynamicPropertyDescriptors.

@Override
protected List<PropertyDescriptor> getDynamicPropertyDescriptors() {
    List<PropertyDescriptor> l = super.getDynamicPropertyDescriptors();
    DatabaseObject dbo = getObject();
    if (dbo instanceof UIDynamicElement) {
        IonBean ionBean = ((UIDynamicElement) dbo).getIonBean();
        if (ionBean != null) {
            for (IonProperty property : ionBean.getProperties().values()) {
                String id = property.getName();
                String displayName = property.getLabel();
                String editor = property.getEditor();
                Object[] values = property.getValues();
                int len = values.length;
                if (property.isHidden()) {
                    continue;
                }
                PropertyDescriptor propertyDescriptor = null;
                if (editor.isEmpty()) {
                    if (len == 0) {
                        propertyDescriptor = new TextPropertyDescriptor(id, displayName);
                    } else if (len == 1) {
                        propertyDescriptor = new PropertyDescriptor(id, displayName);
                    } else {
                        boolean isEditable = values[len - 1].equals(true);
                        int size = isEditable ? len - 1 : len;
                        String[] tags = new String[size];
                        for (int i = 0; i < size; i++) {
                            Object value = values[i];
                            tags[i] = value.equals(false) ? "not set" : value.toString();
                        }
                        // propertyDescriptor = new StringComboBoxPropertyDescriptor(id, displayName, tags, !isEditable);
                        propertyDescriptor = new MobileSmartSourcePropertyDescriptor(id, displayName, tags, !isEditable);
                        ((MobileSmartSourcePropertyDescriptor) propertyDescriptor).databaseObjectTreeObject = this;
                    }
                } else {
                    if (editor.equals("StringComboBoxPropertyDescriptor")) {
                        try {
                            Class<?> c = Class.forName("com.twinsoft.convertigo.eclipse.property_editors." + editor);
                            Method getTags = c.getDeclaredMethod("getTags", new Class[] { DatabaseObjectTreeObject.class, String.class });
                            String[] tags = (String[]) getTags.invoke(null, new Object[] { this, id });
                            propertyDescriptor = new StringComboBoxPropertyDescriptor(id, displayName, tags, true);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    } else {
                        propertyDescriptor = new PropertyDescriptor(id, displayName) {

                            @Override
                            public CellEditor createPropertyEditor(Composite parent) {
                                CellEditor cellEditor = null;
                                try {
                                    Class<?> c = Class.forName("com.twinsoft.convertigo.eclipse.property_editors." + editor);
                                    cellEditor = (CellEditor) c.getConstructor(Composite.class).newInstance(parent);
                                    if (cellEditor instanceof AbstractDialogCellEditor) {
                                        ((AbstractDialogCellEditor) cellEditor).databaseObjectTreeObject = MobileUIComponentTreeObject.this;
                                        ((AbstractDialogCellEditor) cellEditor).propertyDescriptor = this;
                                    }
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                                return cellEditor;
                            }
                        };
                    }
                }
                propertyDescriptor.setCategory(property.getCategory());
                propertyDescriptor.setDescription(cleanDescription(property.getDescription()));
                propertyDescriptor.setValidator(getValidator(id));
                l.add(propertyDescriptor);
            }
        }
    }
    return l;
}
Also used : IonProperty(com.twinsoft.convertigo.beans.mobile.components.dynamic.IonProperty) PropertyDescriptor(org.eclipse.ui.views.properties.PropertyDescriptor) StringComboBoxPropertyDescriptor(com.twinsoft.convertigo.eclipse.property_editors.StringComboBoxPropertyDescriptor) MobileSmartSourcePropertyDescriptor(com.twinsoft.convertigo.eclipse.property_editors.MobileSmartSourcePropertyDescriptor) TextPropertyDescriptor(org.eclipse.ui.views.properties.TextPropertyDescriptor) MobileSmartSourcePropertyDescriptor(com.twinsoft.convertigo.eclipse.property_editors.MobileSmartSourcePropertyDescriptor) Composite(org.eclipse.swt.widgets.Composite) IonBean(com.twinsoft.convertigo.beans.mobile.components.dynamic.IonBean) CellEditor(org.eclipse.jface.viewers.CellEditor) AbstractDialogCellEditor(com.twinsoft.convertigo.eclipse.property_editors.AbstractDialogCellEditor) UIDynamicElement(com.twinsoft.convertigo.beans.mobile.components.UIDynamicElement) Method(java.lang.reflect.Method) CoreException(org.eclipse.core.runtime.CoreException) EngineException(com.twinsoft.convertigo.engine.EngineException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) AbstractDialogCellEditor(com.twinsoft.convertigo.eclipse.property_editors.AbstractDialogCellEditor) StringComboBoxPropertyDescriptor(com.twinsoft.convertigo.eclipse.property_editors.StringComboBoxPropertyDescriptor) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) TextPropertyDescriptor(org.eclipse.ui.views.properties.TextPropertyDescriptor)

Example 3 with MobileSmartSourcePropertyDescriptor

use of com.twinsoft.convertigo.eclipse.property_editors.MobileSmartSourcePropertyDescriptor in project convertigo by convertigo.

the class TreeDropAdapter method validateDrop.

/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.ViewerDropAdapter#validateDrop(java.lang.Object, int, org.eclipse.swt.dnd.TransferData)
	 */
@Override
public boolean validateDrop(Object target, int operation, TransferData transferType) {
    if (TextTransfer.getInstance().isSupportedType(transferType)) {
        if (getCurrentOperation() == DND.DROP_MOVE) {
            Object targetObject = getCurrentTarget();
            Object sourceObject = getSelectedObject();
            if (targetObject != null && targetObject instanceof TreeObject) {
                TreeObject targetTreeObject = (TreeObject) targetObject;
                if (sourceObject != null && sourceObject instanceof TreeObject) {
                    TreeObject sourceTreeObject = (TreeObject) sourceObject;
                    boolean isFocus = sourceTreeObject.viewer.getControl().isFocusControl();
                    if (isFocus && (sourceObject == targetObject || targetTreeObject.isChildOf(sourceTreeObject))) {
                        return false;
                    }
                }
                if (targetObject instanceof DatabaseObjectTreeObject) {
                    try {
                        String xmlData = TextTransfer.getInstance().nativeToJava(transferType).toString();
                        List<Object> list = ConvertigoPlugin.clipboardManagerDND.read(xmlData);
                        DatabaseObject databaseObject = (DatabaseObject) list.get(0);
                        DatabaseObject targetDatabaseObject = ((DatabaseObjectTreeObject) target).getObject();
                        if (DatabaseObjectsManager.acceptDatabaseObjects(targetDatabaseObject, databaseObject)) {
                            return true;
                        }
                        DatabaseObject parentDatabaseObject = targetDatabaseObject.getParent();
                        if (parentDatabaseObject != null && DatabaseObjectsManager.acceptDatabaseObjects(parentDatabaseObject, databaseObject)) {
                            return true;
                        }
                        return false;
                    } catch (Exception e) {
                        e.printStackTrace(System.out);
                    }
                }
            }
        }
        return true;
    }
    if (StepSourceTransfer.getInstance().isSupportedType(transferType)) {
        if (target instanceof TreeObject) {
            TreeObject targetTreeObject = (TreeObject) target;
            // Check for drop to a step which contains a stepSource definition
            // if (targetTreeObject.getObject() instanceof IStepSourceContainer) {
            Object ob = targetTreeObject.getObject();
            if (ob instanceof Step && ((Step) ob).canWorkOnSource() || ob instanceof IStepSourceContainer) {
                StepSource stepSource = StepSourceTransfer.getInstance().getStepSource();
                if (stepSource != null) {
                    Step targetStep = (Step) ((ob instanceof StepVariable) ? ((StepVariable) ob).getParent() : ob);
                    // Check for drop to a step in the same sequence
                    Long key = Long.valueOf(stepSource.getPriority());
                    Step sourceStep = targetStep.getSequence().loadedSteps.get(key);
                    if ((sourceStep != null) && (!targetStep.equals(sourceStep))) {
                        // Check for drop on a 'following' step
                        try {
                            List<TreeObject> siblings = new ArrayList<TreeObject>();
                            getNextSiblings(siblings, targetTreeObject.getProjectTreeObject(), sourceStep);
                            // System.out.println("siblings: "+siblings.toString());
                            return siblings.contains(targetTreeObject);
                        } catch (Exception e) {
                            e.printStackTrace(System.out);
                        }
                        ;
                    }
                }
            }
        }
    }
    if (PaletteSourceTransfer.getInstance().isSupportedType(transferType)) {
        if (target instanceof TreeObject) {
            TreeObject targetTreeObject = (TreeObject) target;
            PaletteSource paletteSource = PaletteSourceTransfer.getInstance().getPaletteSource();
            if (paletteSource != null) {
                try {
                    String xmlData = paletteSource.getXmlData();
                    List<Object> list = ConvertigoPlugin.clipboardManagerDND.read(xmlData);
                    DatabaseObject databaseObject = (DatabaseObject) list.get(0);
                    if (targetTreeObject instanceof ObjectsFolderTreeObject) {
                        ObjectsFolderTreeObject folderTreeObject = (ObjectsFolderTreeObject) targetTreeObject;
                        if (!ProjectExplorerView.folderAcceptMobileComponent(folderTreeObject.folderType, databaseObject)) {
                            return false;
                        }
                        // continue
                        targetTreeObject = folderTreeObject.getParent();
                    }
                    if (targetTreeObject instanceof DatabaseObjectTreeObject) {
                        DatabaseObject targetDatabaseObject = ((DatabaseObjectTreeObject) targetTreeObject).getObject();
                        if (targetDatabaseObject != null) {
                            if (!DatabaseObjectsManager.acceptDatabaseObjects(targetDatabaseObject, databaseObject)) {
                                return false;
                            }
                            if (targetTreeObject instanceof MobileComponentTreeObject) {
                                if (!com.twinsoft.convertigo.beans.mobile.components.dynamic.ComponentManager.acceptDatabaseObjects(targetDatabaseObject, databaseObject)) {
                                    return false;
                                }
                                if (!com.twinsoft.convertigo.beans.mobile.components.dynamic.ComponentManager.isTplCompatible(targetDatabaseObject, databaseObject)) {
                                    return false;
                                }
                            }
                            if (targetTreeObject instanceof NgxComponentTreeObject) {
                                if (!com.twinsoft.convertigo.beans.ngx.components.dynamic.ComponentManager.acceptDatabaseObjects(targetDatabaseObject, databaseObject)) {
                                    return false;
                                }
                                if (!com.twinsoft.convertigo.beans.ngx.components.dynamic.ComponentManager.isTplCompatible(targetDatabaseObject, databaseObject)) {
                                    return false;
                                }
                            }
                            return true;
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace(System.out);
                }
            }
        }
    }
    if (MobileSourceTransfer.getInstance().isSupportedType(transferType)) {
        MobileSource mobileSource = MobileSourceTransfer.getInstance().getMobileSource();
        if (mobileSource != null) {
            if (target instanceof MobileUIComponentTreeObject) {
                MobileUIComponentTreeObject mcto = GenericUtils.cast(target);
                com.twinsoft.convertigo.beans.mobile.components.MobileSmartSource mss = com.twinsoft.convertigo.beans.mobile.components.MobileSmartSource.valueOf(mobileSource.getJsonString());
                if (mss == null || !mss.isDroppableInto(mcto.getObject())) {
                    return false;
                }
                for (IPropertyDescriptor descriptor : mcto.getPropertyDescriptors()) {
                    if (descriptor instanceof MobileSmartSourcePropertyDescriptor) {
                        if (!((MobileSmartSourcePropertyDescriptor) descriptor).isReadOnly()) {
                            return true;
                        }
                    }
                }
            }
            if (target instanceof NgxUIComponentTreeObject) {
                NgxUIComponentTreeObject mcto = GenericUtils.cast(target);
                com.twinsoft.convertigo.beans.ngx.components.MobileSmartSource mss = com.twinsoft.convertigo.beans.ngx.components.MobileSmartSource.valueOf(mobileSource.getJsonString());
                if (mss == null || !mss.isDroppableInto(mcto.getObject())) {
                    return false;
                }
                for (IPropertyDescriptor descriptor : mcto.getPropertyDescriptors()) {
                    if (descriptor instanceof NgxSmartSourcePropertyDescriptor) {
                        if (!((NgxSmartSourcePropertyDescriptor) descriptor).isReadOnly()) {
                            return true;
                        }
                    }
                }
            }
        }
    }
    return false;
}
Also used : NgxUIComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.NgxUIComponentTreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) MobileSmartSourcePropertyDescriptor(com.twinsoft.convertigo.eclipse.property_editors.MobileSmartSourcePropertyDescriptor) NgxComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.NgxComponentTreeObject) ArrayList(java.util.ArrayList) SequenceStep(com.twinsoft.convertigo.beans.steps.SequenceStep) XMLElementStep(com.twinsoft.convertigo.beans.steps.XMLElementStep) Step(com.twinsoft.convertigo.beans.core.Step) TransactionStep(com.twinsoft.convertigo.beans.steps.TransactionStep) StepVariable(com.twinsoft.convertigo.beans.variables.StepVariable) NgxSmartSourcePropertyDescriptor(com.twinsoft.convertigo.eclipse.property_editors.NgxSmartSourcePropertyDescriptor) IStepSourceContainer(com.twinsoft.convertigo.beans.core.IStepSourceContainer) ObjectsFolderTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ObjectsFolderTreeObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) MobileComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileComponentTreeObject) IOException(java.io.IOException) ObjectWithSameNameException(com.twinsoft.convertigo.engine.ObjectWithSameNameException) SAXException(org.xml.sax.SAXException) EngineException(com.twinsoft.convertigo.engine.EngineException) InvalidOperationException(com.twinsoft.convertigo.engine.InvalidOperationException) MobileUIComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileUIComponentTreeObject) PropertyTableRowTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.PropertyTableRowTreeObject) NgxComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.NgxComponentTreeObject) IOrderableTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IOrderableTreeObject) FolderTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.FolderTreeObject) ObjectsFolderTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ObjectsFolderTreeObject) NgxUIComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.NgxUIComponentTreeObject) MobileUIComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileUIComponentTreeObject) IPropertyTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IPropertyTreeObject) PropertyTableTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.PropertyTableTreeObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) ScreenClassTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ScreenClassTreeObject) MobileComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileComponentTreeObject) PropertyTableRowTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.PropertyTableRowTreeObject) NgxComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.NgxComponentTreeObject) IOrderableTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IOrderableTreeObject) FolderTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.FolderTreeObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) ObjectsFolderTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ObjectsFolderTreeObject) NgxUIComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.NgxUIComponentTreeObject) MobileUIComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileUIComponentTreeObject) IPropertyTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IPropertyTreeObject) RequestableObject(com.twinsoft.convertigo.beans.core.RequestableObject) PropertyTableTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.PropertyTableTreeObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) ScreenClassTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ScreenClassTreeObject) MobileComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileComponentTreeObject) IPropertyDescriptor(org.eclipse.ui.views.properties.IPropertyDescriptor)

Aggregations

DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)3 MobileSmartSourcePropertyDescriptor (com.twinsoft.convertigo.eclipse.property_editors.MobileSmartSourcePropertyDescriptor)3 EngineException (com.twinsoft.convertigo.engine.EngineException)3 RequestableObject (com.twinsoft.convertigo.beans.core.RequestableObject)2 NgxSmartSourcePropertyDescriptor (com.twinsoft.convertigo.eclipse.property_editors.NgxSmartSourcePropertyDescriptor)2 DatabaseObjectTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject)2 FolderTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.FolderTreeObject)2 IOrderableTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IOrderableTreeObject)2 IPropertyTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IPropertyTreeObject)2 MobileComponentTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileComponentTreeObject)2 MobileUIComponentTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileUIComponentTreeObject)2 NgxComponentTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.NgxComponentTreeObject)2 NgxUIComponentTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.NgxUIComponentTreeObject)2 ObjectsFolderTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ObjectsFolderTreeObject)2 PropertyTableRowTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.PropertyTableRowTreeObject)2 PropertyTableTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.PropertyTableTreeObject)2 ScreenClassTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ScreenClassTreeObject)2 TreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject)2 InvalidOperationException (com.twinsoft.convertigo.engine.InvalidOperationException)2 ObjectWithSameNameException (com.twinsoft.convertigo.engine.ObjectWithSameNameException)2