use of com.cubrid.common.ui.spi.model.CubridDatabase in project cubrid-manager by CUBRID.
the class DatabaseQueryNewAction method run.
/**
* @see org.eclipse.jface.action.Action#run()
*/
public void run() {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null) {
return;
}
Object[] obj = this.getSelectedObj();
CubridDatabase[] cubridDatabases = handleSelectionObj(obj);
if (cubridDatabases.length == 0) {
return;
}
/*Limit max number one time*/
if (cubridDatabases.length > LayoutUtil.MAX_OPEN_QUERY_EDITOR_NUM) {
CommonUITool.openConfirmBox(Messages.bind(Messages.msgMaxOpenNum, LayoutUtil.MAX_OPEN_QUERY_EDITOR_NUM));
List<CubridDatabase> list = new ArrayList<CubridDatabase>(LayoutUtil.MAX_OPEN_QUERY_EDITOR_NUM);
for (int i = 0; i < LayoutUtil.MAX_OPEN_QUERY_EDITOR_NUM; i++) {
list.add(cubridDatabases[i]);
}
cubridDatabases = new CubridDatabase[LayoutUtil.MAX_OPEN_QUERY_EDITOR_NUM];
list.toArray(cubridDatabases);
}
// [TOOLS-2425]Support shard broker
// it is used in order to check first shard database when you open several editor of databases.
int count = cubridDatabases.length;
for (CubridDatabase database : cubridDatabases) {
QueryUnit queryUnit = new QueryUnit();
queryUnit.setDatabase(database);
// [TOOLS-2425]Support shard broker
DatabaseInfo dbInfo = database.getDatabaseInfo();
if (dbInfo == null) {
continue;
}
int shardId = 0;
int shardVal = 0;
int shardQueryType = DatabaseInfo.SHARD_QUERY_TYPE_VAL;
if (count == 1) {
// [TOOLS-2425]Support shard broker
if (dbInfo != null && dbInfo.isShard()) {
ShardIdSelectionDialog dialog = new ShardIdSelectionDialog(getShell());
dialog.setDatabaseInfo(dbInfo);
dialog.setShardId(shardId);
dialog.setShardVal(shardVal);
dialog.setShardQueryType(shardQueryType);
if (dialog.open() == IDialogConstants.OK_ID) {
shardId = dialog.getShardId();
shardVal = dialog.getShardVal();
shardQueryType = dialog.getShardQueryType();
}
}
}
try {
IEditorPart editor = window.getActivePage().openEditor(queryUnit, QueryEditorPart.ID);
if (editor != null && database != null) {
QueryEditorPart editorPart = (QueryEditorPart) editor;
editorPart.connect(database);
// [TOOLS-2425]Support shard broker
if (dbInfo.isShard()) {
editorPart.setShardId(shardId);
editorPart.setShardVal(shardVal);
editorPart.setShardQueryType(shardQueryType);
editorPart.changeQueryEditorPartNameWithShard();
}
}
} catch (PartInitException e) {
LOGGER.error(e.getMessage());
}
}
}
use of com.cubrid.common.ui.spi.model.CubridDatabase in project cubrid-manager by CUBRID.
the class DatabaseQueryNewAction method handleSelectionObj.
/**
* handleSelectionObj
* @param objs
* @return
*/
private CubridDatabase[] handleSelectionObj(Object[] objs) {
List<CubridDatabase> returnArray = new ArrayList<CubridDatabase>();
CubridDatabase database = null;
for (Object obj : objs) {
if (obj instanceof ISchemaNode) {
database = ((ISchemaNode) obj).getDatabase();
if (database != null) {
//if multiple selection ,only open a query editor with one database
if (!returnArray.contains(database)) {
returnArray.add(database);
}
}
}
}
return returnArray.toArray(new CubridDatabase[0]);
}
use of com.cubrid.common.ui.spi.model.CubridDatabase in project cubrid-manager by CUBRID.
the class CubridSPFolderLoader 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.isLogined() || database.getRunningType() == DbRunningType.STANDALONE) {
parent.removeAllChild();
CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
return;
}
// add function folder
String functionFolderId = parent.getId() + NODE_SEPARATOR + FUNCTION_FOLDER_ID;
ICubridNode functionFolder = parent.getChild(functionFolderId);
if (functionFolder == null) {
functionFolder = new DefaultSchemaNode(functionFolderId, FUNCTION_FOLDER_NAME, "icons/navigator/folder.png");
functionFolder.setType(NodeType.STORED_PROCEDURE_FUNCTION_FOLDER);
functionFolder.setContainer(true);
ICubridNodeLoader loader = new CubridFunctionFolderLoader();
loader.setLevel(getLevel());
functionFolder.setLoader(loader);
parent.addChild(functionFolder);
if (getLevel() == DEFINITE_LEVEL) {
functionFolder.getChildren(monitor);
}
} else {
if (functionFolder.getLoader() != null && functionFolder.getLoader().isLoaded()) {
functionFolder.getLoader().setLoaded(false);
functionFolder.getChildren(monitor);
}
}
// add procedure folder
String procedureFolderId = parent.getId() + NODE_SEPARATOR + PROCEDURE_FOLDER_ID;
ICubridNode procedureFolder = parent.getChild(procedureFolderId);
if (procedureFolder == null) {
procedureFolder = new DefaultSchemaNode(procedureFolderId, PROCEDURE_FOLDER_NAME, "icons/navigator/folder.png");
procedureFolder.setType(NodeType.STORED_PROCEDURE_PROCEDURE_FOLDER);
procedureFolder.setContainer(true);
ICubridNodeLoader loader = new CubridProcedureFolderLoader();
loader.setLevel(getLevel());
procedureFolder.setLoader(loader);
parent.addChild(procedureFolder);
if (getLevel() == DEFINITE_LEVEL) {
procedureFolder.getChildren(monitor);
}
} else {
if (procedureFolder.getLoader() != null && procedureFolder.getLoader().isLoaded()) {
procedureFolder.getLoader().setLoaded(false);
procedureFolder.getChildren(monitor);
}
}
setLoaded(true);
CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
}
}
use of com.cubrid.common.ui.spi.model.CubridDatabase in project cubrid-manager by CUBRID.
the class CubridUserTableColumnLoader 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.isLogined() || database.getRunningType() == DbRunningType.STANDALONE) {
parent.removeAllChild();
CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
return;
}
if (columns == null && !getColumns(parent, monitor, database)) {
return;
}
if (monitor.isCanceled()) {
columns = null;
setLoaded(true);
return;
}
parent.removeAllChild();
String parentId = parent.getId();
if (columns != null && !columns.isEmpty()) {
for (TableColumn column : columns) {
String label = column.getColumnName() + ",";
label += FieldHandlerUtils.getComleteType(column.getTypeName(), column.getSubElementTypeName(), column.getPrecision(), column.getScale());
String nodeId = parentId + NODE_SEPARATOR + column.getColumnName();
ICubridNode node = new DefaultSchemaNode(nodeId, label, "icons/navigator/table_column_item.png");
if (column.isPrimaryKey()) {
node.setIconPath("icons/primary_key.png");
}
node.setType(NodeType.TABLE_COLUMN);
node.setModelObj(column);
node.setContainer(false);
parent.addChild(node);
}
}
columns = null;
setLoaded(true);
CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
}
}
use of com.cubrid.common.ui.spi.model.CubridDatabase in project cubrid-manager by CUBRID.
the class CubridUserTableIndexLoader 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.isLogined() || database.getRunningType() == DbRunningType.STANDALONE) {
parent.removeAllChild();
CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
return;
}
DatabaseInfo databaseInfo = database.getDatabaseInfo();
final GetUserClassIndexesTask task = new GetUserClassIndexesTask(databaseInfo);
monitorCancel(monitor, new ITask[] { task });
String tableName = parent.getParent().getLabel();
List<TableIndex> indexes = task.getIndexesNames(tableName);
final String errorMsg = task.getErrorMsg();
if (!monitor.isCanceled() && errorMsg != null && errorMsg.trim().length() > 0) {
parent.removeAllChild();
Display display = Display.getDefault();
display.syncExec(new Runnable() {
public void run() {
CommonUITool.openErrorBox(errorMsg);
}
});
setLoaded(true);
return;
}
if (monitor.isCanceled()) {
setLoaded(true);
return;
}
parent.removeAllChild();
String parentId = parent.getId();
if (indexes != null && !indexes.isEmpty()) {
for (TableIndex index : indexes) {
String indexName = index.getIndexName();
String nodeId = parentId + NODE_SEPARATOR + indexName;
String label = indexName;
List<String> dependColumns = index.getColumns();
if (dependColumns != null && !dependColumns.isEmpty()) {
String keyAttrName = index.getColumns().toString();
label += keyAttrName.replace('[', '(').replace(']', ')');
}
ICubridNode node = new DefaultSchemaNode(nodeId, label, "icons/navigator/table_index_item.png");
if (index.isPrimaryKey()) {
node.setIconPath("icons/primary_key.png");
}
node.setType(NodeType.TABLE_INDEX);
node.setModelObj(index);
node.setContainer(false);
parent.addChild(node);
}
}
Collections.sort(parent.getChildren());
setLoaded(true);
CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
}
}
Aggregations