Search in sources :

Example 1 with Item

use of org.eclipse.swt.widgets.Item in project translationstudio8 by heartsome.

the class CustomMatchContributionItem method fill.

@Override
public void fill(Menu menu, int index) {
    LinkedHashMap<String, String> map = XLFHandler.getCustomMatchFilterMap();
    if (map == null || map.size() == 0) {
        for (Item item : menu.getItems()) {
            if (!item.isDisposed()) {
                item.dispose();
            }
        }
    } else {
        for (Entry<String, String> entry : map.entrySet()) {
            final String xpath = entry.getValue();
            MenuItem item = new MenuItem(menu, SWT.PUSH);
            item.setText(entry.getKey());
            item.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    XLIFFEditorImplWithNatTable xliffEditor = XLIFFEditorImplWithNatTable.getCurrent();
                    if (xliffEditor == null) {
                        return;
                    }
                    xliffEditor.getXLFHandler().deleteAltTrans(xpath);
                    ArrayList<Integer> rowList = new ArrayList<Integer>();
                    int[] rows = xliffEditor.getSelectedRows();
                    for (int i : rows) {
                        rowList.add(i);
                    }
                    StructuredSelection selection = new StructuredSelection(rowList);
                    xliffEditor.getSite().getSelectionProvider().setSelection(selection);
                }
            });
        }
    }
}
Also used : XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) MenuItem(org.eclipse.swt.widgets.MenuItem) ContributionItem(org.eclipse.jface.action.ContributionItem) Item(org.eclipse.swt.widgets.Item) MenuItem(org.eclipse.swt.widgets.MenuItem) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Example 2 with Item

use of org.eclipse.swt.widgets.Item in project tdi-studio-se by Talend.

the class Schema2XMLLinker method updateLinksStyleAndControlsSelection.

@SuppressWarnings("unchecked")
public void updateLinksStyleAndControlsSelection(Control currentControl) {
    // super.updateLinksStyleAndControlsSelection(currentControl);
    boolean isTarget = false;
    if (getSource() != currentControl) {
        isTarget = true;
    } else {
        isTarget = false;
    }
    HashSet selectedItems = new HashSet();
    Map itemsToSelect = new HashMap();
    if (isTarget) {
        getTarget().deselectAll();
        TreeItem[] selection = getTarget().getSelection();
        for (TreeItem tableItem : selection) {
            selectedItems.add(tableItem.getData());
        }
    } else {
        TableItem[] selection = getSource().getSelection();
        for (TableItem treeItem : selection) {
            selectedItems.add(treeItem.getData());
        }
    }
    List<LinkDescriptor<Item, Object, Tree, Object>> links = linksManager.getLinks();
    for (LinkDescriptor<Item, Object, Tree, Object> link : links) {
        IStyleLink styleLink = null;
        IExtremityLink extremity = null;
        IExtremityLink otherExtremity = null;
        if (isTarget) {
            extremity = link.getExtremity2();
            otherExtremity = link.getExtremity1();
        } else {
            extremity = link.getExtremity1();
            otherExtremity = link.getExtremity2();
        }
        boolean currentItemIsSelected = selectedItems.contains(extremity.getDataItem());
        if (extremity.getGraphicalObject() == xmlViewer.getTree() || otherExtremity.getGraphicalObject() == xmlViewer.getTree()) {
            styleLink = getSelectedLoopStyleLink();
        } else {
            if (currentItemIsSelected) {
                styleLink = getSelectedStyleLink();
                if (isTarget) {
                    itemsToSelect.put(otherExtremity.getGraphicalObject(), null);
                } else {
                    Table currentTable = (Table) otherExtremity.getGraphicalObject();
                    List<TableItem> tableItemsToSelect = (List<TableItem>) itemsToSelect.get(currentTable);
                    if (tableItemsToSelect == null) {
                        tableItemsToSelect = new ArrayList<TableItem>();
                        itemsToSelect.put(currentTable, tableItemsToSelect);
                    }
                    TableItem tableItem = TableUtils.getTableItem(currentTable, otherExtremity.getDataItem());
                    tableItemsToSelect.add(tableItem);
                }
            } else {
                styleLink = getUnselectedStyleLink();
            }
        }
        if (styleLink == null) {
            styleLink = getDefaultStyleLink();
        }
        link.setStyleLink(styleLink);
    }
    if (isTarget) {
        (getSource()).setSelection((TableItem[]) itemsToSelect.keySet().toArray(new TableItem[0]));
    } else {
        Set<Table> set = itemsToSelect.keySet();
        if (set.size() > 0) {
            for (Table table : set) {
                ArrayList<TableItem> tableItemsToSelect = (ArrayList<TableItem>) itemsToSelect.get(table);
                table.deselectAll();
                TableItem[] tableItems = tableItemsToSelect.toArray(new TableItem[0]);
                table.setSelection(tableItems);
            }
        } else {
            xmlViewer.getTree().deselectAll();
        }
    }
    getLinksManager().sortLinks(getDrawingLinksComparator());
}
Also used : Table(org.eclipse.swt.widgets.Table) HashMap(java.util.HashMap) TreeItem(org.eclipse.swt.widgets.TreeItem) TableItem(org.eclipse.swt.widgets.TableItem) ArrayList(java.util.ArrayList) TableItem(org.eclipse.swt.widgets.TableItem) TreeItem(org.eclipse.swt.widgets.TreeItem) Item(org.eclipse.swt.widgets.Item) IExtremityLink(org.talend.commons.ui.swt.drawing.link.IExtremityLink) IStyleLink(org.talend.commons.ui.swt.drawing.link.IStyleLink) Tree(org.eclipse.swt.widgets.Tree) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) LinkDescriptor(org.talend.commons.ui.swt.drawing.link.LinkDescriptor) HashSet(java.util.HashSet)

