Search in sources :

Example 11 with KeyAdapter

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

the class MultiDBQueryComposite method initialize.

/**
	 * Create the SQL history composite
	 */
public void initialize() {
    Composite toolBarComposite = new Composite(this, SWT.NONE);
    GridLayout gridLayout = new GridLayout(2, false);
    gridLayout.verticalSpacing = 0;
    gridLayout.horizontalSpacing = 10;
    gridLayout.marginWidth = 0;
    gridLayout.marginHeight = 0;
    toolBarComposite.setLayout(gridLayout);
    toolBarComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    ToolBar toolBar = new ToolBar(toolBarComposite, SWT.FLAT | SWT.RIGHT);
    toolBar.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, true, false));
    ToolItem refreshToolItem = new ToolItem(toolBar, SWT.PUSH);
    refreshToolItem.setText(Messages.lblItemRefreshMulti);
    refreshToolItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/query_refresh.png"));
    refreshToolItem.setDisabledImage(CommonUIPlugin.getImage("icons/queryeditor/query_refresh.png"));
    refreshToolItem.setToolTipText(Messages.refresh);
    refreshToolItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            //refresh may set tree to group type or not
            //so mark the select db then set it to checked after set input
            //				Object[] checkedObject = ctv.getCheckedElements();
            setInput();
        //				for (Object o : checkedObject) {
        //					if (o instanceof CubridDatabase) {
        //						ctv.setChecked(o, true);
        //					}
        //				}
        //				refresh(editor.getSelectedDatabase());
        }
    });
    runItem = new ToolItem(toolBar, SWT.PUSH);
    runItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/query_run.png"));
    runItem.setDisabledImage(CommonUIPlugin.getImage("icons/queryeditor/query_run_disabled.png"));
    runItem.setText(Messages.lblItemRunMulti);
    runItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            editor.runMultiQuery();
        }
    });
    Label lblNotice = new Label(toolBarComposite, SWT.None);
    lblNotice.setText(Messages.qedit_multiDBQueryComp_noticeToolbarMsg);
    lblNotice.setLayoutData(new GridData(SWT.TRAIL, SWT.CENTER, true, false));
    // create the query result tab folder
    multiDBQueryCompTabFolder = new CTabFolder(this, SWT.BOTTOM);
    multiDBQueryCompTabFolder.setSimple(false);
    multiDBQueryCompTabFolder.setUnselectedImageVisible(true);
    multiDBQueryCompTabFolder.setUnselectedCloseVisible(true);
    multiDBQueryCompTabFolder.setSelectionBackground(CombinedQueryEditorComposite.BACK_COLOR);
    multiDBQueryCompTabFolder.setSelectionForeground(ResourceManager.getColor(SWT.COLOR_BLACK));
    multiDBQueryCompTabFolder.setLayout(new GridLayout(1, true));
    multiDBQueryCompTabFolder.setLayoutData(new GridData(GridData.FILL_BOTH));
    //TabContextMenuManager tabContextMenuManager = new TabContextMenuManager(multiDBQueryCompTabFolder);
    //tabContextMenuManager.createContextMenu();
    multiDBQueryCompTabItem = new CTabItem(resultTabFolder, SWT.NONE);
    multiDBQueryCompTabItem.setText(Messages.qedit_multiDBQueryComp_folder);
    multiDBQueryCompTabItem.setControl(this);
    multiDBQueryCompTabItem.setShowClose(false);
    SashForm bottomSash = new SashForm(multiDBQueryCompTabFolder, SWT.VERTICAL);
    bottomSash.SASH_WIDTH = SASH_WIDTH;
    bottomSash.setBackground(CombinedQueryEditorComposite.BACK_COLOR);
    SashForm tailSash = new SashForm(bottomSash, SWT.HORIZONTAL);
    tailSash.SASH_WIDTH = SASH_WIDTH;
    tailSash.setBackground(CombinedQueryEditorComposite.BACK_COLOR);
    Composite treeComp = new Composite(tailSash, SWT.NONE);
    {
        treeComp.setLayoutData(new GridData(GridData.FILL_BOTH));
        treeComp.setLayout(new GridLayout());
    }
    ctv = new ContainerCheckedTreeViewer(treeComp, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
    ctv.getControl().setLayoutData(CommonUITool.createGridData(GridData.FILL_BOTH, 3, 1, -1, 200));
    ctv.setContentProvider(new MultiDBQueryTreeContentProvider());
    ctv.addCheckStateListener(new ICheckStateListener() {

        public void checkStateChanged(CheckStateChangedEvent event) {
            if (lastSelectedTime != 0 && lastSelectedTime > System.currentTimeMillis()) {
                ctv.setChecked(event.getElement(), true);
                return;
            }
            ctv.setChecked(event.getElement(), false);
            lastSelectedTime = System.currentTimeMillis() + 100;
            if (getQueryDatabaseList().size() > 0 && editor.getAllQueries().trim().length() != 0) {
                editor.setMultiQueryRunItemStatus(true);
            } else if (getQueryDatabaseList().size() == 0) {
                editor.setMultiQueryRunItemStatus(false);
            }
            //if (!event.getChecked()) {
            selectedNodes.remove(event.getElement());
            if (event.getElement() instanceof CubridDatabase) {
                CubridDatabase database = (CubridDatabase) event.getElement();
                if (database.getRunningType() == DbRunningType.STANDALONE || !database.isLogined()) {
                    //ctv.setChecked(event.getElement(), false);
                    selectedNodes.remove(database);
                } else {
                    if (database.getData(INDEXKEY) == null) {
                        database.setData(INDEXKEY, String.valueOf(databaseIndex++));
                    }
                }
            } else if (event.getElement() instanceof CubridServer) {
                CubridServer serverNode = (CubridServer) event.getElement();
                for (ICubridNode dbFolderNode : serverNode.getChildren()) {
                    for (ICubridNode dbNode : dbFolderNode.getChildren()) {
                        if (dbNode instanceof CubridDatabase) {
                            CubridDatabase database = (CubridDatabase) dbNode;
                            if (database.getRunningType() == DbRunningType.STANDALONE || !database.isLogined()) {
                                //ctv.setChecked(dbNode, false);
                                selectedNodes.remove(database);
                            } else if (ctv.getChecked(dbNode)) {
                                ctv.setChecked(dbNode, true);
                                if (dbNode.getData(INDEXKEY) == null) {
                                    dbNode.setData(INDEXKEY, String.valueOf(databaseIndex++));
                                }
                            } else {
                                ctv.setChecked(dbNode, true);
                            }
                        }
                    }
                    //only has one db folder  so first time break it
                    break;
                }
            } else if (event.getElement() instanceof ICubridNode) {
                ICubridNode node = (ICubridNode) event.getElement();
                if (node.getType().equals(NodeType.DATABASE_FOLDER)) {
                    for (ICubridNode dbNode : node.getChildren()) {
                        if (dbNode instanceof CubridDatabase) {
                            CubridDatabase database = (CubridDatabase) dbNode;
                            if (database.getRunningType() == DbRunningType.STANDALONE || !database.isLogined()) {
                                ctv.setChecked(dbNode, false);
                            } else if (ctv.getChecked(dbNode)) {
                                ctv.setChecked(dbNode, true);
                                if (dbNode.getData(INDEXKEY) == null) {
                                    dbNode.setData(INDEXKEY, String.valueOf(databaseIndex++));
                                }
                            } else {
                                ctv.setChecked(dbNode, false);
                            }
                        }
                    }
                }
            //					else if (node.getType().equals(NodeType.GROUP)) {
            //						for (ICubridNode childNode : node.getChildren()) {
            //							//CQB tree
            //							if(childNode instanceof CubridDatabase) {
            //								CubridDatabase database = (CubridDatabase) childNode;
            //								if (database.getRunningType() == DbRunningType.STANDALONE
            //										|| !database.isLogined()) {
            //									if (childNode.getData(INDEXKEY) == null) {
            //										childNode.setData(INDEXKEY, String.valueOf(databaseIndex++));
            //									}
            //								}
            //								continue;
            //							}
            //							//CM tree
            //							for (ICubridNode dbFolderNode : childNode.getChildren()) {
            //								for (ICubridNode dbNode : dbFolderNode.getChildren()) {
            //									if(dbNode instanceof CubridDatabase) {
            //										CubridDatabase database = (CubridDatabase) dbNode;
            //										if (database.getRunningType() == DbRunningType.STANDALONE
            //												|| !database.isLogined()) {
            //											ctv.setChecked(dbNode, false);
            //										} else if (ctv.getChecked(dbNode)) {
            //											ctv.setChecked(dbNode, true);
            //											if (dbNode.getData(INDEXKEY) == null) {
            //												dbNode.setData(INDEXKEY, String.valueOf(databaseIndex++));
            //											}
            //										} else {
            //											ctv.setChecked(dbNode, false);
            //										}
            //									}
            //								}
            //							}
            //							//only has one db folder  so first time break it
            //							break;
            //						}
            //					}
            }
            ctv.refresh();
        }
    });
    ctv.getTree().addKeyListener(new KeyAdapter() {

        public void keyReleased(KeyEvent event) {
            //mac can't drag and drop,so support copy and paste db node
            if (((event.stateMask & SWT.CTRL) != 0) || ((event.stateMask & SWT.COMMAND) != 0) && event.keyCode == 'v') {
                final Clipboard cb = new Clipboard(getShell().getDisplay());
                String plainText = (String) cb.getContents(TextTransfer.getInstance());
                String[] databaseNameArray = plainText.split(",");
                selectedNodes.addAll(getDatabaseNode(databaseNameArray));
                setInput();
            }
        }
    });
    //		ctv.addDoubleClickListener(LayoutManager.getInstance());
    //		ctv.addTreeListener(new ITreeViewerListener() {
    //			public void treeCollapsed(TreeExpansionEvent event) {
    //				CommonTool.clearExpandedElements(ctv);
    //			}
    //
    //			public void treeExpanded(TreeExpansionEvent event) {
    //				CommonTool.clearExpandedElements(ctv);
    //			}
    //		});
    final Tree tableTree = ctv.getTree();
    tableTree.setHeaderVisible(true);
    tableTree.setLinesVisible(true);
    final TreeViewerColumn dbCol = new TreeViewerColumn(ctv, SWT.NONE);
    dbCol.setLabelProvider(new MultiDBQueryTreeColumnLabelProvider());
    dbCol.getColumn().setWidth(250);
    dbCol.getColumn().setText(Messages.qedit_multiDBQueryComp_tree_dbCol);
    final TreeViewerColumn indexCol = new TreeViewerColumn(ctv, SWT.NONE);
    indexCol.setLabelProvider(new MultiDBQueryTreeColumnLabelProvider());
    indexCol.getColumn().setWidth(50);
    indexCol.getColumn().setText(Messages.qedit_multiDBQueryComp_tree_indexCol);
    indexCol.setEditingSupport(new EditingSupport(ctv) {

        TextCellEditor textCellEditor;

        protected boolean canEdit(Object element) {
            if (element instanceof ICubridNode) {
                ICubridNode node = (ICubridNode) element;
                if (node.getType() == NodeType.DATABASE) {
                    CubridDatabase database = (CubridDatabase) element;
                    if ((database.getRunningType() == DbRunningType.CS && database.isLogined())) {
                        return true;
                    }
                }
            }
            return false;
        }

        protected CellEditor getCellEditor(Object element) {
            if (textCellEditor == null) {
                textCellEditor = new TextCellEditor(ctv.getTree());
                textCellEditor.setValidator(new IndexCellEditorValidator());
                textCellEditor.addListener(new ICellEditorListener() {

                    public void applyEditorValue() {
                    }

                    public void cancelEditor() {
                    }

                    public void editorValueChanged(boolean oldValidState, boolean newValidState) {
                    }
                });
            }
            return textCellEditor;
        }

        protected Object getValue(Object element) {
            final ICubridNode node = (ICubridNode) element;
            String index = (String) node.getData(INDEXKEY);
            if (index == null) {
                return "";
            } else {
                return index;
            }
        }

        protected void setValue(Object element, Object value) {
            if (value == null) {
                return;
            }
            try {
                Integer.valueOf((String) value);
            } catch (Exception e) {
                return;
            }
            final ICubridNode node = (ICubridNode) element;
            node.setData(INDEXKEY, value);
            //				setAllParentExpandOrCollapse(node.getParent(), true);
            ctv.refresh();
        }

        /**
			 * MyCellEditorValidator
			 *
			 * @author fulei
			 *
			 */
        class IndexCellEditorValidator implements ICellEditorValidator {

            /**
				 * isValid
				 *
				 * @param value Object
				 * @return String
				 */
            public String isValid(Object value) {
                try {
                    Integer.valueOf((String) value);
                } catch (Exception e) {
                    CommonUITool.openErrorBox(Messages.qedit_multiDBQueryComp_tree_indexErr);
                    return Messages.qedit_multiDBQueryComp_tree_indexErr;
                }
                return null;
            }
        }
    });
    final TreeViewerColumn commentCol = new TreeViewerColumn(ctv, SWT.NONE);
    commentCol.setLabelProvider(new MultiDBQueryTreeColumnLabelProvider());
    commentCol.getColumn().setWidth(200);
    commentCol.getColumn().setText(Messages.qedit_multiDBQueryComp_tree_commentCol);
    CTabItem tabItem = new CTabItem(multiDBQueryCompTabFolder, SWT.NONE);
    tabItem.setText(Messages.qedit_multiDBQueryComp_tabItem);
    tabItem.setControl(bottomSash);
    tabItem.setShowClose(false);
    setInput();
    //		HostNodePersistManager.getInstance().getAllServer();
    multiDBQueryCompTabFolder.setSelection(tabItem);
    dragController = new MultiDBQueryDNDController(this, ctv);
    dragController.registerDropTarget();
}
Also used : CTabFolder(org.eclipse.swt.custom.CTabFolder) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) CellEditor(org.eclipse.jface.viewers.CellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) KeyAdapter(org.eclipse.swt.events.KeyAdapter) Label(org.eclipse.swt.widgets.Label) EditingSupport(org.eclipse.jface.viewers.EditingSupport) CTabItem(org.eclipse.swt.custom.CTabItem) KeyEvent(org.eclipse.swt.events.KeyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) ICellEditorListener(org.eclipse.jface.viewers.ICellEditorListener) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Tree(org.eclipse.swt.widgets.Tree) ToolItem(org.eclipse.swt.widgets.ToolItem) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridServer(com.cubrid.common.ui.spi.model.CubridServer) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) SashForm(org.eclipse.swt.custom.SashForm) ICellEditorValidator(org.eclipse.jface.viewers.ICellEditorValidator) GridData(org.eclipse.swt.layout.GridData) ToolBar(org.eclipse.swt.widgets.ToolBar) ContainerCheckedTreeViewer(org.eclipse.ui.dialogs.ContainerCheckedTreeViewer) Clipboard(org.eclipse.swt.dnd.Clipboard) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 12 with KeyAdapter

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

