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:com.astra.ses.spell.gui.views.controls.SplitPanel.java

License:Open Source License

/***************************************************************************
 * Test method// w  w  w.  j a v a 2 s.co  m
 * @param args
 **************************************************************************/
public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);

    final SplitPanel panel = new SplitPanel(shell, true, 20, 50, Section.SECOND);

    // 1. THE CONTAINER
    GridLayout l = new GridLayout();
    l.numColumns = 1;
    shell.setLayout(l);
    panel.setLayoutData(new GridData(GridData.FILL_BOTH));

    panel.getSection(Section.FIRST).setLayout(new GridLayout());
    panel.getSection(Section.SECOND).setLayout(new GridLayout());

    TableViewer viewer = new TableViewer(panel.getSection(Section.FIRST), SWT.NONE);
    Table table = viewer.getTable();

    TableColumn c1 = new TableColumn(table, SWT.NONE);
    c1.setText("Idx");
    c1.setWidth(15);
    TableColumn c2 = new TableColumn(table, SWT.NONE);
    c2.setText("Description");
    c2.setWidth(120);

    for (int idx = 0; idx < 10; idx++) {
        TableItem item = new TableItem(table, SWT.NONE);
        item.setText(0, Integer.toString(idx));
        item.setText(1, "This is the item " + idx);
    }

    Button button1 = new Button(panel.getSection(Section.FIRST), SWT.PUSH);
    button1.setText("Button 1");
    button1.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    button1.addSelectionListener(new SelectionListener() {
        public void widgetDefaultSelected(SelectionEvent e) {
        };

        public void widgetSelected(SelectionEvent e) {
            if (panel.getSection(Section.SECOND).getChildren().length > 5) {
                Control[] cld = panel.getSection(Section.SECOND).getChildren();
                cld[cld.length - 1].dispose();
            } else {
                Button newButton = new Button(panel.getSection(Section.SECOND), SWT.PUSH);
                newButton.setText("New button");
            }
            panel.computeSection(Section.SECOND);
        }
    });

    panel.computeSection(Section.FIRST);

    Button button2 = new Button(panel.getSection(Section.SECOND), SWT.PUSH);
    button2.setText("Button 2");
    button2.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    panel.computeSection(Section.SECOND);

    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:com.astra.ses.spell.gui.views.controls.watchvariables.WatchVariablesMenuManager.java

License:Open Source License

/***************************************************************************
 * Constructor/*from  w  ww .  j a  v a 2s  .c o m*/
 * 
 * @param parent
 **************************************************************************/
public WatchVariablesMenuManager(TableViewer viewer, WatchVariablesPage page) {
    m_viewer = viewer;
    m_page = page;
    m_menu = new Menu(viewer.getTable());
    m_menu.addMenuListener(new MenuListener() {

        @Override
        public void menuShown(MenuEvent e) {
            fillMenu();
        }

        @Override
        public void menuHidden(MenuEvent e) {
        }
    });
    viewer.getTable().setMenu(m_menu);
}

From source file:com.astra.ses.spell.tabbed.ui.editor.TabularEditor.java

License:Open Source License

/***************************************************************************
 * Configure table layout//from  www . j  a  va 2  s  . c  o  m
 * Default table settings are:
 *    - Number of columns depending on the input
 *  - Table cells are editable
 *  - Table columns have same width
 *  - Table columns resize to fit width
 **************************************************************************/
