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

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

Introduction

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

Prototype

public int getColumnIndex() 

Source Link

Document

Get the index of the cell.

Usage

From source file:org.eclipse.scada.da.ui.widgets.realtime.ItemCellLabelProvider.java

License:Open Source License

private void updateAttributePair(final AttributePair attributePair, final ViewerCell cell) {
    switch (cell.getColumnIndex()) {
    case 0:/* www.  jav a2  s  .  c  o  m*/
        cell.setText(attributePair.key);
        break;
    case 2:
        if (attributePair.value != null) {
            cell.setText(attributePair.value.getType().name());
        }
        break;
    case 3:
        if (attributePair.value != null) {
            cell.setText(attributePair.value.asString("<null>")); //$NON-NLS-1$
        }
        break;
    default:
        break;
    }
}

From source file:org.eclipse.scada.da.ui.widgets.realtime.ItemCellLabelProvider.java

License:Open Source License

private void updateListEntry(final ListEntry listEntry, final ViewerCell cell) {
    cell.setFont(listEntry.getFont());//from  w w w .  ja v a 2  s . c om
    cell.setForeground(listEntry.getForeground());
    cell.setBackground(listEntry.getBackground());

    switch (cell.getColumnIndex()) {
    case 0:
        cell.setImage(listEntry.getImage());
        cell.setText(listEntry.getDataItem().getItem().getId());
        break;
    case 1:
        if (listEntry.getSubscriptionError() != null) {
            cell.setText(String.format("%s (%s)", listEntry.getSubscriptionState(), //$NON-NLS-1$
                    listEntry.getSubscriptionError().getMessage()));
        } else {
            cell.setText(listEntry.getSubscriptionState().name());
        }
        break;
    case 2:
        if (listEntry.getValue() != null) {
            cell.setText(listEntry.getValue().getType().name());
        }
        break;
    case 3:
        if (listEntry.getValue() != null) {
            cell.setText(listEntry.getValue().asString("<null>")); //$NON-NLS-1$
        }
        break;
    case 4:
        if (listEntry.getItemValue() != null) {
            final Calendar timestamp = listEntry.getItemValue().getTimestamp();
            if (timestamp != null) {
                cell.setText(formatTimestamp(timestamp));
            } else {
                cell.setText(null);
            }
        }
        break;
    default:
        break;
    }
}

From source file:org.eclipse.scada.ide.hd.hdsspy.editors.EntryLabelProvider.java

License:Open Source License

@Override
public void update(final ViewerCell cell) {
    final ArchiveEntry entry = (ArchiveEntry) cell.getElement();

    if (cell.getColumnIndex() == 0) {
        if (entry.isHeartbeat()) {
            if (entry.isDeleted()) {
                cell.setImage(this.resourceManager
                        .createImageWithDefault(Activator.getImageDescriptor("icons/heart-empty.png")));
            } else {
                cell.setImage(this.resourceManager
                        .createImageWithDefault(Activator.getImageDescriptor("icons/heart.png")));
            }/*from  www . j  ava  2s .  c o  m*/
        }
    }

    if (entry.isDeleted()) {
        cell.setForeground(this.resourceManager.createColor(new RGB(128, 128, 128)));
    } else if (entry.isError()) {
        cell.setForeground(this.resourceManager.createColor(new RGB(255, 0, 0)));
    }

    switch (cell.getColumnIndex()) {
    case 0:
        cell.setText(DATE_FORMAT.format(entry.getTimestamp()));
        break;
    case 1:
        cell.setText("" + entry.getValue());
        break;
    case 2:
        cell.setText(makeCheck(entry.isError()));
        break;
    case 3:
        cell.setText(makeCheck(entry.isManual()));
        break;
    case 4:
        cell.setText(makeCheck(entry.isDeleted()));
        break;
    case 5:
        cell.setText(makeCheck(entry.isHeartbeat()));
        break;
    }
}

From source file:org.eclipse.sirius.diagram.ui.tools.internal.views.providers.layers.LayersLabelProvider.java

License:Open Source License

/**
 * {@inheritDoc}/*ww w  .j  a v  a  2  s  . c  o m*/
 * 
 * @see org.eclipse.jface.viewers.ColumnLabelProvider#update(org.eclipse.jface.viewers.ViewerCell)
 */
@Override
public void update(final ViewerCell cell) {
    columnIndex = cell.getColumnIndex();
    super.update(cell);
}

