Example usage for org.eclipse.jface.fieldassist FieldDecorationRegistry DEC_REQUIRED

List of usage examples for org.eclipse.jface.fieldassist FieldDecorationRegistry DEC_REQUIRED

Introduction

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

Prototype

String DEC_REQUIRED

To view the source code for org.eclipse.jface.fieldassist FieldDecorationRegistry DEC_REQUIRED.

Click Source Link

Document

Decoration id for the decoration that should be used to cue the user that a field is required.

Usage

From source file:com.netxforge.screens.editing.base.util.DecorationService.java

License:Open Source License

public ControlDecoration getRequiredDecoration(Control control) {
    ControlDecoration deco = new ControlDecoration(control, SWT.LEFT | SWT.CENTER);
    FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault()
            .getFieldDecoration(FieldDecorationRegistry.DEC_REQUIRED);
    deco.setImage(fieldDecoration.getImage());
    deco.hide();//from w  w w.  ja  v  a2s.  com
    return deco;
}

From source file:com.nokia.tools.variant.common.ui.wizards.dialogfields.DialogField.java

License:Open Source License

protected FieldDecoration getRequiredFieldDecoration() {
    if (requiredFieldDecoration == null) {
        requiredFieldDecoration = FieldDecorationRegistry.getDefault()
                .getFieldDecoration(FieldDecorationRegistry.DEC_REQUIRED);
    }//from  w w  w  . j  ava 2  s  .c  o  m
    return requiredFieldDecoration;
}

From source file:com.teamcenter.hendrickson.schmgr.operations.Validator.java

License:MIT License

Image getFieldDecorationImage(String type) {

    String Icontype = FieldDecorationRegistry.DEC_INFORMATION;

    if (type.equals("error")) {

        Icontype = FieldDecorationRegistry.DEC_ERROR;

    } else if (type.equals("warn")) {

        Icontype = FieldDecorationRegistry.DEC_WARNING;

    } else if (type.equals("required")) {

        Icontype = FieldDecorationRegistry.DEC_REQUIRED;

    } else if (type.equals("content")) {

        Icontype = FieldDecorationRegistry.DEC_CONTENT_PROPOSAL;

    } else if (type.equals("quickfix")) {

        Icontype = FieldDecorationRegistry.DEC_ERROR_QUICKFIX;

    } else {//  ww w.j a  va2  s . c  o m

        Icontype = FieldDecorationRegistry.DEC_INFORMATION;

    }

    Image image = FieldDecorationRegistry.getDefault().getFieldDecoration(Icontype).getImage();

    if (type.equals("correct"))
        return image = ResourceManager.getPluginImage("example", "icons/tick.png");
    else
        return image;
}

From source file:eu.esdihumboldt.hale.ui.function.generic.pages.internal.Field.java

License:Open Source License

/**
 * Create a field/*from w  w w.j  a va 2s  .c  o  m*/
 * 
 * @param definition the field definition
 * @param ssid the schema space
 * @param parent the parent composite
 * @param candidates the entity candidates
 * @param initialCell the initial cell
 */
