Search in sources :

Example 11 with ISchemaNode

use of com.cubrid.common.ui.spi.model.ISchemaNode in project cubrid-manager by CUBRID.

the class QueryTunerAction method run.

public void run() {
    Object[] obj = this.getSelectedObj();
    if (!isSupported(obj)) {
        setEnabled(false);
        return;
    }
    ISelectionProvider provider = getSelectionProvider();
    if (!(provider instanceof TreeViewer)) {
        return;
    }
    ISchemaNode node = (ISchemaNode) obj[0];
    String query = getQuery();
    if (StringUtil.isNotEmpty(query)) {
        new QueryTunerDialog(getShell(), node.getDatabase(), query).open();
    } else {
        CommonUITool.openInformationBox(Messages.errSelectQueryForTuning);
        new QueryTunerDialog(getShell(), node.getDatabase()).open();
    }
}
Also used : ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) QueryTunerDialog(com.cubrid.common.ui.query.tuner.dialog.QueryTunerDialog) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) TreeViewer(org.eclipse.jface.viewers.TreeViewer)

Example 12 with ISchemaNode

use of com.cubrid.common.ui.spi.model.ISchemaNode in project cubrid-manager by CUBRID.

the class QueryEditorDNDController method replaceSql.

/**
	 * Replace the SQL
	 *
	 * @return boolean
	 */
private boolean replaceSql() {
    // FIXME move this logic to core module
    List<ISchemaNode> schemaNodeList = new ArrayList<ISchemaNode>();
    Map<String, List<ISchemaNode>> columnNodeMap = new HashMap<String, List<ISchemaNode>>();
    boolean isValid = fillInSelectedNode(schemaNodeList, columnNodeMap);
    if (!isValid || (schemaNodeList.isEmpty() && columnNodeMap.isEmpty())) {
        return false;
    }
    //Confirm whether change database connection
    CubridDatabase db = null;
    for (ISchemaNode selectedNode : schemaNodeList) {
        db = selectedNode.getDatabase();
        break;
    }
    if (db == null) {
        Iterator<List<ISchemaNode>> it = columnNodeMap.values().iterator();
        while (it.hasNext()) {
            db = it.next().get(0).getDatabase();
            break;
        }
    }
    if (db == null) {
        return false;
    }
    CubridDatabase selectedDb = editor.getSelectedDatabase();
    if (!selectedDb.getId().equals(db.getId())) {
        int returnVal = openConfirmDialog();
        if (returnVal == 2 || returnVal == -1) {
            return false;
        }
        if (editor.isTransaction() && returnVal == 0 && !openTransactionDialog(selectedDb)) {
            return false;
        }
        if (returnVal == 0) {
            editor.shutDownConnection();
            editor.connect(db);
        }
    }
    //Get all table SQL
    StringBuilder sqlBuffer = new StringBuilder();
    for (ISchemaNode selectedNode : schemaNodeList) {
        String sql = getScript(selectedNode);
        if (sql != null) {
            sqlBuffer.append(sql);
        }
    }
    //Get the selected columns SQL
    Iterator<Map.Entry<String, List<ISchemaNode>>> it = columnNodeMap.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry<String, List<ISchemaNode>> entry = it.next();
        String sql = getScript(entry.getKey(), entry.getValue());
        if (sql != null) {
            sqlBuffer.append(sql);
        }
    }
    if (sqlBuffer.length() > 0) {
        String sql = sqlBuffer.toString();
        int originalQueryLength = editor.getAllQueries().length();
        int newQueryLength = sql.length();
        int caretOffset = editor.getSqlEditorWidget().getCaretOffset();
        if (originalQueryLength > 0 && caretOffset >= 0) {
            String pre = editor.getAllQueries().substring(0, caretOffset);
            String post = editor.getAllQueries().substring(caretOffset, editor.getAllQueries().length());
            editor.getSqlEditorWidget().setText(pre + sql + post);
            editor.getSqlEditorWidget().setSelection(caretOffset);
        } else {
            editor.setQuery(sql, true, false, false);
            int endIndexOfSelection = originalQueryLength + newQueryLength;
            editor.setSelection(originalQueryLength, endIndexOfSelection);
        }
        ActionManager.getInstance().changeFocusProvider(editor.getSqlEditorWidget());
        return true;
    }
    return false;
}
Also used : ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) HashMap(java.util.HashMap) Map(java.util.Map)

