Search in sources :

Example 1 with PropertiesTableEditorView

use of org.talend.designer.core.ui.editor.properties.macrowidgets.tableeditor.PropertiesTableEditorView in project tdi-studio-se by Talend.

the class TableController method estimateRowSize.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.talend.designer.core.ui.editor.properties.controllers.AbstractElementPropertySectionController#estimateRowSize
     * (org.eclipse.swt.widgets.Composite, org.talend.core.model.process.IElementParameter)
     */
@Override
public int estimateRowSize(Composite subComposite, IElementParameter param) {
    PropertiesTableEditorModel<Map<String, Object>> tableEditorModel = new PropertiesTableEditorModel<Map<String, Object>>();
    updateTableValues(param);
    tableEditorModel.setData(elem, param, part.getProcess());
    PropertiesTableEditorView<Map<String, Object>> tableEditorView = new PropertiesTableEditorView<Map<String, Object>>(subComposite, SWT.NONE, tableEditorModel, !param.isBasedOnSchema(), false);
    tableEditorView.getExtendedTableViewer().setCommandStack(getCommandStack());
    tableEditorView.setReadOnly(param.isReadOnly());
    final Table table = tableEditorView.getTable();
    int toolbarSize = 0;
    if (!param.isBasedOnSchema()) {
        Point size = tableEditorView.getExtendedToolbar().getToolbar().computeSize(SWT.DEFAULT, SWT.DEFAULT);
        toolbarSize = size.y + 5;
    }
    int currentHeightEditor = table.getHeaderHeight() + ((List) param.getValue()).size() * table.getItemHeight() + table.getItemHeight() + toolbarSize;
    int minHeightEditor = table.getHeaderHeight() + getNumberLines(param) * table.getItemHeight() + table.getItemHeight() + toolbarSize;
    tableEditorView.getMainComposite().dispose();
    int ySize2 = Math.max(currentHeightEditor, minHeightEditor);
    return ySize2 + ITabbedPropertyConstants.VSPACE;
}
Also used : PropertiesTableEditorModel(org.talend.designer.core.ui.editor.properties.macrowidgets.tableeditor.PropertiesTableEditorModel) Table(org.eclipse.swt.widgets.Table) PropertiesTableEditorView(org.talend.designer.core.ui.editor.properties.macrowidgets.tableeditor.PropertiesTableEditorView) ArrayList(java.util.ArrayList) List(java.util.List) Point(org.eclipse.swt.graphics.Point) HashMap(java.util.HashMap) Map(java.util.Map) Point(org.eclipse.swt.graphics.Point)

Example 2 with PropertiesTableEditorView

use of org.talend.designer.core.ui.editor.properties.macrowidgets.tableeditor.PropertiesTableEditorView in project tdi-studio-se by Talend.

the class TableController method createControl.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.designer.core.ui.editor.properties2.editors.AbstractElementPropertySectionController#
     * createControl(org.eclipse.swt.widgets.Composite, org.talend.core.model.process.IElementParameter, int, int, int,
     * org.eclipse.swt.widgets.Control)
     */
