Search in sources :

Example 6 with ComponentFileEditorInput

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

the class NgxComponentTreeObject method closeAllEditors.

public void closeAllEditors(boolean save) {
    MobileComponent mc = getObject();
    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(mc) || ((ComponentFileEditorInput) editorInput).isChildOf(mc)) {
                        activePage.closeEditor(editorRef.getEditor(false), save);
                    }
                }
            } catch (Exception e) {
            }
        }
    }
}
Also used : IEditorReference(org.eclipse.ui.IEditorReference) ComponentFileEditorInput(com.twinsoft.convertigo.eclipse.editors.ngx.ComponentFileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorInput(org.eclipse.ui.IEditorInput) MobileComponent(com.twinsoft.convertigo.beans.ngx.components.MobileComponent)

Example 7 with ComponentFileEditorInput

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

the class NgxComponentTreeObject method closeComponentFileEditor.

protected void closeComponentFileEditor(final IFile file) {
    try {
        IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
        IContainer parent = file.getParent();
        String extension = file.getFileExtension();
        for (IEditorReference editorReference : activePage.getEditorReferences()) {
            IEditorInput editorInput = editorReference.getEditorInput();
            if (editorInput instanceof ComponentFileEditorInput) {
                ComponentFileEditorInput cfei = (ComponentFileEditorInput) editorInput;
                IFile oldFile = cfei.getFile();
                if (parent.equals(oldFile.getParent()) && extension.equals(oldFile.getFileExtension())) {
                    activePage.closeEditor(editorReference.getEditor(false), true);
                    return;
                }
            }
        }
    } catch (Exception e) {
    }
}
Also used : IEditorReference(org.eclipse.ui.IEditorReference) IFile(org.eclipse.core.resources.IFile) ComponentFileEditorInput(com.twinsoft.convertigo.eclipse.editors.ngx.ComponentFileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IContainer(org.eclipse.core.resources.IContainer) IEditorInput(org.eclipse.ui.IEditorInput)

Example 8 with ComponentFileEditorInput

use of com.twinsoft.convertigo.eclipse.editors.ngx.ComponentFileEditorInput 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

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