Search in sources :

Example 76 with TreeViewer

use of org.eclipse.jface.viewers.TreeViewer in project cubrid-manager by CUBRID.

the class StopSlaveDbAction method run.

/**
	 * Stop database and refresh navigator
	 */
public void run() {
    Object[] obj = this.getSelectedObj();
    if (!isSupported(obj[0])) {
        setEnabled(false);
        return;
    }
    final ISchemaNode schemaNode = (ISchemaNode) obj[0];
    ReplicationInfo replInfo = (ReplicationInfo) schemaNode.getAdapter(ReplicationInfo.class);
    Set<CubridDatabase> databaseSet = new HashSet<CubridDatabase>();
    for (int j = 0; j < replInfo.getSlaveList().size(); j++) {
        CubridDatabase database = StartSlaveDbAction.getDatabaseByName(schemaNode.getParent(), replInfo.getSlaveList().get(j).getSlaveDbName());
        databaseSet.add(database);
    }
    StringBuffer dbNamesBuffer = new StringBuffer("");
    Iterator<SlaveInfo> it = replInfo.getSlaveList().iterator();
    while (it.hasNext()) {
        dbNamesBuffer.append(it.next().getSlaveDbName()).append(",");
    }
    String dbNames = dbNamesBuffer.toString().substring(0, dbNamesBuffer.toString().length() - 1);
    boolean isStop = CommonUITool.openConfirmBox(getShell(), Messages.bind(Messages.msgConfirmStopDatabase, dbNames));
    if (!isStop) {
        return;
    }
    final Object[] dbObjectArr = new Object[databaseSet.size()];
    databaseSet.toArray(dbObjectArr);
    ISelectionProvider provider = getSelectionProvider();
    final Shell shell = getShell();
    if (provider instanceof TreeViewer && dbObjectArr.length > 0) {
        final TreeViewer viewer = (TreeViewer) provider;
        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++) {
                    ISchemaNode node = (ISchemaNode) dbObjectArr[i];
                    final CubridDatabase database = node.getDatabase();
                    ITask task = taskList.get(i);
                    task.execute();
                    final String msg = task.getErrorMsg();
                    if (openErrorBox(shell, msg, monitor)) {
                        return false;
                    }
                    if (monitor.isCanceled()) {
                        return false;
                    }
                    database.removeAllChild();
                    if (database.getLoader() != null) {
                        database.getLoader().setLoaded(false);
                    }
                    database.setRunningType(DbRunningType.STANDALONE);
                    display.syncExec(new Runnable() {

                        public void run() {
                            viewer.refresh(database, true);
                        }
                    });
                    if (monitor.isCanceled()) {
                        return false;
                    }
                }
                return true;
            }
        };
        for (int i = 0; i < dbObjectArr.length; i++) {
            ISchemaNode node = (ISchemaNode) dbObjectArr[i];
            CubridDatabase database = node.getDatabase();
            CommonUpdateTask task = new CommonUpdateTask(CommonTaskName.STOP_DB_TASK_NAME, database.getServer().getServerInfo(), CommonSendMsg.getCommonDatabaseSendMsg());
            task.setDbName(database.getLabel());
            taskExcutor.addTask(task);
        }
        new ExecTaskWithProgress(taskExcutor).exec();
        if (taskExcutor.isSuccess()) {
            for (int i = 0; i < dbObjectArr.length; i++) {
                CubridDatabase database = (CubridDatabase) dbObjectArr[i];
                CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(database, CubridNodeChangedEventType.DATABASE_STOP));
            }
            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) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) Shell(org.eclipse.swt.widgets.Shell) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) ReplicationInfo(com.cubrid.cubridmanager.core.replication.model.ReplicationInfo) CommonUpdateTask(com.cubrid.cubridmanager.core.common.task.CommonUpdateTask) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) SlaveInfo(com.cubrid.cubridmanager.core.replication.model.SlaveInfo) HashSet(java.util.HashSet) Display(org.eclipse.swt.widgets.Display)

Example 77 with TreeViewer

