Search in sources :

Example 1 with IEditorPart

use of org.eclipse.ui.IEditorPart in project gfm_viewer by satyagraha.

the class MarkdownEditorTrackerDefault method getActiveEditorMarkdownFile.

@Override
public IFile getActiveEditorMarkdownFile() {
    LOGGER.fine("");
    IEditorPart activeEditor = pageEditorTracker.getActiveEditor();
    if (activeEditor == null) {
        return null;
    }
    return getTrackableFile(activeEditor);
}
Also used : IEditorPart(org.eclipse.ui.IEditorPart)

Example 2 with IEditorPart

use of org.eclipse.ui.IEditorPart in project dbeaver by serge-rider.

the class NavigatorHandlerRefresh method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    //final IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
    final IWorkbenchPart workbenchPart = HandlerUtil.getActivePart(event);
    INavigatorModelView navigatorView;
    if (workbenchPart instanceof INavigatorModelView) {
        navigatorView = (INavigatorModelView) workbenchPart;
    } else {
        navigatorView = workbenchPart.getAdapter(INavigatorModelView.class);
    }
    if (navigatorView == null) {
        // Try to refresh as refreshable part
        if (workbenchPart instanceof IRefreshablePart) {
            ((IRefreshablePart) workbenchPart).refreshPart(this, true);
        }
        return null;
    }
    final List<DBNNode> refreshObjects = new ArrayList<>();
    final ISelection selection = HandlerUtil.getCurrentSelection(event);
    DBNNode rootNode = navigatorView.getRootNode();
    if (rootNode == null) {
        if (workbenchPart instanceof IEditorPart) {
            if (((IEditorPart) workbenchPart).getEditorInput() instanceof IDatabaseEditorInput) {
                rootNode = ((IDatabaseEditorInput) ((IEditorPart) workbenchPart).getEditorInput()).getNavigatorNode();
            }
        }
    }
    if (rootNode != null && rootNode.getParentNode() instanceof DBNDatabaseNode) {
        refreshObjects.add(rootNode);
    } else if (selection instanceof IStructuredSelection) {
        final IStructuredSelection structSelection = (IStructuredSelection) selection;
        for (Iterator<?> iter = structSelection.iterator(); iter.hasNext(); ) {
            Object object = iter.next();
            if (object instanceof DBNNode) {
                refreshObjects.add((DBNNode) object);
            }
        }
    }
    // Refresh objects
    if (!refreshObjects.isEmpty()) {
        refreshNavigator(refreshObjects);
    }
    return null;
}
Also used : DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) IEditorPart(org.eclipse.ui.IEditorPart) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IDatabaseEditorInput(org.jkiss.dbeaver.ui.editors.IDatabaseEditorInput) IRefreshablePart(org.jkiss.dbeaver.ui.IRefreshablePart) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ISelection(org.eclipse.jface.viewers.ISelection) INavigatorModelView(org.jkiss.dbeaver.ui.navigator.INavigatorModelView) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 3 with IEditorPart

use of org.eclipse.ui.IEditorPart 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;
}
Also used : SQLEditor(org.jkiss.dbeaver.ui.editors.sql.SQLEditor) IDataSourceContainerProvider(org.jkiss.dbeaver.model.IDataSourceContainerProvider) ProjectExplorerView(org.jkiss.dbeaver.ui.navigator.project.ProjectExplorerView) IFile(org.eclipse.core.resources.IFile) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) ProjectFileEditorInput(org.jkiss.dbeaver.ui.editors.ProjectFileEditorInput) IEditorPart(org.eclipse.ui.IEditorPart) DBPDataSource(org.jkiss.dbeaver.model.DBPDataSource) NotNull(org.jkiss.code.NotNull) InvocationTargetException(java.lang.reflect.InvocationTargetException) IDatabaseEditorInput(org.jkiss.dbeaver.ui.editors.IDatabaseEditorInput) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) NavigatorViewBase(org.jkiss.dbeaver.ui.navigator.database.NavigatorViewBase) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 4 with IEditorPart

use of org.eclipse.ui.IEditorPart in project dbeaver by serge-rider.

the class NavigatorHandlerObjectBase method getCommandTarget.

