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

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

Introduction

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

Prototype

@Override
    public Control getControl() 

Source Link

Usage

From source file:com.bdaum.zoom.ui.internal.dialogs.ConfigureColumnsDialog.java

License:Open Source License

private TableViewer createColumnTable(Composite composite) {
    final TableViewer viewer = new TableViewer(composite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    viewer.setLabelProvider(ZColumnLabelProvider.getDefaultInstance());
    viewer.setContentProvider(ArrayContentProvider.getInstance());
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            updateButtons();//from   ww w  .ja v  a 2s.  c  om
        }
    });
    return viewer;
}

From source file:com.bmw.spdxeditor.editors.spdx.SPDXEditor.java

License:Apache License

/**
 * Create the license text editor component
 * // w  w w.j  a v a 2  s .co m
 * @param parent
 * @return
 * @throws InvalidSPDXAnalysisException
 */
private Group createLicenseTextEditor(Composite parent) throws InvalidSPDXAnalysisException {
    Group licenseTextEditorGroup = new Group(parent, SWT.SHADOW_ETCHED_IN);
    licenseTextEditorGroup.setText("Licenses referenced in SPDX file");
    GridLayout licenseTextEditorGroupLayout = new GridLayout();
    licenseTextEditorGroupLayout.numColumns = 2;
    licenseTextEditorGroup.setLayout(licenseTextEditorGroupLayout);

    // Add table viewer
    final TableViewer tableViewer = new TableViewer(licenseTextEditorGroup,
            SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);

    // The list of available extracted license texts
    final Table table = tableViewer.getTable();
    table.setToolTipText("Right click to add/remove licenses.");

    // Build a drop down menu to add/remove licenses
    Menu licenseTableMenu = new Menu(parent.getShell(), SWT.POP_UP);
    MenuItem addNewLicenseText = new MenuItem(licenseTableMenu, SWT.PUSH);
    addNewLicenseText.setText("Add license text");

    addNewLicenseText.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            // Retrieve the corresponding Services
            IHandlerService handlerService = (IHandlerService) getSite().getService(IHandlerService.class);
            ICommandService commandService = (ICommandService) getSite().getService(ICommandService.class);

            // Retrieve the command
            Command generateCmd = commandService.getCommand("SPDXEditor.addNewLicenseText");

            // Create an ExecutionEvent
            ExecutionEvent executionEvent = handlerService.createExecutionEvent(generateCmd, new Event());

            // Launch the command
            try {
                generateCmd.executeWithChecks(executionEvent);
            } catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException e1) {
                MessageDialog.openError(getSite().getShell(), "Execution failed", e1.getMessage());
            }
        }
    });

    // Listen for changes on model
    this.getInput().addChangeListener(new IResourceChangeListener() {
        @Override
        public void resourceChanged(IResourceChangeEvent event) {
            try {
                SPDXNonStandardLicense[] nonStandardLicenses = getInput().getAssociatedSPDXFile()
                        .getExtractedLicenseInfos();
                tableViewer.setInput(nonStandardLicenses);
                tableViewer.refresh();
                loadLicenseDataFromSPDXFile();

                setLicenseComboBoxValue(concludedLicenseChoice,
                        getInput().getAssociatedSPDXFile().getSpdxPackage().getConcludedLicenses());

                //               populateLicenseSelectorWithAvailableLicenses(declaredLicenseChoice);
                setLicenseComboBoxValue(declaredLicenseChoice,
                        getInput().getAssociatedSPDXFile().getSpdxPackage().getDeclaredLicense());
                setDirtyFlag(true);
            } catch (InvalidSPDXAnalysisException e) {
                e.printStackTrace();
            }
        }
    });

    final MenuItem deleteSelectedLicenseTexts = new MenuItem(licenseTableMenu, SWT.PUSH);
    deleteSelectedLicenseTexts.setText("Delete licenses");
    deleteSelectedLicenseTexts.setEnabled(false);

    tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            // Never enable, not yet implemented
            // deleteSelectedLicenseTexts.setEnabled(table.getSelectionCount()
            // != 0);
        }
    });

    table.setMenu(licenseTableMenu);

    // Make headers and borders visible
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    tableViewer.setContentProvider(ArrayContentProvider.getInstance());

    // Create TableViewerColumn for each column
    TableViewerColumn viewerNameColumn = new TableViewerColumn(tableViewer, SWT.NONE);
    viewerNameColumn.getColumn().setText("License ID");
    viewerNameColumn.getColumn().setWidth(100);

    // Set LabelProvider for each column
    viewerNameColumn.setLabelProvider(new CellLabelProvider() {
        @Override
        public void update(ViewerCell cell) {
            SPDXNonStandardLicense licenseInCell = (SPDXNonStandardLicense) cell.getElement();
            cell.setText(licenseInCell.getId());
        }
    });

    viewerNameColumn = new TableViewerColumn(tableViewer, SWT.NONE);
    viewerNameColumn.getColumn().setText("License text");
    viewerNameColumn.getColumn().setWidth(100);

    viewerNameColumn.setLabelProvider(new CellLabelProvider() {
        @Override
        public void update(ViewerCell cell) {
            SPDXNonStandardLicense iteratorLicense = (SPDXNonStandardLicense) cell.getElement();
            cell.setText(iteratorLicense.getText());
        }
    });

    /*
     * All ExtractedLicensingInfo is contained in the SPDX file assigned to
     * the input.
     */
    tableViewer.setInput(getInput().getAssociatedSPDXFile().getExtractedLicenseInfos());

    GridData spdxDetailsPanelGridData = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
    spdxDetailsPanelGridData.horizontalSpan = 1;
    spdxDetailsPanelGridData.heightHint = 150;
    licenseTextEditorGroup.setLayoutData(spdxDetailsPanelGridData);

    GridData gridData = new GridData();
    gridData.verticalAlignment = GridData.FILL;
    gridData.grabExcessHorizontalSpace = true;
    gridData.grabExcessVerticalSpace = true;
    gridData.horizontalAlignment = GridData.FILL;
    gridData.horizontalSpan = 1;
    gridData.heightHint = 100;
    gridData.minimumWidth = 70;
    tableViewer.getControl().setLayoutData(gridData);

    /*
     * Text editor field for editing license texts.
     */
    final Text licenseEditorText = new Text(licenseTextEditorGroup,
            SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    licenseEditorText.setText("");
    licenseEditorText.setEditable(true);
    GridData gd = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
    gd.minimumHeight = 70;
    gd.minimumWidth = 200;
    gd.heightHint = 100;
    gd.horizontalSpan = 1;
    licenseEditorText.setLayoutData(gd);
    licenseEditorText.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(ModifyEvent e) {
            try {
                SPDXNonStandardLicense[] nonStandardLicenses;
                nonStandardLicenses = getInput().getAssociatedSPDXFile().getExtractedLicenseInfos();
                nonStandardLicenses[table.getSelectionIndex()].setText(licenseEditorText.getText());
                setDirtyFlag(true);
            } catch (InvalidSPDXAnalysisException e1) {
                MessageDialog.openError(getSite().getShell(), "SPDX Analysis error", e1.getMessage());
            }
        }
    });

    /*
     * Listener for updating text editor selection based on selected table
     * entry.
     */
    table.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            SPDXNonStandardLicense[] nonStandardLicenses;
            try {
                nonStandardLicenses = getInput().getAssociatedSPDXFile().getExtractedLicenseInfos();
                licenseEditorText.setText(nonStandardLicenses[table.getSelectionIndex()].getText());
            } catch (InvalidSPDXAnalysisException e1) {
                MessageDialog.openError(getSite().getShell(), "SPDX Analysis invalid", e1.getMessage());
            }
        }
    });

    // Style group panel
    GridData licenseTextEditorGroupGridData = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
    licenseTextEditorGroupGridData.horizontalSpan = 2;
    licenseTextEditorGroup.setLayoutData(licenseTextEditorGroupGridData);

    return licenseTextEditorGroup;
}

