Search in sources :

Example 71 with PartInitException

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

the class ServiceDashboardAction method run.

/**
	 * @see org.eclipse.jface.action.Action#run() Override the run method in
	 *      order to complete showing brokers status server to a broker
	 */
public void run() {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (null == window) {
        return;
    }
    /*Check it open same editor*/
    ServiceDashboardEditor editorPart = findOpenedEditorPart();
    if (editorPart == null) {
        ServiceDashboardEditorInput editorInput = new ServiceDashboardEditorInput();
        editorInput.setName("");
        editorInput.setToolTipText(Messages.serviceDashboardPartToolTip);
        try {
            editorPart = (ServiceDashboardEditor) window.getActivePage().openEditor(editorInput, ServiceDashboardEditor.ID);
            editorPart.loadAllData();
        } catch (PartInitException ex) {
            LOGGER.error(ex.getMessage());
        }
    } else {
        window.getActivePage().activate(editorPart);
        editorPart.loadAllData();
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) PartInitException(org.eclipse.ui.PartInitException) ServiceDashboardEditorInput(com.cubrid.cubridmanager.ui.service.editor.ServiceDashboardEditorInput) ServiceDashboardEditor(com.cubrid.cubridmanager.ui.service.editor.ServiceDashboardEditor)

Example 72 with PartInitException

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

the class CubridWorkbenchContrItem method closeAllEditorAndViewInServer.

/**
	 * Close all editor and view part related with this CUBRID Manager server
	 * node,not include query editor
	 *
	 * @param serverNode the ICubridNode object
	 * @param isSaved the boolean value,if can be saved
	 * @return boolean whether all editors are closed
	 */
public static boolean closeAllEditorAndViewInServer(ICubridNode serverNode, boolean isSaved) {
    boolean isCloseAll = true;
    IWorkbenchPage page = LayoutUtil.getActivePage();
    if (page == null) {
        return isCloseAll;
    }
    IEditorReference[] editorRefArr = page.getEditorReferences();
    if (editorRefArr != null && editorRefArr.length > 0) {
        for (IEditorReference editorRef : editorRefArr) {
            try {
                IEditorInput editorInput = editorRef.getEditorInput();
                if (!(editorInput instanceof ICubridNode)) {
                    continue;
                }
                ICubridNode node = ((ICubridNode) editorInput).getServer();
                if (node != null && node.getId().equals(serverNode.getId())) {
                    boolean isClosed = page.closeEditor(editorRef.getEditor(false), isSaved);
                    if (!isClosed) {
                        isCloseAll = false;
                    }
                }
            } catch (PartInitException e) {
                LOGGER.error("", e);
            }
        }
    }
    IViewReference[] viewRefArr = page.getViewReferences();
    if (viewRefArr != null && viewRefArr.length > 0) {
        for (IViewReference viewRef : viewRefArr) {
            IViewPart viewPart = viewRef.getView(false);
            if (!(viewPart instanceof CubridViewPart)) {
                continue;
            }
            CubridViewPart cubridViewPart = (CubridViewPart) viewPart;
            ICubridNode cubridNode = cubridViewPart.getCubridNode();
            if (cubridNode == null) {
                continue;
            }
            ICubridNode cubridServerNode = cubridNode.getServer();
            if (cubridServerNode.getId().equals(serverNode.getId())) {
                page.hideView(viewPart);
            }
        }
    }
    return isCloseAll;
}
Also used : IViewPart(org.eclipse.ui.IViewPart) IEditorReference(org.eclipse.ui.IEditorReference) CubridViewPart(com.cubrid.common.ui.spi.part.CubridViewPart) IViewReference(org.eclipse.ui.IViewReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) PartInitException(org.eclipse.ui.PartInitException) IEditorInput(org.eclipse.ui.IEditorInput)

Example 73 with PartInitException

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

the class CubridWorkbenchContrItem method openEditorOrView.

/**
	 * Open and reopen the editor or view part of this CUBRID node
	 *
	 * @param cubridNode the ICubridNode object
	 */
public void openEditorOrView(ICubridNode cubridNode) {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return;
    }
    if (cubridNode instanceof ISchemaNode) {
        ISchemaNode schemaNode = (ISchemaNode) cubridNode;
        if (schemaNode.getDatabase() != null && !schemaNode.getDatabase().isLogined()) {
            return;
        }
    }
    //close the editor part that has been open
    String editorId = cubridNode.getEditorId();
    String viewId = cubridNode.getViewId();
    IWorkbenchPart workbenchPart = null;
    if (editorId != null && editorId.trim().length() > 0) {
        IEditorPart editorPart = LayoutUtil.getEditorPart(cubridNode, editorId);
        if (editorPart != null) {
            window.getActivePage().closeEditor(editorPart, false);
        }
    } else if (viewId != null && viewId.trim().length() > 0) {
        IViewPart viewPart = LayoutUtil.getViewPart(cubridNode, viewId);
        if (viewPart != null) {
            // monitor view part do not need to close and then open
            if (MONITOR_VIEWID_LST.contains(viewId)) {
                workbenchPart = viewPart;
                window.getActivePage().bringToTop(viewPart);
            } else {
                window.getActivePage().hideView(viewPart);
            }
        }
    }
    String nodeType = cubridNode.getType();
    ISelectionAction logViewAction = null;
    if (NodeType.contains(nodeType, new String[] { CubridNodeType.BROKER_SQL_LOG, CubridNodeType.LOGS_BROKER_ACCESS_LOG, CubridNodeType.LOGS_BROKER_ERROR_LOG, CubridNodeType.LOGS_BROKER_ADMIN_LOG, CubridNodeType.LOGS_SERVER_DATABASE_LOG })) {
        logViewAction = (ISelectionAction) ActionManager.getInstance().getAction(LogViewAction.ID);
        ((LogViewAction) logViewAction).setCubridNode(cubridNode);
    } else if (NodeType.contains(nodeType, new String[] { CubridNodeType.LOGS_MANAGER_ACCESS_LOG, CubridNodeType.LOGS_MANAGER_ERROR_LOG })) {
        logViewAction = (ISelectionAction) ActionManager.getInstance().getAction(ManagerLogViewAction.ID);
        ((ManagerLogViewAction) logViewAction).setCubridNode(cubridNode);
    }
    if (logViewAction != null && logViewAction.isSupported(cubridNode)) {
        logViewAction.run();
        return;
    }
    if (!StringUtil.isEmpty(editorId)) {
        try {
            if (cubridNode instanceof ISchemaNode) {
                CubridDatabase database = ((ISchemaNode) cubridNode).getDatabase();
                // Judge database is started and open DatabaseDashboardEditor
                if (StringUtil.isEqual(editorId, DatabaseDashboardEditor.ID)) {
                    if (!DbRunningType.CS.equals(database.getRunningType())) {
                        return;
                    }
                }
                // if open the table schema editor,firstly load the schema
                if (StringUtil.isEqual(editorId, SchemaInfoEditorPart.ID)) {
                    SchemaInfo newSchema = database.getDatabaseInfo().getSchemaInfo(cubridNode.getName());
                    if (newSchema == null) {
                        CommonUITool.openErrorBox(database.getDatabaseInfo().getErrorMessage());
                        return;
                    }
                }
            }
            workbenchPart = window.getActivePage().openEditor(cubridNode, editorId, true, IWorkbenchPage.MATCH_ID & IWorkbenchPage.MATCH_INPUT);
        } catch (PartInitException e) {
            LOGGER.error("", e);
        }
    } else if (viewId != null && viewId.trim().length() > 0) {
        try {
            if (MONITOR_VIEWID_LST.contains(viewId)) {
                if (workbenchPart == null) {
                    String secondId = LayoutUtil.getViewSecondId(cubridNode);
                    workbenchPart = window.getActivePage().showView(viewId, secondId, IWorkbenchPage.VIEW_CREATE | IWorkbenchPage.VIEW_ACTIVATE | IWorkbenchPage.VIEW_VISIBLE);
                    window.getActivePage().bringToTop(workbenchPart);
                }
            } else {
                workbenchPart = window.getActivePage().showView(viewId);
            }
        } catch (Exception e) {
            LOGGER.error("", e);
        }
    }
    if (workbenchPart != null) {
        LayoutManager.getInstance().getTitleLineContrItem().changeTitleForViewOrEditPart(cubridNode, workbenchPart);
        LayoutManager.getInstance().getStatusLineContrItem().changeStuatusLineForViewOrEditPart(cubridNode, workbenchPart);
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ManagerLogViewAction(com.cubrid.cubridmanager.ui.logs.action.ManagerLogViewAction) LogViewAction(com.cubrid.cubridmanager.ui.logs.action.LogViewAction) IViewPart(org.eclipse.ui.IViewPart) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) ISelectionAction(com.cubrid.common.ui.spi.action.ISelectionAction) PartInitException(org.eclipse.ui.PartInitException) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 74 with PartInitException

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

the class EditQueryConnAction method run.

/**
	 * Open the query connection
	 */
public void run() {
    // TODO remove later
    CQBGroupNodePersistManager.getInstance().fix();
    Object[] obj = this.getSelectedObj();
    if (!isSupported(obj[0])) {
        setEnabled(false);
        return;
    }
    ISelectionProvider provider = getSelectionProvider();
    if (!(provider instanceof TreeViewer)) {
        return;
    }
    CubridDatabase[] cubridDatabases = handleSelectionObj(obj);
    if (cubridDatabases.length == 0) {
        return;
    }
    ConnectionInfo oldInfo = null;
    ConnectionInfo newInfo = null;
    if (cubridDatabases.length > 1) {
        MultiQueryConnEditDialog dialog = new MultiQueryConnEditDialog(getShell(), Arrays.asList(cubridDatabases));
        if (dialog.open() != MultiQueryConnEditDialog.SAVE_ID) {
            return;
        }
        List<CubridDatabase> newDBList = dialog.getNewDBList();
        for (int i = 0; i < cubridDatabases.length; i++) {
            CubridDatabase saveCubridDatabase = cubridDatabases[i];
            CubridDatabase newCubridDatabase = newDBList.get(i);
            oldInfo = CQBDBNodePersistManager.getInstance().getConnectionInfo(saveCubridDatabase);
            newInfo = CQBDBNodePersistManager.getInstance().getConnectionInfo(newCubridDatabase);
            saveCubridDatabase.setLabel(newCubridDatabase.getLabel());
            saveCubridDatabase.getDatabaseInfo().setDbName(newCubridDatabase.getDatabaseInfo().getDbName());
            saveCubridDatabase.getDatabaseInfo().getAuthLoginedDbUserInfo().setName(newCubridDatabase.getDatabaseInfo().getAuthLoginedDbUserInfo().getName());
            saveCubridDatabase.setAutoSavePassword(newCubridDatabase.isAutoSavePassword());
            if (saveCubridDatabase.isAutoSavePassword()) {
                saveCubridDatabase.getDatabaseInfo().getAuthLoginedDbUserInfo().setNoEncryptPassword(newCubridDatabase.getDatabaseInfo().getAuthLoginedDbUserInfo().getNoEncryptPassword());
            } else {
                saveCubridDatabase.getDatabaseInfo().getAuthLoginedDbUserInfo().setNoEncryptPassword(null);
            }
            saveCubridDatabase.getDatabaseInfo().setBrokerIP(newCubridDatabase.getDatabaseInfo().getBrokerIP());
            saveCubridDatabase.getDatabaseInfo().setBrokerPort(newCubridDatabase.getDatabaseInfo().getBrokerPort());
            DatabaseEditorConfig editorConfig = QueryOptions.getEditorConfig(saveCubridDatabase, false);
            if (editorConfig == null) {
                editorConfig = new DatabaseEditorConfig();
                editorConfig.setBackGround(EditorConstance.getDefaultBackground());
            } else if (editorConfig.getBackGround() == null) {
                editorConfig.setBackGround(EditorConstance.getDefaultBackground());
            }
            if (newCubridDatabase.getData(MultiQueryConnEditDialog.COMMENTKEY) != null) {
                editorConfig.setDatabaseComment((String) newCubridDatabase.getData(MultiQueryConnEditDialog.COMMENTKEY));
            }
            QueryOptions.putEditorConfig(saveCubridDatabase, editorConfig, false);
            CQBDBNodePersistManager.getInstance().fireModifyDatabase(oldInfo, newInfo);
            boolean isContinue = CQBConnectionUtils.processConnectionLogout(saveCubridDatabase);
            if (isContinue) {
                TreeViewer viewer = (TreeViewer) provider;
                viewer.refresh(saveCubridDatabase, true);
                CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(saveCubridDatabase, CubridNodeChangedEventType.DATABASE_LOGOUT));
            }
        }
        LayoutManager.getInstance().fireSelectionChanged(getSelection());
        ActionManager.getInstance().fireSelectionChanged(getSelection());
        CQBGroupNodePersistManager.getInstance().saveAllGroupNode();
        CQBDBNodePersistManager.getInstance().saveDatabases();
        return;
    }
    CubridDatabase database = (CubridDatabase) cubridDatabases[0];
    if (database.getParent() == null) {
        CQBGroupNodePersistManager.getInstance();
    }
    String preName = (database == null || database.getServer() == null) ? "" : database.getServer().getName();
    ServerInfo preServerInfo = (database == null || database.getServer() == null) ? null : database.getServer().getServerInfo();
    oldInfo = CQBDBNodePersistManager.getInstance().getConnectionInfo(database);
    QueryConnDialog dialog = new QueryConnDialog(getShell(), database, false);
    int returnCode = dialog.open();
    if (returnCode == QueryConnDialog.CONNECT_ID) {
        database.removeAllChild();
        newInfo = CQBDBNodePersistManager.getInstance().getConnectionInfo(database);
        TreeViewer treeViewer = (TreeViewer) provider;
        CQBGroupNodePersistManager.getInstance().saveAllGroupNode();
        CQBDBNodePersistManager.getInstance().saveDatabases();
        if (!preName.equals(database.getServer().getName())) {
            QueryOptions.removePref(preServerInfo);
        }
        treeViewer.refresh(database, true);
        treeViewer.expandToLevel(database, 1);
        ActionManager.getInstance().fireSelectionChanged(getSelection());
        LayoutManager.getInstance().fireSelectionChanged(getSelection());
        if (dialog.isFireLogoutEvent()) {
            CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(database, CubridNodeChangedEventType.DATABASE_LOGOUT));
        }
        CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(database, CubridNodeChangedEventType.DATABASE_LOGIN));
        CQBDBNodePersistManager.getInstance().fireModifyDatabase(oldInfo, newInfo);
        try {
            CommonUITool.openQueryEditor(database, true);
        } catch (PartInitException e) {
            LOGGER.error(e.getMessage(), e);
        }
    } else if (returnCode == QueryConnDialog.SAVE_ID) {
        TreeViewer treeViewer = (TreeViewer) provider;
        treeViewer.refresh(database, true);
        treeViewer.expandToLevel(database, 1);
        CQBGroupNodePersistManager.getInstance().saveAllGroupNode();
        CQBDBNodePersistManager.getInstance().saveDatabases();
    }
}
Also used : TreeViewer(org.eclipse.jface.viewers.TreeViewer) MultiQueryConnEditDialog(com.cubrid.cubridquery.ui.connection.dialog.MultiQueryConnEditDialog) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ConnectionInfo(com.cubrid.common.ui.common.persist.ConnectionInfo) PartInitException(org.eclipse.ui.PartInitException) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) DatabaseEditorConfig(com.cubrid.common.ui.spi.model.DatabaseEditorConfig) QueryConnDialog(com.cubrid.cubridquery.ui.connection.dialog.QueryConnDialog)

