Example usage for org.eclipse.jface.fieldassist IControlCreator IControlCreator

List of usage examples for org.eclipse.jface.fieldassist IControlCreator IControlCreator

Introduction

In this page you can find the example usage for org.eclipse.jface.fieldassist IControlCreator IControlCreator.

Prototype

IControlCreator

Source Link

Usage

From source file:fr.imag.adele.cadse.si.workspace.uiplatform.swt.ui.DBrowserUI.java

License:Apache License

@Override
public void createControl(Composite container, int hspan) {

    Control swtControl;/* w  w  w. j a va 2  s.c  o m*/
    IFieldContenProposalProvider proposer = getContentAssistant();
    int style = _field.getStyle();
    if (!_field.isEditable()) {
        style |= SWT.READ_ONLY;
    }
    if (_field.isEditable() && proposer != null) {
        IControlContentAdapter contentAdapter = new ProposerTextContentAdapter(this, _swtuiplatform, proposer);

        _contentAssistField = new ContentAssistField(container, style, new IControlCreator() {
            public Control createControl(Composite controlParent, int style) {
                return new Text(controlParent, style);
            }
        }, contentAdapter, proposer.getContentProposalProvider(), proposer.getCommandId(),
                proposer.getAutoActivationCharacters());
        _contentAssistField.getContentAssistCommandAdapter()
                .setProposalAcceptanceStyle(proposer.getProposalAcceptanceStyle());
        _textControl = (Text) _contentAssistField.getControl();
        swtControl = _contentAssistField.getLayoutControl();
        _contentAssistField.getContentAssistCommandAdapter().addContentProposalListener(this);
    } else {
        swtControl = _textControl = new Text(container, style);
    }
    _textControl.setData(UIField.CADSE_MODEL_KEY, this);
    // swtControl.setData(CADSE_MODEL_KEY, this);
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = hspan - 1;
    swtControl.setLayoutData(gd);

    if (_ic == null) {
        throw new CadseIllegalArgumentException("Cannot create ic for {0}({1})", this,
                getAttributeDefinition());
    }
    _textControl.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            if (!_sendNotification) {
                return;
            }
            _currentValueTextToSend = _textControl.getText();
            if (_currentValueTextToSend.equals("")) {
                _currentValueTextToSend = null;
            }

            _sendNotification = false;
            sendModificationIfNeed(_currentValueTextToSend,
                    (_ic.hasDeleteFunction() && _currentValueTextToSend == null)
                            || _currentValueTextToSend != null);
            if (_currentValueTextToSend == null) {
                setUndefinedValue();
                _textControl.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW));
                _value = null;
                _currentValueText = null;
            } else {
                _textControl.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
            }
            _sendNotification = true;

        }
    });

    _textControl.addKeyListener(new KeyListener() {

        public void keyPressed(KeyEvent e) {
            if (e.character == '\u0008' || e.character == '\u007f') { // 
                if (_ic.hasDeleteFunction() || _currentValueTextToSend == null
                        || "".equals(_currentValueTextToSend)) {
                    _currentValueTextToSend = null;
                    _sendNotification = false;
                    sendModificationIfNeed(_currentValueTextToSend, _ic.hasDeleteFunction());
                    setUndefinedValue();
                    _sendNotification = true;
                    _textControl
                            .setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW));
                    // _textControl.setSelection(0, 0);

                    e.doit = false;
                } else {
                    if (_currentValueTextToSend != null && _currentValueTextToSend.length() == 1) {
                        _sendNotification = false;
                        _currentValueTextToSend = "";
                        _textControl.setText("EMPTY");
                        _sendNotification = true;
                        _textControl.setForeground(
                                Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW));
                        _textControl.setSelection(0, 0);
                        sendModificationIfNeed(_currentValueTextToSend, false);
                        e.doit = false;
                    }
                }
            } else if (e.keyCode == SWT.ARROW_RIGHT || e.keyCode == SWT.ARROW_LEFT) {
                if (_currentValueTextToSend == null || _currentValueTextToSend.length() == 0) {
                    _textControl.setSelection(0, 0);
                    e.doit = false;
                }
            } else if (e.character == '\u001b') { // Escape character

            } else if (e.character == '\n' || e.character == '\r') {
                sendModificationIfNeed(_currentValueTextToSend, true);
            } else {
                if (_currentValueTextToSend == null || _currentValueTextToSend.length() == 0) {
                    _currentValueTextToSend = Character.toString(e.character);
                    _textControl.setText(_currentValueTextToSend);
                    _textControl.setSelection(_currentValueTextToSend.length(),
                            _currentValueTextToSend.length());
                    _textControl.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
                    sendModificationIfNeed(_currentValueTextToSend, false);
                    e.doit = false;
                }
            }
        }

        public void keyReleased(KeyEvent e) {
        }

    });

    _textControl.addFocusListener(new FocusListener() {
        public void focusGained(FocusEvent e) {
        }

        public void focusLost(FocusEvent e) {
            if (_currentValueTextToSend != null) {
                sendModificationIfNeed(_currentValueTextToSend, true);
            }
        }
    });

    _buttonBrowser = new Button(container, SWT.PUSH);
    _buttonBrowser.setText(UIField.SELECT_BUTTON);
    _buttonBrowser.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(@SuppressWarnings("unused") SelectionEvent e) {
            handleSelect();
        }
    });
    _buttonBrowser.setData(UIField.CADSE_MODEL_KEY, this);

    setEditable(_field.isEditable());
}

