Search in sources :

Example 51 with VerifyEvent

use of org.eclipse.swt.events.VerifyEvent in project rap by entirej.

the class EJRWTTextItemRenderer method createComponent.

@Override
public void createComponent(Composite composite) {
    String alignmentProperty = _rendererProps.getStringProperty(EJRWTTextItemRendererDefinitionProperties.PROPERTY_ALIGNMENT);
    if (alignmentProperty == null) {
        alignmentProperty = _rendererProps.getStringProperty("ALLIGNMENT");
    }
    String hint = _screenItemProperties.getHint();
    if (_displayValueAsLabel) {
        labelField = new EJRWTAbstractLabel(composite) {

            @Override
            public Label createLabel(Composite parent) {
                return _valueLabel = newVlaueLabel(parent);
            }

            @Override
            public Control createCustomActionLabel(Composite parent) {
                // TODO Auto-generated method stub
                return null;
            }

            @Override
            public Control createActionLabel(Composite parent) {
                // TODO Auto-generated method stub
                return null;
            }
        };
        _valueLabel.setData(_itemProperties.getName());
        _valueLabel.setData(EJ_RWT.CUSTOM_VARIANT, getCSSKey());
        String customCSSKey = _rendererProps.getStringProperty(EJRWTButtonItemRendererDefinitionProperties.PROPERTY_CSS_KEY);
        if (customCSSKey != null && customCSSKey.trim().length() > 0) {
            _valueLabel.setData(EJ_RWT.CUSTOM_VARIANT, customCSSKey);
        }
        if (hint != null && hint.trim().length() > 0) {
            _valueLabel.setToolTipText(hint);
        }
        setValueLabelAlign(alignmentProperty);
        _visualContext = new EJRWTItemRendererVisualContext(_valueLabel.getBackground(), _valueLabel.getForeground(), _valueLabel.getFont());
        setInitialValue(_baseValue);
    } else {
        final String alignmentProp = alignmentProperty;
        _actionControl = new EJRWTAbstractActionText(composite) {

            @Override
            public Text createText(Composite parent) {
                int style = SWT.BORDER;
                if (_displayValueAsProtected) {
                    style = style | SWT.PASSWORD;
                }
                _textField = newTextField(parent, getComponentStyle(alignmentProp, style));
                _textField.setData(EJ_RWT.CUSTOM_VARIANT, getCSSKey());
                String customCSSKey = _rendererProps.getStringProperty(EJRWTButtonItemRendererDefinitionProperties.PROPERTY_CSS_KEY);
                if (customCSSKey != null && customCSSKey.trim().length() > 0) {
                    _textField.setData(EJ_RWT.CUSTOM_VARIANT, customCSSKey);
                }
                return _textField;
            }

            @Override
            public Control createCustomActionLabel(Composite parent) {
                return createCustomButtonControl(parent);
            }

            @Override
            public Control createActionLabel(Composite parent) {
                Label label = new Label(parent, SWT.NONE);
                label.setImage(EJRWTImageRetriever.get(EJRWTImageRetriever.IMG_FIND_LOV));
                label.addFocusListener(EJRWTTextItemRenderer.this);
                label.addMouseListener(new MouseListener() {

                    private static final long serialVersionUID = 529634857284996692L;

                    @Override
                    public void mouseUp(MouseEvent arg0) {
                        _item.getItemLovController().displayLov(EJLovDisplayReason.LOV);
                    }

                    @Override
                    public void mouseDown(MouseEvent arg0) {
                    }

                    @Override
                    public void mouseDoubleClick(MouseEvent arg0) {
                    }
                });
                final EJFrameworkExtensionProperties rendererProp = EJCoreProperties.getInstance().getApplicationDefinedProperties();
                final EJFrameworkExtensionProperties propertyGroup = rendererProp.getPropertyGroup(EJRWTSingleRecordBlockDefinitionProperties.ACTION_GROUP);
                String lovKey = "SHIFT+ARROW_DOWN";
                if (propertyGroup != null) {
                    lovKey = propertyGroup.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ACTION_LOV_KEY);
                }
                if (lovKey == null) {
                    lovKey = "SHIFT+ARROW_DOWN";
                }
                String[] keys = new String[] { lovKey, "ENTER", "RETURN", "CR" };
                label.setData(EJ_RWT.ACTIVE_KEYS, keys);
                getTextControl().setData(EJ_RWT.ACTIVE_KEYS, keys);
                addKeyListener(new KeyListener() {

                    @Override
                    public void keyReleased(KeyEvent arg0) {
                        if ((arg0.stateMask & SWT.SHIFT) != 0 && arg0.keyCode == SWT.ARROW_DOWN && isLovActivated()) {
                            _item.getItemLovController().displayLov(EJLovDisplayReason.LOV);
                        }
                        if (arg0.keyCode == 13 && (SWT.MULTI != (_textField.getStyle() & SWT.MULTI) || (arg0.stateMask & SWT.CONTROL) != 0)) {
                            commitValue();
                        }
                    }

                    @Override
                    public void keyPressed(KeyEvent arg0) {
                    }
                });
                return label;
            }
        };
        if (_maxLength > 0) {
            _textField.setTextLimit(_maxLength);
        }
        if (hint != null && hint.trim().length() > 0) {
            _textField.setToolTipText(hint);
        }
        _visualContext = new EJRWTItemRendererVisualContext(_textField.getBackground(), _textField.getForeground(), _textField.getFont());
        _textField.setData(_item.getReferencedItemProperties().getName());
        _textField.addFocusListener(this);
        _mandatoryDecoration = new ControlDecoration(_actionControl, SWT.TOP | SWT.LEFT);
        _errorDecoration = new ControlDecoration(_actionControl, SWT.TOP | SWT.LEFT);
        _errorDecoration.setImage(getDecorationImage(FieldDecorationRegistry.DEC_ERROR));
        _mandatoryDecoration.setImage(getDecorationImage(FieldDecorationRegistry.DEC_REQUIRED));
        _mandatoryDecoration.setShowHover(true);
        _mandatoryDecoration.setDescriptionText(_screenItemProperties.getLabel() == null || _screenItemProperties.getLabel().isEmpty() ? "Required Item" : String.format("%s is required", _screenItemProperties.getLabel()));
        if (_isValid) {
            _errorDecoration.hide();
        }
        if (message != null) {
            setMessage(message);
        }
        _mandatoryDecoration.hide();
        _textField.addModifyListener(_modifyListener);
        // TODO: Move to client side validation on Rap 2.4
        if (_valueCase != null && _valueCase != VALUE_CASE.DEFAULT) {
            _textField.addVerifyListener(new VerifyListener() {

                @Override
                public void verifyText(VerifyEvent event) {
                    String caseValue = toCaseValue(event.text);
                    if (!event.text.equals(caseValue)) {
                        event.text = caseValue;
                    }
                }
            });
        }
        setInitialValue(_baseValue);
        _textField.setMessage(defaultMessage == null ? "" : defaultMessage);
        setMessage(message);
    }
}
Also used : EJRWTAbstractLabel(org.entirej.applicationframework.rwt.application.components.EJRWTAbstractLabel) EJFrameworkExtensionProperties(org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionProperties) MouseEvent(org.eclipse.swt.events.MouseEvent) VerifyListener(org.eclipse.swt.events.VerifyListener) Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) EJRWTAbstractLabel(org.entirej.applicationframework.rwt.application.components.EJRWTAbstractLabel) EJRWTAbstractActionText(org.entirej.applicationframework.rwt.application.components.EJRWTAbstractActionText) Text(org.eclipse.swt.widgets.Text) EJRWTAbstractActionText(org.entirej.applicationframework.rwt.application.components.EJRWTAbstractActionText) KeyEvent(org.eclipse.swt.events.KeyEvent) Control(org.eclipse.swt.widgets.Control) MouseListener(org.eclipse.swt.events.MouseListener) ControlDecoration(org.eclipse.jface.fieldassist.ControlDecoration) KeyListener(org.eclipse.swt.events.KeyListener) EJRWTItemRendererVisualContext(org.entirej.applicationframework.rwt.utils.EJRWTItemRendererVisualContext) VerifyEvent(org.eclipse.swt.events.VerifyEvent)