public Field(F definition, SchemaSpaceID ssid, final Composite parent, Set<EntityDefinition> candidates,
        Cell initialCell) {
    super();

    this.definition = definition;
    this.ssid = ssid;

    ControlDecoration descriptionDecoration = null;

    // field name
    if (!definition.getDisplayName().isEmpty()) {
        Label name = new Label(parent, SWT.NONE);
        name.setText(definition.getDisplayName());
        name.setLayoutData(GridDataFactory.swtDefaults().create());

        if (definition.getDescription() != null) {
            // add decoration
            descriptionDecoration = new ControlDecoration(name, SWT.RIGHT, parent);
        }
    }

    selectorContainer = new Composite(parent, SWT.NONE);
    selectorContainer.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    // left margin 6 pixels for ControlDecorations to have place within this
    // component
    // so they're not drawn outside of the ScrolledComposite in case it's
    // present.
    selectorContainer.setLayout(GridLayoutFactory.fillDefaults().extendedMargins(6, 0, 0, 0).create());

    selectionChangedListener = new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            int changedIndex = selectors.indexOf(event.getSelectionProvider());
            S changedSelector = selectors.get(changedIndex);

            // add/remove selector
            // check whether all selectors are valid (so must the changed
            // one be)
            if (countValidEntities() == selectors.size()) {
                // maybe last invalid entity was set, check whether to add
                // another one
                if (Field.this.definition.getMaxOccurrence() != selectors.size()) {
                    S newSelector = createEntitySelector(Field.this.ssid, Field.this.definition,
                            selectorContainer);
                    newSelector.getControl().setLayoutData(GridDataFactory.swtDefaults()
                            .align(SWT.FILL, SWT.CENTER).grab(true, false).create());
                    addSelector(newSelector);

                    // layout new selector in scrolled pane
                    selectorContainer.getParent().getParent().layout();
                }
            } else {
                // check whether a field was set to None and remove the
                // field if it isn't the last one and minOccurrence is still
                // met
                if (event.getSelection().isEmpty() && changedIndex != selectors.size() - 1
                        && Field.this.definition.getMinOccurrence() < selectors.size()) {
                    // check whether first selector will be removed and it
                    // had the fields description
                    boolean createDescriptionDecoration = changedIndex == 0
                            && Field.this.definition.getDisplayName().isEmpty()
                            && !Field.this.definition.getDescription().isEmpty();
                    removeSelector(changedSelector);

                    // add new description decoration if necessary
                    if (createDescriptionDecoration) {
                        ControlDecoration descriptionDecoration = new ControlDecoration(
                                selectors.get(0).getControl(), SWT.RIGHT | SWT.TOP, parent);
                        descriptionDecoration.setDescriptionText(Field.this.definition.getDescription());
                        FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault()
                                .getFieldDecoration(FieldDecorationRegistry.DEC_INFORMATION);
                        descriptionDecoration.setImage(fieldDecoration.getImage());
                        descriptionDecoration.setMarginWidth(2);
                    }

                    // necessary layout call for control decoration to
                    // appear at the correct place
                    selectorContainer.getParent().getParent().layout();

                    // add mandatory decoration to next selector if needed
                    if (changedIndex < Field.this.definition.getMinOccurrence()) {
                        S newMandatorySelector = selectors.get(Field.this.definition.getMinOccurrence() - 1);

                        ControlDecoration mandatory = new ControlDecoration(newMandatorySelector.getControl(),
                                SWT.LEFT | SWT.TOP, parent);
                        FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault()
                                .getFieldDecoration(FieldDecorationRegistry.DEC_REQUIRED);
                        mandatory.setImage(CommonSharedImages.getImageRegistry()
                                .get(CommonSharedImages.IMG_DECORATION_MANDATORY));
                        mandatory.setDescriptionText(fieldDecoration.getDescription());
                    }
                }
            }

            // update state
            updateState();
        }
    };

    // determine number of contained fields and the corresponding values
    int initialFieldCount = definition.getMinOccurrence();

    // TODO determine filters from definition

    List<EntityDefinition> fieldValues = new ArrayList<EntityDefinition>();
    if (initialCell != null) {
        // entities from cell
        List<? extends Entity> entities = null;
        switch (ssid) {
        case SOURCE:
            if (initialCell.getSource() != null) {
                entities = initialCell.getSource().get(definition.getName());
            }
            break;
        case TARGET:
            if (initialCell.getTarget() != null) {
                entities = initialCell.getTarget().get(definition.getName());
            }
            break;
        default:
            throw new IllegalStateException("Illegal schema space");
        }
        if (entities != null) {
            for (Entity entity : entities) {
                fieldValues.add(entity.getDefinition()); // FIXME what about
                // the
                // information
                // in the
                // entity?!
            }
        }
    } else if (candidates != null && !candidates.isEmpty()) {
        // populate from candidates
        LinkedHashSet<EntityDefinition> rotatingCandidates = new LinkedHashSet<EntityDefinition>(candidates);

        // try to add candidates for each required entity
        int limit = Math.max(initialFieldCount, candidates.size());
        for (int i = 0; i < limit; i++) {
            boolean found = false;
            for (EntityDefinition candidate : rotatingCandidates) {
                // XXX checked against filters later, because here filters
                // aren't present yet.
                // if (true) {
                fieldValues.add(candidate);
                rotatingCandidates.remove(candidate);
                rotatingCandidates.add(candidate);
                found = true;
                break;
                // }
            }
            if (!found) {
                fieldValues.add(null);
            }
        }
    }

    // adapt initialFieldCount if needed (and possible)
    if (fieldValues.size() >= initialFieldCount) {
        initialFieldCount = fieldValues.size() + 1;
        if (definition.getMaxOccurrence() != F.UNBOUNDED) {
            initialFieldCount = Math.min(initialFieldCount, definition.getMaxOccurrence());
        }
    }

    // add fields
    for (int num = 0; num < initialFieldCount; num++) {
        // create entity selector
        S selector = createEntitySelector(ssid, definition, selectorContainer);
        selector.getControl().setLayoutData(
                GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).create());

        // do initial selection (before adding it to not trigger selection
        // event)
        EntityDefinition value = (num < fieldValues.size()) ? (fieldValues.get(num)) : (null);
        if (value == null || !selector.accepts(value))
            selector.setSelection(new StructuredSelection());
        else
            selector.setSelection(new StructuredSelection(value));

        // add the selector now
        addSelector(selector);

        // add decorations
        if (num < definition.getMinOccurrence()) {
            ControlDecoration mandatory = new ControlDecoration(selector.getControl(), SWT.LEFT | SWT.TOP,
                    parent);
            FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault()
                    .getFieldDecoration(FieldDecorationRegistry.DEC_REQUIRED);
            mandatory.setImage(
                    CommonSharedImages.getImageRegistry().get(CommonSharedImages.IMG_DECORATION_MANDATORY));
            mandatory.setDescriptionText(fieldDecoration.getDescription());
        }

        if (descriptionDecoration == null && definition.getDescription() != null)
            descriptionDecoration = new ControlDecoration(selector.getControl(), SWT.RIGHT | SWT.TOP, parent);
    }

    // setup description decoration
    if (descriptionDecoration != null) {
        descriptionDecoration.setDescriptionText(definition.getDescription());
        FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault()
                .getFieldDecoration(FieldDecorationRegistry.DEC_INFORMATION);
        descriptionDecoration.setImage(fieldDecoration.getImage());
        descriptionDecoration.setMarginWidth(2);
    }

    updateState();
}

