Search in sources :

Example 6 with ICellEditorListener

use of org.eclipse.jface.viewers.ICellEditorListener in project webtools.sourceediting by eclipse.

the class ComboBoxCellEditorManager method initCellEditor.

protected void initCellEditor() {
    String initialLabelText = label.getText();
    CCombo combo = (CCombo) getCellEditor().getControl();
    combo.setFont(label.getFont());
    combo.setForeground(label.getForegroundColor());
    combo.setBackground(label.getBackgroundColor());
    combo.setVisibleItemCount(20);
    /*
     * combo.addKeyListener(new KeyAdapter() { // hook key pressed - see PR
     * 14201 public void keyPressed(KeyEvent keyEvent) { if (keyEvent.character ==
     * 'z') { getCellEditor().applyEditorValue(); } } });
     */
    ICellEditorListener cellEditorListener = new ICellEditorListener() {

        public void cancelEditor() {
        }

        public void applyEditorValue() {
        }

        public void editorValueChanged(boolean old, boolean newState) {
        }
    };
    getCellEditor().addListener(cellEditorListener);
    String[] item = combo.getItems();
    for (int i = 0; i < item.length; i++) {
        if (item[i].equals(initialLabelText)) {
            getCellEditor().setValue(new Integer(i));
            break;
        }
    }
}
Also used : CCombo(org.eclipse.swt.custom.CCombo) ICellEditorListener(org.eclipse.jface.viewers.ICellEditorListener)

Example 7 with ICellEditorListener

use of org.eclipse.jface.viewers.ICellEditorListener in project archi by archimatetool.

the class DirectEditManager method hookListeners.

protected void hookListeners() {
    ancestorListener = new AncestorListener.Stub() {

        @Override
        public void ancestorMoved(IFigure ancestor) {
            placeCellEditor();
        }
    };
    getEditPart().getFigure().addAncestorListener(ancestorListener);
    Control control = getControl();
    controlListener = new ControlAdapter() {

        @Override
        public void controlMoved(ControlEvent e) {
            // This must be handled async because during scrolling, the
            // CellEditor moves
            // first, but then afterwards the viewport Scrolls, which would
            // cause the
            // shadow to move twice
            Display.getCurrent().asyncExec(new Runnable() {

                @Override
                public void run() {
                    placeCellEditorFrame();
                }
            });
        }

        @Override
        public void controlResized(ControlEvent e) {
            placeCellEditorFrame();
        }
    };
    control.addControlListener(controlListener);
    cellEditorListener = new ICellEditorListener() {

        @Override
        public void applyEditorValue() {
            commit();
        }

        @Override
        public void cancelEditor() {
            bringDown();
        }

        @Override
        public void editorValueChanged(boolean old, boolean newState) {
            handleValueChanged();
        }
    };
    getCellEditor().addListener(cellEditorListener);
    editPartListener = new EditPartListener.Stub() {

        @Override
        public void partDeactivated(EditPart editpart) {
            bringDown();
        }
    };
    getEditPart().addEditPartListener(editPartListener);
}
Also used : ControlAdapter(org.eclipse.swt.events.ControlAdapter) EditPartListener(org.eclipse.gef.EditPartListener) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) EditPart(org.eclipse.gef.EditPart) Control(org.eclipse.swt.widgets.Control) ICellEditorListener(org.eclipse.jface.viewers.ICellEditorListener) AncestorListener(org.eclipse.draw2d.AncestorListener) ControlEvent(org.eclipse.swt.events.ControlEvent) IFigure(org.eclipse.draw2d.IFigure)

Example 8 with ICellEditorListener

use of org.eclipse.jface.viewers.ICellEditorListener in project cubrid-manager by CUBRID.

the class ExportSettingPage method createControl.

