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;
}
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;
}
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();
}
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());
}
}
}
}
}
}
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);
}
Aggregations