use of org.eclipse.jface.viewers.TreeViewer in project cubrid-manager by CUBRID.

the class StartSlaveDbAction method run.

/**
	 * Start database and refresh navigator
	 */
public void run() {
    Object[] obj = this.getSelectedObj();
    if (obj == null || obj.length == 0 || !isSupported(obj[0])) {
        setEnabled(false);
        return;
    }
    final ISchemaNode schemaNode = (ISchemaNode) obj[0];
    ReplicationInfo replInfo = (ReplicationInfo) schemaNode.getAdapter(ReplicationInfo.class);
    Set<CubridDatabase> databaseSet = new HashSet<CubridDatabase>();
    for (int j = 0; j < replInfo.getSlaveList().size(); j++) {
        CubridDatabase database = getDatabaseByName(schemaNode.getParent(), replInfo.getSlaveList().get(j).getSlaveDbName());
        databaseSet.add(database);
    }
    final Object[] dbObjectArr = new Object[databaseSet.size()];
    databaseSet.toArray(dbObjectArr);
    ISelectionProvider provider = getSelectionProvider();
    final Shell shell = getShell();
    if (provider instanceof TreeViewer && dbObjectArr.length > 0) {
        final TreeViewer viewer = (TreeViewer) provider;
        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++) {
                    ISchemaNode node = (ISchemaNode) dbObjectArr[i];
                    final CubridDatabase database = node.getDatabase();
                    ITask task = taskList.get(i);
                    task.execute();
                    final String msg = task.getErrorMsg();
                    if (openErrorBox(shell, msg, monitor)) {
                        return false;
                    }
                    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() {
                            viewer.refresh(database, true);
                        }
                    });
                    if (monitor.isCanceled()) {
                        return false;
                    }
                }
                return true;
            }
        };
        for (int i = 0; i < dbObjectArr.length; i++) {
            ISchemaNode node = (ISchemaNode) dbObjectArr[i];
            CubridDatabase database = node.getDatabase();
            CommonUpdateTask task = new CommonUpdateTask(CommonTaskName.START_DB_TASK_NAME, database.getServer().getServerInfo(), CommonSendMsg.getCommonDatabaseSendMsg());
            task.setDbName(database.getLabel());
            taskExcutor.addTask(task);
        }
        new ExecTaskWithProgress(taskExcutor).exec();
        if (taskExcutor.isSuccess()) {
            for (int i = 0; i < dbObjectArr.length; i++) {
                CubridDatabase database = (CubridDatabase) dbObjectArr[i];
                CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(database, CubridNodeChangedEventType.DATABASE_START));
            }
            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) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) Shell(org.eclipse.swt.widgets.Shell) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) ReplicationInfo(com.cubrid.cubridmanager.core.replication.model.ReplicationInfo) CommonUpdateTask(com.cubrid.cubridmanager.core.common.task.CommonUpdateTask) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) HashSet(java.util.HashSet) Display(org.eclipse.swt.widgets.Display)

Example 78 with TreeViewer

use of org.eclipse.jface.viewers.TreeViewer in project cubrid-manager by CUBRID.

the class StartShardAction method run.

/**
	 * Override the run method in order to complete starting broker environment
	 * 
	 */
