Search in sources :

Example 11 with FormatedContent

use of com.twinsoft.convertigo.beans.common.FormatedContent in project convertigo by convertigo.

the class UIStyle method preconfigure.

@Override
public void preconfigure(Element element) throws Exception {
    super.preconfigure(element);
    try {
        NodeList properties = element.getElementsByTagName("property");
        // migration of styleContent from String to FormatedContent
        Element propElement = (Element) XMLUtils.findNodeByAttributeValue(properties, "name", "styleContent");
        if (propElement != null) {
            Element valueElement = (Element) XMLUtils.findChildNode(propElement, Node.ELEMENT_NODE);
            if (valueElement != null) {
                Document document = valueElement.getOwnerDocument();
                Object content = XMLUtils.readObjectFromXml(valueElement);
                if (content instanceof String) {
                    FormatedContent formated = new FormatedContent((String) content);
                    Element newValueElement = (Element) XMLUtils.writeObjectToXml(document, formated);
                    propElement.replaceChild(newValueElement, valueElement);
                    hasChanged = true;
                    Engine.logBeans.warn("(UIStyle) 'styleContent' has been updated for the object \"" + getName() + "\"");
                }
            }
        }
    } catch (Exception e) {
        throw new EngineException("Unable to preconfigure the style component \"" + getName() + "\".", e);
    }
}
Also used : NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) EngineException(com.twinsoft.convertigo.engine.EngineException) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) FormatedContent(com.twinsoft.convertigo.beans.common.FormatedContent) Document(org.w3c.dom.Document) EngineException(com.twinsoft.convertigo.engine.EngineException)

Example 12 with FormatedContent

use of com.twinsoft.convertigo.beans.common.FormatedContent in project convertigo by convertigo.

the class ApplicationComponent method addUIComponent.

protected void addUIComponent(UIComponent uiComponent, Long after) throws EngineException {
    checkSubLoaded();
    if (uiComponent instanceof UITheme) {
        if (this.theme != null) {
            throw new EngineException("The mobile application \"" + getName() + "\" already contains a theme! Please delete it first.");
        } else {
            UITheme uiTheme = (UITheme) uiComponent;
            if (uiTheme.bNew) {
                if (uiTheme.styleContent.getString().equals("")) {
                    uiTheme.styleContent = new FormatedContent(getThemeTplScss());
                }
            }
            this.theme = uiTheme;
        }
    }
    if (uiComponent instanceof UIAppGuard) {
        UIAppGuard guard = (UIAppGuard) uiComponent;
        if (guard.bNew) {
            AppGuardType guardType = guard.getGuardType();
            if (hasGuard(AppGuardType.onCanActivate) && hasGuard(AppGuardType.onCanDeactivate)) {
                throw new EngineException("The mobile application \"" + getName() + "\" already contains a \"" + guardType.getTopic() + "\" guard! Please delete it first.");
            }
            if (guardType.equals(AppGuardType.onCanActivate) && hasGuard(AppGuardType.onCanActivate)) {
                guard.setGuardType(AppGuardType.onCanDeactivate);
            }
            if (guardType.equals(AppGuardType.onCanDeactivate) && hasGuard(AppGuardType.onCanDeactivate)) {
                guard.setGuardType(AppGuardType.onCanActivate);
            }
        }
    }
    boolean isNew = uiComponent.bNew;
    boolean isCut = !isNew && uiComponent.getParent() == null && uiComponent.isSubLoaded;
    String newDatabaseObjectName = getChildBeanName(vUIComponents, uiComponent.getName(), uiComponent.bNew);
    uiComponent.setName(newDatabaseObjectName);
    vUIComponents.add(uiComponent);
    uiComponent.setParent(this);
    insertOrderedComponent(uiComponent, after);
    if (isNew || isCut) {
        markApplicationAsDirty();
    }
}
Also used : AppGuardType(com.twinsoft.convertigo.beans.ngx.components.UIAppGuard.AppGuardType) EngineException(com.twinsoft.convertigo.engine.EngineException) FormatedContent(com.twinsoft.convertigo.beans.common.FormatedContent)

Example 13 with FormatedContent

use of com.twinsoft.convertigo.beans.common.FormatedContent in project convertigo by convertigo.

the class MobileUIComponentTreeObject method editFunction.

