Search in sources :

Example 61 with ISelectionProvider

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

the class StopDatabaseAction method run.

public void run() {
    Object[] objArr = this.getSelectedObj();
    if (objArr == null || objArr.length <= 0) {
        setEnabled(false);
        return;
    }
    Set<CubridDatabase> databaseSet = new HashSet<CubridDatabase>();
    for (int i = 0; objArr != null && i < objArr.length; i++) {
        if (!isSupported(objArr[i])) {
            setEnabled(false);
            return;
        }
        ISchemaNode schemaNode = (ISchemaNode) objArr[i];
        CubridDatabase database = schemaNode.getDatabase();
        databaseSet.add(database);
    }
    StringBuffer dbNames = new StringBuffer();
    Iterator<CubridDatabase> it = databaseSet.iterator();
    while (it.hasNext()) {
        CubridDatabase database = it.next();
        dbNames.append(database.getLabel()).append(",");
    }
    dbNames = new StringBuffer(dbNames.substring(0, dbNames.length() - 1));
    boolean isStop = CommonUITool.openConfirmBox(getShell(), Messages.bind(Messages.msgConfirmStopDatabase, dbNames.toString()));
    if (!isStop) {
        return;
    }
    Iterator<CubridDatabase> iter = databaseSet.iterator();
    while (iter.hasNext()) {
        CubridDatabase database = iter.next();
        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.msgStopDbWithJob, dbName));
            databaseSet.remove(database);
            continue;
        }
    }
    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();
                    if (!isSupported(database)) {
                        continue;
                    }
                    monitor.subTask(Messages.bind(Messages.stopDbTaskName, database.getName()));
                    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;
            }
        };
        boolean isContinue = true;
        for (int i = 0; i < dbObjectArr.length; i++) {
            ISchemaNode node = (ISchemaNode) dbObjectArr[i];
            CubridDatabase database = node.getDatabase();
            if (!isSupported(database)) {
                setEnabled(false);
                return;
            }
            if (!LayoutUtil.checkAllQueryEditor(database)) {
                isContinue = false;
                break;
            }
            CommonUpdateTask task = new CommonUpdateTask(CommonTaskName.STOP_DB_TASK_NAME, database.getServer().getServerInfo(), CommonSendMsg.getCommonDatabaseSendMsg());
            task.setDbName(database.getLabel());
            taskExcutor.addTask(task);
        }
        if (!isContinue) {
            return;
        }
        new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
        ActionManager.getInstance().fireSelectionChanged(getSelection());
        for (int i = 0; i < dbObjectArr.length; i++) {
            CubridDatabase database = (CubridDatabase) dbObjectArr[i];
            CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(database, CubridNodeChangedEventType.DATABASE_STOP));
        }
    }
}
Also used : ITask(com.cubrid.common.core.task.ITask) TreeViewer(org.eclipse.jface.viewers.TreeViewer) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) Shell(org.eclipse.swt.widgets.Shell) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) CommonUpdateTask(com.cubrid.cubridmanager.core.common.task.CommonUpdateTask) Job(org.eclipse.core.runtime.jobs.Job) HashSet(java.util.HashSet) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) JobFamily(com.cubrid.common.ui.spi.progress.JobFamily) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) Display(org.eclipse.swt.widgets.Display)

Example 62 with ISelectionProvider

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

the class EditMonitorDashboardAction method run.

/**
	 * Open the selected monitoring dash board
	 */
public void run() {
    Object[] objArr = this.getSelectedObj();
    if (objArr == null || objArr.length <= 0) {
        setEnabled(false);
        return;
    }
    ICubridNode node = (ICubridNode) objArr[0];
    Dashboard dashboard = (Dashboard) node.getAdapter(Dashboard.class);
    if (dashboard == null) {
        return;
    }
    AddDashboardDialog dialog = new AddDashboardDialog(getShell());
    dialog.setDashboard(dashboard);
    int returnCode = dialog.open();
    if (returnCode == IDialogConstants.OK_ID) {
        node.setId(dashboard.getName());
        node.setLabel(dashboard.getName());
        MonitorDashboardPersistManager.getInstance().saveDashboard();
        ISelectionProvider provider = getSelectionProvider();
        if (provider instanceof TreeViewer) {
            TreeViewer treeViewer = (TreeViewer) provider;
            treeViewer.refresh(node, true);
        }
        IEditorPart part = LayoutUtil.getEditorPart(node, node.getEditorId());
        if (part instanceof MonitorDashboardEditor) {
            ((MonitorDashboardEditor) part).changePartName(dashboard.getName());
        }
    } else {
        for (int i = 0; i < dashboard.getHostNodeList().size(); i++) {
            HostNode hostNode = dashboard.getHostNodeList().get(i);
            hostNode.getCopyedHaNodeList().clear();
            hostNode.getCopyedHaNodeList().addAll(hostNode.getDbNodeList());
            hostNode.getCopyedHaNodeList().addAll(hostNode.getBrokerNodeList());
        }
    }
}
Also used : AddDashboardDialog(com.cubrid.cubridmanager.ui.mondashboard.dialog.AddDashboardDialog) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) TreeViewer(org.eclipse.jface.viewers.TreeViewer) HostNode(com.cubrid.cubridmanager.ui.mondashboard.editor.model.HostNode) MonitorDashboardEditor(com.cubrid.cubridmanager.ui.mondashboard.editor.MonitorDashboardEditor) Dashboard(com.cubrid.cubridmanager.ui.mondashboard.editor.model.Dashboard) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) IEditorPart(org.eclipse.ui.IEditorPart)

Example 63 with ISelectionProvider

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

the class AddMonitorDashboardAction method run.

/**
	 * Open the dialog
	 */
