Search in sources :

Example 71 with IWorkbenchPage

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

the class RemoveAllDbLogAction method run.

/**
	 * Remove all database logs
	 */
public void run() {
    if (!CommonUITool.openConfirmBox(Messages.warningRemoveLog)) {
        return;
    }
    Object[] selected = this.getSelectedObj();
    DelAllLogTask delAllLogTask = new DelAllLogTask(((DefaultCubridNode) selected[0]).getServer().getServerInfo());
    String[] path = new String[((DefaultCubridNode) selected[0]).getChildren().size()];
    //get last file name
    String lastDBLog = "";
    LogInfo currLogFile;
    for (int i = 0, len = path.length; i < len; i++) {
        currLogFile = ((LogInfo) (((DefaultCubridNode) selected[0]).getChildren().get(i).getAdapter(LogInfo.class)));
        if (lastDBLog.compareTo(currLogFile.getPath()) < 0) {
            lastDBLog = currLogFile.getPath();
        }
    }
    for (int i = 0, len = path.length - 1; i < len; i++) {
        if (!((LogInfo) (((DefaultCubridNode) selected[0]).getChildren().get(i).getAdapter(LogInfo.class))).getPath().equals(lastDBLog)) {
            path[i] = ((LogInfo) (((DefaultCubridNode) selected[0]).getChildren().get(i).getAdapter(LogInfo.class))).getPath();
        }
    }
    delAllLogTask.setPath(path);
    TaskExecutor taskExecutor = new CommonTaskExec(Messages.removeLogTaskName);
    taskExecutor.addTask(delAllLogTask);
    new ExecTaskWithProgress(taskExecutor).busyCursorWhile();
    if (!taskExecutor.isSuccess()) {
        return;
    }
    TreeViewer treeViewer = (TreeViewer) this.getSelectionProvider();
    DefaultCubridNode delNode = ((DefaultCubridNode) selected[0]);
    ICubridNode parentNode = delNode.getParent().getParent();
    parentNode.removeChild(delNode);
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return;
    }
    IWorkbenchPage activePage = window.getActivePage();
    for (int i = 0, len = path.length; i < len; i++) {
        IEditorPart editor = activePage.findEditor(((DefaultCubridNode) selected[0]).getChildren().get(i));
        if (!((LogInfo) (((DefaultCubridNode) selected[0]).getChildren().get(i).getAdapter(LogInfo.class))).getPath().equals(lastDBLog)) {
            treeViewer.remove(((DefaultCubridNode) selected[0]).getChildren().get(i));
            if (null != editor) {
                activePage.closeEditor(editor, true);
            }
        }
    }
}
Also used : CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) DefaultCubridNode(com.cubrid.common.ui.spi.model.DefaultCubridNode) LogInfo(com.cubrid.cubridmanager.core.logs.model.LogInfo) TreeViewer(org.eclipse.jface.viewers.TreeViewer) DelAllLogTask(com.cubrid.cubridmanager.core.logs.task.DelAllLogTask) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) IEditorPart(org.eclipse.ui.IEditorPart) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage)

Example 72 with IWorkbenchPage

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

the class RemoveAllErrorLogAction method run.

/**
	 * Remove all error logs
	 */
public void run() {
    if (!CommonUITool.openConfirmBox(Messages.warningRemoveLog)) {
        return;
    }
    Object[] selected = this.getSelectedObj();
    DelAllLogTask delAllLogTask = new DelAllLogTask(((DefaultCubridNode) selected[0]).getServer().getServerInfo());
    String[] path = new String[((DefaultCubridNode) selected[0]).getChildren().size()];
    for (int i = 0, len = path.length; i < len; i++) {
        path[i] = ((LogInfo) (((DefaultCubridNode) selected[0]).getChildren().get(i).getAdapter(LogInfo.class))).getPath();
    }
    delAllLogTask.setPath(path);
    TaskExecutor taskExecutor = new CommonTaskExec(Messages.removeLogTaskName);
    taskExecutor.addTask(delAllLogTask);
    new ExecTaskWithProgress(taskExecutor).busyCursorWhile();
    if (taskExecutor.isSuccess()) {
        TreeViewer treeViewer = (TreeViewer) this.getSelectionProvider();
        DefaultCubridNode delNode = ((DefaultCubridNode) selected[0]);
        ICubridNode parentNode = delNode.getParent().getParent();
        parentNode.removeChild(delNode);
        IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        IWorkbenchPage activePage = window.getActivePage();
        for (int i = 0, len = path.length; i < len; i++) {
            IEditorPart editor = activePage.findEditor(((DefaultCubridNode) selected[0]).getChildren().get(i));
            treeViewer.remove(((DefaultCubridNode) selected[0]).getChildren().get(i));
            if (null != editor) {
                activePage.closeEditor(editor, true);
            }
        }
    }
}
Also used : CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) DefaultCubridNode(com.cubrid.common.ui.spi.model.DefaultCubridNode) LogInfo(com.cubrid.cubridmanager.core.logs.model.LogInfo) TreeViewer(org.eclipse.jface.viewers.TreeViewer) DelAllLogTask(com.cubrid.cubridmanager.core.logs.task.DelAllLogTask) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) IEditorPart(org.eclipse.ui.IEditorPart) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage)

