Search in sources :

Example 1 with CubridNavigatorView

use of com.cubrid.common.ui.common.navigator.CubridNavigatorView in project cubrid-manager by CUBRID.

the class MultiDBQueryComposite method getDatabaseNode.

/**
	 * find database node by db name array
	 * @param databaseNameArray String[]
	 * @return database node list
	 */
@SuppressWarnings({ "unchecked" })
public List<ICubridNode> getDatabaseNode(String[] databaseNameArray) {
    ArrayList<ICubridNode> databaseNodeList = new ArrayList<ICubridNode>();
    Set<String> typeSet = new HashSet<String>();
    typeSet.add(NodeType.DATABASE);
    CubridNavigatorView navigatorView = CubridNavigatorView.getNavigatorView("com.cubrid.cubridmanager.host.navigator");
    if (navigatorView == null) {
        // on CQB
        navigatorView = CubridNavigatorView.getNavigatorView("com.cubrid.cubridquery.connection.navigator");
    }
    List<ICubridNode> items = (List<ICubridNode>) navigatorView.getRootList();
    for (ICubridNode cubridNode : items) {
        for (String databaseName : databaseNameArray) {
            ICubridNode databaseNode = CommonUITool.findNode(cubridNode, typeSet, databaseName);
            if (databaseNode != null) {
                databaseNodeList.add(databaseNode);
            }
        }
    }
    return databaseNodeList;
}
Also used : CubridNavigatorView(com.cubrid.common.ui.common.navigator.CubridNavigatorView) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) HashSet(java.util.HashSet)

Example 2 with CubridNavigatorView

use of com.cubrid.common.ui.common.navigator.CubridNavigatorView in project cubrid-manager by CUBRID.

the class MultiQueryThread method runQueries.

public void runQueries() {
    CubridNavigatorView navigatorView = CubridNavigatorView.findNavigationView();
    navigatorView.getMultiDBQuerySelectedDBList().clear();
    int index = 0;
    for (Map.Entry<CubridDatabase, QueryResultComposite> entry : dbResultMap.entrySet()) {
        CubridDatabase cubridDatabase = entry.getKey();
        if (index == 0) {
            baseDatabase = cubridDatabase;
        }
        navigatorView.addMultiDBQuerySelectedDB(cubridDatabase);
        QueryResultComposite queryResultComp = entry.getValue();
        MultiQueryThread queryThread = new MultiQueryThread(queries, editor, cubridDatabase, queryResultComp);
        makeProgressBar(queryThread, cubridDatabase, queryResultComp);
        queryThread.run();
        compositeMap.put(cubridDatabase, queryResultComp);
        queryExecuterMap.put(cubridDatabase, queryThread.getQueryExecuterMap());
        logsMap.put(cubridDatabase, queryThread.getLogsMap());
        index++;
    }
    displayResults();
}
Also used : CubridNavigatorView(com.cubrid.common.ui.common.navigator.CubridNavigatorView) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 3 with CubridNavigatorView

use of com.cubrid.common.ui.common.navigator.CubridNavigatorView in project cubrid-manager by CUBRID.

the class DatabaseNavigatorMenu method addSelectionListener.

/**
	 * Add selection listener
	 * 
	 */