Example 75 with PartInitException

use of org.eclipse.ui.PartInitException in project sling by apache.

the class LinkHelper method activateEditor.

@Override
public void activateEditor(IWorkbenchPage aPage, IStructuredSelection aSelection) {
    final Object selectedElement = aSelection.getFirstElement();
    if (!(selectedElement instanceof JcrNode)) {
        return;
    }
    final JcrNode node = (JcrNode) selectedElement;
    // bring properties view to top, if it is open
    // SLING-3641 : moved link-with-editor behavior to the JCR Properties view atm
    //TODO: to be reviewed at a later stage with SLING-3641
    //		IViewPart propertiesView = aPage.findView(IPageLayout.ID_PROP_SHEET);
    //		if (propertiesView!=null) {
    //			aPage.bringToTop(propertiesView);
    //		}
    final IResource resource = node.getResource();
    if (resource == null || !(resource instanceof IFile)) {
        return;
    }
    final IFile selectedFile = (IFile) resource;
    for (final IEditorReference reference : aPage.getEditorReferences()) {
        if (reference == null) {
            continue;
        }
        final IEditorInput editorInput;
        try {
            editorInput = reference.getEditorInput();
        } catch (PartInitException e) {
            //TODO proper logging
            e.printStackTrace();
            continue;
        }
        if (editorInput == null) {
            continue;
        }
        if (!(editorInput instanceof IFileEditorInput)) {
            continue;
        }
        final IFileEditorInput fileEditorInput = (IFileEditorInput) editorInput;
        final IFile file = fileEditorInput.getFile();
        if (file == null) {
            continue;
        }
        if (file.equals(selectedFile)) {
            aPage.bringToTop(reference.getEditor(true));
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IEditorReference(org.eclipse.ui.IEditorReference) IFileEditorInput(org.eclipse.ui.IFileEditorInput) PartInitException(org.eclipse.ui.PartInitException) IResource(org.eclipse.core.resources.IResource) IEditorInput(org.eclipse.ui.IEditorInput)

Aggregations

PartInitException (org.eclipse.ui.PartInitException)720 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)300 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)177 IFile (org.eclipse.core.resources.IFile)146 IEditorPart (org.eclipse.ui.IEditorPart)141 CoreException (org.eclipse.core.runtime.CoreException)94 FileEditorInput (org.eclipse.ui.part.FileEditorInput)88 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)82 IEditorInput (org.eclipse.ui.IEditorInput)74 ISelection (org.eclipse.jface.viewers.ISelection)62 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)60 IResource (org.eclipse.core.resources.IResource)59 IEditorReference (org.eclipse.ui.IEditorReference)53 IViewPart (org.eclipse.ui.IViewPart)53 IOException (java.io.IOException)42 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)41 Point (org.eclipse.swt.graphics.Point)40 IWorkbench (org.eclipse.ui.IWorkbench)40 Path (org.eclipse.core.runtime.Path)39 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)39