From source file:org.eclipse.stardust.modeling.transformation.messaging.modeling.application.transformation.widgets.DelegatingIndexingLabelProvider.java

License:Open Source License

public void update(ViewerCell cell) {
    cell.setFont(labelProvider.getFont(cell.getElement(), cell.getColumnIndex()));
    cell.setImage(labelProvider.getColumnImage(cell.getElement(), cell.getColumnIndex()));
    cell.setText(labelProvider.getColumnText(cell.getElement(), cell.getColumnIndex()));
}

From source file:org.eclipse.team.svn.ui.composite.ResourceSelectionComposite.java

License:Open Source License

public void createControls() {
    GridLayout gridLayout = null;
    GridData data = null;//from  ww  w .j  a v a2 s .co m

    gridLayout = new GridLayout();
    gridLayout.marginHeight = gridLayout.marginWidth = 0;
    this.setLayout(gridLayout);

    int style = SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER;
    Table table = new Table(this, this.showCheckBoxesAndButtons ? style | SWT.CHECK : style);
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    TableLayout layout = new TableLayout();
    table.setLayout(layout);

    this.tableViewer = new CheckboxTableViewer(table);
    data = new GridData(GridData.FILL_BOTH);
    this.tableViewer.getTable().setLayoutData(data);

    // creating a comparator right now to get column listeners
    ResourcesTableComparator comparator = new ResourcesTableComparator(this.tableViewer);

    // checkbox
    TableColumn col = new TableColumn(table, SWT.NONE);
    col.setResizable(false);
    layout.addColumnData(new ColumnPixelData(20, false));

    // resource name
    col = new TableColumn(table, SWT.NONE);
    col.setResizable(true);
    col.setText(SVNUIMessages.ResourceSelectionComposite_Resource);
    layout.addColumnData(new ColumnWeightData(44, true));
    col.addSelectionListener(comparator);

    // status
    col = new TableColumn(table, SWT.NONE);
    col.setResizable(true);
    col.setText(SVNUIMessages.ResourceSelectionComposite_Content);
    layout.addColumnData(new ColumnWeightData(12, true));
    if (this.cacheEnabled) {
        col.addSelectionListener(comparator);
    }

    // propstatus
    col = new TableColumn(table, SWT.NONE);
    col.setResizable(true);
    col.setText(SVNUIMessages.ResourceSelectionComposite_Properties);
    layout.addColumnData(new ColumnWeightData(12, true));
    if (this.cacheEnabled) {
        col.addSelectionListener(comparator);
    }

    TableColumn treatAsEdit = null;
    if (this.allowTreatAsEditsColumn) {
        treatAsEdit = col = new TableColumn(table, SWT.NONE);
        col.setResizable(false);
        col.setText(SVNUIMessages.ResourceSelectionComposite_TreatAsEdit);
        layout.addColumnData(new ColumnWeightData(12, true));
    }

    // adding comparator and selection default sorting column and direction
    this.tableViewer.setComparator(comparator);
    comparator.setColumnNumber(ResourceSelectionComposite.COLUMN_STATUS);
    this.tableViewer.getTable()
            .setSortColumn(this.tableViewer.getTable().getColumn(ResourceSelectionComposite.COLUMN_STATUS));
    this.tableViewer.getTable().setSortDirection(SWT.UP);

    this.tableViewer.setLabelProvider(new ITableLabelProvider() {
        public Image getColumnImage(Object element, int columnIndex) {
            if (columnIndex == ResourceSelectionComposite.COLUMN_NAME && element instanceof IAdaptable) {
                IWorkbenchAdapter adapter = (IWorkbenchAdapter) ((IAdaptable) element)
                        .getAdapter(IWorkbenchAdapter.class);
                if (adapter == null) {
                    return null;
                }
                ImageDescriptor descriptor = adapter.getImageDescriptor(element);
                if (descriptor == null) {
                    return null;
                }

                boolean hasWarning = false;
                boolean hasError = false;
                try {
                    IResource currentResource = (IResource) element;
                    IMarker[] markers = currentResource.findMarkers(IMarker.PROBLEM, true,
                            IResource.DEPTH_INFINITE);
                    // Errors always with highest priority. So, other severities should be ignored.
                    for (int i = 0; i < markers.length && !hasError; i++) {
                        Integer severity = markers[i] != null
                                ? (Integer) markers[i].getAttribute(IMarker.SEVERITY)
                                : null;
                        if (severity != null) {
                            hasWarning |= severity.intValue() == IMarker.SEVERITY_WARNING;
                            hasError |= severity.intValue() == IMarker.SEVERITY_ERROR;
                        }
                    }
                } catch (CoreException e) {
                    // Markers are inaccessible: do not decorate resource icon
                }

                Image image = ResourceSelectionComposite.this.images.get(descriptor);
                if (image == null) {
                    ResourceSelectionComposite.this.images.put(descriptor, image = descriptor.createImage());
                }
                OverlayedImageDescriptor desc = null;
                if (hasError) {
                    desc = new OverlayedImageDescriptor(image, ResourceSelectionComposite.ERROR_IMAGE_DESC,
                            new Point(16, 16), OverlayedImageDescriptor.BOTTOM | OverlayedImageDescriptor.LEFT);
                } else if (hasWarning) {
                    desc = new OverlayedImageDescriptor(image, ResourceSelectionComposite.WARNING_IMAGE_DESC,
                            new Point(16, 16), OverlayedImageDescriptor.BOTTOM | OverlayedImageDescriptor.LEFT);
                } else {
                    desc = new OverlayedImageDescriptor(image, ResourceSelectionComposite.EMPTY_IMAGE_DESC,
                            new Point(16, 16), OverlayedImageDescriptor.BOTTOM | OverlayedImageDescriptor.LEFT);
                }
                image = this.createImage(desc);

                if (ResourceSelectionComposite.this.externalResources.contains(element)) {
                    desc = new OverlayedImageDescriptor(image, ResourceSelectionComposite.SWITCHED_IMAGE_DESC,
                            new Point(16, 16),
                            OverlayedImageDescriptor.BOTTOM | OverlayedImageDescriptor.RIGHT);
                }
                image = this.createImage(desc);

                return image;
            }
            return null;
        }

        protected Image createImage(OverlayedImageDescriptor descriptor) {
            Image image = ResourceSelectionComposite.this.images.get(descriptor);
            if (image == null) {
                ResourceSelectionComposite.this.images.put(descriptor, image = descriptor.createImage());
            }
            return image;
        }

        public String getColumnText(Object element, int columnIndex) {
            if (columnIndex == ResourceSelectionComposite.COLUMN_CHECKBOX) {
                return ""; //$NON-NLS-1$
            }
            IResource resource = (IResource) element;
            if (columnIndex == ResourceSelectionComposite.COLUMN_NAME) {
                String path = resource.getFullPath().toString();
                return path.startsWith("/") ? path.substring(1) : path; //$NON-NLS-1$
            }
            ILocalResource local = SVNRemoteStorage.instance().asLocalResource(resource);
            if (columnIndex == ResourceSelectionComposite.COLUMN_STATUS) {
                return ResourceSelectionComposite.this.contentStatusAsString(local);
            } else if (columnIndex == ResourceSelectionComposite.COLUMN_PROPSTATUS) {
                return ResourceSelectionComposite.this.propertiesStatusAsString(local);
            }
            return ""; //$NON-NLS-1$
        }

        public void addListener(ILabelProviderListener listener) {
        }

        public void dispose() {
        }

        public boolean isLabelProperty(Object element, String property) {
            return false;
        }

        public void removeListener(ILabelProviderListener listener) {
        }
    });

    if (this.allowTreatAsEditsColumn) {
        // the order is important otherwise the common label provider overrides this one
        TableViewerColumn cbColumn = new TableViewerColumn(this.tableViewer, treatAsEdit);
        cbColumn.setLabelProvider(new ColumnLabelProvider() {
            public void update(ViewerCell cell) {
                IResource resource = (IResource) cell.getElement();
                ILocalResource local = SVNRemoteStorage.instance().asLocalResource(resource);
                if (IStateFilter.SF_PREREPLACEDREPLACED.accept(local)) {
                    TableItem item = (TableItem) cell.getItem();
                    Button button;
                    if (ResourceSelectionComposite.this.treatAsEditButtons.containsKey(cell.getElement())) {
                        button = ResourceSelectionComposite.this.treatAsEditButtons.get(cell.getElement());
                    } else {
                        button = new Button((Composite) cell.getViewerRow().getControl(), SWT.CHECK);
                        button.setData(resource);
                        button.setSelection(ResourceSelectionComposite.this.treatAsEdit.contains(resource));
                        button.setBackground(cell.getBackground());
                        button.addSelectionListener(new SelectionAdapter() {
                            public void widgetSelected(SelectionEvent e) {
                                if (((Button) e.getSource()).getSelection()) {
                                    ResourceSelectionComposite.this.treatAsEdit
                                            .add((IResource) ((Button) e.getSource()).getData());
                                } else {
                                    ResourceSelectionComposite.this.treatAsEdit
                                            .remove((IResource) ((Button) e.getSource()).getData());
                                }
                                ResourceSelectionComposite.this.getTableViewer()
                                        .refresh(((Button) e.getSource()).getData());
                            }
                        });
                        ResourceSelectionComposite.this.treatAsEditButtons.put(resource, button);
                    }
                    TableEditor editor = new TableEditor(item.getParent());
                    editor.grabHorizontal = true;
                    editor.grabVertical = true;
                    editor.setEditor(button, item, cell.getColumnIndex());
                    editor.layout();
                }
            }
        });
    }

    this.tableViewer.setContentProvider(new ArrayStructuredContentProvider());

    this.tableViewer.setInput(this.resources);
    for (int i = 0; i < this.resources.length; i++) {
        this.tableViewer.setChecked(this.resources[i], this.isSelectableResource(this.resources[i]));
    }
    this.updateSelectedResources();

    this.tableViewer.addDoubleClickListener(new IDoubleClickListener() {
        public void doubleClick(DoubleClickEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            final IResource resource = (IResource) selection.getFirstElement();
            IResource[] resources = { resource };
            if (selection.size() == 1 && FileUtility.checkForResourcesPresence(resources,
                    IStateFilter.SF_ANY_CHANGE, IResource.DEPTH_ZERO)) {
                UIMonitorUtility.getDisplay().syncExec(new Runnable() {
                    public void run() {
                        ILocalResource local = SVNRemoteStorage.instance().asLocalResource(resource);
                        if (!IStateFilter.SF_INTERNAL_INVALID.accept(local)) {
                            IRepositoryResource remote = local.isCopied() ? SVNUtility.getCopiedFrom(resource)
                                    : SVNRemoteStorage.instance().asRepositoryResource(resource);
                            remote.setSelectedRevision(
                                    CompareResourcesOperation.getRemoteResourceRevisionForCompare(resource));
                            UIMonitorUtility.doTaskScheduledDefault(
                                    new CompareResourcesOperation(local, remote, true, true));
                        }
                    }
                });
            }
        }
    });

    if (!this.showCheckBoxesAndButtons) {
        return;
    }

    this.tableViewer.addSelectionChangedListener(this.selectionListener = new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            ResourceSelectionComposite.this.updateSelectedResources();

            ResourceSelectionComposite.this.fireResourcesSelectionChanged(
                    new ResourceSelectionChangedEvent(ResourceSelectionComposite.this.selectedResources));

            int selectedNumber = ResourceSelectionComposite.this.selectedResources.length;
            ResourceSelectionComposite.this.lblSelectedResourcesNumber
                    .setText(ResourceSelectionComposite.this.resourceNumberToString(selectedNumber));
        }
    });

    Composite tComposite = new Composite(this, SWT.RIGHT);
    GridLayout gLayout = new GridLayout();
    gLayout.numColumns = 4;
    gLayout.marginWidth = 0;
    tComposite.setLayout(gLayout);
    data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL);
    tComposite.setLayoutData(data);

    Button selectButton = new Button(tComposite, SWT.PUSH);
    selectButton.setText(SVNUIMessages.Button_SelectAll);
    data = new GridData();
    data.widthHint = DefaultDialog.computeButtonWidth(selectButton);
    selectButton.setLayoutData(data);
    SelectionListener listener = new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            ResourceSelectionComposite.this.tableViewer.setAllChecked(true);
            Object[] elements = ResourceSelectionComposite.this.tableViewer.getCheckedElements();
            ResourceSelectionComposite.this.selectionListener.selectionChanged(null);
            ResourceSelectionComposite.this.fireResourcesSelectionChanged(new ResourceSelectionChangedEvent(
                    Arrays.asList(elements).toArray(new IResource[elements.length])));
        }
    };
    selectButton.addSelectionListener(listener);

    Button deselectButton = new Button(tComposite, SWT.PUSH);
    deselectButton.setText(SVNUIMessages.Button_ClearSelection);
    data = new GridData();
    data.widthHint = DefaultDialog.computeButtonWidth(deselectButton);
    deselectButton.setLayoutData(data);
    listener = new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            TableItem[] items = ResourceSelectionComposite.this.tableViewer.getTable().getSelection();
            for (TableItem item : items) {
                ResourceSelectionComposite.this.tableViewer.setChecked(item.getData(), false);
            }
            ResourceSelectionComposite.this.selectionListener.selectionChanged(null);
            ResourceSelectionComposite.this
                    .fireResourcesSelectionChanged(new ResourceSelectionChangedEvent(new IResource[0]));
        }
    };
    deselectButton.addSelectionListener(listener);

    deselectButton = new Button(tComposite, SWT.PUSH);
    deselectButton.setText(SVNUIMessages.Button_ClearAll);
    data = new GridData();
    data.widthHint = DefaultDialog.computeButtonWidth(deselectButton);
    deselectButton.setLayoutData(data);
    listener = new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            ResourceSelectionComposite.this.tableViewer.setAllChecked(false);
            ResourceSelectionComposite.this.selectionListener.selectionChanged(null);
            ResourceSelectionComposite.this
                    .fireResourcesSelectionChanged(new ResourceSelectionChangedEvent(new IResource[0]));
        }
    };
    deselectButton.addSelectionListener(listener);

    Composite lComposite = new Composite(tComposite, SWT.NONE);
    GridLayout lLayout = new GridLayout();
    lLayout.horizontalSpacing = 0;
    lLayout.marginWidth = 0;
    lComposite.setLayout(lLayout);
    data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL);
    lComposite.setLayoutData(data);

    this.lblSelectedResourcesNumber = new Label(lComposite, SWT.RIGHT);
    this.lblSelectedResourcesNumber.setText(this.resourceNumberToString(this.selectedResources.length));
    data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL);
    this.lblSelectedResourcesNumber.setLayoutData(data);
}

