use of org.eclipse.jface.text.Document in project dbeaver by serge-rider.
the class BaseTextEditor method saveToExternalFile.
public void saveToExternalFile() {
IEditorInput editorInput = getEditorInput();
IFile curFile = EditorUtils.getFileFromInput(editorInput);
String fileName = curFile == null ? null : curFile.getName();
final Document document = getDocument();
final File saveFile = DialogUtils.selectFileForSave(getSite().getShell(), "Save SQL script", new String[] { "*.sql", "*.txt", "*", "*.*" }, fileName);
if (document == null || saveFile == null) {
return;
}
try {
DBeaverUI.runInProgressService(new DBRRunnableWithProgress() {
@Override
public void run(final DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
StringReader cr = new StringReader(document.get());
ContentUtils.saveContentToFile(cr, saveFile, GeneralUtils.UTF8_ENCODING, monitor);
} catch (Exception e) {
throw new InvocationTargetException(e);
}
}
});
} catch (InterruptedException e) {
// do nothing
} catch (InvocationTargetException e) {
UIUtils.showErrorDialog(getSite().getShell(), "Save failed", null, e.getTargetException());
}
afterSaveToFile(saveFile);
}
use of org.eclipse.jface.text.Document in project dbeaver by serge-rider.
the class FileRefDocumentProvider method createDocument.
@Override
protected Document createDocument(Object element) throws CoreException {
Document document = createEmptyDocument();
IStorage storage = EditorUtils.getStorageFromInput(element);
if (storage != null) {
if (setDocumentContent(document, storage)) {
setupDocument(document);
return document;
}
}
File file = EditorUtils.getLocalFileFromInput(element);
if (file != null) {
try (InputStream stream = new FileInputStream(file)) {
setDocumentContent(document, stream, null);
setupDocument(document);
return document;
} catch (IOException e) {
throw new CoreException(GeneralUtils.makeExceptionStatus(e));
}
}
throw new IllegalArgumentException("Project document provider supports only editor inputs which provides IStorage facility");
}
use of org.eclipse.jface.text.Document in project cubrid-manager by CUBRID.
the class PropDocumentProvider method getDocument.
/**
* Retrieves the document to be edited.
*
* @param element Object
* @return IDocument
*/
public IDocument getDocument(Object element) {
IDocument document = null;
if (element instanceof IEditorInput) {
IEditorInput ei = ((IEditorInput) element);
DocumentProvider dp = (DocumentProvider) ei.getAdapter(DocumentProvider.class);
if (dp != null) {
document = dp.getDocument(element);
}
}
if (document == null) {
document = new Document();
}
IDocumentPartitioner partitioner = new FastPartitioner(new PropPartitionScanner(), PropPartitionScanner.LEGAL_CONTENT_TYPES);
partitioner.connect(document);
document.setDocumentPartitioner(partitioner);
return document;
}
use of org.eclipse.jface.text.Document in project cubrid-manager by CUBRID.
the class XMLDocumentProvider method getDocument.
/**
* Retrieves the document to be edited.
*
* @param element Object
* @return IDocument
*/
public IDocument getDocument(Object element) {
IDocument document = null;
if (element instanceof IEditorInput) {
IEditorInput ei = ((IEditorInput) element);
DocumentProvider dp = (DocumentProvider) ei.getAdapter(DocumentProvider.class);
if (dp != null) {
document = dp.getDocument(element);
}
}
if (document == null) {
document = new Document();
}
IDocumentPartitioner partitioner = new FastPartitioner(new XMLPartitionScanner(), new String[] { XMLPartitionScanner.XML_TAG, XMLPartitionScanner.XML_COMMENT });
partitioner.connect(document);
document.setDocumentPartitioner(partitioner);
return document;
}
use of org.eclipse.jface.text.Document in project AutoRefactor by JnRouvignac.
the class RefactoringRulesTest method testRefactoring0.
private void testRefactoring0() throws Exception {
final String sampleName = testName + "Sample.java";
final File sampleIn = new File(SAMPLES_BASE_DIR, "samples_in/" + sampleName);
assertTrue(testName + ": sample in file " + sampleIn + " should exist", sampleIn.exists());
final File sampleOut = new File(SAMPLES_BASE_DIR, "samples_out/" + sampleName);
assertTrue(testName + ": sample out file " + sampleOut + " should exist", sampleOut.exists());
final String refactoringClassname = testName + "Refactoring";
final RefactoringRule refactoring = getRefactoringClass(refactoringClassname);
assertNotNull(testName + ": refactoring class " + refactoringClassname + " should exist.\n" + "Make sure you added it to the method getAllRefactoringRules() " + "of the " + AllRefactoringRules.class + ".", refactoring);
final String sampleInSource = readAll(sampleIn);
final String sampleOutSource = readAll(sampleOut);
final IPackageFragment packageFragment = JavaCoreHelper.getPackageFragment(PACKAGE_NAME);
final ICompilationUnit cu = packageFragment.createCompilationUnit(sampleName, sampleInSource, true, null);
cu.getBuffer().setContents(sampleInSource);
cu.save(null, true);
final IDocument doc = new Document(sampleInSource);
new ApplyRefactoringsJob(null, null, TEST_ENVIRONMENT).applyRefactoring(doc, cu, new AggregateASTVisitor(Arrays.asList(refactoring)), newJavaProjectOptions(Release.javaSE("1.7.0"), 4), new NullProgressMonitor());
final String actual = normalizeJavaSourceCode(doc.get().replaceAll("samples_in", "samples_out"));
final String expected = normalizeJavaSourceCode(sampleOutSource);
assertEquals(testName + ": wrong output;", expected, actual);
}
Aggregations