Search in sources :

Example 66 with FocusEvent

use of org.eclipse.swt.events.FocusEvent in project translationstudio8 by heartsome.

the class CustomMatchConditionDialog method setGray.

/**
	 * 为Text控件增加灰色提醒,获得焦点时自动清除灰色提醒
	 * @param text
	 *            Text控件
	 * @param initTxt
	 *            灰色提醒字符串
	 */
private void setGray(final Text text, final String initTxt) {
    text.setForeground(gray);
    text.setText(initTxt);
    text.addFocusListener(new FocusListener() {

        public void focusLost(FocusEvent arg0) {
            if (text.getText().trim().equals("")) {
                if (!text.getForeground().equals(gray)) {
                    text.setForeground(gray);
                }
                text.setText(initTxt);
            } else {
                if (!text.getForeground().equals(black)) {
                    text.setForeground(black);
                }
            }
        }

        public void focusGained(FocusEvent arg0) {
            if (text.getText().trim().equals(initTxt)) {
                text.setText("");
                text.setForeground(black);
            } else {
                if (!text.getForeground().equals(black)) {
                    text.setForeground(black);
                }
            }
        }
    });
}
Also used : FocusListener(org.eclipse.swt.events.FocusListener) FocusEvent(org.eclipse.swt.events.FocusEvent)

Example 67 with FocusEvent

use of org.eclipse.swt.events.FocusEvent in project cubrid-manager by CUBRID.

the class TableSchemaCompareInfoPart method registerContextMenu.

/**
	 * register context menu
	 */
private void registerContextMenu() {
    tablesSchemaCompareTable.getTable().addFocusListener(new FocusAdapter() {

        public void focusGained(FocusEvent event) {
            ActionManager.getInstance().changeFocusProvider(tablesSchemaCompareTable.getTable());
        }
    });
    MenuManager menuManager = new MenuManager();
    menuManager.setRemoveAllWhenShown(true);
    Menu contextMenu = menuManager.createContextMenu(tablesSchemaCompareTable.getTable());
    tablesSchemaCompareTable.getTable().setMenu(contextMenu);
    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    Menu menu = new Menu(shell, SWT.POP_UP);
    final MenuItem tableLeftDDL = new MenuItem(menu, SWT.PUSH);
    tableLeftDDL.setText(Messages.copyTablesLeftDDL);
    tableLeftDDL.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            copyTableAlterDDL(sourceDB, targetDB, true);
        }
    });
    final MenuItem tableRightDDL = new MenuItem(menu, SWT.PUSH);
    tableRightDDL.setText(Messages.copyTablesRightDDL);
    tableRightDDL.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            copyTableAlterDDL(targetDB, sourceDB, false);
        }
    });
    tablesSchemaCompareTable.getTable().setMenu(menu);
}
Also used : FocusAdapter(org.eclipse.swt.events.FocusAdapter) Shell(org.eclipse.swt.widgets.Shell) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) MenuManager(org.eclipse.jface.action.MenuManager) SelectionEvent(org.eclipse.swt.events.SelectionEvent) MenuItem(org.eclipse.swt.widgets.MenuItem) Menu(org.eclipse.swt.widgets.Menu) FocusEvent(org.eclipse.swt.events.FocusEvent)

Example 68 with FocusEvent

use of org.eclipse.swt.events.FocusEvent in project cubrid-manager by CUBRID.

the class SerialDashboardEditorPart method registerContextMenu.

private void registerContextMenu() {
    serialsDetailInfoTable.getTable().addFocusListener(new FocusAdapter() {

        public void focusGained(FocusEvent event) {
            ActionManager.getInstance().changeFocusProvider(serialsDetailInfoTable.getTable());
        }
    });
    MenuManager menuManager = new MenuManager();
    menuManager.setRemoveAllWhenShown(true);
    Menu contextMenu = menuManager.createContextMenu(serialsDetailInfoTable.getTable());
    serialsDetailInfoTable.getTable().setMenu(contextMenu);
    Menu menu = new Menu(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.POP_UP);
    final MenuItem editSerialItem = new MenuItem(menu, SWT.PUSH);
    editSerialItem.setText(Messages.serialsDetailInfoPartEditSerialBtn);
    editSerialItem.setImage(CommonUIPlugin.getImage("icons/action/serial_edit.png"));
    editSerialItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            editSerial();
        }
    });
    final MenuItem dropSerialItem = new MenuItem(menu, SWT.PUSH);
    dropSerialItem.setText(Messages.serialsDetailInfoPartDropSerialBtn);
    dropSerialItem.setImage(CommonUIPlugin.getImage("icons/action/serial_delete.png"));
    dropSerialItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            dropSerial();
        }
    });
    new MenuItem(menu, SWT.SEPARATOR);
    final MenuItem addSerialItem = new MenuItem(menu, SWT.PUSH);
    addSerialItem.setText(Messages.serialsDetailInfoPartCreateSerialBtn);
    addSerialItem.setImage(CommonUIPlugin.getImage("icons/action/serial_add.png"));
    addSerialItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            addSerial();
        }
    });
    serialsDetailInfoTable.getTable().setMenu(menu);
}
Also used : FocusAdapter(org.eclipse.swt.events.FocusAdapter) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) MenuManager(org.eclipse.jface.action.MenuManager) SelectionEvent(org.eclipse.swt.events.SelectionEvent) MenuItem(org.eclipse.swt.widgets.MenuItem) Menu(org.eclipse.swt.widgets.Menu) FocusEvent(org.eclipse.swt.events.FocusEvent)