From source file:net.refractions.udig.ui.filter.IExpressionViewer.java

License:Open Source License

/**
 * Provide required feedback./*from   w  ww  . j  a  va  2 s .c  o  m*/
 * <p>
 * This method will make use of an associated ControlDecoration if available.
 * </p>
 */
protected void feedback(String warning, boolean isRequired) {
    if (isRequired) {
        if (input != null && input.getFeedback() != null) {
            ControlDecoration feedback = input.getFeedback();

            feedback.setDescriptionText(warning);

            FieldDecorationRegistry decorations = FieldDecorationRegistry.getDefault();
            if (isRequired) {
                FieldDecoration requiredDecoration = decorations
                        .getFieldDecoration(FieldDecorationRegistry.DEC_REQUIRED);
                feedback.setImage(requiredDecoration.getImage());
            } else {
                FieldDecoration warningDecoration = decorations
                        .getFieldDecoration(FieldDecorationRegistry.DEC_WARNING);
                feedback.setImage(warningDecoration.getImage());
            }
            feedback.show();
        }
        Control control = getControl();
        if (control != null && !control.isDisposed()) {
            control.setToolTipText(warning);
        }
    } else {
        feedback(warning);
    }
}

From source file:org.bbaw.pdr.ae.view.control.customSWTWidges.DefinedRelationEditorLine.java

License:Open Source License

private void loadRelation() {

    if (_relation != null && _relation.getObject() != null) {
        PdrObject o = _facade.getPdrObject(_relation.getObject());
        if (o != null) {
            _personText.setText(o.getDisplayName());
        } else {//w  ww .  j a  va 2  s  .  c om
            _personText.setText(_relation.getObject().toString());
            _decoPersonId.setImage(FieldDecorationRegistry.getDefault()
                    .getFieldDecoration(FieldDecorationRegistry.DEC_ERROR).getImage());
            _decoPersonId.setDescriptionText(NLMessages.getString("Editor_missing_object_no_relation"));
        }
    }

    else {
        _personText.setText("");
        _decoPersonId.setImage(FieldDecorationRegistry.getDefault()
                .getFieldDecoration(FieldDecorationRegistry.DEC_REQUIRED).getImage());
    }

    // context, class

    _composite.redraw();
    _composite.layout();
    _composite.update();
}

From source file:org.bbaw.pdr.ae.view.control.customSWTWidges.RelationEditorLine2.java

License:Open Source License

