Search in sources :

Example 1 with CubridDatabase

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();
}
Also used : ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) DefaultSchemaNode(com.cubrid.common.ui.spi.model.DefaultSchemaNode) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 2 with CubridDatabase

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);
                        }
                    }
                }
            }
        }
    });
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) TreeItem(org.eclipse.swt.widgets.TreeItem) TreeViewer(org.eclipse.jface.viewers.TreeViewer) MouseAdapter(org.eclipse.swt.events.MouseAdapter) MouseTrackAdapter(org.eclipse.swt.events.MouseTrackAdapter) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) Point(org.eclipse.swt.graphics.Point) DefaultSchemaNode(com.cubrid.common.ui.spi.model.DefaultSchemaNode) OpenTargetAction(com.cubrid.common.ui.common.action.OpenTargetAction) KeyEvent(org.eclipse.swt.events.KeyEvent) ISelection(org.eclipse.jface.viewers.ISelection) SelectionEvent(org.eclipse.swt.events.SelectionEvent) KeyListener(org.eclipse.swt.events.KeyListener) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 3 with CubridDatabase

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;
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 4 with 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());
    }
}
Also used : Point(org.eclipse.swt.graphics.Point) PartInitException(org.eclipse.ui.PartInitException) IOException(java.io.IOException) ImportConfig(com.cubrid.common.ui.cubrid.table.dialog.imp.ImportConfig) TableConfig(com.cubrid.common.ui.cubrid.table.dialog.imp.TableConfig) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) ImportDataEditorInput(com.cubrid.common.ui.cubrid.table.dialog.imp.ImportDataEditorInput) Map(java.util.Map) File(java.io.File) HashSet(java.util.HashSet)

Example 5 with CubridDatabase

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);
}
Also used : CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) IOException(java.io.IOException) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) Clipboard(org.eclipse.swt.dnd.Clipboard) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Aggregations

CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)278 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)104 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)79 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)67 ArrayList (java.util.ArrayList)45 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)43 TreeViewer (org.eclipse.jface.viewers.TreeViewer)42 DbUserInfo (com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo)36 DefaultSchemaNode (com.cubrid.common.ui.spi.model.DefaultSchemaNode)33 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)30 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)29 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)28 CubridNavigatorView (com.cubrid.common.ui.common.navigator.CubridNavigatorView)25 CubridServer (com.cubrid.common.ui.spi.model.CubridServer)22 Shell (org.eclipse.swt.widgets.Shell)22 DatabaseEditorConfig (com.cubrid.common.ui.spi.model.DatabaseEditorConfig)19 CommonTaskExec (com.cubrid.common.ui.spi.progress.CommonTaskExec)18 ServerUserInfo (com.cubrid.cubridmanager.core.common.model.ServerUserInfo)18 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)18 ITask (com.cubrid.common.core.task.ITask)17