use of org.jkiss.dbeaver.ui.editors.entity.EntityEditor in project dbeaver by dbeaver.
the class ItemListControl method fillCustomActions.
@Override
public void fillCustomActions(IContributionManager contributionManager) {
super.fillCustomActions(contributionManager);
final DBNNode rootNode = getRootNode();
if (rootNode instanceof DBNDatabaseFolder && ((DBNDatabaseFolder) rootNode).getItemsMeta() != null) {
contributionManager.add(new Action(UINavigatorMessages.obj_editor_properties_control_action_filter_setting, DBeaverIcons.getImageDescriptor(UIIcon.FILTER)) {
@Override
public void run() {
NavigatorHandlerFilterConfig.configureFilters(getShell(), rootNode);
}
});
}
addColumnConfigAction(contributionManager);
IWorkbenchSite workbenchSite = getWorkbenchSite();
if (rootNode instanceof DBNDatabaseFolder) {
contributionManager.add(new Separator());
contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, NavigatorCommands.CMD_OBJECT_OPEN));
{
if (ObjectPropertyTester.canCreateObject(rootNode, true)) {
contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, NavigatorCommands.CMD_OBJECT_CREATE));
} else if (ObjectPropertyTester.canCreateObject(rootNode, false)) {
contributionManager.add(new Action(null, Action.AS_DROP_DOWN_MENU) {
{
setActionDefinitionId(NavigatorCommands.CMD_OBJECT_CREATE);
}
@Override
public void run() {
super.run();
}
@Override
public IMenuCreator getMenuCreator() {
return new MenuCreator(control -> {
List<IContributionItem> items = NavigatorHandlerObjectCreateNew.fillCreateMenuItems((IWorkbenchPartSite) workbenchSite, rootNode);
MenuManager menuManager = new MenuManager();
for (IContributionItem cc : items) {
menuManager.add(cc);
}
return menuManager;
});
}
});
}
}
contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, NavigatorCommands.CMD_OBJECT_DELETE));
}
if (rootNode instanceof DBNDatabaseNode && rootNode.isPersisted()) {
boolean hasReorder = false;
List<Class<?>> childrenTypes = ((DBNDatabaseNode) rootNode).getChildrenTypes(null);
for (Class<?> chilType : childrenTypes) {
if (DBWorkbench.getPlatform().getEditorsRegistry().getObjectManager(chilType, DBEObjectReorderer.class) != null) {
hasReorder = true;
break;
}
}
if (hasReorder) {
contributionManager.add(new Separator());
contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, NavigatorCommands.CMD_OBJECT_MOVE_UP));
contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, NavigatorCommands.CMD_OBJECT_MOVE_DOWN));
}
}
if (rootNode instanceof DBNDatabaseNode) {
// Expand/collapse
final List<DBXTreeNode> inlineMetas = collectInlineMetas((DBNDatabaseNode) rootNode, ((DBNDatabaseNode) rootNode).getMeta());
if (!inlineMetas.isEmpty()) {
contributionManager.add(new Separator());
contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, IWorkbenchCommandConstants.NAVIGATE_COLLAPSE_ALL, null, UIIcon.TREE_COLLAPSE_ALL));
contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, IWorkbenchCommandConstants.NAVIGATE_EXPAND_ALL, null, UIIcon.TREE_EXPAND_ALL));
}
}
// Save/revert
if (workbenchSite instanceof MultiPageEditorSite) {
final MultiPageEditorPart editor = ((MultiPageEditorSite) workbenchSite).getMultiPageEditor();
if (editor instanceof EntityEditor) {
contributionManager.add(new Separator());
DatabaseEditorUtils.contributeStandardEditorActions(workbenchSite, contributionManager);
}
}
}
use of org.jkiss.dbeaver.ui.editors.entity.EntityEditor in project dbeaver by serge-rider.
the class ItemListControl method fillCustomActions.
@Override
protected void fillCustomActions(IContributionManager contributionManager) {
super.fillCustomActions(contributionManager);
final DBNNode rootNode = getRootNode();
if (rootNode instanceof DBNDatabaseFolder && ((DBNDatabaseFolder) rootNode).getItemsMeta() != null) {
contributionManager.add(new Action("Filter", DBeaverIcons.getImageDescriptor(UIIcon.FILTER)) {
@Override
public void run() {
NavigatorHandlerFilterConfig.configureFilters(getShell(), rootNode);
}
});
}
IWorkbenchSite workbenchSite = getWorkbenchSite();
if (workbenchSite != null) {
contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, IWorkbenchCommandConstants.FILE_REFRESH));
}
if (rootNode instanceof DBNDatabaseNode) {
contributionManager.add(new Separator());
contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, CoreCommands.CMD_OBJECT_OPEN));
contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, CoreCommands.CMD_OBJECT_CREATE));
contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, CoreCommands.CMD_OBJECT_DELETE));
}
if (rootNode instanceof DBNDatabaseNode && rootNode.isPersisted()) {
boolean hasReorder = false;
List<Class<?>> childrenTypes = ((DBNDatabaseNode) rootNode).getChildrenTypes(null);
for (Class<?> chilType : childrenTypes) {
if (EntityEditorsRegistry.getInstance().getObjectManager(chilType, DBEObjectReorderer.class) != null) {
hasReorder = true;
break;
}
}
if (hasReorder) {
contributionManager.add(new Separator());
contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, CoreCommands.CMD_OBJECT_MOVE_UP));
contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, CoreCommands.CMD_OBJECT_MOVE_DOWN));
}
}
if (workbenchSite instanceof MultiPageEditorSite) {
final MultiPageEditorPart editor = ((MultiPageEditorSite) workbenchSite).getMultiPageEditor();
if (editor instanceof EntityEditor) {
contributionManager.add(new Separator());
contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, IWorkbenchCommandConstants.FILE_SAVE, null, UIIcon.SAVE, null, true));
contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, IWorkbenchCommandConstants.FILE_REVERT, null, UIIcon.RESET, null, true));
}
}
}
use of org.jkiss.dbeaver.ui.editors.entity.EntityEditor in project dbeaver by dbeaver.
the class CompileHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final IWorkbenchPart activePart = HandlerUtil.getActiveEditor(event);
final List<OracleSourceObject> objects = getSelectedObjects(event);
if (!objects.isEmpty()) {
if (activePart instanceof EntityEditor) {
// Save editor before compile
// USe null monitor as entity editor has its own detached job for save
EntityEditor entityEditor = (EntityEditor) activePart;
if (entityEditor.isDirty()) {
NullProgressMonitor monitor = new NullProgressMonitor();
entityEditor.doSave(monitor);
if (monitor.isCanceled()) {
// Save failed - doesn't make sense to compile
return null;
}
}
}
final Shell activeShell = HandlerUtil.getActiveShell(event);
if (objects.size() == 1) {
final OracleSourceObject unit = objects.get(0);
DBCSourceHost sourceHost = null;
if (activePart != null) {
sourceHost = RuntimeUtils.getObjectAdapter(activePart, DBCSourceHost.class);
if (sourceHost == null) {
sourceHost = activePart.getAdapter(DBCSourceHost.class);
}
}
if (sourceHost != null && sourceHost.getSourceObject() != unit) {
sourceHost = null;
}
final DBCCompileLog compileLog = sourceHost == null ? new DBCCompileLogBase() : sourceHost.getCompileLog();
compileLog.clearLog();
Throwable error = null;
try {
DBeaverUI.runInProgressService(new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
compileUnit(monitor, compileLog, unit);
} catch (DBCException e) {
throw new InvocationTargetException(e);
}
}
});
if (compileLog.getError() != null) {
error = compileLog.getError();
}
} catch (InvocationTargetException e) {
error = e.getTargetException();
} catch (InterruptedException e) {
return null;
}
if (error != null) {
DBUserInterface.getInstance().showError("Unexpected compilation error", null, error);
} else if (!CommonUtils.isEmpty(compileLog.getErrorStack())) {
// Show compile errors
int line = -1, position = -1;
StringBuilder fullMessage = new StringBuilder();
for (DBCCompileError oce : compileLog.getErrorStack()) {
fullMessage.append(oce.toString()).append(GeneralUtils.getDefaultLineSeparator());
if (line < 0) {
line = oce.getLine();
position = oce.getPosition();
}
}
// If compiled object is currently open in editor - try to position on error line
if (sourceHost != null && sourceHost.getSourceObject() == unit && line > 0 && position > 0) {
sourceHost.positionSource(line, position);
activePart.getSite().getPage().activate(activePart);
}
String errorTitle = unit.getName() + " compilation failed";
if (sourceHost != null) {
sourceHost.setCompileInfo(errorTitle, true);
sourceHost.showCompileLog();
}
DBUserInterface.getInstance().showError(errorTitle, fullMessage.toString());
} else {
String message = unit.getName() + " compiled successfully";
if (sourceHost != null) {
sourceHost.setCompileInfo(message, true);
}
UIUtils.showMessageBox(activeShell, "Done", message, SWT.ICON_INFORMATION);
}
} else {
OracleCompilerDialog dialog = new OracleCompilerDialog(activeShell, objects);
dialog.open();
}
}
return null;
}
use of org.jkiss.dbeaver.ui.editors.entity.EntityEditor in project dbeaver by dbeaver.
the class PackageNavigateHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final OracleProcedurePackaged procedure = getSelectedProcedure(event);
if (procedure != null) {
OraclePackage procPackage = procedure.getParentObject();
IEditorPart entityEditor = NavigatorHandlerObjectOpen.openEntityEditor(procPackage);
if (entityEditor instanceof EntityEditor) {
((EntityEditor) entityEditor).switchFolder("source.definition");
SQLEditorBase sqlEditor = entityEditor.getAdapter(SQLEditorBase.class);
if (sqlEditor != null) {
new NavigateJob(procedure, sqlEditor).schedule();
}
}
}
return null;
}
use of org.jkiss.dbeaver.ui.editors.entity.EntityEditor in project dbeaver by serge-rider.
the class ContentEditor method doSave.
@Override
public void doSave(final IProgressMonitor monitor) {
if (!isDirty()) {
// Nothing to save
return;
}
// Execute save in UI thread
UIUtils.syncExec(() -> {
try {
// Check for dirty parts
final List<IEditorPart> dirtyParts = new ArrayList<>();
for (ContentPartInfo partInfo : contentParts) {
if (partInfo.activated && partInfo.editorPart.isDirty()) {
dirtyParts.add(partInfo.editorPart);
}
}
IEditorPart dirtyPart = null;
if (dirtyParts.isEmpty()) {
// No modified parts - no additional save required
} else if (dirtyParts.size() == 1) {
// Single part modified - save it
dirtyPart = dirtyParts.get(0);
} else {
// Multiple parts modified - need to choose one
dirtyPart = SelectContentPartDialog.selectContentPart(getSite().getShell(), dirtyParts);
}
if (dirtyPart != null) {
saveInProgress = true;
try {
dirtyPart.doSave(monitor);
} finally {
saveInProgress = false;
}
}
// Set dirty flag - if error will occur during content save
// then document remains dirty
ContentEditor.this.dirty = true;
ContentEditorInput editorInput = getEditorInput();
editorInput.updateContentFromFile(new DefaultProgressMonitor(monitor), editorInput.getValue());
editorInput.getValueController().updateValue(editorInput.getValue(), true);
// Activate owner editor and focus on cell corresponding to this content editor
IWorkbenchPartSite parentEditorSite = editorInput.getValueController().getValueSite();
IWorkbenchPart parentEditor;
if (parentEditorSite instanceof MultiPageEditorSite) {
parentEditor = ((MultiPageEditorSite) parentEditorSite).getMultiPageEditor();
if (parentEditor instanceof EntityEditor) {
((EntityEditor) parentEditor).setActiveEditor(IEntityDataEditor.class);
}
} else {
parentEditor = parentEditorSite.getPart();
}
parentEditorSite.getWorkbenchWindow().getActivePage().activate(parentEditor);
// Close editor
closeValueEditor();
} catch (Exception e) {
DBWorkbench.getPlatformUI().showError("Can't save content", "Can't save content to database", e);
}
});
}
Aggregations