From source file:org.apache.ivyde.internal.eclipse.ui.IvyFilePathText.java

License:Apache License

protected Text createText(Composite parent) {
    errorDecoration = FieldDecorationRegistry.getDefault()
            .getFieldDecoration(FieldDecorationRegistry.DEC_ERROR);

    ivyFilePathTextDeco = new DecoratedField(this, SWT.LEFT | SWT.TOP, new IControlCreator() {
        public Control createControl(Composite parent, int style) {
            return new Text(parent, SWT.SINGLE | SWT.BORDER);
        }//from w ww . j a v  a  2  s . com
    });
    ivyFilePathTextDeco.addFieldDecoration(errorDecoration, SWT.TOP | SWT.LEFT, false);
    ivyFilePathTextDeco.hideDecoration(errorDecoration);

    ivyFilePathText = (Text) ivyFilePathTextDeco.getControl();
    ivyFilePathTextDeco.getLayoutControl()
            .setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));

    return ivyFilePathText;
}

From source file:org.apache.ivyde.internal.eclipse.ui.SettingsSetupEditor.java

License:Apache License

public SettingsSetupEditor(Composite parent, int style, IProject project) {
    super(parent, style);

    GridLayout layout = new GridLayout();
    setLayout(layout);/* w  w  w.  ja  v a 2 s.  c  o m*/

    loadOnDemandButton = new Button(this, SWT.CHECK);
    loadOnDemandButton.setText("reload the settings only on demand");
    loadOnDemandButton.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));

    settingsEditor = new PathEditor(this, SWT.NONE, "Ivy settings path:", project, "*.xml") {

        protected Text createText(Composite parent) {
            errorDecoration = FieldDecorationRegistry.getDefault()
                    .getFieldDecoration(FieldDecorationRegistry.DEC_ERROR);

            settingsTextDeco = new DecoratedField(parent, SWT.LEFT | SWT.TOP, new IControlCreator() {
                public Control createControl(Composite p, int s) {
                    return new Text(p, SWT.SINGLE | SWT.BORDER);
                }
            });
            settingsTextDeco.addFieldDecoration(errorDecoration, SWT.TOP | SWT.LEFT, false);
            // settingsTextDeco.setMarginWidth(2);
            settingsTextDeco.hideDecoration(errorDecoration);
            // this doesn't work well: we want the decoration image to be clickable, but it
            // actually
            // hides the clickable area
            // settingsTextDeco.getLayoutControl().addMouseListener(new MouseAdapter() {
            // public void mouseDoubleClick(MouseEvent e) {
            // super.mouseDoubleClick(e);
            // }
            // public void mouseDown(MouseEvent e) {
            // if (settingsError != null) {
            // settingsError.show(IStatus.ERROR, "IvyDE configuration problem", null);
            // }
            // }
            // });

            Text settingsText = (Text) settingsTextDeco.getControl();
            settingsText.setToolTipText(TOOLTIP_SETTINGS_PATH);
            settingsTextDeco.getLayoutControl()
                    .setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));

            return settingsText;
        }

        protected boolean addButtons(Composite buttons) {
            defaultButton = new Button(buttons, SWT.NONE);
            defaultButton.setLayoutData(new GridData(GridData.END, GridData.CENTER, true, false));
            defaultButton.setText("Default");
            defaultButton.addSelectionListener(new SelectionAdapter() {
                public void widgetSelected(SelectionEvent e) {
                    getText().setText("");
                }
            });
            return true;
        }

        protected void setFile(String f) {
            try {
                getText().setText(new File(f).toURI().toURL().toExternalForm());
                textUpdated();
            } catch (MalformedURLException ex) {
                // this cannot happen
                IvyPlugin.logError("The file got from the file browser has not a valid URL", ex);
            }
        }

        protected void textUpdated() {
            settingsUpdated();
        }
    };
    settingsEditor.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));

    ivyUserDirEditor = new PathEditor(this, SWT.NONE, "Ivy user dir:", project, null) {
        protected void textUpdated() {
            settingsUpdated();
        }
    };
    ivyUserDirEditor.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));

    propFilesEditor = new FileListEditor(this, SWT.NONE, "Property files:", "Property file:", project,
            "*.properties") {
        protected void fileListUpdated() {
            settingsUpdated();
        }
    };
    propFilesEditor.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
}

