Search in sources :

Example 16 with CubridNavigatorView

use of com.cubrid.common.ui.common.navigator.CubridNavigatorView in project cubrid-manager by CUBRID.

the class EditHostAction method doRun.

/**
	 * Perform do run
	 * 
	 * @param obj
	 */
public void doRun(CubridServer[] servers, boolean actionIsConnect) {
    //multi edit
    if (servers.length > 1) {
        MultiHostEditDialog dialog = new MultiHostEditDialog(getShell(), Arrays.asList(servers));
        if (dialog.open() != MultiHostEditDialog.SAVE_ID) {
            return;
        }
        BrokerIntervalSettingManager brokerManager = BrokerIntervalSettingManager.getInstance();
        //new server infolist
        List<CubridServer> newServerInfoList = dialog.getNewServerList();
        for (int i = 0; i < servers.length; i++) {
            CubridServer newServer = newServerInfoList.get(i);
            CubridServer server = servers[i];
            if (server == null) {
                continue;
            }
            // if the server is not changed, ignore it.
            if (!checkServerChanges(newServer, server)) {
                continue;
            }
            ServerInfo oldServerInfo = server.getServerInfo();
            if (oldServerInfo == null) {
                LOGGER.error("oldServerInfo is null.");
                continue;
            }
            ServerInfo newServerInfo = newServer.getServerInfo();
            if (newServerInfo == null) {
                LOGGER.error("newServerInfo is null.");
                continue;
            }
            if (!newServerInfo.getServerName().equals(server.getLabel())) {
                QueryOptions.removePref(server.getServerInfo());
                brokerManager.removeAllBrokerIntervalSettingInServer(server.getLabel());
            }
            if (oldServerInfo.isConnected()) {
                HostUtils.processHostDisconnected(server);
            }
            server.setAutoSavePassword(newServer.isAutoSavePassword());
            server.getServerInfo().setServerName(newServerInfo.getServerName());
            server.getServerInfo().setHostAddress(newServerInfo.getHostAddress());
            server.getServerInfo().setHostMonPort(newServerInfo.getHostMonPort());
            server.getServerInfo().setJdbcDriverVersion(newServerInfo.getJdbcDriverVersion());
            server.getServerInfo().setUserName(newServerInfo.getUserName());
            if (newServer.isAutoSavePassword()) {
                server.getServerInfo().setUserPassword(newServerInfo.getUserPassword());
            } else {
                server.getServerInfo().setUserPassword(null);
            }
            server.setId(newServerInfo.getServerName());
            server.setLabel(newServerInfo.getServerName());
            CMHostNodePersistManager.getInstance().addServer(newServerInfo.getHostAddress(), newServerInfo.getHostMonPort(), newServerInfo.getUserName(), newServerInfo);
            CMGroupNodePersistManager.getInstance().saveAllGroupNode();
            CMHostNodePersistManager.getInstance().saveServers();
            if (server.getLoader() != null) {
                server.getLoader().setLoaded(false);
            }
            CubridWorkbenchContrItem.closeAllEditorAndViewInServer(server, false);
            CubridNavigatorView navigatorView = CubridNavigatorView.getNavigatorView(CubridHostNavigatorView.ID);
            if (navigatorView != null) {
                navigatorView.getViewer().refresh(server, true);
            }
            CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(server, CubridNodeChangedEventType.SERVER_DISCONNECTED));
        }
        return;
    }
    // single edit
    HostDialog dialog = new HostDialog(getShell(), false, actionIsConnect);
    CubridServer server = null;
    try {
        server = servers[0];
        //read it from hostgroup preference first
        if (server.getParent() == null) {
            CMGroupNodePersistManager.getInstance();
        }
    } catch (ClassCastException cce) {
        CubridGroupNode node = (CubridGroupNode) getSelectedObj()[0];
        for (ICubridNode icNode : node.getChildren()) {
            if (icNode instanceof CubridServer) {
                if (!((CubridServer) icNode).isConnected())
                    server = (CubridServer) icNode;
            }
        }
    }
    ServerInfo oldServerInfo = server.getServerInfo();
    if (oldServerInfo == null) {
        LOGGER.error("oldServerInfo is null.");
        return;
    }
    dialog.setServer(server);
    int returnCode = dialog.open();
    if (returnCode != HostDialog.SAVE_ID && returnCode != HostDialog.CONNECT_ID) {
        return;
    }
    // Save the server info
    ServerInfo serverInfo = dialog.getServerInfo();
    if (serverInfo == null) {
        LOGGER.error("serverInfo is null.");
        return;
    }
    if (!serverInfo.getServerName().equals(server.getLabel())) {
        QueryOptions.removePref(server.getServerInfo());
        BrokerIntervalSettingManager.getInstance().removeAllBrokerIntervalSettingInServer(server.getLabel());
    }
    if (oldServerInfo.isConnected() && !oldServerInfo.equals(serverInfo)) {
        HostUtils.processHostDisconnected(server);
    }
    server.setId(serverInfo.getServerName());
    server.setLabel(serverInfo.getServerName());
    server.setServerInfo(serverInfo);
    server.setAutoSavePassword(dialog.isSavePassword());
    CMHostNodePersistManager.getInstance().addServer(serverInfo.getHostAddress(), serverInfo.getHostMonPort(), serverInfo.getUserName(), serverInfo);
    // Refresh the tree node
    if (returnCode == HostDialog.CONNECT_ID) {
        ISelectionProvider provider = getSelectionProvider();
        if (provider instanceof TreeViewer) {
            server.removeAllChild();
            if (server.getLoader() != null) {
                server.getLoader().setLoaded(false);
            }
            TreeViewer treeViewer = (TreeViewer) provider;
            treeViewer.refresh(server, true);
            treeViewer.expandToLevel(server, 1);
            treeViewer.setSelection(null, true);
            treeViewer.setSelection(new StructuredSelection(server), true);
            setEnabled(false);
        }
    }
    CMGroupNodePersistManager.getInstance().saveAllGroupNode();
    CMHostNodePersistManager.getInstance().saveServers();
    ActionManager.getInstance().fireSelectionChanged(getSelection());
    LayoutManager.getInstance().fireSelectionChanged(getSelection());
    CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(server, CubridNodeChangedEventType.SERVER_CONNECTED));
}
Also used : BrokerIntervalSettingManager(com.cubrid.cubridmanager.ui.broker.editor.internal.BrokerIntervalSettingManager) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) TreeViewer(org.eclipse.jface.viewers.TreeViewer) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) MultiHostEditDialog(com.cubrid.cubridmanager.ui.host.dialog.MultiHostEditDialog) CubridServer(com.cubrid.common.ui.spi.model.CubridServer) CubridNavigatorView(com.cubrid.common.ui.common.navigator.CubridNavigatorView) CubridGroupNode(com.cubrid.common.ui.spi.model.CubridGroupNode) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) HostDialog(com.cubrid.cubridmanager.ui.host.dialog.HostDialog)

