Search in sources :

Example 16 with ClassInfo

use of com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo in project cubrid-manager by CUBRID.

the class CreateViewAction method run.

public void run(CubridDatabase database) {
    TaskExecutor taskExcutor = new CommonTaskExec(null);
    DatabaseInfo databaseInfo = database.getDatabaseInfo();
    JDBCGetAllDbUserTask task = new JDBCGetAllDbUserTask(databaseInfo);
    taskExcutor.addTask(task);
    new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
    if (!taskExcutor.isSuccess()) {
        return;
    }
    List<String> dbUserList = task.getDbUserList();
    CreateViewDialog dialog = new CreateViewDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), database, true);
    dialog.setDbUserList(dbUserList);
    ISelectionProvider provider = getSelectionProvider();
    if (dialog.open() == IDialogConstants.OK_ID && (provider instanceof TreeViewer)) {
        TreeViewer treeViewer = (TreeViewer) provider;
        ICubridNode folderNode = database.getChild(database.getId() + ICubridNodeLoader.NODE_SEPARATOR + CubridViewsFolderLoader.VIEWS_FOLDER_ID);
        if (folderNode == null || !folderNode.getLoader().isLoaded()) {
            return;
        }
        String viewName = dialog.getNewViewName();
        String owner = dialog.getOwner();
        String id = folderNode.getId() + ICubridNodeLoader.NODE_SEPARATOR + viewName;
        ClassInfo newClassInfo = new ClassInfo(viewName, owner, ClassType.VIEW, false, false);
        ICubridNode newNode = CubridViewsFolderLoader.createUserViewNode(id, newClassInfo);
        CommonUITool.addNodeToTree(treeViewer, folderNode, newNode);
        CommonUITool.updateFolderNodeLabelIncludingChildrenCount(treeViewer, folderNode);
        CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(newNode, CubridNodeChangedEventType.NODE_ADD));
    } else {
        canceledTask = true;
    }
}
Also used : CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) TreeViewer(org.eclipse.jface.viewers.TreeViewer) JDBCGetAllDbUserTask(com.cubrid.cubridmanager.core.cubrid.user.task.JDBCGetAllDbUserTask) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) CreateViewDialog(com.cubrid.common.ui.cubrid.table.dialog.CreateViewDialog) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) ClassInfo(com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo)

Example 17 with ClassInfo

use of com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo 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 18 with ClassInfo

use of com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo in project cubrid-manager by CUBRID.

the class CubridSystemTableFolderLoader 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) {
            database.getDatabaseInfo().setSysTableInfoList(null);
            parent.removeAllChild();
            CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
            return;
        }
        DatabaseInfo databaseInfo = database.getDatabaseInfo();
        final GetAllClassListTask task = new GetAllClassListTask(databaseInfo);
        monitorCancel(monitor, new ITask[] { task });
        List<ClassInfo> allClassInfoList = task.getSchema(false, true);
        final String errorMsg = task.getErrorMsg();
        if (!monitor.isCanceled() && errorMsg != null && errorMsg.trim().length() > 0) {
            parent.removeAllChild();
            openErrorBox(errorMsg);
            setLoaded(true);
            return;
        }
        if (monitor.isCanceled()) {
            setLoaded(true);
            return;
        }
        parent.removeAllChild();
        if (allClassInfoList != null) {
            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.setType(NodeType.SYSTEM_TABLE);
                classNode.setEditorId(SchemaInfoEditorPart.ID);
                classNode.setContainer(false);
                classNode.setModelObj(classInfo);
                parent.addChild(classNode);
            }
        }
        database.getDatabaseInfo().setSysTableInfoList(allClassInfoList);
        Collections.sort(parent.getChildren());
        setLoaded(true);
        CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
    }
}
Also used : GetAllClassListTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllClassListTask) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) DefaultSchemaNode(com.cubrid.common.ui.spi.model.DefaultSchemaNode) ClassInfo(com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo)

Example 19 with ClassInfo

use of com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo in project cubrid-manager by CUBRID.

the class EditUserDialog method setAuthBtnEnableDisable.

/**
	 * Set the auth button disable
	 * 
	 */
