Search in sources :

Example 1 with JsonTableView

use of org.talend.designer.core.generic.ui.JsonTableView in project tdi-studio-se by Talend.

the class JsonTableController method estimateRowSize.

@Override
public int estimateRowSize(Composite subComposite, IElementParameter param) {
    JsonTableView tableEditorView = generateTableEditorView(subComposite, param);
    int height = adjustTableHeight(tableEditorView, param);
    return height + ITabbedPropertyConstants.VSPACE;
}
Also used : JsonTableView(org.talend.designer.core.generic.ui.JsonTableView) Point(org.eclipse.swt.graphics.Point)

Example 2 with JsonTableView

use of org.talend.designer.core.generic.ui.JsonTableView in project tdi-studio-se by Talend.

the class JsonTableController method createControl.

@Override
public Control createControl(final Composite parentComposite, final IElementParameter param, final int numInRow, final int nbInRow, int top, final Control lastControl) {
    this.curParameter = param;
    this.paramFieldType = param.getFieldType();
    final Composite container = parentComposite;
    JsonTableView tableEditorView = generateTableEditorView(parentComposite, param);
    final Composite mainComposite = tableEditorView.getMainComposite();
    mainComposite.setData(PARAMETER_NAME, param.getName());
    String labelDisplayName = param.getDisplayName();
    CLabel label = getWidgetFactory().createCLabel(container, labelDisplayName);
    FormData formData = new FormData();
    if (lastControl != null) {
        formData.left = new FormAttachment(lastControl, 0);
    } else {
        formData.left = new FormAttachment((((numInRow - 1) * MAX_PERCENT) / nbInRow), 0);
    }
    formData.top = new FormAttachment(0, top);
    label.setLayoutData(formData);
    formData = new FormData();
    int currentLabelWidth = STANDARD_LABEL_WIDTH;
    GC gc = new GC(label);
    Point labelSize = gc.stringExtent(param.getDisplayName());
    gc.dispose();
    if ((labelSize.x + (ITabbedPropertyConstants.HSPACE * 2)) > currentLabelWidth) {
        currentLabelWidth = labelSize.x + (ITabbedPropertyConstants.HSPACE * 2);
    }
    if (numInRow == 1) {
        if (lastControl != null) {
            formData.left = new FormAttachment(lastControl, currentLabelWidth);
        } else {
            formData.left = new FormAttachment(0, currentLabelWidth);
        }
    } else {
        formData.left = new FormAttachment(label, 0, SWT.RIGHT);
    }
    formData.right = new FormAttachment((numInRow * MAX_PERCENT) / nbInRow, 0);
    formData.top = new FormAttachment(0, top);
    int height = adjustTableHeight(tableEditorView, param);
    formData.bottom = new FormAttachment(0, top + height);
    mainComposite.setLayoutData(formData);
    hashCurControls.put(param.getName(), tableEditorView.getExtendedTableViewer().getTableViewerCreator());
    this.dynamicProperty.setCurRowSize(height + ITabbedPropertyConstants.VSPACE);
    if (isInWizard()) {
        label.setAlignment(SWT.RIGHT);
        if (lastControl != null) {
            formData.right = new FormAttachment(lastControl, 0);
        } else {
            formData.right = new FormAttachment(100, -ITabbedPropertyConstants.HSPACE);
        }
        formData.left = new FormAttachment((((nbInRow - numInRow) * MAX_PERCENT) / nbInRow), currentLabelWidth + ITabbedPropertyConstants.HSPACE);
        formData = (FormData) label.getLayoutData();
        formData.right = new FormAttachment(mainComposite, 0);
        formData.left = new FormAttachment((((nbInRow - numInRow) * MAX_PERCENT) / nbInRow), 0);
        return label;
    }
    return mainComposite;
}
Also used : CLabel(org.eclipse.swt.custom.CLabel) FormData(org.eclipse.swt.layout.FormData) Composite(org.eclipse.swt.widgets.Composite) JsonTableView(org.talend.designer.core.generic.ui.JsonTableView) Point(org.eclipse.swt.graphics.Point) GC(org.eclipse.swt.graphics.GC) FormAttachment(org.eclipse.swt.layout.FormAttachment) Point(org.eclipse.swt.graphics.Point)

Example 3 with JsonTableView

use of org.talend.designer.core.generic.ui.JsonTableView in project tdi-studio-se by Talend.

the class JsonTableController method generateTableEditorView.

private JsonTableView generateTableEditorView(Composite parent, IElementParameter param) {
    JsonTableVO vo = null;
    Object value = param.getValue();
    if (value != null) {
        String valueStr = TalendQuoteUtils.removeQuotesIfExist(String.valueOf(value));
        if (StringUtils.isNotBlank(valueStr)) {
            vo = JsonTableHandler.getInstance().parse(valueStr);
        }
    }
    if (vo != null) {
        rows = vo.getData();
        if (rows != null) {
            rowsNum = rows.size();
        }
        titles = vo.getTitles();
    }
    JsonFieldModel tableEditorModel = new JsonFieldModel(rows);
    JsonTableView tableEditorView = new JsonTableView(parent, tableEditorModel, readonly, !hideToolbar) {

        @Override
        protected List<String> getColumnTitles() {
            return titles;
        }
    };
    tableEditorView.getExtendedTableViewer().setCommandStack(getCommandStack());
    tableEditorView.setReadOnly(param.isReadOnly() || param.isRepositoryValueUsed());
    tableEditorModel.setModifiedBeanListenable(tableEditorView.getTableViewerCreator());
    final Table table = tableEditorView.getTable();
    table.setToolTipText(VARIABLE_TOOLTIP + param.getVariableName());
    // add listener to tableMetadata (listen the event of the toolbars)
    tableEditorView.getExtendedTableModel().addAfterOperationListListener(new IListenableListListener() {

        @Override
        public void handleEvent(ListenableListEvent event) {
            if (elem instanceof Node) {
                Node node = (Node) elem;
                node.checkAndRefreshNode();
            }
        }
    });
    return tableEditorView;
}
Also used : JsonFieldModel(org.talend.designer.core.generic.ui.JsonFieldModel) ListenableListEvent(org.talend.commons.utils.data.list.ListenableListEvent) Table(org.eclipse.swt.widgets.Table) Node(org.talend.designer.core.ui.editor.nodes.Node) JsonTableView(org.talend.designer.core.generic.ui.JsonTableView) IListenableListListener(org.talend.commons.utils.data.list.IListenableListListener) JsonTableVO(org.talend.designer.core.generic.ui.JsonTableVO)

Aggregations

JsonTableView (org.talend.designer.core.generic.ui.JsonTableView)3 Point (org.eclipse.swt.graphics.Point)2 CLabel (org.eclipse.swt.custom.CLabel)1 GC (org.eclipse.swt.graphics.GC)1 FormAttachment (org.eclipse.swt.layout.FormAttachment)1 FormData (org.eclipse.swt.layout.FormData)1 Composite (org.eclipse.swt.widgets.Composite)1 Table (org.eclipse.swt.widgets.Table)1 IListenableListListener (org.talend.commons.utils.data.list.IListenableListListener)1 ListenableListEvent (org.talend.commons.utils.data.list.ListenableListEvent)1 JsonFieldModel (org.talend.designer.core.generic.ui.JsonFieldModel)1 JsonTableVO (org.talend.designer.core.generic.ui.JsonTableVO)1 Node (org.talend.designer.core.ui.editor.nodes.Node)1