use of com.cubrid.common.ui.spi.model.CubridDatabase 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();
}
use of com.cubrid.common.ui.spi.model.CubridDatabase in project cubrid-manager by CUBRID.
the class RunSQLFileDialog method buttonPressed.
/**
* When press button,call it
*
* @param buttonId the button id
*/
protected void buttonPressed(int buttonId) {
if (buttonId == IDialogConstants.OK_ID) {
if (!validate()) {
return;
}
for (CubridDatabase database : cubridDatabases) {
RunSQLFileEditorInput input = new RunSQLFileEditorInput(database, filesList, fileCharsetCombo.getText(), threadCountSpinner.getSelection(), commitCountSpinner.getSelection(), saveErrExcelPath.getText());
try {
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
workbenchWindow.getActivePage().openEditor(input, RunSQLFileViewPart.ID);
} catch (Exception e) {
LOGGER.error("", e);
}
}
}
setReturnCode(buttonId);
close();
}
use of com.cubrid.common.ui.spi.model.CubridDatabase in project cubrid-manager by CUBRID.
the class NavigatorViewSorter method compare.
/**
* @see <code>ViewerSorter</code>
*
* @param viewer
* Viewer
* @param e1
* Object
* @param e2
* Object
*
* @return int
*/
public int compare(Viewer viewer, Object e1, Object e2) {
if (e1 == null && e2 == null) {
return 0;
}
if (e1 == null) {
return -1;
}
if (e2 == null) {
return -1;
}
if (!(e1 instanceof ICubridNode) || !(e2 instanceof ICubridNode)) {
return 0;
}
ICubridNode node1 = (ICubridNode) e1;
ICubridNode node2 = (ICubridNode) e2;
// If group node, not sorting
if (node1 instanceof CubridGroupNode) {
return 0;
} else // If cubrid group node ,use the list's order
if ((node1 instanceof CubridServer) || (node1 instanceof CubridDatabase)) {
return order * node1.getLabel().compareTo(node2.getLabel());
}
int cat1 = category(node1);
int cat2 = category(node2);
if (cat1 > 0 && cat2 > 0) {
return cat1 - cat2;
}
if (cat1 != cat2) {
return cat1 - cat2;
}
return node1.compareTo(node2);
}
use of com.cubrid.common.ui.spi.model.CubridDatabase in project cubrid-manager by CUBRID.
the class CubridNavigatorView method showSchemaInfo.
private void showSchemaInfo(TreeItem item) {
if (System.currentTimeMillis() - lastKeyInputTimestamp <= 50) {
return;
}
boolean isAutoShowSchemaInfo = GeneralPreference.isAutoShowSchemaInfo();
if (!isAutoShowSchemaInfo) {
return;
}
Object obj = null;
if (item != null) {
obj = item.getData();
}
DefaultSchemaNode table = null;
if (obj != null) {
if ((obj instanceof ICubridNode)) {
ICubridNode node = (ICubridNode) obj;
if (NodeType.USER_TABLE.equals(node.getType()) || NodeType.USER_VIEW.equals(node.getType()) || NodeType.USER_PARTITIONED_TABLE_FOLDER.equals(node.getType()) || NodeType.SYSTEM_TABLE.equals(node.getType()) || NodeType.SYSTEM_VIEW.equals(node.getType())) {
table = (DefaultSchemaNode) node;
}
}
}
final CubridDatabase database = table == null ? null : table.getDatabase();
currentDatabaseInfo = database == null ? null : database.getDatabaseInfo();
final String schemaName = table == null ? null : table.getName();
boolean isTable = (ActionSupportUtil.isSupportSingleSelection(table, new String[] { NodeType.USER_TABLE, NodeType.SYSTEM_TABLE, NodeType.USER_PARTITIONED_TABLE_FOLDER }));
showQuickView(currentDatabaseInfo, schemaName, isTable);
lastKeyInputTimestamp = System.currentTimeMillis();
}
use of com.cubrid.common.ui.spi.model.CubridDatabase in project cubrid-manager by CUBRID.
the class CubridNavigatorView method addListener.
/**
*
* Add listener
*
*/
protected void addListener() {
tv.getTree().addMouseListener(new MouseAdapter() {
public void mouseDown(MouseEvent event) {
if (toolTip.isVisible()) {
toolTip.setVisible(false);
}
}
public void mouseUp(MouseEvent event) {
if (event.button == 1 && LayoutManager.getInstance().isUseClickOnce()) {
ISelection selection = tv.getSelection();
if (selection == null || selection.isEmpty()) {
return;
}
Object obj = ((IStructuredSelection) selection).getFirstElement();
if (!(obj instanceof ICubridNode)) {
return;
}
ICubridNode cubridNode = (ICubridNode) obj;
LayoutManager.getInstance().getWorkbenchContrItem().openEditorOrView(cubridNode);
}
}
});
tv.getTree().addMouseTrackListener(new MouseTrackAdapter() {
public void mouseHover(MouseEvent event) {
if (toolTip.isVisible()) {
toolTip.setVisible(false);
}
int x = event.x;
int y = event.y;
TreeItem item = tv.getTree().getItem(new Point(x, y));
if (item == null) {
return;
}
showToolTip(item);
}
});
tv.getTree().addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent event) {
widgetSelected(event);
}
public void widgetSelected(SelectionEvent event) {
if (toolTip.isVisible()) {
toolTip.setVisible(false);
}
TreeItem[] items = tv.getTree().getSelection();
if (items == null || items.length == 0) {
return;
}
showToolTip(items[0]);
if (items.length == 1) {
showSchemaInfo(items[0]);
} else {
showSchemaInfo(null);
}
}
});
addDragDropSupport(tv.getTree());
tv.getTree().addKeyListener(new KeyListener() {
public void keyReleased(KeyEvent e) {
}
public void keyPressed(KeyEvent e) {
// prevent to make events by key press for a long time
if (e.character == ' ') {
TreeItem[] items = tv.getTree().getSelection();
if (items == null || items.length == 0) {
return;
}
if (items.length == 1) {
showSchemaInfo(items[0]);
} else {
showSchemaInfo(null);
}
}
lastKeyInputTimestamp = System.currentTimeMillis();
// by showing object information tab on the query editor.
if (e.keyCode == SWT.F2) {
TreeItem[] items = tv.getTree().getSelection();
if (items == null || items.length == 0) {
return;
}
for (TreeItem item : items) {
Object obj = item.getData();
if (obj instanceof ICubridNode) {
ICubridNode node = (ICubridNode) obj;
if (NodeType.USER_TABLE.equals(node.getType()) || NodeType.SYSTEM_TABLE.equals(node.getType()) || NodeType.USER_VIEW.equals(node.getType()) || NodeType.SYSTEM_VIEW.equals(node.getType())) {
DefaultSchemaNode table = (DefaultSchemaNode) obj;
OpenTargetAction action = new OpenTargetAction();
action.showObjectInfo(table);
} else if (NodeType.TABLE_FOLDER.equals(node.getType())) {
CubridNavigatorView view = CubridNavigatorView.getNavigatorView(ID_CQB);
if (view == null) {
view = CubridNavigatorView.getNavigatorView(ID_CM);
}
if (view == null) {
return;
}
TreeViewer treeViewer = view.getViewer();
//if not expand ,expand the node and wait until all children be added
if (!treeViewer.getExpandedState(node)) {
treeViewer.expandToLevel(node, 1);
while (node.getChildren().size() == 0) {
try {
Thread.sleep(500);
} catch (Exception ignored) {
}
}
}
CubridDatabase database = (CubridDatabase) node.getParent();
OpenTargetAction action = new OpenTargetAction();
action.showTableDashboard(database);
}
}
}
}
}
});
}
Aggregations