@Override
public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NONE);
    container.setLayout(new FormLayout());
    setControl(container);
    Composite leftComposite = new Composite(container, SWT.NONE);
    leftComposite.setLayout(new GridLayout());
    FormData leftData = new FormData();
    leftData.top = new FormAttachment(0, 5);
    leftData.bottom = new FormAttachment(100, 0);
    leftData.left = new FormAttachment(0, 5);
    leftData.right = new FormAttachment(45, 0);
    leftComposite.setLayoutData(leftData);
    Composite rightComposite = new Composite(container, SWT.NONE);
    FormData rightData = new FormData();
    rightData.top = new FormAttachment(0, 5);
    rightData.bottom = new FormAttachment(100, 0);
    rightData.left = new FormAttachment(45, 0);
    rightData.right = new FormAttachment(100, -5);
    rightComposite.setLayoutData(rightData);
    GridLayout rightCompositeLayout = new GridLayout();
    rightCompositeLayout.verticalSpacing = 10;
    rightComposite.setLayout(rightCompositeLayout);
    Label tableInfoLabel = new Label(leftComposite, SWT.None);
    tableInfoLabel.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    tableInfoLabel.setText(Messages.exportWizardSourceTableLable);
    treeViewer = new CheckboxTreeViewer(leftComposite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
    treeViewer.getTree().setLayoutData(CommonUITool.createGridData(GridData.FILL_BOTH, 1, 1, -1, -1));
    treeViewer.setContentProvider(new FilterTreeContentProvider());
    treeViewer.getTree().setLinesVisible(true);
    treeViewer.getTree().setHeaderVisible(true);
    treeViewer.addCheckStateListener(new ICheckStateListener() {

        public void checkStateChanged(CheckStateChangedEvent event) {
            updateDialogStatus(null);
        }
    });
    final TreeViewerColumn dbObjectCol = new TreeViewerColumn(treeViewer, SWT.NONE);
    dbObjectCol.setLabelProvider(new ExportObjectLabelProvider());
    final TreeViewerColumn whereCnd = new TreeViewerColumn(treeViewer, SWT.NONE);
    whereCnd.setLabelProvider(new ExportObjectLabelProvider());
    whereCnd.setEditingSupport(new EditingSupport(treeViewer) {

        TextCellEditor textCellEditor;

        protected boolean canEdit(Object element) {
            if (element instanceof ICubridNode) {
                ICubridNode node = (ICubridNode) element;
                if (node.getType() == NodeType.TABLE_COLUMN_FOLDER) {
                    return true;
                }
            }
            return false;
        }

        protected CellEditor getCellEditor(Object element) {
            if (textCellEditor == null) {
                textCellEditor = new TextCellEditor(treeViewer.getTree());
                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 condition = (String) node.getData(ExportObjectLabelProvider.CONDITION);
            if (condition == null) {
                return "";
            } else {
                return condition;
            }
        }

        protected void setValue(Object element, Object value) {
            final ICubridNode node = (ICubridNode) element;
            node.setData(ExportObjectLabelProvider.CONDITION, value);
            treeViewer.refresh();
            updateDialogStatus(null);
        }
    });
    dbObjectCol.getColumn().setWidth(160);
    dbObjectCol.getColumn().setText(Messages.tableLabel);
    whereCnd.getColumn().setWidth(120);
    whereCnd.getColumn().setText(Messages.conditionLabel);
    final Button selectAllBtn = new Button(leftComposite, SWT.CHECK);
    {
        selectAllBtn.setText(Messages.btnSelectAll);
        GridData gridData = new GridData();
        gridData.grabExcessHorizontalSpace = true;
        gridData.horizontalIndent = 0;
        gridData.horizontalSpan = 3;
        selectAllBtn.setLayoutData(gridData);
    }
    selectAllBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            boolean selection = selectAllBtn.getSelection();
            for (ICubridNode node : tablesOrViewLst) {
                treeViewer.setGrayed(node, false);
                treeViewer.setChecked(node, selection);
            }
            updateDialogStatus(null);
        }
    });
    /* Export content option */
    Group exportOptionGroup = new Group(rightComposite, SWT.None);
    exportOptionGroup.setText(Messages.exportWizardWhatExport);
    exportOptionGroup.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 1, 1, -1, -1));
    RowLayout layout = new RowLayout();
    layout.spacing = 8;
    layout.marginWidth = 5;
    exportOptionGroup.setLayout(layout);
    schemaButton = new Button(exportOptionGroup, SWT.CHECK);
    schemaButton.setText(Messages.lblExportTargetSchema);
    schemaButton.addSelectionListener(new SelectionListener() {

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

        public void widgetDefaultSelected(SelectionEvent e) {
            boolean selection = schemaButton.getSelection();
            indexButton.setEnabled(selection);
            serialButton.setEnabled(selection);
            viewButton.setEnabled(selection);
            startValueButton.setEnabled(selection);
            updateDialogStatus(null);
        }
    });
    dataButton = new Button(exportOptionGroup, SWT.CHECK);
    dataButton.setText(Messages.lblExportTargetData);
    dataButton.addSelectionListener(new SelectionListener() {

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

        public void widgetDefaultSelected(SelectionEvent e) {
            updateDialogStatus(null);
            updateExportLobButtonStatus();
        }
    });
    indexButton = new Button(exportOptionGroup, SWT.CHECK);
    indexButton.setText(Messages.lblExportTargetIndex);
    serialButton = new Button(exportOptionGroup, SWT.CHECK);
    serialButton.setText(Messages.lblExportTargetSerial);
    viewButton = new Button(exportOptionGroup, SWT.CHECK);
    viewButton.setText(Messages.lblExportTargetView);
    exportLobButton = new Button(exportOptionGroup, SWT.CHECK);
    exportLobButton.setText(Messages.lblExportLobData);
    exportLobButton.setToolTipText(Messages.lblExportLobData);
    exportLobButton.setEnabled(false);
    startValueButton = new Button(exportOptionGroup, SWT.CHECK);
    startValueButton.setText(Messages.lblExportTargetStartValue);
    startValueButton.setToolTipText(Messages.tipExportTargetStartValue);
    /* Type group */
    Group typeOptionGroup = new Group(rightComposite, SWT.None);
    typeOptionGroup.setText(Messages.exportWizardWhereExport);
    typeOptionGroup.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 1, 1, -1, -1));
    typeOptionGroup.setLayout(new GridLayout(2, false));
    Label typeLabel = new Label(typeOptionGroup, SWT.None);
    typeLabel.setText(Messages.exportWizardFileType);
    typeLabel.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    Composite typeComposite = new Composite(typeOptionGroup, SWT.None);
    typeComposite.setLayoutData(CommonUITool.createGridData(GridData.FILL_BOTH, 1, 1, -1, -1));
    typeComposite.setLayout(new GridLayout(6, false));
    sqlButton = new Button(typeComposite, SWT.RADIO);
    sqlButton.setText("SQL");
    sqlButton.setToolTipText("SQL");
    sqlButton.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    sqlButton.addSelectionListener(new SelectionListener() {

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

        public void widgetDefaultSelected(SelectionEvent e) {
            useFirstAsColumnBtn.setEnabled(false);
            setNullWidgetStatus(false);
            setDelimiterWidgetStatus(false);
            updateDialogStatus(null);
            updateExportLobButtonStatus();
        }
    });
    csvButton = new Button(typeComposite, SWT.RADIO);
    csvButton.setText("CSV");
    csvButton.setToolTipText("CSV");
    csvButton.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    csvButton.addSelectionListener(new SelectionListener() {

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

        public void widgetDefaultSelected(SelectionEvent e) {
            useFirstAsColumnBtn.setEnabled(true);
            setNullWidgetStatus(true);
            setDelimiterWidgetStatus(false);
            updateDialogStatus(null);
            updateExportLobButtonStatus();
        }
    });
    xlsButton = new Button(typeComposite, SWT.RADIO);
    xlsButton.setText("XLS");
    xlsButton.setToolTipText("XLS");
    xlsButton.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    xlsButton.addSelectionListener(new SelectionListener() {

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

        public void widgetDefaultSelected(SelectionEvent e) {
            useFirstAsColumnBtn.setEnabled(true);
            setNullWidgetStatus(true);
            setDelimiterWidgetStatus(false);
            updateDialogStatus(null);
            updateExportLobButtonStatus();
        }
    });
    xlsxButton = new Button(typeComposite, SWT.RADIO);
    xlsxButton.setText("XLSX");
    xlsxButton.setToolTipText("XLSX");
    xlsxButton.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    xlsxButton.addSelectionListener(new SelectionListener() {

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

        public void widgetDefaultSelected(SelectionEvent e) {
            useFirstAsColumnBtn.setEnabled(true);
            setNullWidgetStatus(true);
            setDelimiterWidgetStatus(false);
            updateDialogStatus(null);
            updateExportLobButtonStatus();
        }
    });
    txtButton = new Button(typeComposite, SWT.RADIO);
    txtButton.setText("TXT");
    txtButton.setToolTipText("TXT");
    txtButton.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    txtButton.addSelectionListener(new SelectionListener() {

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

        public void widgetDefaultSelected(SelectionEvent e) {
            useFirstAsColumnBtn.setEnabled(true);
            setNullWidgetStatus(true);
            setDelimiterWidgetStatus(true);
            updateDialogStatus(null);
            updateExportLobButtonStatus();
        }
    });
    obsButton = new Button(typeComposite, SWT.RADIO);
    obsButton.setText("OBS");
    obsButton.setToolTipText("OBS");
    obsButton.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    obsButton.addSelectionListener(new SelectionListener() {

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

        public void widgetDefaultSelected(SelectionEvent e) {
            useFirstAsColumnBtn.setEnabled(false);
            setNullWidgetStatus(false);
            setDelimiterWidgetStatus(false);
            updateDialogStatus(null);
            updateExportLobButtonStatus();
        }
    });
    Label pathLabel = new Label(typeOptionGroup, SWT.None);
    pathLabel.setText(Messages.exportWizardFilepath);
    pathLabel.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    Composite fileComposite = new Composite(typeOptionGroup, SWT.None);
    fileComposite.setLayoutData(CommonUITool.createGridData(GridData.FILL_BOTH, 1, 1, -1, -1));
    fileComposite.setLayout(new GridLayout(2, false));
    pathText = new Text(fileComposite, SWT.BORDER);
    pathText.setLayoutData(CommonUITool.createGridData(GridData.FILL_BOTH, 1, 1, -1, -1));
    pathText.setEditable(false);
    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 savedDirFile = TableUtil.getSavedDir(getShell(), Messages.titleSelectFolderToBeExported, Messages.msgSelectFolderToBeExported, pathText.getText());
            if (savedDirFile != null) {
                String savePathString = null;
                String[] files = savedDirFile.list();
                String databaseName = getDatabase().getDatabaseInfo().getDbName();
                if (files != null && files.length > 0) {
                    String confirmMessage = Messages.bind(Messages.errorExportExistsFilesInFolder, databaseName);
                    boolean useCreate = CommonUITool.openConfirmBox(confirmMessage);
                    if (useCreate) {
                        File newFolder = new File(savedDirFile.getAbsolutePath() + File.separator + databaseName);
                        boolean existsDbNameFolder = newFolder.exists();
                        files = newFolder.list();
                        if (existsDbNameFolder && files != null && files.length > 0) {
                            String newFolderName = databaseName + "_" + DateUtil.getDatetimeStringOnNow("HHmmss");
                            savePathString = savedDirFile.getAbsolutePath() + File.separator + newFolderName;
                            String warnMessage = Messages.bind(Messages.errorExportExistsFilesInFolderWithRename, newFolderName);
                            CommonUITool.openWarningBox(warnMessage);
                        } else {
                            savePathString = savedDirFile.getAbsolutePath() + File.separator + databaseName;
                        }
                        new File(savePathString).mkdirs();
                    } else {
                        return;
                    }
                } else {
                    savePathString = savedDirFile.getAbsolutePath();
                }
                pathText.setText(savePathString);
            }
            updateDialogStatus(null);
        }
    });
    Group parsingGroup = new Group(rightComposite, SWT.None);
    parsingGroup.setText(Messages.exportWizardParsingOption);
    parsingGroup.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 1, 1, -1, -1));
    GridLayout parsingGroupLayout = new GridLayout(4, false);
    parsingGroupLayout.horizontalSpacing = 10;
    parsingGroup.setLayout(parsingGroupLayout);
    Label threadCountLabel = new Label(parsingGroup, SWT.None);
    threadCountLabel.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    threadCountLabel.setText(Messages.lblThreadCount);
    threadCountSpinner = new Spinner(parsingGroup, SWT.BORDER | SWT.LEFT);
    threadCountSpinner.setValues(DEFAULT_EXPORT_THREAD_COUNT, MIN_EXPORT_THREAD_COUNT, MAX_EXPORT_THREAD_COUNT, 0, 1, 2);
    threadCountSpinner.setLayoutData(CommonUITool.createGridData(GridData.HORIZONTAL_ALIGN_FILL, 1, 1, -1, -1));
    Label emptyLabel = new Label(parsingGroup, SWT.None);
    emptyLabel.setLayoutData(CommonUITool.createGridData(2, 1, -1, -1));
    emptyLabel.setText("");
    Label dbCharsetLabel = new Label(parsingGroup, SWT.None);
    dbCharsetLabel.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    dbCharsetLabel.setText(Messages.lblJDBCCharset);
    dbCharsetCombo = new Combo(parsingGroup, SWT.BORDER);
    dbCharsetCombo.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    dbCharsetCombo.setItems(QueryOptions.getAllCharset(null));
    dbCharsetCombo.setEnabled(false);
    Label fileCharsetLabel = new Label(parsingGroup, SWT.None);
    fileCharsetLabel.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    fileCharsetLabel.setText(Messages.lblFileCharset);
    fileCharsetCombo = new Combo(parsingGroup, SWT.BORDER);
    fileCharsetCombo.setLayoutData(CommonUITool.createGridData(1, 1, -1, 21));
    fileCharsetCombo.setItems(QueryOptions.getAllCharset(null));
    Group dataOptionGroup = new Group(rightComposite, SWT.None);
    dataOptionGroup.setText(Messages.exportWizardDataOption);
    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.exportFirstLineFLAG);
        GridData gridData = new GridData();
        gridData.grabExcessHorizontalSpace = true;
        gridData.horizontalIndent = 0;
        gridData.horizontalSpan = 2;
        useFirstAsColumnBtn.setLayoutData(gridData);
        useFirstAsColumnBtn.setSelection(false);
    }
    Group delimiterOptionGroup = new Group(dataOptionGroup, SWT.None);
    delimiterOptionGroup.setText(Messages.exportWizardDelimiterOptions);
    delimiterOptionGroup.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 1, 1, -1, -1));
    delimiterOptionGroup.setLayout(new GridLayout(2, false));
    Label columnLabel = new Label(delimiterOptionGroup, SWT.None);
    columnLabel.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    columnLabel.setText(Messages.exportWizardColumnSeperator);
    columnDelimiterCombo = new Combo(delimiterOptionGroup, SWT.BORDER);
    columnDelimiterCombo.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 1, 1, -1, -1));
    columnDelimiterCombo.setTextLimit(32);
    columnDelimiterCombo.setItems(columnDelimeterName);
    columnDelimiterCombo.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent event) {
            updateDialogStatus(null);
        }
    });
    Label rowLabel = new Label(delimiterOptionGroup, SWT.None);
    rowLabel.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    rowLabel.setText(Messages.exportWizardRowSeperator);
    rowDelimiterCombo = new Combo(delimiterOptionGroup, SWT.BORDER);
    rowDelimiterCombo.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 1, 1, -1, -1));
    rowDelimiterCombo.setTextLimit(32);
    rowDelimiterCombo.setItems(rowDelimeterName);
    rowDelimiterCombo.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent event) {
            updateDialogStatus(null);
        }
    });
    Group nullValueGroup = new Group(dataOptionGroup, SWT.None);
    nullValueGroup.setText(Messages.exportWizardNullOptions);
    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'");
    nullOneButton.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    nullTwoButton = new Button(nullValueGroup, SWT.RADIO);
    nullTwoButton.setText("'\\N'");
    nullTwoButton.setLayoutData(CommonUITool.createGridData(2, 1, -1, -1));
    nullThreeButton = new Button(nullValueGroup, SWT.RADIO);
    nullThreeButton.setText("'(NULL)'");
    nullThreeButton.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    otherButton = new Button(nullValueGroup, SWT.RADIO);
    otherButton.setText(Messages.btnOther);
    otherButton.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    otherButton.addSelectionListener(new SelectionListener() {

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

        public void widgetDefaultSelected(SelectionEvent e) {
            updateDialogStatus(null);
        }
    });
    otherText = new Text(nullValueGroup, SWT.BORDER);
    otherText.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 1, 1, -1, -1));
    otherText.setTextLimit(64);
    otherText.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent event) {
            updateDialogStatus(null);
        }
    });
    useFirstAsColumnBtn.setEnabled(false);
    setNullWidgetStatus(false);
    setDelimiterWidgetStatus(false);
}
Also used : Group(org.eclipse.swt.widgets.Group) ModifyListener(org.eclipse.swt.events.ModifyListener) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) CellEditor(org.eclipse.jface.viewers.CellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) Spinner(org.eclipse.swt.widgets.Spinner) Label(org.eclipse.swt.widgets.Label) EditingSupport(org.eclipse.jface.viewers.EditingSupport) Combo(org.eclipse.swt.widgets.Combo) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) ICellEditorListener(org.eclipse.jface.viewers.ICellEditorListener) Button(org.eclipse.swt.widgets.Button) RowLayout(org.eclipse.swt.layout.RowLayout) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FormAttachment(org.eclipse.swt.layout.FormAttachment) FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) FilterTreeContentProvider(com.cubrid.common.ui.common.dialog.FilterTreeContentProvider) ExportObjectLabelProvider(com.cubrid.common.ui.common.navigator.ExportObjectLabelProvider) GridData(org.eclipse.swt.layout.GridData) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) File(java.io.File) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 9 with ICellEditorListener

