Search in sources :

Example 1 with MobileBuilder

use of com.twinsoft.convertigo.engine.mobile.MobileBuilder in project convertigo by convertigo.

the class TreeDropAdapter method performDrop.

/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.ViewerDropAdapter#performDrop(java.lang.Object)
	 */
@Override
public boolean performDrop(Object data) {
    MobileBuilder mb = null;
    Engine.logStudio.info("---------------------- Drop started ----------------------");
    try {
        Object targetObject = getCurrentTarget();
        IEditorPart editorPart = ConvertigoPlugin.getDefault().getApplicationComponentEditor();
        if (editorPart != null) {
            IEditorInput input = editorPart.getEditorInput();
            if (input instanceof com.twinsoft.convertigo.eclipse.editors.mobile.ApplicationComponentEditorInput) {
                com.twinsoft.convertigo.eclipse.editors.mobile.ApplicationComponentEditorInput editorInput = GenericUtils.cast(input);
                mb = editorInput.getApplication().getProject().getMobileBuilder();
            }
            if (input instanceof com.twinsoft.convertigo.eclipse.editors.ngx.ApplicationComponentEditorInput) {
                com.twinsoft.convertigo.eclipse.editors.ngx.ApplicationComponentEditorInput editorInput = GenericUtils.cast(input);
                mb = editorInput.getApplication().getProject().getMobileBuilder();
            }
        }
        // Handle tree objects reordering with Drag and Drop
        if (data instanceof String) {
            boolean insertBefore = (feedback & DND.FEEDBACK_INSERT_BEFORE) != 0;
            boolean insertAfter = (feedback & DND.FEEDBACK_INSERT_AFTER) != 0;
            if (insertBefore || insertAfter) {
                Object sourceObject = getSelectedObject();
                TreeParent targetTreeParent = ((TreeObject) targetObject).getParent();
                List<? extends TreeObject> children = targetTreeParent.getChildren();
                int destPosition = children.indexOf(targetObject);
                int srcPosition = children.indexOf(sourceObject);
                int delta = destPosition - srcPosition;
                int count = (delta < 0) ? (insertBefore ? delta : delta + 1) : (insertBefore ? delta - 1 : delta);
                if (count != 0) {
                    if (mb != null) {
                        mb.prepareBatchBuild();
                    }
                    BatchOperationHelper.start();
                    if (count < 0) {
                        new DatabaseObjectIncreasePriorityAction(Math.abs(count)).run();
                    } else {
                        new DatabaseObjectDecreasePriorityAction(Math.abs(count)).run();
                    }
                    BatchOperationHelper.stop();
                }
                return true;
            }
        }
        // Handle objects copy or move with Drag and drop
        if (targetObject instanceof TreeObject) {
            TreeObject targetTreeObject = (TreeObject) targetObject;
            if (targetTreeObject != null) {
                ProjectExplorerView explorerView = ConvertigoPlugin.getDefault().getProjectExplorerView();
                Document document = null;
                try {
                    Shell shell = Display.getDefault().getActiveShell();
                    try {
                        // Try to parse text data into an XML document
                        String source = data.toString();
                        document = XMLUtils.getDefaultDocumentBuilder().parse(new InputSource(new StringReader(source)));
                        if (mb != null) {
                            mb.prepareBatchBuild();
                        }
                        BatchOperationHelper.start();
                        ClipboardAction.dnd.paste(source, shell, explorerView, targetTreeObject, true);
                        BatchOperationHelper.stop();
                        return true;
                    } catch (SAXException sax) {
                        BatchOperationHelper.cancel();
                        if (mb != null) {
                            mb.prepareBatchBuild();
                        }
                        BatchOperationHelper.start();
                        // Parse failed probably because data was not XML but an XPATH String
                        // in this case, create DatabaseObjects of the correct Type according to the folder where the XPATH is dropped on
                        performDrop(data, explorerView, targetTreeObject);
                        BatchOperationHelper.stop();
                        return true;
                    }
                } catch (Exception e) {
                    BatchOperationHelper.cancel();
                    if (e instanceof ObjectWithSameNameException) {
                        document = null;
                    }
                    if (e instanceof InvalidOperationException) {
                        document = null;
                    }
                    // Case of unauthorized databaseObject paste
                    if (document != null) {
                        try {
                            if (!(targetTreeObject instanceof IPropertyTreeObject)) {
                                Element rootElement = document.getDocumentElement();
                                NodeList nodeList = rootElement.getChildNodes();
                                boolean unauthorized = false;
                                int len = nodeList.getLength();
                                Node node;
                                // case of folder, retrieve owner object
                                targetTreeObject = explorerView.getFirstSelectedDatabaseObjectTreeObject(targetTreeObject);
                                if (detail == DND.DROP_COPY) {
                                    for (int i = 0; i < len; i++) {
                                        node = (Node) nodeList.item(i);
                                        if (node.getNodeType() != Node.TEXT_NODE) {
                                            // Special objects paste
                                            if (!paste(node, targetTreeObject)) {
                                                // Real unauthorized databaseObject paste
                                                unauthorized = true;
                                            }
                                        }
                                    }
                                    reloadTreeObject(explorerView, targetTreeObject);
                                } else if (detail == DND.DROP_MOVE) {
                                    for (int i = 0; i < len; i++) {
                                        node = (Node) nodeList.item(i);
                                        if (node.getNodeType() != Node.TEXT_NODE) {
                                            // Special objects move
                                            if (!move(node, targetTreeObject)) {
                                                // Real unauthorized databaseObject move
                                                unauthorized = true;
                                            }
                                        }
                                    }
                                    reloadTreeObject(explorerView, targetTreeObject);
                                } else {
                                    // Real unauthorized databaseObject
                                    unauthorized = true;
                                }
                                if (unauthorized) {
                                    throw e;
                                }
                                return true;
                            }
                        } catch (Exception ex) {
                            ConvertigoPlugin.errorMessageBox(ex.getMessage());
                            return false;
                        }
                    } else {
                        ConvertigoPlugin.errorMessageBox(e.getMessage());
                        return false;
                    }
                }
            }
        }
        return false;
    } finally {
        Engine.logStudio.info("---------------------- Drop ended   ----------------------");
        BatchOperationHelper.cancel();
    }
}
Also used : InputSource(org.xml.sax.InputSource) TreeParent(com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeParent) DatabaseObjectIncreasePriorityAction(com.twinsoft.convertigo.eclipse.popup.actions.DatabaseObjectIncreasePriorityAction) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException) Shell(org.eclipse.swt.widgets.Shell) StringReader(java.io.StringReader) InvalidOperationException(com.twinsoft.convertigo.engine.InvalidOperationException) DatabaseObjectDecreasePriorityAction(com.twinsoft.convertigo.eclipse.popup.actions.DatabaseObjectDecreasePriorityAction) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) NodeList(org.w3c.dom.NodeList) IEditorPart(org.eclipse.ui.IEditorPart) 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) ObjectWithSameNameException(com.twinsoft.convertigo.engine.ObjectWithSameNameException) MobileBuilder(com.twinsoft.convertigo.engine.mobile.MobileBuilder) 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) IEditorInput(org.eclipse.ui.IEditorInput) IPropertyTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IPropertyTreeObject)