From source file:com.bmw.spdxeditor.editors.spdx.SPDXEditor.java

License:Apache License

/**
 * Create the linked files group panel// ww  w.  jav a2  s .c  om
 * 
 * @param parent
 * @return
 * @throws InvalidSPDXAnalysisException
 */
private Composite createLinkedFilesDetailsPanel(Composite parent) throws InvalidSPDXAnalysisException {
    Group linkedFilesDetailsGroup = new Group(parent, SWT.SHADOW_ETCHED_IN);
    linkedFilesDetailsGroup.setText("Referenced files");
    GridLayout linkedFilesDetailsGroupLayout = new GridLayout();
    linkedFilesDetailsGroup.setLayout(linkedFilesDetailsGroupLayout);

    // Add table viewer
    final TableViewer tableViewer = new TableViewer(linkedFilesDetailsGroup,
            SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);

    GridData gridData = new GridData();
    gridData.verticalAlignment = GridData.FILL;
    gridData.horizontalAlignment = GridData.FILL;
    gridData.heightHint = 80;
    gridData.grabExcessHorizontalSpace = true;
    gridData.grabExcessVerticalSpace = true;
    tableViewer.getControl().setLayoutData(gridData);

    // SWT Table
    final Table table = tableViewer.getTable();

    table.setToolTipText("Right-click to add or remove files");

    // Make header and columns visible
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    tableViewer.setContentProvider(ArrayContentProvider.getInstance());

    // Add context menu to TableViewer
    Menu linkesFileTableMenu = new Menu(parent.getShell(), SWT.POP_UP);
    MenuItem addNewLicenseText = new MenuItem(linkesFileTableMenu, SWT.PUSH);
    addNewLicenseText.setText("Add source code archive");
    addNewLicenseText.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            // Retrieve the corresponding Services
            IHandlerService handlerService = (IHandlerService) getSite().getService(IHandlerService.class);
            ICommandService commandService = (ICommandService) getSite().getService(ICommandService.class);

            // Retrieve the command
            Command generateCmd = commandService.getCommand("SPDXEditor.addLinkedSourceCodeFile");

            // Create an ExecutionEvent
            ExecutionEvent executionEvent = handlerService.createExecutionEvent(generateCmd, new Event());

            // Launch the command
            try {
                generateCmd.executeWithChecks(executionEvent);
            } catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException e1) {
                MessageDialog.openError(getSite().getShell(), "Error", e1.getMessage());
            }

        }
    });

    final MenuItem deleteSelectedLicenseTexts = new MenuItem(linkesFileTableMenu, SWT.PUSH);
    deleteSelectedLicenseTexts.setText("Delete selected source code archive");
    deleteSelectedLicenseTexts.setEnabled(false);
    deleteSelectedLicenseTexts.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            // Retrieve the corresponding Services
            IHandlerService handlerService = (IHandlerService) getSite().getService(IHandlerService.class);
            ICommandService commandService = (ICommandService) getSite().getService(ICommandService.class);
            // Retrieve the command
            Command generateCmd = commandService.getCommand("SPDXEditor.removedLinkedSourceCodeFile");
            // Create an ExecutionEvent
            ExecutionEvent executionEvent = handlerService.createExecutionEvent(generateCmd, new Event());
            // Launch the command
            try {
                generateCmd.executeWithChecks(executionEvent);
            } catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException e1) {
                MessageDialog.openError(getSite().getShell(), "Error", e1.getMessage());
            }
        }
    });

    table.setMenu(linkesFileTableMenu);
    tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            deleteSelectedLicenseTexts.setEnabled(table.getSelectionCount() != 0);
        }
    });

    // Create TableViewer for each column
    TableViewerColumn viewerNameColumn = new TableViewerColumn(tableViewer, SWT.NONE);
    viewerNameColumn.getColumn().setText("File name");
    viewerNameColumn.getColumn().setWidth(160);

    viewerNameColumn.setLabelProvider(new CellLabelProvider() {
        @Override
        public void update(ViewerCell cell) {
            SPDXFile currentFile = (SPDXFile) cell.getElement();
            cell.setText(currentFile.getName());
        }
    });

    viewerNameColumn = new TableViewerColumn(tableViewer, SWT.NONE);
    viewerNameColumn.getColumn().setText("Type");
    viewerNameColumn.getColumn().setWidth(120);

    viewerNameColumn.setLabelProvider(new CellLabelProvider() {
        @Override
        public void update(ViewerCell cell) {
            SPDXFile currentFile = (SPDXFile) cell.getElement();
            cell.setText(currentFile.getType());
        }
    });
    // License choice for file
    viewerNameColumn = new TableViewerColumn(tableViewer, SWT.NONE);
    viewerNameColumn.getColumn().setText("Concluded License");
    viewerNameColumn.getColumn().setWidth(120);

    // // LabelProvider fr jede Spalte setzen
    viewerNameColumn.setLabelProvider(new CellLabelProvider() {
        @Override
        public void update(ViewerCell cell) {
            SPDXFile currentFile = (SPDXFile) cell.getElement();
            SPDXLicenseInfo spdxConcludedLicenseInfo = currentFile.getConcludedLicenses();
            cell.setText(getLicenseIdentifierTextForLicenseInfo(spdxConcludedLicenseInfo));

        }
    });

    viewerNameColumn = new TableViewerColumn(tableViewer, SWT.NONE);
    viewerNameColumn.getColumn().setText("SHA1 hash");
    viewerNameColumn.getColumn().setWidth(120);

    // LabelProvider fr jede Spalte setzen
    viewerNameColumn.setLabelProvider(new CellLabelProvider() {
        @Override
        public void update(ViewerCell cell) {
            SPDXFile currentFile = (SPDXFile) cell.getElement();
            cell.setText(currentFile.getSha1());
        }
    });

    SPDXFile[] referencedFiles = getInput().getAssociatedSPDXFile().getSpdxPackage().getFiles();
    tableViewer.setInput(referencedFiles);
    getSite().setSelectionProvider(tableViewer);

    this.getInput().addChangeListener(new IResourceChangeListener() {
        @Override
        public void resourceChanged(IResourceChangeEvent event) {
            SPDXFile[] referencedFiles;
            try {
                referencedFiles = getInput().getAssociatedSPDXFile().getSpdxPackage().getFiles();
                tableViewer.setInput(referencedFiles);
                tableViewer.refresh();
                setDirtyFlag(true);
            } catch (InvalidSPDXAnalysisException e) {
                MessageDialog.openError(getSite().getShell(), "SPDX Analysis invalid", e.getMessage());
            }
        }
    });

    GridData spdxDetailsPanelGridData = new GridData(SWT.FILL, SWT.BEGINNING, true, true);
    spdxDetailsPanelGridData.horizontalSpan = 1;

    spdxDetailsPanelGridData.grabExcessVerticalSpace = true;
    spdxDetailsPanelGridData.grabExcessHorizontalSpace = true;
    spdxDetailsPanelGridData.minimumHeight = 90;
    linkedFilesDetailsGroup.setLayoutData(spdxDetailsPanelGridData);

    return linkedFilesDetailsGroup;
}