protected void addSelectionListener() {
    MenuItem[] allNodes = getAllMenuNodes();
    for (final MenuItem item : allNodes) {
        item.addSelectionListener(new SelectionAdapter() {

            public void widgetSelected(SelectionEvent event) {
                if (item.getStyle() != SWT.CHECK && item.getStyle() != SWT.RADIO) {
                    CommonUITool.openErrorBox(parent.getShell(), Messages.plsSelectDb);
                    return;
                }
                if (editor.isRunning()) {
                    CommonUITool.openErrorBox(parent.getShell(), Messages.errEditorRunning);
                    item.setSelection(false);
                    return;
                }
                CubridDatabase oldSelectedDb = (CubridDatabase) getSelectedDb();
                final DatabaseMenuItem dbItem = (DatabaseMenuItem) item;
                CubridDatabase selectedDb = dbItem.getDatabase();
                if (selectedDb != null && selectedDb.getId().equals(IND_DATABASE_ID)) {
                    if (oldSelectedDb == null) {
                        return;
                    }
                    dbItem.setSelection(false);
                    // on CM
                    CubridNavigatorView navigatorView = CubridNavigatorView.getNavigatorView("com.cubrid.cubridmanager.host.navigator");
                    if (navigatorView != null) {
                        TreeViewer treeViewer = navigatorView.getViewer();
                        Tree tree = treeViewer.getTree();
                        if (tree == null) {
                            return;
                        }
                        for (int i = 0; i < tree.getItemCount(); i++) {
                            TreeItem itm = tree.getItem(i);
                            if (itm == null) {
                                continue;
                            }
                            showDatabaseOnEditingWithHostOnGroup(dbItem, oldSelectedDb, treeViewer, tree, itm);
                        }
                        return;
                    }
                    // on CQB
                    navigatorView = CubridNavigatorView.getNavigatorView("com.cubrid.cubridquery.connection.navigator");
                    if (navigatorView != null) {
                        TreeViewer treeViewer = navigatorView.getViewer();
                        Tree tree = treeViewer.getTree();
                        if (tree == null) {
                            return;
                        }
                        for (int i = 0; i < tree.getItemCount(); i++) {
                            TreeItem itm = tree.getItem(i);
                            if (itm == null) {
                                continue;
                            }
                            showDatabaseOnEditingOnGroup(oldSelectedDb, treeViewer, tree, itm);
                        }
                        return;
                    }
                    return;
                } else if (oldSelectedDb != null && selectedDb != null && oldSelectedDb.getId().equals(selectedDb.getId())) {
                    return;
                } else if (selectedDb != null && selectedDb.getId().equals(SELF_DATABASE_ID)) {
                    if (!NULL_DATABASE_ID.equals(oldSelectedDb.getId())) {
                        boolean confirm = CommonUITool.openConfirmBox(editor.getSite().getShell(), Messages.changeDbConfirm);
                        if (!confirm) {
                            dbItem.setSelection(false);
                            return;
                        }
                    }
                    if (!handleWithSelfConn(dbItem)) {
                        return;
                    }
                } else if (oldSelectedDb != null && !oldSelectedDb.getId().equals(NULL_DATABASE_ID)) {
                    boolean confirm = CommonUITool.openConfirmBox(editor.getSite().getShell(), Messages.changeDbConfirm);
                    if (!confirm) {
                        dbItem.setSelection(false);
                        return;
                    }
                }
                boolean valid = editor.resetJDBCConnection();
                if (valid) {
                    selectMenuItem(dbItem);
                    editor.getCombinedQueryComposite().getMultiDBQueryComp().setMainDatabase(dbItem.getDatabase());
                    editor.refreshQueryOptions();
                } else {
                    dbItem.setSelection(false);
                }
            }

            // on cm
            private void showDatabaseOnEditingWithHost(final CubridDatabase oldSelectedDb, final TreeViewer treeViewer, final Tree tree, final TreeItem itm) {
                if (itm != null && itm.getData() != null && itm.getData() instanceof ICubridNode && NodeType.SERVER.equals(((ICubridNode) itm.getData()).getType())) {
                    String serverName = ((ICubridNode) itm.getData()).getServer().getServerName();
                    if (serverName == null || oldSelectedDb == null || oldSelectedDb.getServer() == null) {
                        return;
                    }
                    if (!serverName.equals(oldSelectedDb.getServer().getName())) {
                        return;
                    }
                    if (treeViewer != null && !itm.getExpanded()) {
                        treeViewer.expandToLevel(itm.getData(), 1);
                    }
                    Display.getDefault().timerExec(100, new Runnable() {

                        public void run() {
                            showDatabaseOnEditingWithHostLoop(oldSelectedDb, tree, itm, 1);
                        }
                    });
                }
            }

            // on cqb
            private void showDatabaseOnEditing(CubridDatabase oldSelectedDb, TreeViewer treeViewer, Tree tree, TreeItem itm) {
                ISchemaNode cNode = (ISchemaNode) itm.getData();
                String user = cNode.getDatabase().getUserName();
                String dbName = cNode.getDatabase().getDatabaseInfo().getDbName();
                String hostName = cNode.getDatabase().getDatabaseInfo().getBrokerIP();
                if (user == null || dbName == null || hostName == null) {
                    return;
                }
                if (user.equals(oldSelectedDb.getUserName()) && dbName.equals(oldSelectedDb.getDatabaseInfo().getDbName()) && hostName.equals(oldSelectedDb.getDatabaseInfo().getBrokerIP())) {
                    tree.setSelection(itm);
                    tree.setTopItem(itm);
                    final String origDbName = itm.getText();
                    final TreeItem updatableItem = itm;
                    itm.setText("[ [ [ " + origDbName + " ] ] ]");
                    Display.getDefault().timerExec(500, new Runnable() {

                        public void run() {
                            updatableItem.setText("[ [ " + origDbName + " ] ]");
                        }
                    });
                    Display.getDefault().timerExec(530, new Runnable() {

                        public void run() {
                            updatableItem.setText("[ " + origDbName + " ]");
                        }
                    });
                    Display.getDefault().timerExec(560, new Runnable() {

                        public void run() {
                            updatableItem.setText(origDbName);
                        }
                    });
                }
            }

            private void showDatabaseOnEditingWithHostLoop(final CubridDatabase oldSelectedDb, final Tree tree, final TreeItem itm, final int count) {
                if (count > 10) {
                    return;
                }
                boolean ok = false;
                try {
                    for (int j = 0; j < itm.getItemCount(); j++) {
                        TreeItem sub = itm.getItem(j);
                        if (sub.getData() instanceof ICubridNode && NodeType.DATABASE_FOLDER.equals(((ICubridNode) sub.getData()).getType())) {
                            ok = true;
                            for (int k = 0; k < sub.getItemCount(); k++) {
                                TreeItem dbNode = sub.getItem(k);
                                if (dbNode == null || dbNode.getData() == null) {
                                    continue;
                                }
                                String dbName = ((ICubridNode) dbNode.getData()).getName();
                                if (dbName != null && dbName.equals(oldSelectedDb.getName())) {
                                    tree.setSelection(dbNode);
                                    tree.setTopItem(dbNode);
                                    final String origDbName = dbNode.getText();
                                    final TreeItem updatableItem = dbNode;
                                    dbNode.setText("[ [ [ " + origDbName + " ] ] ]");
                                    Display.getDefault().timerExec(500, new Runnable() {

                                        public void run() {
                                            updatableItem.setText("[ [ " + origDbName + " ] ]");
                                        }
                                    });
                                    Display.getDefault().timerExec(530, new Runnable() {

                                        public void run() {
                                            updatableItem.setText("[ " + origDbName + " ]");
                                        }
                                    });
                                    Display.getDefault().timerExec(560, new Runnable() {

                                        public void run() {
                                            updatableItem.setText(origDbName);
                                        }
                                    });
                                }
                            }
                        }
                    }
                } catch (Exception ignored) {
                    ok = false;
                }
                if (!ok) {
                    final int nextCount = count + 1;
                    Display.getDefault().timerExec(500, new Runnable() {

                        public void run() {
                            showDatabaseOnEditingWithHostLoop(oldSelectedDb, tree, itm, nextCount);
                        }
                    });
                }
            }

            // on group mode
            private void showDatabaseOnEditingWithHostOnGroup(final DatabaseMenuItem dbItem, final CubridDatabase oldSelectedDb, final TreeViewer treeViewer, final Tree tree, final TreeItem item) {
                if (item == null || item.getData() == null) {
                    return;
                }
                if (item.getData() instanceof CubridGroupNode) {
                    CubridGroupNode grp = (CubridGroupNode) item.getData();
                    if (lastSelectedDatabaseMenu == null || lastSelectedDatabaseMenu.getGroupName() == null || grp == null || !lastSelectedDatabaseMenu.getGroupName().equals(grp.getName())) {
                        return;
                    }
                    if (treeViewer != null && !item.getExpanded()) {
                        treeViewer.expandToLevel(item.getData(), 1);
                        Display.getDefault().timerExec(500, new Runnable() {

                            public void run() {
                                for (int i = 0; i < item.getItemCount(); i++) {
                                    final TreeItem itm = item.getItem(i);
                                    if (itm == null) {
                                        continue;
                                    }
                                    showDatabaseOnEditingWithHost(oldSelectedDb, treeViewer, tree, itm);
                                }
                            }
                        });
                    } else {
                        for (int i = 0; i < item.getItemCount(); i++) {
                            final TreeItem itm = item.getItem(i);
                            if (itm == null) {
                                continue;
                            }
                            showDatabaseOnEditingWithHost(oldSelectedDb, treeViewer, tree, itm);
                        }
                    }
                } else {
                    showDatabaseOnEditingWithHost(oldSelectedDb, treeViewer, tree, item);
                }
            }

            // on group mode
            private void showDatabaseOnEditingOnGroup(final CubridDatabase oldSelectedDb, final TreeViewer treeViewer, final Tree tree, final TreeItem item) {
                if (item == null || item.getData() == null) {
                    return;
                }
                if (item.getData() instanceof CubridGroupNode) {
                    CubridGroupNode grp = (CubridGroupNode) item.getData();
                    if (lastSelectedDatabaseMenu == null || lastSelectedDatabaseMenu.getGroupName() == null || grp == null || !lastSelectedDatabaseMenu.getGroupName().equals(grp.getName())) {
                        return;
                    }
                    if (treeViewer != null && !item.getExpanded()) {
                        treeViewer.expandToLevel(item.getData(), 1);
                        Display.getDefault().timerExec(500, new Runnable() {

                            public void run() {
                                for (int i = 0; i < item.getItemCount(); i++) {
                                    final TreeItem itm = item.getItem(i);
                                    if (itm == null) {
                                        continue;
                                    }
                                    showDatabaseOnEditing(oldSelectedDb, treeViewer, tree, itm);
                                }
                            }
                        });
                    } else {
                        for (int i = 0; i < item.getItemCount(); i++) {
                            final TreeItem itm = item.getItem(i);
                            if (itm == null) {
                                continue;
                            }
                            showDatabaseOnEditing(oldSelectedDb, treeViewer, tree, itm);
                        }
                    }
                } else {
                    showDatabaseOnEditing(oldSelectedDb, treeViewer, tree, item);
                }
            }
        });
    }
//		multiSelectItem.addSelectionListener(new SelectionAdapter() {
//			
//			public void widgetSelected(SelectionEvent e) {
//				DatabaseSelectionDialog dialog = new DatabaseSelectionDialog(multiSelectItem.getParent().getShell());
//				dialog.setItems(dbSelectionMenu.getItems());
//				dialog.open();
//				CubridDatabase[] databases = dialog.getSelectedDbItem();
//				if (databases.length == 0) {
//					return;
//				}
//				Map<CubridDatabase, DatabaseMenuItem> allItems = new HashMap<CubridDatabase, DatabaseMenuItem>();
//				for (MenuItem item : dbSelectionMenu.getItems()) {
//					if (item instanceof DatabaseMenuItem) {
//						DatabaseMenuItem dbItem = (DatabaseMenuItem)item;
//						dbItem.setSelection(false);
//						allItems.put(dbItem.getDatabase(), dbItem);
//					}
//				}
//				List<DatabaseMenuItem> selected = new ArrayList<DatabaseMenuItem>();
//				for (CubridDatabase db : databases) {
//					if (!allItems.containsKey(db)) {
//						continue;
//					}
//					allItems.get(db).setSelection(true);
//					selected.add(allItems.get(db));
//				}
//				selectMenuItem(selected.toArray(new DatabaseMenuItem[0]));
//			}
//		});
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) TreeViewer(org.eclipse.jface.viewers.TreeViewer) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) MenuItem(org.eclipse.swt.widgets.MenuItem) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridNavigatorView(com.cubrid.common.ui.common.navigator.CubridNavigatorView) CubridGroupNode(com.cubrid.common.ui.spi.model.CubridGroupNode) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Tree(org.eclipse.swt.widgets.Tree) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 4 with CubridNavigatorView

