Search in sources :

Example 81 with IWorkbenchPage

use of org.eclipse.ui.IWorkbenchPage in project cubrid-manager by CUBRID.

the class LayoutUtil method checkAllQueryEditor.

/**
	 * 
	 * When database logout or stop,check query editor whether some transaction
	 * are not commit
	 * 
	 * @param databaseNode the CubridDatabase object
	 * @return <code>true</code> if transaction is commited;<code>false</code>
	 *         otherwise
	 */
public static boolean checkAllQueryEditor(CubridDatabase databaseNode) {
    IWorkbenchPage page = getActivePage();
    if (page == null) {
        return true;
    }
    boolean isContinue = true;
    IEditorReference[] editorRefArr = page.getEditorReferences();
    if (editorRefArr == null || editorRefArr.length == 0) {
        return true;
    }
    for (IEditorReference editorRef : editorRefArr) {
        String editorId = editorRef.getId();
        if (editorId != null && editorId.equals(QueryEditorPart.ID)) {
            QueryEditorPart queryEditor = (QueryEditorPart) editorRef.getEditor(false);
            CubridDatabase db = queryEditor.getSelectedDatabase();
            if (db != null && db.getId().equals(databaseNode.getId())) {
                isContinue = queryEditor.resetJDBCConnection();
            }
        }
    }
    return isContinue;
}
Also used : QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) IEditorReference(org.eclipse.ui.IEditorReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 82 with IWorkbenchPage

use of org.eclipse.ui.IWorkbenchPage in project cubrid-manager by CUBRID.

the class CommonUITool method openQueryEditor.

/**
	 * Open new query editor.
	 *
	 * @param database of query editor.
	 * @param careDBRunType whether care the database running type that only whether donot open the query editor if the running type is not CS.
	 * @throws PartInitException when open editor error.
	 */
public static QueryEditorPart openQueryEditor(CubridDatabase database, boolean careDBRunType) throws PartInitException {
    IWorkbenchPage page = LayoutUtil.getActivePage();
    if (page == null) {
        return null;
    }
    if (database != null && careDBRunType && database.getRunningType() != DbRunningType.CS) {
        return null;
    }
    QueryUnit input = new QueryUnit();
    input.setDatabase(database);
    IEditorPart editor = page.openEditor(input, QueryEditorPart.ID);
    if (editor != null) {
        ((QueryEditorPart) editor).connect(database);
    }
    return (QueryEditorPart) editor;
}
Also used : QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) QueryUnit(com.cubrid.common.ui.query.editor.QueryUnit) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart)

Example 83 with IWorkbenchPage

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

the class DIManager method getInjector.

public Injector getInjector(Component.Scope scope) {
    if (scope == null) {
        throw new IllegalArgumentException("null scope");
    }
    switch(scope) {
        case PLUGIN:
            return pluginInjector;
        case PAGE:
            IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
            if (workbenchWindow == null) {
                throw new IllegalStateException("no active workbench window");
            }
            IWorkbenchPage workbenchPage = workbenchWindow.getActivePage();
            if (workbenchPage == null) {
                throw new IllegalStateException("no active workbench page");
            }
            Injector pageInjector = pageInjectorMap.get(workbenchPage);
            if (pageInjector == null) {
                throw new IllegalStateException("unable to locate pageInjector for page: " + workbenchPage);
            }
            return pageInjector;
        default:
            throw new IllegalArgumentException("unexpected scope: " + scope);
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage)

Example 84 with IWorkbenchPage

use of org.eclipse.ui.IWorkbenchPage 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 85 with IWorkbenchPage

use of org.eclipse.ui.IWorkbenchPage in project cubrid-manager by CUBRID.

the class MonitorStatisticEditor method openDetailView.

public void openDetailView(StatisticChartItem statisticChartItem, List<StatisticData> statisticDataList) {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return;
    }
    IWorkbenchPage page = window.getActivePage();
    if (page == null) {
        return;
    }
    StringBuilder secondaryIdSb = new StringBuilder(MonitorStatisticDetailViewPart.ID);
    secondaryIdSb.append("@").append(this.pageNode.getId());
    IViewReference viewReference = page.findViewReference(MonitorStatisticDetailViewPart.ID, secondaryIdSb.toString());
    if (viewReference == null) {
        try {
            MonitorStatisticDetailViewPart viewPart = (MonitorStatisticDetailViewPart) page.showView(MonitorStatisticDetailViewPart.ID, secondaryIdSb.toString(), IWorkbenchPage.VIEW_ACTIVATE);
            viewPart.setMultiHost(isMultiHost);
            viewPart.init(this.pageNode, this);
            viewPart.setStatisticChartItem(statisticChartItem);
            viewPart.setStatisticDataList(statisticDataList);
            viewPart.reloadChart();
        } catch (PartInitException ex) {
            viewReference = null;
        }
    } else {
        MonitorStatisticDetailViewPart viewPart = (MonitorStatisticDetailViewPart) viewReference.getView(false);
        window.getActivePage().bringToTop(viewPart);
        viewPart.setStatisticChartItem(statisticChartItem);
        viewPart.setStatisticDataList(statisticDataList);
        viewPart.reloadChart();
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IViewReference(org.eclipse.ui.IViewReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException)

Aggregations

IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)294 IEditorPart (org.eclipse.ui.IEditorPart)126 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)102 PartInitException (org.eclipse.ui.PartInitException)96 IFile (org.eclipse.core.resources.IFile)63 IViewPart (org.eclipse.ui.IViewPart)58 IEditorReference (org.eclipse.ui.IEditorReference)40 IWorkbench (org.eclipse.ui.IWorkbench)32 CoreException (org.eclipse.core.runtime.CoreException)31 ArrayList (java.util.ArrayList)30 IViewReference (org.eclipse.ui.IViewReference)29 IEditorInput (org.eclipse.ui.IEditorInput)28 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)27 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)22 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)18 Path (org.eclipse.core.runtime.Path)18 FileEditorInput (org.eclipse.ui.part.FileEditorInput)17 IOException (java.io.IOException)16 IProject (org.eclipse.core.resources.IProject)16 ISelection (org.eclipse.jface.viewers.ISelection)16