use of org.eclipse.swt.widgets.MenuItem 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]));
// }
// });
}
use of org.eclipse.swt.widgets.MenuItem in project cubrid-manager by CUBRID.
the class DatabaseSelectionDialog method setItems.
public void setItems(MenuItem[] items) {
List<CubridDatabase> database = new ArrayList<CubridDatabase>();
for (MenuItem item : items) {
DatabaseMenuItem dbItem = (DatabaseMenuItem) item;
if (dbItem.getStyle() != SWT.CHECK) {
continue;
}
database.add(dbItem.getDatabase());
}
initDatabase = database.toArray(new CubridDatabase[0]);
}
use of org.eclipse.swt.widgets.MenuItem in project cubrid-manager by CUBRID.
the class FilterResultContrItem method addSelectionListener.
/**
* Add selection listener
*
*/
private void addSelectionListener() {
MenuItem[] items = filterMenu.getItems();
for (final MenuItem item : items) {
if (item.equals(moreMenuItem)) {
continue;
}
item.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
if (event.widget.equals(caseSensitiveItem)) {
caseSensitiveItem.setSelection(true);
caseInSensitiveItem.setSelection(false);
} else if (event.widget.equals(caseInSensitiveItem)) {
caseSensitiveItem.setSelection(false);
caseInSensitiveItem.setSelection(true);
}
if (event.widget.equals(matchFromStartItem)) {
matchFromStartItem.setSelection(true);
matchExactItem.setSelection(false);
matchAnyWhereItem.setSelection(false);
} else if (event.widget.equals(matchExactItem)) {
matchExactItem.setSelection(true);
matchFromStartItem.setSelection(false);
matchAnyWhereItem.setSelection(false);
} else if (event.widget.equals(matchAnyWhereItem)) {
matchAnyWhereItem.setSelection(true);
matchFromStartItem.setSelection(false);
matchExactItem.setSelection(false);
}
doFilter();
}
});
}
}
use of org.eclipse.swt.widgets.MenuItem in project cubrid-manager by CUBRID.
the class BLOBCellPopupDialog method loadProgramMenu.
/**
*
* Load the program menus
*
*/
private void loadProgramMenu() {
if (programMenu != null) {
programMenu.dispose();
}
programMenu = new Menu(getShell(), SWT.POP_UP);
String fileType = getFileType();
// Load the default application
if (fileType != null && fileType.trim().length() > 0) {
final Program program = Program.findProgram(fileType);
if (program != null && program.getName() != null && program.getName().trim().length() > 0) {
programMenuItem = new MenuItem(programMenu, SWT.NONE);
programMenuItem.setText(program.getName());
ImageData imageData = program.getImageData();
if (imageData != null) {
final Image image = new Image(getShell().getDisplay(), imageData);
programMenuItem.setImage(image);
programMenu.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
image.dispose();
}
});
}
programMenuItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
openByExternalProgram(program);
}
});
new MenuItem(programMenu, SWT.SEPARATOR);
}
}
// Load the other applications
Program[] programs = Program.getPrograms();
if (programs != null) {
for (final Program program : programs) {
String name = program.getName();
if (name == null || name.trim().length() == 0) {
continue;
}
if (programMenuItem != null && programMenuItem.getText().equals(name.trim())) {
continue;
}
final MenuItem selectProgramMenuItem = new MenuItem(programMenu, SWT.NONE);
selectProgramMenuItem.setText(name);
ImageData imageData = program.getImageData();
if (imageData != null) {
final Image image = new Image(getShell().getDisplay(), imageData);
selectProgramMenuItem.setImage(image);
selectProgramMenuItem.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
image.dispose();
}
});
}
selectProgramMenuItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
openByExternalProgram(program);
}
});
}
}
Rectangle rect = openByExternalBtn.getBounds();
Point pt = new Point(rect.x, rect.y + rect.height);
pt = openByExternalBtn.getParent().toDisplay(pt);
programMenu.setLocation(pt);
programMenu.setVisible(true);
}
use of org.eclipse.swt.widgets.MenuItem in project cubrid-manager by CUBRID.
the class RunSQLFileDialog method registerContextMenu.
/**
* register context menu
*/
private void registerContextMenu() {
sqlFileTableViewer.getTable().addFocusListener(new FocusAdapter() {
public void focusGained(FocusEvent event) {
ActionManager.getInstance().changeFocusProvider(sqlFileTableViewer.getTable());
}
});
MenuManager menuManager = new MenuManager();
menuManager.setRemoveAllWhenShown(true);
Menu contextMenu = menuManager.createContextMenu(sqlFileTableViewer.getTable());
sqlFileTableViewer.getTable().setMenu(contextMenu);
Menu menu = new Menu(getShell(), SWT.POP_UP);
final MenuItem itemDelete = new MenuItem(menu, SWT.PUSH);
itemDelete.setText("delete");
itemDelete.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
List<String> deleteFiles = new ArrayList<String>();
for (int i = 0; i < sqlFileTableViewer.getTable().getSelectionIndices().length; i++) {
int index = sqlFileTableViewer.getTable().getSelectionIndices()[i];
deleteFiles.add(filesList.get(index));
}
filesList.removeAll(deleteFiles);
sqlFileTableViewer.setInput(filesList);
sqlFileTableViewer.refresh();
}
});
sqlFileTableViewer.getTable().setMenu(menu);
Menu dbTablecontextMenu = menuManager.createContextMenu(databaseTableViewer.getTable());
databaseTableViewer.getTable().setMenu(dbTablecontextMenu);
Menu dbTableMenu = new Menu(getShell(), SWT.POP_UP);
final MenuItem dbTableItemDelete = new MenuItem(dbTableMenu, SWT.PUSH);
dbTableItemDelete.setText("delete");
dbTableItemDelete.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
List<CubridDatabase> deleteCubridDatabase = new ArrayList<CubridDatabase>();
for (int i = 0; i < databaseTableViewer.getTable().getSelectionIndices().length; i++) {
int index = databaseTableViewer.getTable().getSelectionIndices()[i];
deleteCubridDatabase.add(cubridDatabases[index]);
}
List<CubridDatabase> dbList = Arrays.asList(cubridDatabases);
ArrayList<CubridDatabase> newDbList = new ArrayList<CubridDatabase>();
for (CubridDatabase cubridDatabase : dbList) {
if (deleteCubridDatabase.contains(cubridDatabase)) {
continue;
}
newDbList.add(cubridDatabase);
}
cubridDatabases = newDbList.toArray(new CubridDatabase[newDbList.size()]);
databaseTableViewer.setInput(cubridDatabases);
databaseTableViewer.refresh();
}
});
sqlFileTableViewer.getTable().setMenu(menu);
databaseTableViewer.getTable().setMenu(dbTableMenu);
runSQLFileDialogDNDController = new RunSQLFileDialogDNDController(this);
runSQLFileDialogDNDController.registerDropTarget();
}
Aggregations