Example 52 with VerifyEvent

use of org.eclipse.swt.events.VerifyEvent in project dbeaver by dbeaver.

the class ExtendedDirectEditManager method initCellEditor.

/**
 * @see org.eclipse.gef.tools.DirectEditManager#initCellEditor()
 */
@Override
protected void initCellEditor() {
    Text text = (Text) getCellEditor().getControl();
    // add the verifyListener to apply changes to the control size
    verifyListener = new VerifyListener() {

        /**
         * Changes the size of the editor control to reflect the changed
         * text
         */
        @Override
        public void verifyText(VerifyEvent event) {
            Text text = (Text) getCellEditor().getControl();
            String oldText = text.getText();
            String leftText = oldText.substring(0, event.start);
            String rightText = oldText.substring(event.end, oldText.length());
            GC gc = new GC(text);
            String s = leftText + event.text + rightText;
            Point size = gc.textExtent(leftText + event.text + rightText);
            gc.dispose();
            if (size.x != 0)
                size = text.computeSize(size.x, SWT.DEFAULT);
            else {
                // just make it square
                size.x = size.y;
            }
            getCellEditor().getControl().setSize(size.x, size.y);
        }
    };
    text.addVerifyListener(verifyListener);
    // set the initial value of the
    originalValue = getFigureText(this.figure);
    getCellEditor().setValue(originalValue);
    // calculate the font size of the underlying
    IFigure figure = getEditPart().getFigure();
    figureFont = figure.getFont();
    FontData data = figureFont.getFontData()[0];
    Dimension fontSize = new Dimension(0, data.getHeight());
    // set the font to be used
    this.figure.translateToAbsolute(fontSize);
    data.setHeight(fontSize.height);
    figureFont = new Font(null, data);
    // set the validator for the CellEditor
    getCellEditor().setValidator(validator);
    text.setFont(figureFont);
    text.selectAll();
}
Also used : VerifyListener(org.eclipse.swt.events.VerifyListener) FontData(org.eclipse.swt.graphics.FontData) Text(org.eclipse.swt.widgets.Text) Point(org.eclipse.swt.graphics.Point) Dimension(org.eclipse.draw2d.geometry.Dimension) GC(org.eclipse.swt.graphics.GC) VerifyEvent(org.eclipse.swt.events.VerifyEvent) Font(org.eclipse.swt.graphics.Font) IFigure(org.eclipse.draw2d.IFigure)

