Search in sources :

Example 61 with ISchemaNode

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

the class ActionSupportUtil method hasAdminPermissionOnStopState.

/**
	 * Whether having cubrid manager's administrative permissions on stop state
	 *
	 * @param obj ISchemaNode or ISchemaNode[]
	 * @return boolean
	 */
public static boolean hasAdminPermissionOnStopState(Object obj) {
    if (!ActionSupportUtil.hasAdminPermission(obj)) {
        return false;
    }
    ISchemaNode node = (ISchemaNode) obj;
    CubridDatabase database = node.getDatabase();
    if (database == null) {
        return false;
    }
    if (database.getRunningType() != DbRunningType.STANDALONE) {
        return false;
    }
    return true;
}
Also used : ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 62 with ISchemaNode

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

the class ActionSupportUtil method isSupportSinSelCheckDbUser.

/**
	 * 
	 * Return whether support the single selection and the selection type is
	 * equal <code>type</code> and the selection owner is equal to logined
	 * database user
	 * 
	 * @param obj Object
	 * @param type String
	 * @return boolean
	 */
public static boolean isSupportSinSelCheckDbUser(Object obj, String type) {
    if (obj == null) {
        return false;
    }
    Object selectedObj = obj;
    if (obj instanceof Object[]) {
        Object[] objArr = (Object[]) obj;
        if (objArr.length == 1) {
            selectedObj = objArr[0];
        } else {
            return false;
        }
    }
    if (!(selectedObj instanceof ISchemaNode)) {
        return false;
    }
    ISchemaNode node = (ISchemaNode) selectedObj;
    if (type.equals(node.getType())) {
        ISchemaNode schemaNode = (ISchemaNode) selectedObj;
        CubridDatabase database = schemaNode.getDatabase();
        if (isNotRunningAndNotLogin(database)) {
            return false;
        }
        DatabaseInfo dbInfo = database.getDatabaseInfo();
        if (dbInfo == null) {
            LOGGER.error("The database.getDatabaseInfo() is a null.");
            return false;
        }
        DbUserInfo userInfo = dbInfo.getAuthLoginedDbUserInfo();
        if (userInfo == null) {
            LOGGER.error("The dbInfo.getAuthLoginedDbUserInfo() is a null.");
            return false;
        }
        if (userInfo.isDbaAuthority()) {
            return true;
        }
        boolean isSameUser = StringUtil.isEqualIgnoreCase(userInfo.getName(), getOwner(schemaNode));
        if (isSameUser) {
            return true;
        }
    }
    return false;
}
Also used : DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 63 with ISchemaNode

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

the class ActionSupportUtil method isSupportMultiSelCheckDbUser.

/**
	 * 
	 * Return whether support the multi selection and all selection type is
	 * equal <code>type</code> and the all selection owner is equal to logined
	 * database user
	 * 
	 * @param obj Object
	 * @param type String
	 * @return boolean
	 */
public static boolean isSupportMultiSelCheckDbUser(Object obj, String type) {
    if (obj instanceof ISchemaNode) {
        ISchemaNode schemaNode = (ISchemaNode) obj;
        if (!type.equals(schemaNode.getType())) {
            return false;
        }
        CubridDatabase database = schemaNode.getDatabase();
        if (isNotRunningAndNotLogin(database)) {
            return false;
        }
        DatabaseInfo dbInfo = database.getDatabaseInfo();
        if (dbInfo == null) {
            LOGGER.error("The database.getDatabaseInfo() is a null.");
            return false;
        }
        DbUserInfo userInfo = dbInfo.getAuthLoginedDbUserInfo();
        if (userInfo == null) {
            LOGGER.error("The dbInfo.getAuthLoginedDbUserInfo() is a null.");
            return false;
        }
        if (userInfo.isDbaAuthority()) {
            return true;
        }
        boolean isSameUser = StringUtil.isEqualIgnoreCase(userInfo.getName(), getOwner(schemaNode));
        if (isSameUser) {
            return true;
        }
    } else if (obj instanceof Object[]) {
        Object[] objArr = (Object[]) obj;
        if (objArr.length == 0) {
            return false;
        }
        CubridDatabase database = null;
        for (Object object : objArr) {
            //Check every object whether support
            if (!isSupportMultiSelCheckDbUser(object, type)) {
                return false;
            }
            //Check whether they are in the same database
            ISchemaNode node = (ISchemaNode) object;
            CubridDatabase db = node.getDatabase();
            if (database == null) {
                database = db;
            } else if (!database.getId().equals(db.getId())) {
                return false;
            }
        }
        //Check the database whether login and running
        if (isNotRunningAndNotLogin(database)) {
            return false;
        }
        return true;
    }
    return false;
}
Also used : DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 64 with ISchemaNode

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

the class ShowDatabaseDashboardAction method isSupported.