From source file:org.talend.camel.designer.generator.RouteComponentController.java

License:Open Source License

@Override
public int estimateRowSize(Composite subComposite, IElementParameter param) {
    final DecoratedField dField = new DecoratedField(subComposite, SWT.BORDER, new IControlCreator() {

        public Control createControl(Composite parent, int style) {
            return getWidgetFactory().createButton(parent, EParameterName.ROUTE_COMPONENT_TYPE.getDisplayName(),
                    SWT.None);/*  w w w.  j a  va 2s  .c o m*/
        }

    });
    Point initialSize = dField.getLayoutControl().computeSize(SWT.DEFAULT, SWT.DEFAULT);
    dField.getLayoutControl().dispose();

    return initialSize.y + ITabbedPropertyConstants.VSPACE;
}

From source file:org.talend.camel.designer.generator.RouteResourceController.java

License:Open Source License

@Override
public int estimateRowSize(Composite subComposite, IElementParameter param) {
    final DecoratedField dField = new DecoratedField(subComposite, SWT.BORDER, new IControlCreator() {

        public Control createControl(Composite parent, int style) {
            return getWidgetFactory().createButton(parent, EParameterName.ROUTE_RESOURCE_TYPE.getDisplayName(),
                    SWT.None);//w  w w. j  a  v a  2  s .c  o m
        }

    });
    Point initialSize = dField.getLayoutControl().computeSize(SWT.DEFAULT, SWT.DEFAULT);
    dField.getLayoutControl().dispose();

    return initialSize.y + ITabbedPropertyConstants.VSPACE;
}

From source file:org.talend.designer.core.ui.editor.properties.controllers.AbstractLanguageMemoController.java

License:Open Source License