From source file:com.hilotec.elexis.messwerte.v2.views.MessungenUebersichtV21.java

License:Open Source License

private void initializeContent() {
    tableViewers.clear();/*from   w  ww  .  j av a  2 s.c  o  m*/
    config.readFromXML();
    for (MessungTyp t : config.getTypes()) {
        TableViewer tv = createTableViewer(tabfolder, t);
        Control c = tv.getControl();
        c.setData(DATA_TYP, t);
        c.setData(DATA_VIEWER, tv);
        tableViewers.add(tv);
        CTabItem ti = new CTabItem(tabfolder, SWT.NONE);
        ti.setText(t.getTitle());
        ti.setControl(c);
        tv.setInput(null);
        tv.addDoubleClickListener(new IDoubleClickListener() {
            public void doubleClick(DoubleClickEvent event) {
                editAktion.run();
            }
        });
        ViewMenus menu = new ViewMenus(getViewSite());
        menu.createControlContextMenu(tv.getControl(), editAktion, copyAktion, loeschenAktion, neuAktion,
                exportAktion);
    }
    tabfolder.setSelection(0);
}

From source file:com.hilotec.elexis.messwerte.v2.views.MessungenUebersichtV21.java

License:Open Source License

private void refreshContent(Patient patient, MessungTyp requestedTyp) {

    if (patient != null) {
        if (form.getCursor() == null)
            form.setCursor(new Cursor(form.getShell().getDisplay(), SWT.CURSOR_WAIT));

        form.setText(patient.getLabel());
        tabfolder.setData(DATA_PATIENT, patient);

        MessungTyp typToRefresh = requestedTyp;
        TableViewer viewerToRefresh = null;

        for (TableViewer tv : tableViewers) {
            Control c = tv.getControl();
            if (!c.isDisposed()) {
                MessungTyp typ = (MessungTyp) c.getData(DATA_TYP);

                // bei unbekannten typen (z.B. bei reloadXML) einfach den ersten refreshen
                if (typToRefresh == null) {
                    typToRefresh = typ;/*from  w  ww  .  j  ava2  s .c om*/
                    viewerToRefresh = tv;
                    break;
                } else {
                    if (requestedTyp.getName().equals(typ.getName())) {
                        typToRefresh = typ;
                        viewerToRefresh = tv;
                        break;
                    }
                }
            }
        }
        if (viewerToRefresh != null) {
            viewerToRefresh.setInput(Messung.getPatientMessungen(patient, typToRefresh));
        }
        if (form.getCursor() != null)
            form.setCursor(null);
    }
}

