Search in sources :

Example 6 with CombinedQueryEditorComposite

use of com.cubrid.common.ui.query.control.CombinedQueryEditorComposite in project cubrid-manager by CUBRID.

the class QueryEditorPart method dispose.

/**
	 * When dispose query editor, interrupt query thread, clear result and query
	 * plan, reset query connection
	 */
public void dispose() {
    if (isTransaction()) {
        String msg = Messages.bind(Messages.connCloseConfirm, new String[] { this.getSelectedDatabase().getLabel() });
        String[] buttons = new String[] { Messages.btnYes, Messages.btnNo };
        MessageDialog dialog = new MessageDialog(Display.getDefault().getActiveShell(), com.cubrid.common.ui.common.Messages.titleConfirm, null, msg, MessageDialog.QUESTION, buttons, 0) {

            protected void buttonPressed(int buttonId) {
                switch(buttonId) {
                    case 0:
                        try {
                            queryAction(QUERY_ACTION.COMMIT);
                        } catch (SQLException ex) {
                            CommonUITool.openErrorBox(Messages.bind(com.cubrid.common.ui.common.Messages.errCommonTip, ex.getErrorCode(), ex.getMessage()));
                            LOGGER.error("", ex);
                        }
                        setReturnCode(0);
                        close();
                        break;
                    case 1:
                        try {
                            queryAction(QUERY_ACTION.ROLLBACK);
                        } catch (SQLException ex) {
                            CommonUITool.openErrorBox(Messages.bind(com.cubrid.common.ui.common.Messages.errCommonTip, ex.getErrorCode(), ex.getMessage()));
                            LOGGER.error("", ex);
                        }
                        setReturnCode(1);
                        close();
                        break;
                    default:
                        break;
                }
            }
        };
        int returnVal = dialog.open();
        if (returnVal != 0 && returnVal != 1) {
            try {
                queryAction(QUERY_ACTION.ROLLBACK);
            } catch (SQLException ex) {
                LOGGER.error("", ex);
                String errmsg = Messages.bind(com.cubrid.common.ui.common.Messages.errCommonTip, ex.getErrorCode(), ex.getMessage());
                CommonUITool.openErrorBox(errmsg);
            }
        }
    }
    try {
        if (connection.hasConnection()) {
            queryAction(QUERY_ACTION.CLOSE);
        }
        if (queryThread != null && !queryThread.isInterrupted()) {
            queryThread.interrupt();
            queryThread = null;
        }
        for (CombinedQueryEditorComposite combinedQueryEditorComposite : getAllCombinedQueryEditorComposite()) {
            clearResult(combinedQueryEditorComposite);
            clearPlan(combinedQueryEditorComposite);
            combinedQueryEditorComposite.getSqlEditorComp().release();
        }
    } catch (Exception event) {
        LOGGER.error("", event);
    } finally {
        connection.close();
        connection = null;
    }
    if (result != null) {
        result.dispose();
    }
    super.dispose();
}
Also used : CombinedQueryEditorComposite(com.cubrid.common.ui.query.control.CombinedQueryEditorComposite) SQLException(java.sql.SQLException) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) Point(org.eclipse.swt.graphics.Point) PartInitException(org.eclipse.ui.PartInitException) SQLException(java.sql.SQLException) IOException(java.io.IOException)

Example 7 with CombinedQueryEditorComposite

use of com.cubrid.common.ui.query.control.CombinedQueryEditorComposite in project cubrid-manager by CUBRID.

the class QueryEditorPart method promptToSaveOnClose.