private void loadRelation() {

    if (_relation != null && _relation.getObject() != null) {
        PdrObject o = _facade.getPdrObject(_relation.getObject());
        if (o != null) {
            _personText.setText(o.getDisplayName());
        } else {//from w  w w.j  a va2  s .c o m
            _personText.setText(_relation.getObject().toString());
            _decoPersonId.setImage(FieldDecorationRegistry.getDefault()
                    .getFieldDecoration(FieldDecorationRegistry.DEC_ERROR).getImage());
            _decoPersonId.setDescriptionText(NLMessages.getString("Editor_missing_object_no_relation"));
        }
    }

    else {
        _personText.setText("");
        _decoPersonId.setImage(FieldDecorationRegistry.getDefault()
                .getFieldDecoration(FieldDecorationRegistry.DEC_REQUIRED).getImage());
    }

    // context, class

    if (_relation != null && _facade.getConfigs().get(_relation.getProvider()) != null) {
        _relationContextComboViewer.setInput(_facade.getConfigs().get(_relation.getProvider()).getChildren()
                .get("aodl:relation").getChildren());
    }
    if (_relation != null && _relation.getContext() != null) {
        setComboViewerByString(_relationContextComboViewer, _relation.getContext());
    }
    if (_relation != null && _relation.getRClass() != null) {
        if (_relation.getContext() != null && _facade.getConfigs().get(_relation.getProvider()) != null
                && _facade.getConfigs().get(_relation.getProvider()).getChildren().get("aodl:relation") != null
                && _facade.getConfigs().get(_relation.getProvider()).getChildren().get("aodl:relation")
                        .getChildren().get(_relation.getContext()) != null) {
            _relationClassComboViewer.setInput(_facade.getConfigs().get(_relation.getProvider()).getChildren()
                    .get("aodl:relation").getChildren().get(_relation.getContext()).getChildren());
        }
        setComboViewerByString(_relationClassComboViewer, _relation.getRClass());
    } else {
        _relationClassComboViewer.setInput(null);
        _relationClassComboViewer.refresh();
    }
    _relationClassCombo.layout();
    if (_relation != null && _relation.getRelation() != null) {
        if (_relation.getRClass() != null && _facade.getConfigs().get(_relation.getProvider()) != null
                && _facade.getConfigs().get(_relation.getProvider()).getChildren().get("aodl:relation") != null
                && _facade.getConfigs().get(_relation.getProvider()).getChildren().get("aodl:relation")
                        .getChildren().get(_relation.getContext()) != null
                && _facade.getConfigs().get(_relation.getProvider()).getChildren().get("aodl:relation")
                        .getChildren().get(_relation.getContext()).getChildren()
                        .get(_relation.getRClass()) != null) {
            _relValueComboViewer.setInput(_facade.getConfigs().get(_relation.getProvider()).getChildren()
                    .get("aodl:relation").getChildren().get(_relation.getContext()).getChildren()
                    .get(_relation.getRClass()).getChildren());
        }
        setComboViewerByString(_relValueComboViewer, _relation.getRelation());
    } else {
        _relValueComboViewer.setInput(null);
        _relValueComboViewer.refresh();
    }
    _composite.redraw();
    _composite.layout();
    _composite.update();
}

From source file:org.bbaw.pdr.ae.view.control.customSWTWidges.TimeStmEditorLine.java

License:Open Source License

