Search in sources :

Example 46 with SelectionListener

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

the class ExportQueryResultDialog method createComposite.

/**
	 * Create the composite
	 *
	 * @param parent Composite
	 */
private void createComposite(Composite parent) {
    final boolean isOneResult = queryExecuterList.size() == 1;
    String tableName = null;
    try {
        tableName = UIQueryUtil.getTableNameFromQuery(queryExecuterList.get(0).getConnection().checkAndConnectQuietly(), queryExecuterList.get(0).getOrignQuery());
    } finally {
        if (queryExecuterList.get(0).getConnection().isAutoClosable()) {
            queryExecuterList.get(0).getConnection().close();
        }
    }
    boolean isTable = isOneResult && !StringUtil.isEmpty(tableName);
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout());
    composite.setLayoutData(CommonUITool.createGridData(GridData.FILL_BOTH, 1, 1, -1, -1));
    // where to export group
    Group whereOptionGroup = new Group(composite, SWT.None);
    whereOptionGroup.setText(Messages.grpWhereExport);
    whereOptionGroup.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 1, 1, -1, -1));
    whereOptionGroup.setLayout(new GridLayout(2, false));
    Label fileTypeLabel = new Label(whereOptionGroup, SWT.None);
    fileTypeLabel.setText(Messages.lblFileType);
    fileTypeLabel.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    Composite fileTypeComposite = new Composite(whereOptionGroup, SWT.None);
    fileTypeComposite.setLayoutData(CommonUITool.createGridData(GridData.FILL_BOTH, 1, 1, -1, -1));
    int layoutCount = 0;
    if (isTable) {
        sqlButton = new Button(fileTypeComposite, SWT.RADIO);
        sqlButton.setText("SQL");
        sqlButton.setLayoutData(CommonUITool.createGridData(1, 1, 50, -1));
        sqlButton.setSelection(true);
        sqlButton.addSelectionListener(new SelectionListener() {

            public void widgetSelected(SelectionEvent e) {
                widgetDefaultSelected(e);
            }

            public void widgetDefaultSelected(SelectionEvent e) {
                useFirstAsColumnBtn.setEnabled(false);
                setNullWidgetStatus(false);
                setDelimiterWidgetStatus(false);
                fileCharsetCombo.setText(DEFAULT_FILE_CHARSET);
                changeFileSuffix();
                verify();
            }
        });
        layoutCount++;
    }
    csvButton = new Button(fileTypeComposite, SWT.RADIO);
    csvButton.setText("CSV");
    csvButton.setSelection(isTable ? false : true);
    csvButton.setLayoutData(CommonUITool.createGridData(1, 1, 50, -1));
    csvButton.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            widgetDefaultSelected(e);
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            useFirstAsColumnBtn.setEnabled(true);
            setNullWidgetStatus(true);
            setDelimiterWidgetStatus(false);
            fileCharsetCombo.setText(DEFAULT_FILE_CHARSET);
            changeFileSuffix();
            verify();
        }
    });
    layoutCount++;
    xlsButton = new Button(fileTypeComposite, SWT.RADIO);
    xlsButton.setText("XLS");
    xlsButton.setLayoutData(CommonUITool.createGridData(1, 1, 50, -1));
    xlsButton.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            widgetDefaultSelected(e);
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            useFirstAsColumnBtn.setEnabled(true);
            setNullWidgetStatus(true);
            setDelimiterWidgetStatus(false);
            String charset = StringUtil.getDefaultCharset();
            if (charset != null) {
                fileCharsetCombo.setText(charset);
            }
            changeFileSuffix();
            verify();
        }
    });
    layoutCount++;
    xlsxButton = new Button(fileTypeComposite, SWT.RADIO);
    xlsxButton.setText("XLSX");
    xlsxButton.setLayoutData(CommonUITool.createGridData(1, 1, 57, -1));
    xlsxButton.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            widgetDefaultSelected(e);
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            useFirstAsColumnBtn.setEnabled(true);
            setNullWidgetStatus(true);
            setDelimiterWidgetStatus(false);
            fileCharsetCombo.setText(DEFAULT_FILE_CHARSET);
            changeFileSuffix();
            verify();
        }
    });
    layoutCount++;
    txtButton = new Button(fileTypeComposite, SWT.RADIO);
    txtButton.setText("TXT");
    txtButton.setLayoutData(CommonUITool.createGridData(1, 1, 50, -1));
    txtButton.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            widgetDefaultSelected(e);
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            useFirstAsColumnBtn.setEnabled(true);
            setNullWidgetStatus(true);
            setDelimiterWidgetStatus(true);
            fileCharsetCombo.setText(DEFAULT_FILE_CHARSET);
            changeFileSuffix();
            verify();
        }
    });
    layoutCount++;
    fileTypeComposite.setLayout(new GridLayout(layoutCount, false));
    Label pathLabel = new Label(whereOptionGroup, SWT.None);
    pathLabel.setText(Messages.lblFilePath);
    pathLabel.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    Composite fileComposite = new Composite(whereOptionGroup, SWT.None);
    fileComposite.setLayoutData(CommonUITool.createGridData(GridData.FILL_BOTH, 1, 1, -1, -1));
    fileComposite.setLayout(new GridLayout(2, false));
    filePathText = new Text(fileComposite, SWT.BORDER);
    filePathText.setLayoutData(CommonUITool.createGridData(GridData.FILL_BOTH, 1, 1, -1, -1));
    Button browseButton = new Button(fileComposite, SWT.None);
    browseButton.setText(Messages.btnBrowse);
    browseButton.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    browseButton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            File file = FileDialogUtils.getDataExportedFile(getShell(), new String[] { "*.*" }, new String[] { "*.*" }, null);
            if (file == null) {
                return;
            }
            filePathText.setText(file.getAbsolutePath() + getFileExtName(getFileType()));
            verify();
        }
    });
    Group parsingGroup = new Group(composite, SWT.None);
    parsingGroup.setText(Messages.grpParsingOption);
    parsingGroup.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 1, 1, -1, -1));
    parsingGroup.setLayout(new GridLayout(4, false));
    Label threadCountLabel = new Label(parsingGroup, SWT.None);
    threadCountLabel.setLayoutData(CommonUITool.createGridData(GridData.HORIZONTAL_ALIGN_BEGINNING, 1, 1, 100, -1));
    threadCountLabel.setText(Messages.lblThreadCount);
    threadCountSpinner = new Spinner(parsingGroup, SWT.BORDER | SWT.LEFT);
    threadCountSpinner.setValues(queryExecuterList.size(), 1, queryExecuterList.size(), 0, 1, 1);
    threadCountSpinner.setLayoutData(CommonUITool.createGridData(GridData.HORIZONTAL_ALIGN_BEGINNING, 1, 1, 100, -1));
    exportFromCacheBtn = new Button(parsingGroup, SWT.CHECK);
    {
        exportFromCacheBtn.setText(Messages.lblExportFromCache);
        exportFromCacheBtn.setLayoutData(CommonUITool.createGridData(GridData.HORIZONTAL_ALIGN_BEGINNING, 2, 1, -1, -1));
        exportFromCacheBtn.setSelection(false);
        exportFromCacheBtn.setToolTipText(Messages.tipExportFromCache);
    }
    Label dbCharsetLabel = new Label(parsingGroup, SWT.None);
    dbCharsetLabel.setLayoutData(CommonUITool.createGridData(GridData.HORIZONTAL_ALIGN_BEGINNING, 1, 1, 110, -1));
    dbCharsetLabel.setText(Messages.lblJDBCCharset);
    dbCharsetCombo = new Combo(parsingGroup, SWT.BORDER);
    dbCharsetCombo.setLayoutData(CommonUITool.createGridData(1, 1, 100, 21));
    String dbCharset = database.getDatabaseInfo().getCharSet();
    dbCharsetCombo.setItems(QueryOptions.getAllCharset(null));
    if (dbCharset != null && dbCharset.length() > 0) {
        dbCharsetCombo.setText(dbCharset);
    }
    dbCharsetCombo.setEnabled(false);
    Label fileCharsetLabel = new Label(parsingGroup, SWT.None);
    fileCharsetLabel.setLayoutData(CommonUITool.createGridData(GridData.HORIZONTAL_ALIGN_BEGINNING, 1, 1, -1, -1));
    fileCharsetLabel.setText(Messages.lblFileCharset);
    fileCharsetCombo = new Combo(parsingGroup, SWT.BORDER);
    fileCharsetCombo.setLayoutData(CommonUITool.createGridData(1, 1, 100, 21));
    fileCharsetCombo.setItems(QueryOptions.getAllCharset(null));
    fileCharsetCombo.setText(DEFAULT_FILE_CHARSET);
    fileCharsetCombo.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent event) {
            verify();
        }
    });
    Group dataOptionGroup = new Group(composite, SWT.None);
    dataOptionGroup.setText(Messages.grpDataOptions);
    dataOptionGroup.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 1, 1, -1, -1));
    dataOptionGroup.setLayout(new GridLayout(2, false));
    useFirstAsColumnBtn = new Button(dataOptionGroup, SWT.CHECK);
    {
        useFirstAsColumnBtn.setText(Messages.btnFirstLineAsCol);
        GridData gridData = new GridData();
        gridData.widthHint = 400;
        gridData.grabExcessHorizontalSpace = true;
        gridData.horizontalIndent = 0;
        gridData.horizontalSpan = 2;
        useFirstAsColumnBtn.setLayoutData(gridData);
        useFirstAsColumnBtn.setSelection(true);
    }
    Group delimiterOptionGroup = new Group(dataOptionGroup, SWT.None);
    delimiterOptionGroup.setText(Messages.grpDelimiter);
    delimiterOptionGroup.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 1, 1, -1, -1));
    delimiterOptionGroup.setLayout(new GridLayout(2, false));
    Label rowLabel = new Label(delimiterOptionGroup, SWT.None);
    rowLabel.setLayoutData(CommonUITool.createGridData(GridData.HORIZONTAL_ALIGN_BEGINNING, 1, 1, -1, -1));
    rowLabel.setText(Messages.lblRow);
    rowDelimiterCombo = new Combo(delimiterOptionGroup, SWT.BORDER);
    rowDelimiterCombo.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    rowDelimiterCombo.setTextLimit(32);
    rowDelimiterCombo.setItems(rowDelimeterName);
    rowDelimiterCombo.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent event) {
            verify();
        }
    });
    Label columnLabel = new Label(delimiterOptionGroup, SWT.None);
    columnLabel.setLayoutData(CommonUITool.createGridData(GridData.HORIZONTAL_ALIGN_BEGINNING, 1, 1, -1, -1));
    columnLabel.setText(Messages.lblCol);
    columnDelimiterCombo = new Combo(delimiterOptionGroup, SWT.BORDER);
    columnDelimiterCombo.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    columnDelimiterCombo.setTextLimit(32);
    columnDelimiterCombo.setItems(columnDelimeterName);
    columnDelimiterCombo.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent event) {
            verify();
        }
    });
    Group nullValueGroup = new Group(dataOptionGroup, SWT.None);
    nullValueGroup.setText(Messages.grpNullOption);
    nullValueGroup.setLayoutData(CommonUITool.createGridData(GridData.FILL_BOTH, 1, 1, -1, -1));
    nullValueGroup.setLayout(new GridLayout(3, false));
    nullOneButton = new Button(nullValueGroup, SWT.RADIO);
    nullOneButton.setText(NULL_VALUES[0]);
    nullOneButton.setLayoutData(CommonUITool.createGridData(1, 1, 70, -1));
    nullOneButton.setSelection(true);
    nullTwoButton = new Button(nullValueGroup, SWT.RADIO);
    nullTwoButton.setText(NULL_VALUES[1]);
    nullTwoButton.setLayoutData(CommonUITool.createGridData(2, 1, 70, -1));
    nullThreeButton = new Button(nullValueGroup, SWT.RADIO);
    nullThreeButton.setText(NULL_VALUES[2]);
    nullThreeButton.setLayoutData(CommonUITool.createGridData(1, 1, 70, -1));
    otherButton = new Button(nullValueGroup, SWT.RADIO);
    otherButton.setText(Messages.btnOther);
    otherButton.setLayoutData(CommonUITool.createGridData(1, 1, 70, -1));
    otherButton.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            widgetDefaultSelected(e);
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            verify();
        }
    });
    otherText = new Text(nullValueGroup, SWT.BORDER);
    otherText.setLayoutData(CommonUITool.createGridData(1, 1, 60, 14));
    otherText.setTextLimit(64);
    otherText.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent event) {
            verify();
        }
    });
    if (sqlButton != null && sqlButton.getSelection()) {
        useFirstAsColumnBtn.setEnabled(false);
        setDelimiterWidgetStatus(false);
        setNullWidgetStatus(false);
    } else {
        useFirstAsColumnBtn.setEnabled(true);
        setDelimiterWidgetStatus(false);
        setNullWidgetStatus(true);
    }
}
Also used : Group(org.eclipse.swt.widgets.Group) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) Spinner(org.eclipse.swt.widgets.Spinner) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) Combo(org.eclipse.swt.widgets.Combo) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GridData(org.eclipse.swt.layout.GridData) File(java.io.File) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 47 with SelectionListener