the class FilterResultContrItem method createControl.

/**
	 * Create the content
	 *
	 * @param parent Composite
	 * @return Control
	 */
protected Control createControl(Composite parent) {
    Composite comp = new Composite(parent, SWT.NONE);
    GridData gridData = new GridData(GridData.FILL, GridData.FILL, true, true);
    comp.setLayoutData(gridData);
    final GridLayout gdLayout = new GridLayout(5, false);
    gdLayout.marginHeight = 0;
    gdLayout.marginWidth = 0;
    gdLayout.horizontalSpacing = 0;
    gdLayout.verticalSpacing = 0;
    gdLayout.marginRight = 10;
    comp.setLayout(gdLayout);
    Label lbl = new Label(comp, SWT.NONE);
    lbl.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    lbl.setText(" " + Messages.lblFilterSearch + " ");
    text = new Text(comp, SWT.NONE | SWT.BORDER | SWT.LEFT);
    text.setLayoutData(CommonUITool.createGridData(1, 1, 100, -1));
    text.addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent e) {
            if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) {
                doFilter();
            }
        }
    });
    dropDownButton = new Button(comp, SWT.FLAT | SWT.DOWN);
    dropDownButton.setText(Messages.lblFilterSearchOption);
    dropDownButton.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event event) {
            handleSelectionEvent();
        }
    });
    Label lblLimit = new Label(comp, SWT.NONE);
    lblLimit.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    lblLimit.setText(" " + Messages.lblSearchLimit + " ");
    pageLimitCombo = new Combo(comp, SWT.READ_ONLY);
    pageLimitCombo.setItems(new String[] { "1000", "5000", "10000" });
    pageLimitCombo.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    pageLimitCombo.setText("" + pageLimit);
    pageLimitCombo.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            int limit = StringUtil.intValue(pageLimitCombo.getText());
            ServerInfo serverInfo = qe.getDatabase().getServer().getServerInfo();
            QueryOptions.setSearchUnitCount(serverInfo, limit);
        }
    });
    loadMenuItems();
    return comp;
}
Also used : Listener(org.eclipse.swt.widgets.Listener) ModifyListener(org.eclipse.swt.events.ModifyListener) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) KeyAdapter(org.eclipse.swt.events.KeyAdapter) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) Combo(org.eclipse.swt.widgets.Combo) KeyEvent(org.eclipse.swt.events.KeyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) Event(org.eclipse.swt.widgets.Event) KeyEvent(org.eclipse.swt.events.KeyEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Example 13 with KeyAdapter

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

the class SqlmapNavigatorView method createCondView.

/**
	 * Create the main view.
	 *
	 * @param parent {@link Composite} the parent composite
	 */
private void createCondView(Composite parent) {
    String[] columnNames = { Messages.lblSqlmapUse, Messages.lblSqlmapCondition };
    Label lblCondTitle = new Label(parent, SWT.NONE);
    lblCondTitle.setText(Messages.lblSqlmapConditions);
    condView = CommonUITool.createCommonTableViewer(parent, null, columnNames, CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 1, 1, -1, 80));
    condView.setColumnProperties(columnNames);
    condView.setContentProvider(new TableContentProvider());
    condView.setLabelProvider(new SqlmapLabelProvider(this));
    condView.setCellModifier(new SqlmapCellModifier(this));
    CellEditor[] cellEditor = new CellEditor[columnNames.length];
    cellEditor[0] = new CheckboxCellEditor(condView.getTable());
    condView.setCellEditors(cellEditor);
    TableLayout tableLayout = new TableLayout();
    tableLayout.addColumnData(new ColumnPixelData(30));
    tableLayout.addColumnData(new ColumnPixelData(160));
    condView.getTable().setLayout(tableLayout);
    condView.getTable().addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent e) {
            if (e.character == ' ') {
                toggleUsedBySelectedCondition();
            }
            super.keyPressed(e);
        }
    });
}
Also used : CheckboxCellEditor(org.eclipse.jface.viewers.CheckboxCellEditor) CellEditor(org.eclipse.jface.viewers.CellEditor) CheckboxCellEditor(org.eclipse.jface.viewers.CheckboxCellEditor) KeyAdapter(org.eclipse.swt.events.KeyAdapter) Label(org.eclipse.swt.widgets.Label) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) KeyEvent(org.eclipse.swt.events.KeyEvent) TableContentProvider(com.cubrid.common.ui.spi.TableContentProvider) TableLayout(org.eclipse.jface.viewers.TableLayout)