public int promptToSaveOnClose() {
    ServerInfo serverInfo = getSelectedServer() == null ? null : getSelectedServer().getServerInfo();
    boolean isWithoutPrompt = QueryOptions.getWithoutPromptSave(serverInfo);
    CTabItem[] items = combinedQueryEditortabFolder.getItems();
    if (items.length == 0) {
        willClose = true;
        return ISaveablePart2.NO;
    }
    if (items.length > 1) {
        String msg = Messages.bind(Messages.msgConfirmEditorClose, items.length);
        if (!CommonUITool.openConfirmBox(msg)) {
            return ISaveablePart2.CANCEL;
        }
    }
    if (isWithoutPrompt) {
        willClose = true;
        return ISaveablePart2.NO;
    }
    willClose = true;
    int dirtyCount = 0;
    for (CombinedQueryEditorComposite combinedQueryEditorComposite : getAllCombinedQueryEditorComposite()) {
        if (combinedQueryEditorComposite.isDirty()) {
            dirtyCount++;
        }
    }
    String msg = Messages.bind(Messages.msgConfirmEditorSave, dirtyCount);
    if (dirtyCount > 0 && !CommonUITool.openConfirmBox(msg)) {
        return ISaveablePart2.NO;
    }
    int cancelCount = 0;
    for (CTabItem item : items) {
        if (item instanceof SubQueryEditorTabItem) {
            CombinedQueryEditorComposite combinedQueryEditorComposite = ((SubQueryEditorTabItem) item).getControl();
            try {
                if (combinedQueryEditorComposite.isDirty()) {
                    if (combinedQueryEditorComposite.getSqlEditorComp().save()) {
                        combinedQueryEditorComposite.dispose();
                        item.dispose();
                    } else {
                        cancelCount++;
                    }
                }
            } catch (IOException e) {
                LOGGER.error("", e);
            }
        }
    }
    if (cancelCount > 0) {
        return ISaveablePart2.CANCEL;
    }
    return ISaveablePart2.NO;
}
Also used : CombinedQueryEditorComposite(com.cubrid.common.ui.query.control.CombinedQueryEditorComposite) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) IOException(java.io.IOException) CTabItem(org.eclipse.swt.custom.CTabItem) Point(org.eclipse.swt.graphics.Point)

Example 8 with CombinedQueryEditorComposite

use of com.cubrid.common.ui.query.control.CombinedQueryEditorComposite in project cubrid-manager by CUBRID.

the class ERSchemaEditor method generateSqlsToQueryEditor.

private void generateSqlsToQueryEditor(List<StringBuffer> sqls) throws PartInitException {
    final boolean isSupportOnServer = CompatibleUtil.isCommentSupports(database.getDatabaseInfo());
    final QueryEditorPart editPart = CommonUITool.openQueryEditor(database, false);
    editPart.setQuery(sqls.get(0).toString(), true, false, false);
    if (sqls.size() > 1) {
        editPart.newQueryTab(sqls.get(1).toString(), false);
    }
    UIJob job = new UIJob("") {

        public IStatus runInUIThread(IProgressMonitor monitor) {
            String tabMessage = isSupportOnServer ? Messages.edittabNameAlterSQL : Messages.edittabNameInsertSQL;
            List<CombinedQueryEditorComposite> allTabItems = editPart.getAllCombinedQueryEditorComposite();
            editPart.updateTabName(allTabItems.get(0).getSubQueryEditorTabItem(), tabMessage, true);
            if (allTabItems.size() > 1) {
                editPart.updateTabName(allTabItems.get(1).getSubQueryEditorTabItem(), Messages.edittabNameUpdateSQL, true);
            }
            return Status.OK_STATUS;
        }
    };
    job.setPriority(UIJob.BUILD);
    job.schedule();
}
Also used : QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CombinedQueryEditorComposite(com.cubrid.common.ui.query.control.CombinedQueryEditorComposite) UIJob(org.eclipse.ui.progress.UIJob)

Example 9 with CombinedQueryEditorComposite

use of com.cubrid.common.ui.query.control.CombinedQueryEditorComposite in project cubrid-manager by CUBRID.

the class RestoreQueryEditorAction method run.