Example 2 with MobileBuilder

use of com.twinsoft.convertigo.engine.mobile.MobileBuilder in project convertigo by convertigo.

the class ProjectExplorerView method edit.

private void edit(TreeObject treeObject) {
    final Tree tree = viewer.getTree();
    final TreeEditor editor = new TreeEditor(tree);
    final Color black = getSite().getShell().getDisplay().getSystemColor(SWT.COLOR_BLACK);
    TreeItem[] items = tree.getSelection();
    if (items.length > 0) {
        final TreeItem item = items[0];
        final TreeObject theTreeObject = treeObject;
        if (treeObject instanceof ProjectTreeObject) {
            if (((ProjectTreeObject) treeObject).getModified()) {
                // Project need to be saved to avoid xsd/wsdl modification errors - Fix ticket #2265
                ConvertigoPlugin.warningMessageBox("Please save project before renaming it.");
                return;
            }
        }
        if (treeObject.getObject() instanceof HandlerStatement) {
            return;
        }
        if ((item != null) && lastItem.length > 0 && (item == lastItem[0])) {
            boolean isCarbon = SWT.getPlatform().equals("carbon");
            final Composite composite = new Composite(tree, SWT.NONE);
            if (!isCarbon) {
                composite.setBackground(black);
            }
            final Text text = new Text(composite, SWT.NONE);
            final int inset = isCarbon ? 0 : 1;
            composite.addListener(SWT.Resize, new Listener() {

                public void handleEvent(Event e) {
                    Rectangle rect = composite.getClientArea();
                    text.setBounds(rect.x + inset, rect.y + inset, rect.width - inset * 2, rect.height - inset * 2);
                }
            });
            Listener textListener = new Listener() {

                public void handleEvent(final Event e) {
                    MobileBuilder mba = null;
                    MobileBuilder mbo = null;
                    IEditorPart editorPart = ConvertigoPlugin.getDefault().getApplicationComponentEditor();
                    if (editorPart != null) {
                        IEditorInput input = editorPart.getEditorInput();
                        if (input instanceof com.twinsoft.convertigo.eclipse.editors.mobile.ApplicationComponentEditorInput) {
                            com.twinsoft.convertigo.eclipse.editors.mobile.ApplicationComponentEditorInput editorInput = GenericUtils.cast(input);
                            mba = editorInput.getApplication().getProject().getMobileBuilder();
                        }
                        if (input instanceof com.twinsoft.convertigo.eclipse.editors.ngx.ApplicationComponentEditorInput) {
                            com.twinsoft.convertigo.eclipse.editors.ngx.ApplicationComponentEditorInput editorInput = GenericUtils.cast(input);
                            mba = editorInput.getApplication().getProject().getMobileBuilder();
                        }
                    }
                    if (theTreeObject instanceof DatabaseObjectTreeObject) {
                        mbo = ((DatabaseObjectTreeObject) theTreeObject).getObject().getProject().getMobileBuilder();
                    }
                    String newName = null;
                    String oldName = null;
                    boolean needRefresh = false;
                    boolean needProjectReload = false;
                    if (theTreeObject instanceof DatabaseObjectTreeObject) {
                        oldName = ((DatabaseObject) ((DatabaseObjectTreeObject) theTreeObject).getObject()).getName();
                    } else if (theTreeObject instanceof TraceTreeObject) {
                        oldName = ((TraceTreeObject) theTreeObject).getName();
                    } else if (theTreeObject instanceof DesignDocumentViewTreeObject) {
                        oldName = ((DesignDocumentViewTreeObject) theTreeObject).getName();
                    } else if (theTreeObject instanceof DesignDocumentFunctionTreeObject) {
                        oldName = ((DesignDocumentFunctionTreeObject) theTreeObject).getName();
                    }
                    switch(e.type) {
                        case SWT.FocusOut:
                            editingTextCtrl = null;
                            composite.dispose();
                            break;
                        case SWT.Verify:
                            String newText = text.getText();
                            String leftText = newText.substring(0, e.start);
                            String rightText = newText.substring(e.end, newText.length());
                            GC gc = new GC(text);
                            Point size = gc.textExtent(leftText + e.text + rightText);
                            gc.dispose();
                            size = text.computeSize(size.x, SWT.DEFAULT);
                            editor.horizontalAlignment = SWT.LEFT;
                            Rectangle itemRect = item.getBounds(), rect = tree.getClientArea();
                            editor.minimumWidth = Math.max(size.x, itemRect.width) + inset * 2;
                            int left = itemRect.x, right = rect.x + rect.width;
                            editor.minimumWidth = Math.min(editor.minimumWidth, right - left);
                            editor.minimumHeight = size.y + inset * 2;
                            editor.layout();
                            break;
                        case SWT.Traverse:
                            switch(e.detail) {
                                case SWT.TRAVERSE_RETURN:
                                    Engine.logStudio.info("---------------------- Rename started ----------------------");
                                    if (mba != null) {
                                        mba.prepareBatchBuild();
                                    }
                                    newName = text.getText();
                                    // Save and close editors
                                    if (theTreeObject instanceof IClosableTreeObject) {
                                        ((IClosableTreeObject) theTreeObject).closeAllEditors(true);
                                    }
                                    if (theTreeObject instanceof DatabaseObjectTreeObject) {
                                        DatabaseObjectTreeObject dbObjectTreeObject = (DatabaseObjectTreeObject) theTreeObject;
                                        if (dbObjectTreeObject.rename(newName, Boolean.TRUE)) {
                                            item.setText(newName);
                                            needRefresh = true;
                                            if (theTreeObject instanceof ProjectTreeObject) {
                                                needProjectReload = true;
                                            }
                                        }
                                    } else if (theTreeObject instanceof TraceTreeObject) {
                                        TraceTreeObject traceTreeObject = (TraceTreeObject) theTreeObject;
                                        traceTreeObject.rename(newName);
                                        if (traceTreeObject.hasChanged) {
                                            item.setText(newName);
                                            traceTreeObject.hasChanged = false;
                                            needRefresh = true;
                                        }
                                    } else if (theTreeObject instanceof DesignDocumentViewTreeObject) {
                                        DesignDocumentViewTreeObject ddvto = (DesignDocumentViewTreeObject) theTreeObject;
                                        if (ddvto.rename(newName, Boolean.TRUE)) {
                                            item.setText(newName);
                                            needRefresh = true;
                                        }
                                    } else if (theTreeObject instanceof DesignDocumentFunctionTreeObject) {
                                        DesignDocumentFunctionTreeObject ddfto = (DesignDocumentFunctionTreeObject) theTreeObject;
                                        if (ddfto.rename(newName, Boolean.TRUE)) {
                                            item.setText(newName);
                                            needRefresh = true;
                                        }
                                    }
                                // FALL THROUGH
                                case SWT.TRAVERSE_ESCAPE:
                                    editingTextCtrl = null;
                                    composite.dispose();
                                    e.doit = false;
                            }
                            break;
                    }
                    if (needRefresh) {
                        boolean updateDlg = false;
                        boolean updateReferences = false;
                        int update = 0;
                        // Updates references to object if needed
                        if ((theTreeObject instanceof ProjectTreeObject) || (theTreeObject instanceof SequenceTreeObject) || (theTreeObject instanceof ConnectorTreeObject) || (theTreeObject instanceof TransactionTreeObject) || (theTreeObject instanceof VariableTreeObject2) || (theTreeObject instanceof IDesignTreeObject) || (theTreeObject instanceof MobilePageComponentTreeObject) || (theTreeObject instanceof MobileUIComponentTreeObject) || (theTreeObject instanceof NgxPageComponentTreeObject) || (theTreeObject instanceof NgxUIComponentTreeObject)) {
                            String objectType = "";
                            if (theTreeObject instanceof ProjectTreeObject) {
                                objectType = "project";
                                updateDlg = true;
                            } else if (theTreeObject instanceof SequenceTreeObject) {
                                objectType = "sequence";
                                updateDlg = true;
                            } else if (theTreeObject instanceof ConnectorTreeObject) {
                                objectType = "connector";
                                updateDlg = true;
                            } else if (theTreeObject instanceof TransactionTreeObject) {
                                objectType = "transaction";
                                updateDlg = true;
                            } else if (theTreeObject instanceof VariableTreeObject2) {
                                objectType = "variable";
                                updateDlg = ((DatabaseObject) theTreeObject.getObject()) instanceof RequestableVariable ? true : false;
                            } else if (theTreeObject instanceof DesignDocumentTreeObject) {
                                objectType = "document";
                                updateDlg = true;
                            } else if (theTreeObject instanceof DesignDocumentViewTreeObject) {
                                objectType = "view";
                                updateDlg = true;
                            } else if (theTreeObject instanceof DesignDocumentFilterTreeObject) {
                                objectType = "filter";
                                updateDlg = true;
                            } else if (theTreeObject instanceof DesignDocumentUpdateTreeObject) {
                                objectType = "update";
                                updateDlg = true;
                            } else if (theTreeObject instanceof DesignDocumentValidateTreeObject) {
                                objectType = "validate";
                                updateDlg = true;
                            } else if (theTreeObject instanceof MobilePageComponentTreeObject) {
                                objectType = "page";
                                updateDlg = true;
                            } else if (theTreeObject instanceof NgxPageComponentTreeObject) {
                                objectType = "page";
                                updateDlg = true;
                            } else if (theTreeObject instanceof MobileUIComponentTreeObject) {
                                DatabaseObject dbo = (DatabaseObject) theTreeObject.getObject();
                                if (dbo instanceof com.twinsoft.convertigo.beans.mobile.components.UIDynamicMenu) {
                                    objectType = "menu";
                                    updateDlg = true;
                                }
                                if (dbo instanceof com.twinsoft.convertigo.beans.mobile.components.UIActionStack) {
                                    objectType = "shared action";
                                    updateDlg = true;
                                }
                                if (dbo instanceof com.twinsoft.convertigo.beans.mobile.components.UISharedComponent) {
                                    objectType = "shared component";
                                    updateDlg = true;
                                }
                                if (dbo instanceof com.twinsoft.convertigo.beans.mobile.components.UIStackVariable) {
                                    objectType = "variable";
                                    updateDlg = true;
                                }
                                if (dbo instanceof com.twinsoft.convertigo.beans.mobile.components.UICompVariable) {
                                    objectType = "variable";
                                    updateDlg = true;
                                }
                            } else if (theTreeObject instanceof NgxUIComponentTreeObject) {
                                DatabaseObject dbo = (DatabaseObject) theTreeObject.getObject();
                                if (dbo instanceof com.twinsoft.convertigo.beans.ngx.components.UIDynamicMenu) {
                                    objectType = "menu";
                                    updateDlg = true;
                                }
                                if (dbo instanceof com.twinsoft.convertigo.beans.ngx.components.UIActionStack) {
                                    objectType = "shared action";
                                    updateDlg = true;
                                }
                                if (dbo instanceof com.twinsoft.convertigo.beans.ngx.components.UISharedComponent) {
                                    objectType = "shared component";
                                    updateDlg = true;
                                }
                                if (dbo instanceof com.twinsoft.convertigo.beans.ngx.components.UIStackVariable) {
                                    objectType = "variable";
                                    updateDlg = true;
                                }
                                if (dbo instanceof com.twinsoft.convertigo.beans.ngx.components.UICompVariable) {
                                    objectType = "variable";
                                    updateDlg = true;
                                }
                            }
                            if (updateDlg) {
                                Shell shell = Display.getDefault().getActiveShell();
                                CustomDialog customDialog = new CustomDialog(shell, "Update object references", "Do you want to update " + objectType + " references ?\n You can replace '" + oldName + "' by '" + newName + "' in all loaded projects \n or replace '" + oldName + "' by '" + newName + "' in current project only.", 670, 200, new ButtonSpec("Replace in all loaded projects", true), new ButtonSpec("Replace in current project", false), new ButtonSpec("Do not replace anywhere", false));
                                int response = customDialog.open();
                                if (response == 0) {
                                    updateReferences = true;
                                    update = TreeObjectEvent.UPDATE_ALL;
                                }
                                if (response == 1) {
                                    updateReferences = true;
                                    update = TreeObjectEvent.UPDATE_LOCAL;
                                }
                            }
                        }
                        TreeObjectEvent treeObjectEvent = null;
                        if (updateReferences) {
                            treeObjectEvent = new TreeObjectEvent(theTreeObject, "name", oldName, newName, update);
                        } else {
                            treeObjectEvent = new TreeObjectEvent(theTreeObject, "name", oldName, newName);
                        }
                        BatchOperationHelper.start();
                        ProjectExplorerView.this.refreshTree();
                        ProjectExplorerView.this.setSelectedTreeObject(theTreeObject);
                        ProjectExplorerView.this.fireTreeObjectPropertyChanged(treeObjectEvent);
                        if (updateReferences && needProjectReload) {
                            ((ProjectTreeObject) theTreeObject).save(false);
                        }
                        if (mbo != null) {
                            if (theTreeObject instanceof MobilePageComponentTreeObject) {
                                try {
                                    mbo.pageRenamed((com.twinsoft.convertigo.beans.mobile.components.PageComponent) theTreeObject.getObject(), oldName);
                                } catch (EngineException e1) {
                                    e1.printStackTrace();
                                }
                            }
                            if (theTreeObject instanceof NgxPageComponentTreeObject) {
                                try {
                                    mbo.pageRenamed((com.twinsoft.convertigo.beans.ngx.components.PageComponent) theTreeObject.getObject(), oldName);
                                } catch (EngineException e1) {
                                    e1.printStackTrace();
                                }
                            }
                        }
                        BatchOperationHelper.stop();
                        Engine.logStudio.info("---------------------- Rename ended   ----------------------");
                        StructuredSelection structuredSelection = new StructuredSelection(theTreeObject);
                        ISelectionListener listener = null;
                        // refresh properties view
                        listener = ConvertigoPlugin.getDefault().getPropertiesView();
                        if (listener != null)
                            listener.selectionChanged((IWorkbenchPart) ProjectExplorerView.this, structuredSelection);
                        // refresh references view
                        listener = ConvertigoPlugin.getDefault().getReferencesView();
                        if (listener != null)
                            listener.selectionChanged((IWorkbenchPart) ProjectExplorerView.this, structuredSelection);
                    }
                    if (needProjectReload) {
                        Engine.theApp.databaseObjectsManager.clearCache(newName);
                        reloadProject(theTreeObject);
                        refreshTree();
                    }
                }
            };
            text.addListener(SWT.FocusOut, textListener);
            text.addListener(SWT.Traverse, textListener);
            text.addListener(SWT.Verify, textListener);
            editor.setEditor(composite, item);
            if (theTreeObject instanceof DatabaseObjectTreeObject) {
                text.setText(((DatabaseObjectTreeObject) theTreeObject).getName());
            } else if (theTreeObject instanceof TraceTreeObject) {
                text.setText(((TraceTreeObject) theTreeObject).getName());
            } else if (theTreeObject instanceof DesignDocumentViewTreeObject) {
                text.setText(((DesignDocumentViewTreeObject) theTreeObject).getName());
            } else if (theTreeObject instanceof DesignDocumentFunctionTreeObject) {
                text.setText(((DesignDocumentFunctionTreeObject) theTreeObject).getName());
            }
            text.selectAll();
            text.setFocus();
            editingTextCtrl = text;
        }
        lastItem[0] = item;
    }
}
Also used : NgxUIComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.NgxUIComponentTreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) TreeItem(org.eclipse.swt.widgets.TreeItem) DesignDocumentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DesignDocumentTreeObject) Rectangle(org.eclipse.swt.graphics.Rectangle) EngineException(com.twinsoft.convertigo.engine.EngineException) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ISelectionListener(org.eclipse.ui.ISelectionListener) CustomDialog(com.twinsoft.convertigo.eclipse.dialogs.CustomDialog) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) Tree(org.eclipse.swt.widgets.Tree) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) ButtonSpec(com.twinsoft.convertigo.eclipse.dialogs.ButtonSpec) NgxPageComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.NgxPageComponentTreeObject) Color(org.eclipse.swt.graphics.Color) IClosableTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IClosableTreeObject) ConnectorTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ConnectorTreeObject) MobileUIComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileUIComponentTreeObject) MobilePageComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobilePageComponentTreeObject) MobileBuilder(com.twinsoft.convertigo.engine.mobile.MobileBuilder) UrlMappingParameterTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.UrlMappingParameterTreeObject) MobileApplicationTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileApplicationTreeObject) IClosableTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IClosableTreeObject) XMLRecordDescriptionTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.XMLRecordDescriptionTreeObject) DesignDocumentValidateTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DesignDocumentValidateTreeObject) UrlMappingTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.UrlMappingTreeObject) DesignDocumentUpdateTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DesignDocumentUpdateTreeObject) DesignDocumentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DesignDocumentTreeObject) MobileApplicationComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileApplicationComponentTreeObject) UrlMappingOperationTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.UrlMappingOperationTreeObject) ReferenceTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ReferenceTreeObject) HandlersDeclarationTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.HandlersDeclarationTreeObject) UrlMappingResponseTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.UrlMappingResponseTreeObject) UnloadedProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.UnloadedProjectTreeObject) NgxUIComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.NgxUIComponentTreeObject) MobileUIComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileUIComponentTreeObject) CriteriaTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.CriteriaTreeObject) IPropertyTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IPropertyTreeObject) UrlAuthenticationTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.UrlAuthenticationTreeObject) SequenceTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.SequenceTreeObject) MobileRouteActionComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileRouteActionComponentTreeObject) ListenerTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ListenerTreeObject) TransactionTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TransactionTreeObject) PropertyTableTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.PropertyTableTreeObject) FullSyncListenerTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.FullSyncListenerTreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) ConnectorTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ConnectorTreeObject) IDesignTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IDesignTreeObject) ScreenClassTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ScreenClassTreeObject) StatementTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StatementTreeObject) NgxApplicationComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.NgxApplicationComponentTreeObject) MobileRouteEventComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileRouteEventComponentTreeObject) PropertyTableRowTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.PropertyTableRowTreeObject) IEditableTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IEditableTreeObject) XMLTableDescriptionTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.XMLTableDescriptionTreeObject) ProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject) DesignDocumentViewTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DesignDocumentViewTreeObject) TemplateTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TemplateTreeObject) TestCaseTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TestCaseTreeObject) ObjectsFolderTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ObjectsFolderTreeObject) PropertyTableColumnTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.PropertyTableColumnTreeObject) DesignDocumentFilterTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DesignDocumentFilterTreeObject) VariableTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.VariableTreeObject) DesignDocumentFunctionTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DesignDocumentFunctionTreeObject) MobilePlatformTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobilePlatformTreeObject) ExtractionRuleTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ExtractionRuleTreeObject) MobileRouteComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileRouteComponentTreeObject) SheetTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.SheetTreeObject) UrlMapperTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.UrlMapperTreeObject) StepTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StepTreeObject) NgxPageComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.NgxPageComponentTreeObject) MobilePageComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobilePageComponentTreeObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) TraceTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TraceTreeObject) DocumentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DocumentTreeObject) DesignDocumentFilterTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DesignDocumentFilterTreeObject) TransactionTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TransactionTreeObject) MigrationListener(com.twinsoft.convertigo.engine.MigrationListener) TreeDragListener(com.twinsoft.convertigo.eclipse.dnd.TreeDragListener) ISelectionListener(org.eclipse.ui.ISelectionListener) CompositeListener(com.twinsoft.convertigo.eclipse.editors.CompositeListener) DatabaseObjectListener(com.twinsoft.convertigo.engine.DatabaseObjectListener) Listener(org.eclipse.swt.widgets.Listener) EngineListener(com.twinsoft.convertigo.engine.EngineListener) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) ITreeViewerListener(org.eclipse.jface.viewers.ITreeViewerListener) IMenuListener(org.eclipse.jface.action.IMenuListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) IDesignTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IDesignTreeObject) DesignDocumentViewTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DesignDocumentViewTreeObject) HandlerStatement(com.twinsoft.convertigo.beans.statements.HandlerStatement) Shell(org.eclipse.swt.widgets.Shell) GC(org.eclipse.swt.graphics.GC) VariableTreeObject2(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.VariableTreeObject2) DesignDocumentValidateTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DesignDocumentValidateTreeObject) TreeEditor(org.eclipse.swt.custom.TreeEditor) Composite(org.eclipse.swt.widgets.Composite) SequenceTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.SequenceTreeObject) Text(org.eclipse.swt.widgets.Text) RequestableVariable(com.twinsoft.convertigo.beans.variables.RequestableVariable) IEditorPart(org.eclipse.ui.IEditorPart) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) DesignDocumentFunctionTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DesignDocumentFunctionTreeObject) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) EngineEvent(com.twinsoft.convertigo.engine.EngineEvent) TreeExpansionEvent(org.eclipse.jface.viewers.TreeExpansionEvent) DatabaseObjectImportedEvent(com.twinsoft.convertigo.engine.DatabaseObjectImportedEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) DatabaseObjectLoadedEvent(com.twinsoft.convertigo.engine.DatabaseObjectLoadedEvent) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) CompositeEvent(com.twinsoft.convertigo.eclipse.editors.CompositeEvent) Event(org.eclipse.swt.widgets.Event) UnloadedProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.UnloadedProjectTreeObject) ProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject) TraceTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TraceTreeObject) IEditorInput(org.eclipse.ui.IEditorInput) DesignDocumentUpdateTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DesignDocumentUpdateTreeObject)