Example 14 with KeyAdapter

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

the class DataCompareEditorPart method createContent.

private void createContent(Composite parent) {
    compareTableViewer = new TableViewer(parent, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
    compareTableViewer.setUseHashlookup(true);
    compareTableViewer.setColumnProperties(columnNames);
    CommonUITool.createGridLayout(compareTableViewer.getTable(), 1, 0, 10, 0, 10, 0, 0, 0, 0);
    compareTableViewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    compareTableViewer.getTable().setLinesVisible(true);
    compareTableViewer.getTable().setHeaderVisible(true);
    sorter = new DataCompareSchemaListViewSorter();
    sorter.setSortType(DataCompareSchemaListViewSorter.SORT_TABLE);
    compareTableViewer.setSorter(sorter);
    makeContextMenu(compareTableViewer);
    final TableViewerColumn firstCol = new TableViewerColumn(compareTableViewer, SWT.NONE);
    firstCol.getColumn().setWidth(30);
    firstCol.getColumn().setResizable(false);
    firstCol.getColumn().setAlignment(SWT.CENTER);
    firstCol.getColumn().setImage(CommonUIPlugin.getImage("icons/unchecked.gif"));
    firstCol.getColumn().addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            TableItem[] items = compareTableViewer.getTable().getItems();
            if (items == null) {
                return;
            }
            for (TableItem item : items) {
                DataCompare dataCompare = (DataCompare) item.getData();
                dataCompare.setUse(isSelectAll);
            }
            compareTableViewer.refresh();
            Image image = null;
            if (isSelectAll) {
                image = CommonUIPlugin.getImage("icons/checked.gif");
            } else {
                image = CommonUIPlugin.getImage("icons/unchecked.gif");
            }
            firstCol.getColumn().setImage(image);
            isSelectAll = !isSelectAll;
        }
    });
    TableViewerColumn col = new TableViewerColumn(compareTableViewer, SWT.NONE);
    col.getColumn().setWidth(200);
    col.getColumn().setText(Messages.lblDataCompareTable);
    makeSortTableColumn(col, DataCompareSchemaListViewSorter.SORT_TABLE);
    col = new TableViewerColumn(compareTableViewer, SWT.LEFT);
    col.getColumn().setWidth(100);
    col.getColumn().setText(Messages.lblDataCompareRecordSource);
    makeSortTableColumn(col, DataCompareSchemaListViewSorter.SORT_SOURCE_RECORDS);
    col = new TableViewerColumn(compareTableViewer, SWT.LEFT);
    col.getColumn().setWidth(100);
    col.getColumn().setText(Messages.lblDataCompareRecordTarget);
    makeSortTableColumn(col, DataCompareSchemaListViewSorter.SORT_TARGET_RECORDS);
    col = new TableViewerColumn(compareTableViewer, SWT.LEFT);
    col.getColumn().setWidth(100);
    col.getColumn().setText(Messages.lblDataCompareRecordProgress);
    makeSortTableColumn(col, DataCompareSchemaListViewSorter.SORT_PROGRESS);
    col = new TableViewerColumn(compareTableViewer, SWT.LEFT);
    col.getColumn().setWidth(100);
    col.getColumn().setText(Messages.lblDataCompareRecordMatch);
    makeSortTableColumn(col, DataCompareSchemaListViewSorter.SORT_MATCHES);
    col = new TableViewerColumn(compareTableViewer, SWT.LEFT);
    col.getColumn().setWidth(100);
    col.getColumn().setText(Messages.lblDataCompareRecordNoMatch);
    makeSortTableColumn(col, DataCompareSchemaListViewSorter.SORT_NOT_MATCHES);
    col = new TableViewerColumn(compareTableViewer, SWT.LEFT);
    col.getColumn().setWidth(100);
    col.getColumn().setText(Messages.lblDataCompareRecordNotExist);
    makeSortTableColumn(col, DataCompareSchemaListViewSorter.SORT_NOT_EXISTS);
    col = new TableViewerColumn(compareTableViewer, SWT.LEFT);
    col.getColumn().setWidth(300);
    col.getColumn().setText(Messages.lblDataCompareRecordError);
    makeSortTableColumn(col, DataCompareSchemaListViewSorter.SORT_ERROR);
    CellEditor[] cellEditor = new CellEditor[1];
    cellEditor[0] = new CheckboxCellEditor(compareTableViewer.getTable());
    compareTableViewer.setCellEditors(cellEditor);
    compareTableViewer.setCellModifier(new DataCompareCellModifier(this));
    compareTableViewer.setContentProvider(new DataCompareSchemaListContentProvider());
    compareTableViewer.setLabelProvider(new DataCompareSchemaListLabelProvider());
    compareList = new ArrayList<DataCompare>();
    compareTableViewer.setInput(compareList);
    txtProgress = new StyledText(parent, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL);
    txtProgress.setEditable(false);
    txtProgress.setWordWrap(true);
    txtProgress.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 1, 1, -1, 100));
    txtProgress.setBackground(txtProgress.getDisplay().getSystemColor(SWT.COLOR_BLACK));
    txtProgress.setForeground(txtProgress.getDisplay().getSystemColor(SWT.COLOR_GREEN));
    compareTableViewer.getTable().setToolTipText(Messages.msgYouCanSeeDetailDblclick);
    compareTableViewer.getTable().addKeyListener(new KeyAdapter() {

        public void keyReleased(KeyEvent e) {
            if (e.character == ' ') {
                TableItem[] items = compareTableViewer.getTable().getSelection();
                if (items == null) {
                    return;
                }
                for (TableItem item : items) {
                    DataCompare dataCompare = (DataCompare) item.getData();
                    dataCompare.setUse(!dataCompare.isUse());
                }
                compareTableViewer.refresh();
            }
        }
    });
    compareTableViewer.addDoubleClickListener(new IDoubleClickListener() {

        public void doubleClick(DoubleClickEvent event) {
            if (!refreshedRecordCounts) {
                CommonUITool.openWarningBox(Messages.msgClickRefreshToEsimateDiff);
                return;
            }
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            DataCompare model = (DataCompare) selection.getFirstElement();
            if (!model.isSameSchema()) {
                CommonUITool.openWarningBox(Messages.msgTheSchemaDiff);
                return;
            }
            if (model.getRecordsTarget() == -1) {
                CommonUITool.openWarningBox(Messages.msgTargetNotFound);
                return;
            }
            if (model.getRecordsSource() == 0 && model.getRecordsTarget() > 0) {
                CommonUITool.openWarningBox(Messages.msgTargetNoData);
                return;
            }
            if (model.getRecordsSource() == 0) {
                CommonUITool.openWarningBox(Messages.msgNoDataToCompare);
                return;
            }
            if (model.getProgressPosition() == 0) {
                CommonUITool.openWarningBox(Messages.msgNotYetCompared);
                return;
            }
            if (model.getNotMatches() == 0 && model.getNotExists() == 0) {
                CommonUITool.openWarningBox(Messages.msgSameData);
                return;
            }
            showDataCompareDetailEditor(model.getSchemaInfo());
        }
    });
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) CheckboxCellEditor(org.eclipse.jface.viewers.CheckboxCellEditor) CellEditor(org.eclipse.jface.viewers.CellEditor) CheckboxCellEditor(org.eclipse.jface.viewers.CheckboxCellEditor) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) TableItem(org.eclipse.swt.widgets.TableItem) KeyAdapter(org.eclipse.swt.events.KeyAdapter) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Image(org.eclipse.swt.graphics.Image) KeyEvent(org.eclipse.swt.events.KeyEvent) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DataCompare(com.cubrid.common.ui.compare.data.model.DataCompare) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 15 with KeyAdapter

