Search in sources :

Example 1 with GetUserClassColumnsTask

use of com.cubrid.cubridmanager.core.cubrid.table.task.GetUserClassColumnsTask in project cubrid-manager by CUBRID.

the class CubridTablesFolderLoader method createUserTableNodes.

/**
	 * Create user table node
	 * 
	 * @param parent ICubridNode
	 * @param allClassInfoList A list includes all the class info
	 * @param level The load level
	 * @param monitor The IProgressMonitor
	 */
private void createUserTableNodes(ICubridNode parent, List<ClassInfo> allClassInfoList, int level, IProgressMonitor monitor) {
    List<String> tables = new ArrayList<String>();
    for (ClassInfo classInfo : allClassInfoList) {
        String id = parent.getId() + NODE_SEPARATOR + classInfo.getClassName();
        ICubridNode classNode = new DefaultSchemaNode(id, classInfo.getClassName(), "icons/navigator/schema_table_item.png");
        classNode.setEditorId(SchemaInfoEditorPart.ID);
        classNode.setContainer(true);
        classNode.setModelObj(classInfo);
        classNode.setType(NodeType.USER_TABLE);
        parent.addChild(classNode);
        ICubridNodeLoader loader = null;
        if (classInfo.isPartitionedClass()) {
            classNode.setType(NodeType.USER_PARTITIONED_TABLE_FOLDER);
            classNode.setIconPath("icons/navigator/schema_table_partition.png");
            classNode.setContainer(true);
            loader = new CubridPartitionedTableLoader();
        } else {
            loader = new CubridUserTableLoader();
        }
        loader.setLevel(level);
        classNode.setLoader(loader);
        tables.add(classInfo.getClassName());
    }
    if (level == DEFINITE_LEVEL) {
        CubridDatabase database = ((ISchemaNode) parent).getDatabase();
        DatabaseInfo databaseInfo = database.getDatabaseInfo();
        final GetUserClassColumnsTask task = new GetUserClassColumnsTask(databaseInfo);
        monitorCancel(monitor, new ITask[] { task });
        Map<String, List<TableColumn>> columnsOfTable = task.getColumns(tables);
        final String errorMsg = task.getErrorMsg();
        if (!monitor.isCanceled() && !task.isInTransation() && errorMsg != null && errorMsg.trim().length() > 0) {
            Display display = Display.getDefault();
            display.syncExec(new Runnable() {

                public void run() {
                    CommonUITool.openErrorBox(errorMsg);
                }
            });
            parent.removeAllChild();
            setLoaded(true);
            return;
        }
        if (monitor.isCanceled()) {
            setLoaded(true);
            return;
        }
        for (ClassInfo classInfo : allClassInfoList) {
            String tableId = parent.getId() + NODE_SEPARATOR + classInfo.getClassName();
            ICubridNode node = parent.getChild(tableId);
            CubridUserTableLoader tableLoader = (CubridUserTableLoader) node.getLoader();
            tableLoader.setColumns(columnsOfTable.get(classInfo.getClassName()));
            node.getChildren(monitor);
            tableLoader.setLoaded(true);
        }
    }
}
Also used : ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ArrayList(java.util.ArrayList) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) DefaultSchemaNode(com.cubrid.common.ui.spi.model.DefaultSchemaNode) ICubridNodeLoader(com.cubrid.common.ui.spi.model.ICubridNodeLoader) ArrayList(java.util.ArrayList) List(java.util.List) GetUserClassColumnsTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetUserClassColumnsTask) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) ClassInfo(com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo) Display(org.eclipse.swt.widgets.Display)

Example 2 with GetUserClassColumnsTask

use of com.cubrid.cubridmanager.core.cubrid.table.task.GetUserClassColumnsTask in project cubrid-manager by CUBRID.

the class CubridUserTableColumnLoader method getColumns.

/**
	 * Get the columns based upon the given parent node
	 * 
	 * @param parent the given parent node
	 * @param monitor the IProgressMonitor object
	 * @param database the given database
	 * @return whether is in transaction
	 */
private boolean getColumns(ICubridNode parent, final IProgressMonitor monitor, CubridDatabase database) {
    DatabaseInfo databaseInfo = database.getDatabaseInfo();
    final GetUserClassColumnsTask task = new GetUserClassColumnsTask(databaseInfo);
    monitorCancel(monitor, new ITask[] { task });
    String tableName = parent.getParent().getLabel();
    columns = task.getColumns(tableName);
    final String errorMsg = task.getErrorMsg();
    if (!monitor.isCanceled() && errorMsg != null && errorMsg.trim().length() > 0) {
        Display display = Display.getDefault();
        display.syncExec(new Runnable() {

            public void run() {
                CommonUITool.openErrorBox(errorMsg);
            }
        });
        columns = null;
        if (!task.isInTransation()) {
            parent.removeAllChild();
            setLoaded(true);
            return false;
        }
    }
    return true;
}
Also used : DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) GetUserClassColumnsTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetUserClassColumnsTask) Display(org.eclipse.swt.widgets.Display)

Aggregations

DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)2 GetUserClassColumnsTask (com.cubrid.cubridmanager.core.cubrid.table.task.GetUserClassColumnsTask)2 Display (org.eclipse.swt.widgets.Display)2 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)1 DefaultSchemaNode (com.cubrid.common.ui.spi.model.DefaultSchemaNode)1 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)1 ICubridNodeLoader (com.cubrid.common.ui.spi.model.ICubridNodeLoader)1 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)1 ClassInfo (com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1