Example usage for org.eclipse.jface.viewers ViewerCell getElement

List of usage examples for org.eclipse.jface.viewers ViewerCell getElement

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers ViewerCell getElement.

Prototype

public Object getElement() 

Source Link

Document

Get the element this row represents.

Usage

From source file:com.blackducksoftware.integration.eclipseplugin.views.providers.DependencyTreeViewLabelProvider.java

License:Apache License

@Override
public void update(ViewerCell cell) {
    super.update(cell);
    cell.setText(getText(cell.getElement()));
    cell.setImage(getImage(cell.getElement()));
    styleCell(cell);/*from  w ww  . j av  a 2s . c  o  m*/
}

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

License:Apache License

/**
 * Create the license text editor component
 * //  w ww .ja v  a  2s .  c o 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//from w ww  . j  a  va 2s . c  o m
 * 
 * @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.cloudbees.eclipse.run.ui.wizards.ClickStartComposite.java

License:Open Source License

private void init() {

    GridLayout layout = new GridLayout(1, false);
    layout.marginHeight = 0;/*from w  ww.j  a v  a2 s.c om*/
    layout.marginWidth = 0;
    layout.horizontalSpacing = 0;
    layout.verticalSpacing = 0;
    layout.marginTop = 10;
    setLayout(layout);

    GridData d1 = new GridData();
    d1.horizontalSpan = 1;
    d1.grabExcessHorizontalSpace = true;
    d1.grabExcessVerticalSpace = true;
    d1.horizontalAlignment = SWT.FILL;
    d1.verticalAlignment = SWT.FILL;
    setLayoutData(d1);

    Group group = new Group(this, SWT.FILL);
    group.setText(GROUP_LABEL);

    GridLayout grl = new GridLayout(1, false);
    grl.horizontalSpacing = 0;
    grl.verticalSpacing = 0;
    grl.marginHeight = 0;
    grl.marginWidth = 0;
    grl.marginTop = 4;
    group.setLayout(grl);

    GridData data = new GridData();
    data.horizontalSpan = 1;
    data.grabExcessHorizontalSpace = true;
    data.grabExcessVerticalSpace = true;
    data.horizontalAlignment = SWT.FILL;
    data.verticalAlignment = SWT.FILL;
    group.setLayoutData(data);

    /*   this.addTemplateCheck = new Button(group, SWT.CHECK);
       this.addTemplateCheck.setText(FORGE_REPO_CHECK_LABEL);
       this.addTemplateCheck.setSelection(false);
       this.addTemplateCheck.setLayoutData(data);
       this.addTemplateCheck.addSelectionListener(new MakeForgeRepoSelectionListener());
            
       data = new GridData();
       data.verticalAlignment = SWT.CENTER;
            
       this.templateLabel = new Label(group, SWT.NULL);
       this.templateLabel.setLayoutData(data);
       this.templateLabel.setText("Template:");
       this.templateLabel.setEnabled(false);
            
       data = new GridData();
       data.grabExcessHorizontalSpace = true;
       data.horizontalAlignment = SWT.FILL;
            
       this.templateCombo = new Combo(group, SWT.DROP_DOWN | SWT.BORDER | SWT.READ_ONLY);
       this.templateCombo.setLayoutData(data);
       this.templateCombo.setEnabled(false);
       this.repoComboViewer = new ComboViewer(this.templateCombo);
       this.repoComboViewer.setLabelProvider(new TemplateLabelProvider());
       this.repoComboViewer.addSelectionChangedListener(new ISelectionChangedListener() {
            
         public void selectionChanged(final SelectionChangedEvent event) {
           ISelection selection = ClickStartComposite.this.repoComboViewer.getSelection();
           if (selection instanceof StructuredSelection) {
     ClickStartComposite.this.selectedTemplate = (ClickStartTemplate) ((StructuredSelection) selection)
         .getFirstElement();
           }
           validate();
         }
       });*/
    /*
            
    Composite compositeJenkinsInstances = new Composite(group, SWT.NONE);
    compositeJenkinsInstances.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    GridLayout gl_compositeJenkinsInstances = new GridLayout(2, false);
    gl_compositeJenkinsInstances.marginWidth = 0;
    compositeJenkinsInstances.setLayout(gl_compositeJenkinsInstances);
    */
    Composite compositeTable = new Composite(group, SWT.NONE);
    compositeTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    GridLayout gl_compositeTable = new GridLayout(1, false);
    gl_compositeTable.marginHeight = 0;
    gl_compositeTable.marginWidth = 0;
    compositeTable.setLayout(gl_compositeTable);

    v = new TableViewer(compositeTable, SWT.BORDER | SWT.FULL_SELECTION);
    v.getTable().setLinesVisible(true);
    v.getTable().setHeaderVisible(true);
    v.setContentProvider(templateProvider);
    v.setInput("");

    v.getTable().setLayout(new GridLayout(1, false));

    GridData vgd = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
    v.getTable().setLayoutData(vgd);
    ColumnViewerToolTipSupport.enableFor(v, ToolTip.NO_RECREATE);

    CellLabelProvider labelProvider = new CellLabelProvider() {

        public String getToolTipText(Object element) {
            ClickStartTemplate t = (ClickStartTemplate) element;
            return t.description;
        }

        public Point getToolTipShift(Object object) {
            return new Point(5, 5);
        }

        public int getToolTipDisplayDelayTime(Object object) {
            return 200;
        }

        public int getToolTipTimeDisplayed(Object object) {
            return 10000;
        }

        public void update(ViewerCell cell) {
            int idx = cell.getColumnIndex();
            ClickStartTemplate t = (ClickStartTemplate) cell.getElement();
            if (idx == 0) {
                cell.setText(t.name);
            } else if (idx == 1) {
                String comps = "";

                for (int i = 0; i < t.components.length; i++) {
                    comps = comps + t.components[i].name;
                    if (i < t.components.length - 1) {
                        comps = comps + ", ";
                    }
                }
                cell.setText(comps);
            }

        }

    };

    /*    this.table = new Table(compositeTable, SWT.BORDER | SWT.FULL_SELECTION);
        this.table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
        this.table.setHeaderVisible(true);
        this.table.setLinesVisible(true);
    */
    v.getTable().addSelectionListener(new SelectionListener() {

        public void widgetSelected(final SelectionEvent e) {
            selectedTemplate = (ClickStartTemplate) e.item.getData();
            ClickStartComposite.this.fireTemplateChanged();
        }

        public void widgetDefaultSelected(final SelectionEvent e) {
            selectedTemplate = (ClickStartTemplate) e.item.getData();
            ClickStartComposite.this.fireTemplateChanged();
        }
    });

    //ColumnViewerToolTipSupport

    TableViewerColumn tblclmnLabel = new TableViewerColumn(v, SWT.NONE);
    tblclmnLabel.getColumn().setWidth(300);
    tblclmnLabel.getColumn().setText("Template");//TODO i18n
    tblclmnLabel.setLabelProvider(labelProvider);

    TableViewerColumn tblclmnUrl = new TableViewerColumn(v, SWT.NONE);
    tblclmnUrl.getColumn().setWidth(800);
    tblclmnUrl.getColumn().setText("Components");//TODO i18n
    tblclmnUrl.setLabelProvider(labelProvider);

    loadData();

    //Group group2 = new Group(this, SWT.NONE);
    //group2.setText("");
    //group2.setLayout(ld2);
    GridData data2 = new GridData();
    data2.horizontalSpan = 1;
    data2.grabExcessHorizontalSpace = true;
    //data2.grabExcessVerticalSpace = true;
    data2.horizontalAlignment = SWT.FILL;
    //data2.verticalAlignment = SWT.FILL;
    //group2.setLayoutData(data2);

    browser = new Browser(this, SWT.NONE);
    //browser.getVerticalBar().setVisible(false);
    //browser.getHorizontalBar().setVisible(false);

    GridLayout ld2 = new GridLayout(2, true);
    ld2.horizontalSpacing = 0;
    ld2.verticalSpacing = 0;
    ld2.marginHeight = 0;
    ld2.marginWidth = 0;

    GridData gd2 = new GridData(SWT.FILL, SWT.FILL);
    gd2.heightHint = 50;
    gd2.horizontalSpan = 1;
    gd2.grabExcessHorizontalSpace = true;
    gd2.grabExcessVerticalSpace = false;
    gd2.horizontalAlignment = SWT.FILL;

    browser.setLayout(ld2);
    browser.setLayoutData(gd2);

    Color bg = this.getBackground();
    bgStr = "rgb(" + bg.getRed() + "," + bg.getGreen() + "," + bg.getBlue() + ")";

    browser.setText("<html><head><style>body{background-color:" + bgStr
            + ";margin:0px;padding:0px;width:100%;}</style></head><body style='overflow:hidden;'></body></html>");

    //shell.open();

    //browser.setUrl("https://google.com");

    browser.addLocationListener(new LocationListener() {

        @Override
        public void changing(LocationEvent event) {
            String url = event.location;
            try {
                if (url != null && url.startsWith("http")) {
                    event.doit = false;
                    PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser().openURL(new URL(url));
                }
            } catch (PartInitException e) {
                e.printStackTrace();
            } catch (MalformedURLException e) {
                e.printStackTrace();
            }
        }

        @Override
        public void changed(LocationEvent event) {
            //event.doit = false;
        }
    });

    v.getTable().setFocus();

    /*    getParent().setBackground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
        setBackground(Display.getDefault().getSystemColor(SWT.COLOR_RED));
        group.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_CYAN));
        v.getTable().setBackground(Display.getDefault().getSystemColor(SWT.COLOR_DARK_GREEN));
        browser.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_DARK_YELLOW));
    */}