Example 3 with Item

use of org.eclipse.swt.widgets.Item in project tdi-studio-se by Talend.

the class JSONFileSchema2TreeLinker method addLink.

private LinkDescriptor<Item, Object, Tree, Object> addLink(Item tableItem, Object dataItem1, Tree tree, Object dataItem2, boolean lastOne) {
    LinkDescriptor<Item, Object, Tree, Object> link = new LinkDescriptor<Item, Object, Tree, Object>(new ItemExtremityDescriptor(tableItem, dataItem1), new ExtremityLink<Tree, Object>(tree, dataItem2));
    link.setStyleLink(getUnselectedStyleLink());
    getLinksManager().addLink(link);
    updateLinksStyleAndControlsSelection(tree, lastOne);
    return link;
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) TreeItem(org.eclipse.swt.widgets.TreeItem) Item(org.eclipse.swt.widgets.Item) ItemExtremityDescriptor(org.talend.commons.ui.swt.drawing.link.ItemExtremityDescriptor) Tree(org.eclipse.swt.widgets.Tree) LinkDescriptor(org.talend.commons.ui.swt.drawing.link.LinkDescriptor)

Example 4 with Item

use of org.eclipse.swt.widgets.Item in project tdi-studio-se by Talend.

the class AddArrayIndexForParentsDialog method createDialogArea.

