use of org.eclipse.jface.viewers.TreeViewer 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.TreeViewer 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.TreeViewer 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.TreeViewer in project cubrid-manager by CUBRID.
the class TableEditorPart method completeAll.
public void completeAll() {
CommonUITool.openInformationBox(Messages.titleSuccess, Messages.bind(Messages.msgNull2DefComplete, jobName));
if (this.isNewTableFlag) {
ICubridNode node = database.getChild(database.getId() + ICubridNodeLoader.NODE_SEPARATOR + CubridTablesFolderLoader.TABLES_FOLDER_ID);
if (node == null || !node.getLoader().isLoaded()) {
return;
}
String id = node.getId() + ICubridNodeLoader.NODE_SEPARATOR + tableName;
boolean isPartition = newSchemaInfo.getPartitionList() != null && newSchemaInfo.getPartitionList().size() > 0;
ClassInfo newClassInfo = new ClassInfo(tableName, owner, ClassType.NORMAL, false, isPartition);
ICubridNode newNode = CubridTablesFolderLoader.createUserTableNode(node, id, newClassInfo, node.getLoader().getLevel(), new NullProgressMonitor());
if (CubridNavigatorView.findNavigationView() == null) {
getSite().getWorkbenchWindow().getActivePage().closeEditor(editor, false);
return;
}
TreeViewer treeViewer = CubridNavigatorView.findNavigationView().getViewer();
if (treeViewer == null || treeViewer.getTree() == null || treeViewer.getTree().isDisposed()) {
getSite().getWorkbenchWindow().getActivePage().closeEditor(editor, false);
return;
}
CommonUITool.addNodeToTree(treeViewer, node, newNode);
// refresh table folder count label
CommonUITool.updateFolderNodeLabelIncludingChildrenCount(treeViewer, node);
CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(newNode, CubridNodeChangedEventType.NODE_ADD));
} else {
if (database == null) {
return;
}
database.getDatabaseInfo().removeSchema(tableName);
if (oldPartitionInfoList.isEmpty() && !partitionInfoList.isEmpty()) {
editedTableNode.setIconPath("icons/navigator/schema_table_partition.png");
editedTableNode.setType(NodeType.USER_PARTITIONED_TABLE_FOLDER);
editedTableNode.setLoader(new CubridPartitionedTableLoader());
} else if (!oldPartitionInfoList.isEmpty() && partitionInfoList.isEmpty()) {
editedTableNode.setIconPath("icons/navigator/schema_table_item.png");
editedTableNode.setType(NodeType.USER_TABLE);
editedTableNode.setLoader(new CubridUserTableLoader());
}
TreeViewer treeViewer = CubridNavigatorView.findNavigationView().getViewer();
if (treeViewer == null || treeViewer.getTree() == null || treeViewer.getTree().isDisposed()) {
getSite().getWorkbenchWindow().getActivePage().closeEditor(editor, false);
return;
}
CommonUITool.refreshNavigatorTree(treeViewer, editedTableNode);
CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(editedTableNode, CubridNodeChangedEventType.NODE_REFRESH));
/* Broadcast the view changed */
QueryEditorUtil.fireSchemaNodeChanged(editedTableNode);
}
getSite().getWorkbenchWindow().getActivePage().closeEditor(editor, false);
}
use of org.eclipse.jface.viewers.TreeViewer in project cubrid-manager by CUBRID.
the class StartDatabaseAction method doRun.
public void doRun(ISchemaNode[] schemaArray) {
if (schemaArray == null || schemaArray.length == 0) {
return;
}
List<ISchemaNode> startList = new ArrayList<ISchemaNode>();
/*Judge start job is running*/
for (ISchemaNode node : schemaArray) {
if (!isSupported(node)) {
setEnabled(false);
return;
}
CubridDatabase database = node.getDatabase();
final JobFamily jobFamily = new JobFamily();
String serverName = database.getServer().getName();
String dbName = database.getName();
jobFamily.setServerName(serverName);
jobFamily.setDbName(dbName);
Job[] jobs = Job.getJobManager().find(jobFamily);
if (jobs.length > 0) {
CommonUITool.openWarningBox(Messages.bind(Messages.msgStartDbWithJob, dbName));
continue;
}
startList.add(database);
}
CubridNavigatorView navigationView = CubridNavigatorView.findNavigationView();
if (navigationView != null && startList.size() > 0) {
final TreeViewer treeViewer = navigationView.getViewer();
TaskExecutor taskExcutor = new TaskExecutor() {
public boolean exec(final IProgressMonitor monitor) {
Display display = Display.getDefault();
if (monitor.isCanceled()) {
return false;
}
for (int i = 0; i < taskList.size(); i++) {
ITask task = taskList.get(i);
final CubridDatabase database = (CubridDatabase) task.getData("dbName");
if (!isSupported(database)) {
continue;
}
monitor.subTask(Messages.bind(Messages.startDbTaskName, database.getName()));
task.execute();
if (openErrorBox(shell, task.getErrorMsg(), monitor) || monitor.isCanceled()) {
return false;
}
openWarningBox(shell, task.getWarningMsg(), monitor);
if (monitor.isCanceled()) {
return false;
}
database.removeAllChild();
if (database.getLoader() != null) {
database.getLoader().setLoaded(false);
}
database.setRunningType(DbRunningType.CS);
display.syncExec(new Runnable() {
public void run() {
treeViewer.refresh(database, true);
}
});
if (monitor.isCanceled()) {
return false;
}
}
return true;
}
};
for (ISchemaNode schemaNode : startList) {
CubridDatabase database = schemaNode.getDatabase();
if (!isSupported(database)) {
setEnabled(false);
return;
}
ServerInfo serverInfo = database.getServer().getServerInfo();
CommonUpdateTask task = new CommonUpdateTask(CommonTaskName.START_DB_TASK_NAME, serverInfo, CommonSendMsg.getCommonDatabaseSendMsg());
task.setDbName(database.getLabel());
task.putData("dbName", database);
taskExcutor.addTask(task);
}
new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
ActionManager.getInstance().fireSelectionChanged(getSelection());
}
}
Aggregations