use of com.cubrid.common.ui.spi.model.ICubridNode in project cubrid-manager by CUBRID.
the class DeleteProcedureAction method run.
public void run() {
// FIXME logic code move to core module
Object[] objects = this.getSelectedObj();
if (objects == null || !isSupported(objects)) {
this.setEnabled(false);
return;
}
Shell shell = getShell();
CubridDatabase database = null;
ISchemaNode node = null;
if (objects[0] instanceof ISchemaNode && NodeType.STORED_PROCEDURE_PROCEDURE.equals(((ISchemaNode) objects[0]).getType())) {
node = (ISchemaNode) objects[0];
database = node.getDatabase();
}
if (database == null || node == null) {
CommonUITool.openErrorBox(shell, Messages.errSelectProcedure);
return;
}
if (!CommonUITool.openConfirmBox(shell, Messages.msgSureDropProcedure)) {
return;
}
CommonSQLExcuterTask task = new CommonSQLExcuterTask(database.getDatabaseInfo());
String sql = " DROP PROCEDURE " + QuerySyntax.escapeKeyword(node.getName());
task.addSqls(sql);
TaskExecutor taskExcutor = new CommonTaskExec(null);
taskExcutor.addTask(task);
new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
if (!taskExcutor.isSuccess()) {
return;
}
ISelectionProvider provider = this.getSelectionProvider();
ICubridNode parent = node.getParent();
if (provider instanceof TreeViewer) {
TreeViewer viewer = (TreeViewer) provider;
for (int i = 0; objects != null && i < objects.length; i++) {
parent.removeChild((ISchemaNode) objects[i]);
}
viewer.remove(parent, objects);
viewer.setSelection(new StructuredSelection(parent), true);
}
}
use of com.cubrid.common.ui.spi.model.ICubridNode in project cubrid-manager by CUBRID.
the class DropTableAction method run.
/**
* @see org.eclipse.jface.action.Action#run()
*/
public void run() {
Object[] obj = this.getSelectedObj();
if (!isSupported(obj)) {
setEnabled(false);
return;
}
// FIXME move this logic to core module
int len = obj.length;
StringBuilder sb = new StringBuilder();
ISchemaNode table = (ISchemaNode) obj[0];
String type = table.getType();
for (int i = 0; i < len && i < 100; i++) {
table = (DefaultSchemaNode) obj[i];
if (sb.length() > 0) {
sb.append(", ");
}
sb.append(table.getName());
}
if (len > 100) {
sb.append("...");
}
String message = null;
if (NodeType.USER_TABLE.equals(type) || NodeType.USER_PARTITIONED_TABLE_FOLDER.equals(type)) {
message = Messages.bind(Messages.dropTable, sb.toString());
}
boolean ret = CommonUITool.openConfirmBox(message);
if (!ret) {
return;
}
String taskName = Messages.bind(Messages.dropTableTaskName, sb.toString());
TaskExecutor taskExecutor = new CommonTaskExec(taskName);
DropTableOrViewTask task = new DropTableOrViewTask(table.getDatabase().getDatabaseInfo());
List<String> tableNameList = new ArrayList<String>();
for (int i = 0; i < len; i++) {
table = (DefaultSchemaNode) obj[i];
tableNameList.add(table.getName());
}
String[] tableNames = new String[tableNameList.size()];
tableNames = tableNameList.toArray(tableNames);
task.setTableName(tableNames);
taskExecutor.addTask(task);
new ExecTaskWithProgress(taskExecutor).exec();
if (taskExecutor.isSuccess()) {
// delete table/column descriptions which is dropping table.
DatabaseInfo dbInfo = table.getDatabase().getDatabaseInfo();
Connection conn = null;
try {
conn = JDBCConnectionManager.getConnection(dbInfo, false);
IDatabaseSpec dbSpec = table.getDatabase().getDatabaseInfo();
boolean isSupportTableComment = SchemaCommentHandler.isInstalledMetaTable(dbSpec, conn);
if (isSupportTableComment) {
for (int i = 0; i < len; i++) {
table = (DefaultSchemaNode) obj[i];
SchemaCommentHandler.deleteDescription(dbInfo, conn, table.getName());
}
}
} catch (SQLException e) {
LOGGER.error(e.getMessage(), e);
} finally {
QueryUtil.freeQuery(conn);
}
ISelectionProvider provider = this.getSelectionProvider();
final TreeViewer viewer = (TreeViewer) provider;
ICubridNode parent = table.getParent();
table.getDatabase().getDatabaseInfo().removeSchema(table.getName());
for (int i = 0; i < len; i++) {
parent.removeChild((ISchemaNode) obj[i]);
/*Broadcast the view changed*/
QueryEditorUtil.fireSchemaNodeChanged((ISchemaNode) obj[i]);
}
viewer.remove(parent, obj);
viewer.setSelection(new StructuredSelection(parent), true);
//refresh user folder count label
CommonUITool.updateFolderNodeLabelIncludingChildrenCount(viewer, parent);
/*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();
for (int i = 0; i < len; i++) {
if (tableOfEditor.equals((ISchemaNode) obj[i])) {
workbenchWindow.getActivePage().closeEditor(editor, false);
break;
}
}
}
}
}
}
use of com.cubrid.common.ui.spi.model.ICubridNode in project cubrid-manager by CUBRID.
the class MakeCloneQueryAction method run.
/**
* @see org.eclipse.jface.action.Action#run()
*/
public void run() {
final Object[] obj = this.getSelectedObj();
if (!isSupported(obj)) {
setEnabled(false);
return;
}
final DefaultSchemaNode tableNode = (DefaultSchemaNode) obj[0];
CubridDatabase db = tableNode.getDatabase();
DatabaseInfo dbInfo = db.getDatabaseInfo();
GetTablesTask getTableTask = new GetTablesTask(dbInfo);
List<String> tableList = getTableTask.getAllTableAndViews();
String tableName = null;
if (NodeType.USER_TABLE.equals(tableNode.getType())) {
tableName = tableNode.getName();
}
final CloneTableDialog dialog = new CloneTableDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), tableList, tableName);
if (IDialogConstants.OK_ID == dialog.open()) {
targetName = dialog.getTargetName();
ICubridNode[] nodeArray = { tableNode };
super.doRun(nodeArray);
}
}
use of com.cubrid.common.ui.spi.model.ICubridNode in project cubrid-manager by CUBRID.
the class SerialDashboardEditorPart method openEditSerialDialog.
private void openEditSerialDialog(SerialInfo serialInfo) {
Set<String> typeSet = new HashSet<String>();
typeSet.add(NodeType.SERIAL);
ICubridNode serialNode = CommonUITool.findNode(database, typeSet, serialInfo.getName());
if (serialNode != null) {
EditSerialAction action = (EditSerialAction) ActionManager.getInstance().getAction(EditSerialAction.ID);
if (action.run(database, (ISchemaNode) serialNode) == IDialogConstants.OK_ID) {
refresh();
}
}
}
use of com.cubrid.common.ui.spi.model.ICubridNode in project cubrid-manager by CUBRID.
the class ColumnSelectSqlAction method isSupported.
public boolean isSupported(Object obj) {
boolean isPlainSupport = ActionSupportUtil.isSupportMultiSelection(obj, new String[] { NodeType.TABLE_COLUMN }, true);
boolean isSameTable = true;
if (isPlainSupport && obj instanceof Object[]) {
Object[] objArr = (Object[]) obj;
String parentNodeId = "";
for (int i = 0; i < objArr.length; i++) {
ISchemaNode schemaNode = (ISchemaNode) objArr[i];
ICubridNode parent = schemaNode.getParent();
if (i == 0) {
parentNodeId = parent.getId();
} else {
isSameTable = parentNodeId.equals(parent.getId());
}
}
}
return isPlainSupport && isSameTable;
}
Aggregations