use of org.eclipse.swt.widgets.TreeItem in project cubrid-manager by CUBRID.
the class DatabaseSelectionDialog method selectChild.
private void selectChild(TreeItem item, List<CubridDatabase> databases) {
if (item.getData(KEY_DATABASE) != null && databases.contains(item.getData(KEY_DATABASE))) {
item.getParentItem().setChecked(true);
item.setChecked(true);
checkItemChild(item, true);
databases.remove(item.getData(KEY_DATABASE));
}
if (item.getItemCount() == 0)
return;
for (TreeItem cItem : item.getItems()) {
selectChild(cItem, databases);
}
}
use of org.eclipse.swt.widgets.TreeItem in project cubrid-manager by CUBRID.
the class DatabaseSelectionDialog method initTreeData.
private void initTreeData() {
if (initDatabase == null)
return;
Map<String, TreeItem> treeMap = new HashMap<String, TreeItem>();
for (CubridDatabase item : initDatabase) {
CubridDatabase db = item;
if (db.getServer() == null)
continue;
TreeItem pItem = treeMap.get(db.getServer().getServerName());
if (pItem == null) {
pItem = new TreeItem(dbTree, SWT.NONE);
pItem.setImage(CommonUIPlugin.getImage("icons/navigator/database_group.png"));
pItem.setText(db.getServer().getServerName());
treeMap.put(db.getServer().getServerName(), pItem);
}
if (!db.isLogined())
return;
TreeItem treeItem = new TreeItem(pItem, SWT.NONE);
treeItem.setText(db.getLabel());
treeItem.setImage(CommonUIPlugin.getImage(db.getStartAndLoginIconPath().trim()));
treeItem.setData(KEY_DATABASE, db);
}
}
use of org.eclipse.swt.widgets.TreeItem in project cubrid-manager by CUBRID.
the class DatabaseSelectionDialog method widgetSelected.
public void widgetSelected(SelectionEvent e) {
if (!(e.widget instanceof Button))
return;
TYPE type = (TYPE) e.widget.getData(KEY_ID);
switch(type) {
case SELECT:
boolean select = Boolean.parseBoolean(e.widget.getData(KEY_VALUE).toString());
for (TreeItem item : dbTree.getItems()) {
item.setChecked(select);
checkItemChild(item, select);
}
break;
case EXPAND:
boolean expand = Boolean.parseBoolean(e.widget.getData(KEY_VALUE).toString());
for (TreeItem item : dbTree.getItems()) {
item.setExpanded(expand);
}
break;
}
}
use of org.eclipse.swt.widgets.TreeItem 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 org.eclipse.swt.widgets.TreeItem in project azure-tools-for-java by Microsoft.
the class ServiceExplorerView method hookMouseActions.
private void hookMouseActions() {
viewer.addDoubleClickListener(new IDoubleClickListener() {
public void doubleClick(DoubleClickEvent event) {
doubleClickAction.run();
}
});
Tree tree = (Tree) viewer.getControl();
tree.addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent e) {
if (e.button == 1) {
// left button
TreeItem[] selection = ((Tree) e.widget).getSelection();
if (selection.length > 0) {
TreeItem item = ((Tree) e.widget).getSelection()[0];
Node node = ((TreeNode) item.getData()).node;
// we do not propagate the click event to it
if (!node.isLoading()) {
node.getClickAction().fireNodeActionEvent();
}
}
}
}
});
}
Aggregations