Example 17 with CubridNavigatorView

use of com.cubrid.common.ui.common.navigator.CubridNavigatorView 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)

Example 18 with CubridNavigatorView

use of com.cubrid.common.ui.common.navigator.CubridNavigatorView 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)

Example 19 with CubridNavigatorView

use of com.cubrid.common.ui.common.navigator.CubridNavigatorView in project cubrid-manager by CUBRID.

the class CubridStatusLineContrItem method changeStuatusLineForNavigator.

/**
	 *
	 * Change status line for navigator selection
	 *
	 * @param selection the ISelection object
	 */
public void changeStuatusLineForNavigator(ISelection selection) {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return;
    }
    WorkbenchWindow workbenchWindow = null;
    StatusLineManager statusLineManager = null;
    if (window instanceof WorkbenchWindow) {
        workbenchWindow = (WorkbenchWindow) window;
        statusLineManager = workbenchWindow.getStatusLineManager();
    }
    //workbenchWindow.setStatus("");
    clearStatusLine();
    updateStatusLineForRestoreQueryEditor();
    if (selection == null || selection.isEmpty()) {
        return;
    }
    Object obj = ((IStructuredSelection) selection).getFirstElement();
    if (!(obj instanceof ICubridNode)) {
        return;
    }
    CubridNavigatorView navigatorView = CubridNavigatorView.findNavigationView();
    boolean isShowGroup = navigatorView == null ? false : navigatorView.savedIsShowGroup();
    ICubridNode cubridNode = (ICubridNode) obj;
    String nodePath = cubridNode.getLabel();
    ICubridNode parent = cubridNode.getParent();
    while (parent != null) {
        if (!isShowGroup && NodeType.GROUP.equals(parent.getType())) {
            break;
        }
        nodePath = parent.getLabel() + "/" + nodePath;
        parent = parent.getParent();
    }
    //workbenchWindow.setStatus(nodePath);
    CubridServer server = cubridNode.getServer();
    ServerInfo serverInfo = server == null ? null : server.getServerInfo();
    if (serverInfo == null || !serverInfo.isConnected()) {
        return;
    }
    if (statusLineManager != null) {
        updateStatusLine(statusLineManager, cubridNode);
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) WorkbenchWindow(org.eclipse.ui.internal.WorkbenchWindow) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) CubridNavigatorView(com.cubrid.common.ui.common.navigator.CubridNavigatorView) StatusLineManager(org.eclipse.jface.action.StatusLineManager) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridServer(com.cubrid.common.ui.spi.model.CubridServer)

