Search in sources :

Example 6 with Listener

use of org.eclipse.swt.widgets.Listener in project otertool by wuntee.

the class GuiWorkshop method addColumnSorter.

public static void addColumnSorter(final Table table, TableColumn column, final int index, final String[] dataKeys) {
    Listener sortListener = new Listener() {

        public void handleEvent(Event e) {
            TableItem[] items = table.getItems();
            Collator collator = Collator.getInstance(Locale.getDefault());
            TableColumn column = (TableColumn) e.widget;
            for (int i = 1; i < items.length; i++) {
                String value1 = items[i].getText(index);
                for (int j = 0; j < i; j++) {
                    String value2 = items[j].getText(index);
                    if (table.getSortDirection() == SWT.UP || table.getSortDirection() == SWT.NONE && collator.compare(value1, value2) < 0) {
                        String[] values = new String[table.getColumnCount()];
                        for (int k = 0; k < table.getColumnCount(); k++) {
                            values[k] = items[i].getText(k);
                        }
                        // Get data from list item
                        Map<String, Object> dataMap = new HashMap<String, Object>();
                        for (String key : dataKeys) {
                            dataMap.put(key, items[i].getData(key));
                        }
                        items[i].dispose();
                        TableItem item = new TableItem(table, SWT.NONE, j);
                        item.setText(values);
                        // Set data for new item
                        for (String key : dataMap.keySet()) {
                            item.setData(key, dataMap.get(key));
                        }
                        items = table.getItems();
                        break;
                    } else if (table.getSortDirection() == SWT.DOWN && collator.compare(value1, value2) > 0) {
                        String[] values = new String[table.getColumnCount()];
                        for (int k = 0; k < table.getColumnCount(); k++) {
                            values[k] = items[i].getText(k);
                        }
                        // Get data from list item
                        Map<String, Object> dataMap = new HashMap<String, Object>();
                        for (String key : dataKeys) {
                            dataMap.put(key, items[i].getData(key));
                        }
                        items[i].dispose();
                        TableItem item = new TableItem(table, SWT.NONE, j);
                        item.setText(values);
                        // Set data for new item
                        for (String key : dataMap.keySet()) {
                            item.setData(key, dataMap.get(key));
                        }
                        items = table.getItems();
                        break;
                    }
                }
            }
            if (table.getSortDirection() == SWT.NONE || table.getSortDirection() == SWT.UP) {
                table.setSortDirection(SWT.DOWN);
            } else {
                table.setSortDirection(SWT.UP);
            }
            table.setSortColumn(column);
        }
    };
    column.addListener(SWT.Selection, sortListener);
}
Also used : Listener(org.eclipse.swt.widgets.Listener) HashMap(java.util.HashMap) TableItem(org.eclipse.swt.widgets.TableItem) TableColumn(org.eclipse.swt.widgets.TableColumn) Collator(java.text.Collator) Event(org.eclipse.swt.widgets.Event) HashMap(java.util.HashMap) Map(java.util.Map)

Example 7 with Listener

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

the class ToolbarOutputZone method addListeners.

/**
     * DOC amaumont Comment method "addListeners".
     */
private void addListeners() {
    // final UIManager uiManager = getMapperManager().getUiManager();
    addOutputItem.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event event) {
            getMapperManager().addOutput();
        }
    });
    removeOutputItem.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event event) {
            getMapperManager().removeSelectedOutput();
        }
    });
    guessItem.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event event) {
            List<DataMapTableView> outputsTablesView = getMapperManager().getUiManager().getOutputsTablesView();
            for (DataMapTableView dataMapTableView : outputsTablesView) {
                dataMapTableView.notifyFocusLost();
            }
            getMapperManager().mapAutomaticallly();
        }
    });
}
Also used : Listener(org.eclipse.swt.widgets.Listener) Event(org.eclipse.swt.widgets.Event) List(java.util.List) DataMapTableView(org.talend.designer.mapper.ui.visualmap.table.DataMapTableView)

Example 8 with Listener

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

the class ProcessVersionComposite method addSortListener.

/**
     * DOC Administrator Comment method "addSortListener".
     * 
     * @param table
     * @param column1
     * @param column2
     * @param column3
     */