@SuppressWarnings("unchecked")
private void setAuthBtnEnableDisable() {
    grantButton.setEnabled(false);
    revokeButton.setEnabled(false);
    /*Can't grant/revoke for  current login user*/
    if (StringUtil.isEqual(this.userName, currentUserInfo.getName())) {
        return;
    }
    DbUserInfo currentUserInfo = database.getDatabaseInfo().getAuthLoginedDbUserInfo();
    boolean isDbaAuthority = currentUserInfo.isDbaAuthority();
    if (classTable.getSelectionCount() > 0 && classTable.isFocusControl()) {
        boolean tag = true;
        if (!isDbaAuthority) {
            for (TableItem item : classTable.getSelection()) {
                ClassAuthorizations authorizations = currentUserAuthorizations.get(item.getText());
                boolean ownertag = false;
                for (ClassInfo bean : allClassInfoList) {
                    if (item.getText().equals(bean.getClassName())) {
                        if (currentUserInfo.getName().equalsIgnoreCase(bean.getOwnerName())) {
                            ownertag = true;
                        }
                        break;
                    }
                }
                tag = tag && (ownertag || authorizations == null || authorizations.isGrantPriv());
                if (!tag) {
                    break;
                }
            }
        }
        grantButton.setEnabled(tag);
    } else if (authTable.getSelectionCount() > 0 && authTable.isFocusControl()) {
        boolean tag = true;
        if (!isDbaAuthority) {
            for (TableItem item : authTable.getSelection()) {
                ClassAuthorizations authorizations = currentUserAuthorizations.get(item.getText());
                boolean ownertag = false;
                for (ClassInfo bean : allClassInfoList) {
                    if (item.getText().equals(bean.getClassName())) {
                        if (currentUserInfo.getName().equalsIgnoreCase(bean.getOwnerName())) {
                            ownertag = true;
                        }
                        break;
                    }
                }
                tag = tag && (ownertag || authorizations == null || (authorizations.isAllPriv() || authorizations.isRevokePriv((Map<String, Object>) item.getData())));
                if (!tag) {
                    break;
                }
            }
        }
        revokeButton.setEnabled(tag);
    }
}
Also used : DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) ClassAuthorizations(com.cubrid.cubridmanager.core.cubrid.table.model.ClassAuthorizations) TableItem(org.eclipse.swt.widgets.TableItem) Map(java.util.Map) HashMap(java.util.HashMap) ClassInfo(com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo)

Example 20 with ClassInfo

use of com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo in project cubrid-manager by CUBRID.

the class EditUserDialog method initial.

/**
	 * Initial data
	 */