From source file:com.hilotec.elexis.messwerte.v2.views.MessungenUebersichtV21.java

License:Open Source License

private TableViewer createTableViewer(Composite parent, MessungTyp t) {
    TableViewer viewer = new TableViewer(parent,
            SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
    createColumns(parent, viewer, t);//from w  w w.  j  av a2 s.c  om
    final Table table = viewer.getTable();
    table.setHeaderVisible(true);
    table.setLinesVisible(true);

    viewer.setContentProvider(new ArrayContentProvider());

    // Make the selection available to other views
    getSite().setSelectionProvider(viewer);
    // Set the sorter for the table

    // 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);
    viewer.setComparator(new MessungenComparator());
    return viewer;
}

From source file:com.ibm.etools.mft.conversion.esb.editor.parameter.ConversionEditor.java

License:Open Source License

protected void createOptionTable(final ScrolledForm form) {

    final TableViewer viewer = new TableViewer(form.getBody(), SWT.BORDER | SWT.FULL_SELECTION);
    viewer.getTable().setHeaderVisible(true);
    viewer.getTable().setLinesVisible(true);
    GridData data = new GridData(GridData.FILL_BOTH);
    data.heightHint = 130;/*from  w  w  w .  java  2  s.co  m*/
    viewer.getControl().setLayoutData(data);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new OptionLabelProvider());
    viewer.addDoubleClickListener(this);

    for (int i = 0; i < COLUMN_HEADINGS.length; i++) {
        TableColumn column = new TableColumn(viewer.getTable(), SWT.None);
        column.setText(COLUMN_HEADINGS[i]);
        column.setResizable(true);
        column.setWidth(WIDTHES[i]);
    }
    viewer.setColumnProperties(PROPERTIES);

    optionViewer = viewer;
}

