use of org.eclipse.jface.viewers.ISelectionProvider 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 org.eclipse.jface.viewers.ISelectionProvider in project cubrid-manager by CUBRID.
the class EditTableAction method run.
public void run() {
Object[] obj = this.getSelectedObj();
if (!isSupported(obj)) {
setEnabled(false);
return;
}
ISelectionProvider provider = getSelectionProvider();
if (!(provider instanceof TreeViewer)) {
return;
}
ISchemaNode tableNode = (ISchemaNode) obj[0];
doRun(tableNode, MODE_TABLE_EDIT);
}
use of org.eclipse.jface.viewers.ISelectionProvider in project cubrid-manager by CUBRID.
the class SchemaInfoEditorPart method createContextMenu.
/**
*
* Create the context menu
*
* @param control Control
*/
private void createContextMenu(final Control control) {
MenuManager contextMenuManager = new MenuManager();
contextMenuManager.setRemoveAllWhenShown(true);
contextMenuManager.addMenuListener(new IMenuListener() {
public void menuAboutToShow(IMenuManager manager) {
ISelectionProvider provider = ActionManager.getInstance().getSelectionProvider();
if (!(provider instanceof TreeViewer)) {
return;
}
TreeViewer viewer = (TreeViewer) provider;
viewer.setSelection(new StructuredSelection(schemaNode), true);
viewer.getTree().setFocus();
MenuProvider menuProvider = new MenuProvider();
String type = schemaNode.getType();
if (NodeType.SYSTEM_TABLE.equals(type)) {
menuProvider.buildSystemTableMenu(manager);
} else if (NodeType.SYSTEM_VIEW.equals(type)) {
menuProvider.buildSystemViewMenu(manager);
} else if (NodeType.USER_PARTITIONED_TABLE_FOLDER.equals(type)) {
menuProvider.buildUserTableMenu(manager, schemaNode);
} else if (NodeType.USER_PARTITIONED_TABLE.equals(type)) {
menuProvider.buildPartitionedTableMenu(manager);
} else if (NodeType.USER_TABLE.equals(type)) {
menuProvider.buildUserTableMenu(manager, schemaNode);
} else if (NodeType.USER_VIEW.equals(type)) {
menuProvider.buildUserViewMenu(manager);
}
manager.remove(ShowSchemaEditorAction.ID);
}
});
Menu contextMenu = contextMenuManager.createContextMenu(control);
control.setMenu(contextMenu);
}
use of org.eclipse.jface.viewers.ISelectionProvider in project cubrid-manager by CUBRID.
the class CreateDatabaseAction method run.
public void run() {
Object[] obj = this.getSelectedObj();
if (obj != null && obj.length > 0) {
if (!isSupported(obj[0])) {
this.setEnabled(false);
return;
}
node = (ICubridNode) obj[0];
server = node.getServer();
ISelectionProvider provider = this.getSelectionProvider();
viewer = (TreeViewer) provider;
}
String serverNameKey = node.getServer().getId() + ICubridNodeLoader.NODE_SEPARATOR + CubridServerLoader.DATABASE_FOLDER_ID;
ICubridNode cubridServer = node.getServer().getChild(serverNameKey);
CMWizardDialog dialog = new CMWizardDialog(getShell(), new CreateDatabaseWizard(server, viewer, cubridServer));
dialog.setPageSize(580, 420);
dialog.open();
}
use of org.eclipse.jface.viewers.ISelectionProvider in project cubrid-manager by CUBRID.
the class DeleteDatabaseAction method run.
public void run() {
Object[] obj = this.getSelectedObj();
if (!isSupported(obj[0])) {
setEnabled(false);
return;
}
ISelectionProvider provider = this.getSelectionProvider();
if (!(provider instanceof TreeViewer)) {
return;
}
ISchemaNode node = (ISchemaNode) obj[0];
CubridDatabase database = node.getDatabase();
if (database == null) {
CommonUITool.openErrorBox(getShell(), Messages.msgSelectDB);
return;
}
CommonQueryTask<DbSpaceInfoList> task = new CommonQueryTask<DbSpaceInfoList>(database.getServer().getServerInfo(), CommonSendMsg.getCommonDatabaseSendMsg(), new DbSpaceInfoList());
task.setDbName(database.getName());
TaskExecutor taskExcutor = new CommonTaskExec(Messages.getDbSpaceInfoTaskName);
taskExcutor.addTask(task);
new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
if (!taskExcutor.isSuccess()) {
return;
}
DeleteDatabaseDialog dlg = new DeleteDatabaseDialog(getShell());
dlg.setDbSpaceInfo(task.getResultModel());
dlg.setDatabase(database);
ICubridNode parent = database.getParent();
if (dlg.open() == DeleteDatabaseDialog.DELETE_ID) {
boolean isContinue = DatabaseUtils.processDatabaseDeleted(database);
if (isContinue) {
TreeViewer viewer = (TreeViewer) provider;
parent.removeChild(database);
viewer.remove(parent, obj);
viewer.setSelection(new StructuredSelection(parent));
}
}
}
Aggregations