Search in sources :

Example 41 with PartInitException

use of org.eclipse.ui.PartInitException 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 42 with PartInitException

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

the class SchemaInfoEditorPart method dispose.

@Override
public void dispose() {
    if (cubridNode.getType().equals(NodeType.USER_TABLE) || cubridNode.getType().equals(NodeType.USER_VIEW) || cubridNode.getType().equals(NodeType.SYSTEM_TABLE) || cubridNode.getType().equals(NodeType.SYSTEM_VIEW)) {
        IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        QueryUnit unit = new QueryUnit();
        unit.setDatabase(((DefaultSchemaNode) cubridNode).getDatabase());
        try {
            IEditorPart editor = window.getActivePage().openEditor(unit, QueryEditorPart.ID);
            if (editor != null)
                ((QueryEditorPart) editor).connect(unit.getDatabase());
        } catch (PartInitException e) {
            LOGGER.error(e.getMessage(), e);
        }
    }
    super.dispose();
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) QueryUnit(com.cubrid.common.ui.query.editor.QueryUnit) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException)

Example 43 with PartInitException

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

the class CopyQueryEditorAction method run.

/**
	 * @see org.eclipse.jface.action.Action#run()
	 */
public void run() {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return;
    }
    IEditorPart editor = window.getActivePage().getActiveEditor();
    if (editor instanceof QueryEditorPart) {
        QueryUnit queryUnit = new QueryUnit();
        QueryEditorPart qep = (QueryEditorPart) editor;
        CubridDatabase database = qep.getSelectedDatabase();
        if (database != null) {
            queryUnit.setDatabase(database);
        }
        // [TOOLS-2425]Support shard broker
        if (database != null) {
            DatabaseInfo dbInfo = database.getDatabaseInfo();
            if (dbInfo != null && dbInfo.isShard()) {
                ShardIdSelectionDialog dialog = new ShardIdSelectionDialog(Display.getDefault().getActiveShell());
                dialog.setDatabaseInfo(dbInfo);
                dialog.setShardId(0);
                if (dialog.open() == IDialogConstants.OK_ID) {
                    dbInfo.setCurrentShardId(dialog.getShardId());
                }
            }
        }
        try {
            IEditorPart newEditor = window.getActivePage().openEditor(queryUnit, QueryEditorPart.ID);
            if (newEditor != null && database != null) {
                ((QueryEditorPart) newEditor).connect(database);
            }
        } catch (PartInitException e) {
            LOGGER.error(e.getMessage());
        }
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) QueryUnit(com.cubrid.common.ui.query.editor.QueryUnit) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ShardIdSelectionDialog(com.cubrid.common.ui.common.dialog.ShardIdSelectionDialog) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 44 with PartInitException

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

the class DatabaseQueryNewAction method run.

/**
	 * @see org.eclipse.jface.action.Action#run()
	 */
public void run() {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return;
    }
    Object[] obj = this.getSelectedObj();
    CubridDatabase[] cubridDatabases = handleSelectionObj(obj);
    if (cubridDatabases.length == 0) {
        return;
    }
    /*Limit max number one time*/
    if (cubridDatabases.length > LayoutUtil.MAX_OPEN_QUERY_EDITOR_NUM) {
        CommonUITool.openConfirmBox(Messages.bind(Messages.msgMaxOpenNum, LayoutUtil.MAX_OPEN_QUERY_EDITOR_NUM));
        List<CubridDatabase> list = new ArrayList<CubridDatabase>(LayoutUtil.MAX_OPEN_QUERY_EDITOR_NUM);
        for (int i = 0; i < LayoutUtil.MAX_OPEN_QUERY_EDITOR_NUM; i++) {
            list.add(cubridDatabases[i]);
        }
        cubridDatabases = new CubridDatabase[LayoutUtil.MAX_OPEN_QUERY_EDITOR_NUM];
        list.toArray(cubridDatabases);
    }
    // [TOOLS-2425]Support shard broker
    // it is used in order to check first shard database when you open several editor of databases.
    int count = cubridDatabases.length;
    for (CubridDatabase database : cubridDatabases) {
        QueryUnit queryUnit = new QueryUnit();
        queryUnit.setDatabase(database);
        // [TOOLS-2425]Support shard broker
        DatabaseInfo dbInfo = database.getDatabaseInfo();
        if (dbInfo == null) {
            continue;
        }
        int shardId = 0;
        int shardVal = 0;
        int shardQueryType = DatabaseInfo.SHARD_QUERY_TYPE_VAL;
        if (count == 1) {
            // [TOOLS-2425]Support shard broker
            if (dbInfo != null && dbInfo.isShard()) {
                ShardIdSelectionDialog dialog = new ShardIdSelectionDialog(getShell());
                dialog.setDatabaseInfo(dbInfo);
                dialog.setShardId(shardId);
                dialog.setShardVal(shardVal);
                dialog.setShardQueryType(shardQueryType);
                if (dialog.open() == IDialogConstants.OK_ID) {
                    shardId = dialog.getShardId();
                    shardVal = dialog.getShardVal();
                    shardQueryType = dialog.getShardQueryType();
                }
            }
        }
        try {
            IEditorPart editor = window.getActivePage().openEditor(queryUnit, QueryEditorPart.ID);
            if (editor != null && database != null) {
                QueryEditorPart editorPart = (QueryEditorPart) editor;
                editorPart.connect(database);
                // [TOOLS-2425]Support shard broker
                if (dbInfo.isShard()) {
                    editorPart.setShardId(shardId);
                    editorPart.setShardVal(shardVal);
                    editorPart.setShardQueryType(shardQueryType);
                    editorPart.changeQueryEditorPartNameWithShard();
                }
            }
        } catch (PartInitException e) {
            LOGGER.error(e.getMessage());
        }
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ArrayList(java.util.ArrayList) ShardIdSelectionDialog(com.cubrid.common.ui.common.dialog.ShardIdSelectionDialog) IEditorPart(org.eclipse.ui.IEditorPart) QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) QueryUnit(com.cubrid.common.ui.query.editor.QueryUnit) PartInitException(org.eclipse.ui.PartInitException) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 45 with PartInitException

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