From source file:com.contrastsecurity.ide.eclipse.ui.internal.model.TagLabelProvider.java

License:Open Source License

@Override
public void update(ViewerCell cell) {
    Object element = cell.getElement();

    int index = cell.getColumnIndex();
    switch (index) {
    case 0:// w  w w  .j a v a  2  s  .  c  om
        String title = getText(element, index);
        cell.setText(title);
        break;
    case 1:
        // Image image = getImage(index);
        // cell.setImage(image);
        break;
    default:
        break;
    }
    super.update(cell);
}

From source file:com.contrastsecurity.ide.eclipse.ui.internal.model.VulnerabilityLabelProvider.java

License:Open Source License

@Override
public void update(ViewerCell cell) {
    Object element = cell.getElement();
    if (element instanceof Trace) {
        int index = cell.getColumnIndex();
        switch (index) {
        case 0:/*from w w w  . j a  v a2  s  .c om*/
        case 3:
            Image image = getImage(element, index);
            cell.setImage(image);
            break;
        case 1:
            String title = getText(element, index);
            if (title.startsWith(UNLICENSED_PREFIX)) {
                StyledString text = new StyledString();
                StyleRange range = new StyleRange(0, UNLICENSED_PREFIX.length(), Constants.UNLICENSED_COLOR,
                        null);
                text.append(title, StyledString.DECORATIONS_STYLER);
                StyleRange[] ranges = { range };
                cell.setStyleRanges(ranges);
            }
            cell.setText(title);
            break;
        case 2:
            String appName = ((Trace) element).getApplication().getName();
            cell.setText(appName);
            break;
        default:
            break;
        }
        if (index == 0) {

        }
    }
    super.update(cell);
}