use of com.cubrid.common.ui.common.navigator.CubridNavigatorView in project cubrid-manager by CUBRID.

the class ShowSchemaAction method run.

/**
	 * @see org.eclipse.jface.action.Action#run() Override the run method in
	 *      order to complete showing brokers status server to a broker
	 */
public void run() {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        showError();
        return;
    }
    IEditorPart editor = window.getActivePage().getActiveEditor();
    if (editor == null) {
        showError();
        return;
    }
    if (!(editor instanceof QueryEditorPart)) {
        showError();
        return;
    }
    QueryEditorPart queryEditorPart = (QueryEditorPart) editor;
    CubridDatabase db = queryEditorPart.getSelectedDatabase();
    if (db == null || !db.isLogined()) {
        showError();
        return;
    }
    String tableName = queryEditorPart.getSelectedText();
    if (tableName == null) {
        showError();
        return;
    }
    DatabaseInfo databaseInfo = db.getDatabaseInfo();
    if (databaseInfo == null) {
        showError();
        return;
    }
    CubridNavigatorView mainNav = CubridNavigatorView.findNavigationView();
    if (mainNav != null) {
        mainNav.showQuickView(databaseInfo, tableName, true);
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) CubridNavigatorView(com.cubrid.common.ui.common.navigator.CubridNavigatorView) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) IEditorPart(org.eclipse.ui.IEditorPart) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 5 with CubridNavigatorView