Example 69 with FocusEvent

use of org.eclipse.swt.events.FocusEvent in project cubrid-manager by CUBRID.

the class QueryResultComposite method makeResult.

/**
	 * make the result contents.
	 * 
	 * @param result QueryExecuter
	 */
private void makeResult(final QueryExecuter result, CTabFolder parentFolder) {
    editor.getCombinedQueryComposite().getRecentlyUsedSQLComposite().refreshRecentlyUsedSQLList();
    //final CTabFolder queryResultTabFolder = ((QueryResultComposite)queryResultTabItem.getControl()).queryResultTabFolder;
    ViewForm viewForm = new ViewForm(parentFolder, SWT.NONE);
    // create the bottom sash
    final SashForm tableLogSash = new SashForm(viewForm, SWT.VERTICAL);
    tableLogSash.SASH_WIDTH = SASH_WIDTH;
    tableLogSash.setBackground(CombinedQueryEditorComposite.BACK_COLOR);
    final Composite resultContainer = new Composite(tableLogSash, SWT.None);
    resultContainer.setLayout(new FormLayout());
    final Table resultTable = new Table(resultContainer, SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.HIDE_SELECTION);
    setDropTraget(resultTable);
    resultTable.setHeaderVisible(true);
    resultTable.setLinesVisible(true);
    resultTable.setBackground(BACKGROUND_NORMAL);
    CommonUITool.hackForYosemite(resultTable);
    // display data compare label for multiple queries
    if (this.multiResultsCompare == true) {
        Composite compareButtonComposite = new Composite(resultContainer, SWT.None);
        compareButtonComposite.setLayout(new FillLayout());
        displayDataCompareLabel(compareButtonComposite, resultTable);
        FormData tableData = new FormData();
        tableData.top = new FormAttachment(0, 0);
        tableData.bottom = new FormAttachment(100, -28);
        tableData.left = new FormAttachment(0, 0);
        tableData.right = new FormAttachment(100, 0);
        resultTable.setLayoutData(tableData);
        FormData compareData = new FormData();
        compareData.top = new FormAttachment(100, -28);
        compareData.bottom = new FormAttachment(100, 0);
        compareData.left = new FormAttachment(0, 0);
        compareData.right = new FormAttachment(100, 0);
        compareButtonComposite.setLayoutData(compareData);
    } else {
        FormData tableData = new FormData();
        tableData.top = new FormAttachment(0, 0);
        tableData.bottom = new FormAttachment(100, 0);
        tableData.left = new FormAttachment(0, 0);
        tableData.right = new FormAttachment(100, 0);
        resultTable.setLayoutData(tableData);
    }
    final SashForm logSash = new SashForm(tableLogSash, SWT.HORIZONTAL);
    logSash.SASH_WIDTH = SASH_WIDTH;
    logSash.setBackground(CombinedQueryEditorComposite.BACK_COLOR);
    logSash.setLayoutData(CommonUITool.createGridData(GridData.FILL_BOTH, 1, 1, -1, -1));
    StyledText messagesArea = new StyledText(logSash, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.READ_ONLY | SWT.WRAP);
    CommonUITool.registerCopyPasteContextMenu(messagesArea, false, false);
    tableLogSash.setWeights(new int[] { 8, 2 });
    messagesArea.setToolTipText(Messages.tooltipHowToExpandLogPane);
    messagesArea.addFocusListener(new FocusListener() {

        public void focusLost(FocusEvent e) {
            tableLogSash.setWeights(new int[] { 8, 2 });
        }

        public void focusGained(FocusEvent e) {
            tableLogSash.setWeights(new int[] { 2, 8 });
        }
    });
    TableCursor cursor = new TableCursor(resultTable, SWT.NONE);
    TableSelectSupport tableSelectSupport = new TableSelectSupport(resultTable, cursor);
    if (this.multiResultsCompare == true) {
        result.setMultiResultsCompare(true);
        result.setBaseQueryExecuter(this.baseQueryExecuter);
    }
    result.makeResult(tableSelectSupport, messagesArea, isMutliQuery);
    // Auto set column size, maximum is 300px,minimum is 50px
    for (int i = 1; i < resultTable.getColumnCount(); i++) {
        resultTable.getColumns()[i].pack();
        if (resultTable.getColumns()[i].getWidth() > 300) {
            resultTable.getColumns()[i].setWidth(300);
        }
        if (resultTable.getColumns()[i].getWidth() < 50) {
            resultTable.getColumns()[i].setWidth(50);
        }
    }
    // fill the view form action on top right corner
    ToolBar topRightToolBar = new ToolBar(viewForm, SWT.FLAT);
    ToolBarManager toolBarManager = new ToolBarManager(topRightToolBar);
    result.makeActions(toolBarManager, resultTable);
    // fill the view form action on top right corner
    ToolBar topLeftToolBar = new ToolBar(viewForm, SWT.FLAT);
    swRecordItem = new ToolItem(topLeftToolBar, SWT.CHECK);
    result.swRecordItem = swRecordItem;
    swRecordItem.setToolTipText(Messages.getOidOn);
    swRecordItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/query_update.png"));
    swRecordItem.setEnabled(true);
    swRecordItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            if (editor.isCollectExecStats()) {
                result.swRecordItem.setSelection(false);
                CommonUITool.openErrorBox(getShell(), Messages.errNotEditableOnStat);
                return;
            }
            if (!result.isContainPrimayKey()) {
                result.swRecordItem.setSelection(false);
                CommonUITool.openErrorBox(getShell(), Messages.errNoPrimaryKey);
                return;
            }
            if (!result.isSingleTableQuery()) {
                result.swRecordItem.setSelection(false);
                CommonUITool.openErrorBox(getShell(), Messages.errNotInOneTable);
                return;
            }
            if (!checkConnection()) {
                result.swRecordItem.setSelection(false);
                CommonUITool.openErrorBox(getShell(), Messages.errMsgExecuteInResult);
                return;
            }
            result.tblResult.forceFocus();
            if (result.swRecordItem.getSelection()) {
                result.swRecordItem.setToolTipText(Messages.getOidOn);
                result.setEditMode(true);
                result.insertRecordItem.setEnabled(true);
                if (result.tblResult.getSelectionCount() > 0) {
                    result.delRecordItem.setEnabled(true);
                }
            } else {
                if (result.isModifiedResult()) {
                    result.swRecordItem.setSelection(true);
                    CommonUITool.openErrorBox(getShell(), Messages.errHasNoCommit);
                    return;
                }
                result.swRecordItem.setToolTipText(Messages.getOidOff);
                result.setEditMode(false);
                result.insertRecordItem.setEnabled(false);
                result.delRecordItem.setEnabled(false);
            }
        }
    });
    //added by kevin, for insert record
    insertRecordItem = new ToolItem(topLeftToolBar, SWT.PUSH);
    result.insertRecordItem = insertRecordItem;
    insertRecordItem.setToolTipText(com.cubrid.common.ui.cubrid.table.Messages.insertInstanceMsgTitle);
    insertRecordItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/table_record_insert.png"));
    insertRecordItem.setDisabledImage(CommonUIPlugin.getImage("icons/queryeditor/table_record_insert_disabled.png"));
    insertRecordItem.setEnabled(false);
    insertRecordItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            if (!result.getEditable()) {
                CommonUITool.openErrorBox(getShell(), Messages.errNotEditable);
                return;
            }
            if (!checkConnection()) {
                CommonUITool.openErrorBox(getShell(), Messages.errMsgExecuteInResult);
                return;
            }
            result.insertSaveItem.setEnabled(result.getEditable());
            result.rollbackModifiedItem.setEnabled(result.getEditable());
            result.addNewItem();
        }
    });
    delRecordItem = new ToolItem(topLeftToolBar, SWT.PUSH);
    result.delRecordItem = delRecordItem;
    delRecordItem.setToolTipText(Messages.delete);
    delRecordItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/table_record_delete.png"));
    delRecordItem.setDisabledImage(CommonUIPlugin.getImage("icons/queryeditor/table_record_delete_disabled.png"));
    delRecordItem.setEnabled(false);
    delRecordItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            if (!result.getEditable()) {
                CommonUITool.openErrorBox(getShell(), Messages.errNotEditable);
                return;
            }
            if (!checkConnection()) {
                CommonUITool.openErrorBox(getShell(), Messages.errMsgExecuteInResult);
                return;
            }
            result.tblResult.forceFocus();
            result.deleteRecord(result.tblResult, null);
        }
    });
    insertSaveItem = new ToolItem(topLeftToolBar, SWT.PUSH);
    result.insertSaveItem = insertSaveItem;
    insertSaveItem.setToolTipText(Messages.insertCommit);
    insertSaveItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/query_commit.png"));
    insertSaveItem.setDisabledImage(CommonUIPlugin.getImage("icons/queryeditor/query_commit_disabled.png"));
    insertSaveItem.setEnabled(false);
    insertSaveItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            if (!checkConnection()) {
                CommonUITool.openErrorBox(getShell(), Messages.errMsgExecuteInResult);
                return;
            }
            if (result.getQueryEditor().isActive()) {
                CommonUITool.openWarningBox(Messages.msgActiveTran);
                return;
            }
            if (!CommonUITool.openConfirmBox(getShell(), (Messages.msgCommitEdited))) {
                return;
            }
            try {
                if (result.saveInsertedUpdatedDeletedRecords()) {
                    insertSaveItem.setEnabled(false);
                    result.rollbackModifiedItem.setEnabled(false);
                    result.swRecordItem.setSelection(false);
                }
                result.swRecordItem.setSelection(false);
                result.insertRecordItem.setEnabled(false);
                result.delRecordItem.setEnabled(false);
                result.setEditMode(false);
            } catch (ParamSetException e) {
                if (e.getParameter() != null && !StringUtil.isEmpty(e.getParameter().getDataType())) {
                    CommonUITool.openErrorBox(Messages.bind(Messages.errTextTypeNotMatch, e.getParameter().getDataType()) + StringUtil.NEWLINE + e.getLocalizedMessage());
                } else {
                    CommonUITool.openErrorBox(getShell(), e.getLocalizedMessage());
                }
            } catch (SQLException e) {
                e.printStackTrace();
                CommonUITool.openErrorBox(getShell(), e.getErrorCode() + StringUtil.NEWLINE + e.getMessage());
                /*Can't edit any data if necessary*/
                //					result.setEditMode(false);
                //				    delRecordItem.setEnabled(false);
                //					insertRecordItem.setEnabled(false);
                //					insertSaveItem.setEnabled(false) ;
                //					swRecordItem.setEnabled(false);
                //					rollbackModifiedItem.setEnabled(false);
                result.getTblResult().setBackground(BACKGROUND_DIRTY);
            }
        }
    });
    rollbackModifiedItem = new ToolItem(topLeftToolBar, SWT.PUSH);
    result.rollbackModifiedItem = rollbackModifiedItem;
    rollbackModifiedItem.setToolTipText(Messages.insertRollback);
    rollbackModifiedItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/query_rollback.png"));
    rollbackModifiedItem.setDisabledImage(CommonUIPlugin.getImage("icons/queryeditor/query_rollback_disabled.png"));
    rollbackModifiedItem.setEnabled(false);
    rollbackModifiedItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            if (!CommonUITool.openConfirmBox(getShell(), (Messages.msgRollbackEdited))) {
                return;
            }
            result.tblResult.forceFocus();
            insertSaveItem.setEnabled(false);
            rollbackModifiedItem.setEnabled(false);
            result.clearModifiedLog();
            QueryInfo queryInfo = result.getQueryInfo();
            queryInfo.setCurrentPage(queryInfo.getCurrentPage());
            result.makeItem();
            result.updateActions();
            result.swRecordItem.setSelection(false);
            result.insertRecordItem.setEnabled(false);
            result.delRecordItem.setEnabled(false);
            result.setEditMode(false);
            result.tblResult.setBackground(BACKGROUND_NORMAL);
        }
    });
    if (!isMutliQuery) {
        new ToolItem(topLeftToolBar, SWT.SEPARATOR);
        copyInsertSqlFromRecordsItem = new ToolItem(topLeftToolBar, SWT.PUSH);
        copyInsertSqlFromRecordsItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/record_to_insert.png"));
        copyInsertSqlFromRecordsItem.setToolTipText(Messages.makeInsertFromSelectedRecord);
        copyInsertSqlFromRecordsItem.addSelectionListener(new SelectionListener() {

            public void widgetSelected(SelectionEvent e) {
                if (editor == null) {
                    return;
                }
                String text = editor.getQueryExecuter().makeInsertQueryWithSelectedRecords();
                if (StringUtil.isEmpty(text)) {
                    CommonUITool.openErrorBox(getShell(), Messages.canNotMakeQueryBecauseNoSelected);
                    return;
                }
                CommonUITool.copyContentToClipboard(text);
            }

            public void widgetDefaultSelected(SelectionEvent e) {
            }
        });
        copyUpdateSqlFromRecordsItem = new ToolItem(topLeftToolBar, SWT.PUSH);
        copyUpdateSqlFromRecordsItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/record_to_update.png"));
        copyUpdateSqlFromRecordsItem.setToolTipText(Messages.makeUpdateFromSelectedRecord);
        copyUpdateSqlFromRecordsItem.addSelectionListener(new SelectionListener() {

            public void widgetSelected(SelectionEvent e) {
                if (editor == null) {
                    return;
                }
                String text = editor.getQueryExecuter().makeUpdateQueryWithSelectedRecords();
                if (StringUtil.isEmpty(text)) {
                    CommonUITool.openErrorBox(getShell(), Messages.canNotMakeQueryBecauseNoSelected);
                    return;
                }
                CommonUITool.copyContentToClipboard(text);
            }

            public void widgetDefaultSelected(SelectionEvent e) {
            }
        });
    }
    new ToolItem(topLeftToolBar, SWT.SEPARATOR);
    final ToolItem exportDataItem = new ToolItem(topLeftToolBar, SWT.PUSH);
    exportDataItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/table_data_export.png"));
    exportDataItem.setToolTipText(Messages.msgExportAllQueryResults);
    exportDataItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            CTabItem[] items = queryResultTabFolder.getItems();
            if (items == null || items.length == 0) {
                return;
            }
            List<QueryExecuter> qeList = new ArrayList<QueryExecuter>();
            for (CTabItem item : items) {
                if (!(item.getData() instanceof QueryExecuter)) {
                    continue;
                }
                QueryExecuter qe = (QueryExecuter) item.getData();
                qeList.add(qe);
            }
            if (qeList.isEmpty()) {
                return;
            }
            ExportQueryResultDialog dialog = new ExportQueryResultDialog(getShell(), qeList);
            dialog.open();
        }
    });
    new ToolItem(topLeftToolBar, SWT.SEPARATOR);
    final ToolItem showLogItem = new ToolItem(topLeftToolBar, SWT.PUSH);
    showLogItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/qe_panel_down.png"));
    showLogItem.setToolTipText(Messages.tooltip_qedit_log_show_hide);
    showLogItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            if (tableLogSash.getMaximizedControl() == null) {
                tableLogSash.setMaximizedControl(resultContainer);
                showLogItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/qe_panel_up.png"));
                tableLogSash.layout(true);
            } else {
                tableLogSash.setMaximizedControl(null);
                showLogItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/qe_panel_down.png"));
                tableLogSash.layout(true);
            }
        }
    });
    new ToolItem(topLeftToolBar, SWT.SEPARATOR);
    viewForm.setContent(tableLogSash);
    viewForm.setTopRight(topRightToolBar);
    viewForm.setTopLeft(topLeftToolBar);
    final QueryTableTabItem queryTableTabItem = new QueryTableTabItem(parentFolder, SWT.NONE);
    queryTableTabItem.setText(Messages.qedit_result + (result.idx + 1));
    queryTableTabItem.setControl(viewForm);
    queryTableTabItem.setData(result);
    queryTableTabItem.addDisposeListener(new DisposeListener() {

        public void widgetDisposed(DisposeEvent e) {
            InfoWindowManager.getInstance().updateContent(editor);
        }
    });
    parentFolder.setSelection(queryTableTabItem);
    tableSelectSupport.addSelectChangeListener(new ISelectionChangeListener() {

        @SuppressWarnings("unchecked")
        public void selectionChanged(SelectionChangeEvent event) {
            boolean active = event.selectedArray.length > 0;
            boolean canEdit = active && result.getEditable() && result.isEditMode();
            if (delRecordItem != null) {
                delRecordItem.setEnabled(canEdit);
            }
            if (copyInsertSqlFromRecordsItem != null) {
                copyInsertSqlFromRecordsItem.setEnabled(active);
            }
            if (copyUpdateSqlFromRecordsItem != null) {
                copyUpdateSqlFromRecordsItem.setEnabled(active);
            }
            /*TOOLS-3632 Add calculation info*/
            int count = event.selectedArray.length;
            BigDecimal sum = new BigDecimal(0);
            BigDecimal average = null;
            int numericCount = 0;
            QueryResultTableCalcInfo queryResultTableCalcInfo = null;
            StatusLineContrItem statusCont = LayoutManager.getInstance().getStatusLineContrItem();
            if (count > 1) {
                for (Point p : event.selectedArray) {
                    TableColumn column = result.tblResult.getColumn(p.x);
                    if (column == null) {
                        continue;
                    }
                    ColumnInfo columnInfo = (ColumnInfo) column.getData();
                    if (columnInfo == null) {
                        continue;
                    }
                    String dataType = columnInfo.getType();
                    if (!DataType.isNumberType(dataType)) {
                        continue;
                    }
                    TableItem item = result.tblResult.getItem(p.y);
                    if (item == null || item.getData() == null) {
                        continue;
                    }
                    Map<String, CellValue> dataMap = (Map<String, CellValue>) item.getData();
                    CellValue cellValue = dataMap.get(Integer.toString(p.x));
                    if (cellValue != null && cellValue.getValue() != null) {
                        numericCount++;
                        Object value = cellValue.getValue();
                        if (value instanceof Integer) {
                            sum = sum.add(new BigDecimal((Integer) value));
                        } else if (value instanceof Short) {
                            sum = sum.add(new BigDecimal((Short) value));
                        } else if (value instanceof Long) {
                            sum = sum.add(new BigDecimal((Long) value));
                        } else if (value instanceof Float) {
                            sum = sum.add(new BigDecimal((Float) value));
                        } else if (value instanceof Double) {
                            sum = sum.add(new BigDecimal((Double) value));
                        } else if (value instanceof BigDecimal) {
                            sum = sum.add((BigDecimal) value);
                        }
                    }
                }
                if (numericCount > 0) {
                    average = sum.divide(new BigDecimal(numericCount), 3, RoundingMode.HALF_UP);
                    queryResultTableCalcInfo = new QueryResultTableCalcInfo(count, average, sum);
                } else {
                    queryResultTableCalcInfo = new QueryResultTableCalcInfo(count);
                }
            }
            queryTableTabItem.setQueryResultTableCalcInfo(queryResultTableCalcInfo);
            InfoWindowManager.getInstance().updateContent(editor);
            statusCont.changeStuatusLineForViewOrEditPart(editor.getSelectedDatabase(), editor);
        }
    });
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) DisposeEvent(org.eclipse.swt.events.DisposeEvent) FocusEvent(org.eclipse.swt.events.FocusEvent) CTabItem(org.eclipse.swt.custom.CTabItem) SelectionEvent(org.eclipse.swt.events.SelectionEvent) List(java.util.List) ArrayList(java.util.ArrayList) CellValue(com.cubrid.common.ui.spi.table.CellValue) FormAttachment(org.eclipse.swt.layout.FormAttachment) FormData(org.eclipse.swt.layout.FormData) StatusLineContrItem(com.cubrid.common.ui.spi.contribution.StatusLineContrItem) StyledText(org.eclipse.swt.custom.StyledText) ParamSetException(com.cubrid.common.ui.spi.util.paramSetter.ParamSetException) FillLayout(org.eclipse.swt.layout.FillLayout) TableColumn(org.eclipse.swt.widgets.TableColumn) SelectionChangeEvent(com.cubrid.common.ui.spi.table.SelectionChangeEvent) ViewForm(org.eclipse.swt.custom.ViewForm) QueryResultTableCalcInfo(com.cubrid.common.ui.query.editor.QueryResultTableCalcInfo) ExportQueryResultDialog(com.cubrid.common.ui.query.dialog.ExportQueryResultDialog) FocusListener(org.eclipse.swt.events.FocusListener) Map(java.util.Map) SelectionListener(org.eclipse.swt.events.SelectionListener) DisposeListener(org.eclipse.swt.events.DisposeListener) TableCursor(org.eclipse.swt.custom.TableCursor) SQLException(java.sql.SQLException) ToolBarManager(org.eclipse.jface.action.ToolBarManager) ToolItem(org.eclipse.swt.widgets.ToolItem) FormLayout(org.eclipse.swt.layout.FormLayout) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) QueryTableTabItem(com.cubrid.common.ui.query.editor.QueryTableTabItem) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) BigDecimal(java.math.BigDecimal) SashForm(org.eclipse.swt.custom.SashForm) TableSelectSupport(com.cubrid.common.ui.spi.table.TableSelectSupport) ToolBar(org.eclipse.swt.widgets.ToolBar) ISelectionChangeListener(com.cubrid.common.ui.spi.table.ISelectionChangeListener)

