Search in sources :

Example 1 with TextFileDocumentProvider

use of org.eclipse.ui.editors.text.TextFileDocumentProvider in project erlide_eclipse by erlang.

the class ErlangScratchPad method initializeEditor.

@Override
protected void initializeEditor() {
    colorManager = new ColorManager();
    setDocumentProvider(new TextFileDocumentProvider());
    final IPreferenceStore store = ErlangScratchPad.getErlangEditorPreferenceStore();
    setPreferenceStore(store);
    final ErlangSourceViewerConfiguration cfg = new ErlangScratchPadConfiguration(getPreferenceStore(), colorManager, this);
    setSourceViewerConfiguration(cfg);
}
Also used : ErlangSourceViewerConfiguration(org.erlide.ui.editors.erl.ErlangSourceViewerConfiguration) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) ColorManager(org.erlide.ui.util.ColorManager) TextFileDocumentProvider(org.eclipse.ui.editors.text.TextFileDocumentProvider)

Example 2 with TextFileDocumentProvider

use of org.eclipse.ui.editors.text.TextFileDocumentProvider in project tdq-studio-se by Talend.

the class CommonFormEditor method updateDocumentProvider.

/**
 * Provide a new DocumentProvider based on the given editor input.
 *
 * @param input the editor input.
 * @throws CoreException
 */
