Search in sources :

Example 1 with GetUserClassIndexesTask

use of com.cubrid.cubridmanager.core.cubrid.table.task.GetUserClassIndexesTask 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));
    }
}
Also used : ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) TableIndex(com.cubrid.cubridmanager.core.cubrid.table.model.TableIndex) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) DefaultSchemaNode(com.cubrid.common.ui.spi.model.DefaultSchemaNode) GetUserClassIndexesTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetUserClassIndexesTask) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) Display(org.eclipse.swt.widgets.Display)

Aggregations

CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)1 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 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)1 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)1 TableIndex (com.cubrid.cubridmanager.core.cubrid.table.model.TableIndex)1 GetUserClassIndexesTask (com.cubrid.cubridmanager.core.cubrid.table.task.GetUserClassIndexesTask)1 Display (org.eclipse.swt.widgets.Display)1