Example 73 with IWorkbenchPage

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

the class CopyToClipboardAction method openNewQueryEditor.

/**
	 * Open the new query editor
	 * 
	 * @return IEditorPart
	 */
private IEditorPart openNewQueryEditor() {
    IWorkbenchPage activePage = LayoutUtil.getActivePage();
    QueryUnit queryUnit = new QueryUnit();
    Object[] selected = getSelectedObj();
    CubridDatabase database = null;
    if (selected.length >= 1 && selected[0] instanceof ISchemaNode) {
        database = ((ISchemaNode) selected[0]).getDatabase();
        queryUnit.setDatabase(database);
    }
    try {
        IEditorPart editor = activePage.openEditor(queryUnit, QueryEditorPart.ID);
        if (editor != null && database != null) {
            ((QueryEditorPart) editor).connect(database);
        }
        return editor;
    } catch (PartInitException e) {
        LOGGER.error(e.getMessage());
    }
    return null;
}
Also used : QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) QueryUnit(com.cubrid.common.ui.query.editor.QueryUnit) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 74 with IWorkbenchPage

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

the class CopyToClipboardAction method doRun.

/**
	 * Do run
	 * 
	 * @param objects
	 */
protected void doRun(final Object[] objects) {
    final int len = objects.length;
    final Display display = PlatformUI.getWorkbench().getDisplay();
    BusyIndicator.showWhile(display, new Runnable() {

        public void run() {
            IEditorPart ep = null;
            if (isCopyToEditor) {
                IWorkbenchPage activePage = LayoutUtil.getActivePage();
                ep = activePage.getActiveEditor();
                if (!(ep instanceof QueryEditorPart)) {
                    ep = openNewQueryEditor();
                }
                if (!(ep instanceof QueryEditorPart)) {
                    ep = null;
                }
            }
            StringBuffer allTableSql = new StringBuffer();
            for (int i = 0; i < len; i++) {
                DefaultSchemaNode table = (DefaultSchemaNode) objects[i];
                String sql = getStmtSQL(table, ep);
                if (sql != null && sql.trim().length() > 0) {
                    allTableSql.append(sql);
                    allTableSql.append(StringUtil.NEWLINE);
                    allTableSql.append(StringUtil.NEWLINE);
                }
            }
            if (allTableSql.length() > 0) {
                if (isCopyToEditor) {
                    if (ep instanceof QueryEditorPart) {
                        ((QueryEditorPart) ep).setQuery(allTableSql.toString(), true, false, false);
                    }
                } else {
                    CommonUITool.copyContentToClipboard(allTableSql.toString());
                }
            }
        }
    });
}
Also used : QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) DefaultSchemaNode(com.cubrid.common.ui.spi.model.DefaultSchemaNode) Display(org.eclipse.swt.widgets.Display)

Example 75 with IWorkbenchPage

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

the class AbstractBasicPart method postSchemaDataChanged.

public void postSchemaDataChanged(PropertyChangeEvent evt) {
    String property = evt.getPropertyName();
    boolean isDataChanged = PropertyChangeProvider.CHILD_CHANGE.equals(property) | PropertyChangeProvider.OUTPUT_CHANGE.equals(property) | PropertyChangeProvider.INPUT_CHANGE.equals(property) | PropertyChangeProvider.TEXT_CHANGE.equals(property);
    if (!isDataChanged) {
        return;
    }
    IWorkbenchPage page = getActivePage();
    if (page == null) {
        return;
    }
    IEditorPart editor = page.getActiveEditor();
    if (editor instanceof ERSchemaEditor) {
        ERSchemaEditor erEditor = (ERSchemaEditor) editor;
        erEditor.setDirty(true);
    }
}
Also used : ERSchemaEditor(com.cubrid.common.ui.er.editor.ERSchemaEditor) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart)

Aggregations

IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)294 IEditorPart (org.eclipse.ui.IEditorPart)126 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)102 PartInitException (org.eclipse.ui.PartInitException)96 IFile (org.eclipse.core.resources.IFile)63 IViewPart (org.eclipse.ui.IViewPart)58 IEditorReference (org.eclipse.ui.IEditorReference)40 IWorkbench (org.eclipse.ui.IWorkbench)32 CoreException (org.eclipse.core.runtime.CoreException)31 ArrayList (java.util.ArrayList)30 IViewReference (org.eclipse.ui.IViewReference)29 IEditorInput (org.eclipse.ui.IEditorInput)28 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)27 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)22 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)18 Path (org.eclipse.core.runtime.Path)18 FileEditorInput (org.eclipse.ui.part.FileEditorInput)17 IOException (java.io.IOException)16 IProject (org.eclipse.core.resources.IProject)16 ISelection (org.eclipse.jface.viewers.ISelection)16