Example usage for org.eclipse.jface.viewers TableViewer getTable

List of usage examples for org.eclipse.jface.viewers TableViewer getTable

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers TableViewer getTable.

Prototype

public Table getTable() 

Source Link

Document

Returns this table viewer's table control.

Usage

From source file:de.dfki.iui.mmds.sdk.editors.grammar_rules.UtteranceEditorPart.java

License:Creative Commons License

/**
 * @param parent//from   www. j  ava2s .co m
 *            This class is called from the init() method. Here all the SWT
 *            and JFace components in the form are drawn.
 */
@Override
public void createPartControl(Composite parent) {
    super.createPartControl(parent);

    // sash form is used to split the main form into two parts
    SashForm sashForm = new SashForm(frmNewForm.getBody(), SWT.NONE);
    formToolkit.adapt(sashForm);
    formToolkit.paintBordersFor(sashForm);

    Section sctnNewSection = formToolkit.createSection(sashForm, Section.DESCRIPTION | Section.TITLE_BAR);

    formToolkit.paintBordersFor(sctnNewSection);
    sctnNewSection.setText("Utterance Rules");
    sctnNewSection.setExpanded(true);
    sctnNewSection.setDescription("Create or edit new Rules here");

    utteranceListComposite = new ContentListComposite(sctnNewSection, SWT.NONE,
            Grammar_rulesPackage.eINSTANCE.getRuleset_Rules(), Grammar_rulesPackage.eINSTANCE.getUtterance(),
            editor, cb);
    formToolkit.adapt(utteranceListComposite);
    sctnNewSection.setClient(utteranceListComposite);
    final TableViewer utterancesTableViewer = utteranceListComposite.getTableViewer();

    // the first column where the name of the Rule can be viewed and edited
    utteranceListComposite.addColumn(getString("_UI_Rule_name_feature"), COLUMN_TYPE.RULENAME);

    // the second column where the user can enable or disable the rule
    utteranceListComposite.addColumn(getString("_UI_Rule_enabled_feature"), COLUMN_TYPE.ENABLED);

    utterancesTableViewer.setColumnProperties(new String[] { "0", "1" });

    // setting a cell modifier so the rules can be edited in the TableViewer
    // directly
    utterancesTableViewer.setCellModifier(new ICellModifier() {

        @Override
        public boolean canModify(Object element, String property) {
            return true;
        }

        @Override
        public Object getValue(Object element, String property) {
            Object result = null;
            Rule rule = (Rule) element;
            // checking to see which property should be shown, name or
            // isEnabled and what is going to be shown in the table
            switch (property) {
            case "0":
                if (rule.getName() == null) {
                    result = "";
                } else {
                    result = rule.getName() + "";
                }
                break;
            case "1":
                result = new Boolean(rule.isEnabled());
                break;
            }
            return result;
        }

        @Override
        public void modify(Object element, String property, Object value) {
            // getting the selected element
            TableItem item = (TableItem) element;
            // getting the selected rule
            Rule oldValue = (Rule) item.getData();
            EAttribute feature = null;
            // depending on which property should be edited a different
            // feature is set for the setCommand
            switch (property) {
            case "0":
                feature = Grammar_rulesPackage.eINSTANCE.getRule_Name();
                break;
            case "1":
                feature = Grammar_rulesPackage.eINSTANCE.getRule_Enabled();
                break;
            }
            if (oldValue.getName() != null) {
                // if the name has not changed do nothing
                if ((property.equals("0") && !oldValue.getName().equals(value)) || property.equals("1")) {
                    editor.getEditingDomain().getCommandStack().execute(
                            SetCommand.create(editor.getEditingDomain(), item.getData(), feature, value));

                }
            } else {
                editor.getEditingDomain().getCommandStack()
                        .execute(SetCommand.create(editor.getEditingDomain(), item.getData(), feature, value));
            }
        }

    });

    // setting a cell editor for both properties of the Utterance Rules that
    // need to be edited
    utterancesTableViewer
            .setCellEditors(new CellEditor[] { new TextCellEditor(utterancesTableViewer.getTable()),
                    new CheckboxCellEditor(utterancesTableViewer.getTable()) });
    utterancesTableViewer.setInput(ruleset);

    // on selection changed update the details view (the PhraseMapping Table
    // Viewer and the Interpretation TreeViewer
    utterancesTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        // This ensures that we handle selections correctly.
        //
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) utterancesTableViewer.getSelection();
            if (selection != null && selection.size() == 1) {
                setSelectedUtterance((Utterance) selection.getFirstElement());
                editor.setCurrentViewer(utterancesTableViewer);
            } else {
                setSelectedUtterance(null);
            }
        }
    });

    Composite rightSide = new Composite(sashForm, SWT.NONE);
    formToolkit.adapt(rightSide);
    formToolkit.paintBordersFor(rightSide);
    rightSide.setLayout(new FillLayout(SWT.HORIZONTAL));

    SashForm sashForm_1 = new SashForm(rightSide, SWT.VERTICAL);
    formToolkit.adapt(sashForm_1);
    formToolkit.paintBordersFor(sashForm_1);

    final Section sctnNewSection_1 = formToolkit.createSection(sashForm_1, Section.TWISTIE | Section.TITLE_BAR);
    formToolkit.paintBordersFor(sctnNewSection_1);
    sctnNewSection_1.setText("Phrases");
    sctnNewSection_1.setExpanded(true);

    phraseMappingComposite = new ContentListComposite(sctnNewSection_1, SWT.NONE,
            Grammar_rulesPackage.eINSTANCE.getUtterance_Phrases(), EcorePackage.eINSTANCE.getEString(), editor,
            cb);
    formToolkit.adapt(phraseMappingComposite);
    sctnNewSection_1.setClient(phraseMappingComposite);

    // phrase Column
    phraseMappingComposite.addColumn(getString("_UI_PhraseMapping_name_feature"), COLUMN_TYPE.RULENAME);

    phraseMappingComposite.getTableViewer().setColumnProperties(new String[] { "0" });

    // cell modifier for changing the phrases in the table
    phraseMappingComposite.getTableViewer().setCellModifier(new ICellModifier() {

        @Override
        public boolean canModify(Object element, String property) {
            return true;
        }

        @Override
        public Object getValue(Object element, String property) {
            return element;
        }

        @Override
        public void modify(Object element, String property, Object value) {
            TableItem item = (TableItem) element;
            String oldValue = (String) item.getData();
            EAttribute feature = Grammar_rulesPackage.eINSTANCE.getUtterance_Phrases();
            String newString = (String) value;
            if (oldValue == null || !oldValue.equals(newString)) {
                // execute a replace comand where the oldPhrase is
                // updated with a new Phrase
                for (String phrase : selectedUtterance.getPhrases()) {
                    if (phrase.equals(newString)) {
                        errorLabel.setText("Phrases must be unique");
                        sctnNewSection_1.layout();
                        return;
                    }
                }
                ReplaceCommand cmd = new ReplaceCommand(editor.getEditingDomain(), selectedUtterance, feature,
                        oldValue, newString);

                editor.getEditingDomain().getCommandStack().execute(cmd);
            }

        }

    });

    phraseMappingComposite.getTableViewer().setCellEditors(
            new CellEditor[] { new TextCellEditor(phraseMappingComposite.getTableViewer().getTable()) });

    // this label is used to show the error that is given with a wrong
    // Phrase input
    errorLabel = formToolkit.createLabel(sctnNewSection_1, "", SWT.NONE);
    sctnNewSection_1.setTextClient(errorLabel);
    errorLabel.setForeground(
            getEditorSite().getWorkbenchWindow().getWorkbench().getDisplay().getSystemColor(SWT.COLOR_RED));

    // to set a validation of the phrases a listener is added to the cell
    // editor of the phrase mapping table.
    CellEditor[] test = phraseMappingComposite.getTableViewer().getCellEditors();
    for (final CellEditor e : test) {
        if (e instanceof TextCellEditor) {
            // the validator is set to a class designed previously, called
            // ABNF validator
            e.setValidator(new ABNFValidator());
            e.addListener(new ICellEditorListener() {
                @Override
                public void applyEditorValue() {
                    setErrorMessage(null);
                }

                @Override
                public void cancelEditor() {
                    setErrorMessage(null);
                }

                // here the error message is set
                @Override
                public void editorValueChanged(boolean oldValidState, boolean newValidState) {
                    setErrorMessage(e.getErrorMessage());
                }

                // here the error message is set to the a label
                private void setErrorMessage(String errorMessage) {
                    if (errorMessage != null) {
                        errorLabel.setText(errorMessage);
                        sctnNewSection_1.layout();
                    } else {
                        errorLabel.setText("");
                        sctnNewSection_1.layout();
                    }
                }
            });
        }
    }

    Section sctnNewSection_2 = formToolkit.createSection(sashForm_1, Section.TWISTIE | Section.TITLE_BAR);
    formToolkit.paintBordersFor(sctnNewSection_2);
    sctnNewSection_2.setText("Interpretation");
    sctnNewSection_2.setExpanded(true);

    treeViewerComposite = new EObjectTreeViewerComposite(sctnNewSection_2, SWT.NONE, editor,
            utteranceListComposite);
    formToolkit.adapt(treeViewerComposite);
    formToolkit.paintBordersFor(treeViewerComposite);
    sctnNewSection_2.setClient(treeViewerComposite);

    sashForm_1.setWeights(new int[] { 1, 1 });
    sashForm.setWeights(new int[] { 1, 1 });
    setSelectedUtterance(null);
}

