use of org.jkiss.dbeaver.runtime.ui.UIServiceSQL in project dbeaver by serge-rider.
the class NavigatorHandlerObjectBase method showScript.
protected static boolean showScript(IWorkbenchWindow workbenchWindow, DBECommandContext commandContext, Map<String, Object> options, String dialogTitle) {
Collection<? extends DBECommand> commands = commandContext.getFinalCommands();
StringBuilder script = new StringBuilder();
try {
UIUtils.runInProgressService(monitor -> {
try {
for (DBECommand command : commands) {
DBEPersistAction[] persistActions = command.getPersistActions(monitor, commandContext.getExecutionContext(), options);
script.append(SQLUtils.generateScript(commandContext.getExecutionContext().getDataSource(), persistActions, false));
if (script.length() == 0) {
script.append(SQLUtils.generateComments(commandContext.getExecutionContext().getDataSource(), persistActions, false));
}
}
} catch (DBException e) {
throw new InvocationTargetException(e);
}
});
} catch (InvocationTargetException e) {
DBWorkbench.getPlatformUI().showError("Script generation error", "Error generating alter script", e.getTargetException());
} catch (InterruptedException e) {
return false;
}
if (script.length() > 0) {
UIServiceSQL serviceSQL = DBWorkbench.getService(UIServiceSQL.class);
if (serviceSQL != null) {
return serviceSQL.openSQLViewer(commandContext.getExecutionContext(), dialogTitle, UIIcon.SQL_PREVIEW, script.toString(), true, false) == IDialogConstants.PROCEED_ID;
}
} else {
return UIUtils.confirmAction(workbenchWindow.getShell(), dialogTitle, "No SQL script available.\nAre you sure you want to proceed?");
}
return false;
}
use of org.jkiss.dbeaver.runtime.ui.UIServiceSQL in project dbeaver by serge-rider.
the class NavigatorHandlerObjectOpen method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
if (UIUtils.isInDialog()) {
// If some modal dialog is open then we don't do this
return null;
}
final ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection instanceof IStructuredSelection) {
final IStructuredSelection structSelection = (IStructuredSelection) selection;
if (structSelection.size() > MAX_OBJECT_SIZE_NO_CONFIRM) {
if (!UIUtils.confirmAction(HandlerUtil.getActiveShell(event), "Open " + structSelection.size() + " editors", "You are about to open " + structSelection.size() + " editors. Are you sure?")) {
return null;
}
}
for (Iterator<?> iter = structSelection.iterator(); iter.hasNext(); ) {
Object element = iter.next();
DBNNode node = null;
if (element instanceof IResource) {
UIServiceSQL serviceSQL = DBWorkbench.getService(UIServiceSQL.class);
if (serviceSQL != null) {
serviceSQL.openResource((IResource) element);
}
continue;
} else if (element instanceof DBNNode) {
node = (DBNNode) element;
} else {
DBSObject object = RuntimeUtils.getObjectAdapter(element, DBSObject.class);
if (object != null) {
node = getNodeByObject(object);
}
}
if (node != null) {
NavigatorUtils.openNavigatorNode(node, HandlerUtil.getActiveWorkbenchWindow(event), event.getParameters());
}
}
}
return null;
}
use of org.jkiss.dbeaver.runtime.ui.UIServiceSQL in project dbeaver by dbeaver.
the class ResultSetFilterPanel method createObjectPanel.
@NotNull
private Control createObjectPanel(Shell popup) throws PartInitException {
Composite panel = new Composite(popup, SWT.NONE);
GridLayout gl = new GridLayout(2, false);
// gl.marginWidth = 0;
gl.marginHeight = 0;
// gl.horizontalSpacing = 0;
panel.setLayout(gl);
Label iconLabel = new Label(panel, SWT.NONE);
DBPImage activeObjectImage = getActiveObjectImage();
if (activeObjectImage != null) {
iconLabel.setImage(DBeaverIcons.getImage(activeObjectImage));
}
iconLabel.setToolTipText(ResultSetMessages.sql_editor_resultset_filter_panel_label);
iconLabel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
iconLabel.setCursor(getDisplay().getSystemCursor(SWT.CURSOR_HAND));
iconLabel.addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent e) {
openEditorForActiveQuery();
}
});
Composite editorPH = new Composite(panel, SWT.NONE);
editorPH.setLayoutData(new GridData(GridData.FILL_BOTH));
editorPH.setLayout(new FillLayout());
try {
UIServiceSQL serviceSQL = DBWorkbench.getService(UIServiceSQL.class);
if (serviceSQL != null) {
Object sqlPanel = serviceSQL.createSQLPanel(viewer.getSite(), editorPH, viewer, ResultSetViewer.DEFAULT_QUERY_TEXT, false, viewer.getActiveQueryText());
if (sqlPanel instanceof TextViewer) {
StyledText textWidget = ((TextViewer) sqlPanel).getTextWidget();
// textWidget.setAlwaysShowScrollBars(false);
panel.setBackground(textWidget.getBackground());
return textWidget;
}
}
return null;
} catch (DBException e) {
throw new PartInitException("Error creating SQL panel", e);
}
}
use of org.jkiss.dbeaver.runtime.ui.UIServiceSQL in project dbeaver by dbeaver.
the class NavigatorHandlerObjectBase method showScript.
protected static boolean showScript(IWorkbenchWindow workbenchWindow, DBECommandContext commandContext, Map<String, Object> options, String dialogTitle) {
Collection<? extends DBECommand> commands = commandContext.getFinalCommands();
StringBuilder script = new StringBuilder();
try {
UIUtils.runInProgressService(monitor -> {
try {
for (DBECommand command : commands) {
DBEPersistAction[] persistActions = command.getPersistActions(monitor, commandContext.getExecutionContext(), options);
script.append(SQLUtils.generateScript(commandContext.getExecutionContext().getDataSource(), persistActions, false));
if (script.length() == 0) {
script.append(SQLUtils.generateComments(commandContext.getExecutionContext().getDataSource(), persistActions, false));
}
}
} catch (DBException e) {
throw new InvocationTargetException(e);
}
});
} catch (InvocationTargetException e) {
DBWorkbench.getPlatformUI().showError("Script generation error", "Error generating alter script", e.getTargetException());
} catch (InterruptedException e) {
return false;
}
if (script.length() > 0) {
UIServiceSQL serviceSQL = DBWorkbench.getService(UIServiceSQL.class);
if (serviceSQL != null) {
return serviceSQL.openSQLViewer(commandContext.getExecutionContext(), dialogTitle, UIIcon.SQL_PREVIEW, script.toString(), true, false) == IDialogConstants.PROCEED_ID;
}
} else {
return UIUtils.confirmAction(workbenchWindow.getShell(), dialogTitle, "No SQL script available.\nAre you sure you want to proceed?");
}
return false;
}
use of org.jkiss.dbeaver.runtime.ui.UIServiceSQL in project dbeaver by dbeaver.
the class NavigatorHandlerObjectOpen method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
if (UIUtils.isInDialog()) {
// If some modal dialog is open then we don't do this
return null;
}
final ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection instanceof IStructuredSelection) {
final IStructuredSelection structSelection = (IStructuredSelection) selection;
if (structSelection.size() > MAX_OBJECT_SIZE_NO_CONFIRM) {
if (!UIUtils.confirmAction(HandlerUtil.getActiveShell(event), "Open " + structSelection.size() + " editors", "You are about to open " + structSelection.size() + " editors. Are you sure?")) {
return null;
}
}
for (Iterator<?> iter = structSelection.iterator(); iter.hasNext(); ) {
Object element = iter.next();
DBNNode node = null;
if (element instanceof IResource) {
UIServiceSQL serviceSQL = DBWorkbench.getService(UIServiceSQL.class);
if (serviceSQL != null) {
serviceSQL.openResource((IResource) element);
}
continue;
} else if (element instanceof DBNNode) {
node = (DBNNode) element;
} else {
DBSObject object = RuntimeUtils.getObjectAdapter(element, DBSObject.class);
if (object != null) {
node = getNodeByObject(object);
}
}
if (node != null) {
NavigatorUtils.openNavigatorNode(node, HandlerUtil.getActiveWorkbenchWindow(event), event.getParameters());
}
}
}
return null;
}
Aggregations