use of org.eclipse.ui.IEditorInput 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.ui.IEditorInput 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.ui.IEditorInput 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.ui.IEditorInput in project cubrid-manager by CUBRID.
the class EditConfigEditor method doImport.
/**
* Perform the import based upon the given ConfigType.
*
* @param configType the ConfigType
*/
protected void doImport(ConfigType configType) {
IEditorInput input = this.getEditorInput();
if (!(input instanceof ConfEditInput)) {
return;
}
ImportConfigDialog dialog = new ImportConfigDialog(this.getSite().getShell(), configType, true);
if (defaultImportFileName != null && !"".equals(defaultImportFileName)) {
dialog.setDefaultFileName(defaultImportFileName);
}
if (defaultImportFileCharset != null && !"".equals(defaultImportFileCharset)) {
dialog.setDefaultCharset(defaultImportFileCharset);
}
if (dialog.open() == Dialog.OK) {
defaultImportFileName = dialog.getDefaultFileName();
defaultImportFileCharset = dialog.getDefaultCharset();
contents = dialog.getImportFileContent();
createContent();
}
}
use of org.eclipse.ui.IEditorInput in project cubrid-manager by CUBRID.
the class EditConfigEditor method doExport.
/**
* Perform the export based upon the given ConfigType.
*
* @param configType the ConfigType
*/
protected void doExport(ConfigType configType) {
IEditorInput input = this.getEditorInput();
if (!(input instanceof ConfEditInput)) {
return;
}
ExportConfigDialog dialog = new ExportConfigDialog(this.getSite().getShell(), configType, true);
if (defaultExportFilePath != null && !"".equals(defaultExportFilePath)) {
dialog.setDefaultFilePath(defaultExportFilePath);
}
if (defaultExportFileName != null && !"".equals(defaultExportFileName)) {
dialog.setDefaultFileName(defaultExportFileName);
}
if (defaultExportFileExtName != null && !"".equals(defaultExportFileExtName)) {
dialog.setDefaultFileExtName(defaultExportFileExtName);
}
if (defaultExportFileCharset != null && !"".equals(defaultExportFileCharset)) {
dialog.setOutputFileCharset(defaultExportFileCharset);
}
if (dialog.open() == Dialog.OK) {
defaultExportFilePath = dialog.getDefaultFilePath();
defaultExportFileName = dialog.getDefaultFileName();
defaultExportFileExtName = dialog.getDefaultFileExtName();
String fileFullName = dialog.getOutputFileFullName();
defaultExportFileCharset = dialog.getOutputFileCharset();
ConfigParaHelp.exportConf(contents, fileFullName, defaultExportFileCharset);
}
}
Aggregations