From source file:de.fkoeberle.autocommit.message.ui.AdvancedPage.java

License:Open Source License

/**
 * Create contents of the editor part.//w  w w.j av a2 s .  c om
 * 
 * @param parent
 */
@Override
public void createFormContent(IManagedForm managedForm) {
    super.createFormContent(managedForm);
    FormToolkit toolkit = managedForm.getToolkit();
    ScrolledForm scrolledForm = managedForm.getForm();
    Composite body = scrolledForm.getBody();
    toolkit.decorateFormHeading(scrolledForm.getForm());
    toolkit.paintBordersFor(body);

    scrolledForm.setText("Advanced");
    Composite parent = scrolledForm.getBody();
    parent.setLayout(new FillLayout(SWT.HORIZONTAL));
    Composite container = toolkit.createComposite(parent);
    container.setLayout(new GridLayout(1, false));

    Composite header = toolkit.createComposite(container);
    header.setLayout(new GridLayout(2, false));

    Label generateLabel = toolkit.createLabel(header, "Generate:");
    generateLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));

    final ComboViewer comboViewer = new ComboViewer(header, SWT.READ_ONLY);
    final Combo combo = comboViewer.getCombo();
    toolkit.adapt(combo, true, true);

    GridData comboLayoutData = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
    comboLayoutData.widthHint = 315;
    combo.setLayoutData(comboLayoutData);
    comboViewer.addSelectionChangedListener(new ComboSelectionListener(combo, comboViewer));

    comboViewer.setContentProvider(new ObservableListContentProvider());
    comboViewer.setLabelProvider(new DefaultProfileLabelProvider());
    comboViewer.setInput(model.getProfiles());

    ProfileComboBoxUpdater profileComboBoxUpdater = new ProfileComboBoxUpdater(comboViewer);
    model.addCurrentProfileListener(new ProfileComboBoxUpdater(comboViewer));
    profileComboBoxUpdater.currentProfileChanged();

    SashForm sashForm = new SashForm(container, SWT.NONE);
    sashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    toolkit.adapt(sashForm, false, false);

    Section leftSection = managedForm.getToolkit().createSection(sashForm, Section.TWISTIE | Section.TITLE_BAR);
    managedForm.getToolkit().paintBordersFor(leftSection);
    leftSection.setText("Used commit message factories:");

    Composite leftComposite = managedForm.getToolkit().createComposite(leftSection, SWT.NONE);
    managedForm.getToolkit().paintBordersFor(leftComposite);
    leftSection.setClient(leftComposite);
    leftComposite.setLayout(new GridLayout(1, false));

    final TableViewer usedFactoriesTableViewer = new TableViewer(leftComposite, SWT.BORDER | SWT.MULTI);
    usedFactoriesTable = usedFactoriesTableViewer.getTable();
    usedFactoriesTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    usedFactoriesTableViewer.setContentProvider(new ObservableListContentProvider());
    usedFactoriesTableViewer.setLabelProvider(new FactoryLabelProvider());
    usedFactoriesTableViewer.setInput(model.getFactoryDescriptions());

    Section middleSection = managedForm.getToolkit().createSection(sashForm,
            Section.TWISTIE | Section.TITLE_BAR);
    managedForm.getToolkit().paintBordersFor(middleSection);
    middleSection.setText("Unused commit message factories:");

    Composite middleComposite = managedForm.getToolkit().createComposite(middleSection, SWT.NONE);
    managedForm.getToolkit().paintBordersFor(middleComposite);
    middleSection.setClient(middleComposite);
    middleComposite.setLayout(new GridLayout(1, false));

    TableViewer unusedFactoriesTableViewer = new TableViewer(middleComposite, SWT.BORDER | SWT.MULTI);
    unusedFactoriesTable = unusedFactoriesTableViewer.getTable();
    unusedFactoriesTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    unusedFactoriesTableViewer.setContentProvider(new ObservableListContentProvider());
    unusedFactoriesTableViewer.setLabelProvider(new FactoryLabelProvider());
    unusedFactoriesTableViewer.setInput(model.getUnusedFactoryDescriptions());

    addDragAndDropSupport(usedFactoriesTableViewer, unusedFactoriesTableViewer);

    usedFactoriesTableViewer.addSelectionChangedListener(new FactoriesSelectionListener(CMFList.USED,
            usedFactoriesTableViewer, unusedFactoriesTableViewer, toolkit));
    unusedFactoriesTableViewer.addSelectionChangedListener(new FactoriesSelectionListener(CMFList.UNUSED,
            unusedFactoriesTableViewer, usedFactoriesTableViewer, toolkit));

    Section rightSection = managedForm.getToolkit().createSection(sashForm,
            Section.TWISTIE | Section.TITLE_BAR);
    managedForm.getToolkit().paintBordersFor(rightSection);
    rightSection.setText("Selected commit message factories:");

    Composite rightComposite = managedForm.getToolkit().createComposite(rightSection, SWT.NONE);
    managedForm.getToolkit().paintBordersFor(rightComposite);
    rightSection.setClient(rightComposite);
    rightComposite.setLayout(new GridLayout(1, false));

    final ScrolledComposite scrolledComposite = new ScrolledComposite(rightComposite,
            SWT.V_SCROLL | SWT.BORDER);
    scrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    toolkit.adapt(scrolledComposite);
    factoriesComposite = new Composite(scrolledComposite, SWT.NONE);
    scrolledComposite.setContent(factoriesComposite);
    toolkit.adapt(factoriesComposite);
    GridLayout layout = new GridLayout();
    layout.numColumns = 1;
    factoriesComposite.setLayout(layout);
    scrolledComposite.addControlListener(new ControlAdapter() {
        @Override
        public void controlResized(ControlEvent e) {
            Rectangle r = scrolledComposite.getClientArea();
            factoriesComposite.setSize(factoriesComposite.computeSize(r.width, SWT.DEFAULT));
            factoriesComposite.layout();
        }
    });
    scrolledComposite.setAlwaysShowScrollBars(true);
    sashForm.setWeights(new int[] { 180, 180, 350 });
    /*
     * Expand after generating it's content so that content gets properly
     * shown:
     */
    leftSection.setExpanded(true);
    middleSection.setExpanded(true);
    rightSection.setExpanded(true);
}