private void createEditor() {
    this.setLayout(new GridLayout(1, false));
    ((GridLayout) this.getLayout()).marginHeight = 0;
    ((GridLayout) this.getLayout()).verticalSpacing = 0;

    FocusListener focusListener = new FocusListener() {

        @Override//w  w  w. j a v  a  2  s. c  om
        public void focusGained(final FocusEvent e) {
            Event ee = new Event();
            ee.widget = TimeStmEditorLine.this;
            SelectionEvent se = new SelectionEvent(ee);
            for (SelectionListener s : _selectionListener) {
                s.widgetSelected(se);
            }

        }

        @Override
        public void focusLost(final FocusEvent e) {

        }
    };

    _composite = new Composite(this, SWT.NONE);
    _composite.setLayoutData(new GridData());
    ((GridData) _composite.getLayoutData()).horizontalAlignment = SWT.FILL;
    ((GridData) _composite.getLayoutData()).grabExcessHorizontalSpace = true;
    _composite.setLayout(new GridLayout(12, false));
    ((GridLayout) _composite.getLayout()).marginHeight = 0;
    ((GridLayout) _composite.getLayout()).verticalSpacing = 0;

    _dateFromLabel = new Button(_composite, SWT.CHECK);
    _dateFromLabel.setText(NLMessages.getString("Editor_timeStm_date_from"));
    _dateFromLabel.setLayoutData(new GridData());
    ((GridData) _dateFromLabel.getLayoutData()).horizontalSpan = 1;
    ((GridData) _dateFromLabel.getLayoutData()).horizontalAlignment = SWT.RIGHT;
    _dateFromLabel.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            _customSetTime = !_customSetTime;
            setActivateTime(_customSetTime);

            contentChanged();
        }
    });

    _comboDayFrom = new Combo(_composite, SWT.READ_ONLY);
    _comboDayFrom.setLayoutData(new GridData());
    _comboDayFrom.setItems(AEConstants.DAYS);
    _comboDayFrom.addFocusListener(focusListener);

    _comboDayFrom.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(final SelectionEvent se) {
            _timeFrom.getTimeStamp().setDay(_comboDayFrom.getSelectionIndex());
            contentChanged();
        }
    });

    _comboMonthFrom = new Combo(_composite, SWT.READ_ONLY);
    _comboMonthFrom.setLayoutData(new GridData());
    ((GridData) _comboMonthFrom.getLayoutData()).horizontalAlignment = GridData.FILL;
    ((GridData) _comboMonthFrom.getLayoutData()).grabExcessHorizontalSpace = true;
    _comboMonthFrom.setItems(AEConstants.MONTHS);
    _comboMonthFrom.addFocusListener(focusListener);

    _comboMonthFrom.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(final SelectionEvent se) {
            _timeFrom.getTimeStamp().setMonth(_comboMonthFrom.getSelectionIndex());
            contentChanged();
        }
    });

    _spinnerYearFrom = new YearSpinner(_composite, SWT.BORDER);
    _spinnerYearFrom.addFocusListener(focusListener);

    _decoTimeFrom = new ControlDecoration(_spinnerYearFrom, SWT.LEFT | SWT.TOP);

    _spinnerYearFrom.pack();
    _spinnerYearFrom.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(final SelectionEvent se) {
            _timeFrom.getTimeStamp().setYear(_spinnerYearFrom.getSelection());
            if (_timeFrom.isValid()) {
                _decoTimeFrom.setImage(null);
            } else {
                _decoTimeFrom.setImage(FieldDecorationRegistry.getDefault()
                        .getFieldDecoration(FieldDecorationRegistry.DEC_ERROR).getImage());
            }
            contentChanged();
        }
    });

    _dateToButton = new Button(_composite, SWT.CHECK);
    _dateToButton.setText(NLMessages.getString("Editor_timeStm_date_to"));
    _dateToButton.setLayoutData(new GridData());
    ((GridData) _dateToButton.getLayoutData()).horizontalSpan = 1;
    ((GridData) _dateToButton.getLayoutData()).horizontalAlignment = SWT.RIGHT;
    _dateToButton.addFocusListener(focusListener);

    _dateToButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            _pointOfTime = !_pointOfTime;
            setPointOfTiem(_pointOfTime);
            contentChanged();
        }
    });

    _comboDayTo = new Combo(_composite, SWT.READ_ONLY);
    _comboDayTo.setLayoutData(new GridData());
    ((GridData) _comboDayTo.getLayoutData()).horizontalAlignment = GridData.FILL;
    ((GridData) _comboDayTo.getLayoutData()).grabExcessHorizontalSpace = true;
    _comboDayTo.setItems(AEConstants.DAYS);
    _comboDayTo.addFocusListener(focusListener);

    _comboDayTo.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(final SelectionEvent se) {
            _timeTo.getTimeStamp().setDay(_comboDayTo.getSelectionIndex());
            contentChanged();
        }
    });

    _comboMonthTo = new Combo(_composite, SWT.READ_ONLY);
    _comboMonthTo.setLayoutData(new GridData());
    ((GridData) _comboMonthTo.getLayoutData()).horizontalAlignment = GridData.FILL;
    ((GridData) _comboMonthTo.getLayoutData()).grabExcessHorizontalSpace = true;
    _comboMonthTo.setItems(AEConstants.MONTHS);
    _comboMonthTo.addFocusListener(focusListener);

    _comboMonthTo.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(final SelectionEvent se) {
            _timeTo.getTimeStamp().setMonth(_comboMonthTo.getSelectionIndex());
            contentChanged();
        }
    });

    _spinnerYearTo = new YearSpinner(_composite, SWT.BORDER);
    _spinnerYearTo.addFocusListener(focusListener);

    _decoTimeTo = new ControlDecoration(_spinnerYearTo, SWT.LEFT | SWT.TOP);
    if (_timeTo.getTimeStamp() != null) {
        _spinnerYearTo.setSelection(_timeTo.getTimeStamp().getYear());
    } else {
        _decoTimeTo.setImage(FieldDecorationRegistry.getDefault()
                .getFieldDecoration(FieldDecorationRegistry.DEC_REQUIRED).getImage());
    }
    _spinnerYearTo.pack();
    _spinnerYearTo.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(final SelectionEvent se) {
            _timeTo.getTimeStamp().setYear(_spinnerYearTo.getSelection());
            if (_timeTo.isValid()) {
                _decoTimeTo.setImage(null);
            } else {
                _decoTimeTo.setImage(FieldDecorationRegistry.getDefault()
                        .getFieldDecoration(FieldDecorationRegistry.DEC_ERROR).getImage());
            }
            contentChanged();
        }
    });

}

From source file:org.bbaw.pdr.ae.view.control.customSWTWidges.ValidationEditorLine.java

License:Open Source License

private void loadValidation() {
    if (_validationStm.getReference() != null) {
        if (_validationStm.getReference().getSourceId() != null) {
            PdrObject o = _facade.getPdrObject(_validationStm.getReference().getSourceId());
            if (o != null) {
                _sourceText.setText(o.getDisplayName());
                _decoValId.setImage(null);
            } else {
                _sourceText.setText(_validationStm.getReference().getSourceId().toString());
                _decoValId.setImage(FieldDecorationRegistry.getDefault()
                        .getFieldDecoration(FieldDecorationRegistry.DEC_ERROR).getImage());
                _decoValId.setDescriptionText(NLMessages.getString("Editor_missing_object_no_relation"));
            }/*from   w  ww.  j  ava2  s  . c om*/
        }
        if (_validationStm.getReference().getInternal() != null) {
            _sourcePageText.setText(_validationStm.getReference().getInternal());
        }
    } else {
        _sourceText.setText("");
        _decoValId.setImage(FieldDecorationRegistry.getDefault()
                .getFieldDecoration(FieldDecorationRegistry.DEC_REQUIRED).getImage());
    }

}