@Override
public Control createControl(final Composite subComposite, final IElementParameter param, final int numInRow,
        final int nbInRow, final int top, final Control lastControl) {
    this.curParameter = param;
    this.paramFieldType = param.getFieldType();
    int nbLines = param.getNbLines();
    final String paramName = param.getName();

    Control cLayout;// www. j a  v  a  2  s  . c om
    StyledText text;
    FormData data;
    viewer = null;
    if (param.getNbLines() != 1) {
        if (language.equals("java")) { //$NON-NLS-1$
            String context = param.getContext();
            if (!param.isNoCheck() && context != null
                    && (context.equals("begin") || context.equals("main") || context.equals("end"))) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                Composite a = new Composite(subComposite, SWT.NO_FOCUS);
                a.setLayout(new FormLayout());
                Composite b = new Composite(a, SWT.NO_FOCUS);
                b.setLayout(new GridLayout());
                data = new FormData();
                data.left = new FormAttachment(0, 0);
                data.top = new FormAttachment(0, 0);
                data.right = new FormAttachment(100, 0);
                data.bottom = new FormAttachment(100, 0);

                b.setLayoutData(data);
                Process process = null;
                if (elem instanceof Node) {
                    process = (Process) ((Node) elem).getProcess();
                } else if (elem instanceof Connection) {
                    process = (Process) ((Connection) elem).getSource().getProcess();
                }
                TalendJavaEditor javaEditor = ((AbstractMultiPageTalendEditor) process.getEditor())
                        .getCodeEditor();

                viewer = TalendJavaSourceViewer.createViewerForComponent(b,
                        SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL | SWT.WRAP, javaEditor, null,
                        elem.getElementName(), context);
                text = viewer.getTextWidget();
                IPreferenceStore preferenceStore = CorePlugin.getDefault().getPreferenceStore();
                FontData fontData = PreferenceConverter.getFontData(preferenceStore,
                        TalendDesignerPrefConstants.MEMO_TEXT_FONT);
                Font font = new Font(text.getDisplay(), fontData);
                addResourceDisposeListener(text, font);
                text.setFont(font);

                text.setData(PARAMETER_NAME, param.getName());
                editionControlHelper.register(param.getName(), text);
                cLayout = a;
            } else {
                Composite a = new Composite(subComposite, SWT.NO_FOCUS);
                a.setLayout(new FormLayout());
                Composite b = new Composite(a, SWT.NO_FOCUS);
                b.setLayout(new GridLayout());
                data = new FormData();
                data.left = new FormAttachment(0, 0);
                data.top = new FormAttachment(0, 0);
                data.right = new FormAttachment(100, 0);
                data.bottom = new FormAttachment(100, 0);

                b.setLayoutData(data);

                if (isNeedToAddCodeGenerateButton()) {
                    addCodeGenerateButton(b);
                }

                Process process = null;
                if (elem instanceof Node) {
                    process = (Process) ((Node) elem).getProcess();
                } else if (elem instanceof Connection) {
                    Connection connection = (Connection) elem;
                    process = (Process) connection.getSource().getProcess();
                    // see bug 0001645
                    if (connection.getLineStyle().equals(EConnectionType.RUN_IF)
                            || connection.getLineStyle().equals(EConnectionType.ROUTE_WHEN)
                            || connection.getLineStyle().equals(EConnectionType.ROUTE_CATCH)) {
                        viewer = TalendJavaSourceViewer.createViewerForIfConnection(b);
                    }
                }
                if (viewer == null) {
                    viewer = TalendJavaSourceViewer.createViewer(b,
                            SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL | SWT.WRAP, false);
                }

                text = viewer.getTextWidget();
                IPreferenceStore preferenceStore = CorePlugin.getDefault().getPreferenceStore();
                FontData fontData = PreferenceConverter.getFontData(preferenceStore,
                        TalendDesignerPrefConstants.MEMO_TEXT_FONT);
                Font font = new Font(text.getDisplay(), fontData);
                addResourceDisposeListener(text, font);
                text.setFont(font);
                text.setData(PARAMETER_NAME, param.getName());
                editionControlHelper.register(param.getName(), text);
                cLayout = a;
            }
        } else {
            Composite a = new Composite(subComposite, SWT.NO_FOCUS);
            a.setLayout(new FormLayout());
            Composite b = new Composite(a, SWT.NO_FOCUS);
            b.setLayout(new GridLayout());
            data = new FormData();
            data.left = new FormAttachment(0, 0);
            data.top = new FormAttachment(0, 0);
            data.right = new FormAttachment(100, 0);
            data.bottom = new FormAttachment(100, 0);

            b.setLayoutData(data);

            if (isNeedToAddCodeGenerateButton()) {
                addCodeGenerateButton(b);
            }
            text = viewer.getTextWidget();
            IPreferenceStore preferenceStore = CorePlugin.getDefault().getPreferenceStore();
            FontData fontData = PreferenceConverter.getFontData(preferenceStore,
                    TalendDesignerPrefConstants.MEMO_TEXT_FONT);
            Font font = new Font(text.getDisplay(), fontData);
            addResourceDisposeListener(text, font);
            text.setFont(font);

            Process process = null;

            if (elem instanceof Node) {
                process = (Process) ((Node) elem).getProcess();
            } else if (elem instanceof Connection) {
                process = (Process) ((Connection) elem).getSource().getProcess();
            }
            text.setData(PARAMETER_NAME, param.getName());
            editionControlHelper.register(param.getName(), text);
            cLayout = a;
        }
    } else {
        IControlCreator txtCtrl = new IControlCreator() {

            @Override
            public Control createControl(final Composite parent, final int style) {
                final StyledText control = new ColorStyledText(parent, style,
                        CorePlugin.getDefault().getPreferenceStore(), language);
                Display display = Display.getCurrent();
                if (display == null) {
                    display = Display.getDefault();
                }
                if (display != null) {
                    display.syncExec(new Runnable() {

                        @Override
                        public void run() {
                            IPreferenceStore preferenceStore = CorePlugin.getDefault().getPreferenceStore();
                            FontData fontData = PreferenceConverter.getFontData(preferenceStore,
                                    TalendDesignerPrefConstants.MEMO_TEXT_FONT);
                            Font font = new Font(parent.getDisplay(), fontData);
                            addResourceDisposeListener(control, font);
                            control.setFont(font);
                        }
                    });
                }

                return control;
            }
        };
        DecoratedField dField = null;
        dField = new DecoratedField(subComposite, SWT.BORDER | SWT.WRAP, txtCtrl);
        cLayout = dField.getLayoutControl();
        text = (StyledText) dField.getControl();
        data = (FormData) text.getLayoutData();
        editionControlHelper.register(param.getName(), text);
        if (param.isRequired()) {
            FieldDecoration decoration = FieldDecorationRegistry.getDefault()
                    .getFieldDecoration(FieldDecorationRegistry.DEC_REQUIRED);
            dField.addFieldDecoration(decoration, SWT.RIGHT | SWT.TOP, false);
        }
    }

    if (getAdditionalHeightSize() != 0) {
        nbLines += this.getAdditionalHeightSize() / text.getLineHeight();
    }
    data.height = text.getLineHeight() * nbLines;
    text.getParent().setSize(subComposite.getSize().x, text.getLineHeight() * nbLines);
    cLayout.setBackground(subComposite.getBackground());
    // for bug 7580
    if (!(text instanceof ReconcilerStyledText)) {
        text.setEnabled(!param.isReadOnly());
    } else {
        text.setEditable(!param.isReadOnly());
    }
    if (elem instanceof Node) {
        text.setToolTipText(VARIABLE_TOOLTIP + param.getVariableName());
    }

    addDragAndDropTarget(text);

    // IDocument document = viewer.getDocument();
    // if (document != null) {
    // Process pro = null;
    // if (elem instanceof Node) {
    // pro = (Process) ((Node) elem).getProcess();
    // } else if (elem instanceof Connection) {
    // pro = (Process) ((Connection) elem).getSource().getProcess();
    // }
    // final Process process = pro;
    // document.addDocumentListener(new IDocumentListener() {
    //
    // public void documentChanged(DocumentEvent event) {
    // if (!process.isReadOnly())
    // ContextParameterExtractor.saveContext(paramName, elem, viewer.getTextWidget().getText(), process);
    // }
    //
    // public void documentAboutToBeChanged(DocumentEvent event) {
    // // nothing to do
    // }
    // });
    //
    // }

    CLabel labelLabel = getWidgetFactory().createCLabel(subComposite, param.getDisplayName());
    data = new FormData();
    if (lastControl != null) {
        data.left = new FormAttachment(lastControl, 0);
    } else {
        data.left = new FormAttachment((((numInRow - 1) * MAX_PERCENT) / nbInRow), 0);
    }
    data.top = new FormAttachment(0, top);
    labelLabel.setLayoutData(data);
    if (numInRow != 1) {
        labelLabel.setAlignment(SWT.RIGHT);
    }
    // *********************
    data = new FormData();
    int currentLabelWidth = STANDARD_LABEL_WIDTH;
    GC gc = new GC(labelLabel);
    Point labelSize = gc.stringExtent(param.getDisplayName());
    gc.dispose();

    if ((labelSize.x + ITabbedPropertyConstants.HSPACE) > currentLabelWidth) {
        currentLabelWidth = labelSize.x + ITabbedPropertyConstants.HSPACE;
    }

    if (numInRow == 1) {
        if (lastControl != null) {
            data.left = new FormAttachment(lastControl, currentLabelWidth);
        } else {
            data.left = new FormAttachment(0, currentLabelWidth);
        }

    } else {
        data.left = new FormAttachment(labelLabel, 0, SWT.RIGHT);
    }
    data.right = new FormAttachment((numInRow * MAX_PERCENT) / nbInRow, 0);
    data.top = new FormAttachment(0, top);
    cLayout.setLayoutData(data);
    // **********************

    hashCurControls.put(param.getName(), text);

    Point initialSize = cLayout.computeSize(SWT.DEFAULT, SWT.DEFAULT);

    dynamicProperty.setCurRowSize(initialSize.y + ITabbedPropertyConstants.VSPACE);
    return null;
}

