Search in sources :

Example 26 with CubridDatabase

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();
}
Also used : FocusAdapter(org.eclipse.swt.events.FocusAdapter) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ArrayList(java.util.ArrayList) MenuItem(org.eclipse.swt.widgets.MenuItem) FocusEvent(org.eclipse.swt.events.FocusEvent) MenuManager(org.eclipse.jface.action.MenuManager) SelectionEvent(org.eclipse.swt.events.SelectionEvent) List(java.util.List) ArrayList(java.util.ArrayList) Menu(org.eclipse.swt.widgets.Menu) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 27 with CubridDatabase

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();
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) RunSQLFileEditorInput(com.cubrid.common.ui.common.sqlrunner.part.RunSQLFileEditorInput) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 28 with CubridDatabase

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

Example 29 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 30 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)

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