From source file:com.dubture.symfony.ui.views.ServiceLabelProvider.java

License:Open Source License

@Override
public void update(ViewerCell cell) {

    Object element = cell.getElement();

    Styler style = null;//from   ww w.  j  a  v a2s  .  co m

    if (element instanceof IProject) {

        IProject project = (IProject) element;
        StyledString styledString = new StyledString(project.getName(), style);
        cell.setText(styledString.toString());
        cell.setImage(PHPPluginImages.get(PHPPluginImages.IMG_OBJS_PHP_PROJECT));

    } else if (element instanceof Service) {

        Service service = (Service) element;
        String name = service.getClassName() != null ? service.getClassName() : service.getId();
        StyledString styledString = new StyledString(name, style);

        String decoration = MessageFormat.format(" [{0}]", new Object[] { service.getId() }); //$NON-NLS-1$
        styledString.append(decoration, StyledString.DECORATIONS_STYLER);

        cell.setText(styledString.toString());
        cell.setStyleRanges(styledString.getStyleRanges());

        if (service.isPublic()) {
            cell.setImage(SymfonyPluginImages.get(SymfonyPluginImages.IMG_OBJS_SERVICE_PUBLIC));
        } else {
            cell.setImage(SymfonyPluginImages.get(SymfonyPluginImages.IMG_OBJS_SERVICE_PRIVATE));
        }

    } else if (element instanceof Bundle) {

        Bundle bundle = (Bundle) element;

        StyledString styledString = new StyledString(bundle.getElementName(), style);
        cell.setText(styledString.toString());
        cell.setImage(SymfonyPluginImages.get(SymfonyPluginImages.IMG_OBJS_BUNDLE2));

    }
}

