Search in sources :

Example 31 with QueryEditorPart

use of com.cubrid.common.ui.query.editor.QueryEditorPart in project cubrid-manager by CUBRID.

the class ApplicationWorkbenchWindowAdvisor method preWindowShellClose.

/**
	 * Performs arbitrary actions as the window's shell is being closed
	 * directly, and possibly veto the close.
	 * 
	 * @return <code>true</code> to allow the window to close, and
	 *         <code>false</code> to prevent the window from closing
	 * @see org.eclipse.ui.IWorkbenchWindow#close
	 * @see WorkbenchAdvisor#preShutdown()
	 */
public boolean preWindowShellClose() {
    Shell shell = getWindowConfigurer().getWindow().getShell();
    GeneralPreference.setMaximizeWindowOnStartUp(shell.getMaximized());
    if (timer != null) {
        timer.cancel();
        HeartBeatTaskManager.getInstance().cancel();
    }
    /*Close the information window*/
    InfoWindowManager.dispose();
    /*All opened queryEditor*/
    List<QueryEditorPart> editorPartList = QueryEditorUtil.getAllQueryEditorPart();
    boolean isNeedSaveQueryEditor = isNeedSaveQueryEditor(editorPartList);
    boolean hasJobRunning = false;
    final JobFamily jobFamily = new JobFamily();
    jobFamily.setServerName(JobFamily.ALL_SERVER);
    Job[] jobs = Job.getJobManager().find(jobFamily);
    if (jobs.length > 0) {
        hasJobRunning = true;
    }
    boolean isExit = false;
    if (hasJobRunning) {
        isExit = CommonUITool.openConfirmBox(getWindowConfigurer().getWindow().getShell(), Messages.msgExistConfirmWithJob);
        if (isExit) {
            Display.getDefault().asyncExec(new Runnable() {

                public void run() {
                    try {
                        Job.getJobManager().cancel(jobFamily);
                    } catch (Exception e) {
                        LOGGER.error("Stopping background jobs was failed.", e);
                    }
                }
            });
            if (isNeedSaveQueryEditor) {
                processSaveQueryEditor();
            }
        }
    } else {
        if (isNeedSaveQueryEditor) {
            processSaveQueryEditor();
            return true;
        } else {
            if (GeneralPreference.isAlwaysExit()) {
                return true;
            }
            MessageDialogWithToggle dialog = MessageDialogWithToggle.openOkCancelConfirm(getWindowConfigurer().getWindow().getShell(), com.cubrid.common.ui.common.Messages.titleExitConfirm, Messages.msgExistConfirm, com.cubrid.common.ui.common.Messages.msgToggleExitConfirm, false, CommonUIPlugin.getDefault().getPreferenceStore(), GeneralPreference.IS_ALWAYS_EXIT);
            isExit = dialog.getReturnCode() == 0 ? true : false;
        }
    }
    return isExit;
}
Also used : Shell(org.eclipse.swt.widgets.Shell) QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle) JobFamily(com.cubrid.common.ui.spi.progress.JobFamily) Job(org.eclipse.core.runtime.jobs.Job)

Example 32 with QueryEditorPart

use of com.cubrid.common.ui.query.editor.QueryEditorPart in project cubrid-manager by CUBRID.

the class OpenQueryAction method run.

public void run() {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return;
    }
    String fileName = null;
    try {
        SetFileEncodingDialog dialog = new SetFileEncodingDialog(getShell(), StringUtil.getDefaultCharset(), true);
        if (IDialogConstants.OK_ID != dialog.open()) {
            return;
        }
        fileName = dialog.getFilePath();
        IEditorPart editor = window.getActivePage().openEditor(new QueryUnit(), QueryEditorPart.ID);
        if (editor == null) {
            return;
        }
        QueryEditorPart queryEditor = (QueryEditorPart) editor;
        queryEditor.getCombinedQueryComposite().getSqlEditorComp().open(dialog.getFilePath(), dialog.getEncoding());
        Object[] obj = this.getSelectedObj();
        CubridDatabase[] cubridDatabases = handleSelectionObj(obj);
        if (cubridDatabases.length > 0 && cubridDatabases[0] != null) {
            ((QueryEditorPart) editor).connect(cubridDatabases[0]);
        }
    } catch (PartInitException e) {
        LOGGER.error("Can not initialize the query editor UI.", e);
    } catch (IOException e) {
        LOGGER.error("Can not open the {} file.", fileName, e);
        //TODO: message localizing
        CommonUITool.openErrorBox(e.getMessage());
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) QueryUnit(com.cubrid.common.ui.query.editor.QueryUnit) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException) IOException(java.io.IOException) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) SetFileEncodingDialog(com.cubrid.common.ui.query.dialog.SetFileEncodingDialog)