private void initial() {
    if (!CubridDatabase.hasValidDatabaseInfo(database)) {
        LOGGER.error("The database is invalid.");
        return;
    }
    this.currentUserInfo = database.getDatabaseInfo().getAuthLoginedDbUserInfo();
    currentUserAuthorizations = currentUserInfo.getUserAuthorizations();
    for (DbUserInfo userInfo : userListInfo.getUserList()) {
        if (userInfo.getName().equals(currentUserInfo.getName())) {
            currentUserInfo = userInfo;
            currentUserAuthorizations = currentUserInfo.getUserAuthorizations();
            break;
        }
    }
    List<String> groupList = null;
    if (newFlag) {
        userNameText.setEnabled(true);
        classGrantMap = new HashMap<String, ClassAuthorizations>();
        Map<String, String> map = new HashMap<String, String>();
        map.put("0", DB_DEFAULT_USERNAME);
        groupList = new ArrayList<String>();
        groupList.add(DB_DEFAULT_USERNAME);
    } else {
        for (DbUserInfo bean : userListInfo.getUserList()) {
            if (bean.getName().equalsIgnoreCase(userName)) {
                userInfo = bean;
            }
            List<String> groups = bean.getGroups().getGroup();
            if (groups != null) {
                for (String g : groups) {
                    if (userName != null && userName.equalsIgnoreCase(g)) {
                        Map<String, String> map = new HashMap<String, String>();
                        map.put("0", bean.getName());
                        memberListData.add(map);
                    }
                }
            }
        }
        memberTableViewer.refresh();
        if (database.getDatabaseInfo().getAuthLoginedDbUserInfo().getName().equalsIgnoreCase(userName) || database.getDatabaseInfo().getAuthLoginedDbUserInfo().getName().equalsIgnoreCase(DB_DBA_USERNAME)) {
            changePwdBtn.setEnabled(true);
        } else {
            changePwdBtn.setEnabled(false);
        }
        userNameText.setText(userInfo.getName());
        groupList = userInfo.getGroups().getGroup();
        classGrantMap = userInfo.getUserAuthorizations();
        oldLoginPassword = database.getDatabaseInfo().getAuthLoginedDbUserInfo().getNoEncryptPassword();
        if (oldLoginPassword == null) {
            oldLoginPassword = "";
        }
    }
    Map<String, String> groupMap = new HashMap<String, String>();
    Map<String, String> memberMap = new HashMap<String, String>();
    // set group map
    if (groupList == null) {
        groupList = new ArrayList<String>();
    }
    for (String group : groupList) {
        groupMap.put(group.toLowerCase(Locale.getDefault()), "");
    }
    if (memberListData != null) {
        for (Map<String, String> map : memberListData) {
            memberMap.put(map.get("0").toLowerCase(Locale.getDefault()), "");
        }
    }
    for (DbUserInfo user : userListInfo.getUserList()) {
        if (!groupMap.containsKey(user.getName().toLowerCase()) && !memberMap.containsKey(user.getName().toLowerCase()) && !user.getName().equalsIgnoreCase(userName)) {
            Map<String, String> map = new HashMap<String, String>();
            map.put("0", user.getName().toLowerCase());
            allUserListData.add(map);
        }
    }
    for (String userName : groupList) {
        Map<String, String> map = new HashMap<String, String>();
        map.put("0", userName.toLowerCase(Locale.getDefault()));
        groupListData.add(map);
    }
    allUserTableViewer.refresh();
    groupTableViewer.refresh();
    Iterator<String> authIter = classGrantMap.keySet().iterator();
    while (authIter.hasNext()) {
        String className = authIter.next();
        if (!partitionClassMap.containsKey(className)) {
            authListData.add(getItemAuthMap(classGrantMap.get(className)));
            authListDataOld.add(getItemAuthMap(classGrantMap.get(className)));
        }
    }
    if (!DB_DBA_USERNAME.equalsIgnoreCase(userName) && !isDBAGroup()) {
        authTableViewer.refresh();
        for (ClassInfo bean : allClassInfoList) {
            if (classGrantMap.containsKey(bean.getClassName()) || bean.isSystemClass() || bean.getOwnerName().equalsIgnoreCase(DB_DEFAULT_USERNAME)) {
                continue;
            }
            Map<String, String> map = new HashMap<String, String>();
            map.put("0", bean.getClassName());
            map.put("1", Messages.msgUserSchema);
            map.put("2", bean.getOwnerName());
            map.put("3", bean.getClassType() == ClassType.VIEW ? Messages.msgVirtualClass : Messages.msgClass);
            classListData.add(map);
        }
        classTableViewer.refresh();
        packTable(classTable);
        packTable(authTable);
    }
    packTable(allUserTable);
    packTable(userGroupTable);
    packTable(memberTableViewer.getTable());
}
Also used : DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) ClassAuthorizations(com.cubrid.cubridmanager.core.cubrid.table.model.ClassAuthorizations) HashMap(java.util.HashMap) ClassInfo(com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo)

Aggregations

ClassInfo (com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo)29 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)10 GetAllClassListTask (com.cubrid.cubridmanager.core.cubrid.table.task.GetAllClassListTask)10 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)9 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)8 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)8 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)8 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)8 DefaultSchemaNode (com.cubrid.common.ui.spi.model.DefaultSchemaNode)7 SQLException (java.sql.SQLException)6 Map (java.util.Map)6 DBAttribute (com.cubrid.common.core.common.model.DBAttribute)5 ClassAuthorizations (com.cubrid.cubridmanager.core.cubrid.table.model.ClassAuthorizations)5 GetAllAttrTask (com.cubrid.cubridmanager.core.cubrid.table.task.GetAllAttrTask)5 GetViewAllColumnsTask (com.cubrid.cubridmanager.core.cubrid.table.task.GetViewAllColumnsTask)5 TreeViewer (org.eclipse.jface.viewers.TreeViewer)5 DbUserInfo (com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo)4 ClassType (com.cubrid.cubridmanager.core.utils.ModelUtil.ClassType)4 CreateViewDialog (com.cubrid.common.ui.cubrid.table.dialog.CreateViewDialog)3