Search in sources :

Example 1 with RestorableQueryEditorInfo

use of com.cubrid.common.ui.spi.model.RestorableQueryEditorInfo in project cubrid-manager by CUBRID.

the class ApplicationPersistUtil method loadRestorableQueryEditorInfo.

/**
	 * load RestorableQueryEditorInfo from IXMLMemento
	 *
	 * @param element
	 * @return
	 */
public RestorableQueryEditorInfo loadRestorableQueryEditorInfo(IXMLMemento element) {
    DateFormat formater = DateUtil.getDateFormat(DATE_PATTERN, Locale.ENGLISH);
    RestorableQueryEditorInfo status = new RestorableQueryEditorInfo();
    status.setServerName(element.getString("server"));
    status.setDatabaseName(element.getString("database"));
    try {
        status.setCreatedTime(formater.parse(element.getString("create_time")));
    } catch (Exception e) {
        LOGGER.error("Parse the create time failed:" + e.getMessage(), e);
    }
    status.setQueryContents(element.getString("content"));
    return status;
}
Also used : DateFormat(java.text.DateFormat) RestorableQueryEditorInfo(com.cubrid.common.ui.spi.model.RestorableQueryEditorInfo) ParseException(java.text.ParseException) IOException(java.io.IOException)

Example 2 with RestorableQueryEditorInfo

use of com.cubrid.common.ui.spi.model.RestorableQueryEditorInfo in project cubrid-manager by CUBRID.

the class ApplicationPersistUtil method loadSQLTabItem.

/**
	 * loadSQLTabItem if has sql_tabItem node ,is new version old version not
	 * have this node
	 *
	 * @param element
	 * @return
	 */
private ArrayList<RestorableQueryEditorInfo> loadSQLTabItem(IXMLMemento element) {
    IXMLMemento[] sql_tabItemArray = element.getChildren("sql_tabItem");
    ArrayList<RestorableQueryEditorInfo> sql_tabItemList = new ArrayList<RestorableQueryEditorInfo>();
    if (sql_tabItemArray != null && sql_tabItemArray.length > 0) {
        for (int i = 0; sql_tabItemArray != null && i < sql_tabItemArray.length; i++) {
            IXMLMemento child = sql_tabItemArray[i];
            sql_tabItemList.add(loadRestorableQueryEditorInfo(child));
        }
    } else {
        if (element.getString("database") != null) {
            sql_tabItemList.add(loadRestorableQueryEditorInfo(element));
        }
    }
    return sql_tabItemList;
}
Also used : IXMLMemento(com.cubrid.cubridmanager.core.common.xml.IXMLMemento) ArrayList(java.util.ArrayList) RestorableQueryEditorInfo(com.cubrid.common.ui.spi.model.RestorableQueryEditorInfo)

Example 3 with RestorableQueryEditorInfo

use of com.cubrid.common.ui.spi.model.RestorableQueryEditorInfo in project cubrid-manager by CUBRID.

the class CheckQueryEditorTask method doSave.

public void doSave() {
    ApplicationPersistUtil.getInstance().clearAllEditorStatus();
    Display.getDefault().syncExec(new Runnable() {

        public void run() {
            Date createTime = new Date();
            List<QueryEditorPart> editorPartList = QueryEditorUtil.getAllQueryEditorPart();
            for (QueryEditorPart editor : editorPartList) {
                ArrayList<RestorableQueryEditorInfo> sqlTabItemList = new ArrayList<RestorableQueryEditorInfo>();
                for (CombinedQueryEditorComposite combinedQueryEditorComposite : editor.getAllCombinedQueryEditorComposite()) {
                    StyledText text = combinedQueryEditorComposite.getSqlEditorComp().getText();
                    if (text == null) {
                        LOGGER.warn("The editor.getSqlTextEditor() is a null.");
                        continue;
                    }
                    if (StringUtil.isEmpty(text.getText())) {
                        LOGGER.warn("The text.getText() is a null.");
                        continue;
                    }
                    CubridDatabase cubridDatabase = editor.getSelectedDatabase();
                    RestorableQueryEditorInfo editorStatus = new RestorableQueryEditorInfo();
                    if (cubridDatabase != null) {
                        DatabaseInfo dbInfo = cubridDatabase.getDatabaseInfo();
                        if (dbInfo != null) {
                            editorStatus.setDatabaseName(dbInfo.getDbName());
                        }
                        CubridServer cubridServer = cubridDatabase.getServer();
                        if (cubridServer != null) {
                            editorStatus.setServerName(cubridServer.getId());
                        }
                    }
                    editorStatus.setQueryContents(text.getText());
                    editorStatus.setCreatedTime(createTime);
                    sqlTabItemList.add(editorStatus);
                }
                ApplicationPersistUtil.getInstance().addEditorStatus(sqlTabItemList);
            }
        }
    });
    ApplicationPersistUtil.getInstance().save();
}
Also used : QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) StyledText(org.eclipse.swt.custom.StyledText) CombinedQueryEditorComposite(com.cubrid.common.ui.query.control.CombinedQueryEditorComposite) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) CubridServer(com.cubrid.common.ui.spi.model.CubridServer) RestorableQueryEditorInfo(com.cubrid.common.ui.spi.model.RestorableQueryEditorInfo) Date(java.util.Date)

