Search in sources :

Example 1 with SetFileEncodingDialog

use of com.cubrid.common.ui.query.dialog.SetFileEncodingDialog in project cubrid-manager by CUBRID.

the class QueryOpenAction method run.

/**
	 * @see org.eclipse.jface.action.Action#run()
	 */
public void run() {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null || window.getActivePage() == null) {
        return;
    }
    IEditorPart editor = window.getActivePage().getActiveEditor();
    if (editor != null && editor.isDirty()) {
        int confirm = CommonUITool.openMsgBox(editor.getSite().getShell(), MessageDialog.WARNING, Messages.saveResource, Messages.bind(Messages.saveConfirm, editor.getTitle()), new String[] { Messages.btnYes, Messages.btnNo, Messages.cancel });
        switch(confirm) {
            case 0:
                editor.doSave(null);
                break;
            case 1:
                break;
            default:
                return;
        }
    }
    try {
        if (editor == null) {
            IEditorInput input = new QueryUnit();
            editor = window.getActivePage().openEditor(input, QueryEditorPart.ID);
        }
    } catch (PartInitException e) {
        CommonUITool.openErrorBox(e.getMessage());
    }
    if (editor == null) {
        return;
    }
    try {
        QueryEditorPart queryEditor = (QueryEditorPart) editor;
        SQLEditorComposite editorComp = queryEditor.getCombinedQueryComposite().getSqlEditorComp();
        String encoding = editorComp.getDocument().getEncoding();
        SetFileEncodingDialog dialog = new SetFileEncodingDialog(getShell(), encoding, true);
        if (IDialogConstants.OK_ID == dialog.open()) {
            editorComp.open(dialog.getFilePath(), dialog.getEncoding());
        }
    } catch (IOException e) {
        CommonUITool.openErrorBox(e.getMessage());
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) SQLEditorComposite(com.cubrid.common.ui.query.control.SQLEditorComposite) QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) QueryUnit(com.cubrid.common.ui.query.editor.QueryUnit) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException) IOException(java.io.IOException) SetFileEncodingDialog(com.cubrid.common.ui.query.dialog.SetFileEncodingDialog) IEditorInput(org.eclipse.ui.IEditorInput)

Example 2 with SetFileEncodingDialog

use of com.cubrid.common.ui.query.dialog.SetFileEncodingDialog in project cubrid-manager by CUBRID.

the class SQLEditorComposite method doOpen.

/**
	 * Open a file which
	 */
public void doOpen() throws IOException {
    if (dirty && !CommonUITool.openConfirmBox(Messages.msgConfirmEditorNotSaved)) {
        return;
    }
    String charset = document.getEncoding();
    SetFileEncodingDialog dialog = new SetFileEncodingDialog(getShell(), charset, true);
    if (IDialogConstants.OK_ID == dialog.open()) {
        open(dialog.getFilePath(), dialog.getEncoding());
    }
}
Also used : SetFileEncodingDialog(com.cubrid.common.ui.query.dialog.SetFileEncodingDialog)

Example 3 with SetFileEncodingDialog

use of com.cubrid.common.ui.query.dialog.SetFileEncodingDialog in project cubrid-manager by CUBRID.

the class SQLEditorComposite method save.

/**
	 * save the content of querySourceView
	 *
	 * @return boolean
	 * @throws IOException if failed
	 */
public boolean save() throws IOException {
    if (filepath == null) {
        doSaveAs();
        return false;
    }
    File file = new File(filepath);
    if (file == null || !file.exists()) {
        SetFileEncodingDialog dialog = new SetFileEncodingDialog(getShell(), document.getEncoding(), false);
        if (IDialogConstants.OK_ID == dialog.open()) {
            document.setEncoding(dialog.getEncoding());
            filepath = dialog.getFilePath();
            document.setFileName(filepath);
        } else {
            return false;
        }
    } else {
        document.setEncoding(document.getEncoding());
        document.setFileName(filepath);
    }
    document.save();
    dirty = false;
    updateTabName(filepath);
    return true;
}
Also used : File(java.io.File) SetFileEncodingDialog(com.cubrid.common.ui.query.dialog.SetFileEncodingDialog)

Example 4 with SetFileEncodingDialog

use of com.cubrid.common.ui.query.dialog.SetFileEncodingDialog in project cubrid-manager by CUBRID.

the class SQLEditorComposite method doSaveAs.

/**
	 * Save as the file content
	 *
	 * @throws IOException if failed
	 */
public void doSaveAs() throws IOException {
    SetFileEncodingDialog dialog = new SetFileEncodingDialog(getShell(), document.getEncoding(), false, filepath);
    if (IDialogConstants.OK_ID == dialog.open()) {
        if (StringUtil.isEqual(filepath, dialog.getFilePath())) {
            if (!CommonUITool.openConfirmBox(Messages.msgConfirmEditorExistFile)) {
                return;
            }
        }
        document.setEncoding(dialog.getEncoding());
        filepath = dialog.getFilePath();
        document.setFileName(filepath);
        document.save();
        dirty = false;
        updateTabName(filepath);
    }
}
Also used : SetFileEncodingDialog(com.cubrid.common.ui.query.dialog.SetFileEncodingDialog)

Example 5 with SetFileEncodingDialog

use of com.cubrid.common.ui.query.dialog.SetFileEncodingDialog in project cubrid-manager by CUBRID.

the class FavoriteQueryNavigatorView method addFile.

/**
	 * Add a favorite by external sql file(s).
	 */
private void addFile() {
    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    String charset = StringUtil.getDefaultCharset();
    SetFileEncodingDialog dialog = new SetFileEncodingDialog(shell, charset, true);
    if (dialog.open() != IDialogConstants.OK_ID) {
        return;
    }
    String memo = null;
    try {
        CubridDatabase cubridDatabase = getCurrentDatabase();
        memo = cubridDatabase.getDatabaseInfo().getDbName() + "@" + cubridDatabase.getServer().getServerInfo().getHostAddress();
    } catch (Exception e) {
        memo = "";
    }
    String filenameToSave = dialog.getFilePath();
    File file = new File(filenameToSave);
    String pathname = file.getPath();
    String filename = file.getName();
    int sp = pathname.indexOf(filename);
    if (sp != -1) {
        pathname = pathname.substring(0, sp);
    }
    lastDirectory = pathname;
    charset = dialog.getEncoding();
    addFavoriteByFileLink(lastDirectory, filename, memo, charset);
}
Also used : Shell(org.eclipse.swt.widgets.Shell) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) SetFileEncodingDialog(com.cubrid.common.ui.query.dialog.SetFileEncodingDialog) File(java.io.File) PartInitException(org.eclipse.ui.PartInitException) IOException(java.io.IOException) Point(org.eclipse.swt.graphics.Point)

Aggregations

SetFileEncodingDialog (com.cubrid.common.ui.query.dialog.SetFileEncodingDialog)6 IOException (java.io.IOException)3 PartInitException (org.eclipse.ui.PartInitException)3 QueryEditorPart (com.cubrid.common.ui.query.editor.QueryEditorPart)2 QueryUnit (com.cubrid.common.ui.query.editor.QueryUnit)2 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)2 File (java.io.File)2 IEditorPart (org.eclipse.ui.IEditorPart)2 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)2 SQLEditorComposite (com.cubrid.common.ui.query.control.SQLEditorComposite)1 Point (org.eclipse.swt.graphics.Point)1 Shell (org.eclipse.swt.widgets.Shell)1 IEditorInput (org.eclipse.ui.IEditorInput)1