public void run() {
    final Object[] obj = this.getSelectedObj();
    CubridShard selection = (CubridShard) obj[0];
    if (null == selection) {
        return;
    }
    ServerInfo serverInfo = selection.getServer().getServerInfo();
    StartShardTask task = new StartShardTask(serverInfo, selection.getName());
    IMessageHandler messageHandler = new IMessageHandler() {

        public String translate(String message) {
            if (message == null) {
                return "";
            }
            if (message.indexOf("failed to metadata validate check") != -1) {
                return Messages.errStartShardNotConfigOrFailed + StringUtil.NEWLINE + StringUtil.NEWLINE + Messages.msgShardGuide;
            }
            return "";
        }
    };
    TaskExecutor taskExecutor = new CommonTaskExec(Messages.startShardActionName, messageHandler);
    taskExecutor.addTask(task);
    new ExecTaskWithProgress(taskExecutor).exec();
    if (!taskExecutor.isSuccess()) {
        return;
    }
    if (!task.isSuccess()) {
        String msg = Messages.bind(Messages.errCanNotStartShardBroker, Messages.msgShardGuide);
        CommonUITool.openErrorBox(msg);
        return;
    }
    selection.setRunning(true);
    TreeViewer treeViewer = (TreeViewer) this.getSelectionProvider();
    CommonUITool.refreshNavigatorTree(treeViewer, selection);
    ActionManager.getInstance().fireSelectionChanged(getSelection());
}
Also used : CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IMessageHandler(com.cubrid.common.ui.spi.IMessageHandler) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) TreeViewer(org.eclipse.jface.viewers.TreeViewer) CubridShard(com.cubrid.cubridmanager.ui.spi.model.CubridShard) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) StartShardTask(com.cubrid.cubridmanager.core.shard.task.StartShardTask)

Example 79 with TreeViewer

use of org.eclipse.jface.viewers.TreeViewer in project cubrid-manager by CUBRID.

the class StartShardEnvAction method run.

/**
	 * Override the run method in order to complete starting broker environment
	 * 
	 */
public void run() {
    final Object[] obj = this.getSelectedObj();
    CubridShardFolder selection = (CubridShardFolder) obj[0];
    if (null == selection) {
        return;
    }
    ServerInfo serverInfo = selection.getServer().getServerInfo();
    StartShardTask task = new StartShardTask(serverInfo, null);
    IMessageHandler messageHandler = new IMessageHandler() {

        public String translate(String message) {
            if (message == null) {
                return "";
            }
            if (message.indexOf("failed to metadata validate check") != -1) {
                return Messages.errStartShardNotConfigOrFailed + StringUtil.NEWLINE + StringUtil.NEWLINE + Messages.msgShardGuide;
            }
            return "";
        }
    };
    TaskExecutor taskExecutor = new CommonTaskExec(Messages.startShardEnvActionName, messageHandler);
    taskExecutor.addTask(task);
    new ExecTaskWithProgress(taskExecutor).exec();
    if (!taskExecutor.isSuccess()) {
        return;
    }
    if (!task.isSuccess()) {
        String msg = Messages.bind(Messages.errCanNotStartShardBroker, Messages.msgShardGuide);
        CommonUITool.openErrorBox(msg);
        return;
    }
    selection.setRunning(true);
    TreeViewer treeViewer = (TreeViewer) this.getSelectionProvider();
    CommonUITool.refreshNavigatorTree(treeViewer, selection);
    ActionManager.getInstance().fireSelectionChanged(getSelection());
}
Also used : CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IMessageHandler(com.cubrid.common.ui.spi.IMessageHandler) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) CubridShardFolder(com.cubrid.cubridmanager.ui.spi.model.CubridShardFolder) StartShardTask(com.cubrid.cubridmanager.core.shard.task.StartShardTask)

Example 80 with TreeViewer

use of org.eclipse.jface.viewers.TreeViewer in project cubrid-manager by CUBRID.

the class CubridBrokerFolderLoader method load.

/**
	 * 
	 * Load children object for parent
	 * 
	 * @param parent the parent node
	 * @param monitor the IProgressMonitor object
	 */