Example 53 with VerifyEvent

use of org.eclipse.swt.events.VerifyEvent in project archi-modelrepository-plugin by archi-contribs.

the class ModelRepositoryPreferencePage method createContents.

@Override
protected Control createContents(Composite parent) {
    // Help
    PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, HELP_ID);
    Composite client = new Composite(parent, SWT.NULL);
    GridLayout layout = new GridLayout();
    layout.marginWidth = layout.marginHeight = 0;
    client.setLayout(layout);
    // User details
    Group userDetailsGroup = new Group(client, SWT.NULL);
    userDetailsGroup.setText(Messages.ModelRepositoryPreferencePage_1);
    userDetailsGroup.setLayout(new GridLayout(2, false));
    userDetailsGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    Label label = new Label(userDetailsGroup, SWT.NULL);
    label.setText(Messages.ModelRepositoryPreferencePage_2);
    fUserNameTextField = UIUtils.createSingleTextControl(userDetailsGroup, SWT.BORDER, false);
    fUserNameTextField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    // Single text control so strip CRLFs
    label = new Label(userDetailsGroup, SWT.NULL);
    label.setText(Messages.ModelRepositoryPreferencePage_3);
    fUserEmailTextField = UIUtils.createSingleTextControl(userDetailsGroup, SWT.BORDER, false);
    fUserEmailTextField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    // Workspace Group
    Group workspaceGroup = new Group(client, SWT.NULL);
    workspaceGroup.setText(Messages.ModelRepositoryPreferencePage_4);
    workspaceGroup.setLayout(new GridLayout(3, false));
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.widthHint = 500;
    workspaceGroup.setLayoutData(gd);
    // Workspace folder location
    label = new Label(workspaceGroup, SWT.NULL);
    label.setText(Messages.ModelRepositoryPreferencePage_5);
    fUserRepoFolderTextField = UIUtils.createSingleTextControl(workspaceGroup, SWT.BORDER, false);
    fUserRepoFolderTextField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    Button folderButton = new Button(workspaceGroup, SWT.PUSH);
    folderButton.setText(Messages.ModelRepositoryPreferencePage_6);
    folderButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            String folderPath = chooseFolderPath();
            if (folderPath != null) {
                fUserRepoFolderTextField.setText(folderPath);
            }
        }
    });
    // Fetch in background
    fFetchInBackgroundButton = new Button(workspaceGroup, SWT.CHECK);
    fFetchInBackgroundButton.setText(Messages.ModelRepositoryPreferencePage_19);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = 3;
    fFetchInBackgroundButton.setLayoutData(gd);
    // Refresh interval
    label = new Label(workspaceGroup, SWT.NULL);
    label.setText(Messages.ModelRepositoryPreferencePage_21);
    fFetchInBackgroundIntervalSpinner = new Spinner(workspaceGroup, SWT.BORDER);
    fFetchInBackgroundIntervalSpinner.setMinimum(30);
    fFetchInBackgroundIntervalSpinner.setMaximum(3000);
    // Authentication
    Group authGroup = new Group(client, SWT.NULL);
    authGroup.setText(Messages.ModelRepositoryPreferencePage_0);
    authGroup.setLayout(new GridLayout());
    authGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    // Primary password
    fChangePrimaryPasswordButton = new Button(authGroup, SWT.PUSH);
    fChangePrimaryPasswordButton.setText(Messages.ModelRepositoryPreferencePage_25);
    fChangePrimaryPasswordButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            updatePrimaryPassword();
        }
    });
    // SSH Credentials
    Group sshGroup = new Group(authGroup, SWT.NULL);
    sshGroup.setText(Messages.ModelRepositoryPreferencePage_7);
    sshGroup.setLayout(new GridLayout(3, false));
    sshGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    label = new Label(sshGroup, SWT.NULL);
    label.setText(Messages.ModelRepositoryPreferencePage_24);
    fSSHIdentityFileTextField = UIUtils.createSingleTextControl(sshGroup, SWT.BORDER, false);
    fSSHIdentityFileTextField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    fSSHIdentitySelectButton = new Button(sshGroup, SWT.PUSH);
    fSSHIdentitySelectButton.setText(Messages.ModelRepositoryPreferencePage_6);
    fSSHIdentitySelectButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            String identityFile = chooseIdentityFile();
            if (identityFile != null) {
                fSSHIdentityFileTextField.setText(identityFile);
            }
        }
    });
    fSSHIdentityRequiresPasswordButton = new Button(sshGroup, SWT.CHECK);
    fSSHIdentityRequiresPasswordButton.setText(Messages.ModelRepositoryPreferencePage_22);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = 4;
    fSSHIdentityRequiresPasswordButton.setLayoutData(gd);
    fSSHIdentityRequiresPasswordButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            updateIdentityControls();
        }
    });
    label = new Label(sshGroup, SWT.NULL);
    label.setText(Messages.ModelRepositoryPreferencePage_23);
    fSSHIdentityPasswordTextField = UIUtils.createSingleTextControl(sshGroup, SWT.BORDER | SWT.PASSWORD, false);
    fSSHIdentityPasswordTextField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    fSSHIdentityPasswordTextField.setEnabled(false);
    // HTTP Credentials
    Group httpGroup = new Group(authGroup, SWT.NULL);
    httpGroup.setText(Messages.ModelRepositoryPreferencePage_9);
    httpGroup.setLayout(new GridLayout(1, false));
    httpGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    fStoreCredentialsButton = new Button(httpGroup, SWT.CHECK);
    fStoreCredentialsButton.setText(Messages.ModelRepositoryPreferencePage_8);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    fStoreCredentialsButton.setLayoutData(gd);
    // Proxy Group
    Group proxyGroup = new Group(client, SWT.NULL);
    proxyGroup.setText(Messages.ModelRepositoryPreferencePage_10);
    proxyGroup.setLayout(new GridLayout(4, false));
    proxyGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    fUseProxyButton = new Button(proxyGroup, SWT.CHECK);
    fUseProxyButton.setText(Messages.ModelRepositoryPreferencePage_11);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = 4;
    fUseProxyButton.setLayoutData(gd);
    fUseProxyButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            updateProxyControls();
        }
    });
    label = new Label(proxyGroup, SWT.NULL);
    label.setText(Messages.ModelRepositoryPreferencePage_12);
    fProxyHostTextField = UIUtils.createSingleTextControl(proxyGroup, SWT.BORDER, false);
    fProxyHostTextField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    fProxyHostTextField.setEnabled(false);
    label = new Label(proxyGroup, SWT.NULL);
    label.setText(Messages.ModelRepositoryPreferencePage_13);
    fProxyPortTextField = UIUtils.createSingleTextControl(proxyGroup, SWT.BORDER, false);
    fProxyPortTextField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    fProxyPortTextField.setEnabled(false);
    fProxyPortTextField.addVerifyListener(new VerifyListener() {

        @Override
        public void verifyText(VerifyEvent e) {
            String currentText = ((Text) e.widget).getText();
            String port = currentText.substring(0, e.start) + e.text + currentText.substring(e.end);
            try {
                int portNum = Integer.valueOf(port);
                if (portNum < 0 || portNum > 65535) {
                    e.doit = false;
                }
            } catch (NumberFormatException ex) {
                if (!port.equals("")) {
                    // $NON-NLS-1$
                    e.doit = false;
                }
            }
        }
    });
    fRequiresProxyAuthenticationButton = new Button(proxyGroup, SWT.CHECK);
    fRequiresProxyAuthenticationButton.setText(Messages.ModelRepositoryPreferencePage_14);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = 4;
    fRequiresProxyAuthenticationButton.setLayoutData(gd);
    fRequiresProxyAuthenticationButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            updateProxyControls();
        }
    });
    label = new Label(proxyGroup, SWT.NULL);
    label.setText(Messages.ModelRepositoryPreferencePage_15);
    fProxyUserNameTextField = UIUtils.createSingleTextControl(proxyGroup, SWT.BORDER, false);
    fProxyUserNameTextField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    fProxyUserNameTextField.setEnabled(false);
    label = new Label(proxyGroup, SWT.NULL);
    label.setText(Messages.ModelRepositoryPreferencePage_16);
    fProxyUserPasswordTextField = UIUtils.createSingleTextControl(proxyGroup, SWT.BORDER | SWT.PASSWORD, false);
    fProxyUserPasswordTextField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    fProxyUserPasswordTextField.setEnabled(false);
    setValues();
    return client;
}
Also used : Group(org.eclipse.swt.widgets.Group) VerifyListener(org.eclipse.swt.events.VerifyListener) Composite(org.eclipse.swt.widgets.Composite) Spinner(org.eclipse.swt.widgets.Spinner) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) VerifyEvent(org.eclipse.swt.events.VerifyEvent)