/**
	 * 
	 * @see com.cubrid.common.ui.spi.action.ISelectionAction#isSupported(java
	 *      .lang.Object)
	 * @param obj the object
	 * @return <code>true</code> if support this object;<code>false</code>
	 *         otherwise
	 */
public boolean isSupported(Object obj) {
    if (obj instanceof ISchemaNode) {
        ISchemaNode node = (ISchemaNode) obj;
        CubridDatabase database = node.getDatabase();
        if (CubridNodeType.DATABASE.equals(node.getType()) && database.isLogined()) {
            return true;
        }
    }
    return false;
}
Also used : ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 65 with ISchemaNode

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

the class StartDatabaseAction method doRun.

public void doRun(ISchemaNode[] schemaArray) {
    if (schemaArray == null || schemaArray.length == 0) {
        return;
    }
    List<ISchemaNode> startList = new ArrayList<ISchemaNode>();
    /*Judge start job is running*/
    for (ISchemaNode node : schemaArray) {
        if (!isSupported(node)) {
            setEnabled(false);
            return;
        }
        CubridDatabase database = node.getDatabase();
        final JobFamily jobFamily = new JobFamily();
        String serverName = database.getServer().getName();
        String dbName = database.getName();
        jobFamily.setServerName(serverName);
        jobFamily.setDbName(dbName);
        Job[] jobs = Job.getJobManager().find(jobFamily);
        if (jobs.length > 0) {
            CommonUITool.openWarningBox(Messages.bind(Messages.msgStartDbWithJob, dbName));
            continue;
        }
        startList.add(database);
    }
    CubridNavigatorView navigationView = CubridNavigatorView.findNavigationView();
    if (navigationView != null && startList.size() > 0) {
        final TreeViewer treeViewer = navigationView.getViewer();
        TaskExecutor taskExcutor = new TaskExecutor() {

            public boolean exec(final IProgressMonitor monitor) {
                Display display = Display.getDefault();
                if (monitor.isCanceled()) {
                    return false;
                }
                for (int i = 0; i < taskList.size(); i++) {
                    ITask task = taskList.get(i);
                    final CubridDatabase database = (CubridDatabase) task.getData("dbName");
                    if (!isSupported(database)) {
                        continue;
                    }
                    monitor.subTask(Messages.bind(Messages.startDbTaskName, database.getName()));
                    task.execute();
                    if (openErrorBox(shell, task.getErrorMsg(), monitor) || monitor.isCanceled()) {
                        return false;
                    }
                    openWarningBox(shell, task.getWarningMsg(), monitor);
                    if (monitor.isCanceled()) {
                        return false;
                    }
                    database.removeAllChild();
                    if (database.getLoader() != null) {
                        database.getLoader().setLoaded(false);
                    }
                    database.setRunningType(DbRunningType.CS);
                    display.syncExec(new Runnable() {

                        public void run() {
                            treeViewer.refresh(database, true);
                        }
                    });
                    if (monitor.isCanceled()) {
                        return false;
                    }
                }
                return true;
            }
        };
        for (ISchemaNode schemaNode : startList) {
            CubridDatabase database = schemaNode.getDatabase();
            if (!isSupported(database)) {
                setEnabled(false);
                return;
            }
            ServerInfo serverInfo = database.getServer().getServerInfo();
            CommonUpdateTask task = new CommonUpdateTask(CommonTaskName.START_DB_TASK_NAME, serverInfo, CommonSendMsg.getCommonDatabaseSendMsg());
            task.setDbName(database.getLabel());
            task.putData("dbName", database);
            taskExcutor.addTask(task);
        }
        new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
        ActionManager.getInstance().fireSelectionChanged(getSelection());
    }
}
Also used : ITask(com.cubrid.common.core.task.ITask) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) ArrayList(java.util.ArrayList) JobFamily(com.cubrid.common.ui.spi.progress.JobFamily) CubridNavigatorView(com.cubrid.common.ui.common.navigator.CubridNavigatorView) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) CommonUpdateTask(com.cubrid.cubridmanager.core.common.task.CommonUpdateTask) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) Job(org.eclipse.core.runtime.jobs.Job) Display(org.eclipse.swt.widgets.Display)

Aggregations

ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)158 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)104 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)55 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)30 ArrayList (java.util.ArrayList)28 TreeViewer (org.eclipse.jface.viewers.TreeViewer)27 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)23 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)23 DefaultSchemaNode (com.cubrid.common.ui.spi.model.DefaultSchemaNode)22 DbUserInfo (com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo)22 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)21 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)21 Shell (org.eclipse.swt.widgets.Shell)16 ITask (com.cubrid.common.core.task.ITask)13 CommonTaskExec (com.cubrid.common.ui.spi.progress.CommonTaskExec)13 IEditorPart (org.eclipse.ui.IEditorPart)12 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)12 HashSet (java.util.HashSet)11 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)11 PartInitException (org.eclipse.ui.PartInitException)10