Search in sources :

Example 1 with StructuredTextEditor

use of org.eclipse.wst.sse.ui.StructuredTextEditor in project tmdm-studio-se by Talend.

the class XSDEditor method doSave.

@Override
public void doSave(IProgressMonitor monitor) {
    XSDDirectivesManager.removeUnusedXSDImports(getXSDSchema());
    structuredTextEditor.doSave(monitor);
    InputStream stream = null;
    try {
        EditorPart part = (EditorPart) getSelectedPage();
        String xsd = null;
        if (null != part) {
            if (part instanceof StructuredTextEditor) {
                xsd = ((StructuredTextEditor) part).getTextViewer().getDocument().get();
            } else {
                // main page or er editor
                DataModelMainPage dmp = getdMainPage();
                xsd = dmp.getXSDSchemaString();
            }
        }
        if (null != xsd) {
            DataModelMainPage mainPage = getdMainPage();
            WSDataModel wsDataModel = (WSDataModel) xobject.getWsObject();
            wsDataModel.setXsdSchema(xsd);
            if (mainPage != null) {
                mainPage.save(xsd);
            }
            // $NON-NLS-1$
            fileContents = xsd.getBytes("utf-8");
        }
        getDataModelEditorPage().setDirty(false);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    } finally {
        IOUtils.closeQuietly(stream);
        if (null != monitor) {
            monitor.done();
        }
    }
}
Also used : WSDataModel(com.amalto.workbench.webservices.WSDataModel) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DataModelMainPage(com.amalto.workbench.editors.DataModelMainPage) MultiPageEditorPart(org.eclipse.ui.part.MultiPageEditorPart) IEditorPart(org.eclipse.ui.IEditorPart) EditorPart(org.eclipse.ui.part.EditorPart) StructuredTextEditor(org.eclipse.wst.sse.ui.StructuredTextEditor) PartInitException(org.eclipse.ui.PartInitException) SAXParseException(org.xml.sax.SAXParseException)

Example 2 with StructuredTextEditor

use of org.eclipse.wst.sse.ui.StructuredTextEditor in project tmdm-studio-se by Talend.

the class XSDEditor method createSourcePage.

protected void createSourcePage() {
    this.structuredTextEditor = new StructuredTextEditor() {

        @Override
        public boolean isEditable() {
            if (isReadOnly()) {
                return false;
            }
            return super.isEditable();
        }
    };
    try {
        int index = addPage(this.structuredTextEditor, getEditorInput());
        setPageText(index, org.eclipse.wst.xsd.ui.internal.adt.editor.Messages._UI_LABEL_SOURCE);
        this.structuredTextEditor.update();
        this.structuredTextEditor.setEditorPart(this);
        this.structuredTextEditor.addPropertyListener(this);
        /*
             * **please don't remove this annotation util the problem is really resolve.
             * 
             * Here add a property listener to source editor to achieve a effect that when source editor is modified by
             * user, notify the model editor that it should be in dirty state.
             * 
             * this is not a perfect resolution of issue TMDM-6403, because we have not find the real reason that lead
             * to that result. the more detailed thing is the variable 'fSynchronizationStamp' in class
             * 'ResourceTextFileBuffer' is updated in some place and this variable finally affect the variable
             * 'fCanBeSaved' (see documentChanged method of the inner class DocumentListener)which indicated the source
             * editor's dirty state, so affect combined editor's dirty state,then affect the combined editor's property
             * listener's execution, then lead to the editor's save and model validation.
             */
        firePropertyChange(1);
    } catch (PartInitException e) {
        ErrorDialog.openError(getSite().getShell(), Messages.XSDEditor_ErrorMessage, null, e.getStatus());
    }
}
Also used : PartInitException(org.eclipse.ui.PartInitException) StructuredTextEditor(org.eclipse.wst.sse.ui.StructuredTextEditor)

Example 3 with StructuredTextEditor

use of org.eclipse.wst.sse.ui.StructuredTextEditor in project liferay-ide by liferay.

the class LayoutTplEditor method createEditorPages.