public void run() {
    AddDashboardDialog dialog = new AddDashboardDialog(getShell());
    int returnCode = dialog.open();
    if (returnCode == IDialogConstants.OK_ID) {
        Dashboard dashboard = dialog.getDashboard();
        DefaultCubridNode dashboardNode = new DefaultCubridNode(dashboard.getName(), dashboard.getName(), "icons/navigator/status_item.png");
        dashboardNode.setType(CubridNodeType.MONITOR_DASHBOARD);
        dashboardNode.setEditorId(MonitorDashboardEditor.ID);
        dashboardNode.setModelObj(dashboard);
        MonitorDashboardPersistManager.getInstance().addMonitorDashboard(dashboardNode);
        ISelectionProvider provider = getSelectionProvider();
        if (provider instanceof TreeViewer) {
            TreeViewer treeViewer = (TreeViewer) provider;
            /*TOOLS-3665 Refresh the input of TreeViewer*/
            treeViewer.setInput(CubridMonitorNavigatorView.getTreeViewerInput());
            CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(dashboardNode, CubridNodeChangedEventType.NODE_ADD));
            LayoutManager.getInstance().getWorkbenchContrItem().openEditorOrView(dashboardNode);
        }
    }
}
Also used : DefaultCubridNode(com.cubrid.common.ui.spi.model.DefaultCubridNode) AddDashboardDialog(com.cubrid.cubridmanager.ui.mondashboard.dialog.AddDashboardDialog) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Dashboard(com.cubrid.cubridmanager.ui.mondashboard.editor.model.Dashboard) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)

Example 64 with ISelectionProvider

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

the class RefreshAction method run.

/**
	 * Reload the selected CUBRID node
	 */
public void run() {
    final Object[] obj = this.getSelectedObj();
    if (obj == null || obj.length == 0 || !isSupported(obj[0])) {
        return;
    }
    ICubridNode cubridNode = (ICubridNode) obj[0];
    if (cubridNode == null) {
        return;
    }
    String nodeType = cubridNode.getType();
    if (NodeType.USER_TABLE.equals(nodeType) || NodeType.SYSTEM_TABLE.equals(nodeType) || NodeType.USER_PARTITIONED_TABLE_FOLDER.equals(nodeType) || NodeType.USER_PARTITIONED_TABLE.equals(nodeType) || NodeType.SYSTEM_VIEW.equals(nodeType) || NodeType.USER_VIEW.equals(nodeType)) {
        ISchemaNode schemaNode = (ISchemaNode) cubridNode;
        schemaNode.getDatabase().getDatabaseInfo().removeSchema(cubridNode.getLabel());
    }
    LayoutManager.getInstance().getWorkbenchContrItem().reopenEditorOrView(cubridNode);
    ISelectionProvider provider = this.getSelectionProvider();
    if ((provider instanceof TreeViewer) && cubridNode != null && cubridNode.isContainer()) {
        TreeViewer viewer = (TreeViewer) provider;
        CommonUITool.refreshNavigatorTree(viewer, cubridNode);
    }
}
Also used : ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode)

Example 65 with ISelectionProvider

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

the class ChangeShardAction method run.

/**
	 * Reload the selected CUBRID node
	 */
public void run() {
    final Object[] obj = this.getSelectedObj();
    if (obj == null || obj.length == 0 || !isSupported(obj[0])) {
        return;
    }
    ICubridNode cubridNode = (ICubridNode) obj[0];
    if (cubridNode == null) {
        return;
    }
    String nodeType = cubridNode.getType();
    if (!NodeType.DATABASE.equals(nodeType)) {
        return;
    }
    ISchemaNode schemaNode = (ISchemaNode) cubridNode;
    DatabaseInfo dbInfo = schemaNode.getDatabase().getDatabaseInfo();
    if (!dbInfo.isShard()) {
        return;
    }
    ShardIdSelectionDialog dialog = new ShardIdSelectionDialog(getShell());
    dialog.setDatabaseInfo(dbInfo);
    dialog.setShardId(dbInfo.getCurrentShardId());
    dialog.setShardVal(dbInfo.getCurrentShardVal());
    dialog.setShardQueryType(dbInfo.getShardQueryType());
    if (dialog.open() != IDialogConstants.OK_ID) {
        return;
    }
    int shardId = dialog.getShardId();
    int shardVal = dialog.getShardVal();
    int shardQueryType = dialog.getShardQueryType();
    dbInfo.setCurrentShardId(shardId);
    dbInfo.setCurrentShardVal(shardVal);
    dbInfo.setShardQueryType(shardQueryType);
    ISelectionProvider provider = this.getSelectionProvider();
    if ((provider instanceof TreeViewer) && cubridNode != null && cubridNode.isContainer()) {
        TreeViewer viewer = (TreeViewer) provider;
        CommonUITool.refreshNavigatorTree(viewer, cubridNode);
    }
}
Also used : ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ShardIdSelectionDialog(com.cubrid.common.ui.common.dialog.ShardIdSelectionDialog) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode)

Aggregations

ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)83 TreeViewer (org.eclipse.jface.viewers.TreeViewer)40 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)25 ISelection (org.eclipse.jface.viewers.ISelection)24 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 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)15 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)13 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)13 ITextSelection (org.eclipse.jface.text.ITextSelection)12 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)12 ArrayList (java.util.ArrayList)10 Shell (org.eclipse.swt.widgets.Shell)10 CommonTaskExec (com.cubrid.common.ui.spi.progress.CommonTaskExec)8 IEditorPart (org.eclipse.ui.IEditorPart)8 HashSet (java.util.HashSet)6 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 StyledText (org.eclipse.swt.custom.StyledText)6 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)6