use of org.eclipse.swt.events.SelectionListener 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)

Example 48 with SelectionListener

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

the class QueryRecordListComparator method createQueryCompareTab.

private void createQueryCompareTab(CTabFolder tabFolder) {
    CTabItem item = new CTabItem(tabFolder, SWT.None | SWT.MULTI | SWT.V_SCROLL);
    item.setText(Messages.tabItemQueryCompare);
    Composite composite = new Composite(tabFolder, SWT.None);
    composite.setLayout(new GridLayout());
    item.setControl(composite);
    Composite topComposite = new Composite(composite, SWT.None);
    topComposite.setLayout(new FormLayout());
    topComposite.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 1, 1, -1, 25));
    Composite leftTopComposite = new Composite(topComposite, SWT.None);
    FormData leftTopData = new FormData();
    leftTopData.top = new FormAttachment(0, 0);
    leftTopData.bottom = new FormAttachment(100, 0);
    leftTopData.left = new FormAttachment(0, 0);
    leftTopData.right = new FormAttachment(50, 0);
    leftTopComposite.setLayoutData(leftTopData);
    leftTopComposite.setLayout(new GridLayout(2, false));
    Composite rightTopComposite = new Composite(topComposite, SWT.None);
    FormData rightTopData = new FormData();
    rightTopData.top = new FormAttachment(0, 0);
    rightTopData.bottom = new FormAttachment(100, 0);
    rightTopData.left = new FormAttachment(50, 0);
    rightTopData.right = new FormAttachment(100, 0);
    rightTopComposite.setLayoutData(rightTopData);
    rightTopComposite.setLayout(new GridLayout(5, false));
    Label leftLabel = new Label(leftTopComposite, SWT.None);
    leftLabel.setText(Messages.lblQuery);
    leftLabel.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    queryRecordLeftCombo = new Combo(leftTopComposite, SWT.READ_ONLY);
    queryRecordLeftCombo.setLayoutData(CommonUITool.createGridData(1, 1, 200, -1));
    queryRecordLeftCombo.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            displayCompareQueryRecord();
        }

        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
    Label rightLabel = new Label(rightTopComposite, SWT.None);
    rightLabel.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    rightLabel.setText(Messages.lblQuery);
    queryRecordRightCombo = new Combo(rightTopComposite, SWT.READ_ONLY);
    queryRecordRightCombo.setLayoutData(CommonUITool.createGridData(1, 1, 200, -1));
    queryRecordRightCombo.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            displayCompareQueryRecord();
        }

        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
    ToolBar leftToolBar = new ToolBar(rightTopComposite, SWT.None);
    leftToolBar.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    compareItem = new ToolItem(leftToolBar, SWT.None);
    compareItem.setImage(CommonUIPlugin.getImage("icons/action/refresh_tuning.png"));
    compareItem.setToolTipText(Messages.itemTooltipCompare);
    compareItem.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            widgetDefaultSelected(e);
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            displayCompareQueryRecord();
        }
    });
    delQueryRecordItem = new ToolItem(leftToolBar, SWT.None);
    delQueryRecordItem.setImage(CommonUIPlugin.getImage("icons/queryplan/delete_query.gif"));
    delQueryRecordItem.setToolTipText(Messages.itemTooltipRemoveQuery);
    delQueryRecordItem.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            widgetDefaultSelected(e);
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            if (CommonUITool.openConfirmBox(Messages.confirmDeleteQueryPlanOnTuner)) {
                removeQueryRecord();
            }
        }
    });
    Composite folderPlaceComposite = new Composite(rightTopComposite, SWT.None);
    folderPlaceComposite.setLayoutData(CommonUITool.createGridData(GridData.FILL_BOTH, 1, 1, -1, -1));
    ToolBar rightToolBar = new ToolBar(rightTopComposite, SWT.None);
    rightToolBar.setLayoutData(CommonUITool.createGridData(GridData.HORIZONTAL_ALIGN_END, 1, 1, -1, -1));
    multiRunItem = new ToolItem(rightToolBar, SWT.None);
    multiRunItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/query_multi_run.png"));
    multiRunItem.setToolTipText(Messages.itemTooltipRunAgain);
    multiRunItem.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            widgetDefaultSelected(e);
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            QueryRecord leftRecord = getSelectedLeftQueryRecord();
            QueryRecord rightRecord = getSelectedRightQueryRecord();
            if (leftRecord == null || rightRecord == null) {
                CommonUITool.openErrorBox(Messages.errCompareQueryEmpty);
                return;
            }
            runQueryPlanAgain(leftRecord.getQuery(), rightRecord.getQuery());
        }
    });
    sqlModeItem = new ToolItem(rightToolBar, SWT.CHECK);
    sqlModeItem.setImage(CommonUIPlugin.getImage("icons/queryplan/sql_compare.gif"));
    sqlModeItem.setToolTipText(Messages.itemTooltipQuery);
    sqlModeItem.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            widgetDefaultSelected(e);
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            updateCompareDisplayModel(DISPLAY_SQL);
        }
    });
    textModelItem = new ToolItem(rightToolBar, SWT.CHECK);
    textModelItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/qe_explain_mode_raw.png"));
    textModelItem.setToolTipText(Messages.tooltip_qedit_explain_display_mode);
    textModelItem.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            widgetDefaultSelected(e);
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            updateCompareDisplayModel(DISPLAY_TEXT);
        }
    });
    treeModelItem = new ToolItem(rightToolBar, SWT.CHECK);
    treeModelItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/qe_explain_mode_tree.png"));
    treeModelItem.setToolTipText(Messages.tooltip_qedit_explain_display_mode);
    treeModelItem.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            widgetDefaultSelected(e);
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            updateCompareDisplayModel(DISPLAY_TREE);
        }
    });
    graphModelItem = new ToolItem(rightToolBar, SWT.CHECK);
    graphModelItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/qe_explain_mode_graph.png"));
    graphModelItem.setToolTipText(Messages.tooltip_qedit_explain_display_mode);
    graphModelItem.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            widgetDefaultSelected(e);
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            updateCompareDisplayModel(DISPLAY_GRAPH);
        }
    });
    Composite tablesComposite = new Composite(composite, SWT.None);
    tablesComposite.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 1, 1, -1, 60));
    tablesComposite.setLayout(new FormLayout());
    /*Left composite*/
    Composite leftTableComposite = new Composite(tablesComposite, SWT.BORDER);
    leftTableComposite.setLayout(new GridLayout());
    FormData leftTableData = new FormData();
    leftTableData.top = new FormAttachment(0, 0);
    leftTableData.bottom = new FormAttachment(100, 0);
    leftTableData.left = new FormAttachment(0, 0);
    leftTableData.right = new FormAttachment(50, -2);
    leftTableComposite.setLayoutData(leftTableData);
    /*Right composite*/
    Composite rightTableComposite = new Composite(tablesComposite, SWT.BORDER);
    rightTableComposite.setLayout(new GridLayout());
    FormData rightTabelData = new FormData();
    rightTabelData.top = new FormAttachment(0, 0);
    rightTabelData.bottom = new FormAttachment(100, 0);
    rightTabelData.left = new FormAttachment(50, 2);
    rightTabelData.right = new FormAttachment(100, 0);
    rightTableComposite.setLayoutData(rightTabelData);
    compareLeftTableViewer = new TableViewer(leftTableComposite, SWT.FULL_SELECTION);
    compareLeftTableViewer.getTable().setLayoutData(CommonUITool.createGridData(GridData.FILL_BOTH, 1, 1, -1, -1));
    compareLeftTableViewer.getTable().setHeaderVisible(true);
    compareLeftTableViewer.getTable().setLinesVisible(false);
    compareLeftTableViewer.setContentProvider(new QueryPlanContentProvider());
    compareLeftTableViewer.setLabelProvider(new QueryPlanLabelPrivoder(compareLeftTableViewer, false));
    TableColumn fetchColumnLeft = new TableColumn(compareLeftTableViewer.getTable(), SWT.None);
    fetchColumnLeft.setText(Messages.columnFetches);
    fetchColumnLeft.setWidth(60);
    TableColumn dirtyColumnLeft = new TableColumn(compareLeftTableViewer.getTable(), SWT.None);
    dirtyColumnLeft.setText(Messages.columnDirties);
    dirtyColumnLeft.setWidth(60);
    TableColumn ioReadColumnLeft = new TableColumn(compareLeftTableViewer.getTable(), SWT.None);
    ioReadColumnLeft.setText(Messages.columnIORead);
    ioReadColumnLeft.setWidth(80);
    TableColumn ioWriteColumnLeft = new TableColumn(compareLeftTableViewer.getTable(), SWT.None);
    ioWriteColumnLeft.setText(Messages.columnIOWrite);
    ioWriteColumnLeft.setWidth(80);
    TableColumn costColumnLeft = new TableColumn(compareLeftTableViewer.getTable(), SWT.None);
    costColumnLeft.setText(Messages.columnCost);
    costColumnLeft.setWidth(60);
    compareRightTableViewer = new TableViewer(rightTableComposite, SWT.FULL_SELECTION);
    compareRightTableViewer.getTable().setLayoutData(CommonUITool.createGridData(GridData.FILL_BOTH, 1, 1, -1, -1));
    compareRightTableViewer.getTable().setHeaderVisible(true);
    compareRightTableViewer.getTable().setLinesVisible(false);
    compareRightTableViewer.setContentProvider(new QueryPlanContentProvider());
    compareRightTableViewer.setLabelProvider(new QueryPlanLabelPrivoder(compareRightTableViewer, false));
    TableColumn fetchColumnRight = new TableColumn(compareRightTableViewer.getTable(), SWT.None);
    fetchColumnRight.setText(Messages.columnFetches);
    fetchColumnRight.setWidth(60);
    TableColumn dirtyColumnRight = new TableColumn(compareRightTableViewer.getTable(), SWT.None);
    dirtyColumnRight.setText(Messages.columnDirties);
    dirtyColumnRight.setWidth(60);
    TableColumn ioReadColumnRight = new TableColumn(compareRightTableViewer.getTable(), SWT.None);
    ioReadColumnRight.setText(Messages.columnIORead);
    ioReadColumnRight.setWidth(80);
    TableColumn ioWriteColumnRight = new TableColumn(compareRightTableViewer.getTable(), SWT.None);
    ioWriteColumnRight.setText(Messages.columnIOWrite);
    ioWriteColumnRight.setWidth(80);
    TableColumn costColumnRight = new TableColumn(compareRightTableViewer.getTable(), SWT.None);
    costColumnRight.setText(Messages.columnCost);
    costColumnRight.setWidth(60);
    queryPlanCompareSashForm = new SashForm(composite, SWT.VERTICAL);
    queryPlanCompareSashForm.setLayoutData(CommonUITool.createGridData(GridData.FILL_BOTH, 1, 1, -1, -1));
    queryPlanCompareSashForm.setBackground(SASH_COLOR);
    queryPlanCompareSashForm.setLayout(new GridLayout());
    queryPlanCompareSashForm.setLayoutData(CommonUITool.createGridData(GridData.FILL_BOTH, 1, 1, -1, -1));
    Composite textMergeComposite = new Composite(queryPlanCompareSashForm, SWT.None);
    textMergeComposite.setLayoutData(CommonUITool.createGridData(GridData.FILL_BOTH, 1, 1, -1, -1));
    textMergeComposite.setLayout(new FillLayout());
    textMergeConfig = new CompareConfiguration();
    textMergeConfig.setProperty(CompareConfiguration.SHOW_PSEUDO_CONFLICTS, Boolean.FALSE);
    textMergeConfig.setProperty(CompareConfiguration.IGNORE_WHITESPACE, Boolean.TRUE);
    textMergeConfig.setLeftEditable(false);
    textMergeConfig.setRightEditable(false);
    textMergeViewer = new TextMergeViewer(textMergeComposite, SWT.BORDER, textMergeConfig);
    DiffNode queryDiffNode = new DiffNode(null, Differencer.CHANGE, null, new TextCompareInput(""), new TextCompareInput(""));
    textMergeViewer.setInput(queryDiffNode);
    Composite compareQueryPlanComposite = new Composite(queryPlanCompareSashForm, SWT.None);
    compareQueryPlanComposite.setLayoutData(CommonUITool.createGridData(GridData.FILL_BOTH, 1, 1, -1, -1));
    compareQueryPlanComposite.setLayout(new FormLayout());
    DatabaseInfo databaseInfo = database == null ? null : database.getDatabaseInfo();
    leftComparePlanComposite = new QueryPlanComposite(compareQueryPlanComposite, SWT.BORDER, null, databaseInfo);
    FormData leftData = new FormData();
    leftData.top = new FormAttachment(0, 0);
    leftData.bottom = new FormAttachment(100, 0);
    leftData.left = new FormAttachment(0, 0);
    leftData.right = new FormAttachment(50, 0);
    leftComparePlanComposite.setLayoutData(leftData);
    rightComparePlanComposite = new QueryPlanComposite(compareQueryPlanComposite, SWT.BORDER, null, databaseInfo);
    FormData rightData = new FormData();
    rightData.top = new FormAttachment(0, 0);
    rightData.bottom = new FormAttachment(100, 0);
    rightData.left = new FormAttachment(50, 0);
    rightData.right = new FormAttachment(100, 0);
    rightComparePlanComposite.setLayoutData(rightData);
    queryPlanCompareSashForm.setWeights(new int[] { 100, 0 });
}
Also used : DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) CompareConfiguration(org.eclipse.compare.CompareConfiguration) Label(org.eclipse.swt.widgets.Label) DiffNode(org.eclipse.compare.structuremergeviewer.DiffNode) Combo(org.eclipse.swt.widgets.Combo) CTabItem(org.eclipse.swt.custom.CTabItem) TextMergeViewer(org.eclipse.compare.contentmergeviewer.TextMergeViewer) GridLayout(org.eclipse.swt.layout.GridLayout) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TextCompareInput(com.cubrid.common.ui.compare.schema.control.TextCompareInput) FormAttachment(org.eclipse.swt.layout.FormAttachment) ToolItem(org.eclipse.swt.widgets.ToolItem) FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) Composite(org.eclipse.swt.widgets.Composite) QueryPlanComposite(com.cubrid.common.ui.query.control.queryplan.QueryPlanComposite) QueryPlanComposite(com.cubrid.common.ui.query.control.queryplan.QueryPlanComposite) QueryRecord(com.cubrid.common.ui.query.tuner.QueryRecord) FillLayout(org.eclipse.swt.layout.FillLayout) TableColumn(org.eclipse.swt.widgets.TableColumn) SashForm(org.eclipse.swt.custom.SashForm) ToolBar(org.eclipse.swt.widgets.ToolBar) TableViewer(org.eclipse.jface.viewers.TableViewer) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 49 with SelectionListener

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