Example 4 with RestorableQueryEditorInfo

use of com.cubrid.common.ui.spi.model.RestorableQueryEditorInfo in project cubrid-manager by CUBRID.

the class ApplicationPersistUtil method saveToXmlFile.

private void saveToXmlFile(IXMLMemento parent) {
    if (editorStatusList == null) {
        return;
    }
    DateFormat formater = DateUtil.getDateFormat(DATE_PATTERN, Locale.ENGLISH);
    for (List<RestorableQueryEditorInfo> statusList : editorStatusList) {
        IXMLMemento memento = parent.createChild("editor_status");
        for (RestorableQueryEditorInfo status : statusList) {
            IXMLMemento tabItem = memento.createChild("sql_tabItem");
            tabItem.putString("content", status.getQueryContents());
            tabItem.putString("create_time", formater.format(status.getCreatedTime()));
            tabItem.putString("database", status.getDatabaseName() == null ? "" : status.getDatabaseName());
            tabItem.putString("server", status.getServerName() == null ? "" : status.getServerName());
        }
    }
    IXMLMemento queryListDataMemento = parent.createChild("query_record_list_data");
    for (Entry<String, List<QueryRecordProject>> entry : queryRecordMap.entrySet()) {
        String key = entry.getKey();
        List<QueryRecordProject> list = entry.getValue();
        for (QueryRecordProject queryRecordList : list) {
            IXMLMemento queryListMemento = queryListDataMemento.createChild("query_redord_list");
            String createDate = formater.format(queryRecordList.getCreateDate());
            queryListMemento.putString("database_key", key);
            queryListMemento.putString("create_date", createDate);
            queryListMemento.putString("name", queryRecordList.getName());
            for (QueryRecord queryRecord : queryRecordList.getQueryRecordList()) {
                IXMLMemento queryRecordMemento = queryListMemento.createChild("query_record");
                queryRecordMemento.putString("name", queryRecord.getName());
                queryRecordMemento.putString("create_date", formater.format(queryRecord.getCreateDate()));
                queryRecordMemento.putString("start_time", String.valueOf(queryRecord.getStartTime()));
                queryRecordMemento.putString("stop_time", String.valueOf(queryRecord.getStopTime()));
                queryRecordMemento.putString("query", queryRecord.getQuery());
                if (queryRecord.getQueryPlan() != null) {
                    StructQueryPlan queryPlan = queryRecord.getQueryPlan();
                    IXMLMemento queryPlanMemento = queryRecordMemento.createChild("query_plan");
                    queryPlanMemento.putString("query", queryPlan.getSql());
                    queryPlanMemento.putString("plan", queryPlan.getPlanRaw());
                    queryPlanMemento.putString("create_date", formater.format(queryPlan.getCreated()));
                }
                if (queryRecord.getStatistics() != null) {
                    IXMLMemento statisticsMemento = queryRecordMemento.createChild("statistics");
                    for (Entry<String, String> prop : queryRecord.getStatistics().entrySet()) {
                        statisticsMemento.putString(prop.getKey(), prop.getValue());
                    }
                }
            }
        }
    }
}
Also used : QueryRecordProject(com.cubrid.common.ui.query.tuner.QueryRecordProject) IXMLMemento(com.cubrid.cubridmanager.core.common.xml.IXMLMemento) DateFormat(java.text.DateFormat) QueryRecord(com.cubrid.common.ui.query.tuner.QueryRecord) ArrayList(java.util.ArrayList) List(java.util.List) RestorableQueryEditorInfo(com.cubrid.common.ui.spi.model.RestorableQueryEditorInfo) StructQueryPlan(com.cubrid.common.core.queryplan.StructQueryPlan)

Example 5 with RestorableQueryEditorInfo

use of com.cubrid.common.ui.spi.model.RestorableQueryEditorInfo 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

RestorableQueryEditorInfo (com.cubrid.common.ui.spi.model.RestorableQueryEditorInfo)5 ArrayList (java.util.ArrayList)4 CombinedQueryEditorComposite (com.cubrid.common.ui.query.control.CombinedQueryEditorComposite)2 QueryEditorPart (com.cubrid.common.ui.query.editor.QueryEditorPart)2 IXMLMemento (com.cubrid.cubridmanager.core.common.xml.IXMLMemento)2 DateFormat (java.text.DateFormat)2 List (java.util.List)2 StructQueryPlan (com.cubrid.common.core.queryplan.StructQueryPlan)1 QueryUnit (com.cubrid.common.ui.query.editor.QueryUnit)1 QueryRecord (com.cubrid.common.ui.query.tuner.QueryRecord)1 QueryRecordProject (com.cubrid.common.ui.query.tuner.QueryRecordProject)1 StatusLineContrItem (com.cubrid.common.ui.spi.contribution.StatusLineContrItem)1 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)1 CubridServer (com.cubrid.common.ui.spi.model.CubridServer)1 ApplicationPersistUtil (com.cubrid.common.ui.spi.persist.ApplicationPersistUtil)1 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)1 IOException (java.io.IOException)1 ParseException (java.text.ParseException)1 Date (java.util.Date)1 StyledText (org.eclipse.swt.custom.StyledText)1