Search in sources :

Example 1 with EditFunctionDialog

use of com.cubrid.common.ui.cubrid.procedure.dialog.EditFunctionDialog 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 2 with EditFunctionDialog

use of com.cubrid.common.ui.cubrid.procedure.dialog.EditFunctionDialog in project cubrid-manager by CUBRID.

the class EditFunctionAction method run.

/**
	 * Open the EditFunctionDialog and edit function
	 */
public void run() {
    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_FUNCTION.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(getText());
    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;
    }
    EditFunctionDialog dlg = new EditFunctionDialog(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) 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) EditFunctionDialog(com.cubrid.common.ui.cubrid.procedure.dialog.EditFunctionDialog) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) GetSPInfoListTask(com.cubrid.cubridmanager.core.cubrid.sp.task.GetSPInfoListTask)

Aggregations

EditFunctionDialog (com.cubrid.common.ui.cubrid.procedure.dialog.EditFunctionDialog)2 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)2 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)2 SPInfo (com.cubrid.cubridmanager.core.cubrid.sp.model.SPInfo)2 Shell (org.eclipse.swt.widgets.Shell)2 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)1 CommonTaskExec (com.cubrid.common.ui.spi.progress.CommonTaskExec)1 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)1 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)1 GetSPInfoListTask (com.cubrid.cubridmanager.core.cubrid.sp.task.GetSPInfoListTask)1 DbUserInfo (com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo)1 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)1 TreeViewer (org.eclipse.jface.viewers.TreeViewer)1