@Override
public Control createControl(final Composite parentComposite, final IElementParameter param, final int numInRow, final int nbInRow, int top, final Control lastControlPrm) {
    this.curParameter = param;
    this.paramFieldType = param.getFieldType();
    final Composite container = parentComposite;
    PropertiesTableEditorModel<Map<String, Object>> tableEditorModel = new PropertiesTableEditorModel<Map<String, Object>>();
    tableEditorModel.setData(elem, param, getProcess(elem, part));
    PropertiesTableEditorView<Map<String, Object>> tableEditorView = new PropertiesTableEditorView<Map<String, Object>>(parentComposite, SWT.NONE, tableEditorModel, !param.isBasedOnSchema(), false);
    tableEditorView.getExtendedTableViewer().setCommandStack(getCommandStack());
    tableEditorView.setReadOnly(param.isReadOnly() || param.isRepositoryValueUsed());
    tableEditorModel.setModifiedBeanListenable(tableEditorView.getTableViewerCreator());
    tableEditorModel.addModifiedBeanListenerForAggregateComponent();
    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();
            }
        }
    });
    final Composite mainComposite = tableEditorView.getMainComposite();
    CLabel labelLabel2 = getWidgetFactory().createCLabel(container, param.getDisplayName());
    FormData formData = new FormData();
    if (lastControlPrm != null) {
        formData.left = new FormAttachment(lastControlPrm, 0);
    } else {
        formData.left = new FormAttachment((((numInRow - 1) * MAX_PERCENT) / nbInRow), 0);
    }
    formData.top = new FormAttachment(0, top);
    labelLabel2.setLayoutData(formData);
    if (numInRow != 1) {
        labelLabel2.setAlignment(SWT.RIGHT);
    }
    // *********************
    formData = new FormData();
    int currentLabelWidth2 = STANDARD_LABEL_WIDTH;
    GC gc2 = new GC(labelLabel2);
    Point labelSize2 = gc2.stringExtent(param.getDisplayName());
    gc2.dispose();
    boolean needOffset = true;
    if ((labelSize2.x + ITabbedPropertyConstants.HSPACE) > currentLabelWidth2) {
        currentLabelWidth2 = labelSize2.x + ITabbedPropertyConstants.HSPACE;
        needOffset = false;
    }
    int tableHorizontalOffset = -5;
    if (numInRow == 1) {
        if (lastControlPrm != null) {
            if (needOffset) {
                formData.left = new FormAttachment(lastControlPrm, currentLabelWidth2 + tableHorizontalOffset);
            } else {
                formData.left = new FormAttachment(lastControlPrm, currentLabelWidth2);
            }
        } else {
            if (needOffset) {
                formData.left = new FormAttachment(0, currentLabelWidth2 + tableHorizontalOffset);
            } else {
                formData.left = new FormAttachment(0, currentLabelWidth2);
            }
        }
    } else {
        formData.left = new FormAttachment(labelLabel2, 0 + tableHorizontalOffset, SWT.RIGHT);
    }
    formData.right = new FormAttachment((numInRow * MAX_PERCENT) / nbInRow, 0);
    formData.top = new FormAttachment(0, top);
    int toolbarSize = 0;
    if (!param.isBasedOnSchema()) {
        Point size = tableEditorView.getExtendedToolbar().getToolbar().computeSize(SWT.DEFAULT, SWT.DEFAULT);
        toolbarSize = size.y + 5;
    }
    int currentHeightEditor = table.getHeaderHeight() + ((List) param.getValue()).size() * table.getItemHeight() + table.getItemHeight() + toolbarSize;
    int minHeightEditor = table.getHeaderHeight() + getNumberLines(param) * table.getItemHeight() + table.getItemHeight() + toolbarSize;
    int ySize2 = Math.max(currentHeightEditor, minHeightEditor);
    ySize2 = Math.min(ySize2, 500);
    formData.bottom = new FormAttachment(0, top + ySize2);
    mainComposite.setLayoutData(formData);
    hashCurControls.put(param.getName(), tableEditorView.getExtendedTableViewer().getTableViewerCreator());
    hashCurControls.put(TOOLBAR_NAME, tableEditorView.getToolBar());
    updateTableValues(param);
    this.dynamicProperty.setCurRowSize(ySize2 + ITabbedPropertyConstants.VSPACE);
    if (isInWizard()) {
        labelLabel2.setAlignment(SWT.RIGHT);
        if (lastControlPrm != null) {
            formData.right = new FormAttachment(lastControlPrm, 0);
        } else {
            formData.right = new FormAttachment(100, -ITabbedPropertyConstants.HSPACE);
        }
        formData.left = new FormAttachment((((nbInRow - numInRow) * MAX_PERCENT) / nbInRow), currentLabelWidth2 + ITabbedPropertyConstants.HSPACE);
        formData = (FormData) labelLabel2.getLayoutData();
        formData.right = new FormAttachment(mainComposite, 0);
        formData.left = new FormAttachment((((nbInRow - numInRow) * MAX_PERCENT) / nbInRow), 0);
        return labelLabel2;
    }
    return mainComposite;
}
Also used : CLabel(org.eclipse.swt.custom.CLabel) FormData(org.eclipse.swt.layout.FormData) PropertiesTableEditorModel(org.talend.designer.core.ui.editor.properties.macrowidgets.tableeditor.PropertiesTableEditorModel) ListenableListEvent(org.talend.commons.utils.data.list.ListenableListEvent) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) Node(org.talend.designer.core.ui.editor.nodes.Node) Point(org.eclipse.swt.graphics.Point) IListenableListListener(org.talend.commons.utils.data.list.IListenableListListener) Point(org.eclipse.swt.graphics.Point) PropertiesTableEditorView(org.talend.designer.core.ui.editor.properties.macrowidgets.tableeditor.PropertiesTableEditorView) ArrayList(java.util.ArrayList) List(java.util.List) GC(org.eclipse.swt.graphics.GC) HashMap(java.util.HashMap) Map(java.util.Map) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Aggregations

ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Point (org.eclipse.swt.graphics.Point)2 Table (org.eclipse.swt.widgets.Table)2 PropertiesTableEditorModel (org.talend.designer.core.ui.editor.properties.macrowidgets.tableeditor.PropertiesTableEditorModel)2 PropertiesTableEditorView (org.talend.designer.core.ui.editor.properties.macrowidgets.tableeditor.PropertiesTableEditorView)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 IListenableListListener (org.talend.commons.utils.data.list.IListenableListListener)1 ListenableListEvent (org.talend.commons.utils.data.list.ListenableListEvent)1 Node (org.talend.designer.core.ui.editor.nodes.Node)1