protected Control createDialogArea(Composite parent) {
    Composite createDialogArea = (Composite) super.createDialogArea(parent);
    FillLayout layout = new FillLayout();
    // layout.horizontalSpacing = 1;
    // layout.numColumns = 1;
    GridData data = new GridData(GridData.FILL_BOTH);
    createDialogArea.setLayout(layout);
    createDialogArea.setLayoutData(data);
    table = new TableViewer(createDialogArea, SWT.FULL_SELECTION | SWT.BORDER);
    new TableColumn(table.getTable(), SWT.LEFT).setText(COLUMN_NAME[0]);
    table.getTable().getColumn(0).pack();
    new TableColumn(table.getTable(), SWT.LEFT).setText(COLUMN_NAME[1]);
    table.getTable().getColumn(1).pack();
    table.getTable().setHeaderVisible(true);
    table.getTable().setLinesVisible(true);
    table.setContentProvider(new IndexContentProvider());
    table.setLabelProvider(new IndexLabelProvider());
    table.setInput(arrayIndexList);
    table.setColumnProperties(COLUMN_NAME);
    CellEditor[] editors = new CellEditor[2];
    editors[0] = null;
    editors[1] = new TextCellEditor(table.getTable());
    table.setCellEditors(editors);
    table.setCellModifier(new ICellModifier() {

        public boolean canModify(Object element, String property) {
            if (property.equals(COLUMN_NAME[0]))
                return false;
            return true;
        }

        public Object getValue(Object element, String property) {
            ArrayIndexList index = (ArrayIndexList) element;
            if (property.equals(COLUMN_NAME[1])) {
                if (index.getIndexNum() != null) {
                    return index.getIndexNum();
                } else {
                    return "";
                }
            }
            return null;
        }

        public void modify(Object element, String property, Object value) {
            if (element instanceof Item)
                element = ((Item) element).getData();
            ArrayIndexList index = (ArrayIndexList) element;
            if (property.equals(COLUMN_NAME[1]))
                index.setIndexNum((String) value);
            table.refresh();
        }
    });
    return createDialogArea;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) CellEditor(org.eclipse.jface.viewers.CellEditor) FillLayout(org.eclipse.swt.layout.FillLayout) TableColumn(org.eclipse.swt.widgets.TableColumn) Item(org.eclipse.swt.widgets.Item) GridData(org.eclipse.swt.layout.GridData) ICellModifier(org.eclipse.jface.viewers.ICellModifier) ArrayIndexList(org.talend.designer.webservice.data.ArrayIndexList) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 5 with Item

use of org.eclipse.swt.widgets.Item in project tdi-studio-se by Talend.

the class SchemaXMLLinker method addLink.

/**
     * amaumont Comment method "addLink".
     * 
     * @param tableItem
     * @param dataItem1
     * @param tree
     * @param dataItem2
     */
private LinkDescriptor<Item, Object, Tree, Object> addLink(Item tableItem, Object dataItem1, Tree tree, Object dataItem2, boolean lastOne) {
    LinkDescriptor<Item, Object, Tree, Object> link = new LinkDescriptor<Item, Object, Tree, Object>(new ItemExtremityDescriptor(tableItem, dataItem1), new ExtremityLink<Tree, Object>(tree, dataItem2));
    link.setStyleLink(getUnselectedStyleLink());
    getLinksManager().addLink(link);
    updateLinksStyleAndControlsSelection(tree, lastOne);
    return link;
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) TreeItem(org.eclipse.swt.widgets.TreeItem) Item(org.eclipse.swt.widgets.Item) ItemExtremityDescriptor(org.talend.commons.ui.swt.drawing.link.ItemExtremityDescriptor) Tree(org.eclipse.swt.widgets.Tree) LinkDescriptor(org.talend.commons.ui.swt.drawing.link.LinkDescriptor)

Aggregations

Item (org.eclipse.swt.widgets.Item)23 HashMap (java.util.HashMap)15 Map (java.util.Map)14 TableItem (org.eclipse.swt.widgets.TableItem)14 ICellModifier (org.eclipse.jface.viewers.ICellModifier)13 CellEditor (org.eclipse.jface.viewers.CellEditor)12 TextCellEditor (org.eclipse.jface.viewers.TextCellEditor)11 Tree (org.eclipse.swt.widgets.Tree)7 TreeItem (org.eclipse.swt.widgets.TreeItem)7 LinkDescriptor (org.talend.commons.ui.swt.drawing.link.LinkDescriptor)7 GridData (org.eclipse.swt.layout.GridData)6 ArrayList (java.util.ArrayList)5 SelectionEvent (org.eclipse.swt.events.SelectionEvent)5 ToolItem (org.eclipse.swt.widgets.ToolItem)5 List (java.util.List)4 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)4 Composite (org.eclipse.swt.widgets.Composite)4 HashSet (java.util.HashSet)3 ComboBoxCellEditor (org.eclipse.jface.viewers.ComboBoxCellEditor)3 GridLayout (org.eclipse.swt.layout.GridLayout)3