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;
}
}
}
}
}
}
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);
}
}
Aggregations