the class QueryRecordListComparator method createResultColumn.

private void createResultColumn(final TableViewer tableViewer, final QueryRecord queryRecord) {
    if (queryRecord != null) {
        TableColumn[] tblColumn = new TableColumn[(queryRecord.getColumnInfoList() == null ? 0 : queryRecord.getColumnInfoList().size()) + 1];
        tblColumn[0] = new TableColumn(tableViewer.getTable(), SWT.NONE);
        tblColumn[0].setText("NO");
        tblColumn[0].setWidth(40);
        if (queryRecord.getColumnInfoList() == null) {
            return;
        }
        final Map<String, ColumnComparator> colComparatorMap = new HashMap<String, ColumnComparator>();
        for (int j = 0; j < queryRecord.getColumnInfoList().size(); j++) {
            tblColumn[j + 1] = new TableColumn(tableViewer.getTable(), SWT.NONE);
            ColumnInfo columnInfo = (ColumnInfo) queryRecord.getColumnInfoList().get(j);
            String name = columnInfo.getName();
            String type = columnInfo.getType();
            tblColumn[j + 1].setText(name);
            tblColumn[j + 1].setToolTipText(columnInfo.getComleteType());
            tblColumn[j + 1].setData(columnInfo);
            tblColumn[j + 1].pack();
            ColumnComparator comparator = new ColumnComparator(columnInfo.getIndex(), type, true);
            if (colComparatorMap != null) {
                colComparatorMap.put(columnInfo.getIndex(), comparator);
            }
            tblColumn[j + 1].addSelectionListener(new SelectionListener() {

                @SuppressWarnings("unchecked")
                public void widgetSelected(SelectionEvent event) {
                    TableColumn column = (TableColumn) event.widget;
                    if (column == null || column.getText() == null || column.getText().trim().length() == 0) {
                        return;
                    }
                    TableColumn sortedColumn = tableViewer.getTable().getSortColumn();
                    int width = column.getWidth();
                    ColumnInfo columnInfo = (ColumnInfo) column.getData();
                    ColumnComparator comparator = colComparatorMap.get(columnInfo.getIndex());
                    tableViewer.getTable().setSortColumn(column);
                    tableViewer.getTable().setSortDirection(comparator.isAsc() ? SWT.UP : SWT.DOWN);
                    Collections.sort(queryRecord.getPageData(), comparator);
                    comparator.setAsc(!comparator.isAsc());
                    column.pack();
                    if (column.equals(sortedColumn)) {
                        column.setWidth(width);
                    } else {
                        column.setWidth(width + 25);
                    }
                    tableViewer.refresh();
                }

                public void widgetDefaultSelected(SelectionEvent event) {
                }
            });
        }
    }
}
Also used : HashMap(java.util.HashMap) ColumnComparator(com.cubrid.common.ui.query.control.ColumnComparator) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ColumnInfo(com.cubrid.common.ui.query.control.ColumnInfo) TableColumn(org.eclipse.swt.widgets.TableColumn) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 50 with SelectionListener

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

