Search in sources :

Example 51 with DefaultSchemaNode

use of com.cubrid.common.ui.spi.model.DefaultSchemaNode in project cubrid-manager by CUBRID.

the class CQBDbConnectionLoader method addViewFolder.

/**
	 * Add view folder
	 * 
	 * @param monitor the IProgressMonitor
	 * @param database the CubridDatabase
	 */
private void addViewFolder(final IProgressMonitor monitor, CubridDatabase database) {
    String viewsFolderId = database.getId() + NODE_SEPARATOR + VIEWS_FOLDER_ID;
    ICubridNode viewsFolder = database.getChild(viewsFolderId);
    if (viewsFolder == null) {
        viewsFolder = new DefaultSchemaNode(viewsFolderId, VIEWS_FOLDER_NAME, "icons/navigator/schema_view.png");
        viewsFolder.setType(NodeType.VIEW_FOLDER);
        viewsFolder.setContainer(true);
        ICubridNodeLoader loader = new CubridViewsFolderLoader();
        loader.setLevel(getLevel());
        viewsFolder.setLoader(loader);
        database.addChild(viewsFolder);
        if (getLevel() == DEFINITE_LEVEL) {
            viewsFolder.getChildren(monitor);
        }
    } else {
        if (viewsFolder.getLoader() != null && viewsFolder.getLoader().isLoaded()) {
            viewsFolder.getLoader().setLoaded(false);
            viewsFolder.getChildren(monitor);
        }
    }
}
Also used : ICubridNodeLoader(com.cubrid.common.ui.spi.model.ICubridNodeLoader) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) DefaultSchemaNode(com.cubrid.common.ui.spi.model.DefaultSchemaNode) CubridViewsFolderLoader(com.cubrid.common.ui.spi.model.loader.schema.CubridViewsFolderLoader)

Example 52 with DefaultSchemaNode

use of com.cubrid.common.ui.spi.model.DefaultSchemaNode 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));
    }
}
Also used : 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) DefaultSchemaNode(com.cubrid.common.ui.spi.model.DefaultSchemaNode) GetUserListTask(com.cubrid.cubridmanager.core.cubrid.user.task.GetUserListTask) DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) DbUserInfoList(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfoList) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 53 with DefaultSchemaNode

use of com.cubrid.common.ui.spi.model.DefaultSchemaNode in project cubrid-manager by CUBRID.

the class CopyPOJOToClipboard method run.

/**
	 * @see org.eclipse.jface.action.Action#run()
	 */
public void run() {
    final Object[] obj = this.getSelectedObj();
    if (!isSupported(obj)) {
        setEnabled(false);
        return;
    }
    final Display display = PlatformUI.getWorkbench().getDisplay();
    BusyIndicator.showWhile(display, new Runnable() {

        public void run() {
            DefaultSchemaNode table = (DefaultSchemaNode) obj[0];
            String pojoString = getPojoString(table);
            CommonUITool.copyContentToClipboard(pojoString);
            CommonUITool.openInformationBox(Messages.titleCopyToPojo, Messages.msgCopyToPojo);
        }
    });
}
Also used : DefaultSchemaNode(com.cubrid.common.ui.spi.model.DefaultSchemaNode) Display(org.eclipse.swt.widgets.Display)

Example 54 with DefaultSchemaNode

use of com.cubrid.common.ui.spi.model.DefaultSchemaNode in project cubrid-manager by CUBRID.

the class ColumnProposalAdvisor method nodeChanged.

/**
	 * Perform node changed event
	 */
public void nodeChanged(CubridNodeChangedEvent event) {
    ICubridNode cubridNode = event.getCubridNode();
    CubridNodeChangedEventType eventType = event.getType();
    if (cubridNode == null || eventType == null) {
        return;
    }
    if ((NodeType.USER_TABLE.equals(cubridNode.getType()) || NodeType.USER_VIEW.equals(cubridNode.getType())) && cubridNode instanceof DefaultSchemaNode) {
        DefaultSchemaNode schemaNode = (DefaultSchemaNode) cubridNode;
        DatabaseInfo databaseInfo = schemaNode.getDatabase().getDatabaseInfo();
        if (CubridNodeChangedEventType.NODE_REMOVE.equals(eventType)) {
            removeTable(databaseInfo, schemaNode.getName());
        } else if (CubridNodeChangedEventType.NODE_ADD.equals(eventType) || CubridNodeChangedEventType.NODE_REFRESH.equals(eventType)) {
            refreshTable(databaseInfo, schemaNode.getName());
        }
    }
    if (NodeType.DATABASE.equals(cubridNode.getType()) && cubridNode instanceof CubridDatabase) {
        CubridDatabase database = (CubridDatabase) cubridNode;
        if (CubridNodeChangedEventType.DATABASE_LOGIN.equals(eventType)) {
            removeProposal(database.getDatabaseInfo());
            findProposal(database.getDatabaseInfo());
        }
        if (CubridNodeChangedEventType.DATABASE_LOGOUT.equals(eventType)) {
            removeProposal(database.getDatabaseInfo());
        }
        if (CubridNodeChangedEventType.CONTAINER_NODE_REFRESH.equals(eventType)) {
            removeProposal(database.getDatabaseInfo());
            findProposal(database.getDatabaseInfo());
        }
    }
    if (NodeType.TABLE_FOLDER.equals(cubridNode.getType()) || NodeType.VIEW_FOLDER.equals(cubridNode.getType()) && CubridNodeChangedEventType.CONTAINER_NODE_REFRESH.equals(eventType) && cubridNode instanceof DefaultSchemaNode) {
        DefaultSchemaNode schemaNode = (DefaultSchemaNode) cubridNode;
        removeProposal(schemaNode.getDatabase().getDatabaseInfo());
        findProposal(schemaNode.getDatabase().getDatabaseInfo());
    }
}
Also used : DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) CubridNodeChangedEventType(com.cubrid.common.ui.spi.event.CubridNodeChangedEventType) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) DefaultSchemaNode(com.cubrid.common.ui.spi.model.DefaultSchemaNode) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 55 with DefaultSchemaNode