From source file:org.eclipse.ui.examples.views.properties.tabbed.logic.properties.Model.ModelOutputFiles.java

License:Open Source License

/**
 * @wbp.parser.entryPoint//w  w w  .  j  av  a 2  s  . c o m
 */
public void createControls(Composite parent, TabbedPropertySheetPage tabbedPropertySheetPage) {
    super.createControls(parent, tabbedPropertySheetPage);

    outputFileNames = new ArrayList<OutputPair>();
    removeButtons = new HashMap<Object, Button>();
    editButtons = new HashMap<Object, Button>();

    final Composite composite = getWidgetFactory().createFlatFormComposite(parent);
    composite.setBounds(28, 10, 900, 252);
    composite.setLayout(null);

    ///------------- output file field
    lblOutputfile = new Label(composite, SWT.NONE);
    lblOutputfile.setBounds(10, 15, 55, 15);
    lblOutputfile.setText("File Name");

    txtOutputFileName = new Text(composite, SWT.BORDER);
    txtOutputFileName.setBounds(105, 15, 300, 21);

    lblNumerOfLines = new Label(composite, SWT.NONE);
    lblNumerOfLines.setBounds(10, 45, 55, 15);
    lblNumerOfLines.setText("lines");

    txtNumberOfLines = new Text(composite, SWT.BORDER);
    txtNumberOfLines.setBounds(105, 45, 50, 21);

    /// minimum size label and textbox
    lblFileSize = new Label(composite, SWT.NONE);
    lblFileSize.setBounds(220, 45, 85, 15);
    lblFileSize.setText("Minimum Size ");

    txtFileSize = new Text(composite, SWT.BORDER);
    txtFileSize.setBounds(320, 45, 50, 21);

    lblBytes = new Label(composite, SWT.NONE);
    lblBytes.setBounds(390, 45, 85, 15);
    lblBytes.setText("Bytes ");

    chkBreakOperation = new Button(composite, SWT.CHECK);
    chkBreakOperation.setBounds(10, 75, 255, 15);
    chkBreakOperation.setText("break the operation ");

    Button btnBrows = new Button(composite, SWT.NONE);
    btnBrows.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {

            FileDialog fileDialog = new FileDialog(composite.getShell());
            // Set the text
            fileDialog.setText("Select File");
            // Set filter on .txt files
            fileDialog.setFilterExtensions(new String[] { "*.*" });
            // Put in a readable name for the filter
            fileDialog.setFilterNames(new String[] { "All Files(*.*)" });
            // Open Dialog and save result of selection
            //             if(!txtWorkingDirectory.getText().trim().equals(""))
            //                fileDialog.setFilterPath(txtWorkingDirectory.getText());             

            String selected = fileDialog.open();
            //btnAddToList.setEnabled(true);
            if (selected != null)
                txtOutputFileName.setText(selected.substring(selected.lastIndexOf("\\") + 1));
            //else btnAddToList.setEnabled(false); 

        }
    });
    btnBrows.setBounds(415, 13, 75, 25);
    btnBrows.setText("brows");

    btnAddToList = new Button(composite, SWT.NONE);

    btnAddToList.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            if (txtOutputFileName.getText().trim().equals(""))
                return;
            OutputPair op = new OutputPair();
            op.setFileName(txtOutputFileName.getText().trim());
            op.setNumberOfLines(txtNumberOfLines.getText().trim());
            op.setMinFileSize(txtFileSize.getText().trim());

            op.setBreakIfHappend(chkBreakOperation.getSelection());

            if (!outputFileNames.contains(op)) {
                outputFileNames.add(op);
                //((ResusModel)getElement()).setInputFileNames((ArrayList<String>)inputFileNames);
                setOutputFiles(outputFileNames);

            } else {
                MessageBox messageBox = new MessageBox(composite.getShell(), SWT.ICON_ERROR | SWT.OK);
                messageBox.setText("Error");
                messageBox.setMessage("Your selected file is already in list");
                System.out.println("errror ");

                return;
            }

            //ListChanged();
            viewer.setInput(outputFileNames);
            viewer.refresh();

        }

    });
    btnAddToList.setBounds(15, 103, 95, 25);
    btnAddToList.setText("Add To List");

    //-----------------------------------------table-------------------
    viewer = new TableViewer(composite, SWT.BORDER | SWT.FULL_SELECTION);

    final Table table_1 = viewer.getTable();
    table_1.setBounds(5, 136, 685, 132);

    viewer.getTable().setHeaderVisible(true);
    viewer.getTable().setLinesVisible(true);
    viewer.setContentProvider(new ArrayContentProvider());

    TableColumn column = new TableColumn(viewer.getTable(), SWT.NONE);
    column.setText(" Row ");
    column.setWidth(50);
    TableViewerColumn rowCol = new TableViewerColumn(viewer, column);
    rowCol.setLabelProvider(new RowNumberLabelProvider());

    column = new TableColumn(viewer.getTable(), SWT.NONE);
    column.setText("File Name");
    column.setWidth(300);
    TableViewerColumn firstNameCol = new TableViewerColumn(viewer, column);
    firstNameCol.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            OutputPair p = (OutputPair) element;
            return p.getFileName();
        }

    });

    column = new TableColumn(viewer.getTable(), SWT.NONE);
    column.setText("Number Of Lines");
    column.setWidth(105);
    TableViewerColumn linesCol = new TableViewerColumn(viewer, column);
    linesCol.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            OutputPair p = (OutputPair) element;
            return p.getNumberOfLines();
        }

    });

    column = new TableColumn(viewer.getTable(), SWT.NONE);
    column.setText("Min File Size");
    column.setWidth(85);
    TableViewerColumn MinFileSizeCol = new TableViewerColumn(viewer, column);
    MinFileSizeCol.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            OutputPair p = (OutputPair) element;
            return p.getMinFileSize();
        }

    });

    column = new TableColumn(viewer.getTable(), SWT.NONE);
    column.setText("Break");
    column.setWidth(50);
    TableViewerColumn breakCol = new TableViewerColumn(viewer, column);
    breakCol.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            OutputPair p = (OutputPair) element;
            return Boolean.toString(p.isBreakIfHappend());
        }

    });

    column = new TableColumn(viewer.getTable(), SWT.NONE);
    column.setText("Remove");
    column.setWidth(80);
    TableViewerColumn actionsNameCol = new TableViewerColumn(viewer, column);

    actionsNameCol.setLabelProvider(new ColumnLabelProvider() {
        //make sure you dispose these buttons when viewer input changes
        //final Map<Object, Button> 

        @Override
        public void update(ViewerCell cell) {

            TableItem item = (TableItem) cell.getItem();
            Button button;
            if (removeButtons.containsKey(cell.getElement())) {
                button = removeButtons.get(cell.getElement());
            } else {
                button = new Button((Composite) cell.getViewerRow().getControl(), SWT.NONE);
                button.setText("Remove");
                final OutputPair pair = (OutputPair) cell.getElement();
                button.addSelectionListener(new SelectionAdapter() {
                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        outputFileNames.remove(pair);

                        ((Button) e.getSource()).dispose();
                        removeButtons.remove(pair);

                        setOutputFiles(outputFileNames);

                        viewer.setInput(outputFileNames);
                        viewer.refresh();
                    }
                });
                removeButtons.put(cell.getElement(), button);
            }
            TableEditor editor = new TableEditor(item.getParent());
            editor.grabHorizontal = true;
            editor.grabVertical = true;
            editor.setEditor(button, item, cell.getColumnIndex());
            editor.layout();
        }

    });

    viewer.setInput(outputFileNames);

    Label lblHelpTip = new Label(composite, SWT.WRAP | SWT.BORDER);
    lblHelpTip.setText(ResusMessages.Model_OutputFiles_information);
    lblHelpTip.setBounds(composite.getBounds().width + composite.getLocation().x, 10, 500, 200);

}