the class JaretTablePrintDialog method createPrinterSelection.

private void createPrinterSelection(Composite parent) {
    Composite area = new Composite(parent, SWT.NULL);
    area.setLayout(new RowLayout());
    // area.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
    _printerCombo = new CCombo(area, SWT.BORDER | SWT.READ_ONLY);
    _printerCombo.setItems(_printers);
    _printerCombo.select(_pIdx);
    Button select = new Button(area, SWT.PUSH);
    select.setText("Configure");
    select.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            PrintDialog pd = new PrintDialog(Display.getCurrent().getActiveShell());
            PrinterData pdata = pd.open();
            if (pdata != null) {
                _printerData = pdata;
                select(_printerData);
            }
        }

        private void select(PrinterData printerData) {
            for (int i = 0; i < _pdatas.length; i++) {
                PrinterData pd = _pdatas[i];
                if (pd.name.equals(printerData.name)) {
                    _printerCombo.select(i);
                    break;
                }
            }
        }

        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
}
Also used : CCombo(org.eclipse.swt.custom.CCombo) Composite(org.eclipse.swt.widgets.Composite) Button(org.eclipse.swt.widgets.Button) PrintDialog(org.eclipse.swt.printing.PrintDialog) PrinterData(org.eclipse.swt.printing.PrinterData) RowLayout(org.eclipse.swt.layout.RowLayout) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

SelectionListener (org.eclipse.swt.events.SelectionListener)711 SelectionEvent (org.eclipse.swt.events.SelectionEvent)665 GridData (org.eclipse.swt.layout.GridData)411 Button (org.eclipse.swt.widgets.Button)409 Composite (org.eclipse.swt.widgets.Composite)381 GridLayout (org.eclipse.swt.layout.GridLayout)374 Label (org.eclipse.swt.widgets.Label)256 Text (org.eclipse.swt.widgets.Text)152 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)140 Group (org.eclipse.swt.widgets.Group)137 ModifyListener (org.eclipse.swt.events.ModifyListener)113 ModifyEvent (org.eclipse.swt.events.ModifyEvent)112 Combo (org.eclipse.swt.widgets.Combo)101 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)69 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)69 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)69 FormData (org.eclipse.swt.layout.FormData)69 Event (org.eclipse.swt.widgets.Event)69 FormAttachment (org.eclipse.swt.layout.FormAttachment)68 ArrayList (java.util.ArrayList)57