Example 13 with ISchemaNode

use of com.cubrid.common.ui.spi.model.ISchemaNode in project cubrid-manager by CUBRID.

the class QueryNewAction method getSelectedSever.

/**
	 * Get current selected server
	 * 
	 * @return CubridServer
	 */
private CubridServer getSelectedSever() {
    Object[] selected = getSelectedObj();
    CubridServer server = null;
    if (selected != null && selected.length >= 1) {
        if (selected[0] instanceof ISchemaNode) {
            server = ((ISchemaNode) selected[0]).getServer();
        } else if (selected[0] instanceof ICubridNode) {
            server = ((ICubridNode) selected[0]).getServer();
        }
    }
    return server;
}
Also used : ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridServer(com.cubrid.common.ui.spi.model.CubridServer)

Example 14 with ISchemaNode

use of com.cubrid.common.ui.spi.model.ISchemaNode in project cubrid-manager by CUBRID.

the class QueryNewAction method handleSelectionObj.

/**
	 * handleSelectionObj
	 * @param objs
	 * @return
	 */
private CubridDatabase[] handleSelectionObj(Object[] objs) {
    List<CubridDatabase> returnArray = new ArrayList<CubridDatabase>();
    CubridDatabase database = null;
    for (Object obj : objs) {
        if (obj instanceof ISchemaNode) {
            database = ((ISchemaNode) obj).getDatabase();
            if (database != null) {
                //if multiple selection ,only open a query editor with one database
                if (!returnArray.contains(database)) {
                    returnArray.add(database);
                }
            }
        }
    }
    return returnArray.toArray(new CubridDatabase[0]);
}
Also used : ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) ArrayList(java.util.ArrayList) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 15 with ISchemaNode

use of com.cubrid.common.ui.spi.model.ISchemaNode in project cubrid-manager by CUBRID.

the class QueryNewCustomAction method run.

/**
	 * @see org.eclipse.jface.action.Action#run()
	 */
public void run() {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return;
    }
    Object[] selected = getSelectedObj();
    LoginQueryEditDialog dialog = new LoginQueryEditDialog(getShell());
    if (selected != null && selected.length == 1 && selected[0] instanceof ISchemaNode) {
        dialog.setSelServerName(((ISchemaNode) selected[0]).getServer().getServerName());
        dialog.setSelDatabaseName(((ISchemaNode) selected[0]).getDatabase().getName());
    } else if (selected != null && selected.length == 1 && selected[0] instanceof CubridServer) {
        dialog.setSelServerName(((CubridServer) selected[0]).getName());
    } else {
        dialog.setSelServerName(DatabaseNavigatorMenu.SELF_DATABASE_SELECTED_LABEL);
    }
    if (dialog.open() == IDialogConstants.OK_ID) {
        try {
            IEditorInput input = new QueryUnit();
            IEditorPart editor = window.getActivePage().openEditor(input, QueryEditorPart.ID);
            ((QueryEditorPart) editor).connect(DatabaseNavigatorMenu.SELF_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) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) LoginQueryEditDialog(com.cubrid.cubridmanager.ui.common.dialog.LoginQueryEditDialog) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException) CubridServer(com.cubrid.common.ui.spi.model.CubridServer) IEditorInput(org.eclipse.ui.IEditorInput)

Aggregations

ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)158 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)104 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)55 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)30 ArrayList (java.util.ArrayList)28 TreeViewer (org.eclipse.jface.viewers.TreeViewer)27 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)23 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)23 DefaultSchemaNode (com.cubrid.common.ui.spi.model.DefaultSchemaNode)22 DbUserInfo (com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo)22 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)21 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)21 Shell (org.eclipse.swt.widgets.Shell)16 ITask (com.cubrid.common.core.task.ITask)13 CommonTaskExec (com.cubrid.common.ui.spi.progress.CommonTaskExec)13 IEditorPart (org.eclipse.ui.IEditorPart)12 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)12 HashSet (java.util.HashSet)11 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)11 PartInitException (org.eclipse.ui.PartInitException)10