From source file:org.eclipse.wazaabi.engine.swt.commons.views.collections.ColumnManager.java

License:Open Source License

protected void createViewerColumn(final org.eclipse.swt.widgets.Widget w,
        final AbstractColumnDescriptor columnDescriptor, final int columnIndex) {

    ViewerColumn viewerColumn = null;/*from  w w w.jav  a 2  s  . co m*/
    if (w instanceof org.eclipse.swt.widgets.Tree) {
        viewerColumn = new TreeViewerColumn((TreeViewer) collectionView.getViewer(),
                getSWTColumnHeaderStyle(columnDescriptor));

        // TODO : not supported yet
        // viewerColumn.getColumn().setMoveable(true);

        final TreeColumn column = ((TreeViewerColumn) viewerColumn).getColumn();

        column.setText(columnDescriptor.getLabel() != null ? columnDescriptor.getLabel() : "");//$NON-NLS-1$

        if (getSWTWidget() instanceof org.eclipse.swt.widgets.Composite
                && ((org.eclipse.swt.widgets.Composite) getSWTWidget())
                        .getLayout() instanceof AbstractColumnLayout) {
            ColumnLayoutData columnLayoutData = null;
            if (columnDescriptor.eClass() == CoreCollectionsStylesPackage.Literals.COLUMN_DESCRIPTOR)
                columnLayoutData = new ColumnPixelData(((ColumnDescriptor) columnDescriptor).getWidth(),
                        columnDescriptor.isResizable());
            else if (columnDescriptor
                    .eClass() == CoreCollectionsStylesPackage.Literals.WEIGHTED_COLUMN_DESCRIPTOR)
                columnLayoutData = new ColumnWeightData(
                        ((WeightedColumnDescriptor) columnDescriptor).getWeight(),
                        ((WeightedColumnDescriptor) columnDescriptor).getMinimumWidth(),
                        columnDescriptor.isResizable());
            ((AbstractColumnLayout) ((org.eclipse.swt.widgets.Composite) getSWTWidget()).getLayout())
                    .setColumnData(column, columnLayoutData);
        }

    } else if (w instanceof org.eclipse.swt.widgets.Table) {
        viewerColumn = new TableViewerColumn((TableViewer) collectionView.getViewer(),
                getSWTColumnHeaderStyle(columnDescriptor));

        // TODO : not supported yet
        // viewerColumn.getColumn().setMoveable(true);

        ((TableViewerColumn) viewerColumn).getColumn()
                .setText(columnDescriptor.getLabel() != null ? columnDescriptor.getLabel() : "");//$NON-NLS-1$

        final TableColumn column = ((TableViewerColumn) viewerColumn).getColumn();

        column.setText(columnDescriptor.getLabel() != null ? columnDescriptor.getLabel() : "");//$NON-NLS-1$

        if (getSWTWidget() instanceof org.eclipse.swt.widgets.Composite
                && ((org.eclipse.swt.widgets.Composite) getSWTWidget())
                        .getLayout() instanceof AbstractColumnLayout) {
            ColumnLayoutData columnLayoutData = null;
            if (columnDescriptor.eClass() == CoreCollectionsStylesPackage.Literals.COLUMN_DESCRIPTOR)
                columnLayoutData = new ColumnPixelData(((ColumnDescriptor) columnDescriptor).getWidth(),
                        columnDescriptor.isResizable());
            else if (columnDescriptor
                    .eClass() == CoreCollectionsStylesPackage.Literals.WEIGHTED_COLUMN_DESCRIPTOR)
                columnLayoutData = new ColumnWeightData(
                        ((WeightedColumnDescriptor) columnDescriptor).getWeight(),
                        ((WeightedColumnDescriptor) columnDescriptor).getMinimumWidth(),
                        columnDescriptor.isResizable());
            ((AbstractColumnLayout) ((org.eclipse.swt.widgets.Composite) getSWTWidget()).getLayout())
                    .setColumnData(column, columnLayoutData);
        }

    }
    if (viewerColumn != null) {
        if (collectionView.getLabelProvider() instanceof PathSelectorLabelProvider) {
            final PathSelectorLabelProvider labelProvider = (PathSelectorLabelProvider) collectionView
                    .getLabelProvider();
            viewerColumn.setLabelProvider(new ColumnLabelProvider() {

                public String getText(Object element) {
                    return labelProvider.getColumnText(element, columnIndex);
                }

                public Image getImage(Object element) {
                    return labelProvider.getColumnImage(element, columnIndex);
                }

            });
        } else if (collectionView.getLabelProvider() instanceof DynamicLabelProvider) {
            final DynamicLabelProvider labelProvider = (DynamicLabelProvider) collectionView.getLabelProvider();
            viewerColumn.setLabelProvider(new StyledCellLabelProvider() {

                @Override
                public void update(ViewerCell cell) {
                    final Object element = cell.getElement();
                    final int columnIndex = cell.getColumnIndex();
                    final Display display = cell.getControl().getDisplay();
                    cell.setText(labelProvider.getColumnText(element, columnIndex));
                    cell.setImage(labelProvider.getColumnImage(element, columnIndex));
                    final Color foreground = labelProvider.getForegroundColor(element, columnIndex, display);
                    if (foreground != null)
                        cell.setForeground(foreground);
                    final Color background = labelProvider.getBackgroundColor(element, columnIndex, display);
                    if (background != null)
                        cell.setBackground(background);
                    final Font font = labelProvider.getFont(element, columnIndex, display, cell.getFont());
                    if (font != null)
                        cell.setFont(font);
                    super.update(cell);
                }
            });
        } else
            viewerColumn.setLabelProvider(new ColumnLabelProvider() {

                public String getText(Object element) {
                    return element != null ? element.toString() : ""; //$NON-NLS-1$
                }

            });
        if (columnDescriptor.getEditingSupport() != null) {
            DynamicEditingSupport dynamicEditingSupport = new DynamicEditingSupport(this, columnDescriptor);
            dynamicEditingSupports.put(columnDescriptor, dynamicEditingSupport);
            viewerColumn.setEditingSupport(dynamicEditingSupport);
        }
    }

}