private void editFunction(final UIComponent uic, final String functionMarker, final String propertyName) {
    try {
        IScriptComponent main = uic.getMainScriptComponent();
        if (main == null) {
            return;
        }
        // Refresh project resources for editor
        String projectName = uic.getProject().getName();
        IProject project = ConvertigoPlugin.getDefault().getProjectPluginResource(projectName);
        project.refreshLocal(IResource.DEPTH_INFINITE, null);
        // Close editor and Reopen it after file has been rewritten
        String relativePath = uic.getProject().getMobileBuilder().getFunctionTempTsRelativePath(uic);
        IFile file = project.getFile(relativePath);
        if (!(uic instanceof UICustomAction)) {
            closeComponentFileEditor(file);
        }
        if (main instanceof ApplicationComponent) {
            if (uic.compareToTplVersion("7.5.2.0") < 0) {
                ConvertigoPlugin.logError("The ability to use forms or actions inside a menu is avalaible since 7.5.2 version." + "\nPlease change your Template project for the 'mobilebuilder_tpl_7_5_2' template.", true);
                return;
            }
        }
        uic.getProject().getMobileBuilder().writeFunctionTempTsFile(uic, functionMarker);
        file.refreshLocal(IResource.DEPTH_ZERO, null);
        // Open file in editor
        if (file.exists()) {
            IEditorInput input = new ComponentFileEditorInput(file, uic);
            if (input != null) {
                IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(file.getName());
                IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
                String editorId = desc.getId();
                IEditorPart editorPart = activePage.openEditor(input, editorId);
                addMarkers(file, editorPart);
                editorPart.addPropertyListener(new IPropertyListener() {

                    boolean isFirstChange = false;

                    @Override
                    public void propertyChanged(Object source, int propId) {
                        if (source instanceof ITextEditor) {
                            if (propId == IEditorPart.PROP_DIRTY) {
                                if (!isFirstChange) {
                                    isFirstChange = true;
                                    return;
                                }
                                isFirstChange = false;
                                ITextEditor editor = (ITextEditor) source;
                                IDocumentProvider dp = editor.getDocumentProvider();
                                IDocument doc = dp.getDocument(editor.getEditorInput());
                                String marker = MobileBuilder.getMarker(doc.get(), functionMarker);
                                String content = MobileBuilder.getFormatedContent(marker, functionMarker);
                                FormatedContent formated = new FormatedContent(content);
                                MobileUIComponentTreeObject.this.setPropertyValue(propertyName, formated);
                            }
                        }
                    }
                });
            }
        }
    } catch (Exception e) {
        ConvertigoPlugin.logException(e, "Unable to edit function for '" + uic.getName() + "' component!");
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IScriptComponent(com.twinsoft.convertigo.beans.mobile.components.IScriptComponent) ApplicationComponent(com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent) ComponentFileEditorInput(com.twinsoft.convertigo.eclipse.editors.mobile.ComponentFileEditorInput) IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) IEditorPart(org.eclipse.ui.IEditorPart) IProject(org.eclipse.core.resources.IProject) IPropertyListener(org.eclipse.ui.IPropertyListener) CoreException(org.eclipse.core.runtime.CoreException) EngineException(com.twinsoft.convertigo.engine.EngineException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) UICustomAction(com.twinsoft.convertigo.beans.mobile.components.UICustomAction) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) FormatedContent(com.twinsoft.convertigo.beans.common.FormatedContent) IEditorInput(org.eclipse.ui.IEditorInput) IDocument(org.eclipse.jface.text.IDocument)

Example 14 with FormatedContent

use of com.twinsoft.convertigo.beans.common.FormatedContent in project convertigo by convertigo.

the class NgxUIComponentTreeObject method editCompTsFile.

