use of com.cubrid.common.ui.query.control.DatabaseMenuItem in project cubrid-manager by CUBRID.
the class CMDatabaseNavigatorMenu method loadNavigatorMenu.
/**
* load all database on all server. if not login or database not started,
* the item disabled.
*
* @param dbSelectionMenu
*/
public void loadNavigatorMenu(Menu dbSelectionMenu) {
setSelectedImage(CubridManagerUIPlugin.getImage("/icons/navigator/eclipse_dot.png"));
CubridNavigatorView navigatorView = CubridNavigatorView.getNavigatorView(CubridHostNavigatorView.ID);
boolean isShowGroup = navigatorView == null ? false : navigatorView.isShowGroup();
List<CubridGroupNode> groupList = CMGroupNodePersistManager.getInstance().getAllGroupNodes();
if (groupList == null || groupList.isEmpty()) {
return;
}
Collections.sort(groupList, new Comparator<CubridGroupNode>() {
public int compare(CubridGroupNode o1, CubridGroupNode o2) {
if (o1 == null || o2 == null || o1.getLabel() == null || o2.getLabel() == null) {
return 0;
}
return o1.getLabel().compareToIgnoreCase(o2.getLabel());
}
});
int count = 0;
for (CubridGroupNode groupNode : groupList) {
// if (NodeFilterManager.getInstance().isHidden(groupNode)) {
// continue;
// }
List<ICubridNode> nodeList = groupNode.getChildren();
if (nodeList == null || nodeList.isEmpty()) {
continue;
}
DatabaseMenuItem groupMenuItem = null;
Menu groupSub = null;
String groupName = null;
if (isShowGroup) {
groupName = groupNode.getLabel();
groupMenuItem = new DatabaseMenuItem(groupNode.getId(), dbSelectionMenu, SWT.CASCADE);
groupMenuItem.setImage(CubridManagerUIPlugin.getImage("/icons/navigator/group.png"));
groupMenuItem.setText(groupName);
groupSub = new Menu(dbSelectionMenu);
groupMenuItem.setMenu(groupSub);
}
Collections.sort(nodeList, new Comparator<ICubridNode>() {
public int compare(ICubridNode o1, ICubridNode o2) {
if (o1 == null || o2 == null || o1.getLabel() == null || o2.getLabel() == null) {
return 0;
}
return o1.getLabel().compareToIgnoreCase(o2.getLabel());
}
});
int itemCountInGroup = 0;
for (ICubridNode node : nodeList) {
// }
if (node instanceof CubridServer) {
CubridServer server = (CubridServer) node;
ICubridNode databaseFolderNode = server.getChild(server.getId() + ICubridNodeLoader.NODE_SEPARATOR + CubridServerLoader.DATABASE_FOLDER_ID);
if (databaseFolderNode == null) {
continue;
}
// if (NodeFilterManager.getInstance().isHidden(databaseFolderNode)) {
// continue;
// }
ICubridNode[] dbs = databaseFolderNode.getChildren(new NullProgressMonitor());
if (dbs == null || dbs.length == 0) {
continue;
}
String serverName = server.getLabel();
DatabaseMenuItem serverMenuItem = null;
Menu serverSub = null;
if (isShowGroup) {
serverMenuItem = new DatabaseMenuItem(server.getId(), groupSub, SWT.CASCADE);
serverMenuItem.setImage(CubridManagerUIPlugin.getImage("/icons/navigator/host.png"));
serverMenuItem.setText(serverName);
serverSub = new Menu(groupSub);
serverMenuItem.setMenu(serverSub);
} else {
serverMenuItem = new DatabaseMenuItem(server.getId(), dbSelectionMenu, SWT.CASCADE);
serverMenuItem.setImage(CubridManagerUIPlugin.getImage("/icons/navigator/host.png"));
serverMenuItem.setText(serverName);
serverSub = new Menu(dbSelectionMenu);
serverMenuItem.setMenu(serverSub);
}
count++;
for (ICubridNode database : dbs) {
// if (NodeFilterManager.getInstance().isHidden(database)) {
// continue;
// }
CubridDatabase db = (CubridDatabase) database;
if (!db.isLogined()) {
continue;
}
itemCountInGroup++;
DatabaseMenuItem dbItem = new DatabaseMenuItem(database.getId(), serverSub, SWT.RADIO);
dbItem.setText(database.getLabel());
dbItem.setDatabase((CubridDatabase) database);
dbItem.setEnabled(db.isLogined() && db.getRunningType() == DbRunningType.CS);
dbItem.setGroupName(groupName);
count++;
}
}
}
if (itemCountInGroup <= 0 && groupSub != null && groupMenuItem != null) {
groupSub.dispose();
groupMenuItem.dispose();
continue;
}
}
if (count > 0) {
new MenuItem(dbSelectionMenu, SWT.SEPARATOR);
}
}
use of com.cubrid.common.ui.query.control.DatabaseMenuItem in project cubrid-manager by CUBRID.
the class ERDBNavigatorMenuWrapper method selectMenuItem.
/**
* target a database selection change
*
* @param item
* DatabaseMenuItem
*/
public void selectMenuItem(DatabaseMenuItem item) {
DatabaseMenuItem tmpItem = item;
if (tmpItem != null) {
if (selectedMenuItem != null && !selectedMenuItem.isDisposed()) {
selectedMenuItem.setSelection(false);
}
if (listener != null) {
Event e = new Event();
e.data = tmpItem.getDatabase();
listener.handleEvent(e);
}
tmpItem.setSelection(true);
selectedMenuItem = tmpItem;
setText(tmpItem);
selectdDb = tmpItem.getDatabase();
/* Save current selectDB */
lastSelectdDb = selectdDb;
lastUser = (selectdDb == null ? null : selectdDb.getUserName());
LayoutManager.getInstance().getTitleLineContrItem().changeTitleForQueryEditor(selectdDb);
LayoutManager.getInstance().getStatusLineContrItem().changeStuatusLineForViewOrEditPart(selectdDb, erSchemaEditor);
erSchemaEditor.changeDataBase(lastSelectdDb);
}
}
use of com.cubrid.common.ui.query.control.DatabaseMenuItem in project cubrid-manager by CUBRID.
the class ERDBNavigatorMenuWrapper method setDatabase.
/**
* Set the database
*
* @param database
* CubridDatabase
*/
public void setDatabase(CubridDatabase database) {
// show the selected database menu item
if ((database.isLogined() && database.getRunningType() == DbRunningType.CS)) {
DatabaseMenuItem item = findById(database.getId());
selectMenuItem(item);
}
}
use of com.cubrid.common.ui.query.control.DatabaseMenuItem in project cubrid-manager by CUBRID.
the class ERDBNavigatorMenuWrapper method addSelectionListener.
/**
* Add selection listener
*/
public void addSelectionListener() {
// FIXME need modulation because of
// complicated codes
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;
}
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 mode
if (ApplicationType.CUBRID_MANAGER.equals(PerspectiveManager.getInstance().getCurrentMode())) {
CubridNavigatorView navigatorView = CubridNavigatorView.getNavigatorView(CubridNavigatorView.ID_CM);
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;
}
} else if (ApplicationType.CUBRID_QUERY_BROWSER.equals(PerspectiveManager.getInstance().getCurrentMode())) {
// on CQB mode
CubridNavigatorView navigatorView = CubridNavigatorView.getNavigatorView(CubridNavigatorView.ID_CQB);
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(erSchemaEditor.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(erSchemaEditor.getSite().getShell(), Messages.changeDbConfirm);
if (!confirm) {
dbItem.setSelection(false);
return;
}
}
selectMenuItem(dbItem);
}
// 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);
}
}
});
}
}
use of com.cubrid.common.ui.query.control.DatabaseMenuItem in project cubrid-manager by CUBRID.
the class CQDatabaseNavigatorMenu method loadNavigatorMenu.
/**
* load all database on all server. if not login or database not started,
* the item disabled.
*
* @param dbSelectionMenu
*/
public void loadNavigatorMenu(Menu dbSelectionMenu) {
setSelectedImage(CubridQueryUIPlugin.getImage("/icons/navigator/eclipse_dot.png"));
CubridNavigatorView navigatorView = CubridNavigatorView.getNavigatorView(CubridQueryNavigatorView.ID);
boolean isShowGroup = navigatorView == null ? false : navigatorView.isShowGroup();
List<CubridGroupNode> groupList = CQBGroupNodePersistManager.getInstance().getAllGroupNodes();
if (groupList == null || groupList.isEmpty()) {
return;
}
Collections.sort(groupList, new Comparator<CubridGroupNode>() {
public int compare(CubridGroupNode o1, CubridGroupNode o2) {
if (o1 == null || o2 == null || o1.getLabel() == null || o2.getLabel() == null) {
return 0;
}
return o1.getLabel().compareToIgnoreCase(o2.getLabel());
}
});
int count = 0;
for (CubridGroupNode groupNode : groupList) {
// if (NodeFilterManager.getInstance().isHidden(groupNode)) {
// continue;
// }
List<ICubridNode> nodeList = groupNode.getChildren();
if (nodeList == null || nodeList.isEmpty()) {
continue;
}
DatabaseMenuItem groupMenuItem = null;
Menu groupSub = null;
String groupName = null;
if (isShowGroup) {
groupName = groupNode.getLabel();
groupMenuItem = new DatabaseMenuItem(groupNode.getId(), dbSelectionMenu, SWT.CASCADE);
groupMenuItem.setImage(CubridQueryUIPlugin.getImage("/icons/navigator/group.png"));
groupMenuItem.setText(groupNode.getLabel());
groupSub = new Menu(dbSelectionMenu);
groupMenuItem.setMenu(groupSub);
}
Collections.sort(nodeList, new Comparator<ICubridNode>() {
public int compare(ICubridNode o1, ICubridNode o2) {
if (o1 == null || o2 == null || o1.getLabel() == null || o2.getLabel() == null) {
return 0;
}
return o1.getLabel().compareToIgnoreCase(o2.getLabel());
}
});
int itemCountInGroup = 0;
for (ICubridNode node : nodeList) {
// }
if (node instanceof CubridDatabase) {
CubridDatabase database = (CubridDatabase) node;
if (!database.isLogined()) {
continue;
}
itemCountInGroup++;
DatabaseMenuItem dbItem = null;
if (isShowGroup) {
dbItem = new DatabaseMenuItem(database.getId(), groupSub, SWT.RADIO);
} else {
dbItem = new DatabaseMenuItem(database.getId(), dbSelectionMenu, SWT.RADIO);
}
dbItem.setText(database.getLabelWithUser());
dbItem.setDatabase((CubridDatabase) database);
dbItem.setEnabled(database.isLogined() && database.getRunningType() == DbRunningType.CS);
dbItem.setGroupName(groupName);
count++;
}
}
// If it has no active item on the group, it's group should be disposed
if (isShowGroup && itemCountInGroup <= 0 && groupSub != null && groupMenuItem != null) {
groupSub.dispose();
groupMenuItem.dispose();
}
}
if (count > 0) {
new MenuItem(dbSelectionMenu, SWT.SEPARATOR);
}
}
Aggregations