Search in sources :

Example 86 with IEditorInput

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);
}
Also used : IFile(org.eclipse.core.resources.IFile) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) Document(org.eclipse.jface.text.Document) IFile(org.eclipse.core.resources.IFile) IEditorInput(org.eclipse.ui.IEditorInput) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 87 with IEditorInput

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;
}
Also used : IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) FastPartitioner(org.eclipse.jface.text.rules.FastPartitioner) DocumentProvider(com.cubrid.tool.editor.DocumentProvider) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) IDocument(org.eclipse.jface.text.IDocument) IEditorInput(org.eclipse.ui.IEditorInput)

Example 88 with IEditorInput

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;
}
Also used : IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) FastPartitioner(org.eclipse.jface.text.rules.FastPartitioner) DocumentProvider(com.cubrid.tool.editor.DocumentProvider) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) XMLPartitionScanner(com.cubrid.tool.editor.xml.scanner.XMLPartitionScanner) IDocument(org.eclipse.jface.text.IDocument) IEditorInput(org.eclipse.ui.IEditorInput)

Example 89 with IEditorInput

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();
    }
}
Also used : ConfEditInput(com.cubrid.cubridmanager.ui.host.action.ConfEditInput) ImportConfigDialog(com.cubrid.cubridmanager.ui.host.dialog.ImportConfigDialog) IEditorInput(org.eclipse.ui.IEditorInput)

Example 90 with IEditorInput

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);
    }
}
Also used : ExportConfigDialog(com.cubrid.cubridmanager.ui.host.dialog.ExportConfigDialog) ConfEditInput(com.cubrid.cubridmanager.ui.host.action.ConfEditInput) IEditorInput(org.eclipse.ui.IEditorInput)

Aggregations

IEditorInput (org.eclipse.ui.IEditorInput)135 IFile (org.eclipse.core.resources.IFile)38 IEditorPart (org.eclipse.ui.IEditorPart)37 PartInitException (org.eclipse.ui.PartInitException)31 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)28 CoreException (org.eclipse.core.runtime.CoreException)25 IFileEditorInput (org.eclipse.ui.IFileEditorInput)22 IDocument (org.eclipse.jface.text.IDocument)17 IEditorReference (org.eclipse.ui.IEditorReference)17 FileEditorInput (org.eclipse.ui.part.FileEditorInput)16 File (java.io.File)14 ArrayList (java.util.ArrayList)14 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)14 IDocumentProvider (org.eclipse.ui.texteditor.IDocumentProvider)14 IResource (org.eclipse.core.resources.IResource)13 Shell (org.eclipse.swt.widgets.Shell)13 IViewPart (org.eclipse.ui.IViewPart)13 IPath (org.eclipse.core.runtime.IPath)12 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)12 FileStoreEditorInput (org.eclipse.ui.ide.FileStoreEditorInput)11