@Override
protected void createEditorPages() throws PartInitException {
    _sourcePage = new StructuredTextEditor();
    _sourcePage.setEditorPart(this);
    addPage(_SOURCE_PAGE_INDEX, _sourcePage, getEditorInput());
    setPageText(_SOURCE_PAGE_INDEX, _SOURCE_PAGE_TITLE);
    initSourceModel();
    addDeferredPage(1, _PREVIEW_PAGE_TITLE, "preview");
    addDeferredPage(2, _DESIGN_PAGE_TITLE, "designPage");
}
Also used : StructuredTextEditor(org.eclipse.wst.sse.ui.StructuredTextEditor)

Example 4 with StructuredTextEditor

use of org.eclipse.wst.sse.ui.StructuredTextEditor in project liferay-ide by liferay.

the class UITestsUtils method getEditor.

public static StructuredTextEditor getEditor(IFile file) {
    StructuredTextEditor editor = (StructuredTextEditor) fileToEditorMap.get(file);
    if (editor == null) {
        try {
            final IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
            final IWorkbenchPage page = workbenchWindow.getActivePage();
            final IEditorPart editorPart = IDE.openEditor(page, file, true, true);
            assertNotNull(editorPart);
            if (editorPart instanceof SapphireEditorForXml) {
                editor = ((SapphireEditorForXml) editorPart).getXmlEditor();
            } else if (editorPart instanceof StructuredTextEditor) {
                editor = ((StructuredTextEditor) editorPart);
            } else if (editorPart instanceof XMLMultiPageEditorPart) {
                XMLMultiPageEditorPart xmlEditorPart = (XMLMultiPageEditorPart) editorPart;
                editor = (StructuredTextEditor) xmlEditorPart.getAdapter(StructuredTextEditor.class);
            }
            assertNotNull(editor);
            standardizeLineEndings(editor);
            fileToEditorMap.put(file, editor);
        } catch (Exception e) {
            fail("Could not open editor for " + file + " exception: " + e.getMessage());
        }
    }
    return editor;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) SapphireEditorForXml(org.eclipse.sapphire.ui.swt.xml.editor.SapphireEditorForXml) XMLMultiPageEditorPart(org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) StructuredTextEditor(org.eclipse.wst.sse.ui.StructuredTextEditor)

Example 5 with StructuredTextEditor

use of org.eclipse.wst.sse.ui.StructuredTextEditor in project liferay-ide by liferay.

the class UITestsUtils method getSourceViewerConfiguraionFromOpenedEditor.

// open the editor and get the actual SourceViewerConfiguration
public static SourceViewerConfiguration getSourceViewerConfiguraionFromOpenedEditor(IFile file) throws Exception {
    StructuredTextEditor editor = getEditor(file);
    Method getConfMethod = ReflectionUtil.getDeclaredMethod(editor.getClass(), "getSourceViewerConfiguration", true);
    if (getConfMethod != null) {
        getConfMethod.setAccessible(true);
        Object obj = getConfMethod.invoke(editor);
        if (obj != null && obj instanceof SourceViewerConfiguration) {
            return (SourceViewerConfiguration) obj;
        }
    }
    return null;
}
Also used : SourceViewerConfiguration(org.eclipse.jface.text.source.SourceViewerConfiguration) Method(java.lang.reflect.Method) StructuredTextEditor(org.eclipse.wst.sse.ui.StructuredTextEditor)

Aggregations

StructuredTextEditor (org.eclipse.wst.sse.ui.StructuredTextEditor)67 IFile (org.eclipse.core.resources.IFile)29 IEditorPart (org.eclipse.ui.IEditorPart)28 StructuredTextViewer (org.eclipse.wst.sse.ui.internal.StructuredTextViewer)21 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)18 IDocument (org.eclipse.jface.text.IDocument)15 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)15 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)12 Position (org.eclipse.jface.text.Position)11 ArrayList (java.util.ArrayList)10 List (java.util.List)10 BadLocationException (org.eclipse.jface.text.BadLocationException)9 ITextSelection (org.eclipse.jface.text.ITextSelection)6 PartInitException (org.eclipse.ui.PartInitException)6 XMLMultiPageEditorPart (org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart)6 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 Action (org.eclipse.jface.action.Action)4 Separator (org.eclipse.jface.action.Separator)4 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)3 IFileEditorInput (org.eclipse.ui.IFileEditorInput)3