Search in sources :

Example 1 with ComponentFileEditorInput

use of com.twinsoft.convertigo.eclipse.editors.ngx.ComponentFileEditorInput in project convertigo by convertigo.

the class NgxUIComponentTreeObject method openCssFileEditor.

private void openCssFileEditor() {
    final UIStyle ms = (UIStyle) getObject();
    String filePath = "/_private/editor/" + StringUtils.hash(ms.getParent().getQName()) + "/" + ms.getName() + ".scss";
    try {
        // Refresh project resource
        String projectName = ms.getProject().getName();
        IProject project = ConvertigoPlugin.getDefault().getProjectPluginResource(projectName);
        // Close editor
        IFile file = project.getFile(filePath);
        closeComponentFileEditor(file);
        // Write css file
        SwtUtils.fillFile(file, formatStyleContent(ms));
        // Open file in editor
        if (file.exists()) {
            IEditorInput input = new ComponentFileEditorInput(file, ms);
            if (input != null) {
                String editorId = "org.eclipse.ui.genericeditor.GenericEditor";
                IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
                IEditorPart editorPart = activePage.openEditor(input, editorId);
                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 content = unformatStyleContent(ms, doc.get());
                                if (content != null) {
                                    FormatedContent formatedContent = new FormatedContent(content);
                                    NgxUIComponentTreeObject.this.setPropertyValue("styleContent", formatedContent);
                                }
                            }
                        }
                    }
                });
            }
        }
    } catch (CoreException e) {
        ConvertigoPlugin.logException(e, "Unable to open file '" + filePath + "'!");
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) ComponentFileEditorInput(com.twinsoft.convertigo.eclipse.editors.ngx.ComponentFileEditorInput) IEditorPart(org.eclipse.ui.IEditorPart) IProject(org.eclipse.core.resources.IProject) IPropertyListener(org.eclipse.ui.IPropertyListener) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) CoreException(org.eclipse.core.runtime.CoreException) UIStyle(com.twinsoft.convertigo.beans.ngx.components.UIStyle) 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 2 with ComponentFileEditorInput

use of com.twinsoft.convertigo.eclipse.editors.ngx.ComponentFileEditorInput in project convertigo by convertigo.

the class NgxUIComponentTreeObject method openHtmlFileEditor.

private void openHtmlFileEditor() {
    final UICustom mc = (UICustom) getObject();
    String filePath = "/_private/" + mc.priority + ".html";
    try {
        // Refresh project resource
        String projectName = mc.getProject().getName();
        IProject project = ConvertigoPlugin.getDefault().getProjectPluginResource(projectName);
        project.refreshLocal(IResource.DEPTH_INFINITE, null);
        // Close editor
        IFile file = project.getFile(filePath);
        closeComponentFileEditor(file);
        // Write html file
        try {
            InputStream is = new ByteArrayInputStream(mc.getCustomTemplate().getBytes("ISO-8859-1"));
            file.create(is, true, null);
            file.setCharset("ISO-8859-1", null);
        } catch (UnsupportedEncodingException e) {
        }
        file.refreshLocal(IResource.DEPTH_ZERO, null);
        // Open file in editor
        if (file.exists()) {
            IEditorInput input = new ComponentFileEditorInput(file, mc);
            if (input != null) {
                String editorId = "org.eclipse.ui.genericeditor.GenericEditor";
                IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
                IEditorPart editorPart = activePage.openEditor(input, editorId);
                editorPart.addPropertyListener(new IPropertyListener() {

                    boolean isFirstChange = false;

                    @Override
                    public void propertyChanged(Object source, int propId) {
                        if (source instanceof ITextEditor) {
                            // org.eclipse.wst.sse.ui.StructuredTextEditor
                            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 htmlTemplate = doc.get();
                                NgxUIComponentTreeObject.this.setPropertyValue("htmlTemplate", htmlTemplate);
                            }
                        }
                    }
                });
            }
        }
    } catch (CoreException e) {
        ConvertigoPlugin.logException(e, "Unable to open file '" + filePath + "'!");
    }
}
Also used : UICustom(com.twinsoft.convertigo.beans.ngx.components.UICustom) IFile(org.eclipse.core.resources.IFile) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ComponentFileEditorInput(com.twinsoft.convertigo.eclipse.editors.ngx.ComponentFileEditorInput) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IEditorPart(org.eclipse.ui.IEditorPart) IProject(org.eclipse.core.resources.IProject) IPropertyListener(org.eclipse.ui.IPropertyListener) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) IEditorInput(org.eclipse.ui.IEditorInput) IDocument(org.eclipse.jface.text.IDocument)

Example 3 with ComponentFileEditorInput

use of com.twinsoft.convertigo.eclipse.editors.ngx.ComponentFileEditorInput in project convertigo by convertigo.