use of org.eclipse.swt.events.KeyAdapter in project MonjaDB by Kanatoko.

the class MActionView method init2.

//--------------------------------------------------------------------------------
public void init2() {
    parent.setLayout(new FormLayout());
    sashForm = new SashForm(parent, SWT.SMOOTH | SWT.VERTICAL);
    FormData fd_sashForm1 = new FormData();
    fd_sashForm1.top = new FormAttachment(0, 1);
    fd_sashForm1.left = new FormAttachment(0, 1);
    fd_sashForm1.right = new FormAttachment(100, -1);
    fd_sashForm1.bottom = new FormAttachment(100, -1);
    sashForm.setLayoutData(fd_sashForm1);
    table = new Table(sashForm, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
    table.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            onTableStateChange();
        }
    });
    table.addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent e) {
            if (e.keyCode == 13) {
                e.doit = false;
                if (//Shift + Enter
                (e.stateMask & SWT.SHIFT) != 0) {
                    repeatActionsOnTable();
                } else {
                    editActions();
                }
            }
        }
    });
    FormData fd_table = new FormData();
    fd_table.top = new FormAttachment(0, 0);
    fd_table.bottom = new FormAttachment(100, 0);
    fd_table.left = new FormAttachment(0, 0);
    fd_table.right = new FormAttachment(100, 0);
    table.setLayoutData(fd_table);
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    TableColumn actionColumn = new TableColumn(table, SWT.NONE);
    actionColumn.setWidth(100);
    actionColumn.setText("Action");
    TableColumn dateColumn = new TableColumn(table, SWT.NONE);
    dateColumn.setWidth(100);
    dateColumn.setText("Date");
    editorComposite = new Composite(sashForm, SWT.BORDER);
    editorComposite.setLayout(new FormLayout());
    text = new Text(editorComposite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.CANCEL | SWT.MULTI);
    text.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            onTextStateChange();
        }
    });
    FormData fd_text = new FormData();
    fd_text.bottom = new FormAttachment(100, -40);
    fd_text.right = new FormAttachment(100);
    fd_text.top = new FormAttachment(0);
    fd_text.left = new FormAttachment(0);
    text.setLayoutData(fd_text);
    executeButton = new Button(editorComposite, SWT.NONE);
    executeButton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            executeActionsOnText();
        }
    });
    executeButton.setEnabled(false);
    FormData fd_executeButton = new FormData();
    fd_executeButton.top = new FormAttachment(text, 6);
    fd_executeButton.left = new FormAttachment(text, -120, SWT.RIGHT);
    fd_executeButton.right = new FormAttachment(100, -10);
    executeButton.setLayoutData(fd_executeButton);
    executeButton.setText("Execute");
    editorComposite.addControlListener(new ControlAdapter() {

        public void controlResized(ControlEvent e) {
            onSashResize();
        }
    });
    MSwtUtil.getTableColumnWidthFromProperties("actionListTable", table, prop, new int[] { 200, 100 });
    MSwtUtil.addListenerToTableColumns2(table, this);
    //table.addListener( SWT.KeyDown, this );
    table.addListener(SWT.MouseDoubleClick, this);
    menuManager = new MenuManager();
    Menu contextMenu = menuManager.createContextMenu(table);
    table.setMenu(contextMenu);
    //executeTableAction
    {
        redoAction = new Action() {

            public void run() {
                //------------
                repeatActionsOnTable();
            }
        };
        //------------
        redoAction.setToolTipText("Redo Selected Actions");
        redoAction.setText("Redo\tShift+Enter");
        initAction(redoAction, "table_go.png", menuManager);
        redoAction.setEnabled(false);
    }
    //editAction
    {
        editAction = new Action() {

            public void run() {
                //------------
                editActions();
            }
        };
        //------------
        editAction.setToolTipText("Edit Actions on The Text Editor");
        editAction.setText("Edit\tEnter");
        initAction(editAction, "pencil.png", menuManager);
        editAction.setEnabled(false);
    }
    dropDownMenu.add(new Separator());
    menuManager.add(new Separator());
    //executeAction
    {
        executeAction = new Action() {

            public void run() {
                //------------
                executeActionsOnText();
            }
        };
        //------------
        executeAction.setToolTipText("Execute Actions on the Textarea");
        executeAction.setText("Execute");
        setActionImage(executeAction, "bullet_go.png");
        addActionToToolBar(executeAction);
        executeAction.setEnabled(false);
        dropDownMenu.add(executeAction);
    }
    dropDownMenu.add(new Separator());
    menuManager.add(new Separator());
    //copyAction
    {
        copyAction = new Action() {

            public void run() {
                //------------
                copyActions();
            }
        };
        //------------
        copyAction.setToolTipText("Copy Actions to Clipboard");
        copyAction.setText("Copy");
        setActionImage(copyAction, "page_copy.png");
        addActionToToolBar(copyAction);
        copyAction.setEnabled(false);
        dropDownMenu.add(copyAction);
        menuManager.add(copyAction);
    }
    dropDownMenu.add(new Separator());
    menuManager.add(new Separator());
    //clearAction
    {
        clearAction = new Action() {

            public void run() {
                //------------
                clearActions();
            }
        };
        //------------
        clearAction.setToolTipText("Clear All");
        clearAction.setText("Clear All");
        initAction(clearAction, "table_delete.png", menuManager);
        clearAction.setEnabled(false);
    }
    //saveAction
    {
        saveAction = new Action() {

            public void run() {
                //------------
                saveActions();
            }
        };
        //------------
        saveAction.setToolTipText("Save Action");
        saveAction.setText("Save");
        initAction(saveAction, "cog_add.png", menuManager);
        saveAction.setEnabled(false);
    }
    //load actionLogList
    if (prop.containsKey(ACTION_LOG_LIST)) {
        String savedStr = prop.getProperty(ACTION_LOG_LIST);
        actionLogList = (java.util.List) JSON.parse(savedStr);
        for (int i = 0; i < actionLogList.size(); ++i) {
            Map actionLog = (Map) actionLogList.get(i);
            addActionToTable(actionLog);
        }
    } else {
        actionLogList = new LinkedList();
    }
    if (prop.containsKey(ACTIONLOG_COMPOSITE_WEIGHT)) {
        (new Thread() {

            public void run() {
                MSystemUtil.sleep(0);
                shell.getDisplay().asyncExec(new Runnable() {

                    public void run() {
                        //----
                        sashForm.setWeights(prop.getIntArrayProperty(ACTIONLOG_COMPOSITE_WEIGHT));
                    }
                });
            //----
            }
        }).start();
    } else {
        sashForm.setWeights(new int[] { 70, 30 });
    }
    initializedTime = System.currentTimeMillis();
}
Also used : MEditAction(net.jumperz.app.MMonjaDBCore.action.mj.MEditAction) Action(org.eclipse.jface.action.Action) ModifyListener(org.eclipse.swt.events.ModifyListener) ControlAdapter(org.eclipse.swt.events.ControlAdapter) KeyAdapter(org.eclipse.swt.events.KeyAdapter) KeyEvent(org.eclipse.swt.events.KeyEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Menu(org.eclipse.swt.widgets.Menu) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) TableColumn(org.eclipse.swt.widgets.TableColumn) SashForm(org.eclipse.swt.custom.SashForm) java.util(java.util) MenuManager(org.eclipse.jface.action.MenuManager) ControlEvent(org.eclipse.swt.events.ControlEvent) Separator(org.eclipse.jface.action.Separator)

Aggregations

KeyAdapter (org.eclipse.swt.events.KeyAdapter)80 KeyEvent (org.eclipse.swt.events.KeyEvent)80 GridData (org.eclipse.swt.layout.GridData)50 GridLayout (org.eclipse.swt.layout.GridLayout)40 Composite (org.eclipse.swt.widgets.Composite)39 SelectionEvent (org.eclipse.swt.events.SelectionEvent)33 Text (org.eclipse.swt.widgets.Text)30 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)28 Label (org.eclipse.swt.widgets.Label)24 Button (org.eclipse.swt.widgets.Button)20 TableViewer (org.eclipse.jface.viewers.TableViewer)18 ModifyEvent (org.eclipse.swt.events.ModifyEvent)17 ModifyListener (org.eclipse.swt.events.ModifyListener)16 FocusEvent (org.eclipse.swt.events.FocusEvent)15 Point (org.eclipse.swt.graphics.Point)15 Table (org.eclipse.swt.widgets.Table)14 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)12 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)12 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)12 FocusAdapter (org.eclipse.swt.events.FocusAdapter)11