Search in sources :

Example 1 with ISchemaNode

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

the class EditProcedureAction method run.

/**
	 * Open the EditProcedureDialog and edit procedure
	 */
public void run() {
    // FIXME logic code move to core module
    Object[] objArr = this.getSelectedObj();
    if (!isSupported(objArr)) {
        this.setEnabled(false);
        return;
    }
    Shell shell = getShell();
    CubridDatabase database = null;
    ISchemaNode node = null;
    if (objArr[0] instanceof ISchemaNode && NodeType.STORED_PROCEDURE_PROCEDURE.equals(((ISchemaNode) objArr[0]).getType())) {
        node = (ISchemaNode) objArr[0];
        database = node.getDatabase();
    }
    if (database == null || node == null) {
        CommonUITool.openErrorBox(shell, Messages.errSelectProcedure);
        return;
    }
    final GetSPInfoListTask task = new GetSPInfoListTask(database.getDatabaseInfo());
    task.setSpName(node.getName());
    TaskExecutor taskExcutor = new CommonTaskExec(null);
    taskExcutor.addTask(task);
    new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
    if (!taskExcutor.isSuccess()) {
        return;
    }
    List<SPInfo> list = task.getSPInfoList();
    if (list.size() > 1) {
        CommonUITool.openErrorBox(shell, Messages.errDuplicateName);
        return;
    }
    if (list.isEmpty()) {
        CommonUITool.openErrorBox(shell, Messages.errNotExistName);
        return;
    }
    EditProcedureDialog dlg = new EditProcedureDialog(shell);
    dlg.setDatabase(database);
    dlg.setNewFlag(false);
    dlg.setSpInfo(list.get(0));
    if (dlg.open() == IDialogConstants.OK_ID) {
        ActionManager.getInstance().fireSelectionChanged(getSelection());
    }
}
Also used : CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) EditProcedureDialog(com.cubrid.common.ui.cubrid.procedure.dialog.EditProcedureDialog) Shell(org.eclipse.swt.widgets.Shell) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) SPInfo(com.cubrid.cubridmanager.core.cubrid.sp.model.SPInfo) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) GetSPInfoListTask(com.cubrid.cubridmanager.core.cubrid.sp.task.GetSPInfoListTask)

Example 2 with ISchemaNode

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

the class DeleteSerialAction method run.

/**
	 * Delete the selected serials
	 */
public void run(ISchemaNode[] nodeArray) {
    if (nodeArray == null) {
        LOGGER.error("The nodeArray parameter is a null.");
        return;
    }
    final List<String> serialNameList = new ArrayList<String>();
    final StringBuffer serialNames = new StringBuffer();
    for (int i = 0; nodeArray != null && i < nodeArray.length; i++) {
        if (!isSupported(nodeArray[i])) {
            setEnabled(false);
            return;
        }
        ISchemaNode schemaNode = (ISchemaNode) nodeArray[i];
        if (i == 0) {
            serialNames.append(schemaNode.getLabel());
        }
        serialNameList.add(schemaNode.getLabel());
    }
    if (nodeArray.length > 1) {
        serialNames.append(", ...");
    }
    String cfmMsg = Messages.bind(Messages.msgConfirmDelSerial, serialNames.toString(), nodeArray.length);
    boolean isDelete = CommonUITool.openConfirmBox(getShell(), cfmMsg);
    if (!isDelete) {
        return;
    }
    final Shell shell = getShell();
    TaskExecutor taskExcutor = new TaskExecutor() {

        public boolean exec(final IProgressMonitor monitor) {
            if (monitor.isCanceled()) {
                return false;
            }
            String taskName = Messages.bind(Messages.delSerialTaskName, serialNames.toString());
            monitor.beginTask(taskName, IProgressMonitor.UNKNOWN);
            for (ITask task : taskList) {
                if (task instanceof DeleteSerialTask) {
                    DeleteSerialTask deleteSerialTask = (DeleteSerialTask) task;
                    String[] serialNames = new String[serialNameList.size()];
                    deleteSerialTask.deleteSerial(serialNameList.toArray(serialNames));
                }
                final String msg = task.getErrorMsg();
                if (openErrorBox(shell, msg, monitor)) {
                    return false;
                }
                if (monitor.isCanceled()) {
                    return false;
                }
            }
            return true;
        }
    };
    ISchemaNode schemaNode = (ISchemaNode) nodeArray[0];
    CubridDatabase database = schemaNode.getDatabase();
    DatabaseInfo databaseInfo = database.getDatabaseInfo();
    DeleteSerialTask deleteSerialTask = new DeleteSerialTask(databaseInfo);
    taskExcutor.addTask(deleteSerialTask);
    new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
    if (!taskExcutor.isSuccess()) {
        return;
    }
    ISelectionProvider provider = this.getSelectionProvider();
    ICubridNode parent = schemaNode.getParent();
    if (provider instanceof TreeViewer) {
        TreeViewer viewer = (TreeViewer) provider;
        for (int i = 0; nodeArray != null && i < nodeArray.length; i++) {
            parent.removeChild((ICubridNode) nodeArray[i]);
        }
        viewer.remove(parent, nodeArray);
        viewer.setSelection(new StructuredSelection(parent), true);
        CommonUITool.updateFolderNodeLabelIncludingChildrenCount(viewer, parent);
    }
}
Also used : ITask(com.cubrid.common.core.task.ITask) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) DeleteSerialTask(com.cubrid.cubridmanager.core.cubrid.serial.task.DeleteSerialTask) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) 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) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 3 with ISchemaNode

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