protected void updateDocumentProvider(IEditorInput input) throws CoreException {
    IProgressMonitor rememberedProgressMonitor = null;
    provider = new TextFileDocumentProvider();
    provider.addElementStateListener(fElementStateListener);
    IDocumentProviderExtension2 extension = (IDocumentProviderExtension2) provider;
    extension.setProgressMonitor(rememberedProgressMonitor);
    provider.connect(input);
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IDocumentProviderExtension2(org.eclipse.ui.texteditor.IDocumentProviderExtension2) TextFileDocumentProvider(org.eclipse.ui.editors.text.TextFileDocumentProvider)

Example 3 with TextFileDocumentProvider

use of org.eclipse.ui.editors.text.TextFileDocumentProvider in project jbosstools-hibernate by jbosstools.

the class SaveQueryEditorListener method propertyChanged.

/* (non-Javadoc)
	 * @see org.eclipse.ui.IPropertyListener#propertyChanged(java.lang.Object, int)
	 */
public void propertyChanged(Object source, int propId) {
    if (IEditorPart.PROP_DIRTY == propId && !editor.isDirty()) {
        IDocumentProvider docProvider = fromEditorPart.getDocumentProvider();
        final IFile file = ((IFileEditorInput) fromEditorPart.getEditorInput()).getFile();
        final IDocument doc = docProvider.getDocument(fromEditorPart.getEditorInput());
        boolean isDocChanged = true;
        try {
            if (query.equals(doc.get(position.x, position.y))) {
                isDocChanged = false;
            }
        } catch (BadLocationException e1) {
        // document changed and we can get the exception
        }
        final String editorTitle = fromEditorPart.getTitle();
        final String editor_name = editor instanceof HQLEditor ? JdtUiMessages.SaveQueryEditorListener_hql_editor : JdtUiMessages.SaveQueryEditorListener_cri_editor;
        if (isDocChanged) {
            String information_message = NLS.bind(JdtUiMessages.SaveQueryEditorListener_replacequestion_confirm, editorTitle);
            MessageDialog.openInformation(null, JdtUiMessages.SaveQueryEditorListener_replacetitle_info, information_message);
            return;
        }
        final String newQuery = editor.getEditorText();
        final String wizard_title = NLS.bind(JdtUiMessages.SaveQueryEditorListener_refactoringtitle, editor_name);
        Refactoring ref = new Refactoring() {

            @Override
            public RefactoringStatus checkFinalConditions(IProgressMonitor pm) {
                return RefactoringStatus.create(Status.OK_STATUS);
            }

            @Override
            public RefactoringStatus checkInitialConditions(IProgressMonitor pm) {
                return RefactoringStatus.create(Status.OK_STATUS);
            }

            @Override
            public Change createChange(IProgressMonitor pm) {
                String change_name = NLS.bind(JdtUiMessages.SaveQueryEditorListener_change_name, editor_name, editorTitle);
                DocumentChange change = new DocumentChange(change_name, doc);
                TextEdit replaceEdit = new ReplaceEdit(position.x, position.y, newQuery);
                change.setEdit(replaceEdit);
                String cc_name = NLS.bind(JdtUiMessages.SaveQueryEditorListener_composite_change_name, editor_name);
                MultiStateTextFileChange mChange = new MultiStateTextFileChange(cc_name, file);
                mChange.addChange(change);
                return mChange;
            }

            @Override
            public String getName() {
                return JdtUiMessages.SaveQueryEditorListener_composite_change_name;
            }
        };
        RefactoringWizard wizard = new RefactoringWizard(ref, RefactoringWizard.DIALOG_BASED_USER_INTERFACE) {

            @Override
            protected void addUserInputPages() {
                UserInputWizardPage page = new UserInputWizardPage(wizard_title) {

                    public void createControl(Composite parent) {
                        Composite container = new Composite(parent, SWT.NULL);
                        GridLayout layout = new GridLayout();
                        container.setLayout(layout);
                        layout.numColumns = 1;
                        layout.verticalSpacing = 9;
                        Label label = new Label(container, SWT.NULL);
                        label.setText(NLS.bind(JdtUiMessages.SaveQueryEditorListener_replacequestion, editor_name, editorTitle));
                        setControl(container);
                    }
                };
                addPage(page);
            }
        };
        wizard.setWindowTitle(wizard_title);
        wizard.setDefaultPageTitle(wizard_title);
        IWorkbenchWindow win = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        if (new RefactoringStarter().activate(wizard, win.getShell(), wizard_title, RefactoringSaveHelper.SAVE_ALL)) {
            query = newQuery;
            position.y = query.length();
            fromEditorPart.doSave(null);
        } else {
            if (editor.getDocumentProvider() instanceof TextFileDocumentProvider) {
                ((TextFileDocumentProvider) editor.getDocumentProvider()).setCanSaveDocument(editor.getEditorInput());
            }
        }
    }
}
Also used : MultiStateTextFileChange(org.eclipse.ltk.core.refactoring.MultiStateTextFileChange) UserInputWizardPage(org.eclipse.ltk.ui.refactoring.UserInputWizardPage) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IFile(org.eclipse.core.resources.IFile) Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) RefactoringStarter(org.eclipse.jdt.internal.ui.refactoring.actions.RefactoringStarter) DocumentChange(org.eclipse.ltk.core.refactoring.DocumentChange) TextFileDocumentProvider(org.eclipse.ui.editors.text.TextFileDocumentProvider) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) GridLayout(org.eclipse.swt.layout.GridLayout) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) RefactoringWizard(org.eclipse.ltk.ui.refactoring.RefactoringWizard) IFileEditorInput(org.eclipse.ui.IFileEditorInput) TextEdit(org.eclipse.text.edits.TextEdit) ReplaceEdit(org.eclipse.text.edits.ReplaceEdit) HQLEditor(org.hibernate.eclipse.hqleditor.HQLEditor) Refactoring(org.eclipse.ltk.core.refactoring.Refactoring) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 4 with TextFileDocumentProvider

use of org.eclipse.ui.editors.text.TextFileDocumentProvider in project erlide_eclipse by erlang.

the class ErlangEditor method initializeEditor.

@Override
protected void initializeEditor() {
    colorManager = new ColorManager();
    setDocumentProvider(new TextFileDocumentProvider());
    final IPreferenceStore store = ErlangEditor.getErlangEditorPreferenceStore();
    setPreferenceStore(store);
    final ErlangSourceViewerConfiguration cfg = new EditorConfiguration(getPreferenceStore(), this, colorManager);
    setSourceViewerConfiguration(cfg);
}
Also used : IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) ColorManager(org.erlide.ui.util.ColorManager) TextFileDocumentProvider(org.eclipse.ui.editors.text.TextFileDocumentProvider)