Example 33 with QueryEditorPart

use of com.cubrid.common.ui.query.editor.QueryEditorPart in project cubrid-manager by CUBRID.

the class BrokerLogParserAction method run.

public void run() {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return;
    }
    BrokerLogParserDialog dialog = new BrokerLogParserDialog(window.getShell());
    dialog.open();
    if (dialog.getReturnCode() != IDialogConstants.OK_ID) {
        return;
    }
    String sql = dialog.getResultSql();
    try {
        QueryUnit input = new QueryUnit();
        QueryEditorPart editor = (QueryEditorPart) window.getActivePage().openEditor(input, QueryEditorPart.ID);
        editor.setQuery(sql, false, false, false);
    } catch (PartInitException e) {
        LOGGER.debug("Failed sql is {}.", sql);
        LOGGER.error("Can not parse broker sql log.", e);
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) BrokerLogParserDialog(com.cubrid.common.ui.common.dialog.BrokerLogParserDialog) QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) QueryUnit(com.cubrid.common.ui.query.editor.QueryUnit) PartInitException(org.eclipse.ui.PartInitException)

Example 34 with QueryEditorPart

use of com.cubrid.common.ui.query.editor.QueryEditorPart in project cubrid-manager by CUBRID.

the class OpenTargetAction method showObjectInfo.

public void showObjectInfo(DefaultSchemaNode table) {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return;
    }
    try {
        QueryEditorPart queryEditPart = null;
        IEditorPart editorPart = window.getActivePage().getActiveEditor();
        if (editorPart != null && editorPart instanceof QueryEditorPart) {
            QueryEditorPart activeQueryEditorPart = (QueryEditorPart) editorPart;
            if (table.getDatabase().equals(activeQueryEditorPart.getSelectedDatabase())) {
                queryEditPart = activeQueryEditorPart;
            }
        }
        if (queryEditPart != null) {
            queryEditPart.getCombinedQueryComposite().createObjInfoFolder(table);
            window.getActivePage().activate(queryEditPart);
        } else {
            QueryUnit input = new QueryUnit();
            input.setDatabase(table.getDatabase());
            queryEditPart = (QueryEditorPart) window.getActivePage().openEditor(input, QueryEditorPart.ID);
            queryEditPart.connect(table.getDatabase());
            queryEditPart.getCombinedQueryComposite().createObjInfoFolder(table);
        }
    } catch (PartInitException e) {
        LOGGER.error("Can not initialize the query editor UI.", e);
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) QueryUnit(com.cubrid.common.ui.query.editor.QueryUnit) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException)

Example 35 with QueryEditorPart

use of com.cubrid.common.ui.query.editor.QueryEditorPart 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

QueryEditorPart (com.cubrid.common.ui.query.editor.QueryEditorPart)51 IEditorPart (org.eclipse.ui.IEditorPart)41 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)39 QueryUnit (com.cubrid.common.ui.query.editor.QueryUnit)21 PartInitException (org.eclipse.ui.PartInitException)19 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)13 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)8 ArrayList (java.util.ArrayList)7 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)6 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)5 List (java.util.List)5 StyledText (org.eclipse.swt.custom.StyledText)5 ShardIdSelectionDialog (com.cubrid.common.ui.common.dialog.ShardIdSelectionDialog)4 CombinedQueryEditorComposite (com.cubrid.common.ui.query.control.CombinedQueryEditorComposite)4 IOException (java.io.IOException)4 IEditorReference (org.eclipse.ui.IEditorReference)4 CubridServer (com.cubrid.common.ui.spi.model.CubridServer)3 DefaultSchemaNode (com.cubrid.common.ui.spi.model.DefaultSchemaNode)3 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)3 Control (org.eclipse.swt.widgets.Control)3