From source file:org.talend.designer.core.ui.editor.properties.controllers.AbstractLanguageMemoController.java

License:Open Source License

@Override
public int estimateRowSize(Composite subComposite, IElementParameter param) {
    if (!estimateInitialized) {
        IControlCreator txtCtrl = new IControlCreator() {

            @Override/*w w  w .  j  a v  a 2 s.  c o  m*/
            public Control createControl(final Composite parent, final int style) {
                final ColorStyledText colorText = new ColorStyledText(parent, style,
                        CorePlugin.getDefault().getPreferenceStore(), language);
                Display display = Display.getCurrent();
                if (display == null) {
                    display = Display.getDefault();
                }
                if (display != null) {
                    display.syncExec(new Runnable() {

                        @Override
                        public void run() {
                            IPreferenceStore preferenceStore = CorePlugin.getDefault().getPreferenceStore();
                            String fontType = preferenceStore
                                    .getString(TalendDesignerPrefConstants.MEMO_TEXT_FONT);
                            FontData fontData = new FontData(fontType);
                            Font font = new Font(parent.getDisplay(), fontData);
                            addResourceDisposeListener(colorText, font);
                            colorText.setFont(font);
                        }
                    });
                }
                return colorText;
            }
        };

        DecoratedField dField = null;
        if (param.getNbLines() != 1) {
            dField = new DecoratedField(subComposite,
                    SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL | SWT.WRAP, txtCtrl);
        } else {
            dField = new DecoratedField(subComposite, SWT.BORDER | SWT.WRAP, txtCtrl);
        }

        StyledText text = (StyledText) dField.getControl();
        FormData d = (FormData) text.getLayoutData();
        d.height = text.getLineHeight();
        text.getParent().setSize(subComposite.getSize().x, text.getLineHeight());
        rowSizeByLine = text.getLineHeight();
        Point initialSize = dField.getLayoutControl().computeSize(SWT.DEFAULT, SWT.DEFAULT);
        dField.getLayoutControl().dispose();
        rowSizeFixed = ITabbedPropertyConstants.VSPACE + (initialSize.y - rowSizeByLine);
        estimateInitialized = true;
    }

    return rowSizeFixed + (rowSizeByLine * param.getNbLines());
}