Example 70 with FocusEvent

use of org.eclipse.swt.events.FocusEvent in project cubrid-manager by CUBRID.

the class SQLEditorComposite method addListener.

/**
	 * Add listener for text
	 */
private void addListener() {
    text.addModifyListener(new ModifyListener() {

        IAction undoAction = ActionManager.getInstance().getAction(UndoAction.ID);

        IAction redoAction = ActionManager.getInstance().getAction(RedoAction.ID);

        public void modifyText(ModifyEvent event) {
            setDirty(true);
            if (!undoAction.isEnabled()) {
                FocusAction.changeActionStatus(undoAction, text);
            }
            if (!redoAction.isEnabled()) {
                FocusAction.changeActionStatus(redoAction, text);
            }
            ServerInfo serverInfo = queryEditor == null || queryEditor.getSelectedServer() == null ? null : queryEditor.getSelectedServer().getServerInfo();
            boolean isLowerCase = QueryOptions.getKeywordLowercase(serverInfo);
            boolean isNoAutoUpperCase = QueryOptions.getNoAutoUppercaseKeyword(serverInfo);
            if (!isLowerCase && !isNoAutoUpperCase) {
                autoReplaceKeyword();
            }
        }

        // FIXME extract method?
        // replace keyword to upper case automatically
        public void autoReplaceKeyword() {
            if (pendingCompletionsListener) {
                return;
            }
            int pos = text.getCaretOffset() - 1;
            if (pos <= 0) {
                return;
            }
            String currentKey = text.getText(pos, pos);
            if (currentKey == null || currentKey.length() <= 0) {
                return;
            }
            char cur = currentKey.charAt(0);
            if (cur != ' ' && cur != '(' && cur != '\t' && cur != '\n' && cur != '\r' && cur != ',') {
                return;
            }
            pos--;
            if (pos < 0) {
                return;
            }
            int spos = pos - 20;
            if (spos < 0) {
                spos = 0;
            }
            String txt = text.getText(spos, pos);
            spos = pos + 1;
            for (int i = txt.length() - 1; i >= 0; i--) {
                char c = txt.charAt(i);
                if (c == ' ' || c == '\t' || c == '\n' || c == '(') {
                    break;
                }
                spos--;
            }
            int epos = pos;
            if (spos < 0 || epos < 0 || spos > epos) {
                return;
            }
            String currentKeyword = text.getText(spos, epos);
            if (currentKeyword == null) {
                return;
            }
            int len = currentKeyword.length();
            for (int i = 0; i < QuerySyntax.KEYWORDS_AUTO_UPPER.length; i++) {
                String keyword = QuerySyntax.KEYWORDS_AUTO_UPPER[i];
                if (keyword.equalsIgnoreCase(currentKeyword)) {
                    pendingCompletionsListener = true;
                    text.replaceTextRange(spos, len, keyword.toUpperCase());
                    pendingCompletionsListener = false;
                    break;
                }
            }
        }
    });
    text.addVerifyKeyListener(new VerifyKeyListener() {

        public void verifyKey(VerifyEvent event) {
            if ((event.stateMask & SWT.SHIFT) != 0 && event.keyCode == SWT.TAB) {
                event.doit = false;
                return;
            }
            if (((event.stateMask & SWT.CTRL) != 0 || (event.stateMask & SWT.COMMAND) != 0) && (event.keyCode == SWT.CR || event.keyCode == SWT.KEYPAD_CR)) {
                event.doit = false;
                return;
            }
            if (((event.stateMask & SWT.CTRL) != 0 || (event.stateMask & SWT.COMMAND) != 0) && (event.stateMask & SWT.ALT) != 0) {
                event.doit = false;
                return;
            }
            if (event.keyCode == SWT.TAB) {
                event.doit = false;
            } else {
                event.doit = true;
            }
        }
    });
    text.addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent event) {
            if ((event.stateMask & SWT.COMMAND) != 0) {
                //for Mac
                if ((event.stateMask & SWT.SHIFT) != 0) {
                    if (event.keyCode == SWT.CR || event.keyCode == SWT.KEYPAD_CR) {
                        queryEditor.runQuery(false);
                        return;
                    }
                }
            }
            if (event.keyCode == SWT.F5 || (event.stateMask & SWT.CTRL) != 0 && event.keyCode == 'e') {
                queryEditor.runQuery(false);
            } else if (event.keyCode == SWT.F6 || (event.stateMask & SWT.CTRL) != 0 && event.keyCode == 'l') {
                queryEditor.runQuery(true);
            } else if (event.keyCode == SWT.F7) {
                queryEditor.getCombinedQueryComposite().showQueryHistory();
            } else if (event.keyCode == SWT.F8) {
                queryEditor.runMultiQuery();
            } else if (event.keyCode == SWT.F1) {
                ActionManager.getInstance().getAction(HelpDocumentAction.ID).run();
            } else if (event.keyCode == SWT.F3) {
                if ((event.stateMask & SWT.SHIFT) == 0) {
                    TextEditorFindReplaceMediator.findNext();
                } else {
                    TextEditorFindReplaceMediator.findPrevious();
                }
            } else if (event.keyCode == SWT.F9) {
                queryEditor.setTuningModeButton(!queryEditor.isTuningModeButton());
            } else if (event.keyCode == SWT.F11) {
                queryEditor.getCombinedQueryComposite().rotateQueryPlanDisplayMode();
            } else if ((event.stateMask & SWT.CTRL) == 0 && (event.stateMask & SWT.SHIFT) == 0 && (event.stateMask & SWT.ALT) == 0 && event.keyCode == SWT.ESC) {
                int cursorOffset = text.getCaretOffset();
                text.setSelectionRange(cursorOffset, 0);
            } else if ((event.stateMask & SWT.CTRL) != 0 && (event.stateMask & SWT.SHIFT) == 0 && (event.stateMask & SWT.ALT) == 0 && event.keyCode == ',') {
                new QuickBuilderDialog(getShell(), SWT.NONE).open();
            } else if ((event.stateMask & SWT.CTRL) != 0 && event.keyCode == ' ') {
                contentAssistant.showPossibleCompletions();
            } else if ((event.stateMask & SWT.CTRL) != 0 && event.keyCode == 'r') {
                recentlyUsedSQLcontentAssistant.showPossibleCompletions();
            } else if ((event.stateMask & SWT.CTRL) != 0 && event.keyCode == 'd') {
                deleteRow();
            } else if ((event.stateMask & SWT.CTRL) != 0 && (event.stateMask & SWT.ALT) != 0 && event.keyCode == SWT.ARROW_DOWN) {
                duplicateRow();
            } else if ((event.stateMask & SWT.CTRL) != 0 && (event.stateMask & SWT.SHIFT) != 0 && event.keyCode == 't') {
                //add sql tab
                queryEditor.addEditorTab();
            } else if (((event.stateMask & SWT.CTRL) != 0 && (event.stateMask & SWT.SHIFT) != 0) && (event.keyCode == 'f' || event.keyCode == 'F')) {
                format();
            } else if ((event.stateMask & SWT.ALT) != 0 && event.keyCode == '/') {
                contentAssist();
            } else if ((event.stateMask & SWT.CTRL) != 0 && event.keyCode == 'o') {
                // Open a SQL file...
                ActionManager.getInstance().getAction(QueryOpenAction.ID).run();
            } else if ((event.stateMask & SWT.CTRL) != 0 && event.keyCode == 's') {
                // Save SQL to a file...
                try {
                    save();
                } catch (IOException e) {
                    MessageDialog.openError(getShell(), Messages.error, Messages.errCanNotSaveASQLFile);
                }
            } else if ((event.stateMask & SWT.CTRL) != 0 && (event.stateMask & SWT.SHIFT) == 0) {
                if (event.keyCode == '/') {
                    inputComment(false, false);
                } else if (event.keyCode == 'z') {
                    event.doit = false;
                    undo();
                } else if (event.keyCode == 'y') {
                    redo();
                } else if (event.keyCode == 'f' || event.keyCode == 'h') {
                    find();
                } else if ((event.stateMask & SWT.ALT) != 0 && (event.keyCode == SWT.CR || event.keyCode == SWT.KEYPAD_CR)) {
                    // NOPMD
                    queryEditor.runQueryPlanInCursorLine();
                } else if (event.keyCode == SWT.CR || event.keyCode == SWT.KEYPAD_CR) {
                    queryEditor.runQueryInCursorLine();
                } else if (event.keyCode == 'g') {
                    gotoLine();
                }
            } else if ((event.stateMask & SWT.CTRL) != 0 && (event.stateMask & SWT.SHIFT) != 0) {
                if ((event.stateMask & SWT.ALT) != 0 && (event.keyCode == SWT.CR || event.keyCode == SWT.KEYPAD_CR)) {
                    // NOPMD
                    queryEditor.runQuery(true);
                } else if (event.keyCode == SWT.CR || event.keyCode == SWT.KEYPAD_CR) {
                    queryEditor.runQuery(false);
                } else if (event.keyCode == 'x') {
                    toUpperCase();
                } else if (event.keyCode == 'y') {
                    toLowerCase();
                }
            } else if ((event.stateMask & SWT.SHIFT) == 0 && event.keyCode == SWT.TAB) {
                indent();
            } else if ((event.stateMask & SWT.SHIFT) != 0 && event.keyCode == SWT.TAB) {
                unindent();
            }
            if (SQLContentAssistProcessor.isShowProposal(event.character)) {
                contentAssistant.showPossibleCompletions();
                useCompletions = true;
            } else if ((event.character >= 'A' && event.character <= 'Z') || (event.character >= 'a' && event.character <= 'z')) {
                if (useCompletions) {
                    contentAssistant.showPossibleCompletions();
                }
                useCompletions = false;
            } else if (event.character == ' ' || event.character == '\t' || event.keyCode == SWT.KEYPAD_CR || event.keyCode == SWT.CR || event.keyCode == SWT.BS || (text.getText().trim().length() < 1)) {
                useCompletions = true;
            }
            // ctrl + alt + 1 ~ 9 : change editor tab
            if ((event.stateMask & SWT.CTRL) != 0 && (event.stateMask & SWT.ALT) != 0 && (event.keyCode >= '1' && event.keyCode <= '9')) {
                IWorkbenchPage page = LayoutUtil.getActivePage();
                if (page != null) {
                    int index = event.keyCode - '1';
                    IEditorReference[] refs = page.getEditorReferences();
                    for (int i = 0, selected = 0; i < refs.length; i++) {
                        IEditorReference ref = refs[i];
                        if (QueryEditorPart.ID.equals(ref.getId())) {
                            if (index == selected) {
                                IEditorPart part = ref.getEditor(true);
                                page.activate(part);
                            }
                            selected++;
                        }
                    }
                }
            } else if ((event.stateMask & SWT.CTRL) != 0 && (event.keyCode >= '1' && event.keyCode <= '9')) {
                // ctrl + 1 ~ 9 : change middle tab
                ITabSelection selector = queryEditor.getCombinedQueryComposite();
                selector.select(event.keyCode - '1', -1);
            } else if ((event.stateMask & SWT.ALT) != 0 && (event.keyCode >= '1' && event.keyCode <= '9')) {
                // alt + 1 ~ 9 : change bottom tab
                ITabSelection selector = queryEditor.getCombinedQueryComposite();
                selector.select(-1, event.keyCode - '1');
            }
        }
    });
    text.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) {
            IAction copyAction = ActionManager.getInstance().getAction(CopyAction.ID);
            copyAction.setEnabled(false);
            IAction cutAction = ActionManager.getInstance().getAction(CutAction.ID);
            cutAction.setEnabled(false);
            IAction reformatColumnsAliasAction = ActionManager.getInstance().getAction(ReformatColumnsAliasAction.ID);
            reformatColumnsAliasAction.setEnabled(false);
            // show schema info view with a selected text
            IAction showSchemaAction = ActionManager.getInstance().getAction(ShowSchemaAction.ID);
            showSchemaAction.setEnabled(false);
            if (event.getSource() instanceof StyledText) {
                StyledText stext = (StyledText) event.getSource();
                if (stext != null && stext.getSelectionText() != null && stext.getSelectionText().length() > 0) {
                    copyAction.setEnabled(true);
                    cutAction.setEnabled(true);
                    reformatColumnsAliasAction.setEnabled(true);
                    CubridDatabase db = queryEditor.getSelectedDatabase();
                    if (DatabaseNavigatorMenu.SELF_DATABASE_ID.equals(db.getId()) && ApplicationType.CUBRID_MANAGER.equals(PerspectiveManager.getInstance().getCurrentMode())) {
                        showSchemaAction.setEnabled(false);
                    } else {
                        showSchemaAction.setEnabled(true);
                    }
                }
            }
        }
    });
    text.addFocusListener(new FocusAdapter() {

        public void focusGained(FocusEvent event) {
            ActionManager.getInstance().changeFocusProvider(text);
        }
    });
    TextEditorFindReplaceMediator editorDialogMediator = new TextEditorFindReplaceMediator();
    text.addFocusListener(editorDialogMediator);
}
Also used : FocusAdapter(org.eclipse.swt.events.FocusAdapter) StyledText(org.eclipse.swt.custom.StyledText) ModifyListener(org.eclipse.swt.events.ModifyListener) IAction(org.eclipse.jface.action.IAction) VerifyKeyListener(org.eclipse.swt.custom.VerifyKeyListener) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) KeyAdapter(org.eclipse.swt.events.KeyAdapter) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) IOException(java.io.IOException) IEditorPart(org.eclipse.ui.IEditorPart) FocusEvent(org.eclipse.swt.events.FocusEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) QuickBuilderDialog(com.cubrid.common.ui.query.builder.quickbuilder.QuickBuilderDialog) IEditorReference(org.eclipse.ui.IEditorReference) TextEditorFindReplaceMediator(com.cubrid.tool.editor.TextEditorFindReplaceMediator) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) VerifyEvent(org.eclipse.swt.events.VerifyEvent)

Aggregations

FocusEvent (org.eclipse.swt.events.FocusEvent)115 FocusAdapter (org.eclipse.swt.events.FocusAdapter)64 SelectionEvent (org.eclipse.swt.events.SelectionEvent)54 FocusListener (org.eclipse.swt.events.FocusListener)47 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)42 GridData (org.eclipse.swt.layout.GridData)38 Composite (org.eclipse.swt.widgets.Composite)34 Text (org.eclipse.swt.widgets.Text)33 GridLayout (org.eclipse.swt.layout.GridLayout)32 Label (org.eclipse.swt.widgets.Label)26 Menu (org.eclipse.swt.widgets.Menu)22 KeyEvent (org.eclipse.swt.events.KeyEvent)21 Button (org.eclipse.swt.widgets.Button)21 Point (org.eclipse.swt.graphics.Point)20 ModifyEvent (org.eclipse.swt.events.ModifyEvent)19 MenuManager (org.eclipse.jface.action.MenuManager)18 ModifyListener (org.eclipse.swt.events.ModifyListener)18 Combo (org.eclipse.swt.widgets.Combo)17 Group (org.eclipse.swt.widgets.Group)17 SelectionListener (org.eclipse.swt.events.SelectionListener)15