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);
}
}
}
}
}
});
}
use of com.cubrid.common.ui.spi.model.CubridDatabase in project cubrid-manager by CUBRID.
the class FavoriteQueryNavigatorView method getCurrentDatabase.
/**
* Return current selected database from the navigation tree.
* @return CubridDatabase
*/
private CubridDatabase getCurrentDatabase() {
CubridDatabase cubridDatabase = null;
CubridNavigatorView nav = CubridNavigatorView.findNavigationView();
if (nav != null) {
TreeItem[] items = nav.getSelectedItems();
if (items.length > 0 && items[0] != null && items[0].getData() instanceof ISchemaNode) {
ISchemaNode node = (ISchemaNode) items[0].getData();
CubridDatabase tempDatabase = node.getDatabase();
if (tempDatabase != null && tempDatabase.isLogined()) {
cubridDatabase = tempDatabase;
}
}
}
return cubridDatabase;
}
use of com.cubrid.common.ui.spi.model.CubridDatabase in project cubrid-manager by CUBRID.
the class FavoriteQueryNavigatorView method executeSql.
/**
* Execute selected queries
*/
private void executeSql() {
CubridDatabase cubridDatabase = getCurrentDatabase();
if (cubridDatabase == null || cubridDatabase.getDatabaseInfo() == null) {
CommonUITool.openErrorBox(com.cubrid.common.ui.query.Messages.errNoConnectionBatchRun);
return;
}
// Judge the file is exist
int[] indexes = tv.getTable().getSelectionIndices();
List<Map<String, String>> list = FavoriteQueryPersistUtil.getInstance().getListData();
for (int i = 0; i < indexes.length; i++) {
Map<String, String> item = list.get(indexes[i]);
String filename = item.get("1");
String fullpath = item.get("4") + File.separator + filename;
if (!new File(fullpath).exists()) {
String msg = Messages.bind(com.cubrid.common.ui.query.Messages.errFileNotExist, fullpath);
CommonUITool.openErrorBox(msg);
return;
}
}
String targetDbName = cubridDatabase.getDatabaseInfo().getDbName() + "@" + cubridDatabase.getServer().getServerInfo().getHostAddress();
String msg = Messages.bind(com.cubrid.common.ui.query.Messages.msgDoYouWantExecuteSql, targetDbName);
if (!CommonUITool.openConfirmBox(msg)) {
return;
}
String charset = StringUtil.getDefaultCharset();
ImportConfig importConfig = new ImportConfig();
importConfig.setImportType(ImportConfig.IMPORT_FROM_SQL);
importConfig.setThreadCount(1);
importConfig.setCommitLine(100);
Set<String> charsets = new HashSet<String>();
for (int i = 0; i < indexes.length; i++) {
Map<String, String> item = list.get(indexes[i]);
String filename = item.get("1");
String fullpath = item.get("4") + File.separator + filename;
charset = item.get("5");
if (StringUtil.isEmpty(charset)) {
charset = StringUtil.getDefaultCharset();
} else {
charsets.add(charset);
}
TableConfig fileConfig = new TableConfig(filename);
fileConfig.setFilePath(fullpath);
fileConfig.setFileType(TableConfig.TYPE_DATA);
importConfig.addTableConfig(fileConfig);
}
importConfig.setFilesCharset(charset);
if (charsets.size() > 1) {
msg = Messages.bind(com.cubrid.common.ui.query.Messages.msgDoYouWantExecuteWithNotSameCharset, charset);
if (!CommonUITool.openConfirmBox(msg)) {
return;
}
}
ImportDataEditorInput input = new ImportDataEditorInput();
input.setDatabase(cubridDatabase);
input.setImportConfig(importConfig);
try {
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input, ImportDataViewPart.ID);
} catch (Exception e) {
CommonUITool.openErrorBox(Display.getCurrent().getActiveShell(), e.getMessage());
}
}
use of com.cubrid.common.ui.spi.model.CubridDatabase in project cubrid-manager by CUBRID.
the class ExportConnectionUtil method buttonPressed.
/**
* Call this method when the button in button bar is pressed
*
* @param buttonId the button id
*/
protected void buttonPressed(int buttonId) {
if (buttonId == COPY_CLIPBOARD_ID) {
List<CubridDatabase> databaseList = getCheckedDatabases();
if (databaseList.size() <= 0) {
CommonUITool.openErrorBox(getShell(), Messages.expConDialogCopyErrorMsg);
return;
}
StringBuilder sb = new StringBuilder();
for (CubridDatabase db : databaseList) {
if (sb.length() > 0) {
sb.append(StringUtil.NEWLINE);
}
sb.append(NodeUtil.getJavaConnectionUrl(db.getDatabaseInfo()));
}
TextTransfer textTransfer = TextTransfer.getInstance();
Clipboard clipboard = CommonUITool.getClipboard();
clipboard.setContents(new Object[] { sb.toString() }, new Transfer[] { textTransfer });
CommonUITool.openInformationBox(Messages.titleSuccess, Messages.expConDialogCopySucessMsg);
return;
} else if (buttonId == IDialogConstants.OK_ID) {
if (!verify()) {
return;
}
FileDialog dialog = new FileDialog(getShell(), SWT.SAVE | SWT.APPLICATION_MODAL);
String[] filterExtensions = new String[] { "*.xls" };
//Windows wild cards
dialog.setFilterExtensions(filterExtensions);
String fileName = dialog.open();
if (fileName == null) {
return;
}
/*Process the file extensions*/
if (!ExportConnectionUtil.isTxtFile(fileName) && !ExportConnectionUtil.isXlsFile(fileName) && !ExportConnectionUtil.isXlsxFile(fileName)) {
int filterIndex = dialog.getFilterIndex();
if (filterIndex == 0 || filterIndex == 2) {
fileName = fileName + ".xls";
} else if (filterIndex == 1) {
fileName = fileName + ".txt";
}
}
TaskExecutor taskExec = new CommonTaskExec(Messages.nameExportConnectionTask);
File file = new File(fileName);
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
LOGGER.error("Create file failed:" + e.getMessage());
}
}
ExportConnectionsTask task = new ExportConnectionsTask(getCheckedDatabases(), file);
taskExec.addTask(task);
new ExecTaskWithProgress(taskExec).busyCursorWhile();
if (taskExec.isSuccess()) {
CommonUITool.openInformationBox(Messages.titleSuccess, Messages.msgConnectionUrlExported);
super.okPressed();
}
}
super.buttonPressed(buttonId);
}
Aggregations