Search in sources :

Example 1 with RowDetailDialog

use of com.cubrid.common.ui.query.dialog.RowDetailDialog in project cubrid-manager by CUBRID.

the class QueryExecuter method createContextMenuItems.

private void createContextMenuItems() {
    Menu menu = new Menu(queryEditor.getEditorSite().getShell(), SWT.POP_UP);
    final MenuItem itemInsert = new MenuItem(menu, SWT.PUSH);
    itemInsert.setText(Messages.insertRecord);
    itemInsert.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            if (!getEditable()) {
                CommonUITool.openErrorBox(Display.getDefault().getActiveShell(), Messages.errNotEditable);
                return;
            }
            insertSaveItem.setEnabled(getEditable());
            rollbackModifiedItem.setEnabled(getEditable());
            addNewItem();
        }
    });
    final MenuItem itemCopy = new MenuItem(menu, SWT.PUSH);
    itemCopy.setText(Messages.copyClipBoard);
    final MenuItem itemDelete = new MenuItem(menu, SWT.PUSH);
    itemDelete.setText(Messages.delete);
    new MenuItem(menu, SWT.SEPARATOR);
    final MenuItem itemDetail = new MenuItem(menu, SWT.PUSH);
    itemDetail.setText(Messages.detailView);
    itemDetail.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            List<Point> selectedList = selectableSupport.getSelectedLocations();
            Point location = selectedList.get(0);
            if (location == null) {
                CommonUITool.openErrorBox(Messages.errShowDetailFailed);
                return;
            }
            //Bug fixed by Kevin.Qian. FYI. allDataList is a global query result to the current query.
            int pageBeginIndex = (queryInfo.getCurrentPage() - 1) * queryInfo.getPageSize();
            Map<String, CellValue> map = allDataList.get(pageBeginIndex + location.y);
            TableItem item = tblResult.getItem(location.y);
            ColumnInfo colInfo = allColumnList.get(location.x - 1);
            RowDetailDialog dialog = new RowDetailDialog(tblResult.getShell(), allColumnList, map, item, colInfo.getName(), executer);
            dialog.open();
        }
    });
    tblResult.setMenu(menu);
    tblResult.addListener(SWT.MouseUp, new Listener() {

        public void handleEvent(Event event) {
            //				Point pt = new Point(event.x, event.y);
            //				itemOid.setEnabled(false);
            int index = tblResult.getSelectionIndex();
            int count = tblResult.getItemCount();
            if (index < 0 || index >= count) {
                return;
            }
        //				final TableItem item = tblResult.getItem(index);
        //				for (int i = 0; i < tblResult.getColumnCount(); i++) {
        //					Rectangle rect = item.getBounds(i);
        //					if (rect.contains(pt)) {
        //						selColumnName = tblResult.getColumn(i).getText();
        ////						Object value = item.getData(i + "");
        ////						String text = item.getText(i);
        ////						if (!DataType.VALUE_NULL.equals(value) && containsOIDs(tblResult.getColumn(i).getText())
        ////							&& !DataType.VALUE_NONE.equals(text)) {
        ////							itemOid.setEnabled(true);
        ////						} else {
        ////							itemOid.setEnabled(false);
        ////						}
        //
        //					}
        //				}
        }
    });
    final MenuItem itemExportAll = new MenuItem(menu, SWT.PUSH);
    itemExportAll.setText(Messages.allExport);
    final MenuItem itemExportSelection = new MenuItem(menu, SWT.PUSH);
    itemExportSelection.setText(Messages.selectExport);
    new MenuItem(menu, SWT.SEPARATOR);
    final MenuItem itemMakeInsertQuery = new MenuItem(menu, SWT.PUSH);
    itemMakeInsertQuery.setText(Messages.makeInsertFromSelectedRecord);
    itemMakeInsertQuery.setImage(CommonUIPlugin.getImage("icons/queryeditor/record_to_insert.png"));
    final MenuItem itemMakeUpdateQuery = new MenuItem(menu, SWT.PUSH);
    itemMakeUpdateQuery.setText(Messages.makeUpdateFromSelectedRecord);
    itemMakeUpdateQuery.setImage(CommonUIPlugin.getImage("icons/queryeditor/record_to_update.png"));
    if (isEmpty()) {
        itemExportAll.setEnabled(false);
        itemExportSelection.setEnabled(false);
        itemDetail.setEnabled(false);
    }
    menu.addMenuListener(new MenuAdapter() {

        public void menuShown(MenuEvent event) {
            List<Point> selectedList = selectableSupport.getSelectedLocations();
            TableItem[] tblItems = selectableSupport.getSelectedTableItems();
            boolean selectedCol = selectableSupport.hasSelected();
            boolean enableItemDetail = (selectedList != null && selectedList.size() == 1);
            itemExportSelection.setEnabled(selectedCol);
            itemCopy.setEnabled(selectedCol);
            if (allDataList.size() > 0) {
                itemExportAll.setEnabled(true);
            } else {
                itemExportAll.setEnabled(false);
            }
            if (executer.getQueryEditor() != null && executer.getQueryEditor().getDatabaseInfo() != null && executer.getQueryEditor().getDatabaseInfo().equals(executer.getDatabaseInfo())) {
                itemInsert.setEnabled(isEditMode());
                itemDetail.setEnabled(enableItemDetail);
                itemDelete.setEnabled(getEditable() && isEditMode());
            } else {
                itemInsert.setEnabled(false);
                itemDetail.setEnabled(false);
                itemDelete.setEnabled(false);
            }
            for (int i = 0; i < tblItems.length; i++) {
                if (isEditMode() && getEditable() && tblItems[i].getText(1).equals(DataType.VALUE_NONE)) {
                    itemDelete.setEnabled(false);
                }
            }
        }
    });
    itemCopy.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            copySelectedItems();
        }
    });
    itemCopy.setAccelerator(SWT.CTRL + 'c');
    itemDelete.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            if (isEditMode()) {
                deleteRecord(tblResult, null);
            }
        }
    });
    itemExportAll.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            ExportResultDialog dialog = new ExportResultDialog(tblResult.getShell(), database, Messages.msgExportAllResults);
            if (IDialogConstants.OK_ID == dialog.open()) {
                ExportQueryResultTaskExecutor task = new ExportQueryResultTaskExecutor(dialog.getFile(), dialog.getFileCharset(), allColumnList, allDataList, false);
                new ExecTaskWithProgress(task).exec();
            }
        }
    });
    //		itemOid.addSelectionListener(new SelectionAdapter() {
    //			/**
    //			 * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
    //			 * @param event an event containing information about the
    //			 *        selection
    //			 */
    //			public void widgetSelected(SelectionEvent event) {
    //				openOidNavigator(button2Position);
    //			}
    //
    //		});
    itemExportSelection.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            ExportResultDialog dialog = new ExportResultDialog(tblResult.getShell(), database, Messages.msgExportSelectedResults);
            if (IDialogConstants.OK_ID == dialog.open()) {
                ExportQueryResultTaskExecutor task = new ExportQueryResultTaskExecutor(dialog.getFile(), dialog.getFileCharset(), tblResult, selectableSupport.getSelectedTableItems(), false);
                new ExecTaskWithProgress(task).exec();
            }
        }
    });
    itemMakeInsertQuery.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            String text = makeInsertQueryWithSelectedRecords();
            CommonUITool.copyContentToClipboard(text);
        }

        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
    itemMakeUpdateQuery.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            String text = makeUpdateQueryWithSelectedRecords();
            CommonUITool.copyContentToClipboard(text);
        }

        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
}
Also used : SelectionListener(org.eclipse.swt.events.SelectionListener) PaintListener(org.eclipse.swt.events.PaintListener) Listener(org.eclipse.swt.widgets.Listener) MouseListener(org.eclipse.swt.events.MouseListener) IMenuListener(org.eclipse.jface.action.IMenuListener) KeyListener(org.eclipse.swt.events.KeyListener) RowDetailDialog(com.cubrid.common.ui.query.dialog.RowDetailDialog) ExportResultDialog(com.cubrid.common.ui.query.dialog.ExportResultDialog) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) TableItem(org.eclipse.swt.widgets.TableItem) MenuAdapter(org.eclipse.swt.events.MenuAdapter) MenuItem(org.eclipse.swt.widgets.MenuItem) Point(org.eclipse.swt.graphics.Point) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) FocusEvent(org.eclipse.swt.events.FocusEvent) MenuEvent(org.eclipse.swt.events.MenuEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) PaintEvent(org.eclipse.swt.events.PaintEvent) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ArrayList(java.util.ArrayList) List(java.util.List) Menu(org.eclipse.swt.widgets.Menu) Map(java.util.Map) HashMap(java.util.HashMap) MenuEvent(org.eclipse.swt.events.MenuEvent) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

ExportResultDialog (com.cubrid.common.ui.query.dialog.ExportResultDialog)1 RowDetailDialog (com.cubrid.common.ui.query.dialog.RowDetailDialog)1 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 IMenuListener (org.eclipse.jface.action.IMenuListener)1 FocusEvent (org.eclipse.swt.events.FocusEvent)1 KeyEvent (org.eclipse.swt.events.KeyEvent)1 KeyListener (org.eclipse.swt.events.KeyListener)1 MenuAdapter (org.eclipse.swt.events.MenuAdapter)1 MenuEvent (org.eclipse.swt.events.MenuEvent)1 MouseEvent (org.eclipse.swt.events.MouseEvent)1 MouseListener (org.eclipse.swt.events.MouseListener)1 PaintEvent (org.eclipse.swt.events.PaintEvent)1 PaintListener (org.eclipse.swt.events.PaintListener)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 SelectionListener (org.eclipse.swt.events.SelectionListener)1