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());
}
}
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());
}
}
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;
}
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);
}
}
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);
}
Aggregations