Search in sources :

Example 1 with Field

use of org.eclipse.linuxtools.internal.mylyn.osio.rest.ui.provisional.AbstractQueryPageSchema.Field in project linuxtools by eclipse.

the class RepositoryQuerySchemaPage method createFieldControls.

private void createFieldControls(Composite attributesComposite, FormToolkit toolkit, int columnCount, TaskAttribute target) {
    int currentColumn = 1;
    int currentPriority = 0;
    int currentLayoutPriority = 0;
    for (Field field : schema.getFields()) {
        TaskAttribute dataAttribute = target.getAttribute(field.getKey());
        AbstractAttributeEditor attributeEditor = factory.createEditor(field.getType(), dataAttribute);
        editorMap.put(dataAttribute.getId(), attributeEditor);
        String layoutPriorityString = dataAttribute.getMetaData().getValue("LayoutPriority");
        int layoutPriority = layoutPriorityString == null ? -1 : Integer.parseInt(layoutPriorityString);
        int priority = (attributeEditor.getLayoutHint() != null) ? attributeEditor.getLayoutHint().getPriority() : LayoutHint.DEFAULT_PRIORITY;
        // TODO: copied from AbstractTaskEditorAttributeSection.createAttributeControls (only layoutPriority is new)
        if (priority != currentPriority || currentLayoutPriority != layoutPriority) {
            currentPriority = priority;
            currentLayoutPriority = layoutPriority;
            if (currentColumn > 1) {
                while (currentColumn <= columnCount) {
                    // $NON-NLS-1$
                    Label l = toolkit.createLabel(attributesComposite, "");
                    GridData gd = GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).hint(0, SWT.DEFAULT).create();
                    l.setLayoutData(gd);
                    currentColumn++;
                }
                currentColumn = 1;
            }
        }
        if (attributeEditor.hasLabel()) {
            attributeEditor.createLabelControl(attributesComposite, toolkit);
            Label label = attributeEditor.getLabelControl();
            label.setBackground(attributesComposite.getBackground());
            label.setForeground(attributesComposite.getForeground());
            String text = label.getText();
            String shortenText = TaskDiffUtil.shortenText(label, text, LABEL_WIDTH);
            label.setText(shortenText);
            if (!text.equals(shortenText)) {
                label.setToolTipText(text);
            }
            GridData gd = GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.CENTER).grab(true, true).hint(LABEL_WIDTH, SWT.DEFAULT).create();
            if (currentColumn > 1) {
                gd.horizontalIndent = COLUMN_GAP;
                gd.widthHint = LABEL_WIDTH + COLUMN_GAP;
            }
            label.setLayoutData(gd);
            currentColumn++;
        }
        attributeEditor.createControl(attributesComposite, toolkit);
        attributeEditor.getControl().setBackground(attributesComposite.getParent().getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
        attributeEditor.getControl().setForeground(attributesComposite.getForeground());
        LayoutHint layoutHint = attributeEditor.getLayoutHint();
        GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
        RowSpan rowSpan = (layoutHint != null && layoutHint.rowSpan != null) ? layoutHint.rowSpan : RowSpan.SINGLE;
        ColumnSpan columnSpan = (layoutHint != null && layoutHint.columnSpan != null) ? layoutHint.columnSpan : ColumnSpan.SINGLE;
        // prevent clipping of decorators on Windows
        gd.horizontalIndent = 1;
        if (rowSpan == RowSpan.SINGLE && columnSpan == ColumnSpan.SINGLE) {
            gd.widthHint = COLUMN_WIDTH;
            gd.horizontalSpan = 1;
        } else {
            if (rowSpan == RowSpan.MULTIPLE) {
                gd.heightHint = MULTI_ROW_HEIGHT;
            }
            if (columnSpan == ColumnSpan.SINGLE) {
                gd.widthHint = COLUMN_WIDTH;
                gd.horizontalSpan = 1;
            } else {
                gd.widthHint = MULTI_COLUMN_WIDTH;
                gd.horizontalSpan = columnCount - currentColumn + 1;
            }
        }
        attributeEditor.getControl().setLayoutData(gd);
        currentColumn += gd.horizontalSpan;
        currentColumn %= columnCount;
    }
}
Also used : Field(org.eclipse.linuxtools.internal.mylyn.osio.rest.ui.provisional.AbstractQueryPageSchema.Field) TaskAttribute(org.eclipse.mylyn.tasks.core.data.TaskAttribute) ColumnSpan(org.eclipse.mylyn.tasks.ui.editors.LayoutHint.ColumnSpan) AbstractAttributeEditor(org.eclipse.mylyn.tasks.ui.editors.AbstractAttributeEditor) Label(org.eclipse.swt.widgets.Label) GridData(org.eclipse.swt.layout.GridData) LayoutHint(org.eclipse.mylyn.tasks.ui.editors.LayoutHint) RowSpan(org.eclipse.mylyn.tasks.ui.editors.LayoutHint.RowSpan) Point(org.eclipse.swt.graphics.Point) LayoutHint(org.eclipse.mylyn.tasks.ui.editors.LayoutHint)