Example 54 with VerifyEvent

use of org.eclipse.swt.events.VerifyEvent in project archi-modelrepository-plugin by archi-contribs.

the class AddBranchDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    setMessage(Messages.AddBranchDialog_2, IMessageProvider.INFORMATION);
    setTitleImage(IArchiImages.ImageFactory.getImage(IArchiImages.ECLIPSE_IMAGE_NEW_WIZARD));
    Composite area = (Composite) super.createDialogArea(parent);
    Composite container = new Composite(area, SWT.NONE);
    container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    GridLayout layout = new GridLayout(2, false);
    container.setLayout(layout);
    txtBranch = createTextField(container, Messages.AddBranchDialog_3, SWT.NONE);
    txtBranch.addVerifyListener(new VerifyListener() {

        @Override
        public void verifyText(VerifyEvent e) {
            String currentText = ((Text) e.widget).getText();
            String newText = (currentText.substring(0, e.start) + e.text + currentText.substring(e.end));
            setMessage(Messages.AddBranchDialog_2, IMessageProvider.INFORMATION);
            boolean isValidRefName = !newText.isEmpty();
            if (isValidRefName) {
                isValidRefName = Repository.isValidRefName(Constants.R_HEADS + newText);
                if (!isValidRefName) {
                    if (newText.startsWith(".") || newText.endsWith(".")) {
                        // $NON-NLS-1$ //$NON-NLS-2$
                        setMessage(Messages.AddBranchDialog_4, IMessageProvider.ERROR);
                    } else if (newText.startsWith("/") || newText.endsWith("/")) {
                        // $NON-NLS-1$ //$NON-NLS-2$
                        setMessage(Messages.AddBranchDialog_5, IMessageProvider.ERROR);
                    } else {
                        setMessage(Messages.AddBranchDialog_7, IMessageProvider.ERROR);
                    }
                }
            }
            getButton(ADD_BRANCH).setEnabled(isValidRefName);
            getButton(ADD_BRANCH_CHECKOUT).setEnabled(isValidRefName);
        }
    });
    return area;
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) VerifyListener(org.eclipse.swt.events.VerifyListener) Composite(org.eclipse.swt.widgets.Composite) GridData(org.eclipse.swt.layout.GridData) VerifyEvent(org.eclipse.swt.events.VerifyEvent)