From source file:org.bbaw.pdr.ae.view.editorlite.view.PersonAspectEditor.java

License:Open Source License

/**
 * Load identifiers.// w  w  w  . ja  v a  2  s. c o  m
 * @param add the add
 * @param del the del
 */
private void loadIdentifiers(final boolean add, final Integer del) {
    if (_scrollCompIdentifier != null) {
        _scrollCompIdentifier.dispose();
    }
    _scrollCompIdentifier = new ScrolledComposite((Composite) _identifierTabItem.getControl(),
            SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    _identifierTabItem.setData("sc", _scrollCompIdentifier);

    _scrollCompIdentifier.setExpandHorizontal(true);
    _scrollCompIdentifier.setExpandVertical(true);
    _scrollCompIdentifier.setMinSize(SWT.DEFAULT, SWT.DEFAULT);
    _scrollCompIdentifier.setLayoutData(new GridData());
    ((GridData) _scrollCompIdentifier.getLayoutData()).heightHint = 380;
    ((GridData) _scrollCompIdentifier.getLayoutData()).widthHint = 630;

    ((GridData) _scrollCompIdentifier.getLayoutData()).horizontalAlignment = SWT.FILL;
    ((GridData) _scrollCompIdentifier.getLayoutData()).grabExcessHorizontalSpace = true;
    _scrollCompIdentifier.setMinHeight(1);
    _scrollCompIdentifier.setMinWidth(1);

    _scrollCompIdentifier.setLayout(new GridLayout());

    Composite contentCompIdentifier = new Composite(_scrollCompIdentifier, SWT.NONE);
    contentCompIdentifier.setLayout(new GridLayout());
    _scrollCompIdentifier.setContent(contentCompIdentifier);

    if (add && _currentPerson.getIdentifiers() == null) {
        _currentPerson.setIdentifiers(new Identifiers());
        _currentPerson.getIdentifiers().setIdentifiers(new Vector<Identifier>());
        _currentPerson.getIdentifiers().getIdentifiers().add(new Identifier());
    } else if (add) {
        _currentPerson.getIdentifiers().getIdentifiers().add(new Identifier());

    }
    if (del != null) {
        //         System.out.println("old size " + _currentPerson.getIdentifiers().getIdentifiers().size()); //$NON-NLS-1$
        _currentPerson.getIdentifiers().remove(del);
    }

    for (int i = 0; i < _currentPerson.getIdentifiers().getIdentifiers().size(); i++) {
        int m = i + 1;
        final Identifier identifier = _currentPerson.getIdentifiers().getIdentifiers().get(i);
        final Group idGroup = new Group(contentCompIdentifier, SWT.SHADOW_IN);
        idGroup.setText(NLMessages.getString("Editor_externalIdentifiers") + m); //$NON-NLS-1$
        idGroup.setLayoutData(new GridData());
        idGroup.setLayout(new GridLayout());
        idGroup.setData("num", i); //$NON-NLS-1$
        ((GridData) idGroup.getLayoutData()).horizontalAlignment = SWT.FILL;
        ((GridData) idGroup.getLayoutData()).grabExcessHorizontalSpace = true;
        ((GridLayout) idGroup.getLayout()).numColumns = 5;
        ((GridLayout) idGroup.getLayout()).makeColumnsEqualWidth = false;

        final Combo idProviderCombo = new Combo(idGroup, SWT.DROP_DOWN | SWT.READ_ONLY);
        idProviderCombo.setEnabled(_mayWritePerson);
        idProviderCombo.setBackground(WHITE_COLOR);
        final ComboViewer idProviderComboViewer = new ComboViewer(idProviderCombo);
        idProviderComboViewer.setContentProvider(new MarkupContentProvider());
        idProviderComboViewer.setLabelProvider(new MarkupLabelProvider());

        idProviderCombo.setLayoutData(new GridData());
        ((GridData) idProviderCombo.getLayoutData()).grabExcessHorizontalSpace = true;
        ((GridData) idProviderCombo.getLayoutData()).horizontalAlignment = SWT.FILL;
        ((GridData) idProviderCombo.getLayoutData()).horizontalIndent = 6;
        if (_facade.getConfigs().get(_configProvider) != null
                && _facade.getConfigs().get(_configProvider).getUsage() != null && !_facade.getConfigs()
                        .get(_configProvider).getUsage().getIdentifiers().getChildren().isEmpty()) {
            ConfigData cd = _facade.getConfigs().get(_configProvider).getUsage().getIdentifiers();
            idProviderComboViewer.setInput(cd.getChildren());

        }
        idProviderComboViewer.addSelectionChangedListener(new ISelectionChangedListener() {
            @Override
            public void selectionChanged(final SelectionChangedEvent event) {
                ISelection iSelection = event.getSelection();
                Object obj = ((IStructuredSelection) iSelection).getFirstElement();
                IAEPresentable cp = (IAEPresentable) obj;
                if (cp != null) {
                    identifier.setProvider(cp.getValue());
                    validate();
                }

            }

        });

        if (identifier.getProvider() != null) {
            ViewHelper.setComboViewerByString(idProviderComboViewer, identifier.getProvider(), true);
        } else if (idProviderCombo.getItemCount() > 0) {
            idProviderComboViewer.setSelection(new StructuredSelection(idProviderComboViewer.getElementAt(0)));
        }

        final Text idText = new Text(idGroup, SWT.BORDER);
        idText.setLayoutData(new GridData());
        idText.setEditable(_mayWritePerson);
        idText.setBackground(WHITE_COLOR);
        ((GridData) idText.getLayoutData()).horizontalSpan = 3;
        ((GridData) idText.getLayoutData()).horizontalAlignment = SWT.FILL;
        ((GridData) idText.getLayoutData()).grabExcessHorizontalSpace = true;
        ((GridData) idText.getLayoutData()).horizontalIndent = 8;

        final ControlDecoration decoIdent = new ControlDecoration(idText, SWT.LEFT | SWT.TOP);
        if (identifier.getIdentifier() != null) {
            idText.setText(identifier.getIdentifier()); //$NON-NLS-1$
        } else {
            idText.setText(""); //$NON-NLS-1$
            decoIdent.setImage(FieldDecorationRegistry.getDefault()
                    .getFieldDecoration(FieldDecorationRegistry.DEC_REQUIRED).getImage());
        }

        idText.addFocusListener(new FocusAdapter() {
            @Override
            public void focusLost(final FocusEvent e) {
                identifier.setIdentifier(idText.getText()); //$NON-NLS-1$
                if (identifier.isValidId()) {
                    decoIdent.setImage(null);
                } else {
                    decoIdent.setImage(FieldDecorationRegistry.getDefault()
                            .getFieldDecoration(FieldDecorationRegistry.DEC_REQUIRED).getImage());
                }
                validate();
            }
        });
        idText.addKeyListener(new KeyListener() {

            @Override
            public void keyPressed(final KeyEvent e) {
            }

            @Override
            public void keyReleased(final KeyEvent e) {
                //               System.out.println("key released"); //$NON-NLS-1$
                identifier.setIdentifier(idText.getText()); //$NON-NLS-1$
                if (identifier.isValidId()) {
                    decoIdent.setImage(null);
                } else {
                    decoIdent.setImage(FieldDecorationRegistry.getDefault()
                            .getFieldDecoration(FieldDecorationRegistry.DEC_REQUIRED).getImage());
                }
                validate();
            }
        });

        final Button showData = new Button(idGroup, SWT.PUSH);
        showData.setText(NLMessages.getString("Editor_showData")); //$NON-NLS-1$
        showData.setToolTipText(NLMessages.getString("Editor_showData_tooltip"));
        showData.setImage(_imageReg.get(IconsInternal.BROWSER));
        showData.setLayoutData(new GridData());
        showData.setData("num", i); //$NON-NLS-1$
        showData.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(final SelectionEvent event) {

                IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench()
                        .getService(IHandlerService.class);
                _facade.setRequestedIdentifierType(identifier.getProvider()); //$NON-NLS-1$
                _facade.setRequestedIdentifier(identifier.getIdentifier()); //$NON-NLS-1$
                try {
                    handlerService.executeCommand("org.bbaw.pdr.ae.view.identifiers.commands" + //$NON-NLS-1$
                    ".OpenBrowserDialog", null); //$NON-NLS-1$
                } catch (ExecutionException e) {
                    e.printStackTrace();
                } catch (NotDefinedException e) {
                    e.printStackTrace();
                } catch (NotEnabledException e) {
                    e.printStackTrace();
                } catch (NotHandledException e) {
                    e.printStackTrace();
                }
            }
        });

        Label qualityLabel = new Label(idGroup, SWT.NONE);
        qualityLabel.setText(""); //$NON-NLS-1$
        qualityLabel.setLayoutData(new GridData());
        final ControlDecoration decoIdentQual = new ControlDecoration(qualityLabel, SWT.LEFT | SWT.TOP);
        // final String qual = "";
        SelectionListener idListener = new SelectionAdapter() {
            @Override
            public void widgetDefaultSelected(final SelectionEvent e) {

                validate();

            }

            @Override
            public void widgetSelected(final SelectionEvent e) {
                final String qual = (String) ((Button) e.getSource()).getData("text");
                //                 System.out.println("pnd qual: " + pndQual); //$NON-NLS-1$
                identifier.setQuality(qual); //$NON-NLS-1$
                if (identifier.isValidQuality()) {
                    decoIdentQual.setImage(null);
                } else {
                    decoIdentQual.setImage(FieldDecorationRegistry.getDefault()
                            .getFieldDecoration(FieldDecorationRegistry.DEC_REQUIRED).getImage());
                }
                validate();
            }
        };

        final Button[] radios = new Button[_ratings.length];

        for (int j = 0; j < _ratings.length; j++) {
            radios[j] = new Button(idGroup, SWT.RADIO);
            radios[j].setText(NLMessages.getString("Editor_" + _ratings[j]));
            radios[j].setData("text", _ratings[j]);
            radios[j].setEnabled(_mayWritePerson);
            radios[j].setLayoutData(new GridData());
            radios[j].addSelectionListener(idListener);
        }

        if (identifier.getQuality() != null) {
            ViewHelper.setRadioByString(radios, identifier.getQuality());
        } else {
            decoIdentQual.setImage(FieldDecorationRegistry.getDefault()
                    .getFieldDecoration(FieldDecorationRegistry.DEC_REQUIRED).getImage());

        }
        Label b = new Label(idGroup, SWT.NONE);
        b.setText(""); //$NON-NLS-1$
        b.setLayoutData(new GridData());
        Label idAuthorityLabel = new Label(idGroup, SWT.NONE);
        idAuthorityLabel.setText(NLMessages.getString("Editor_createdBy")); //$NON-NLS-1$
        idAuthorityLabel.setLayoutData(new GridData());

        final Text idAuthorityText = new Text(idGroup, SWT.BORDER | SWT.READ_ONLY);
        idAuthorityText.setData("num", i); //$NON-NLS-1$

        if (identifier.getAuthority() != null) {
            User u = null;
            try {
                u = _facade.getUserManager().getUserById(identifier.getAuthority().toString());
            } catch (Exception e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            if (u != null) {
                idAuthorityText.setText(u.getDisplayName());
            } else {
                idAuthorityText.setText(identifier.getAuthority().toString());
            }
        } else {
            idAuthorityText.setText(_facade.getCurrentUser().getPdrId().toString());
            identifier.setAuthority(_facade.getCurrentUser().getPdrId());
        }

        idAuthorityText.setLayoutData(new GridData());
        ((GridData) idAuthorityText.getLayoutData()).horizontalSpan = 3;
        ((GridData) idAuthorityText.getLayoutData()).horizontalAlignment = SWT.FILL;
        ((GridData) idAuthorityText.getLayoutData()).grabExcessHorizontalSpace = true;
        ((GridData) idAuthorityText.getLayoutData()).horizontalIndent = 8;
        final Button delIdentifier = new Button(idGroup, SWT.PUSH);
        delIdentifier.setText(NLMessages.getString("Editor_delete")); //$NON-NLS-1$
        delIdentifier.setToolTipText(NLMessages.getString("Editor_remove_identifier_tooltip"));
        delIdentifier.setImage(_imageReg.get(IconsInternal.IDENTIFIER_REMOVE));
        delIdentifier.setLayoutData(new GridData());
        delIdentifier.setData("num", i); //$NON-NLS-1$
        delIdentifier.setEnabled(_mayWritePerson);

        delIdentifier.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(final SelectionEvent event) {
                //               System.out.println("del identifier " + (Integer) delIdentifier.getData("num")); //$NON-NLS-1$ //$NON-NLS-2$
                loadIdentifiers(false, (Integer) delIdentifier.getData("num")); //$NON-NLS-1$
                validate();

            }
        });
        idGroup.layout();
        idGroup.pack();
    } // idGroup
    contentCompIdentifier.redraw();
    contentCompIdentifier.layout();

    _scrollCompIdentifier.setContent(contentCompIdentifier);
    Point point = contentCompIdentifier.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    Point mp = _tabFolder.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    if (point.x > mp.x - 20) {
        point.x = mp.x - 20;
    }
    if (point.y > mp.y - 20) {
        point.y = mp.y - 20;
    }
    _scrollCompIdentifier.setMinSize(point);
    _scrollCompIdentifier.layout();
    _identifierTabItem.getControl().redraw();
    ((Composite) _identifierTabItem.getControl()).layout();
    _identifierTabItem.getControl().update();
}