use of com.cubrid.common.ui.common.navigator.CubridNavigatorView in project cubrid-manager by CUBRID.

the class OpenTargetAction method run.

public void run() {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return;
    }
    final Object[] obj = this.getSelectedObj();
    if (!isSupported(obj)) {
        setEnabled(false);
        return;
    }
    for (int i = 0; i < obj.length; i++) {
        if (!NodeUtil.isCubridNode(obj[i])) {
            continue;
        }
        ICubridNode node = (ICubridNode) obj[i];
        if (NodeUtil.isTableViewNode(node)) {
            DefaultSchemaNode table = (DefaultSchemaNode) obj[i];
            showObjectInfo(table);
        } else if (NodeUtil.isTableFolderNode(node)) {
            CubridNavigatorView view = CubridNavigatorView.findNavigationView();
            if (view == null) {
                return;
            }
            //if not expand ,expand the node and wait until all children be added
            TreeViewer treeViewer = view.getViewer();
            if (!treeViewer.getExpandedState(node)) {
                treeViewer.expandToLevel(node, 1);
                while (node.getChildren().size() == 0) {
                    ThreadUtil.sleep(500);
                }
            }
            showTableDashboard(NodeUtil.getCubridDatabase(node));
        } else if (NodeUtil.isViewFolderNode(node)) {
            CubridNavigatorView view = CubridNavigatorView.getNavigatorView("com.cubrid.cubridquery.connection.navigator");
            if (view == null) {
                view = CubridNavigatorView.getNavigatorView("com.cubrid.cubridmanager.host.navigator");
            }
            if (view == null) {
                return;
            }
            //if not expand ,expand the node and wait until all children be added
            TreeViewer treeViewer = view.getViewer();
            if (!treeViewer.getExpandedState(node)) {
                treeViewer.expandToLevel(node, 1);
                while (node.getChildren().size() == 0) {
                    ThreadUtil.sleep(500);
                }
            }
            openViewsDetailInfoEditor(NodeUtil.getCubridDatabase(node));
        } else if (NodeUtil.isSerialFolderNode(node)) {
            CubridNavigatorView view = CubridNavigatorView.findNavigationView();
            if (view == null) {
                return;
            }
            //if not expand ,expand the node and wait until all children be added
            TreeViewer treeViewer = view.getViewer();
            if (!treeViewer.getExpandedState(node)) {
                treeViewer.expandToLevel(node, 1);
                while (node.getChildren().size() == 0) {
                    ThreadUtil.sleep(500);
                }
            }
            openSerialsDetailInfoEditor(NodeUtil.getCubridDatabase(node), null);
        } else if (NodeUtil.isTriggerFolderNode(node)) {
            CubridNavigatorView view = CubridNavigatorView.findNavigationView();
            if (view == null) {
                return;
            }
            //if not expand ,expand the node and wait until all children be added
            TreeViewer treeViewer = view.getViewer();
            if (!treeViewer.getExpandedState(node)) {
                treeViewer.expandToLevel(node, 1);
                while (node.getChildren().size() == 0) {
                    ThreadUtil.sleep(500);
                }
            }
            openTriggersDetailInfoEditor(NodeUtil.getCubridDatabase(node));
        } else if (NodeUtil.isUserFolderNode(node)) {
            CubridNavigatorView view = CubridNavigatorView.findNavigationView();
            if (view == null) {
                return;
            }
            //if not expand ,expand the node and wait until all children be added
            TreeViewer treeViewer = view.getViewer();
            if (!treeViewer.getExpandedState(node)) {
                treeViewer.expandToLevel(node, 1);
                while (node.getChildren().size() == 0) {
                    ThreadUtil.sleep(500);
                }
            }
            openUsersDetailInfoEditor(NodeUtil.getCubridDatabase(node));
        }
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) 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)

Aggregations

CubridNavigatorView (com.cubrid.common.ui.common.navigator.CubridNavigatorView)50 TreeViewer (org.eclipse.jface.viewers.TreeViewer)36 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)25 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)22 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)21 CubridGroupNode (com.cubrid.common.ui.spi.model.CubridGroupNode)15 CubridServer (com.cubrid.common.ui.spi.model.CubridServer)13 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)12 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)8 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)7 TreeItem (org.eclipse.swt.widgets.TreeItem)7 ArrayList (java.util.ArrayList)6 Tree (org.eclipse.swt.widgets.Tree)6 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)6 DatabaseEditorConfig (com.cubrid.common.ui.spi.model.DatabaseEditorConfig)5 ISelection (org.eclipse.jface.viewers.ISelection)5 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)4 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)4 WorkbenchWindow (org.eclipse.ui.internal.WorkbenchWindow)4 DatabaseMenuItem (com.cubrid.common.ui.query.control.DatabaseMenuItem)3