the class RunSQLFileDialog method addDatabase.

public void addDatabase(Object[] selectedNodes) {
    List<CubridDatabase> dbList = new ArrayList<CubridDatabase>();
    for (CubridDatabase db : cubridDatabases) {
        dbList.add(db);
    }
    for (Object o : selectedNodes) {
        if (!(o instanceof ISchemaNode)) {
            continue;
        }
        ICubridNode node = (ICubridNode) o;
        if (node.getType() != NodeType.DATABASE) {
            continue;
        }
        CubridDatabase database = ((ISchemaNode) o).getDatabase();
        if (!dbList.contains(database)) {
            dbList.add(database);
        }
    }
    cubridDatabases = dbList.toArray(new CubridDatabase[dbList.size()]);
    databaseTableViewer.setInput(cubridDatabases);
}
Also used : ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) ArrayList(java.util.ArrayList) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 4 with ISchemaNode

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

the class DropTriggerAction method run.

public void run(ISchemaNode[] nodeArray) {
    // FIXME move this logic to core module
    if (nodeArray == null) {
        LOGGER.error("The nodeArray is a null.");
        return;
    }
    List<String> triggerNameList = new ArrayList<String>();
    StringBuffer bf = new StringBuffer();
    for (int i = 0; nodeArray != null && i < nodeArray.length; i++) {
        DefaultSchemaNode trigger = (DefaultSchemaNode) nodeArray[i];
        triggerNameList.add(trigger.getName());
        if (i == 0) {
            bf.append(trigger.getName());
        }
    }
    if (nodeArray.length > 1) {
        bf.append(", ...");
    }
    String cfmMsg = Messages.bind(Messages.dropTriggerWarnMSG1, nodeArray.length, bf.toString());
    boolean ret = CommonUITool.openConfirmBox(cfmMsg);
    if (!ret) {
        return;
    }
    ISchemaNode triggerNode = (ISchemaNode) nodeArray[0];
    CommonSQLExcuterTask task = new CommonSQLExcuterTask(triggerNode.getDatabase().getDatabaseInfo());
    for (String triggerName : triggerNameList) {
        String sql = "DROP TRIGGER " + QuerySyntax.escapeKeyword(triggerName);
        task.addSqls(sql);
    }
    String taskName = Messages.bind(Messages.dropTriggerTaskName, bf.toString());
    TaskExecutor taskExecutor = new CommonTaskExec(taskName);
    taskExecutor.addTask(task);
    new ExecTaskWithProgress(taskExecutor).busyCursorWhile();
    if (!taskExecutor.isSuccess()) {
        return;
    }
    String title = com.cubrid.common.ui.common.Messages.titleSuccess;
    String msg = Messages.dropTriggerSuccessMsg;
    CommonUITool.openInformationBox(title, msg);
    ISelectionProvider provider = this.getSelectionProvider();
    ICubridNode parent = triggerNode.getParent();
    if (provider instanceof TreeViewer) {
        TreeViewer viewer = (TreeViewer) provider;
        for (int i = 0; nodeArray != null && i < nodeArray.length; i++) {
            parent.removeChild((ISchemaNode) nodeArray[i]);
        }
        viewer.remove(parent, nodeArray);
        viewer.setSelection(new StructuredSelection(parent), true);
        CommonUITool.updateFolderNodeLabelIncludingChildrenCount(viewer, parent);
    }
}
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) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) DefaultSchemaNode(com.cubrid.common.ui.spi.model.DefaultSchemaNode) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)

Example 5 with ISchemaNode

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

the class TriggerDashboardEditorPart method editTrigger.

/**
	 * editTrigger
	 */
public void editTrigger() {
    TableItem[] items = triggersDetailInfoTable.getTable().getSelection();
    if (items.length != 0) {
        TableItem item = items[0];
        Trigger trigger = (Trigger) item.getData();
        Set<String> typeSet = new HashSet<String>();
        typeSet.add(NodeType.TRIGGER);
        ICubridNode triggerNode = CommonUITool.findNode(database, typeSet, trigger.getName());
        if (triggerNode != null) {
            AlterTriggerAction action = (AlterTriggerAction) ActionManager.getInstance().getAction(AlterTriggerAction.ID);
            if (action.run(database, (ISchemaNode) triggerNode) == IDialogConstants.OK_ID) {
                refresh();
            }
        }
    } else {
        CommonUITool.openWarningBox(Messages.errTriggerNoSelection);
    }
}
Also used : Trigger(com.cubrid.common.core.common.model.Trigger) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) TableItem(org.eclipse.swt.widgets.TableItem) AlterTriggerAction(com.cubrid.common.ui.cubrid.trigger.action.AlterTriggerAction) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) HashSet(java.util.HashSet)

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