Search in sources :

Example 21 with DefaultSchemaNode

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

the class JobAutoDashboardEditorPart method editQueryPlan.

public void editQueryPlan() {
    TableItem[] items = queryPlanInfoTable.getTable().getSelection();
    if (items.length != 0) {
        TableItem item = items[0];
        QueryPlanInfo queryPlanInfo = (QueryPlanInfo) item.getData();
        Set<String> typeSet = new HashSet<String>();
        typeSet.add(CubridNodeType.QUERY_PLAN);
        ICubridNode queryPlanNode = findAutoJobInfoNode(CubridNodeType.QUERY_PLAN, queryPlanInfo.getQuery_id());
        if (queryPlanNode != null) {
            EditQueryPlanAction action = (EditQueryPlanAction) ActionManager.getInstance().getAction(EditQueryPlanAction.ID);
            if (action.run(database, (DefaultSchemaNode) queryPlanNode) == IDialogConstants.OK_ID) {
                refreshQueryPlan();
            }
        }
    } else {
        CommonUITool.openWarningBox(Messages.errJobAutoNoSelection);
    }
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) QueryPlanInfo(com.cubrid.cubridmanager.core.cubrid.jobauto.model.QueryPlanInfo) DefaultSchemaNode(com.cubrid.common.ui.spi.model.DefaultSchemaNode) HashSet(java.util.HashSet) EditQueryPlanAction(com.cubrid.cubridmanager.ui.cubrid.jobauto.action.EditQueryPlanAction)

Example 22 with DefaultSchemaNode

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

the class JobAutoDashboardEditorPart method findAutoJobInfoNode.

/**
	 * find queryPlanoNode or backupPlanNode from treeView
	 *
	 * @param nodeType String
	 * @param nodeType id
	 * @return
	 */
public ICubridNode findAutoJobInfoNode(String nodeType, String id) {
    Set<String> typeSet = new HashSet<String>();
    typeSet.add(nodeType);
    ICubridNode node = CommonUITool.findNode(database, typeSet, id);
    //if backupPlanNode is null,expand the backupPlanNodeFolder then find again
    if (node == null) {
        CubridNavigatorView view = CubridNavigatorView.getNavigatorView(CubridHostNavigatorView.ID);
        TreeViewer treeViewer = view.getViewer();
        ICubridNode jobAutoFolderNode = database.getChild(database.getId() + ICubridNodeLoader.NODE_SEPARATOR + CubridDatabaseLoader.JOB_AUTO_FOLDER_ID);
        String childNodeFolderID = nodeType.equals(CubridNodeType.BACKUP_PLAN) ? CubridJobAutoFolderLoader.BACKUP_PLAN_FOLDER_ID : CubridJobAutoFolderLoader.QUERY_PLAN_FOLDER_ID;
        DefaultSchemaNode folderNode = (DefaultSchemaNode) jobAutoFolderNode.getChild(jobAutoFolderNode.getId() + ICubridNodeLoader.NODE_SEPARATOR + childNodeFolderID);
        treeViewer.expandToLevel(folderNode, 1);
        //wait 5 times expand the folder node
        int time = 0;
        while (folderNode.getChildren().size() == 0 && time++ < 5) {
            try {
                Thread.sleep(500);
            } catch (Exception e) {
            }
        }
    }
    return CommonUITool.findNode(database, typeSet, id);
}
Also used : CubridNavigatorView(com.cubrid.common.ui.common.navigator.CubridNavigatorView) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) DefaultSchemaNode(com.cubrid.common.ui.spi.model.DefaultSchemaNode) PartInitException(org.eclipse.ui.PartInitException) HashSet(java.util.HashSet)

Example 23 with DefaultSchemaNode

use of com.cubrid.common.ui.spi.model.DefaultSchemaNode 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 24 with DefaultSchemaNode

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

the class DeleteTableAction method doRun.

/**
	 * Do run
	 * 
	 * @param obj
	 */
