Search in sources :

Example 66 with IWorkbench

use of org.eclipse.ui.IWorkbench in project cubrid-manager by CUBRID.

the class DropTableAction method doRun.

/**
	 * Do run
	 * @param obj
	 */
private void doRun(Object[] obj) {
    int len = obj.length;
    StringBuilder sb = new StringBuilder();
    ISchemaNode table = (ISchemaNode) obj[0];
    // FIXME move this logic to core module
    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);
        }
        //TODO -KK
        TreeViewer treeViewer = CubridNavigatorView.findNavigationView().getViewer();
        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]);
        }
        treeViewer.remove(parent, obj);
        treeViewer.setSelection(new StructuredSelection(parent), true);
        //refresh user folder count label
        CommonUITool.updateFolderNodeLabelIncludingChildrenCount(treeViewer, 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;
                    }
                }
            }
        }
    }
}
Also used : CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) SQLException(java.sql.SQLException) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) TableEditorInput(com.cubrid.common.ui.cubrid.table.editor.TableEditorInput) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) IEditorPart(org.eclipse.ui.IEditorPart) IWorkbench(org.eclipse.ui.IWorkbench) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IDatabaseSpec(com.cubrid.common.core.common.model.IDatabaseSpec) IEditorReference(org.eclipse.ui.IEditorReference) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) DropTableOrViewTask(com.cubrid.cubridmanager.core.cubrid.table.task.DropTableOrViewTask)

Example 67 with IWorkbench

use of org.eclipse.ui.IWorkbench in project cubrid-manager by CUBRID.

the class NewTableAction method doRun.

private void doRun(ISchemaNode node) {
    CubridDatabase database = node.getDatabase();
    TaskExecutor taskExcutor = new CommonTaskExec(null);
    DatabaseInfo databaseInfo = database.getDatabaseInfo();
    boolean supportCharset = CompatibleUtil.isSupportCreateDBByCharset(databaseInfo);
    JDBCGetAllDbUserTask allUserTask = new JDBCGetAllDbUserTask(databaseInfo);
    taskExcutor.addTask(allUserTask);
    GetCollations collationTask = null;
    if (supportCharset) {
        collationTask = new GetCollations(databaseInfo);
        taskExcutor.addTask(collationTask);
    }
    new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
    if (!taskExcutor.isSuccess()) {
        return;
    }
    TableEditorInput input = new TableEditorInput(database, true, null, null, EditTableAction.MODE_TABLE_EDIT);
    List<String> dbUserList = allUserTask.getDbUserList();
    input.setDbUserList(dbUserList);
    if (supportCharset) {
        List<Collation> collations = collationTask.getCollations();
        input.setCollationList(collations);
    }
    try {
        IWorkbench workbench = PlatformUI.getWorkbench();
        IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
        workbenchWindow.getActivePage().openEditor(input, TableEditorPart.ID);
    } catch (Exception ignore) {
    }
}
Also used : CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) TableEditorInput(com.cubrid.common.ui.cubrid.table.editor.TableEditorInput) JDBCGetAllDbUserTask(com.cubrid.cubridmanager.core.cubrid.user.task.JDBCGetAllDbUserTask) GetCollations(com.cubrid.cubridmanager.core.cubrid.table.task.GetCollations) Collation(com.cubrid.cubridmanager.core.cubrid.database.model.Collation) IWorkbench(org.eclipse.ui.IWorkbench) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 68 with IWorkbench

use of org.eclipse.ui.IWorkbench in project cubrid-manager by CUBRID.

the class LayoutUtil method getActivePage.

/**
	 * 
	 * Get active workbench page
	 * 
	 * @return IWorkbenchPage
	 */
public static IWorkbenchPage getActivePage() {
    IWorkbench workbench = PlatformUI.getWorkbench();
    if (workbench == null) {
        return null;
    }
    IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
    if (window == null) {
        return null;
    }
    return window.getActivePage();
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow)

Example 69 with IWorkbench

use of org.eclipse.ui.IWorkbench in project azure-tools-for-java by Microsoft.

the class UIHelperImpl method openItem.

@Override
public <T extends StorageServiceTreeItem> void openItem(Object projectObject, final ClientStorageAccount clientStorageAccount, final T item, String itemType, String itemName, String iconName) {
    //        Display.getDefault().syncExec(new Runnable() {
    //            @Override
    //            public void run() {
    //                try {
    //                    BlobExplorerView view = (BlobExplorerView) PlatformUI
    //                            .getWorkbench().getActiveWorkbenchWindow()
    //                            .getActivePage().showView("com.microsoft.azureexplorer.views.BlobExplorerView");
    //                    view.init(storageAccount, (BlobContainer) blobContainer);
    //                } catch (PartInitException e) {
    //                    Activator.getDefault().log("Error opening container", e);
    //                }
    //            }
    //        });
    IWorkbench workbench = PlatformUI.getWorkbench();
    IEditorDescriptor editorDescriptor = workbench.getEditorRegistry().findEditor(type2Editor.get(item.getClass()));
    try {
        IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
        IEditorPart newEditor = page.openEditor(new StorageEditorInput(clientStorageAccount.getName(), clientStorageAccount.getConnectionString(), item), editorDescriptor.getId());
    } catch (PartInitException e) {
        Activator.getDefault().log("Error opening " + item.getName(), e);
    }
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) StorageEditorInput(com.microsoft.azuretools.azureexplorer.editors.StorageEditorInput) IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException)

Example 70 with IWorkbench

use of org.eclipse.ui.IWorkbench in project azure-tools-for-java by Microsoft.

the class UIHelperImpl method refreshTable.

@Override
public void refreshTable(Object projectObject, final StorageAccount storageAccount, final Table table) {
    IWorkbench workbench = PlatformUI.getWorkbench();
    final IEditorDescriptor editorDescriptor = workbench.getEditorRegistry().findEditor("com.microsoft.azuretools.azureexplorer.editors.TableFileEditor");
    DefaultLoader.getIdeHelper().invokeLater(new Runnable() {

        public void run() {
        // TODO
        /*try {
                    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
                    TableFileEditor newEditor = (TableFileEditor) page.openEditor(new StorageEditorInput(storageAccount, table), editorDescriptor.getId());
                    newEditor.fillGrid();
                } catch (PartInitException e) {
                    Activator.getDefault().log("Error opening container", e);
                }*/
        }
    });
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IEditorDescriptor(org.eclipse.ui.IEditorDescriptor)

Aggregations

IWorkbench (org.eclipse.ui.IWorkbench)105 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)32 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)31 IEditorPart (org.eclipse.ui.IEditorPart)21 PartInitException (org.eclipse.ui.PartInitException)20 WizardDialog (org.eclipse.jface.wizard.WizardDialog)15 CoreException (org.eclipse.core.runtime.CoreException)12 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)12 Shell (org.eclipse.swt.widgets.Shell)11 IResource (org.eclipse.core.resources.IResource)9 ISelection (org.eclipse.jface.viewers.ISelection)9 Display (org.eclipse.swt.widgets.Display)8 ArrayList (java.util.ArrayList)7 IFile (org.eclipse.core.resources.IFile)7 IEditorDescriptor (org.eclipse.ui.IEditorDescriptor)7 IProject (org.eclipse.core.resources.IProject)6 TreeViewer (org.eclipse.jface.viewers.TreeViewer)6 TableEditorInput (com.cubrid.common.ui.cubrid.table.editor.TableEditorInput)5 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)5 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)5