the class NgxUIComponentTreeObject 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);
                                NgxUIComponentTreeObject.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.ngx.components.IScriptComponent) ApplicationComponent(com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent) ComponentFileEditorInput(com.twinsoft.convertigo.eclipse.editors.ngx.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.ngx.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 4 with ComponentFileEditorInput

use of com.twinsoft.convertigo.eclipse.editors.ngx.ComponentFileEditorInput in project convertigo by convertigo.

the class NgxApplicationComponentTreeObject method editAppComponentTsFile.

public void editAppComponentTsFile() {
    final ApplicationComponent application = getObject();
    try {
        // Refresh project resource
        String projectName = application.getProject().getName();
        IProject project = ConvertigoPlugin.getDefault().getProjectPluginResource(projectName);
        project.refreshLocal(IResource.DEPTH_INFINITE, null);
        // Close editor
        String filePath = application.getProject().getMobileBuilder().getTempTsRelativePath(application);
        IFile file = project.getFile(filePath);
        closeComponentFileEditor(file);
        // Write temporary file
        application.getProject().getMobileBuilder().writeAppComponentTempTs(application);
        file.refreshLocal(IResource.DEPTH_ZERO, null);
        // Open file in editor
        if (file.exists()) {
            IEditorInput input = new ComponentFileEditorInput(file, application);
            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 componentScriptContent = new FormatedContent(MobileBuilder.getMarkers(doc.get()));
                                NgxApplicationComponentTreeObject.this.setPropertyValue("componentScriptContent", componentScriptContent);
                            }
                        }
                    }
                });
            }
        }
    } catch (Exception e) {
        ConvertigoPlugin.logException(e, "Unable to open typescript file for page '" + application.getName() + "'!");
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) ApplicationComponent(com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent) ComponentFileEditorInput(com.twinsoft.convertigo.eclipse.editors.ngx.ComponentFileEditorInput) IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) IEditorPart(org.eclipse.ui.IEditorPart) IProject(org.eclipse.core.resources.IProject) IPropertyListener(org.eclipse.ui.IPropertyListener) InvalidParameterException(java.security.InvalidParameterException) PartInitException(org.eclipse.ui.PartInitException) InvocationTargetException(java.lang.reflect.InvocationTargetException) EngineException(com.twinsoft.convertigo.engine.EngineException) 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 5 with ComponentFileEditorInput

use of com.twinsoft.convertigo.eclipse.editors.ngx.ComponentFileEditorInput in project convertigo by convertigo.

the class NgxPageComponentTreeObject method editPageTsFile.

public void editPageTsFile() {
    final PageComponent page = (PageComponent) getObject();
    try {
        // Refresh project resource
        String projectName = page.getProject().getName();
        IProject project = ConvertigoPlugin.getDefault().getProjectPluginResource(projectName);
        project.refreshLocal(IResource.DEPTH_INFINITE, null);
        // Close editor
        String filePath = page.getProject().getMobileBuilder().getTempTsRelativePath(page);
        IFile file = project.getFile(filePath);
        closeComponentFileEditor(file);
        // Write temporary file
        page.getProject().getMobileBuilder().writePageTempTs(page);
        file.refreshLocal(IResource.DEPTH_ZERO, null);
        // Open file in editor
        if (file.exists()) {
            IEditorInput input = new ComponentFileEditorInput(file, page);
            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()));
                                NgxPageComponentTreeObject.this.setPropertyValue("scriptContent", scriptContent);
                            }
                        }
                    }
                });
            }
        }
    } catch (Exception e) {
        ConvertigoPlugin.logException(e, "Unable to open typescript file for page '" + page.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) PageComponent(com.twinsoft.convertigo.beans.ngx.components.PageComponent) IProject(org.eclipse.core.resources.IProject) IPropertyListener(org.eclipse.ui.IPropertyListener) EngineException(com.twinsoft.convertigo.engine.EngineException) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) FormatedContent(com.twinsoft.convertigo.beans.common.FormatedContent) IEditorInput(org.eclipse.ui.IEditorInput) IDocument(org.eclipse.jface.text.IDocument)

Aggregations

ComponentFileEditorInput (com.twinsoft.convertigo.eclipse.editors.ngx.ComponentFileEditorInput)7 IEditorInput (org.eclipse.ui.IEditorInput)7 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)7 IFile (org.eclipse.core.resources.IFile)6 IProject (org.eclipse.core.resources.IProject)5 IDocument (org.eclipse.jface.text.IDocument)5 IEditorPart (org.eclipse.ui.IEditorPart)5 IPropertyListener (org.eclipse.ui.IPropertyListener)5 IDocumentProvider (org.eclipse.ui.texteditor.IDocumentProvider)5 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)5 FormatedContent (com.twinsoft.convertigo.beans.common.FormatedContent)4 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)4 EngineException (com.twinsoft.convertigo.engine.EngineException)3 CoreException (org.eclipse.core.runtime.CoreException)3 IEditorDescriptor (org.eclipse.ui.IEditorDescriptor)3 ApplicationComponent (com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 IEditorReference (org.eclipse.ui.IEditorReference)2 IScriptComponent (com.twinsoft.convertigo.beans.ngx.components.IScriptComponent)1 MobileComponent (com.twinsoft.convertigo.beans.ngx.components.MobileComponent)1