From source file:de.fkoeberle.autocommit.message.ui.CMFDropAdapter.java

License:Open Source License

@Override
public boolean performDrop(Object data) {
    CMFList sourceListType = listIdToTypeMap.get(data);
    if (sourceListType == null) {
        return false;
    }//from   w  w w .j a  v a 2s . c  o  m
    TableViewer sourceTable = listTypeToTableViewerMap.get(sourceListType);
    int insertIndex = determineInsertIndex();
    try {
        model.moveFactories(sourceListType, targetListType, sourceTable.getTable().getSelectionIndices(),
                insertIndex);
    } catch (ExecutionException e) {
        CMFMultiPageEditorPart.reportError(targetTable.getTable().getShell(), "Drop failed", e);
        return false;
    }

    return true;
}

From source file:de.fuberlin.agcsw.heraclitus.backend.ui.views.OntologyInformationView.java

License:Open Source License

private void createColumns(TableViewer viewer) {

    String[] titles = { "Key", "Value" };
    int[] bounds = { 100, 100, 100, 100 };

    for (int i = 0; i < titles.length; i++) {
        TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE);
        column.getColumn().setText(titles[i]);
        column.getColumn().setWidth(bounds[i]);
        column.getColumn().setResizable(true);
        column.getColumn().setMoveable(true);
    }/*  ww w . ja  v a  2  s. c  o  m*/
    Table table = viewer.getTable();
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
}