Example 55 with VerifyEvent

use of org.eclipse.swt.events.VerifyEvent in project dbeaver by serge-rider.

the class ExtendedDirectEditManager method initCellEditor.

/**
 * @see org.eclipse.gef.tools.DirectEditManager#initCellEditor()
 */
@Override
protected void initCellEditor() {
    Text text = (Text) getCellEditor().getControl();
    // add the verifyListener to apply changes to the control size
    verifyListener = new VerifyListener() {

        /**
         * Changes the size of the editor control to reflect the changed
         * text
         */
        @Override
        public void verifyText(VerifyEvent event) {
            Text text = (Text) getCellEditor().getControl();
            String oldText = text.getText();
            String leftText = oldText.substring(0, event.start);
            String rightText = oldText.substring(event.end, oldText.length());
            GC gc = new GC(text);
            String s = leftText + event.text + rightText;
            Point size = gc.textExtent(leftText + event.text + rightText);
            gc.dispose();
            if (size.x != 0)
                size = text.computeSize(size.x, SWT.DEFAULT);
            else {
                // just make it square
                size.x = size.y;
            }
            getCellEditor().getControl().setSize(size.x, size.y);
        }
    };
    text.addVerifyListener(verifyListener);
    // set the initial value of the
    originalValue = getFigureText(this.figure);
    getCellEditor().setValue(originalValue);
    // calculate the font size of the underlying
    IFigure figure = getEditPart().getFigure();
    figureFont = figure.getFont();
    FontData data = figureFont.getFontData()[0];
    Dimension fontSize = new Dimension(0, data.getHeight());
    // set the font to be used
    this.figure.translateToAbsolute(fontSize);
    data.setHeight(fontSize.height);
    figureFont = new Font(null, data);
    // set the validator for the CellEditor
    getCellEditor().setValidator(validator);
    text.setFont(figureFont);
    text.selectAll();
}
Also used : VerifyListener(org.eclipse.swt.events.VerifyListener) FontData(org.eclipse.swt.graphics.FontData) Text(org.eclipse.swt.widgets.Text) Point(org.eclipse.swt.graphics.Point) Dimension(org.eclipse.draw2d.geometry.Dimension) GC(org.eclipse.swt.graphics.GC) VerifyEvent(org.eclipse.swt.events.VerifyEvent) Font(org.eclipse.swt.graphics.Font) IFigure(org.eclipse.draw2d.IFigure)

Aggregations

VerifyEvent (org.eclipse.swt.events.VerifyEvent)57 VerifyListener (org.eclipse.swt.events.VerifyListener)41 Text (org.eclipse.swt.widgets.Text)29 GridData (org.eclipse.swt.layout.GridData)21 ModifyEvent (org.eclipse.swt.events.ModifyEvent)19 ModifyListener (org.eclipse.swt.events.ModifyListener)18 SelectionEvent (org.eclipse.swt.events.SelectionEvent)18 Composite (org.eclipse.swt.widgets.Composite)18 Label (org.eclipse.swt.widgets.Label)18 GridLayout (org.eclipse.swt.layout.GridLayout)17 VerifyKeyListener (org.eclipse.swt.custom.VerifyKeyListener)14 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)14 Point (org.eclipse.swt.graphics.Point)14 KeyEvent (org.eclipse.swt.events.KeyEvent)12 Button (org.eclipse.swt.widgets.Button)11 FocusEvent (org.eclipse.swt.events.FocusEvent)10 StyledText (org.eclipse.swt.custom.StyledText)7 MouseEvent (org.eclipse.swt.events.MouseEvent)7 Font (org.eclipse.swt.graphics.Font)7 Pattern (java.util.regex.Pattern)6