Search in sources :

Example 1 with RenameTableDialog

use of com.cubrid.common.ui.cubrid.table.dialog.RenameTableDialog in project cubrid-manager by CUBRID.

the class RenameTableAction method doRun.

/**
	 * Perform rename Table
	 * 
	 * @param cubridDatabase
	 * @param table
	 */
private void doRun(CubridDatabase cubridDatabase, ISchemaNode table) {
    boolean isTable = false;
    String type = table.getType();
    if (NodeType.USER_TABLE.equals(type) || NodeType.USER_PARTITIONED_TABLE_FOLDER.equals(type)) {
        isTable = true;
    } else if (NodeType.USER_VIEW.equals(type)) {
        isTable = false;
    }
    String tableName = table.getName();
    CubridDatabase db = table.getDatabase();
    DatabaseInfo dbInfo = db.getDatabaseInfo();
    GetTablesTask getTableTask = new GetTablesTask(dbInfo);
    List<String> tableList = getTableTask.getAllTableAndViews();
    RenameTableDialog dlg = new RenameTableDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), tableName, isTable, tableList, true);
    int ret = dlg.open();
    if (ret == IDialogConstants.OK_ID) {
        String newName = dlg.getNewName();
        RenameTableOrViewTask task = new RenameTableOrViewTask(dbInfo);
        task.setOldClassName(tableName);
        task.setNewClassName(newName);
        task.setTable(isTable);
        String taskName = Messages.bind(com.cubrid.common.ui.cubrid.table.Messages.renameTableTaskName, new String[] { tableName, newName });
        TaskExecutor taskExecutor = new CommonTaskExec(taskName);
        taskExecutor.addTask(task);
        new ExecTaskWithProgress(taskExecutor).exec();
        if (taskExecutor.isSuccess()) {
            ISelectionProvider provider = this.getSelectionProvider();
            final TreeViewer viewer = (TreeViewer) provider;
            //remove the old table schema information
            table.getDatabase().getDatabaseInfo().removeSchema(tableName);
            DefaultSchemaNode cloneTable = null;
            try {
                cloneTable = ((DefaultSchemaNode) table).clone();
                CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(cloneTable, CubridNodeChangedEventType.NODE_REMOVE));
            } catch (CloneNotSupportedException ex) {
                LOGGER.error(ex.getMessage());
            }
            ClassInfo classInfo = (ClassInfo) table.getAdapter(ClassInfo.class);
            classInfo.setClassName(newName);
            table.setId(table.getParent().getId() + ICubridNodeLoader.NODE_SEPARATOR + newName);
            table.setLabel(newName);
            viewer.refresh(table, true);
            LayoutManager.getInstance().getWorkbenchContrItem().reopenEditorOrView(table);
            CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(table, CubridNodeChangedEventType.NODE_ADD));
            ActionManager.getInstance().fireSelectionChanged(getSelection());
            /*Broadcast the view changed*/
            QueryEditorUtil.fireSchemaNodeChanged(table);
            /*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();
                    if (tableOfEditor.equals(table)) {
                        workbenchWindow.getActivePage().closeEditor(editor, false);
                        break;
                    }
                }
            }
        }
    }
}
Also used : CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) TreeViewer(org.eclipse.jface.viewers.TreeViewer) TableEditorInput(com.cubrid.common.ui.cubrid.table.editor.TableEditorInput) RenameTableOrViewTask(com.cubrid.cubridmanager.core.cubrid.table.task.RenameTableOrViewTask) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) IEditorPart(org.eclipse.ui.IEditorPart) DefaultSchemaNode(com.cubrid.common.ui.spi.model.DefaultSchemaNode) IWorkbench(org.eclipse.ui.IWorkbench) RenameTableDialog(com.cubrid.common.ui.cubrid.table.dialog.RenameTableDialog) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IEditorReference(org.eclipse.ui.IEditorReference) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) GetTablesTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetTablesTask) ClassInfo(com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo)

Example 2 with RenameTableDialog

use of com.cubrid.common.ui.cubrid.table.dialog.RenameTableDialog in project cubrid-manager by CUBRID.

the class ModifyTableNameAction method run.

@Override
public void run() {
    PropertyChangeProvider node = getSelectedNode();
    boolean isPhysicModel = getERSchema().isPhysicModel();
    String oldName = ((ERTable) node).getShownName();
    Set<String> names = getERSchema().getAllShownTableNames();
    names.remove(oldName);
    RenameTableDialog dlg = new RenameTableDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), oldName, true, new ArrayList<String>(names), isPhysicModel);
    int ret = dlg.open();
    if (ret == IDialogConstants.OK_ID) {
        String newName = dlg.getNewName();
        if (StringUtil.isEqual(oldName, newName)) {
            return;
        }
        getERSchema().modifyTableNameAndFire(oldName, newName, isPhysicModel);
    }
}
Also used : PropertyChangeProvider(com.cubrid.common.ui.er.model.PropertyChangeProvider) RenameTableDialog(com.cubrid.common.ui.cubrid.table.dialog.RenameTableDialog) ERTable(com.cubrid.common.ui.er.model.ERTable)

Aggregations

RenameTableDialog (com.cubrid.common.ui.cubrid.table.dialog.RenameTableDialog)2 TableEditorInput (com.cubrid.common.ui.cubrid.table.editor.TableEditorInput)1 ERTable (com.cubrid.common.ui.er.model.ERTable)1 PropertyChangeProvider (com.cubrid.common.ui.er.model.PropertyChangeProvider)1 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)1 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)1 DefaultSchemaNode (com.cubrid.common.ui.spi.model.DefaultSchemaNode)1 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)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 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)1 ClassInfo (com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo)1 GetTablesTask (com.cubrid.cubridmanager.core.cubrid.table.task.GetTablesTask)1 RenameTableOrViewTask (com.cubrid.cubridmanager.core.cubrid.table.task.RenameTableOrViewTask)1 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)1 TreeViewer (org.eclipse.jface.viewers.TreeViewer)1 IEditorPart (org.eclipse.ui.IEditorPart)1 IEditorReference (org.eclipse.ui.IEditorReference)1 IWorkbench (org.eclipse.ui.IWorkbench)1