protected void configureTable(TableViewer tableViewer) {
    /*
     * Columns layout
     */
    int numColumns = m_input.getColumnCount();

    tableViewer.setContentProvider(new TabularContentProvider(numColumns));
    tableViewer.setLabelProvider(new TabularLabelProvider(TabularEditorInput.COMMENT));

    /*
     * TABLE CONFIGURATION
     */
    Table table = tableViewer.getTable();
    // TABLE LAYOUT
    GridData viewerData = new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL);
    table.setLayoutData(viewerData);
    // PRESENTATION PROPERTIES
    table.setLinesVisible(linesVisible());
    // Add a control listener to adjust columns width to the table width
    table.addControlListener(new ControlListener() {
        @Override
        public void controlMoved(ControlEvent e) {
        }

        @Override
        public void controlResized(ControlEvent e) {
            Table table = (Table) e.widget;
            Rectangle area = table.getClientArea();
            int newTotalWidth = area.width;
            int oldTotalWidth = 0;
            for (TableColumn column : table.getColumns()) {
                oldTotalWidth += column.getWidth();
            }
            for (TableColumn column : table.getColumns()) {
                int oldWidth = column.getWidth();
                int newWidth = (newTotalWidth * oldWidth) / oldTotalWidth;
                column.setWidth(newWidth);
            }
        }
    });
    /*
     * Table cursor for being able to select table cells with the keyboard
     */
    m_cursor = new TableCursor(table, SWT.BORDER_SOLID);
    // CONTROL EDITOR FOR SHOWING A TEXT WIDGET INSIDE THE CURSOR
    m_cellEditor = new ControlEditor(m_cursor);
    m_cellEditor.grabHorizontal = true;
    m_cellEditor.grabVertical = true;
    /*
     * Selection listener
     */
    m_cursor.addSelectionListener(new SelectionListener() {
        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            /*TableCursor cursor = (TableCursor) e.widget;
            Table table = (Table) cursor.getParent();
            table.setSelection(new TableItem[] {cursor.getRow()});*/
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            stopEdition();
            updatePresentation();
        }
    });
    /*
     * add mouse listener for single click, double click events
     */
    m_cursor.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseDoubleClick(MouseEvent e) {
            startEdition();
        }
    });
    /*
     * Insert a new row when CTRL+Enter is pressed
     * Give focus to the cell editor when pressing enter
     */
    KeyAdapter adapter = new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            // If Control key is pressed
            if ((e.stateMask & SWT.CTRL) != 0) {
                if (e.character == SWT.CR) // new row
                {
                    insertRow();
                } else if (e.character == SWT.DEL) // delete row
                {
                    deleteRow();
                } else if (e.keyCode == 'c' || e.keyCode == 'C') // copy cell
                {
                    copy();
                } else if (e.keyCode == 'v' || e.keyCode == 'V') // paste cell
                {
                    paste();
                } else if (e.keyCode == 'x' || e.keyCode == 'X') // cut cell
                {
                    cut();
                }
            }
            //Clear cell content
            else if (e.character == SWT.DEL) {
                clearCell();
            }
            // If enter is pressed, the cell should be edited
            else if (e.character == SWT.CR) {
                startEdition();
            }
        }
    };
    m_cursor.addKeyListener(adapter);
    // There is need to add the listener to the table when the table has not 
    // any row, so the cursor is not enabled
    table.addKeyListener(adapter);

    String[] colNames = m_input.getColumnNames();

    for (int i = 0; i < numColumns; i++) {
        TableColumn column = new TableColumn(table, SWT.LEFT);
        column.setText(colNames[i]);
        column.setWidth(200);
        column.setResizable(true);
    }

    /*
     * Create popup menu for the table
     */
    TableEditorMenuManager popupMenu = new TableEditorMenuManager(m_table, m_cursor, m_clipboard);
    final Menu menu = popupMenu.createContextMenu(table);
    menu.addMenuListener(new MenuListener() {
        @Override
        public void menuHidden(MenuEvent e) {
        }

        @Override
        public void menuShown(MenuEvent e) {
            for (MenuItem item : menu.getItems()) {
                item.setEnabled(item.isEnabled());
            }
        }

    });
    m_cursor.setMenu(menu);
    table.setMenu(menu);
}

From source file:com.astra.ses.spell.tabbed.ui.views.TabularView.java

License:Open Source License

@Override
public void createPartControl(Composite parent) {
    GridLayout parentLayout = new GridLayout(1, true);
    parentLayout.marginHeight = 0;/*ww  w .  ja v  a 2 s . co m*/
    parentLayout.marginWidth = 0;
    parent.setLayout(parentLayout);

    TableViewer table = new TableViewer(parent, SWT.VIRTUAL | SWT.H_SCROLL | SWT.V_SCROLL);

    TabbedFileParser parser = new TabbedFileParser(m_filePath, COMMENT);
    ArrayList<String[]> m_tabbedModel = parser.getTabbedText();
    int columns = parser.getLongestLength();

    for (int i = 0; i < columns; i++) {
        TableColumn column = new TableColumn(table.getTable(), SWT.LEFT);
        column.setText(String.valueOf(i));
        column.setWidth(350);
        column.setResizable(true);
    }
    if (m_headerNames != null) {
        table.setColumnProperties(m_headerNames);
    }
    table.setContentProvider(new TabularContentProvider(columns));
    table.setLabelProvider(new TabularLabelProvider(COMMENT));

    GridData viewerData = new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL);
    table.getTable().setLayoutData(viewerData);
    table.getTable().setLinesVisible(true);

    table.setInput(m_tabbedModel);
}

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