public void load(final ICubridNode parent, final IProgressMonitor monitor) {
    synchronized (this) {
        if (isLoaded()) {
            return;
        }
        //when refresh broker,firstly check whether this broker exist
        int ret = checkBrokerExist(parent, monitor);
        if (ret == 1 || ret == 2) {
            setLoaded(true);
            return;
        }
        if (ret != 0) {
            Display display = Display.getDefault();
            display.syncExec(new Runnable() {

                public void run() {
                    CommonUITool.openErrorBox(Messages.errBrokerNoExist);
                    CubridNavigatorView navigatorView = CubridNavigatorView.getNavigatorView(CubridHostNavigatorView.ID);
                    TreeViewer treeViewer = navigatorView == null ? null : navigatorView.getViewer();
                    if (treeViewer != null) {
                        CommonUITool.refreshNavigatorTree(treeViewer, parent.getParent());
                    }
                }
            });
            setLoaded(true);
            return;
        }
        // add sql log folder
        String sqlLogFolderId = parent.getId() + NODE_SEPARATOR + SQL_LOG_FOLDER_ID;
        ICubridNode sqlLogFolder = parent.getChild(sqlLogFolderId);
        if (sqlLogFolder == null) {
            sqlLogFolder = new DefaultCubridNode(sqlLogFolderId, SQL_LOG_FOLDER_NAME, "icons/navigator/folder.png");
            sqlLogFolder.setType(CubridNodeType.BROKER_SQL_LOG_FOLDER);
            sqlLogFolder.setContainer(true);
            parent.addChild(sqlLogFolder);
        }
        //add the children of sql log folder
        ServerInfo serverInfo = parent.getServer().getServerInfo();
        BrokerLogInfos brokerLogInfos = new BrokerLogInfos();
        final CommonQueryTask<BrokerLogInfos> task = new CommonQueryTask<BrokerLogInfos>(serverInfo, CommonSendMsg.getGetBrokerLogFileInfoMSGItems(), brokerLogInfos);
        task.setBroker(parent.getLabel());
        monitorCancel(monitor, new ITask[] { task });
        task.execute();
        final String errorMsg = task.getErrorMsg();
        if (!monitor.isCanceled() && errorMsg != null && errorMsg.trim().length() > 0) {
            sqlLogFolder.removeAllChild();
            openErrorBox(errorMsg);
            setLoaded(true);
            return;
        }
        if (monitor.isCanceled()) {
            setLoaded(true);
            return;
        }
        sqlLogFolder.removeAllChild();
        brokerLogInfos = task.getResultModel();
        List<LogInfo> logInfoList = brokerLogInfos == null ? null : brokerLogInfos.getBrokerLogInfoList().getLogFileInfoList();
        if (logInfoList != null && !logInfoList.isEmpty()) {
            for (LogInfo logInfo : logInfoList) {
                String id = sqlLogFolder.getId() + NODE_SEPARATOR + logInfo.getName();
                ICubridNode logInfoNode = new DefaultCubridNode(id, logInfo.getName(), "icons/navigator/sqllog_item.png");
                logInfoNode.setContainer(false);
                logInfoNode.setEditorId(LogEditorPart.ID);
                logInfoNode.setModelObj(logInfo);
                if (LogType.SCRIPT.getText().toLowerCase().equals(logInfo.getType())) {
                    logInfoNode.setType(CubridNodeType.BROKER_SQL_LOG);
                    sqlLogFolder.addChild(logInfoNode);
                }
            }
        }
        Collections.sort(sqlLogFolder.getChildren());
        setLoaded(true);
        CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
    }
}
Also used : DefaultCubridNode(com.cubrid.common.ui.spi.model.DefaultCubridNode) LogInfo(com.cubrid.cubridmanager.core.logs.model.LogInfo) BrokerLogInfos(com.cubrid.cubridmanager.core.logs.model.BrokerLogInfos) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) CubridNavigatorView(com.cubrid.common.ui.common.navigator.CubridNavigatorView) CommonQueryTask(com.cubrid.cubridmanager.core.common.task.CommonQueryTask) Display(org.eclipse.swt.widgets.Display)

Aggregations

TreeViewer (org.eclipse.jface.viewers.TreeViewer)248 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)62 GridData (org.eclipse.swt.layout.GridData)50 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)45 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)43 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)42 Composite (org.eclipse.swt.widgets.Composite)42 Tree (org.eclipse.swt.widgets.Tree)42 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)40 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)39 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)38 CubridNavigatorView (com.cubrid.common.ui.common.navigator.CubridNavigatorView)36 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)36 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)36 GridLayout (org.eclipse.swt.layout.GridLayout)34 CommonTaskExec (com.cubrid.common.ui.spi.progress.CommonTaskExec)31 ArrayList (java.util.ArrayList)29 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)27 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)27 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)25