Search in sources :

Example 1 with CreateOrEditSerialDialog

use of com.cubrid.common.ui.cubrid.serial.dialog.CreateOrEditSerialDialog in project cubrid-manager by CUBRID.

the class EditSerialAction method run.

/**
	 * Open the editSerial dialog and edit serial
	 */
public int run(CubridDatabase database, final ISchemaNode node) {
    final Shell shell = getShell();
    TaskExecutor taskExcutor = new TaskExecutor() {

        public boolean exec(final IProgressMonitor monitor) {
            if (monitor.isCanceled()) {
                return false;
            }
            monitor.beginTask(Messages.loadSerialTaskName, IProgressMonitor.UNKNOWN);
            for (ITask task : taskList) {
                SerialInfo serialInfo = null;
                if (task instanceof GetSerialInfoTask) {
                    GetSerialInfoTask getSerialInfoTask = (GetSerialInfoTask) task;
                    serialInfo = getSerialInfoTask.getSerialInfo(node.getLabel());
                }
                final String msg = task.getErrorMsg();
                if (openErrorBox(shell, msg, monitor)) {
                    return false;
                }
                if (monitor.isCanceled()) {
                    return false;
                }
                if (serialInfo == null) {
                    openErrorBox(shell, Messages.errNameNotExist, monitor);
                    return false;
                }
                node.setModelObj(serialInfo);
            }
            return true;
        }
    };
    DatabaseInfo databaseInfo = database.getDatabaseInfo();
    GetSerialInfoTask task = new GetSerialInfoTask(databaseInfo);
    taskExcutor.addTask(task);
    new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
    if (!taskExcutor.isSuccess()) {
        return IDialogConstants.CANCEL_ID;
    }
    boolean isEditorAble = ActionSupportUtil.isSupportSinSelCheckDbUser(node, NodeType.SERIAL);
    CreateOrEditSerialDialog dialog = new CreateOrEditSerialDialog(getShell(), isEditorAble);
    dialog.setEditedNode(node);
    dialog.setDatabase(database);
    if (dialog.open() == IDialogConstants.OK_ID) {
        CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(node, CubridNodeChangedEventType.NODE_REFRESH));
        ActionManager.getInstance().fireSelectionChanged(getSelection());
        return IDialogConstants.OK_ID;
    }
    return IDialogConstants.CANCEL_ID;
}
Also used : CreateOrEditSerialDialog(com.cubrid.common.ui.cubrid.serial.dialog.CreateOrEditSerialDialog) Shell(org.eclipse.swt.widgets.Shell) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ITask(com.cubrid.common.core.task.ITask) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) SerialInfo(com.cubrid.common.core.common.model.SerialInfo) GetSerialInfoTask(com.cubrid.cubridmanager.core.cubrid.serial.task.GetSerialInfoTask)

Example 2 with CreateOrEditSerialDialog

use of com.cubrid.common.ui.cubrid.serial.dialog.CreateOrEditSerialDialog in project cubrid-manager by CUBRID.

the class CreateSerialAction method run.

/**
	 * run create serial
	 * @param database
	 */
public void run(CubridDatabase database) {
    CreateOrEditSerialDialog dialog = new CreateOrEditSerialDialog(getShell(), true);
    dialog.setDatabase(database);
    ISelectionProvider provider = getSelectionProvider();
    if (dialog.open() == IDialogConstants.OK_ID && (provider instanceof TreeViewer)) {
        TreeViewer treeViewer = (TreeViewer) provider;
        ICubridNode folderNode = database.getChild(database.getId() + ICubridNodeLoader.NODE_SEPARATOR + CubridSerialFolderLoader.SERIAL_FOLDER_ID);
        if (folderNode == null || !folderNode.getLoader().isLoaded()) {
            return;
        }
        // FIXME move this logic to core module
        String serialName = dialog.getSerialName().toLowerCase(Locale.getDefault());
        DbUserInfo userInfo = database.getDatabaseInfo().getAuthLoginedDbUserInfo();
        String id = folderNode.getId() + ICubridNodeLoader.NODE_SEPARATOR + serialName;
        SerialInfo serialInfo = new SerialInfo();
        serialInfo.setName(serialName);
        serialInfo.setOwner(userInfo.getName());
        ICubridNode newNode = CubridSerialFolderLoader.createSerialNode(id, serialInfo);
        CommonUITool.addNodeToTree(treeViewer, folderNode, newNode);
        CommonUITool.updateFolderNodeLabelIncludingChildrenCount(treeViewer, folderNode);
        CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(newNode, CubridNodeChangedEventType.NODE_ADD));
    }
}
Also used : CreateOrEditSerialDialog(com.cubrid.common.ui.cubrid.serial.dialog.CreateOrEditSerialDialog) DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) 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) SerialInfo(com.cubrid.common.core.common.model.SerialInfo)

Aggregations

SerialInfo (com.cubrid.common.core.common.model.SerialInfo)2 CreateOrEditSerialDialog (com.cubrid.common.ui.cubrid.serial.dialog.CreateOrEditSerialDialog)2 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)2 ITask (com.cubrid.common.core.task.ITask)1 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)1 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)1 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)1 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)1 GetSerialInfoTask (com.cubrid.cubridmanager.core.cubrid.serial.task.GetSerialInfoTask)1 DbUserInfo (com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)1 TreeViewer (org.eclipse.jface.viewers.TreeViewer)1 Shell (org.eclipse.swt.widgets.Shell)1