the class BatchRunDialog method buttonPressed.

/**
	 * Call this method when the button in button bar is pressed
	 * 
	 * @param buttonId the button id
	 */
protected void buttonPressed(int buttonId) {
    if (buttonId == RUN_ID) {
        if (!MessageDialog.openConfirm(PlatformUI.getWorkbench().getDisplay().getActiveShell(), Messages.titleBatchRunConfirm, Messages.msgBatchRunConfirm)) {
            return;
        }
        List<String> fileList = container.getFileList();
        RunSQLFileEditorInput input = new RunSQLFileEditorInput(cubridDatabase, fileList);
        try {
            PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input, RunSQLFileViewPart.ID);
        } catch (Exception e) {
            LOGGER.error(e.getLocalizedMessage());
        }
        super.buttonPressed(IDialogConstants.OK_ID);
    } else if (buttonId == PASTE_ID) {
        //			if (!MessageDialog.openConfirm(
        //					PlatformUI.getWorkbench().getDisplay().getActiveShell(),
        //					Messages.titleBatchRunConfirm, Messages.msgBatchRunPasteConfirm)) {
        //				return;
        //			}
        IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        if (window == null || window.getActivePage() == null) {
            return;
        }
        IEditorPart editor = window.getActivePage().getActiveEditor();
        try {
            if (editor == null) {
                IEditorInput input = new QueryUnit();
                editor = window.getActivePage().openEditor(input, QueryEditorPart.ID);
            }
        } catch (PartInitException e) {
            CommonUITool.openErrorBox(e.getMessage());
        }
        if (editor == null) {
            return;
        }
        QueryEditorPart oldEditor = (QueryEditorPart) editor;
        try {
            QueryEditorPart queryEditor = (QueryEditorPart) editor;
            String encoding = queryEditor.getCombinedQueryComposite().getSqlEditorComp().getDocument().getEncoding();
            StringBuilder sb = new StringBuilder();
            List<String> fileList = container.getFileList();
            for (int i = 0; i < fileList.size(); i++) {
                sb.delete(0, sb.length());
                sb.append("/* SQL Filename: ").append(fileList.get(i)).append(" */").append(StringUtil.NEWLINE);
                BufferedReader in = null;
                try {
                    in = new BufferedReader(new InputStreamReader(new FileInputStream(new File(fileList.get(i))), encoding));
                    String line = in.readLine();
                    while (line != null) {
                        sb.append(line + StringUtil.NEWLINE);
                        line = in.readLine();
                    }
                } finally {
                    try {
                        if (in != null) {
                            in.close();
                        }
                    } catch (IOException e) {
                    }
                }
                try {
                    QueryUnit input = new QueryUnit();
                    QueryEditorPart newEditor = (QueryEditorPart) window.getActivePage().openEditor(input, QueryEditorPart.ID);
                    newEditor.setQuery(sb.toString(), false, false, false);
                    newEditor.connect(oldEditor.getSelectedDatabase());
                } catch (Exception e) {
                    CommonUITool.openErrorBox(e.getMessage());
                }
            }
        } catch (IOException e) {
            CommonUITool.openErrorBox(e.getMessage());
        }
        super.buttonPressed(IDialogConstants.OK_ID);
    } else {
        super.buttonPressed(buttonId);
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) InputStreamReader(java.io.InputStreamReader) RunSQLFileEditorInput(com.cubrid.common.ui.common.sqlrunner.part.RunSQLFileEditorInput) IEditorPart(org.eclipse.ui.IEditorPart) IOException(java.io.IOException) PartInitException(org.eclipse.ui.PartInitException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) QueryUnit(com.cubrid.common.ui.query.editor.QueryUnit) BufferedReader(java.io.BufferedReader) List(java.util.List) PartInitException(org.eclipse.ui.PartInitException) File(java.io.File) IEditorInput(org.eclipse.ui.IEditorInput)

Aggregations

PartInitException (org.eclipse.ui.PartInitException)720 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)300 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)177 IFile (org.eclipse.core.resources.IFile)146 IEditorPart (org.eclipse.ui.IEditorPart)141 CoreException (org.eclipse.core.runtime.CoreException)94 FileEditorInput (org.eclipse.ui.part.FileEditorInput)88 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)82 IEditorInput (org.eclipse.ui.IEditorInput)74 ISelection (org.eclipse.jface.viewers.ISelection)62 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)60 IResource (org.eclipse.core.resources.IResource)59 IEditorReference (org.eclipse.ui.IEditorReference)53 IViewPart (org.eclipse.ui.IViewPart)53 IOException (java.io.IOException)42 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)41 Point (org.eclipse.swt.graphics.Point)40 IWorkbench (org.eclipse.ui.IWorkbench)40 Path (org.eclipse.core.runtime.Path)39 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)39