public void editCompTsFile() {
    if (!(getObject() instanceof ISharedComponent)) {
        return;
    }
    final UISharedComponent comp = (UISharedComponent) getObject();
    try {
        // Refresh project resource
        String projectName = comp.getProject().getName();
        IProject project = ConvertigoPlugin.getDefault().getProjectPluginResource(projectName);
        project.refreshLocal(IResource.DEPTH_INFINITE, null);
        // Close editor
        String filePath = comp.getProject().getMobileBuilder().getTempTsRelativePath((ISharedComponent) comp);
        IFile file = project.getFile(filePath);
        closeComponentFileEditor(file);
        // Write temporary file
        comp.getProject().getMobileBuilder().writeCompTempTs((ISharedComponent) comp);
        file.refreshLocal(IResource.DEPTH_ZERO, null);
        // Open file in editor
        if (file.exists()) {
            IEditorInput input = new ComponentFileEditorInput(file, comp);
            if (input != null) {
                IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(file.getName());
                IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
                String editorId = desc.getId();
                IEditorPart editorPart = activePage.openEditor(input, editorId);
                addMarkers(file, editorPart);
                editorPart.addPropertyListener(new IPropertyListener() {

                    boolean isFirstChange = false;

                    @Override
                    public void propertyChanged(Object source, int propId) {
                        if (source instanceof ITextEditor) {
                            if (propId == IEditorPart.PROP_DIRTY) {
                                if (!isFirstChange) {
                                    isFirstChange = true;
                                    return;
                                }
                                isFirstChange = false;
                                ITextEditor editor = (ITextEditor) source;
                                IDocumentProvider dp = editor.getDocumentProvider();
                                IDocument doc = dp.getDocument(editor.getEditorInput());
                                FormatedContent scriptContent = new FormatedContent(MobileBuilder.getMarkers(doc.get()));
                                NgxUIComponentTreeObject.this.setPropertyValue("scriptContent", scriptContent);
                            }
                        }
                    }
                });
            }
        }
    } catch (Exception e) {
        ConvertigoPlugin.logException(e, "Unable to open typescript file for component '" + comp.getName() + "'!");
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) ComponentFileEditorInput(com.twinsoft.convertigo.eclipse.editors.ngx.ComponentFileEditorInput) IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) IEditorPart(org.eclipse.ui.IEditorPart) UISharedComponent(com.twinsoft.convertigo.beans.ngx.components.UISharedComponent) ISharedComponent(com.twinsoft.convertigo.beans.core.ISharedComponent) UISharedComponent(com.twinsoft.convertigo.beans.ngx.components.UISharedComponent) IProject(org.eclipse.core.resources.IProject) IPropertyListener(org.eclipse.ui.IPropertyListener) CoreException(org.eclipse.core.runtime.CoreException) EngineException(com.twinsoft.convertigo.engine.EngineException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) FormatedContent(com.twinsoft.convertigo.beans.common.FormatedContent) IEditorInput(org.eclipse.ui.IEditorInput) IDocument(org.eclipse.jface.text.IDocument)

Example 15 with FormatedContent

use of com.twinsoft.convertigo.beans.common.FormatedContent in project convertigo by convertigo.

the class ApplicationComponent method addUIComponent.

protected void addUIComponent(UIComponent uiComponent, Long after) throws EngineException {
    checkSubLoaded();
    if (uiComponent instanceof UITheme) {
        if (this.theme != null) {
            throw new EngineException("The mobile application \"" + getName() + "\" already contains a theme! Please delete it first.");
        } else {
            UITheme uiTheme = (UITheme) uiComponent;
            if (uiTheme.bNew) {
                if (uiTheme.styleContent.getString().equals("")) {
                    uiTheme.styleContent = new FormatedContent(getThemeTplScss());
                }
            }
            this.theme = uiTheme;
        }
    }
    boolean isNew = uiComponent.bNew;
    boolean isCut = !isNew && uiComponent.getParent() == null && uiComponent.isSubLoaded;
    String newDatabaseObjectName = getChildBeanName(vUIComponents, uiComponent.getName(), uiComponent.bNew);
    uiComponent.setName(newDatabaseObjectName);
    vUIComponents.add(uiComponent);
    uiComponent.setParent(this);
    insertOrderedComponent(uiComponent, after);
    if (isNew || isCut) {
        markApplicationAsDirty();
    }
}
Also used : EngineException(com.twinsoft.convertigo.engine.EngineException) FormatedContent(com.twinsoft.convertigo.beans.common.FormatedContent)

Aggregations

FormatedContent (com.twinsoft.convertigo.beans.common.FormatedContent)17 EngineException (com.twinsoft.convertigo.engine.EngineException)15 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)13 IFile (org.eclipse.core.resources.IFile)9 IProject (org.eclipse.core.resources.IProject)9 IDocument (org.eclipse.jface.text.IDocument)9 IEditorInput (org.eclipse.ui.IEditorInput)9 IEditorPart (org.eclipse.ui.IEditorPart)9 IPropertyListener (org.eclipse.ui.IPropertyListener)9 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)9 IDocumentProvider (org.eclipse.ui.texteditor.IDocumentProvider)9 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)9 IEditorDescriptor (org.eclipse.ui.IEditorDescriptor)7 Document (org.w3c.dom.Document)6 Element (org.w3c.dom.Element)6 NodeList (org.w3c.dom.NodeList)6 ComponentFileEditorInput (com.twinsoft.convertigo.eclipse.editors.ngx.ComponentFileEditorInput)5 CoreException (org.eclipse.core.runtime.CoreException)5 ComponentFileEditorInput (com.twinsoft.convertigo.eclipse.editors.mobile.ComponentFileEditorInput)4 JSONException (org.codehaus.jettison.json.JSONException)4