From source file:org.talend.designer.core.ui.editor.properties.controllers.AS400CheckController.java

License:Open Source License

@Override
public Control createControl(final Composite subComposite, final IElementParameter param, final int numInRow,
        final int nbInRow, final int top, final Control lastControl) {
    final DecoratedField dField = new DecoratedField(subComposite, SWT.BORDER, new IControlCreator() {

        @Override//www .  j  a v  a  2 s  .  c o m
        public Control createControl(Composite parent, int style) {
            return getWidgetFactory().createButton(parent, param.getDisplayName(), SWT.CHECK);
        }

    });
    if (param.isRepositoryValueUsed()) {
        FieldDecoration decoration = FieldDecorationRegistry.getDefault()
                .getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL);
        decoration.setDescription(Messages.getString("CheckController.decoration.description")); //$NON-NLS-1$
        dField.addFieldDecoration(decoration, SWT.RIGHT | SWT.BOTTOM, false);
    }

    Control cLayout = dField.getLayoutControl();
    cLayout.setBackground(subComposite.getBackground());
    Button checkBtn = (Button) dField.getControl();

    FormData data = new FormData();
    data.top = new FormAttachment(0, top);
    if (lastControl != null) {
        data.left = new FormAttachment(lastControl, 0);
    } else {
        data.left = new FormAttachment((((numInRow - 1) * MAX_PERCENT) / nbInRow), 0);
    }
    cLayout.setLayoutData(data);
    hashCurControls.put(param.getName(), checkBtn);
    checkBtn.setEnabled(!param.isReadOnly());
    String propertyType = (String) elem.getPropertyValue(EParameterName.PROPERTY_TYPE.getName());
    if (propertyType.equals(EmfComponent.REPOSITORY)) {
        IProxyRepositoryFactory factory = DesignerPlugin.getDefault().getProxyRepositoryFactory();
        List<ConnectionItem> metadataConnectionsItem = null;
        try {
            metadataConnectionsItem = factory.getMetadataConnectionsItem();

        } catch (PersistenceException e) {
            throw new RuntimeException(e);
        }
        if (metadataConnectionsItem != null) {
            for (ConnectionItem connectionItem : metadataConnectionsItem) {
                String value = connectionItem.getProperty().getId() + ""; //$NON-NLS-1$
                if (value.equals(elem.getPropertyValue(EParameterName.REPOSITORY_PROPERTY_TYPE.getName()))) {
                    boolean b = getConnection(connectionItem).isStandardSQL();
                    checkBtn.setSelection(b);
                }
            }
        }
    } else {
        boolean b = CoreUIPlugin.getDefault().getPreferenceStore()
                .getBoolean(ITalendCorePrefConstants.AS400_SQL_SEG);
        checkBtn.setSelection(b);
    }

    if (elem instanceof Node) {
        checkBtn.setToolTipText(VARIABLE_TOOLTIP + param.getVariableName());
    }

    Point initialSize = checkBtn.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    dynamicProperty.setCurRowSize(initialSize.y + ITabbedPropertyConstants.VSPACE);
    return cLayout;
}