From source file:com.freescale.deadlockpreventer.agent.StatisticsDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {
    parent.setLayout(new GridLayout(2, false));

    viewer = new TableViewer(parent, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
    GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true);
    layoutData.horizontalSpan = 2;//ww w  .j  a va2  s.co m
    viewer.getTable().setLayoutData(layoutData);
    viewer.setContentProvider(new ViewContentProvider());
    ColumnViewerToolTipSupport.enableFor(viewer, ToolTip.NO_RECREATE);
    viewer.setInput(locks);

    IFocusService service = (IFocusService) PlatformUI.getWorkbench().getService(IFocusService.class);

    service.addFocusTracker(viewer.getTable(), StatisticsDialog.class.getPackage().getName() + ".table");

    viewer.setLabelProvider(new CellLabelProvider() {
        @Override
        public void update(ViewerCell cell) {
            Row element = (Row) cell.getElement();
            if (cell.getColumnIndex() == 0)
                cell.setText(element.id);
            if (cell.getColumnIndex() == 1)
                cell.setText(Integer.toString(element.folllowersCount));
            if (cell.getColumnIndex() == 2)
                cell.setText(Integer.toString(element.precedentsCount));
            if (cell.getColumnIndex() == 3)
                cell.setText(element.location);
        }

        public String getToolTipText(Object element) {
            Row row = (Row) element;
            ILock[] locks = transaction.getLocks(row.index, row.index + 1);
            CharArrayWriter writer = new CharArrayWriter();
            Logger.dumpLockInformation(locks, writer);
            return writer.toString();
        }

        public Point getToolTipShift(Object object) {
            return new Point(5, 5);
        }

        public int getToolTipDisplayDelayTime(Object object) {
            return 2000;
        }

        public int getToolTipTimeDisplayed(Object object) {
            return 5000;
        }
    });

    createTableViewerColumn("Lock", 200, 0);
    createTableViewerColumn("Followers", 70, 1);
    createTableViewerColumn("Precedents", 70, 2);
    createTableViewerColumn("Location", 250, 3);

    viewer.getTable().setHeaderVisible(true);
    viewer.getTable().setLinesVisible(true);

    comparator = new TableViewerComparator();
    viewer.setComparator(comparator);

    Button button = new Button(parent, SWT.PUSH);
    button.setText("Export...");
    layoutData = new GridData(SWT.BEGINNING, SWT.TOP, false, false);
    layoutData.widthHint = 80;
    button.setLayoutData(layoutData);
    button.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            StatisticsUtil.export(transaction);
        }
    });

    Label label = new Label(parent, 0);
    label.setText("Total locks: " + locks.length);
    label.setLayoutData(new GridData(SWT.END, SWT.TOP, false, false));

    return super.createDialogArea(parent);
}

From source file:com.freescale.deadlockpreventer.agent.StatisticsDialog.java

License:Open Source License

private TableViewerColumn createTableViewerColumn(String title, int bound, final int colNumber) {
    final TableViewerColumn viewerColumn = new TableViewerColumn(viewer, SWT.NONE);
    final TableColumn column = viewerColumn.getColumn();
    column.setText(title);//ww w  .j  a va  2 s  . c o m
    column.setWidth(bound);
    column.setResizable(true);
    column.setMoveable(true);
    column.addSelectionListener(getSelectionAdapter(column, colNumber));

    viewerColumn.setLabelProvider(new CellLabelProvider() {
        @Override
        public void update(ViewerCell cell) {
            Row element = (Row) cell.getElement();
            switch (colNumber) {
            case 0:
                cell.setText(element.id);
                break;
            case 1:
                cell.setText(Integer.toString(element.folllowersCount));
                break;
            case 2:
                cell.setText(Integer.toString(element.precedentsCount));
                break;
            case 3:
                cell.setText(element.location);
                break;
            }
        }

        public String getToolTipText(Object element) {
            Row row = (Row) element;
            ILock[] locks = transaction.getLocks(row.index, row.index + 1);
            CharArrayWriter writer = new CharArrayWriter();
            try {
                for (String stack : locks[0].getStackTrace()) {
                    writer.write(stack + "\n");
                }
            } catch (IOException e) {
            }
            return writer.toString();
        }
    });
    return viewerColumn;

}

From source file:com.google.gapid.widgets.MeasuringViewLabelProvider.java

License:Apache License

@Override
public void update(ViewerCell cell) {
    // Adjusted from the DelegatingStyledCellLabelProvider implementation.

    StyledString styledString = format(cell.getItem(), cell.getElement(), LinkableStyledString.ignoring(theme))
            .getString();/*from   w  ww .ja  v a  2 s  .  c  o  m*/
    String newText = styledString.toString();

    StyleRange[] oldStyleRanges = cell.getStyleRanges();
    StyleRange[] newStyleRanges = styledString.getStyleRanges();

    if (!Arrays.equals(oldStyleRanges, newStyleRanges)) {
        cell.setStyleRanges(newStyleRanges);
        if (cell.getText().equals(newText)) {
            cell.setText("");
        }
    }
    Color bgcolor = getBackgroundColor(cell.getElement());
    if (bgcolor != null) {
        cell.setBackground(bgcolor);
    }
    cell.setImage(getImage(cell.getElement()));
    cell.setText(newText);
}