Search in sources :

Example 1 with PropertiesTableEditorModel

use of org.talend.designer.core.ui.editor.properties.macrowidgets.tableeditor.PropertiesTableEditorModel 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 PropertiesTableEditorModel

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

the class TableByRowController 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>>();
    if (param.getValue() == null || param.getValue().equals("")) {
        param.setValue(new ArrayList<Map<String, Object>>());
    }
    init(elem, param);
    tableEditorModel.setData(elem, param, getProcess(elem, part));
    PropertiesTableByRowEditorView<Map<String, Object>> tableEditorView = new PropertiesTableByRowEditorView<Map<String, Object>>(parentComposite, SWT.NONE, tableEditorModel, true, 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() + 1 * 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);
    top += this.dynamicProperty.getCurRowSize();
    return null;
}
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) PropertiesTableByRowEditorView(org.talend.designer.core.ui.editor.properties.macrowidgets.tableeditor.PropertiesTableByRowEditorView) GC(org.eclipse.swt.graphics.GC) Map(java.util.Map) HashMap(java.util.HashMap) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Example 3 with PropertiesTableEditorModel

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

the class TableByRowController 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);
    if (param.getValue() == null || param.getValue().equals("")) {
        param.setValue(new ArrayList<Map<String, Object>>());
    }
    init(elem, param);
    tableEditorModel.setData(elem, param, part.getProcess());
    PropertiesTableByRowEditorView<Map<String, Object>> tableEditorView = new PropertiesTableByRowEditorView<Map<String, Object>>(subComposite, SWT.NONE, tableEditorModel, true, 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) PropertiesTableByRowEditorView(org.talend.designer.core.ui.editor.properties.macrowidgets.tableeditor.PropertiesTableByRowEditorView) List(java.util.List) ArrayList(java.util.ArrayList) Point(org.eclipse.swt.graphics.Point) Map(java.util.Map) HashMap(java.util.HashMap) Point(org.eclipse.swt.graphics.Point)

Example 4 with PropertiesTableEditorModel

use of org.talend.designer.core.ui.editor.properties.macrowidgets.tableeditor.PropertiesTableEditorModel 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)

Example 5 with PropertiesTableEditorModel

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

the class PropertyTablePasteCommand method createPastableBeansList.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.talend.commons.ui.swt.advanced.dataeditor.commands.ExtendedTablePasteCommand#createPastableBeansList(java
     * .util.List)
     */
@Override
public List createPastableBeansList(ExtendedTableModel extendedTable, List copiedObjectsList) {
    ArrayList list = new ArrayList();
    IElementParameter param = null;
    INode node = null;
    if (extendedTable instanceof PropertiesTableEditorModel) {
        PropertiesTableEditorModel<B> model = (PropertiesTableEditorModel<B>) extendedTable;
        if (model.getElement() instanceof INode) {
            node = (INode) model.getElement();
            param = model.getElemParameter();
        }
    }
    for (Object current : copiedObjectsList) {
        if (current instanceof HashMap) {
            // create a new column as a copy of this column
            Map<String, Object> clonedRow = (Map<String, Object>) ((HashMap) current).clone();
            if (param != null) {
                for (String key : clonedRow.keySet()) {
                    Object value = clonedRow.get(key);
                    if (value instanceof String && !"".equals(value)) {
                        IElementParameter childParam = null;
                        for (Object o : param.getListItemsValue()) {
                            if (o instanceof IElementParameter) {
                                if (((IElementParameter) o).getName().equals(key)) {
                                    childParam = (IElementParameter) o;
                                    break;
                                }
                            }
                        }
                        if (childParam != null && childParam.getFieldType() == EParameterFieldType.SCHEMA_TYPE) {
                            IMetadataTable originalMetadata = node.getMetadataTable((String) value);
                            IMetadataTable clonedMetadata = originalMetadata.clone();
                            List<String> tableList = new ArrayList<String>();
                            for (IMetadataTable table : node.getMetadataList()) {
                                tableList.add(table.getTableName());
                            }
                            String newTableName = UniqueNodeNameGenerator.generateUniqueNodeName(originalMetadata.getTableName(), tableList);
                            clonedMetadata.setTableName(newTableName);
                            clonedMetadata.setLabel(newTableName);
                            node.getMetadataList().add(clonedMetadata);
                            clonedRow.put(key, newTableName);
                        }
                    }
                }
            }
            list.add(clonedRow);
        }
    }
    return list;
}
Also used : PropertiesTableEditorModel(org.talend.designer.core.ui.editor.properties.macrowidgets.tableeditor.PropertiesTableEditorModel) INode(org.talend.core.model.process.INode) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) IElementParameter(org.talend.core.model.process.IElementParameter) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

HashMap (java.util.HashMap)5 Map (java.util.Map)5 PropertiesTableEditorModel (org.talend.designer.core.ui.editor.properties.macrowidgets.tableeditor.PropertiesTableEditorModel)5 ArrayList (java.util.ArrayList)4 Point (org.eclipse.swt.graphics.Point)4 Table (org.eclipse.swt.widgets.Table)4 List (java.util.List)3 CLabel (org.eclipse.swt.custom.CLabel)2 GC (org.eclipse.swt.graphics.GC)2 FormAttachment (org.eclipse.swt.layout.FormAttachment)2 FormData (org.eclipse.swt.layout.FormData)2 Composite (org.eclipse.swt.widgets.Composite)2 IListenableListListener (org.talend.commons.utils.data.list.IListenableListListener)2 ListenableListEvent (org.talend.commons.utils.data.list.ListenableListEvent)2 Node (org.talend.designer.core.ui.editor.nodes.Node)2 PropertiesTableByRowEditorView (org.talend.designer.core.ui.editor.properties.macrowidgets.tableeditor.PropertiesTableByRowEditorView)2 PropertiesTableEditorView (org.talend.designer.core.ui.editor.properties.macrowidgets.tableeditor.PropertiesTableEditorView)2 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)1 IElementParameter (org.talend.core.model.process.IElementParameter)1 INode (org.talend.core.model.process.INode)1