Example 2 with Field

use of org.eclipse.linuxtools.internal.mylyn.osio.rest.ui.provisional.AbstractQueryPageSchema.Field in project linuxtools by eclipse.

the class RepositoryQuerySchemaPage method isPageComplete.

@Override
public boolean isPageComplete() {
    setMessage(pageDetails.getPageDescription());
    boolean result = super.isPageComplete();
    if (!result) {
        return result;
    }
    setErrorMessage(null);
    setMessage("");
    boolean oneFieldHasValue = false;
    for (Field field : schema.getFields()) {
        oneFieldHasValue |= (targetTaskData.getRoot().getAttribute(field.getKey()).hasValue() && !targetTaskData.getRoot().getAttribute(field.getKey()).getValue().equals(""));
        if (field.isQueryRequired()) {
            String text = targetTaskData.getRoot().getAttribute(field.getKey()).getValue();
            if (text == null || text.length() == 0) {
                setMessage(NLS.bind(Messages.OSIORestQuery_EnterValue, field.getLabel()));
                return false;
            }
        }
        if (field.getType().equals("url")) {
            // $NON-NLS-1$
            String text = targetTaskData.getRoot().getAttribute(field.getKey()).getValue();
            if (text != null && text.length() > 0) {
                Matcher m = URL_PATTERN.matcher(text);
                if (m.find()) {
                    setErrorMessage(null);
                    return true;
                } else {
                    setErrorMessage(NLS.bind(Messages.OSIORestQuery_EnterValidURL, field.getLabel()));
                    return false;
                }
            }
        }
    }
    if (!oneFieldHasValue) {
        setErrorMessage(Messages.OSIORestQuery_SpecifyOneField);
    }
    return true;
}
Also used : Field(org.eclipse.linuxtools.internal.mylyn.osio.rest.ui.provisional.AbstractQueryPageSchema.Field) Matcher(java.util.regex.Matcher)

Aggregations

Field (org.eclipse.linuxtools.internal.mylyn.osio.rest.ui.provisional.AbstractQueryPageSchema.Field)2 Matcher (java.util.regex.Matcher)1 TaskAttribute (org.eclipse.mylyn.tasks.core.data.TaskAttribute)1 AbstractAttributeEditor (org.eclipse.mylyn.tasks.ui.editors.AbstractAttributeEditor)1 LayoutHint (org.eclipse.mylyn.tasks.ui.editors.LayoutHint)1 ColumnSpan (org.eclipse.mylyn.tasks.ui.editors.LayoutHint.ColumnSpan)1 RowSpan (org.eclipse.mylyn.tasks.ui.editors.LayoutHint.RowSpan)1 Point (org.eclipse.swt.graphics.Point)1 GridData (org.eclipse.swt.layout.GridData)1 Label (org.eclipse.swt.widgets.Label)1