From source file:com.ibm.etools.mft.conversion.esb.editor.parameter.GlobalOptionsEditor.java

License:Open Source License

protected TableViewer createConverterSection(final ScrolledForm form, String sectionTitle, String sectionDesc,
        String[] columnHeadings, String[] columnProperties, int[] columnWidthes,
        final String classSelectionMessage, ILabelProvider labelProvider, final Class baseClass) {
    Section section = getToolkit().createSection(form.getBody(),
            Section.DESCRIPTION | Section.TITLE_BAR | Section.TWISTIE | Section.EXPANDED);
    TableWrapData td = new TableWrapData(TableWrapData.FILL_GRAB);
    td.colspan = 1;/*from ww w  . j a v a2s  .  co m*/
    section.setLayoutData(td);
    section.addExpansionListener(new ExpansionAdapter() {
        public void expansionStateChanged(ExpansionEvent e) {
            form.reflow(true);
        }
    });
    section.setText(sectionTitle);
    section.setDescription(sectionDesc);
    Composite sectionClient = getToolkit().createComposite(section);
    sectionClient.setLayout(new GridLayout(2, false));
    section.setClient(sectionClient);

    final TableViewer viewer = new TableViewer(sectionClient, SWT.BORDER | SWT.FULL_SELECTION);
    viewer.getTable().setHeaderVisible(true);
    viewer.getTable().setLinesVisible(true);
    GridData data = new GridData(GridData.FILL_BOTH);
    data.heightHint = 130;
    viewer.getControl().setLayoutData(data);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(labelProvider);
    viewer.addDoubleClickListener(this);
    viewer.setSorter(new ViewerSorter() {
        @Override
        public int compare(Viewer viewer, Object e1, Object e2) {
            Converter c1 = (Converter) e1;
            Converter c2 = (Converter) e2;
            return c1.getType().compareTo(c2.getType());
        }
    });

    for (int i = 0; i < columnHeadings.length; i++) {
        TableColumn column = new TableColumn(viewer.getTable(), SWT.None);
        column.setText(columnHeadings[i]);
        column.setResizable(true);
        column.setWidth(columnWidthes[i]);
    }
    viewer.setColumnProperties(columnProperties);

    viewer.setCellEditors(
            new CellEditor[] { null, null, null, new DialogCellEditor((Composite) viewer.getControl()) {
                @Override
                protected Object openDialogBox(Control cellEditorWindow) {
                    Converter converter = (Converter) ((IStructuredSelection) viewer.getSelection())
                            .getFirstElement();
                    ClassSelectionDialog d = new ClassSelectionDialog(cellEditorWindow.getShell(),
                            (ClassDefinition) getValue(), converter.getType(), classSelectionMessage,
                            baseClass);
                    if (d.open() == ClassSelectionDialog.OK) {
                        if (d.getClazz() == null) {
                            return d.getModel();
                        }
                        if (d.getClazz().length() == 0) {
                            doSetValue(null);
                            return null;
                        }
                        ClassDefinition def = new ClassDefinition();
                        def.setResourceType(d.getResourceType());
                        def.setResourcePath(d.getResourcePath());
                        def.setClazz(d.getClazz());
                        return def;
                    }
                    return d.getModel();
                }

                protected void updateContents(Object value) {
                    if (value != null) {
                        if (value != null && value.toString().length() == 0) {
                            value = WESBConversionMessages.GlobalOptionsEditor_defaultConverter;
                        } else if (value instanceof ClassDefinition) {
                            value = ((ClassDefinition) value).getClazz();
                        }
                    } else {
                        ClassDefinition oldValue = null;
                        if (converterBeingEditted != null) {
                            oldValue = converterBeingEditted.getClazz();
                            converterBeingEditted.setClazz(null);
                        }
                        try {
                            if (converterBeingEditted instanceof PrimitiveConverter) {
                                IPrimitiveConverter ci = PrimitiveManager
                                        .getConverter(converterBeingEditted.getType(), null, getModel());
                                String s = ci.getClass().getName();
                                value = PrimitiveManager.getConverterDisplayName(s);
                            } else if (converterBeingEditted instanceof BindingConverter) {
                                IBindingConverter ci = BindingManager
                                        .getConverter(converterBeingEditted.getType(), null, getModel());
                                String s = ci.getClass().getName();
                                value = BindingManager.getConverterDisplayName(s);
                            }
                        } catch (Exception e) {
                            value = ""; //$NON-NLS-1$
                        } finally {
                            if (converterBeingEditted != null) {
                                converterBeingEditted.setClazz(oldValue);
                            }
                        }
                    }
                    super.updateContents(value);
                }
            } });
    viewer.setCellModifier(new ICellModifier() {

        @Override
        public void modify(Object element, String property, Object value) {
            TableItem ti = (TableItem) element;
            Converter c = (Converter) ti.getData();
            c.setClazz((ClassDefinition) value);
            viewer.refresh(c);
            changed();
        }

        @Override
        public Object getValue(Object element, String property) {
            Converter c = (Converter) element;
            converterBeingEditted = (Converter) element;
            return c.getClazz();
        }

        @Override
        public boolean canModify(Object element, String property) {
            if ("Converter Class".equals(property)) { //$NON-NLS-1$
                return true;
            }
            return false;
        }

    });

    FocusCellOwnerDrawHighlighter highlighter = new FocusCellOwnerDrawHighlighter(viewer);

    if (WESBConversionMessages.GlobalOptionsEditor_primitiveConverters.equals(sectionTitle))
        primitiveHighlighter = highlighter;
    else if (WESBConversionMessages.GlobalOptionsEditor_bindingConverters.equals(sectionTitle))
        bindingHighlighter = highlighter;

    TableViewerFocusCellManager focusCellManager = new TableViewerFocusCellManager(viewer, highlighter);

    ColumnViewerEditorActivationStrategy activationSupport = new ColumnViewerEditorActivationStrategy(viewer) {

        @Override
        protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {

            return event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL
                    || event.eventType == ColumnViewerEditorActivationEvent.MOUSE_CLICK_SELECTION
                    || (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED
                            && event.keyCode == SWT.CR)
                    || event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
        }
    };

    activationSupport.setEnableEditorActivationWithKeyboard(true);

    TableViewerEditor.create(viewer, focusCellManager, activationSupport,
            ColumnViewerEditor.TABBING_HORIZONTAL | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR
                    | ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEYBOARD_ACTIVATION);

    return viewer;
}