use of org.eclipse.jface.viewers.ICellEditorListener in project tdi-studio-se by Talend.

the class InputDataMapTableView method initColumnsOfTableColumns.

@Override
public void initColumnsOfTableColumns(final TableViewerCreator tableViewerCreatorForColumns) {
    TableViewerCreatorColumn column = null;
    //$NON-NLS-1$
    String useInJoinTitle = Messages.getString("InputDataMapTableView.columnTitle.ExplicitJoin");
    column = new TableViewerCreatorColumn(tableViewerCreatorForColumns);
    column.setTitle(useInJoinTitle);
    column.setId(ID_EXPLICIT_JOIN);
    column.setBeanPropertyAccessors(new IBeanPropertyAccessors<InputColumnTableEntry, Boolean>() {

        public Boolean get(InputColumnTableEntry bean) {
            return bean.isJoin();
        }

        public void set(InputColumnTableEntry bean, Boolean value) {
            bean.setJoin(value);
            boolean enable = true;
            if (dropDownItem != null && !dropDownItem.isDisposed()) {
                enable = dropDownItem.isEnabled();
            }
            if (enable && value && mapperManager.getCurrentLanguage().unuseWithExplicitJoin().contains(getInputTable().getJoinType())) {
                if (menu != null) {
                    MenuItem[] menuItems = menu.getItems();
                    for (MenuItem mi : menuItems) {
                        if (mi.getImage() == null) {
                            continue;
                        }
                        if (mi.getText().equals(getInputTable().getJoinType().getLabel())) {
                            mi.setImage(null);
                        }
                    }
                    menuItems[1].setImage(ImageProviderMapper.getImage(ImageInfo.CHECKED_ICON));
                }
                getInputTable().setJoinType(JOIN.INNER_JOIN);
                refreshLabelForJoinDropDown();
                mapperManager.getUiManager().refreshSqlExpression();
            }
        }
    });
    column.setModifiable(true);
    // column.setWidth(12);
    column.setWidth(65);
    //$NON-NLS-1$
    column.setDisplayedValue("");
    // column.setResizable(false);
    CheckboxTableEditorContent checkboxTableEditorContent = new CheckboxTableEditorContent();
    checkboxTableEditorContent.setToolTipText(useInJoinTitle);
    column.setTableEditorContent(checkboxTableEditorContent);
    column.setToolTipHeader(useInJoinTitle);
    column = new TableViewerCreatorColumn(tableViewerCreatorForColumns);
    column.setTitle(DataMapTableView.COLUMN_NAME);
    column.setId(DataMapTableView.ID_NAME_COLUMN);
    column.setBeanPropertyAccessors(new IBeanPropertyAccessors<InputColumnTableEntry, String>() {

        public String get(InputColumnTableEntry bean) {
            return bean.getMetadataColumn().getLabel();
        }

        public void set(InputColumnTableEntry bean, String value) {
            bean.getMetadataColumn().setLabel(value);
        }
    });
    column.setWeight(COLUMN_NAME_SIZE_WEIGHT);
    final TableViewerCreatorColumn columnOperator = new TableViewerCreatorColumn(tableViewerCreatorForColumns);
    //$NON-NLS-1$
    columnOperator.setTitle(Messages.getString("InputDataMapTableView.columnTitle.Operator"));
    columnOperator.setId(DataMapTableView.ID_OPERATOR);
    //$NON-NLS-1$
    columnOperator.setToolTipHeader(Messages.getString("InputDataMapTableView.Operator"));
    columnOperator.setBeanPropertyAccessors(new IBeanPropertyAccessors<InputColumnTableEntry, String>() {

        public String get(InputColumnTableEntry bean) {
            return bean.getOperator();
        }

        public void set(InputColumnTableEntry bean, String value) {
            bean.setOperator(value);
            mapperManager.getProblemsManager().checkProblemsForTableEntry(bean, true);
        }
    });
    columnOperator.setModifiable(true);
    columnOperator.setWidth(85);
    final IDbOperatorManager operatorsManager = mapperManager.getCurrentLanguage().getOperatorsManager();
    IDbOperator[] operators = operatorsManager.getOperators();
    String[] arrayOperators = new String[operators.length + 1];
    //$NON-NLS-1$
    arrayOperators[0] = "";
    for (int i = 0; i < operators.length; i++) {
        arrayOperators[i + 1] = operators[i].getOperator();
    }
    final ComboxCellEditorImproved typeComboEditor = new ComboxCellEditorImproved(tableViewerCreatorForColumns.getTable(), arrayOperators, SWT.NONE);
    typeComboEditor.addListener(new ICellEditorListener() {

        public void applyEditorValue() {
            ModifiedObjectInfo modifiedObjectInfo = tableViewerCreatorForColumns.getModifiedObjectInfo();
            InputColumnTableEntry currentInputEntry = (InputColumnTableEntry) modifiedObjectInfo.getCurrentModifiedBean();
            currentInputEntry.setOriginalExpression(null);
            Combo combo = (Combo) typeComboEditor.getControl();
            String selectedText = combo.getText();
            IDbOperator operatorFromValue = operatorsManager.getOperatorFromValue(selectedText);
            if (operatorFromValue != null && operatorFromValue.isMonoOperand()) {
                //$NON-NLS-1$
                currentInputEntry.setExpression("");
            }
        }

        public void cancelEditor() {
            ModifiedObjectInfo modifiedObjectInfo = tableViewerCreatorForColumns.getModifiedObjectInfo();
            InputColumnTableEntry currentInputEntry = (InputColumnTableEntry) modifiedObjectInfo.getCurrentModifiedBean();
        // currentInputEntry.setExpression(currentInputEntry.getOriginalExpression());
        }

        public void editorValueChanged(boolean oldValidState, boolean newValidState) {
            ModifiedObjectInfo modifiedObjectInfo = tableViewerCreatorForColumns.getModifiedObjectInfo();
            InputColumnTableEntry currentInputEntry = (InputColumnTableEntry) modifiedObjectInfo.getCurrentModifiedBean();
            if (modifiedObjectInfo.getCurrentModifiedColumn() == columnOperator) {
                if (currentInputEntry != modifiedObjectInfo.getPreviousModifiedBean()) {
                    currentInputEntry.setOriginalExpression(currentInputEntry.getExpression());
                }
                Combo combo = (Combo) typeComboEditor.getControl();
                String selectedText = combo.getText();
                if (//$NON-NLS-1$
                !selectedText.equals("") && (currentInputEntry.getExpression() == null || currentInputEntry.getExpression().trim().length() == 0)) {
                    IDbOperator operatorFromValue = operatorsManager.getOperatorFromValue(selectedText);
                    if (operatorFromValue.getAssociatedExpression() != null) {
                        currentInputEntry.setExpression(operatorFromValue.getAssociatedExpression());
                    }
                }
            }
        }
    });
    Combo typeCombo = (Combo) typeComboEditor.getControl();
    // typeCombo.setEditable(true);
    columnOperator.setCellEditor(typeComboEditor, CellEditorValueAdapterFactory.getComboAdapterForComboCellEditorImproved());
    columnOperator.setAlignment(ALIGNMENT.CENTER);
    final TableViewerCreatorColumn columnExpression = new TableViewerCreatorColumn(tableViewerCreatorForColumns);
    //$NON-NLS-1$
    columnExpression.setTitle(Messages.getString("InputDataMapTableView.columnTitle.Expr"));
    columnExpression.setId(DataMapTableView.ID_EXPRESSION_COLUMN);
    columnExpression.setBeanPropertyAccessors(new IBeanPropertyAccessors<InputColumnTableEntry, String>() {

        public String get(InputColumnTableEntry bean) {
            return bean.getExpression();
        }

        public void set(InputColumnTableEntry bean, String value) {
            bean.setExpression(value);
        // mapperManager.getProblemsManager().checkProblemsForTableEntry(bean, true);
        }
    });
    columnExpression.setModifiable(true);
    //$NON-NLS-1$
    columnExpression.setDefaultInternalValue("");
    createExpressionCellEditor(tableViewerCreatorForColumns, columnExpression, new Zone[] { Zone.INPUTS }, false);
    columnExpression.setWeight(COLUMN_EXPRESSION_SIZE_WEIGHT);
    columnExpression.setColorProvider(new IColumnColorProvider() {

        public Color getBackgroundColor(Object bean) {
            if (!cellModifier.canModify(bean, columnExpression.getId())) {
                return READONLY_CELL_BG_COLOR;
            }
            return null;
        }

        public Color getForegroundColor(Object bean) {
            return null;
        }
    });
    configureCellModifier(tableViewerCreatorForColumns);
}
Also used : Color(org.eclipse.swt.graphics.Color) MenuItem(org.eclipse.swt.widgets.MenuItem) Combo(org.eclipse.swt.widgets.Combo) Point(org.eclipse.swt.graphics.Point) ICellEditorListener(org.eclipse.jface.viewers.ICellEditorListener) CheckboxTableEditorContent(org.talend.commons.ui.swt.tableviewer.tableeditor.CheckboxTableEditorContent) IDbOperator(org.talend.designer.dbmap.language.operator.IDbOperator) ModifiedObjectInfo(org.talend.commons.ui.runtime.swt.tableviewer.data.ModifiedObjectInfo) TableViewerCreatorColumn(org.talend.commons.ui.swt.tableviewer.TableViewerCreatorColumn) InputColumnTableEntry(org.talend.designer.dbmap.model.tableentry.InputColumnTableEntry) IColumnColorProvider(org.talend.commons.ui.runtime.swt.tableviewer.behavior.IColumnColorProvider) IDbOperatorManager(org.talend.designer.dbmap.language.operator.IDbOperatorManager) ComboxCellEditorImproved(org.talend.commons.ui.runtime.swt.celleditor.ComboxCellEditorImproved)