use of com.cubrid.common.ui.spi.model.DefaultSchemaNode in project cubrid-manager by CUBRID.

the class CopySQLToFileDialog method okPressed.

/**
	 * OK button pressed. Save SQL to file.
	 */
protected void okPressed() {
    // FIXME move this logic to core module
    final int len = objects.length;
    final Display display = PlatformUI.getWorkbench().getDisplay();
    BusyIndicator.showWhile(display, new Runnable() {

        public void run() {
            StringBuffer allTableSql = new StringBuffer();
            if (btnCreateSQL.getSelection()) {
                for (int i = 0; i < len; i++) {
                    DefaultSchemaNode table = (DefaultSchemaNode) objects[i];
                    String sql = SQLGenerateUtils.getCreateSQL(table);
                    if (sql != null && sql.trim().length() > 0) {
                        allTableSql.append(sql);
                        allTableSql.append(StringUtil.NEWLINE);
                        allTableSql.append(StringUtil.NEWLINE);
                    }
                }
            }
            if (btnGrantSQL.getSelection()) {
                for (int i = 0; i < len; i++) {
                    DefaultSchemaNode table = (DefaultSchemaNode) objects[i];
                    String sql = SQLGenerateUtils.getGrantSQL(table);
                    if (sql != null && sql.trim().length() > 0) {
                        allTableSql.append(sql);
                        allTableSql.append(StringUtil.NEWLINE);
                        allTableSql.append(StringUtil.NEWLINE);
                    }
                }
            }
            if (btnInsertSQL.getSelection()) {
                for (int i = 0; i < len; i++) {
                    DefaultSchemaNode table = (DefaultSchemaNode) objects[i];
                    String sql = SQLGenerateUtils.getInsertSQL(table);
                    if (sql != null && sql.trim().length() > 0) {
                        allTableSql.append(sql);
                        allTableSql.append(StringUtil.NEWLINE);
                        allTableSql.append(StringUtil.NEWLINE);
                    }
                }
            }
            if (btnUpdateSQL.getSelection()) {
                for (int i = 0; i < len; i++) {
                    DefaultSchemaNode table = (DefaultSchemaNode) objects[i];
                    String sql = SQLGenerateUtils.getUpdateSQL(table);
                    if (sql != null && sql.trim().length() > 0) {
                        allTableSql.append(sql);
                        allTableSql.append(StringUtil.NEWLINE);
                        allTableSql.append(StringUtil.NEWLINE);
                    }
                }
            }
            if (btnDeleteSQL.getSelection()) {
                for (int i = 0; i < len; i++) {
                    DefaultSchemaNode table = (DefaultSchemaNode) objects[i];
                    String sql = SQLGenerateUtils.getDeleteSQL(table);
                    if (sql != null && sql.trim().length() > 0) {
                        allTableSql.append(sql);
                        allTableSql.append(StringUtil.NEWLINE);
                        allTableSql.append(StringUtil.NEWLINE);
                    }
                }
            }
            if (btnSelectSQL.getSelection()) {
                for (int i = 0; i < len; i++) {
                    DefaultSchemaNode table = (DefaultSchemaNode) objects[i];
                    String sql = SQLGenerateUtils.getSelectSQL(table);
                    if (sql != null && sql.trim().length() > 0) {
                        allTableSql.append(sql);
                        allTableSql.append(StringUtil.NEWLINE);
                        allTableSql.append(StringUtil.NEWLINE);
                    }
                }
            }
            if (allTableSql.length() == 0) {
                return;
            }
            File file = new File(txtFile.getText());
            if (file.isDirectory()) {
                return;
            }
            try {
                if (!file.delete() && !file.createNewFile()) {
                    return;
                }
                FileOutputStream fos = new FileOutputStream(file);
                fos.write(allTableSql.toString().getBytes("utf-8"));
                fos.flush();
                fos.close();
            } catch (IOException e) {
                LOGGER.error("", e);
            }
        }
    });
    super.okPressed();
}
Also used : FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) DefaultSchemaNode(com.cubrid.common.ui.spi.model.DefaultSchemaNode) File(java.io.File) Display(org.eclipse.swt.widgets.Display)

Aggregations

DefaultSchemaNode (com.cubrid.common.ui.spi.model.DefaultSchemaNode)88 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)62 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)33 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)22 ICubridNodeLoader (com.cubrid.common.ui.spi.model.ICubridNodeLoader)21 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)18 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)17 ArrayList (java.util.ArrayList)15 TreeViewer (org.eclipse.jface.viewers.TreeViewer)10 CommonTaskExec (com.cubrid.common.ui.spi.progress.CommonTaskExec)9 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)9 Display (org.eclipse.swt.widgets.Display)9 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)8 ClassInfo (com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo)7 File (java.io.File)5 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)4 CommonQueryTask (com.cubrid.cubridmanager.core.common.task.CommonQueryTask)4 DbSpaceInfoList (com.cubrid.cubridmanager.core.cubrid.dbspace.model.DbSpaceInfoList)4 GetAllClassListTask (com.cubrid.cubridmanager.core.cubrid.table.task.GetAllClassListTask)4 DbUserInfo (com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo)4