From source file:com.iw.plugins.spindle.ui.wizards.source.MoveImplicitAttributesPage.java

License:Mozilla Public License

private void handleLeftRightChange(Viewer fromViewer, Object changeObject) {

    IStructuredSelection selection = null;
    if (changeObject instanceof ISelection) {

        selection = (IStructuredSelection) changeObject;
    } else {//  ww  w  . j  a  va  2  s .  c  om

        selection = new StructuredSelection(changeObject);
    }

    List fromList = null;
    List toList = null;
    TableViewer toViewer = null;
    if (fromViewer == fAttributesThatStayViewer) {

        fromList = fAttributesThatStay;
        toList = fAttributesThatMove;
        toViewer = fAttributesThatMoveViewer;
    } else {

        fromList = fAttributesThatMove;
        toList = fAttributesThatStay;
        toViewer = fAttributesThatStayViewer;
    }

    if (!selection.isEmpty()) {

        List selectedObjects = selection.toList();
        fromList.removeAll(selectedObjects);
        toList.addAll(selectedObjects);
        fromViewer.setInput(fromList);
        toViewer.setInput(toViewer);
        toViewer.getControl().setFocus();
        toViewer.setSelection(selection);
    }
    updateButtonsEnabled();
    updateStatus();
}

From source file:com.iw.plugins.spindle.wizards.migrate.DefinePagesComponentsPage.java

License:Mozilla Public License

private void handleChange(Viewer fromViewer, Object changeObject) {

    IStructuredSelection selection = null;
    if (changeObject instanceof ISelection) {

        selection = (IStructuredSelection) changeObject;
    } else {/* w ww . j  av  a2s .com*/

        selection = new StructuredSelection(changeObject);
    }

    List fromList = null;
    List toList = null;
    TableViewer toViewer = null;
    if (fromViewer == componentViewer) {

        fromList = componentList;
        toList = pageList;
        toViewer = pageViewer;
    } else {

        fromList = pageList;
        toList = componentList;
        toViewer = componentViewer;
    }

    if (!selection.isEmpty()) {

        List selectedObjects = selection.toList();
        fromList.removeAll(selectedObjects);
        toList.addAll(selectedObjects);
        fromViewer.setInput(fromList);
        toViewer.setInput(toViewer);
        toViewer.getControl().setFocus();
        toViewer.setSelection(selection);
        updateButtonsEnabled();
    }
}