private void addSortListener(final Table table, final TableColumn column1, final TableColumn column2, final TableColumn column3, final TableColumn column4) {
    Listener sortListener = new Listener() {

        private int direction = 1;

        @Override
        public void handleEvent(Event e) {
            final TableColumn column = (TableColumn) e.widget;
            if (column == table.getSortColumn()) {
                direction = -direction;
            }
            if (direction == 1) {
                table.setSortDirection(SWT.DOWN);
            } else {
                table.setSortDirection(SWT.UP);
            }
            table.setSortColumn(column);
            tableViewer.setSorter(new ViewerSorter() {

                int index = 0;

                @Override
                public void sort(Viewer viewer, Object[] elements) {
                    while (index < table.getColumns().length && table.getColumn(index) != column) {
                        index++;
                    }
                    super.sort(viewer, elements);
                }

                @Override
                public int compare(Viewer viewer, Object e1, Object e2) {
                    ITableLabelProvider labelProvider = (ITableLabelProvider) tableViewer.getLabelProvider();
                    String columnText = labelProvider.getColumnText(e1, index) != null ? labelProvider.getColumnText(e1, index) : //$NON-NLS-1$
                    "";
                    String columnText2 = labelProvider.getColumnText(e2, index) != null ? labelProvider.getColumnText(e2, index) : //$NON-NLS-1$
                    "";
                    return getComparator().compare(columnText, columnText2) * direction;
                }
            });
        }
    };
    tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        /*
             * (non-Javadoc)
             * 
             * @seeorg.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.
             * SelectionChangedEvent)
             */
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            ProcessVersionComposite.this.selection = event.getSelection();
            if (getParentWizard() != null) {
                ((WizardPage) getParentWizard()).setPageComplete(true);
            }
        }
    });
    column1.addListener(SWT.Selection, sortListener);
    column2.addListener(SWT.Selection, sortListener);
    column3.addListener(SWT.Selection, sortListener);
    column4.addListener(SWT.Selection, sortListener);
    table.setSortColumn(column1);
    table.setSortDirection(SWT.DOWN);
    tableViewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            if (getParentWizard() == null) {
                ITreeContextualAction editPropertiesAction = getEditPropertiesAction(EditPropertiesAction.class);
                if (editPropertiesAction != null) {
                    editPropertiesAction.run();
                }
            }
        }
    });
}
Also used : IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) ILabelProviderListener(org.eclipse.jface.viewers.ILabelProviderListener) IMenuListener(org.eclipse.jface.action.IMenuListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Listener(org.eclipse.swt.widgets.Listener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) ViewerSorter(org.eclipse.jface.viewers.ViewerSorter) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) ITreeContextualAction(org.talend.commons.ui.swt.actions.ITreeContextualAction) TableColumn(org.eclipse.swt.widgets.TableColumn) ITableLabelProvider(org.eclipse.jface.viewers.ITableLabelProvider) EditPropertiesAction(org.talend.repository.ui.actions.EditPropertiesAction) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Event(org.eclipse.swt.widgets.Event) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IRepositoryObject(org.talend.core.model.repository.IRepositoryObject)

Example 9 with Listener

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

the class ToolbarOutputZone method addListeners.

/**
     * DOC amaumont Comment method "addListeners".
     */
private void addListeners() {
    // final UIManager uiManager = getMapperManager().getUiManager();
    addOutputItem.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event event) {
            getMapperManager().addOutput();
        }
    });
    removeOutputItem.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event event) {
            getMapperManager().removeSelectedOutputTable();
        }
    });
    guessItem.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event event) {
            getMapperManager().mapAutomaticallly();
        }
    });
}
Also used : Listener(org.eclipse.swt.widgets.Listener) Event(org.eclipse.swt.widgets.Event)

Example 10 with Listener

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

the class ToolbarInputZone method addListeners.

/**
     * DOC amaumont Comment method "addListeners".
     */
private void addListeners() {
    // final UIManager uiManager = getMapperManager().getUiManager();
    addAlias.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event event) {
            getMapperManager().addInputAliasTable();
        }
    });
    removeAlias.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event event) {
            getMapperManager().removeSelectedAliasInputTable();
        }
    });
}
Also used : Listener(org.eclipse.swt.widgets.Listener) Event(org.eclipse.swt.widgets.Event)

Aggregations

Listener (org.eclipse.swt.widgets.Listener)876 Event (org.eclipse.swt.widgets.Event)841 SelectionEvent (org.eclipse.swt.events.SelectionEvent)538 Button (org.eclipse.swt.widgets.Button)480 Label (org.eclipse.swt.widgets.Label)452 Text (org.eclipse.swt.widgets.Text)392 ModifyListener (org.eclipse.swt.events.ModifyListener)385 Shell (org.eclipse.swt.widgets.Shell)385 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)382 ModifyEvent (org.eclipse.swt.events.ModifyEvent)376 FormData (org.eclipse.swt.layout.FormData)356 ShellEvent (org.eclipse.swt.events.ShellEvent)354 FormAttachment (org.eclipse.swt.layout.FormAttachment)353 FormLayout (org.eclipse.swt.layout.FormLayout)353 Display (org.eclipse.swt.widgets.Display)342 ShellAdapter (org.eclipse.swt.events.ShellAdapter)325 Composite (org.eclipse.swt.widgets.Composite)295 GridData (org.eclipse.swt.layout.GridData)229 GridLayout (org.eclipse.swt.layout.GridLayout)195 TextVar (org.pentaho.di.ui.core.widget.TextVar)184