use of com.cubrid.common.ui.spi.model.ISchemaNode in project cubrid-manager by CUBRID.
the class CubridWorkbenchContrItem method openSelectQuery.
public void openSelectQuery(ISelection selection) {
final Object obj = ((IStructuredSelection) selection).getFirstElement();
if (!(obj instanceof ICubridNode)) {
return;
}
ISchemaNode table = (ISchemaNode) obj;
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null) {
return;
}
boolean existsEditor = false;
QueryEditorPart editor = null;
QueryUnit input = new QueryUnit();
input.setDatabase(table.getDatabase());
try {
IEditorPart editorPart = window.getActivePage().getActiveEditor();
if (editorPart != null && editorPart instanceof QueryEditorPart) {
QueryEditorPart queryEditorPart = (QueryEditorPart) editorPart;
if (queryEditorPart.getSelectedDatabase() == input.getDatabase()) {
editor = (QueryEditorPart) editorPart;
existsEditor = true;
}
}
if (editor == null) {
editor = (QueryEditorPart) window.getActivePage().openEditor(input, QueryEditorPart.ID);
editor.connect(table.getDatabase());
}
DefaultSchemaNode tableNode = (DefaultSchemaNode) obj;
String sql = getStmtSQL(tableNode) + StringUtil.NEWLINE + StringUtil.NEWLINE;
if (existsEditor) {
editor.newQueryTab(sql, true);
} else {
editor.setQuery(sql, false, true, false);
}
} catch (Exception e) {
LOGGER.error("", e);
}
}
use of com.cubrid.common.ui.spi.model.ISchemaNode 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);
}
}
use of com.cubrid.common.ui.spi.model.ISchemaNode in project cubrid-manager by CUBRID.
the class CQBDbUsersFolderLoader method load.
/**
*
* Load children object for parent
*
* @param parent the parent node
* @param monitor the IProgressMonitor object
*/
public void load(ICubridNode parent, final IProgressMonitor monitor) {
synchronized (this) {
if (isLoaded()) {
return;
}
CubridDatabase database = ((ISchemaNode) parent).getDatabase();
if (database.getRunningType() == DbRunningType.STANDALONE) {
parent.removeAllChild();
CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
return;
}
DatabaseInfo databaseInfo = database.getDatabaseInfo();
DbUserInfoList dbUserInfoList = new DbUserInfoList();
GetUserListTask task = new GetUserListTask(database.getDatabaseInfo());
parent.removeAllChild();
try {
dbUserInfoList = task.getResultModel();
} catch (Exception e) {
LOGGER.error("load user failed", e);
}
DbUserInfo latestDLoginedbUserInfo = databaseInfo.getAuthLoginedDbUserInfo();
List<DbUserInfo> dbUserList = dbUserInfoList == null ? null : dbUserInfoList.getUserList();
formatUserList(dbUserList);
for (int i = 0; dbUserList != null && dbUserList.size() > i; i++) {
DbUserInfo dbUserInfo = dbUserList.get(i);
if (dbUserInfo.getName().equals(latestDLoginedbUserInfo.getName())) {
dbUserInfo.setDbaAuthority(latestDLoginedbUserInfo.isDbaAuthority());
// databaseInfo.setAuthLoginedDbUserInfo(dbUserInfo);
}
String id = parent.getId() + NODE_SEPARATOR + dbUserInfo.getName();
ICubridNode dbUserInfoNode = new DefaultSchemaNode(id, dbUserInfo.getName(), "icons/navigator/user_item.png");
dbUserInfoNode.setType(NodeType.USER);
dbUserInfoNode.setModelObj(dbUserInfo);
dbUserInfoNode.setContainer(false);
dbUserInfoNode.setEditorId(CQBUserEditor.ID);
parent.addChild(dbUserInfoNode);
}
databaseInfo.setDbUserInfoList(dbUserInfoList);
setLoaded(true);
CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
}
}
use of com.cubrid.common.ui.spi.model.ISchemaNode in project cubrid-manager by CUBRID.
the class ChangeShardAction method isSupported.
/**
* Return whether this action support this object,if not support,this action
* will be disabled
*
* @param obj the Object
* @return <code>true</code> if support this obj;<code>false</code>
* otherwise
*/
public boolean isSupported(Object obj) {
if (obj == null) {
return false;
}
if (!(obj instanceof ICubridNode)) {
return false;
}
ICubridNode cubridNode = (ICubridNode) obj;
String nodeType = cubridNode.getType();
if (!NodeType.DATABASE.equals(nodeType)) {
return false;
}
ISchemaNode schemaNode = (ISchemaNode) cubridNode;
DatabaseInfo dbInfo = schemaNode.getDatabase().getDatabaseInfo();
if (!schemaNode.getDatabase().isLogined()) {
return false;
}
if (!dbInfo.isShard()) {
return false;
}
return true;
}
use of com.cubrid.common.ui.spi.model.ISchemaNode in project cubrid-manager by CUBRID.
the class CubridTitleLineContrItem method getTitleForNavigator.
/**
*
* Get title of CUBRID Query application for navigator
*
* @param cubridNode the ICubridNode object
* @return String
*/
protected String getTitleForNavigator(ICubridNode cubridNode) {
if (cubridNode == null) {
return "";
}
StringBuffer titleStrBuffer = new StringBuffer();
if (cubridNode instanceof ISchemaNode) {
ISchemaNode schemaNode = (ISchemaNode) cubridNode;
CubridDatabase database = schemaNode.getDatabase();
if (database != null) {
titleStrBuffer.append(database.getLabel() + " / ");
}
DatabaseInfo dbInfo = database == null ? null : database.getDatabaseInfo();
if (dbInfo == null) {
return "";
}
StringBuffer dbInfoStrBuffer = new StringBuffer();
DbUserInfo dbUserInfo = dbInfo.getAuthLoginedDbUserInfo();
if (dbUserInfo == null || dbUserInfo.getName() == null || dbUserInfo.getName().trim().length() == 0) {
dbInfoStrBuffer.append(dbInfo.getDbName());
} else {
dbInfoStrBuffer.append(dbUserInfo.getName() + "@" + dbInfo.getDbName());
}
String brokerPort = dbInfo.getBrokerPort();
if (brokerPort != null && brokerPort.trim().length() > 0) {
dbInfoStrBuffer.append(":").append(brokerPort);
}
String charset = dbInfo.getCharSet();
if (charset != null && charset.trim().length() > 0) {
dbInfoStrBuffer.append(":charset=").append(charset);
}
titleStrBuffer.append(dbInfoStrBuffer);
} else {
titleStrBuffer.append(cubridNode.getLabel());
}
return titleStrBuffer.toString();
}
Aggregations