Example 20 with CubridNavigatorView

use of com.cubrid.common.ui.common.navigator.CubridNavigatorView in project cubrid-manager by CUBRID.

the class CQBConnectionChangingObserver method refreshNavigationTree.

/**
	 * Refresh the navigation tree
	 */
private void refreshNavigationTree(CubridDatabase database) {
    CubridNavigatorView navigatorView = CubridNavigatorView.getNavigatorView(CubridNavigatorView.ID_CQB);
    TreeViewer treeViewer = navigatorView == null ? null : navigatorView.getViewer();
    if (treeViewer == null) {
        return;
    }
    if (database != null) {
        treeViewer.refresh(database, true);
        treeViewer.expandToLevel(database, 1);
    } else {
        CQBDBNodePersistManager.getInstance().reloadDatabases();
        CQBGroupNodePersistManager.getInstance().reloadGroups();
        if (treeViewer != null) {
            treeViewer.refresh(true);
        }
    }
}
Also used : CubridNavigatorView(com.cubrid.common.ui.common.navigator.CubridNavigatorView) TreeViewer(org.eclipse.jface.viewers.TreeViewer)

Aggregations

CubridNavigatorView (com.cubrid.common.ui.common.navigator.CubridNavigatorView)50 TreeViewer (org.eclipse.jface.viewers.TreeViewer)36 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)25 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)22 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)21 CubridGroupNode (com.cubrid.common.ui.spi.model.CubridGroupNode)15 CubridServer (com.cubrid.common.ui.spi.model.CubridServer)13 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)12 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)8 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)7 TreeItem (org.eclipse.swt.widgets.TreeItem)7 ArrayList (java.util.ArrayList)6 Tree (org.eclipse.swt.widgets.Tree)6 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)6 DatabaseEditorConfig (com.cubrid.common.ui.spi.model.DatabaseEditorConfig)5 ISelection (org.eclipse.jface.viewers.ISelection)5 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)4 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)4 WorkbenchWindow (org.eclipse.ui.internal.WorkbenchWindow)4 DatabaseMenuItem (com.cubrid.common.ui.query.control.DatabaseMenuItem)3