public void run() {
    ApplicationPersistUtil util = ApplicationPersistUtil.getInstance();
    List<ArrayList<RestorableQueryEditorInfo>> restoreList = util.getEditorStatusListAtLastSession();
    if (restoreList == null || restoreList.size() == 0) {
        CommonUITool.openInformationBox(Messages.errNoRestoreQueryEditor);
        return;
    }
    if (!CommonUITool.openConfirmBox(Messages.restoreQueryEditorConfirm)) {
        return;
    }
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        CommonUITool.openErrorBox(Messages.restoreQueryEditorRestoreFailed);
        return;
    }
    for (List<RestorableQueryEditorInfo> editorStatusList : ApplicationPersistUtil.getInstance().getEditorStatusListAtLastSession()) {
        QueryUnit input = new QueryUnit();
        try {
            QueryEditorPart editor = (QueryEditorPart) window.getActivePage().openEditor(input, QueryEditorPart.ID);
            if (editor == null) {
                continue;
            }
            for (int i = 0; i < editorStatusList.size(); i++) {
                RestorableQueryEditorInfo editorStatus = editorStatusList.get(i);
                if (editorStatus == null) {
                    continue;
                }
                String sql = CheckQueryEditorTask.getQuery(editorStatus);
                CombinedQueryEditorComposite combinedQueryComposite = null;
                if (i == 0) {
                    combinedQueryComposite = editor.getCombinedQueryComposite();
                } else {
                    combinedQueryComposite = editor.addEditorTab();
                }
                if (combinedQueryComposite != null) {
                    combinedQueryComposite.getSqlEditorComp().setQueries(sql);
                }
            }
            editor.setCombinedQueryEditortabFolderSelecton(0);
        } catch (PartInitException e) {
            e.printStackTrace();
        }
    }
    ApplicationPersistUtil.getInstance().clearRestorableQueryEditors();
    StatusLineContrItem statusCont = LayoutManager.getInstance().getStatusLineContrItem();
    statusCont.changeStuatusLineForNavigator(null);
    CommonUITool.openInformationBox(Messages.restoreQueryEditorTitle, Messages.restoreQueryEditorRestoreSuccess);
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) StatusLineContrItem(com.cubrid.common.ui.spi.contribution.StatusLineContrItem) CombinedQueryEditorComposite(com.cubrid.common.ui.query.control.CombinedQueryEditorComposite) ArrayList(java.util.ArrayList) ApplicationPersistUtil(com.cubrid.common.ui.spi.persist.ApplicationPersistUtil) QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) QueryUnit(com.cubrid.common.ui.query.editor.QueryUnit) PartInitException(org.eclipse.ui.PartInitException) RestorableQueryEditorInfo(com.cubrid.common.ui.spi.model.RestorableQueryEditorInfo)

Aggregations

CombinedQueryEditorComposite (com.cubrid.common.ui.query.control.CombinedQueryEditorComposite)9 QueryEditorPart (com.cubrid.common.ui.query.editor.QueryEditorPart)4 ArrayList (java.util.ArrayList)3 Point (org.eclipse.swt.graphics.Point)3 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)2 RestorableQueryEditorInfo (com.cubrid.common.ui.spi.model.RestorableQueryEditorInfo)2 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)2 IOException (java.io.IOException)2 CTabItem (org.eclipse.swt.custom.CTabItem)2 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)2 PartInitException (org.eclipse.ui.PartInitException)2 QueryResultComposite (com.cubrid.common.ui.query.control.QueryResultComposite)1 QueryUnit (com.cubrid.common.ui.query.editor.QueryUnit)1 StatusLineContrItem (com.cubrid.common.ui.spi.contribution.StatusLineContrItem)1 CubridServer (com.cubrid.common.ui.spi.model.CubridServer)1 DatabaseEditorConfig (com.cubrid.common.ui.spi.model.DatabaseEditorConfig)1 ApplicationPersistUtil (com.cubrid.common.ui.spi.persist.ApplicationPersistUtil)1 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)1 SQLException (java.sql.SQLException)1 Date (java.util.Date)1