private void doRun(Object[] obj) {
    StringBuilder sb = new StringBuilder();
    final List<String> tableList = new ArrayList<String>();
    CubridDatabase database = null;
    for (int i = 0; i < obj.length; i++) {
        DefaultSchemaNode table = (DefaultSchemaNode) obj[i];
        database = table.getDatabase();
        final String tableName = table.getName();
        tableList.add(tableName);
        if (i < 100) {
            if (sb.length() > 0) {
                sb.append(", ");
            }
            sb.append(tableName);
        }
    }
    if (obj.length > 100) {
        sb.append("...");
    }
    String message = Messages.bind(Messages.confirmTableDeleteWarn, sb.toString());
    if (!CommonUITool.openConfirmBox(message)) {
        return;
    }
    final DelAllRecordsTask task = new DelAllRecordsTask(database.getDatabaseInfo());
    TaskJobExecutor taskExec = new CommonTaskJobExec(new ITaskExecutorInterceptor() {

        public void completeAll() {
            int[] rowCount = task.getDeleteRecordsCount();
            List<String> rowCountList = new ArrayList<String>();
            for (int i = 0; i < rowCount.length; i++) {
                rowCountList.add(String.valueOf(rowCount[i]));
            }
            String message = Messages.bind(Messages.resultTableDeleteInformantion, tableList, rowCountList);
            CommonUITool.openInformationBox(Messages.msg_information, message);
        }

        public IStatus postTaskFinished(ITask task) {
            return Status.OK_STATUS;
        }
    });
    String[] tableNames = new String[tableList.size()];
    tableNames = tableList.toArray(tableNames);
    task.setTableName(tableNames);
    taskExec.addTask(task);
    JobFamily jobFamily = new JobFamily();
    String serverName = database.getServer().getName();
    String dbName = database.getName();
    jobFamily.setServerName(serverName);
    jobFamily.setDbName(dbName);
    String jobName = Messages.msgDeleteTableDataJobName + " - " + tableList.toString() + "@" + dbName + "@" + serverName;
    taskExec.schedule(jobName, jobFamily, false, Job.SHORT);
}
Also used : TaskJobExecutor(com.cubrid.common.ui.spi.progress.TaskJobExecutor) ITaskExecutorInterceptor(com.cubrid.common.ui.spi.progress.ITaskExecutorInterceptor) ITask(com.cubrid.common.core.task.ITask) IStatus(org.eclipse.core.runtime.IStatus) ArrayList(java.util.ArrayList) JobFamily(com.cubrid.common.ui.spi.progress.JobFamily) DefaultSchemaNode(com.cubrid.common.ui.spi.model.DefaultSchemaNode) DelAllRecordsTask(com.cubrid.cubridmanager.core.cubrid.table.task.DelAllRecordsTask) CommonTaskJobExec(com.cubrid.common.ui.spi.progress.CommonTaskJobExec) ArrayList(java.util.ArrayList) List(java.util.List) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 25 with DefaultSchemaNode

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

the class TableToPhpCodeAction method doRun.

/**
	 * Perform all tables
	 *
	 * @param obj
	 */
private void doRun(final Object[] obj) {
    final File filepath = TableUtil.getSavedDirForCreateCodes(getShell(), null);
    if (filepath == null) {
        return;
    }
    if (!CommonUITool.openConfirmBox(Messages.msgConfirmTableToCode)) {
        return;
    }
    final Map<CubridDatabase, Connection> connections = new HashMap<CubridDatabase, Connection>();
    try {
        final Display display = PlatformUI.getWorkbench().getDisplay();
        BusyIndicator.showWhile(display, new Runnable() {

            public void run() {
                // FIXME move this logic to core module
                StringBuilder notExportedList = new StringBuilder();
                for (int i = 0; i < obj.length; i++) {
                    DefaultSchemaNode table = (DefaultSchemaNode) obj[i];
                    Connection connection = connections.get(table.getDatabase());
                    if (connection == null) {
                        try {
                            connection = JDBCConnectionManager.getConnection(table.getDatabase().getDatabaseInfo(), true);
                            connections.put(table.getDatabase(), connection);
                        } catch (Exception e) {
                            LOGGER.error(e.getMessage(), e);
                        }
                    }
                    if (connection == null) {
                        if (notExportedList.length() > 0) {
                            notExportedList.append(", ");
                        }
                        notExportedList.append(table.getName());
                        continue;
                    }
                    String pojoClassFileName = getPojoFileName(table);
                    String pojoClassData = getPojoString(connection, table);
                    String pojoClassPath = filepath.getAbsolutePath() + File.separator + pojoClassFileName;
                    //TODO: error handling
                    boolean result = FileUtil.writeToFile(pojoClassPath, pojoClassData, "utf-8");
                    if (!result) {
                        if (notExportedList.length() > 0) {
                            notExportedList.append(", ");
                        }
                        notExportedList.append(table.getName());
                    }
                }
                finishNotice(notExportedList.toString());
            }
        });
    } finally {
        Collection<Connection> items = connections.values();
        for (Connection conn : items) {
            QueryUtil.freeQuery(conn);
        }
    }
}
Also used : HashMap(java.util.HashMap) Connection(java.sql.Connection) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) DefaultSchemaNode(com.cubrid.common.ui.spi.model.DefaultSchemaNode) File(java.io.File) Display(org.eclipse.swt.widgets.Display)

Aggregations

DefaultSchemaNode (com.cubrid.common.ui.spi.model.DefaultSchemaNode)88 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)62 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)33 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)22 ICubridNodeLoader (com.cubrid.common.ui.spi.model.ICubridNodeLoader)21 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)18 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)17 ArrayList (java.util.ArrayList)15 TreeViewer (org.eclipse.jface.viewers.TreeViewer)10 CommonTaskExec (com.cubrid.common.ui.spi.progress.CommonTaskExec)9 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)9 Display (org.eclipse.swt.widgets.Display)9 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)8 ClassInfo (com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo)7 File (java.io.File)5 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)4 CommonQueryTask (com.cubrid.cubridmanager.core.common.task.CommonQueryTask)4 DbSpaceInfoList (com.cubrid.cubridmanager.core.cubrid.dbspace.model.DbSpaceInfoList)4 GetAllClassListTask (com.cubrid.cubridmanager.core.cubrid.table.task.GetAllClassListTask)4 DbUserInfo (com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo)4