Search in sources :

Example 6 with ISelectionProvider

use of org.eclipse.jface.viewers.ISelectionProvider 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 7 with ISelectionProvider

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

the class DeleteMonitorDashboardAction method run.

/**
	 * Delete the selected monitoring dash board
	 */
public void run() {
    Object[] objArr = this.getSelectedObj();
    if (objArr == null || objArr.length <= 0) {
        setEnabled(false);
        return;
    }
    StringBuffer dashboardNames = new StringBuffer();
    for (int i = 0; objArr != null && i < objArr.length; i++) {
        if (!isSupported(objArr[i])) {
            setEnabled(false);
            return;
        }
        ICubridNode node = (ICubridNode) objArr[i];
        dashboardNames.append(node.getLabel());
        if (i != objArr.length - 1) {
            dashboardNames.append(",");
        }
    }
    boolean isDelete = CommonUITool.openConfirmBox(getShell(), Messages.bind(Messages.msgConfirmDeleteDashboard, dashboardNames.toString()));
    if (!isDelete) {
        return;
    }
    ISelectionProvider provider = this.getSelectionProvider();
    if (provider instanceof TreeViewer) {
        TreeViewer viewer = (TreeViewer) provider;
        for (int i = 0; i < objArr.length; i++) {
            ICubridNode node = (ICubridNode) objArr[i];
            LayoutUtil.closeEditorAndView(node);
            MonitorDashboardPersistManager.getInstance().removeMonitorDashboard(node);
            CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(node, CubridNodeChangedEventType.NODE_REMOVE));
        }
        /*TOOLS-3666 Refresh the input of TreeViewer*/
        viewer.setInput(CubridMonitorNavigatorView.getTreeViewerInput());
    }
}
Also used : ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)

Example 8 with ISelectionProvider

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

the class AddFunctionAction method run.

/**
	 * Open addFunctionDialog
	 */
public void run() {
    // FIXME logic code move to core module
    Shell shell = getShell();
    Object[] obj = this.getSelectedObj();
    if (!isSupported(obj[0])) {
        setEnabled(false);
        return;
    }
    ISchemaNode node = (ISchemaNode) obj[0];
    CubridDatabase database = node.getDatabase();
    EditFunctionDialog dlg = new EditFunctionDialog(shell);
    dlg.setDatabase(database);
    dlg.setNewFlag(true);
    ISelectionProvider provider = getSelectionProvider();
    if (dlg.open() == IDialogConstants.OK_ID && (provider instanceof TreeViewer)) {
        ICubridNode folderNode = database.getChild(database.getId() + ICubridNodeLoader.NODE_SEPARATOR + CubridSPFolderLoader.SP_FOLDER_ID);
        folderNode = folderNode.getChild(folderNode.getId() + ICubridNodeLoader.NODE_SEPARATOR + CubridSPFolderLoader.FUNCTION_FOLDER_ID);
        TreeViewer treeViewer = (TreeViewer) provider;
        if (folderNode == null || !folderNode.getLoader().isLoaded()) {
            return;
        }
        String functionName = dlg.getFunctionName().toLowerCase(Locale.getDefault());
        String id = folderNode.getId() + ICubridNodeLoader.NODE_SEPARATOR + functionName;
        DbUserInfo userInfo = database.getDatabaseInfo().getAuthLoginedDbUserInfo();
        SPInfo spInfo = new SPInfo(functionName);
        spInfo.setOwner(userInfo.getName());
        ICubridNode newNode = CubridFunctionFolderLoader.createFunctionNode(id, spInfo);
        CommonUITool.addNodeToTree(treeViewer, folderNode, newNode);
    }
}
Also used : DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) Shell(org.eclipse.swt.widgets.Shell) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) TreeViewer(org.eclipse.jface.viewers.TreeViewer) SPInfo(com.cubrid.cubridmanager.core.cubrid.sp.model.SPInfo) EditFunctionDialog(com.cubrid.common.ui.cubrid.procedure.dialog.EditFunctionDialog) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 9 with ISelectionProvider

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

the class DeleteProcedureAction method run.

public void run() {
    // FIXME logic code move to core module
    Object[] objects = this.getSelectedObj();
    if (objects == null || !isSupported(objects)) {
        this.setEnabled(false);
        return;
    }
    Shell shell = getShell();
    CubridDatabase database = null;
    ISchemaNode node = null;
    if (objects[0] instanceof ISchemaNode && NodeType.STORED_PROCEDURE_PROCEDURE.equals(((ISchemaNode) objects[0]).getType())) {
        node = (ISchemaNode) objects[0];
        database = node.getDatabase();
    }
    if (database == null || node == null) {
        CommonUITool.openErrorBox(shell, Messages.errSelectProcedure);
        return;
    }
    if (!CommonUITool.openConfirmBox(shell, Messages.msgSureDropProcedure)) {
        return;
    }
    CommonSQLExcuterTask task = new CommonSQLExcuterTask(database.getDatabaseInfo());
    String sql = " DROP PROCEDURE " + QuerySyntax.escapeKeyword(node.getName());
    task.addSqls(sql);
    TaskExecutor taskExcutor = new CommonTaskExec(null);
    taskExcutor.addTask(task);
    new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
    if (!taskExcutor.isSuccess()) {
        return;
    }
    ISelectionProvider provider = this.getSelectionProvider();
    ICubridNode parent = node.getParent();
    if (provider instanceof TreeViewer) {
        TreeViewer viewer = (TreeViewer) provider;
        for (int i = 0; objects != null && i < objects.length; i++) {
            parent.removeChild((ISchemaNode) objects[i]);
        }
        viewer.remove(parent, objects);
        viewer.setSelection(new StructuredSelection(parent), true);
    }
}
Also used : CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) TreeViewer(org.eclipse.jface.viewers.TreeViewer) CommonSQLExcuterTask(com.cubrid.cubridmanager.core.common.task.CommonSQLExcuterTask) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) Shell(org.eclipse.swt.widgets.Shell) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 10 with ISelectionProvider

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

