Search in sources :

Example 6 with ISchemaNode

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

the class AddUserAction method isSupported.

/**
	 *
	 * @see com.cubrid.common.ui.spi.action.ISelectionAction#isSupported(java
	 *      .lang.Object)
	 * @param obj the Object
	 * @return <code>true</code> if support this obj;<code>false</code>
	 *         otherwise
	 */
public boolean isSupported(Object obj) {
    if (!(obj instanceof ISchemaNode)) {
        return false;
    }
    ISchemaNode node = (ISchemaNode) obj;
    CubridDatabase database = node.getDatabase();
    if (database != null && database.getRunningType() == DbRunningType.CS && database.isLogined()) {
        DbUserInfo dbUserInfo = database.getDatabaseInfo().getAuthLoginedDbUserInfo();
        if (dbUserInfo != null && dbUserInfo.isDbaAuthority()) {
            return true;
        }
    }
    return false;
}
Also used : DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 7 with ISchemaNode

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

the class OpenSchemaEditorAction method getDBNodes.

/**
	 * Get data base node that related selected objects, Including login and
	 * logout database.
	 *
	 * @param objs
	 * @return
	 */
private CubridDatabase[] getDBNodes(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) {
                // database node
                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 8 with ISchemaNode

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

the class ERDNDController method getSelectedSchemaInfos.

/**
	 * Replace the SQL, and get clone SchemaInfo list
	 *
	 * @return boolean
	 */
private List<SchemaInfo> getSelectedSchemaInfos() {
    // FIXME move this logic to core module
    List<ISchemaNode> schemaNodeList = new ArrayList<ISchemaNode>();
    List<SchemaInfo> validSchemaInfoList = new ArrayList<SchemaInfo>();
    boolean isValid = fillInSelectedNode(schemaNodeList);
    if (!isValid || (schemaNodeList.isEmpty())) {
        return null;
    }
    boolean isSame = checkSourceDB(schemaNodeList);
    if (!isSame) {
        CommonUITool.openInformationBox(com.cubrid.common.ui.er.Messages.errDragTableSource);
        return null;
    }
    Connection conn = null;
    String err = null;
    try {
        conn = JDBCConnectionManager.getConnection(schemaNodeList.get(0).getDatabase().getDatabaseInfo(), false);
        // Get all tables SchemaInfo
        for (ISchemaNode node : schemaNodeList) {
            SchemaInfo tableInfo = getSchemaInfo(node, conn);
            if (tableInfo == null) {
                String error = node.getDatabase().getDatabaseInfo().getErrorMessage();
                if (StringUtil.isEmpty(error)) {
                    error = com.cubrid.common.ui.er.Messages.errNotExistDraggedTable;
                }
                CommonUITool.openErrorBox(error);
                return null;
            }
            validSchemaInfoList.add(tableInfo);
        }
    } catch (Exception e) {
        LOGGER.error("", e);
        err = e.getMessage();
    } finally {
        QueryUtil.freeQuery(conn);
    }
    if (err != null) {
        CommonUITool.openErrorBox(editor.getGraphicalControl().getShell(), err);
    }
    return validSchemaInfoList;
}
Also used : ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) SQLException(java.sql.SQLException) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 9 with ISchemaNode

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

the class ViewDashboardEditorPart method dropView.

public void dropView() {
    TableItem[] items = viewsDetailInfoTable.getTable().getSelection();
    if (items.length > 0) {
        List<ISchemaNode> selectNodeList = new ArrayList<ISchemaNode>();
        for (TableItem item : items) {
            ViewDetailInfo viewInfo = (ViewDetailInfo) item.getData();
            Set<String> typeSet = new HashSet<String>();
            typeSet.add(NodeType.USER_VIEW);
            ICubridNode viewNode = CommonUITool.findNode(database, typeSet, viewInfo.getViewName());
            selectNodeList.add((ISchemaNode) viewNode);
        }
        if (selectNodeList.size() > 0) {
            DropViewAction action = (DropViewAction) ActionManager.getInstance().getAction(DropViewAction.ID);
            ISchemaNode[] nodeArr = new ISchemaNode[selectNodeList.size()];
            action.run(selectNodeList.toArray(nodeArr));
            if (!action.isCanceledTask()) {
                refresh();
            }
        }
    } else {
        CommonUITool.openWarningBox(Messages.viewDetailInfoPartTableNoSelectionMsg);
    }
}
Also used : ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) TableItem(org.eclipse.swt.widgets.TableItem) ArrayList(java.util.ArrayList) ViewDetailInfo(com.cubrid.common.core.common.model.ViewDetailInfo) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) HashSet(java.util.HashSet) DropViewAction(com.cubrid.common.ui.cubrid.table.action.DropViewAction)

Example 10 with ISchemaNode

use of com.cubrid.common.ui.spi.model.ISchemaNode 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)

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