Example 10 with ICellEditorListener

use of org.eclipse.jface.viewers.ICellEditorListener in project egit by eclipse.

the class ConfigurationEditorComponent method createContents.

/**
 * @return the control being created
 */
public Control createContents() {
    final Composite main = new Composite(parent, SWT.NONE);
    main.setLayout(new GridLayout(2, false));
    GridDataFactory.fillDefaults().grab(true, true).applyTo(main);
    if (editableConfig instanceof FileBasedConfig) {
        Composite locationPanel = new Composite(main, SWT.NONE);
        GridLayout locationLayout = new GridLayout(3, false);
        locationLayout.marginWidth = 0;
        locationPanel.setLayout(locationLayout);
        GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(locationPanel);
        Label locationLabel = new Label(locationPanel, SWT.NONE);
        locationLabel.setText(UIText.ConfigurationEditorComponent_ConfigLocationLabel);
        // GridDataFactory.fillDefaults().applyTo(locationLabel);
        int locationStyle = SWT.BORDER | SWT.READ_ONLY;
        location = new Text(locationPanel, locationStyle);
        GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(location);
        Button openEditor = new Button(locationPanel, SWT.PUSH);
        openEditor.setText(UIText.ConfigurationEditorComponent_OpenEditorButton);
        openEditor.setToolTipText(UIText.ConfigurationEditorComponent_OpenEditorTooltip);
        openEditor.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                IFileStore store = EFS.getLocalFileSystem().getStore(new Path(((FileBasedConfig) editableConfig).getFile().getAbsolutePath()));
                try {
                    IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), new FileStoreEditorInput(store), EditorsUI.DEFAULT_TEXT_EDITOR_ID);
                } catch (PartInitException ex) {
                    Activator.handleError(ex.getMessage(), ex, true);
                }
            }
        });
        openEditor.setEnabled(((FileBasedConfig) editableConfig).getFile() != null);
    }
    tv = new TreeViewer(main, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER);
    Tree tree = tv.getTree();
    GridDataFactory.fillDefaults().hint(100, 60).grab(true, true).applyTo(tree);
    TreeColumn key = new TreeColumn(tree, SWT.NONE);
    key.setText(UIText.ConfigurationEditorComponent_KeyColumnHeader);
    key.setWidth(150);
    final TextCellEditor editor = new TextCellEditor(tree);
    editor.setValidator(new ICellEditorValidator() {

        @Override
        public String isValid(Object value) {
            String editedValue = value.toString();
            return editedValue.length() > 0 ? null : UIText.ConfigurationEditorComponent_EmptyStringNotAllowed;
        }
    });
    editor.addListener(new ICellEditorListener() {

        @Override
        public void editorValueChanged(boolean oldValidState, boolean newValidState) {
            setErrorMessage(editor.getErrorMessage());
        }

        @Override
        public void cancelEditor() {
            setErrorMessage(null);
        }

        @Override
        public void applyEditorValue() {
            setErrorMessage(null);
        }
    });
    TreeColumn value = new TreeColumn(tree, SWT.NONE);
    value.setText(UIText.ConfigurationEditorComponent_ValueColumnHeader);
    value.setWidth(250);
    new TreeViewerColumn(tv, value).setEditingSupport(new EditingSupport(tv) {

        @Override
        protected void setValue(Object element, Object newValue) {
            Entry entry = (Entry) element;
            if (!entry.value.equals(newValue)) {
                entry.changeValue(newValue.toString());
                markDirty();
            }
        }

        @Override
        protected Object getValue(Object element) {
            return ((Entry) element).value;
        }

        @Override
        protected CellEditor getCellEditor(Object element) {
            return editor;
        }

        @Override
        protected boolean canEdit(Object element) {
            return editable && element instanceof Entry;
        }
    });
    tv.setContentProvider(new WorkbenchContentProvider());
    Font defaultFont;
    if (useDialogFont)
        defaultFont = JFaceResources.getDialogFont();
    else
        defaultFont = JFaceResources.getDefaultFont();
    tv.setLabelProvider(new ConfigEditorLabelProvider(defaultFont));
    tree.setHeaderVisible(true);
    tree.setLinesVisible(true);
    Composite buttonPanel = new Composite(main, SWT.NONE);
    GridLayoutFactory.fillDefaults().applyTo(buttonPanel);
    GridDataFactory.fillDefaults().grab(false, false).applyTo(buttonPanel);
    newValue = new Button(buttonPanel, SWT.PUSH);
    GridDataFactory.fillDefaults().applyTo(newValue);
    newValue.setText(UIText.ConfigurationEditorComponent_AddButton);
    newValue.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            String suggestedKey;
            IStructuredSelection sel = (IStructuredSelection) tv.getSelection();
            Object first = sel.getFirstElement();
            if (first instanceof Section)
                suggestedKey = ((Section) first).name + DOT;
            else if (first instanceof SubSection) {
                SubSection sub = (SubSection) first;
                suggestedKey = sub.parent.name + DOT + sub.name + DOT;
            } else if (first instanceof Entry) {
                Entry entry = (Entry) first;
                if (entry.sectionparent != null)
                    suggestedKey = entry.sectionparent.name + DOT;
                else
                    suggestedKey = entry.subsectionparent.parent.name + DOT + entry.subsectionparent.name + DOT;
            } else
                suggestedKey = null;
            AddConfigEntryDialog dlg = new AddConfigEntryDialog(getShell(), suggestedKey);
            if (dlg.open() == Window.OK) {
                String result = dlg.getKey();
                if (result == null) {
                    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=472110
                    return;
                }
                StringTokenizer st = new StringTokenizer(result, DOT);
                if (st.countTokens() == 2) {
                    String sectionName = st.nextToken();
                    String entryName = st.nextToken();
                    Entry entry = ((GitConfig) tv.getInput()).getEntry(sectionName, null, entryName);
                    if (entry == null)
                        editableConfig.setString(sectionName, null, entryName, dlg.getValue());
                    else
                        entry.addValue(dlg.getValue());
                    markDirty();
                } else if (st.countTokens() > 2) {
                    int n = st.countTokens();
                    String sectionName = st.nextToken();
                    StringBuilder b = new StringBuilder(st.nextToken());
                    for (int i = 0; i < n - 3; i++) {
                        b.append(DOT);
                        b.append(st.nextToken());
                    }
                    String subSectionName = b.toString();
                    String entryName = st.nextToken();
                    Entry entry = ((GitConfig) tv.getInput()).getEntry(sectionName, subSectionName, entryName);
                    if (entry == null)
                        editableConfig.setString(sectionName, subSectionName, entryName, dlg.getValue());
                    else
                        entry.addValue(dlg.getValue());
                    markDirty();
                } else
                    Activator.handleError(UIText.ConfigurationEditorComponent_WrongNumberOfTokensMessage, null, true);
            }
        }
    });
    remove = new Button(buttonPanel, SWT.PUSH);
    GridDataFactory.fillDefaults().applyTo(remove);
    remove.setText(UIText.ConfigurationEditorComponent_RemoveButton);
    remove.setToolTipText(UIText.ConfigurationEditorComponent_RemoveTooltip);
    remove.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection sel = (IStructuredSelection) tv.getSelection();
            Object first = sel.getFirstElement();
            if (first instanceof Section) {
                Section section = (Section) first;
                if (MessageDialog.openConfirm(getShell(), UIText.ConfigurationEditorComponent_RemoveSectionTitle, NLS.bind(UIText.ConfigurationEditorComponent_RemoveSectionMessage, section.name))) {
                    editableConfig.unsetSection(section.name, null);
                    markDirty();
                }
            } else if (first instanceof SubSection) {
                SubSection section = (SubSection) first;
                if (MessageDialog.openConfirm(getShell(), UIText.ConfigurationEditorComponent_RemoveSubsectionTitle, NLS.bind(UIText.ConfigurationEditorComponent_RemoveSubsectionMessage, section.parent.name + DOT + section.name))) {
                    editableConfig.unsetSection(section.parent.name, section.name);
                    markDirty();
                }
            } else if (first instanceof Entry) {
                ((Entry) first).removeValue();
                markDirty();
            }
            super.widgetSelected(e);
        }
    });
    tv.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            updateEnablement();
        }
    });
    initControlsFromConfig();
    contents = main;
    return contents;
}
Also used : TreeViewer(org.eclipse.jface.viewers.TreeViewer) CellEditor(org.eclipse.jface.viewers.CellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) Label(org.eclipse.swt.widgets.Label) EditingSupport(org.eclipse.jface.viewers.EditingSupport) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Font(org.eclipse.swt.graphics.Font) GridLayout(org.eclipse.swt.layout.GridLayout) ICellEditorListener(org.eclipse.jface.viewers.ICellEditorListener) Button(org.eclipse.swt.widgets.Button) TreeColumn(org.eclipse.swt.widgets.TreeColumn) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Tree(org.eclipse.swt.widgets.Tree) PartInitException(org.eclipse.ui.PartInitException) FileBasedConfig(org.eclipse.jgit.storage.file.FileBasedConfig) Path(org.eclipse.core.runtime.Path) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Text(org.eclipse.swt.widgets.Text) UIText(org.eclipse.egit.ui.internal.UIText) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) StringTokenizer(java.util.StringTokenizer) ICellEditorValidator(org.eclipse.jface.viewers.ICellEditorValidator) IFileStore(org.eclipse.core.filesystem.IFileStore) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) FileStoreEditorInput(org.eclipse.ui.ide.FileStoreEditorInput)

Aggregations

ICellEditorListener (org.eclipse.jface.viewers.ICellEditorListener)10 TextCellEditor (org.eclipse.jface.viewers.TextCellEditor)6 CellEditor (org.eclipse.jface.viewers.CellEditor)5 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)4 SelectionEvent (org.eclipse.swt.events.SelectionEvent)4 GridLayout (org.eclipse.swt.layout.GridLayout)4 Composite (org.eclipse.swt.widgets.Composite)4 Label (org.eclipse.swt.widgets.Label)4 EditingSupport (org.eclipse.jface.viewers.EditingSupport)3 TreeViewerColumn (org.eclipse.jface.viewers.TreeViewerColumn)3 ControlEvent (org.eclipse.swt.events.ControlEvent)3 GridData (org.eclipse.swt.layout.GridData)3 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)2 AncestorListener (org.eclipse.draw2d.AncestorListener)2 IFigure (org.eclipse.draw2d.IFigure)2 EditPart (org.eclipse.gef.EditPart)2 EditPartListener (org.eclipse.gef.EditPartListener)2 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)2 CheckStateChangedEvent (org.eclipse.jface.viewers.CheckStateChangedEvent)2 ICellEditorValidator (org.eclipse.jface.viewers.ICellEditorValidator)2