Example 3 with MobileBuilder

use of com.twinsoft.convertigo.engine.mobile.MobileBuilder in project convertigo by convertigo.

the class CLI method generateMobileBuilder.

public void generateMobileBuilder(Project project, String mode) throws Exception {
    MobileBuilder mb = project.getMobileBuilder();
    MobileBuilderBuildMode bm = MobileBuilderBuildMode.production;
    try {
        bm = MobileBuilderBuildMode.valueOf(mode);
    } catch (Exception e) {
    }
    mb.setAppBuildMode(bm);
    List<Project> projects = new ArrayList<>();
    projects.add(project);
    int i = 0;
    do {
        for (Reference ref : projects.get(i).getReferenceList()) {
            if (ref instanceof ProjectSchemaReference) {
                ProjectSchemaReference pref = (ProjectSchemaReference) ref;
                Project p = Engine.theApp.referencedProjectManager.importProject(pref.getParser());
                if (p == null) {
                    Engine.logConvertigo.warn("Failed to import project reference: " + pref.getProjectName() + " (ignored)");
                } else if (!projects.contains(p)) {
                    projects.add(p);
                }
            }
        }
    } while (++i < projects.size());
    Collections.reverse(projects);
    for (Project p : projects) {
        MobileBuilder.initBuilder(p, true);
    }
    Collections.reverse(projects);
    for (Project p : projects) {
        MobileBuilder.releaseBuilder(p, true);
    }
}
Also used : Project(com.twinsoft.convertigo.beans.core.Project) ProjectSchemaReference(com.twinsoft.convertigo.beans.references.ProjectSchemaReference) MobileBuilder(com.twinsoft.convertigo.engine.mobile.MobileBuilder) ProjectSchemaReference(com.twinsoft.convertigo.beans.references.ProjectSchemaReference) Reference(com.twinsoft.convertigo.beans.core.Reference) ArrayList(java.util.ArrayList) MobileBuilderBuildMode(com.twinsoft.convertigo.engine.enums.MobileBuilderBuildMode) IOException(java.io.IOException)