License:Open Source License

@SuppressWarnings("unused")
private void createTopicViewer(Composite composite) {
    ExpandCollapseGroup expandCollapseGroup = null;
    if (parser.hasSubtopics()) {
        expandCollapseGroup = new ExpandCollapseGroup(composite, SWT.NONE);
        TreeViewer treeViewer = new TreeViewer(composite,
                SWT.SINGLE | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
        expandCollapseGroup.setViewer((TreeViewer) topicViewer);
        treeViewer.getTree().setLinesVisible(true);
        treeViewer.getTree().setHeaderVisible(true);
        if (!parser.isByName())
            createTreeColumn(treeViewer, 120, Messages.CodesDialog_code, 0);
        createTreeColumn(treeViewer, 150, Messages.CodesDialog_name, 1);
        createTreeColumn(treeViewer, 300, Messages.CodesDialog_explanation, 2);
        UiUtilities.installDoubleClickExpansion(treeViewer);
        topicViewer = treeViewer;//from  w w  w.j a v a2  s  .  co  m
    } else {
        new Label(composite, SWT.NONE);
        TableViewer tableViewer = new TableViewer(composite,
                SWT.SINGLE | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
        tableViewer.getTable().setLinesVisible(true);
        tableViewer.getTable().setHeaderVisible(true);
        if (!parser.isByName())
            createTableColumn(tableViewer, 120, Messages.CodesDialog_code, 0);
        createTableColumn(tableViewer, 150, Messages.CodesDialog_name, 1);
        createTableColumn(tableViewer, 300, Messages.CodesDialog_explanation, 2);
        tableViewer.addDoubleClickListener(doubleClickListener);
        topicViewer = tableViewer;
    }
    GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
    layoutData.heightHint = 300;
    topicViewer.getControl().setLayoutData(layoutData);
    topicViewer.setContentProvider(new TopicContentProvider());
    if (parser.isByName())
        new SortColumnManager(recentViewer, new int[] { SWT.UP, SWT.UP }, 0);
    else
        new SortColumnManager(recentViewer, new int[] { SWT.UP, SWT.UP, SWT.UP }, 1);
    topicViewer.setComparator(ZViewerComparator.INSTANCE);
    topicViewer.setFilters(new ViewerFilter[] { new TopicFilter(true, exclusions) });
    topicViewer.addSelectionChangedListener(selectionChangedListener);
    ZColumnViewerToolTipSupport.enableFor(topicViewer);
}

From source file:com.bdaum.zoom.ui.internal.views.BookmarkView.java

License:Open Source License

private TableViewerColumn createColumn(final TableViewer tViewer, String lab, int w) {
    final TableViewerColumn column = new TableViewerColumn(tViewer, SWT.NONE);
    column.getColumn().setText(lab);/*from   w  w w  .ja v  a 2  s .c  o  m*/
    column.getColumn().setWidth(w);
    column.getColumn().addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            switchSort(tViewer.getTable(), column.getColumn());
        }
    });
    return column;
}

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

License:Apache License