From source file:org.talend.designer.core.ui.editor.properties.controllers.AS400CheckController.java

License:Open Source License

@Override
public int estimateRowSize(Composite subComposite, final IElementParameter param) {
    // TODO Auto-generated method stub
    final DecoratedField dField = new DecoratedField(subComposite, SWT.BORDER, new IControlCreator() {

        @Override/*from w  w  w  .  j a  v a  2  s. c om*/
        public Control createControl(Composite parent, int style) {
            return getWidgetFactory().createButton(parent, param.getDisplayName(), SWT.CHECK);
        }

    });
    Point initialSize = dField.getLayoutControl().computeSize(SWT.DEFAULT, SWT.DEFAULT);
    dField.getLayoutControl().dispose();

    return initialSize.y + ITabbedPropertyConstants.VSPACE;
}

From source file:org.talend.designer.core.ui.editor.properties.controllers.CheckController.java

License:Open Source License

@Override
public Control createControl(final Composite subComposite, final IElementParameter param, final int numInRow,
        final int nbInRow, final int top, final Control lastControl) {
    final DecoratedField dField = new DecoratedField(subComposite, SWT.BORDER, new IControlCreator() {

        @Override/*from ww  w. j  a v  a 2  s . c o m*/
        public Control createControl(Composite parent, int style) {
            return getWidgetFactory().createButton(parent, param.getDisplayName(), SWT.CHECK);
        }

    });
    if (param.isRepositoryValueUsed()) {
        FieldDecoration decoration = FieldDecorationRegistry.getDefault()
                .getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL);
        decoration.setDescription(Messages.getString("CheckController.decoration.description")); //$NON-NLS-1$
        dField.addFieldDecoration(decoration, SWT.RIGHT | SWT.BOTTOM, false);
    }

    Control cLayout = dField.getLayoutControl();
    cLayout.setBackground(subComposite.getBackground());
    Button checkBtn = (Button) dField.getControl();
    checkBtn.setBackground(subComposite.getBackground());

    FormData data = new FormData();
    data.top = new FormAttachment(0, top);
    if (lastControl != null) {
        data.left = new FormAttachment(lastControl, 0);
    } else {
        data.left = new FormAttachment((((numInRow - 1) * MAX_PERCENT) / nbInRow), 0);
    }
    cLayout.setLayoutData(data);
    checkBtn.setData(PARAMETER_NAME, param.getName());
    hashCurControls.put(param.getName(), checkBtn);
    checkBtn.setEnabled(!param.isReadOnly() && !param.isRepositoryValueUsed());
    checkBtn.addSelectionListener(listenerSelection);
    if (elem instanceof Node) {
        checkBtn.setToolTipText(VARIABLE_TOOLTIP + param.getVariableName());
    }

    Point initialSize = checkBtn.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    dynamicProperty.setCurRowSize(initialSize.y + ITabbedPropertyConstants.VSPACE);
    return cLayout;
}