protected static CommandTarget getCommandTarget(IWorkbenchWindow workbenchWindow, DBNContainer container, Class<?> childType, boolean openEditor) throws DBException {
    final Object parentObject = container.getValueObject();
    DBSObject objectToSeek = null;
    if (parentObject instanceof DBSObject) {
        final DBEStructEditor parentStructEditor = EntityEditorsRegistry.getInstance().getObjectManager(parentObject.getClass(), DBEStructEditor.class);
        if (parentStructEditor != null && RuntimeUtils.isTypeSupported(childType, parentStructEditor.getChildTypes())) {
            objectToSeek = (DBSObject) parentObject;
        }
    }
    if (objectToSeek != null) {
        for (final IEditorReference editorRef : workbenchWindow.getActivePage().getEditorReferences()) {
            final IEditorPart editor = editorRef.getEditor(false);
            if (editor instanceof IDatabaseEditor) {
                final IDatabaseEditorInput editorInput = ((IDatabaseEditor) editor).getEditorInput();
                if (editorInput.getDatabaseObject() == objectToSeek) {
                    workbenchWindow.getActivePage().activate(editor);
                    switchEditorFolder(container, editor);
                    return new CommandTarget((IDatabaseEditor) editor);
                }
            }
        }
        if (openEditor && container instanceof DBNDatabaseNode) {
            final IDatabaseEditor editor = (IDatabaseEditor) NavigatorHandlerObjectOpen.openEntityEditor((DBNDatabaseNode) container, null, workbenchWindow);
            if (editor != null) {
                switchEditorFolder(container, editor);
                return new CommandTarget(editor);
            }
        }
    }
    if (container instanceof DBNDatabaseNode) {
        // No editor found - create new command context
        DBPDataSource dataSource = ((DBNDatabaseNode) container).getObject().getDataSource();
        if (dataSource != null) {
            return new CommandTarget(new SimpleCommandContext(dataSource.getDefaultContext(true), !openEditor));
        }
    }
    return new CommandTarget();
}
Also used : IDatabaseEditorInput(org.jkiss.dbeaver.ui.editors.IDatabaseEditorInput) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) IEditorReference(org.eclipse.ui.IEditorReference) SimpleCommandContext(org.jkiss.dbeaver.ui.SimpleCommandContext) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBEStructEditor(org.jkiss.dbeaver.model.edit.DBEStructEditor) IEditorPart(org.eclipse.ui.IEditorPart) DBPDataSource(org.jkiss.dbeaver.model.DBPDataSource) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) IDatabaseEditor(org.jkiss.dbeaver.ui.editors.IDatabaseEditor)

Example 5 with IEditorPart

use of org.eclipse.ui.IEditorPart in project dbeaver by serge-rider.

the class NavigatorHandlerObjectDelete method deleteNewObject.

private boolean deleteNewObject(IWorkbenchWindow workbenchWindow, DBNDatabaseNode node) throws DBException {
    for (final IEditorReference editorRef : workbenchWindow.getActivePage().getEditorReferences()) {
        final IEditorPart editor = editorRef.getEditor(false);
        if (editor instanceof IDatabaseEditor) {
            final IDatabaseEditorInput editorInput = ((IDatabaseEditor) editor).getEditorInput();
            if (editorInput.getDatabaseObject() == node.getObject()) {
                ConfirmResult confirmResult = confirmObjectDelete(workbenchWindow, node, false);
                if (confirmResult == ConfirmResult.NO) {
                    return true;
                }
                // Just close editor
                // It should dismiss new object and remove navigator node
                workbenchWindow.getActivePage().closeEditor(editor, false);
                return true;
            }
        }
    }
    return false;
}
Also used : IDatabaseEditorInput(org.jkiss.dbeaver.ui.editors.IDatabaseEditorInput) IEditorReference(org.eclipse.ui.IEditorReference) IEditorPart(org.eclipse.ui.IEditorPart) IDatabaseEditor(org.jkiss.dbeaver.ui.editors.IDatabaseEditor)

Aggregations

IEditorPart (org.eclipse.ui.IEditorPart)286 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)114 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)80 PartInitException (org.eclipse.ui.PartInitException)57 XLIFFEditorImplWithNatTable (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable)53 XLFHandler (net.heartsome.cat.ts.core.file.XLFHandler)45 IEditorReference (org.eclipse.ui.IEditorReference)43 QueryEditorPart (com.cubrid.common.ui.query.editor.QueryEditorPart)41 IFile (org.eclipse.core.resources.IFile)41 ArrayList (java.util.ArrayList)36 IViewPart (org.eclipse.ui.IViewPart)31 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)27 AbstractMultiPageTalendEditor (org.talend.designer.core.ui.AbstractMultiPageTalendEditor)26 IXliffEditor (net.heartsome.cat.ts.ui.editors.IXliffEditor)24 FileEditorInput (org.eclipse.ui.part.FileEditorInput)23 IEditorInput (org.eclipse.ui.IEditorInput)19 QueryUnit (com.cubrid.common.ui.query.editor.QueryUnit)18 List (java.util.List)17 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)17 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)16