use of org.jkiss.dbeaver.ui.editors.sql.SQLEditor in project dbeaver by serge-rider.
the class NavigatorHandlerLinkEditor method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final IWorkbenchPage activePage = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
final IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
if (activeEditor == null) {
return null;
}
NavigatorViewBase navigatorView = NavigatorUtils.getActiveNavigatorView(event);
if (navigatorView == null) {
return null;
}
if (navigatorView instanceof ProjectExplorerView) {
if (activeEditor instanceof SQLEditor) {
IFile file = EditorUtils.getFileFromInput(activeEditor.getEditorInput());
if (file != null) {
showResourceInNavigator(navigatorView, file);
}
} else if (activeEditor.getEditorInput() instanceof ProjectFileEditorInput) {
IFile editorFile = ((ProjectFileEditorInput) activeEditor.getEditorInput()).getFile();
showResourceInNavigator(navigatorView, editorFile);
}
} else if (activeEditor.getEditorInput() instanceof IDatabaseEditorInput) {
IDatabaseEditorInput editorInput = (IDatabaseEditorInput) activeEditor.getEditorInput();
DBNNode dbnNode = editorInput.getNavigatorNode();
if (dbnNode != null) {
navigatorView.showNode(dbnNode);
}
} else if (activeEditor instanceof IDataSourceContainerProvider) {
DBPDataSourceContainer dsContainer = ((IDataSourceContainerProvider) activeEditor).getDataSourceContainer();
@NotNull final DBSObject activeObject;
if (dsContainer != null) {
DBPDataSource dataSource = dsContainer.getDataSource();
if (dataSource != null) {
activeObject = DBUtils.getDefaultOrActiveObject(dataSource);
} else {
activeObject = dsContainer;
}
final NavigatorViewBase view = navigatorView;
DBeaverUI.runInUI(activePage.getWorkbenchWindow(), new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
DBSObject showObject = activeObject;
if (showObject instanceof DBPDataSource) {
showObject = ((DBPDataSource) showObject).getContainer();
}
DBNDatabaseNode objectNode = view.getModel().getNodeByObject(monitor, showObject, true);
if (objectNode != null) {
view.showNode(objectNode);
}
}
});
}
}
activePage.activate(navigatorView);
return null;
}
use of org.jkiss.dbeaver.ui.editors.sql.SQLEditor in project dbeaver by serge-rider.
the class OpenObjectConsoleHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
DBPDataSourceContainer ds = null;
List<DBSObject> selectedObjects = NavigatorUtils.getSelectedObjects(HandlerUtil.getCurrentSelection(event));
List<DBSEntity> entities = new ArrayList<>();
for (DBSObject object : selectedObjects) {
if (object instanceof DBSEntity) {
entities.add((DBSEntity) object);
ds = object.getDataSource().getContainer();
}
}
DBRRunnableWithResult<String> generator = GenerateSQLContributor.SELECT_GENERATOR(entities, true);
DBeaverUI.runInUI(workbenchWindow, generator);
String sql = generator.getResult();
SQLEditor editor = OpenHandler.openSQLConsole(workbenchWindow, ds, "Query", sql);
if (editor != null) {
editor.processSQL(false, false);
}
return null;
}
use of org.jkiss.dbeaver.ui.editors.sql.SQLEditor in project dbeaver by serge-rider.
the class RenameHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
SQLEditor editor = RuntimeUtils.getObjectAdapter(HandlerUtil.getActivePart(event), SQLEditor.class);
if (editor == null) {
log.error("No active SQL editor");
return null;
}
Shell shell = HandlerUtil.getActiveShell(event);
IFile file = EditorUtils.getFileFromInput(editor.getEditorInput());
if (file == null) {
UIUtils.showErrorDialog(shell, "Rename", "Can't rename - no source file");
return null;
}
String newName = EnterNameDialog.chooseName(shell, "Rename SQL script [" + file.getName() + "]", file.getName());
if (newName == null) {
return null;
}
if (newName.indexOf('.') == -1) {
int divPos = file.getName().lastIndexOf('.');
if (divPos != -1) {
newName += file.getName().substring(divPos);
}
}
if (!newName.equals(file.getName())) {
NullProgressMonitor monitor = new NullProgressMonitor();
editor.doSave(monitor);
try {
file.move(file.getParent().getFullPath().append(newName), true, monitor);
} catch (CoreException e) {
UIUtils.showErrorDialog(shell, "Rename", "Error renaming file '" + file.getName() + "'", e);
}
}
//file.set
return null;
}
use of org.jkiss.dbeaver.ui.editors.sql.SQLEditor in project dbeaver by serge-rider.
the class SwitchPanelHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
SQLEditor editor = RuntimeUtils.getObjectAdapter(HandlerUtil.getActiveEditor(event), SQLEditor.class);
if (editor == null) {
return null;
}
String actionId = event.getCommand().getId();
switch(actionId) {
case CoreCommands.CMD_SQL_SWITCH_PANEL:
editor.toggleActivePanel();
break;
case CoreCommands.CMD_SQL_SHOW_OUTPUT:
editor.showOutputPanel();
break;
case CoreCommands.CMD_SQL_SHOW_LOG:
editor.showExecutionLogPanel();
break;
}
return null;
}
use of org.jkiss.dbeaver.ui.editors.sql.SQLEditor in project dbeaver by dbeaver.
the class CopySourceCodeHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
SQLEditor editor = RuntimeUtils.getObjectAdapter(HandlerUtil.getActiveEditor(event), SQLEditor.class);
if (editor == null) {
return null;
}
ISelection selection = editor.getSelectionProvider().getSelection();
if (selection.isEmpty() || !(selection instanceof TextSelection)) {
return null;
}
TargetFormatDialog dialog = new TargetFormatDialog(editor, (TextSelection) selection);
if (dialog.open() != IDialogConstants.OK_ID) {
return null;
}
UIUtils.setClipboardContents(Display.getCurrent(), TextTransfer.getInstance(), dialog.getConvertedText());
return null;
}
Aggregations