Example 4 with MobileBuilder

use of com.twinsoft.convertigo.engine.mobile.MobileBuilder 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 5 with MobileBuilder

use of com.twinsoft.convertigo.engine.mobile.MobileBuilder in project convertigo by convertigo.

the class ApplicationComponentEditor method launchBuilder.

public void launchBuilder(boolean forceInstall, boolean forceClean) {
    final int buildCount = ++this.buildCount;
    final boolean isDark = SwtUtils.isDark();
    // Close editors (*.temp.ts) to avoid npm error at build launch
    ConvertigoPlugin.getDisplay().syncExec(new Runnable() {

        public void run() {
            try {
                ApplicationComponent app = applicationEditorInput.application;
                IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
                if (activePage != null) {
                    IEditorReference[] editorRefs = activePage.getEditorReferences();
                    for (int i = 0; i < editorRefs.length; i++) {
                        IEditorReference editorRef = (IEditorReference) editorRefs[i];
                        try {
                            IEditorInput editorInput = editorRef.getEditorInput();
                            if (editorInput != null && editorInput instanceof ComponentFileEditorInput) {
                                if (((ComponentFileEditorInput) editorInput).is(app) || ((ComponentFileEditorInput) editorInput).isChildOf(app)) {
                                    activePage.closeEditor(editorRef.getEditor(false), false);
                                }
                            }
                        } catch (Exception e) {
                        }
                    }
                }
            } catch (Throwable t) {
            }
        }
    });
    // Launch build
    Engine.execute(() -> {
        try {
            String loader = IOUtils.toString(getClass().getResourceAsStream("loader.html"), "UTF-8");
            if (isDark) {
                loader = loader.replace("lightblue", "rgb(47,47,47); color: white");
            }
            c8oBrowser.setText(loader);
        } catch (Exception e1) {
            throw new RuntimeException(e1);
        }
        project = applicationEditorInput.application.getProject();
        ionicDir = new File(project.getDirPath(), "_private/ionic");
        nodeModules = new File(ionicDir, "node_modules");
        String nodeVersion = ProcessUtils.getNodeVersion(project);
        nodeDir = ProcessUtils.getDefaultNodeDir();
        try {
            nodeDir = ProcessUtils.getNodeDir(nodeVersion, (r, t, x) -> {
                appendOutput("Downloading nodejs " + nodeVersion + ": " + Math.round((r * 100f) / t) + "%");
            });
        } catch (Exception e1) {
        }
        {
            String versions = "Will use nodejs " + ProcessUtils.getNodeVersion(nodeDir) + " and npm " + ProcessUtils.getNpmVersion(nodeDir);
            appendOutput(versions);
            Engine.logStudio.info(versions);
        }
        String path = nodeDir.getAbsolutePath();
        terminateNode(false);
        MobileBuilder mb = project.getMobileBuilder();
        if (forceInstall || !nodeModules.exists() || mb.getNeedPkgUpdate()) {
            boolean[] running = { true };
            try {
                new File(ionicDir, "package-lock.json").delete();
                new File(ionicDir, "pnpm-lock.yaml").delete();
                if (forceClean) {
                    appendOutput("...", "...", "Removing existing node_modules... This can take several seconds...");
                    Engine.logStudio.info("Removing existing node_modules... This can take several seconds...");
                    com.twinsoft.convertigo.engine.util.FileUtils.deleteQuietly(nodeModules);
                }
                appendOutput("Installing node_modules... This can take several minutes depending on your network connection speed...");
                Engine.logStudio.info("Installing node_modules... This can take several minutes depending on your network connection speed...");
                ProcessBuilder pb;
                Process p;
                // set to true to enable yarn again.
                boolean useYarn = false;
                if (useYarn) {
                    File yarnFile = new File(ionicDir.toString() + "/node_modules/.bin/yarn");
                    if (!yarnFile.exists()) {
                        Engine.logStudio.info("Installing Yarn...");
                        pb = ProcessUtils.getNpmProcessBuilder(path, "npm", "install", "yarn");
                        pb.redirectErrorStream(true);
                        pb.directory(ionicDir);
                        p = pb.start();
                        p.waitFor();
                    }
                    pb = ProcessUtils.getNpmProcessBuilder(path + File.pathSeparator + ionicDir.toString() + "/node_modules/.bin/", "yarn");
                    pb.redirectErrorStream(true);
                    pb.directory(ionicDir);
                    p = pb.start();
                } else {
                    File pnpmFile = new File(ionicDir.toString() + "/node_modules/.bin/pnpm");
                    if (!pnpmFile.exists()) {
                        Engine.logStudio.info("Installing Pnpm...");
                        pb = ProcessUtils.getNpmProcessBuilder(path, "npm", "install", "pnpm");
                        pb.redirectErrorStream(true);
                        pb.directory(ionicDir);
                        p = pb.start();
                        p.waitFor();
                    }
                    pb = ProcessUtils.getNpmProcessBuilder(path + File.pathSeparator + ionicDir.toString() + "/node_modules/.bin/", "pnpm", "install", "--shamefully-hoist");
                    pb.redirectErrorStream(true);
                    pb.directory(ionicDir);
                    p = pb.start();
                }
                /*
					Engine.execute(() -> {
						try {
							while (running[0]) {
								appendOutput("Collecting node_modules: " + FileUtils.byteCountToDisplaySize(FileUtils.sizeOfAsBigInteger(nodeModules)) + " (" + Math.round(System.currentTimeMillis() - start) / 1000 + " sec)");
								Engine.logStudio.info("Installing, node_module size is now : " + FileUtils.byteCountToDisplaySize(FileUtils.sizeOfAsBigInteger(nodeModules)));
								Thread.sleep(1000);
							} 
						} catch (Exception e) {
							appendOutput("Something wrong during the install: " + e);
						}
					});
					*/
                processes.add(p);
                BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
                String line;
                while ((line = br.readLine()) != null) {
                    line = pRemoveEchap.matcher(line).replaceAll("");
                    if (StringUtils.isNotBlank(line)) {
                        Engine.logStudio.info(line);
                        appendOutput(line);
                    }
                }
                Engine.logStudio.info(line);
                appendOutput("\\o/");
            } catch (Exception e) {
                appendOutput(":( " + e);
            }
            running[0] = false;
        }
        mb.setNeedPkgUpdate(false);
        build(path, buildCount, mb);
    });
}
Also used : Element(com.teamdev.jxbrowser.dom.Element) CoreException(org.eclipse.core.runtime.CoreException) FocusEvent(org.eclipse.swt.events.FocusEvent) ApplicationComponent(com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent) StringUtils(org.apache.commons.lang3.StringUtils) Point(org.eclipse.swt.graphics.Point) UISharedComponent(com.twinsoft.convertigo.beans.ngx.components.UISharedComponent) Matcher(java.util.regex.Matcher) Composite(org.eclipse.swt.widgets.Composite) PartInitException(org.eclipse.ui.PartInitException) KeyEvent(org.eclipse.swt.events.KeyEvent) PageComponent(com.twinsoft.convertigo.beans.ngx.components.PageComponent) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) KeyAdapter(org.eclipse.swt.events.KeyAdapter) IEditorPart(org.eclipse.ui.IEditorPart) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) IEditorInput(org.eclipse.ui.IEditorInput) PlatformUI(org.eclipse.ui.PlatformUI) Set(java.util.Set) ToolItem(org.eclipse.swt.widgets.ToolItem) IOUtils(org.apache.commons.io.IOUtils) MenuItem(org.eclipse.swt.widgets.MenuItem) SWT(org.eclipse.swt.SWT) JsAccessible(com.teamdev.jxbrowser.js.JsAccessible) EditorPart(org.eclipse.ui.part.EditorPart) SwtUtils(com.twinsoft.convertigo.eclipse.swt.SwtUtils) DatabaseObjectFoundException(com.twinsoft.convertigo.engine.DatabaseObjectFoundException) SelectionListener(org.eclipse.swt.events.SelectionListener) UIControlEvent(com.twinsoft.convertigo.beans.ngx.components.UIControlEvent) MobileComponent(com.twinsoft.convertigo.beans.ngx.components.MobileComponent) JFaceResources(org.eclipse.jface.resource.JFaceResources) IEditorSite(org.eclipse.ui.IEditorSite) UIActionStack(com.twinsoft.convertigo.beans.ngx.components.UIActionStack) RequestPermissionCallback(com.teamdev.jxbrowser.permission.callback.RequestPermissionCallback) GridData(org.eclipse.swt.layout.GridData) RowData(org.eclipse.swt.layout.RowData) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) Engine(com.twinsoft.convertigo.engine.Engine) UIUseShared(com.twinsoft.convertigo.beans.ngx.components.UIUseShared) JSONObject(org.codehaus.jettison.json.JSONObject) JSONArray(org.codehaus.jettison.json.JSONArray) MobileDebugView(com.twinsoft.convertigo.eclipse.views.mobile.MobileDebugView) NgxBuilderBuildMode(com.twinsoft.convertigo.engine.enums.NgxBuilderBuildMode) JsObject(com.teamdev.jxbrowser.js.JsObject) InputStreamReader(java.io.InputStreamReader) File(java.io.File) Node(com.teamdev.jxbrowser.dom.Node) Project(com.twinsoft.convertigo.beans.core.Project) JSONException(org.codehaus.jettison.json.JSONException) ModifyListener(org.eclipse.swt.events.ModifyListener) FileUtils(com.twinsoft.convertigo.engine.util.FileUtils) IEditorReference(org.eclipse.ui.IEditorReference) UIComponent(com.twinsoft.convertigo.beans.ngx.components.UIComponent) BufferedReader(java.io.BufferedReader) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ProcessUtils(com.twinsoft.convertigo.engine.util.ProcessUtils) GridLayout(org.eclipse.swt.layout.GridLayout) WalkHelper(com.twinsoft.convertigo.engine.helpers.WalkHelper) ClipboardAction(com.twinsoft.convertigo.eclipse.popup.actions.ClipboardAction) ToolBar(org.eclipse.swt.widgets.ToolBar) VerifyListener(org.eclipse.swt.events.VerifyListener) MobileEventListener(com.twinsoft.convertigo.engine.mobile.MobileEventListener) EnginePropertiesManager(com.twinsoft.convertigo.engine.EnginePropertiesManager) InjectJsCallback(com.teamdev.jxbrowser.browser.callback.InjectJsCallback) UIDynamicInvoke(com.twinsoft.convertigo.beans.ngx.components.UIDynamicInvoke) NetworkUtils(com.twinsoft.convertigo.engine.util.NetworkUtils) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Collection(java.util.Collection) UIDynamicAction(com.twinsoft.convertigo.beans.ngx.components.UIDynamicAction) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ConvertigoPlugin(com.twinsoft.convertigo.eclipse.ConvertigoPlugin) PropertyName(com.twinsoft.convertigo.engine.EnginePropertiesManager.PropertyName) List(java.util.List) Pattern(java.util.regex.Pattern) ShowContextMenuCallback(com.teamdev.jxbrowser.browser.callback.ShowContextMenuCallback) Label(org.eclipse.swt.widgets.Label) CompositeEvent(com.twinsoft.convertigo.eclipse.editors.CompositeEvent) Document(com.teamdev.jxbrowser.dom.Document) Image(org.eclipse.swt.graphics.Image) Rectangle(org.eclipse.swt.graphics.Rectangle) FocusListener(org.eclipse.swt.events.FocusListener) Event(org.eclipse.swt.widgets.Event) Frame(com.teamdev.jxbrowser.frame.Frame) MobileBuilder(com.twinsoft.convertigo.engine.mobile.MobileBuilder) HashSet(java.util.HashSet) PaletteSourceTransfer(com.twinsoft.convertigo.eclipse.dnd.PaletteSourceTransfer) BatchOperationHelper(com.twinsoft.convertigo.engine.helpers.BatchOperationHelper) Charset(java.nio.charset.Charset) UIDynamicElement(com.twinsoft.convertigo.beans.ngx.components.UIDynamicElement) Browser(com.teamdev.jxbrowser.browser.Browser) LinkedList(java.util.LinkedList) Response(com.teamdev.jxbrowser.browser.callback.InjectJsCallback.Response) Job(org.eclipse.core.runtime.jobs.Job) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) RowLayout(org.eclipse.swt.layout.RowLayout) IResource(org.eclipse.core.resources.IResource) NumberUtils(org.apache.commons.lang3.math.NumberUtils) KeyListener(org.eclipse.swt.events.KeyListener) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Menu(org.eclipse.swt.widgets.Menu) FocusAdapter(org.eclipse.swt.events.FocusAdapter) C8oBrowser(com.twinsoft.convertigo.eclipse.swt.C8oBrowser) Control(org.eclipse.swt.widgets.Control) InputStreamReader(java.io.InputStreamReader) ApplicationComponent(com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent) Point(org.eclipse.swt.graphics.Point) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) DatabaseObjectFoundException(com.twinsoft.convertigo.engine.DatabaseObjectFoundException) JSONException(org.codehaus.jettison.json.JSONException) IEditorReference(org.eclipse.ui.IEditorReference) MobileBuilder(com.twinsoft.convertigo.engine.mobile.MobileBuilder) BufferedReader(java.io.BufferedReader) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) File(java.io.File) IEditorInput(org.eclipse.ui.IEditorInput)

Aggregations

MobileBuilder (com.twinsoft.convertigo.engine.mobile.MobileBuilder)14 IEditorInput (org.eclipse.ui.IEditorInput)8 Text (org.eclipse.swt.widgets.Text)6 IEditorPart (org.eclipse.ui.IEditorPart)6 Project (com.twinsoft.convertigo.beans.core.Project)5 ProjectExplorerView (com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView)5 File (java.io.File)5 Matcher (java.util.regex.Matcher)5 JSONArray (org.codehaus.jettison.json.JSONArray)5 JSONException (org.codehaus.jettison.json.JSONException)5 CoreException (org.eclipse.core.runtime.CoreException)5 Point (org.eclipse.swt.graphics.Point)5 Rectangle (org.eclipse.swt.graphics.Rectangle)5 Composite (org.eclipse.swt.widgets.Composite)5 Control (org.eclipse.swt.widgets.Control)5 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)4 MobileDebugView (com.twinsoft.convertigo.eclipse.views.mobile.MobileDebugView)4 DatabaseObjectFoundException (com.twinsoft.convertigo.engine.DatabaseObjectFoundException)4 MessageDialog (org.eclipse.jface.dialogs.MessageDialog)4 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)4