From source file:de.gebit.integrity.eclipse.views.IntegrityTestRunnerView.java

License:Open Source License

private void configureTable(final TableViewer aTable) {
    aTable.getTable().setHeaderVisible(true);
    aTable.getTable().setLinesVisible(true);

    TableViewerColumn tempColumn = new TableViewerColumn(aTable,
            SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
    tempColumn.getColumn().setText("Name");
    tempColumn.getColumn().setWidth(150);
    tempColumn.getColumn().setResizable(true);
    tempColumn.getColumn().setMoveable(false);
    tempColumn.setLabelProvider(new ColumnLabelProvider() {
        @Override/*  www .java2s .c om*/
        public String getText(Object anElement) {
            SetListEntry tempEntry = (SetListEntry) anElement;
            return (String) tempEntry.getAttribute(SetListEntryAttributeKeys.NAME);
        }
    });

    tempColumn = new TableViewerColumn(aTable, SWT.NONE);
    tempColumn.getColumn().setText("Value");
    tempColumn.getColumn().setWidth(150);
    tempColumn.getColumn().setResizable(true);
    tempColumn.getColumn().setMoveable(false);
    tempColumn.setLabelProvider(new ColumnLabelProvider() {
        @Override
        public void update(ViewerCell aCell) {
            SetListEntry tempEntry = (SetListEntry) aCell.getElement();
            aCell.setText((String) tempEntry.getAttribute(SetListEntryAttributeKeys.VALUE));
        }
    });
    // Make the value column editable, mostly to be able to copy out results. See issue #77
    tempColumn.setEditingSupport(new EditingSupport(aTable) {

        @Override
        protected void setValue(Object anElement, Object aValue) {
            // not supported, we don't really want to support editing of result values
        }

        @Override
        protected Object getValue(Object anElement) {
            SetListEntry tempEntry = (SetListEntry) anElement;
            return (String) tempEntry.getAttribute(SetListEntryAttributeKeys.VALUE);
        }

        @Override
        protected CellEditor getCellEditor(Object anElement) {
            return new TextCellEditor(aTable.getTable());
        }

        @Override
        protected boolean canEdit(Object anElement) {
            return true;
        }
    });
}

From source file:de.gebit.integrity.eclipse.views.IntegrityTestRunnerView.java

License:Open Source License

private void configureResultTable(final TableViewer aTable) {
    aTable.getTable().setHeaderVisible(true);
    aTable.getTable().setLinesVisible(true);

    TableViewerColumn tempColumn = new TableViewerColumn(aTable,
            SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
    tempColumn.getColumn().setText("Name");
    tempColumn.getColumn().setWidth(150);
    tempColumn.getColumn().setResizable(true);
    tempColumn.getColumn().setMoveable(false);
    tempColumn.setLabelProvider(new ColumnLabelProvider() {
        @Override//from  w  w w . j ava2s. c  om
        public String getText(Object anElement) {
            SetListEntry tempEntry = (SetListEntry) anElement;
            return (String) tempEntry.getAttribute(SetListEntryAttributeKeys.NAME);
        }

        @Override
        public Color getBackground(Object anElement) {
            SetListEntry tempEntry = (SetListEntry) anElement;
            Boolean tempSuccess = (Boolean) tempEntry
                    .getAttribute(SetListEntryAttributeKeys.RESULT_SUCCESS_FLAG);
            if (tempSuccess == null) {
                return super.getBackground(anElement);
            } else if (tempSuccess) {
                return resultTableSuccessColor;
            } else {
                return resultTableFailureColor;
            }
        }
    });

    tempColumn = new TableViewerColumn(aTable, SWT.NONE);
    tempColumn.getColumn().setText("Result");
    tempColumn.getColumn().setWidth(150);
    tempColumn.getColumn().setResizable(true);
    tempColumn.getColumn().setMoveable(false);
    tempColumn.setLabelProvider(new ColumnLabelProvider() {
        @Override
        public void update(ViewerCell aCell) {
            SetListEntry tempEntry = (SetListEntry) aCell.getElement();
            aCell.setText((String) tempEntry.getAttribute(SetListEntryAttributeKeys.VALUE));
        }

        @Override
        public Color getBackground(Object anElement) {
            SetListEntry tempEntry = (SetListEntry) anElement;
            Boolean tempSuccess = (Boolean) tempEntry
                    .getAttribute(SetListEntryAttributeKeys.RESULT_SUCCESS_FLAG);
            if (tempSuccess == null) {
                return super.getBackground(anElement);
            } else if (tempSuccess) {
                return resultTableSuccessColor;
            } else {
                return resultTableFailureColor;
            }
        }
    });
    // Make the value column editable, mostly to be able to copy out results. See issue #77
    tempColumn.setEditingSupport(new EditingSupport(aTable) {

        @Override
        protected void setValue(Object anElement, Object aValue) {
            // not supported, we don't really want to support editing of result values
        }

        @Override
        protected Object getValue(Object anElement) {
            SetListEntry tempEntry = (SetListEntry) anElement;
            return (String) tempEntry.getAttribute(SetListEntryAttributeKeys.VALUE);
        }

        @Override
        protected CellEditor getCellEditor(Object anElement) {
            return new TextCellEditor(aTable.getTable());
        }

        @Override
        protected boolean canEdit(Object anElement) {
            return true;
        }
    });

    tempColumn = new TableViewerColumn(aTable, SWT.NONE);
    tempColumn.getColumn().setText("Expected");
    tempColumn.getColumn().setWidth(150);
    tempColumn.getColumn().setResizable(true);
    tempColumn.getColumn().setMoveable(false);
    tempColumn.setLabelProvider(new ColumnLabelProvider() {
        @Override
        public void update(ViewerCell aCell) {
            SetListEntry tempEntry = (SetListEntry) aCell.getElement();
            aCell.setText((String) tempEntry.getAttribute(SetListEntryAttributeKeys.EXPECTED_RESULT));
        }

        @Override
        public Color getBackground(Object anElement) {
            SetListEntry tempEntry = (SetListEntry) anElement;
            Boolean tempSuccess = (Boolean) tempEntry
                    .getAttribute(SetListEntryAttributeKeys.RESULT_SUCCESS_FLAG);
            if (tempSuccess == null) {
                return super.getBackground(anElement);
            } else if (tempSuccess) {
                return resultTableSuccessColor;
            } else {
                return resultTableFailureColor;
            }
        }
    });
    // Make the value column editable, mostly to be able to copy out results. See issue #77
    tempColumn.setEditingSupport(new EditingSupport(aTable) {

        @Override
        protected void setValue(Object anElement, Object aValue) {
            // not supported, we don't really want to support editing of result values
        }

        @Override
        protected Object getValue(Object anElement) {
            SetListEntry tempEntry = (SetListEntry) anElement;
            return (String) tempEntry.getAttribute(SetListEntryAttributeKeys.EXPECTED_RESULT);
        }

        @Override
        protected CellEditor getCellEditor(Object anElement) {
            return new TextCellEditor(aTable.getTable());
        }

        @Override
        protected boolean canEdit(Object anElement) {
            return true;
        }
    });
}

From source file:de.gebit.integrity.eclipse.views.IntegrityTestRunnerView.java

License:Open Source License

private void configureVarUpdateTable(final TableViewer aTable) {
    aTable.getTable().setHeaderVisible(true);
    aTable.getTable().setLinesVisible(true);

    TableViewerColumn tempColumn = new TableViewerColumn(aTable,
            SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
    tempColumn.getColumn().setText("Result");
    tempColumn.getColumn().setWidth(150);
    tempColumn.getColumn().setResizable(true);
    tempColumn.getColumn().setMoveable(false);
    tempColumn.setLabelProvider(new ColumnLabelProvider() {
        @Override//from  w  w w .  j  a  v  a 2  s  .  co  m
        public String getText(Object anElement) {
            SetListEntry tempEntry = (SetListEntry) anElement;
            return (String) tempEntry.getAttribute(SetListEntryAttributeKeys.PARAMETER_NAME);
        }
    });

    tempColumn = new TableViewerColumn(aTable, SWT.NONE);
    tempColumn.getColumn().setText("Variable");
    tempColumn.getColumn().setWidth(150);
    tempColumn.getColumn().setResizable(true);
    tempColumn.getColumn().setMoveable(false);
    tempColumn.setLabelProvider(new ColumnLabelProvider() {
        @Override
        public String getText(Object anElement) {
            SetListEntry tempEntry = (SetListEntry) anElement;
            return (String) tempEntry.getAttribute(SetListEntryAttributeKeys.VARIABLE_NAME);
        }
    });

    tempColumn = new TableViewerColumn(aTable, SWT.NONE);
    tempColumn.getColumn().setText("Value");
    tempColumn.getColumn().setWidth(150);
    tempColumn.getColumn().setResizable(true);
    tempColumn.getColumn().setMoveable(false);
    tempColumn.setLabelProvider(new ColumnLabelProvider() {
        @Override
        public String getText(Object anElement) {
            SetListEntry tempEntry = (SetListEntry) anElement;
            return (String) tempEntry.getAttribute(SetListEntryAttributeKeys.VALUE);
        }
    });
}

From source file:de.innot.avreclipse.ui.views.supportedmcu.URLColumnLabelProvider.java

License:Open Source License

public void selectionChanged(SelectionChangedEvent event) {
    // Stupid - at least on Windows an external Selection change via the
    // TableViewer.setSelection() method does not cause a Selection event in
    // the underlying Table, so we have to with the SelectionChangeEvent of
    // the TableViewer.

    // When the selection has changed, first a previously selected
    // TableEditor (which still has its "selected" colors) needs to be
    // changed to the unselected colors.
    //// ww w  .j av a2 s.c  o m
    // Then all TableEditors of this column need to recalculate their
    // layout,
    // because the (programmatic) selection change might change the visible
    // part of the Table, which the TableEditors won't notice (again stupid)

    TableViewer source = (TableViewer) event.getSource();
    Table table = source.getTable();
    TableItem item = table.getItem(table.getSelectionIndex());

    // Restore the previously selected link
    if (fLastEditor != null) {
        setEditorColors(fLastEditor, false, false);
    }

    TableEditor editor = fTableEditors.get(item);
    if (editor != null) {
        setEditorColors(editor, true, item.getParent().isFocusControl());
        fLastEditor = editor;
    }

    // Update all Editors. This is called twice, because at - least on
    // windows - clicking on a partially visible row will cause the table to
    // scroll *after* the selection has been made (which -again- the
    // TableEditors will not be aware of, as this partial scroll is without
    // Scroll Events.
    // The 0,5 sec value is just a guess. It works on my PentiumM 1,6 GHz
    // Laptop for a redraw after a partial scroll without much lag.
    // The TableEditor uses 1,5 sec in a similar situation (for a resize),
    // but that caused the update to lag far behind the partial scroll
    // (making the TableEditor hang behind the other Columns.
    // However, if this value is to short, it will cause the TableEditor to
    // be off by one row.
    Display display = item.getDisplay();
    display.syncExec(updateEditors);
    display.timerExec(500, updateEditors);
}

From source file:de.itemis.tooling.terminology.ui.search.TerminologyEObjectSearchDialog.java

License:Open Source License

@Override
protected Label createMessageArea(Composite parent2) {
    Label label = super.createMessageArea(parent2);
    searchControl = new Text(parent2, SWT.BORDER | SWT.SEARCH | SWT.ICON_CANCEL);
    setDefaultGridData(searchControl);//from   w ww .  j av a  2 s.c om

    SelectionAdapter selectionListener = new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            applyFilter();
        }
    };

    initSearchScopeSettings(parent2, selectionListener);
    initCustomersProductsSettings(parent2, selectionListener);

    Composite labelComposite = new Composite(parent2, SWT.NONE);
    setDefaultGridData(labelComposite);
    GridLayout labelCompositeLayout = new GridLayout(2, true);
    labelCompositeLayout.marginWidth = 0;
    labelComposite.setLayout(labelCompositeLayout);
    matchingElementsLabel = new Label(labelComposite, SWT.NONE);
    matchingElementsLabel.setText("Searching...");
    matchingElementsLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
    searchStatusLabel = new Label(labelComposite, SWT.RIGHT);
    searchStatusLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));

    ModifyListener textModifyListener = new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            applyFilter();
        }
    };
    searchControl.addModifyListener(textModifyListener);

    searchControl.addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
            if (e.keyCode == SWT.ARROW_DOWN) {
                definitionControl.setFocus();
            }
        }
    });

    definitionControl.addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
            if (e.keyCode == SWT.ARROW_DOWN) {
                TableViewer tableViewer = getTableViewer();
                tableViewer.getTable().setFocus();
                if (tableViewer.getSelection().isEmpty()) {
                    Object firstElement = tableViewer.getElementAt(0);
                    if (firstElement != null) {
                        tableViewer.setSelection(new StructuredSelection(firstElement));
                    }
                }
            }
        }
    });

    if (initialPatternText != null) {
        searchControl.setText(initialPatternText);
        searchControl.selectAll();
    }
    readSettings();
    return label;
}

From source file:de.marw.cdt.cmake.core.ui.DefinesViewer.java

License:Open Source License

private TableViewer createViewer(Composite parent) {
    TableViewer viewer = new TableViewer(parent,
            SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION);

    createColumns(parent, viewer);/*from  w w  w.  j  ava2  s  .  c o m*/

    final Table table = viewer.getTable();
    table.setHeaderVisible(true);
    table.setLinesVisible(true);

    viewer.setContentProvider(new CmakeDefineTableContentProvider());
    viewer.setLabelProvider(new CmakeVariableLabelProvider());

    // Layout the viewer
    GridData gridData = new GridData();
    gridData.verticalAlignment = GridData.FILL;
    //    gridData.horizontalSpan = 2;
    gridData.grabExcessHorizontalSpace = true;
    gridData.grabExcessVerticalSpace = true;
    gridData.horizontalAlignment = GridData.FILL;
    viewer.getControl().setLayoutData(gridData);
    return viewer;
}