Search in sources :

Example 1 with UICustom

use of com.twinsoft.convertigo.beans.ngx.components.UICustom 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 2 with UICustom

use of com.twinsoft.convertigo.beans.ngx.components.UICustom in project convertigo by convertigo.

the class NgxUIComponentTreeObject method launchEditor.

@Override
public void launchEditor(String editorType) {
    UIComponent uic = getObject();
    if (uic instanceof UICustom) {
        openHtmlFileEditor();
    } else if (uic instanceof UIStyle) {
        openCssFileEditor();
    } else if (uic instanceof UICustomAction) {
        String functionMarker = "function:" + ((UICustomAction) uic).getActionName();
        editFunction(uic, functionMarker, "actionValue");
    } else {
        super.launchEditor(editorType);
    }
}
Also used : UICustom(com.twinsoft.convertigo.beans.ngx.components.UICustom) UIStyle(com.twinsoft.convertigo.beans.ngx.components.UIStyle) UIComponent(com.twinsoft.convertigo.beans.ngx.components.UIComponent) UICustomAction(com.twinsoft.convertigo.beans.ngx.components.UICustomAction)

Aggregations

UICustom (com.twinsoft.convertigo.beans.ngx.components.UICustom)2 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)1 UIComponent (com.twinsoft.convertigo.beans.ngx.components.UIComponent)1 UICustomAction (com.twinsoft.convertigo.beans.ngx.components.UICustomAction)1 UIStyle (com.twinsoft.convertigo.beans.ngx.components.UIStyle)1 ComponentFileEditorInput (com.twinsoft.convertigo.eclipse.editors.ngx.ComponentFileEditorInput)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 IFile (org.eclipse.core.resources.IFile)1 IProject (org.eclipse.core.resources.IProject)1 CoreException (org.eclipse.core.runtime.CoreException)1 IDocument (org.eclipse.jface.text.IDocument)1 IEditorInput (org.eclipse.ui.IEditorInput)1 IEditorPart (org.eclipse.ui.IEditorPart)1 IPropertyListener (org.eclipse.ui.IPropertyListener)1 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)1 IDocumentProvider (org.eclipse.ui.texteditor.IDocumentProvider)1 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)1