/**
 * Create the license text editor component
 * /* ww  w.  j a va  2 s .com*/
 * @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/*from  w  w w  .j  a  v  a 2 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.buglabs.dragonfly.ui.wizards.bugProject.BUGModuleServiceBindingPage.java

License:Open Source License

public void createControl(Composite parent) {
    try {/* w  ww .j  a v a  2 s  .c o  m*/
        Composite mainComposite = new Composite(parent, SWT.NONE);
        GridLayout layout = new GridLayout(1, false);
        mainComposite.setLayout(layout);
        mainComposite.setLayoutData(new GridData(GridData.FILL_BOTH));

        Composite msComp = new Composite(mainComposite, SWT.None);
        msComp.setLayout(new GridLayout(2, false));
        msComp.setLayoutData(new GridData(GridData.FILL_BOTH));

        final TableViewer moduleViewer = new TableViewer(msComp, SWT.BORDER | SWT.V_SCROLL);
        moduleViewer.getTable().setLayoutData(getModuleViewerLayoutData());
        moduleViewer.setContentProvider(new BUGStaticServiceContentProvider());
        moduleViewer.setLabelProvider(new BUGStaticServiceLabelProvider());
        //Load the bug module model from static data provided in the plugin.
        moduleModel = BUGModule.load(getModuleModel());
        moduleViewer.setInput(moduleModel);

        Composite rComp = new Composite(msComp, SWT.None);
        rComp.setLayout(UIUtils.StripGridLayoutMargins(new GridLayout()));
        rComp.setLayoutData(new GridData(GridData.FILL_BOTH));

        serviceViewer = new CheckboxTableViewer(createServiceTable(rComp));
        serviceViewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
        serviceViewer.setContentProvider(new BUGServiceContentProvider());
        serviceViewer.setLabelProvider(new BUGServiceLabelProvider());
        serviceViewer.setInput(null);
        serviceViewer.addCheckStateListener(new ICheckStateListener() {

            public void checkStateChanged(CheckStateChangedEvent event) {
                BUGModuleService bms = (BUGModuleService) ((IStructuredSelection) serviceViewer.getSelection())
                        .getFirstElement();
                if (bms != null) {
                    bms.setSelected(event.getChecked());
                }
                updateModel();
            }
        });

        final Text serviceDescText = new Text(rComp, SWT.MULTI | SWT.WRAP);
        serviceDescText.setLayoutData(getDescriptionLabelLayoutData());
        serviceDescText.setBackground(
                PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW));

        moduleViewer.addSelectionChangedListener(new ISelectionChangedListener() {
            public void selectionChanged(SelectionChangedEvent event) {
                BUGModule bm = (BUGModule) ((IStructuredSelection) moduleViewer.getSelection())
                        .getFirstElement();
                serviceViewer.setInput(bm);
                serviceDescText.setText(bm.getDescription());
                for (BUGModuleService bms : bm.getServices()) {
                    if (bms.isSelected())
                        serviceViewer.setChecked(bms, true);
                }
            }
        });

        serviceViewer.addSelectionChangedListener(new ISelectionChangedListener() {

            public void selectionChanged(SelectionChangedEvent event) {
                BUGModuleService bms = (BUGModuleService) ((IStructuredSelection) serviceViewer.getSelection())
                        .getFirstElement();
                if (bms != null) {
                    if (bms.getDescription() == null) {
                        serviceDescText.setText("");
                    } else {
                        serviceDescText.setText(bms.getDescription());
                    }
                } else {
                    serviceDescText.setText("");
                }
            }
        });

        setControl(mainComposite);
    } catch (IOException e) {
        UIUtils.handleVisualError("Failed to load module data.", e);
    }
}

From source file:com.contrastsecurity.ide.eclipse.ui.internal.preferences.ContrastPreferencesPage.java

License:Open Source License

private TableViewer createTableViewer(Composite composite) {
    TableViewer tableViewer = new TableViewer(composite,
            SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    tableViewer.getTable().setLayoutData(gd);

    tableViewer.getTable().setHeaderVisible(true);
    tableViewer.getTable().setLinesVisible(true);
    tableViewer.setContentProvider(ArrayContentProvider.getInstance());
    TableLayout layout = new TableLayout();
    tableViewer.getTable().setLayout(layout);

    TableColumn orgNameColumn = new TableColumn(tableViewer.getTable(), SWT.NONE);
    orgNameColumn.setText("Organization");
    orgNameColumn.setWidth(180);//w ww.j av  a2  s. c o m

    String[] list = ContrastCoreActivator.getOrganizationList();
    tableViewer.setInput(list);

    if (list.length > 0) {
        String orgName = ContrastCoreActivator.getDefaultOrganization();
        if (orgName != null && !orgName.isEmpty()) {
            tableViewer.getTable().setSelection(ArrayUtils.indexOf(list, orgName));
        } else {
            tableViewer.getTable().setSelection(0);
        }

    }

    return tableViewer;
}