Example 5 with TextFileDocumentProvider

use of org.eclipse.ui.editors.text.TextFileDocumentProvider in project ch.hsr.ifs.cdttesting by IFS-HSR.

the class JumpToRTSHandler method jump.

private void jump() {
    if (className != null) {
        IType cls = null;
        try {
            cls = project.findType(className);
        } catch (JavaModelException e) {
            return;
        }
        try {
            IFile file = project.getProject().getFile(getTestFileName(cls));
            IWorkbench workbench = PlatformUI.getWorkbench();
            IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
            FileEditorInput input = new FileEditorInput(file);
            IDocumentProvider provider = new TextFileDocumentProvider();
            provider.connect(input);
            IDocument document = provider.getDocument(input);
            TestFile testFile = new TestFile(input, provider);
            testFile.parse();
            IEditorDescriptor defaultEditor = workbench.getEditorRegistry().getDefaultEditor(file.getName());
            String editorId = defaultEditor.getId();
            if (!className.equals(testName)) {
                for (Test test : testFile.getTests()) {
                    if (test.toString().equals(testName)) {
                        int line = document.getLineOfOffset(test.getPosition().getOffset());
                        IMarker lineMarker = file.createMarker(IMarker.TEXT);
                        lineMarker.setAttribute(IMarker.LINE_NUMBER, line + 1);
                        lineMarker.setAttribute(IDE.EDITOR_ID_ATTR, editorId);
                        IDE.openEditor(page, lineMarker);
                        lineMarker.delete();
                        return;
                    }
                }
            } else {
                IDE.openEditor(page, file);
            }
        } catch (CoreException | BadLocationException | NullPointerException e) {
            e.printStackTrace();
            MessageDialog.openError(shell, "Jump to RTS", "Failed to find associated RTS file.");
        }
    }
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) IFile(org.eclipse.core.resources.IFile) IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) TextFileDocumentProvider(org.eclipse.ui.editors.text.TextFileDocumentProvider) IType(org.eclipse.jdt.core.IType) IWorkbench(org.eclipse.ui.IWorkbench) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) CoreException(org.eclipse.core.runtime.CoreException) Test(name.graf.emanuel.testfileeditor.model.node.Test) FileEditorInput(org.eclipse.ui.part.FileEditorInput) TestFile(name.graf.emanuel.testfileeditor.model.TestFile) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IMarker(org.eclipse.core.resources.IMarker) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

TextFileDocumentProvider (org.eclipse.ui.editors.text.TextFileDocumentProvider)9 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)6 SourceViewerConfiguration (org.eclipse.jface.text.source.SourceViewerConfiguration)4 ColorManager (org.eclipse.titan.designer.editors.ColorManager)4 ForwardingDocumentProvider (org.eclipse.ui.editors.text.ForwardingDocumentProvider)4 ChainedPreferenceStore (org.eclipse.ui.texteditor.ChainedPreferenceStore)4 IFile (org.eclipse.core.resources.IFile)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 BadLocationException (org.eclipse.jface.text.BadLocationException)2 IDocument (org.eclipse.jface.text.IDocument)2 IDocumentProvider (org.eclipse.ui.texteditor.IDocumentProvider)2 ColorManager (org.erlide.ui.util.ColorManager)2 TestFile (name.graf.emanuel.testfileeditor.model.TestFile)1 Test (name.graf.emanuel.testfileeditor.model.node.Test)1 IMarker (org.eclipse.core.resources.IMarker)1 CoreException (org.eclipse.core.runtime.CoreException)1 IType (org.eclipse.jdt.core.IType)1 JavaModelException (org.eclipse.jdt.core.JavaModelException)1 RefactoringStarter (org.eclipse.jdt.internal.ui.refactoring.actions.RefactoringStarter)1 DocumentChange (org.eclipse.ltk.core.refactoring.DocumentChange)1