From source file:org.eclipse.wst.server.ui.internal.viewers.BaseCellLabelProvider.java

License:Open Source License

public void update(ViewerCell cell) {
    super.update(cell);
    Object element = cell.getElement();
    int index = cell.getColumnIndex();
    cell.setText(getColumnText(element, index));
    Image image = getColumnImage(element, index);
    cell.setImage(image);/*from ww w.java 2 s.  c om*/
}

From source file:org.eclipselabs.e4.tapiji.translator.ui.treeviewer.provider.TreeViewerLabelProvider.java

License:Open Source License

@Override
public void update(final ViewerCell cell) {
    final Object element = cell.getElement();
    final int columnIndex = cell.getColumnIndex();
    cell.setText(this.getColumnText(element, columnIndex));

    /*if (isCrossRefRegion(cell.getText())) {
    cell.setFont(FONT_BOLD);//from  w ww .ja v  a  2s .  c  om
    cell.setBackground(COLOR_CROSSREFERENCE_BACKGROUND);
    cell.setForeground(COLOR_CROSSREFERENCE_FOREGROUND);
    } else {
    cell.setFont(getColumnFont(element, columnIndex));
    cell.setBackground(COLOR_WHITE);
    cell.setForeground(COLOR_BLACK);
    }*/

    if (isSearchEnabled) {
        searchStyle(cell, (Term) element, columnIndex);
    } else {
        cell.setStyleRanges(null);
    }
    super.update(cell);
}