Search in sources :

Example 1 with ISharedComponent

use of com.twinsoft.convertigo.beans.core.ISharedComponent 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)

Aggregations

FormatedContent (com.twinsoft.convertigo.beans.common.FormatedContent)1 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)1 ISharedComponent (com.twinsoft.convertigo.beans.core.ISharedComponent)1 UISharedComponent (com.twinsoft.convertigo.beans.ngx.components.UISharedComponent)1 ComponentFileEditorInput (com.twinsoft.convertigo.eclipse.editors.ngx.ComponentFileEditorInput)1 EngineException (com.twinsoft.convertigo.engine.EngineException)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 IEditorDescriptor (org.eclipse.ui.IEditorDescriptor)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