Search in sources :

Example 1 with ColumnSpan

use of org.eclipse.mylyn.tasks.ui.editors.LayoutHint.ColumnSpan 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 ColumnSpan

use of org.eclipse.mylyn.tasks.ui.editors.LayoutHint.ColumnSpan in project linuxtools by eclipse.

the class OSIORestTaskEditorAttributePart method createAttributeControls.

private void createAttributeControls(Composite attributesComposite, FormToolkit toolkit, int columnCount) {
    int currentColumn = 1;
    int currentPriority = 0;
    for (AbstractAttributeEditor attributeEditor : attributeEditors) {
        int priority = (attributeEditor.getLayoutHint() != null) ? attributeEditor.getLayoutHint().getPriority() : LayoutHint.DEFAULT_PRIORITY;
        if (priority != currentPriority) {
            currentPriority = priority;
            if (currentColumn > 1) {
                while (currentColumn <= columnCount) {
                    // $NON-NLS-1$
                    getManagedForm().getToolkit().createLabel(attributesComposite, "");
                    currentColumn++;
                }
                currentColumn = 1;
            }
        }
        if (attributeEditor.hasLabel()) {
            attributeEditor.createLabelControl(attributesComposite, toolkit);
            Label label = attributeEditor.getLabelControl();
            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).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);
        LayoutHint layoutHint = attributeEditor.getLayoutHint();
        GridData gd = new GridData(SWT.FILL, SWT.CENTER, false, false);
        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);
        getTaskEditorPage().getAttributeEditorToolkit().adapt(attributeEditor);
        currentColumn += gd.horizontalSpan;
        currentColumn %= columnCount;
    }
}
Also used : 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) LayoutHint(org.eclipse.mylyn.tasks.ui.editors.LayoutHint)

Aggregations

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