the class DropTableAction method run.

/**
	 * @see org.eclipse.jface.action.Action#run()
	 */
public void run() {
    Object[] obj = this.getSelectedObj();
    if (!isSupported(obj)) {
        setEnabled(false);
        return;
    }
    // FIXME move this logic to core module
    int len = obj.length;
    StringBuilder sb = new StringBuilder();
    ISchemaNode table = (ISchemaNode) obj[0];
    String type = table.getType();
    for (int i = 0; i < len && i < 100; i++) {
        table = (DefaultSchemaNode) obj[i];
        if (sb.length() > 0) {
            sb.append(", ");
        }
        sb.append(table.getName());
    }
    if (len > 100) {
        sb.append("...");
    }
    String message = null;
    if (NodeType.USER_TABLE.equals(type) || NodeType.USER_PARTITIONED_TABLE_FOLDER.equals(type)) {
        message = Messages.bind(Messages.dropTable, sb.toString());
    }
    boolean ret = CommonUITool.openConfirmBox(message);
    if (!ret) {
        return;
    }
    String taskName = Messages.bind(Messages.dropTableTaskName, sb.toString());
    TaskExecutor taskExecutor = new CommonTaskExec(taskName);
    DropTableOrViewTask task = new DropTableOrViewTask(table.getDatabase().getDatabaseInfo());
    List<String> tableNameList = new ArrayList<String>();
    for (int i = 0; i < len; i++) {
        table = (DefaultSchemaNode) obj[i];
        tableNameList.add(table.getName());
    }
    String[] tableNames = new String[tableNameList.size()];
    tableNames = tableNameList.toArray(tableNames);
    task.setTableName(tableNames);
    taskExecutor.addTask(task);
    new ExecTaskWithProgress(taskExecutor).exec();
    if (taskExecutor.isSuccess()) {
        // delete table/column descriptions which is dropping table.
        DatabaseInfo dbInfo = table.getDatabase().getDatabaseInfo();
        Connection conn = null;
        try {
            conn = JDBCConnectionManager.getConnection(dbInfo, false);
            IDatabaseSpec dbSpec = table.getDatabase().getDatabaseInfo();
            boolean isSupportTableComment = SchemaCommentHandler.isInstalledMetaTable(dbSpec, conn);
            if (isSupportTableComment) {
                for (int i = 0; i < len; i++) {
                    table = (DefaultSchemaNode) obj[i];
                    SchemaCommentHandler.deleteDescription(dbInfo, conn, table.getName());
                }
            }
        } catch (SQLException e) {
            LOGGER.error(e.getMessage(), e);
        } finally {
            QueryUtil.freeQuery(conn);
        }
        ISelectionProvider provider = this.getSelectionProvider();
        final TreeViewer viewer = (TreeViewer) provider;
        ICubridNode parent = table.getParent();
        table.getDatabase().getDatabaseInfo().removeSchema(table.getName());
        for (int i = 0; i < len; i++) {
            parent.removeChild((ISchemaNode) obj[i]);
            /*Broadcast the view changed*/
            QueryEditorUtil.fireSchemaNodeChanged((ISchemaNode) obj[i]);
        }
        viewer.remove(parent, obj);
        viewer.setSelection(new StructuredSelection(parent), true);
        //refresh user folder count label
        CommonUITool.updateFolderNodeLabelIncludingChildrenCount(viewer, parent);
        /*For bug TOOLS-3118: close opened TableEditorPart about dropped table*/
        IWorkbench workbench = PlatformUI.getWorkbench();
        IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
        for (IEditorReference editorRef : workbenchWindow.getActivePage().getEditorReferences()) {
            IEditorPart editor = editorRef.getEditor(true);
            if (editor.getEditorInput() instanceof TableEditorInput) {
                TableEditorInput input = (TableEditorInput) editor.getEditorInput();
                ISchemaNode tableOfEditor = input.getEditedTableNode();
                for (int i = 0; i < len; i++) {
                    if (tableOfEditor.equals((ISchemaNode) obj[i])) {
                        workbenchWindow.getActivePage().closeEditor(editor, false);
                        break;
                    }
                }
            }
        }
    }
}
Also used : DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) SQLException(java.sql.SQLException) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) TableEditorInput(com.cubrid.common.ui.cubrid.table.editor.TableEditorInput) IEditorReference(org.eclipse.ui.IEditorReference) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) Connection(java.sql.Connection) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) IEditorPart(org.eclipse.ui.IEditorPart) IWorkbench(org.eclipse.ui.IWorkbench) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IDatabaseSpec(com.cubrid.common.core.common.model.IDatabaseSpec) DropTableOrViewTask(com.cubrid.cubridmanager.core.cubrid.table.task.DropTableOrViewTask)

Aggregations

ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)170 ISelection (org.eclipse.jface.viewers.ISelection)61 TreeViewer (org.eclipse.jface.viewers.TreeViewer)40 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)30 ITextSelection (org.eclipse.jface.text.ITextSelection)26 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)25 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)24 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)23 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)21 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)18 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)17 ArrayList (java.util.ArrayList)17 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)15 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)13 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)13 IPostSelectionProvider (org.eclipse.jface.viewers.IPostSelectionProvider)13 IEditorPart (org.eclipse.ui.IEditorPart)13 Shell (org.eclipse.swt.widgets.Shell)12 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)10 IDocument (org.eclipse.jface.text.IDocument)9