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

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

Introduction

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

Prototype

public void setText(String text) 

Source Link

Document

Set the text for the cell.

Usage

From source file:cc.xuloo.rcputils.properties.PropertyCellLabelProvider.java

License:Open Source License

@Override
public void update(ViewerCell cell) {
    try {/* ww w  .ja  va 2s .c o m*/
        Object rawValue = null;
        if (valueHandler != null) {
            rawValue = valueHandler.getValue(cell.getElement());
            Object formattedValue = rawValue;
            if (valueFormatter != null) {
                formattedValue = valueFormatter.format(rawValue);
            }
            cell.setText(String.valueOf(formattedValue));
        }
        if (cellFormatter != null) {
            cellFormatter.formatCell(cell, rawValue);
        }
    } catch (Exception e) {
        //RcpUtilsPlugin.logException(e);
    }
}

From source file:ch.elexis.core.ui.contacts.preferences.BezugsKontaktSettings.java

License:Open Source License

@Override
protected Control createContents(Composite parent) {
    updateExistingEntriesIds.clear();//from   w ww.  j a  va 2 s.  co m
    Composite container = new Composite(parent, SWT.NULL);
    container.setLayout(new GridLayout(1, false));

    Group group = new Group(container, SWT.NONE);
    group.setLayout(new GridLayout(1, false));
    group.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    group.setText(Messages.Bezugskontakt_Definition);

    Composite composite = new Composite(group, SWT.NONE);
    GridData gd_composite = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
    gd_composite.heightHint = 300;
    composite.setLayoutData(gd_composite);
    TableColumnLayout tcl_composite = new TableColumnLayout();
    composite.setLayout(tcl_composite);

    tableViewer = new TableViewer(composite, SWT.BORDER | SWT.FULL_SELECTION);
    tableViewer.setContentProvider(ArrayContentProvider.getInstance());

    tableBezugsKontaktRelations = tableViewer.getTable();
    tableBezugsKontaktRelations.setHeaderVisible(true);
    tableBezugsKontaktRelations.setLinesVisible(true);

    if (allowEditing) {
        Menu menu = new Menu(tableBezugsKontaktRelations);
        tableBezugsKontaktRelations.setMenu(menu);

        MenuItem mntmAddBezugsKontaktRelation = new MenuItem(menu, SWT.NONE);
        mntmAddBezugsKontaktRelation.setText(Messages.Bezugskontakt_Add);
        mntmAddBezugsKontaktRelation.setImage(Images.IMG_NEW.getImage());
        mntmAddBezugsKontaktRelation.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                BezugsKontaktRelation bezugsKontaktRelation = new BezugsKontaktRelation("",
                        RelationshipType.AGENERIC, RelationshipType.AGENERIC);
                tableViewer.add(bezugsKontaktRelation);
                tableViewer.setSelection(new StructuredSelection(bezugsKontaktRelation));
            }
        });

        MenuItem mntmRemoveBezugsKontaktRelation = new MenuItem(menu, SWT.NONE);
        mntmRemoveBezugsKontaktRelation.setText(Messages.Bezugskontakt_Delete);
        mntmRemoveBezugsKontaktRelation.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                int selectionsIdx = tableViewer.getTable().getSelectionIndex();
                if (selectionsIdx != -1) {
                    boolean ret = MessageDialog.openQuestion(UiDesk.getTopShell(),
                            Messages.Bezugskontakt_ConfirmDelete, Messages.Bezugskontakt_ConfirmDeleteText);
                    if (ret) {
                        tableViewer.getTable().remove(selectionsIdx);
                    }
                }
            }
        });
    }

    TableViewerColumn viewCol = new TableViewerColumn(tableViewer, SWT.NONE);
    TableColumn col = viewCol.getColumn();
    tcl_composite.setColumnData(col, new ColumnWeightData(1, 140));
    col.setText(Messages.BezugsKonktat_Reference);
    col.setToolTipText(Messages.Bezugskontakt_ReferenceTooltip);
    viewCol.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            BezugsKontaktRelation s = (BezugsKontaktRelation) cell.getElement();
            if (s == null)
                return;
            cell.setText(s.getName());
        }
    });
    viewCol.setEditingSupport(new EditingSupport(tableViewer) {

        @Override
        protected void setValue(Object element, Object value) {
            if (element instanceof BezugsKontaktRelation) {
                String newName = String.valueOf(value);
                BezugsKontaktRelation tableData = null;
                for (TableItem tableItem : tableViewer.getTable().getItems()) {
                    tableData = (BezugsKontaktRelation) tableItem.getData();
                    if (tableData != null && !tableData.equals(element) && !tableData.getName().isEmpty()
                            && newName.equalsIgnoreCase(tableData.getName())) {
                        MessageDialog.openError(UiDesk.getTopShell(), "",
                                Messages.Bezugskontakt_NameMustBeUnique);
                        return;
                    }
                }
                BezugsKontaktRelation bezugsKontaktRelation = (BezugsKontaktRelation) element;
                if (!bezugsKontaktRelation.getName().equals(newName)) {
                    bezugsKontaktRelation.setName(newName);
                    getViewer().update(bezugsKontaktRelation, null);
                    openConfirmUpdateExistingData(bezugsKontaktRelation);
                }
            }

        }

        @Override
        protected Object getValue(Object element) {
            if (element instanceof BezugsKontaktRelation) {
                return ((BezugsKontaktRelation) element).getName();
            }
            return null;
        }

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

        @Override
        protected boolean canEdit(Object element) {
            return allowEditing;
        }
    });

    viewCol = new TableViewerColumn(tableViewer, SWT.NONE);
    col = viewCol.getColumn();
    tcl_composite.setColumnData(col, new ColumnWeightData(0, 140));
    col.setText(Messages.Bezugskontakt_RelationFrom);
    viewCol.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            BezugsKontaktRelation s = (BezugsKontaktRelation) cell.getElement();
            if (s == null)
                return;
            cell.setText(LocalizeUtil.getLocaleText(s.getDestRelationType()));
        }
    });
    viewCol.setEditingSupport(new EditingSupport(tableViewer) {

        @Override
        protected void setValue(Object element, Object value) {
            if (element instanceof BezugsKontaktRelation && value instanceof Integer) {
                BezugsKontaktRelation bezugsKontaktRelation = (BezugsKontaktRelation) element;
                RelationshipType[] allRelationshipTypes = RelationshipType.values();
                if ((int) value != -1 && !bezugsKontaktRelation.getDestRelationType()
                        .equals(allRelationshipTypes[(int) value])) {
                    bezugsKontaktRelation.setDestRelationType(allRelationshipTypes[(int) value]);
                    getViewer().update(bezugsKontaktRelation, null);
                    openConfirmUpdateExistingData(bezugsKontaktRelation);
                }
            }

        }

        @Override
        protected Object getValue(Object element) {
            if (element instanceof BezugsKontaktRelation) {
                BezugsKontaktRelation bezugsKontaktRelation = (BezugsKontaktRelation) element;
                RelationshipType relationshipType = bezugsKontaktRelation.getDestRelationType();
                if (relationshipType != null) {
                    return relationshipType.getValue();
                }
            }

            return 0;
        }

        @Override
        protected CellEditor getCellEditor(Object element) {
            return new ComboBoxCellEditor(tableViewer.getTable(), BezugsKontaktAuswahl.getBezugKontaktTypes(),
                    SWT.NONE);
        }

        @Override
        protected boolean canEdit(Object element) {
            return allowEditing;
        }
    });

    viewCol = new TableViewerColumn(tableViewer, SWT.NONE);
    col = viewCol.getColumn();
    tcl_composite.setColumnData(col, new ColumnWeightData(0, 140));
    col.setText(Messages.Bezugskontakt_RelationTo);

    viewCol.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            BezugsKontaktRelation s = (BezugsKontaktRelation) cell.getElement();
            if (s == null)
                return;
            cell.setText(LocalizeUtil.getLocaleText(s.getSrcRelationType()));
        }
    });
    viewCol.setEditingSupport(new EditingSupport(tableViewer) {

        @Override
        protected void setValue(Object element, Object value) {
            if (element instanceof BezugsKontaktRelation && value instanceof Integer) {
                BezugsKontaktRelation bezugsKontaktRelation = (BezugsKontaktRelation) element;
                RelationshipType[] allRelationshipTypes = RelationshipType.values();
                if ((int) value != -1 && !bezugsKontaktRelation.getSrcRelationType()
                        .equals(allRelationshipTypes[(int) value])) {
                    bezugsKontaktRelation.setSrcRelationType(allRelationshipTypes[(int) value]);
                    getViewer().update(bezugsKontaktRelation, null);
                    openConfirmUpdateExistingData(bezugsKontaktRelation);
                }
            }
        }

        @Override
        protected Object getValue(Object element) {
            if (element instanceof BezugsKontaktRelation) {
                BezugsKontaktRelation bezugsKontaktRelation = (BezugsKontaktRelation) element;
                RelationshipType relationshipType = bezugsKontaktRelation.getSrcRelationType();
                if (relationshipType != null) {
                    return relationshipType.getValue();
                }
            }

            return 0;
        }

        @Override
        protected CellEditor getCellEditor(Object element) {
            return new ComboBoxCellEditor(tableViewer.getTable(), BezugsKontaktAuswahl.getBezugKontaktTypes(),
                    SWT.NONE);
        }

        @Override
        protected boolean canEdit(Object element) {
            return allowEditing;
        }
    });
    ;
    tableViewer
            .setInput(loadBezugKonkaktTypes(CoreHub.globalCfg.get(Patientenblatt2.CFG_BEZUGSKONTAKTTYPEN, "")));
    return container;
}

From source file:cideplus.ui.astview.ASTViewLabelProvider.java

License:Open Source License

@Override
public void update(final ViewerCell cell) {
    Object element = cell.getElement();
    //cell.setStyleRanges(new StyleRange[]{new stylera});
    String text = getText(element);
    cell.setText(text);
    Image image = getImage(element);
    cell.setImage(image);//from  ww  w .j  ava  2s . co m
    if (fullBackgroundColor) {
        cell.setBackground(getBackground(element));
    }
    cell.setForeground(getForeground(element));
    cell.setFont(getFont(element));
    cell.setStyleRanges(new StyleRange[] {
            new StyleRange(0, text.length(), getForeground(element), getBackground(element)) });
}

From source file:com.android.ddmuilib.logcat.LogCatMessageLabelProvider.java

License:Apache License

@Override
public void update(ViewerCell cell) {
    Object element = cell.getElement();
    if (!(element instanceof LogCatMessage)) {
        return;/*from  w ww . j  av a2  s .co  m*/
    }
    LogCatMessage m = (LogCatMessage) element;

    String text = getCellText(m, cell.getColumnIndex());
    cell.setText(text);
    cell.setFont(mLogFont);
    cell.setForeground(getForegroundColor(m));
}

From source file:com.android.ide.eclipse.adt.internal.wizards.newxmlfile.AddTranslationDialog.java

License:Open Source License

/** Populates the table with keys and default strings */
private void fillStrings() {
    ResourceManager manager = ResourceManager.getInstance();
    ProjectResources resources = manager.getProjectResources(mProject);
    mExistingLanguages = resources.getLanguages();

    Collection<ResourceItem> items = resources.getResourceItemsOfType(ResourceType.STRING);

    ResourceItem[] array = items.toArray(new ResourceItem[items.size()]);
    Arrays.sort(array);/*from w  w w  .ja v a2 s.  c om*/

    // TODO: Read in the actual XML files providing the default keys here
    // (they can be obtained via ResourceItem.getSourceFileList())
    // such that we can read all the attributes associated with each
    // item, and if it defines translatable=false, or the filename is
    // donottranslate.xml, we can ignore it, and in other cases just
    // duplicate all the attributes (such as "formatted=true", or other
    // local conventions such as "product=tablet", or "msgid="123123123",
    // etc.)

    mTranslations = Maps.newHashMapWithExpectedSize(items.size());
    IBaseLabelProvider labelProvider = new CellLabelProvider() {
        @Override
        public void update(ViewerCell cell) {
            Object element = cell.getElement();
            int index = cell.getColumnIndex();
            ResourceItem item = (ResourceItem) element;
            switch (index) {
            case KEY_COLUMN: {
                // Key
                cell.setText(item.getName());
                return;
            }
            case DEFAULT_TRANSLATION_COLUMN: {
                // Default translation
                ResourceValue value = item.getResourceValue(ResourceType.STRING, mConfiguration, false);

                if (value != null) {
                    cell.setText(value.getValue());
                    return;
                }
                break;
            }
            case NEW_TRANSLATION_COLUMN: {
                // New translation
                String translation = mTranslations.get(item.getName());
                if (translation != null) {
                    cell.setText(translation);
                    return;
                }
                break;
            }
            default:
                assert false : index;
            }
            cell.setText("");
        }
    };

    mTableViewer.setLabelProvider(labelProvider);
    mTableViewer.setContentProvider(new ArrayContentProvider());
    mTableViewer.setInput(array);
}

From source file:com.android.ide.eclipse.gltrace.editors.StateLabelProvider.java

License:Apache License

@Override
public void update(ViewerCell cell) {
    Object element = cell.getElement();
    if (!(element instanceof IGLProperty)) {
        return;/*from w w w.j a  v a  2 s .  c  o  m*/
    }

    IGLProperty prop = (IGLProperty) element;

    String text = getColumnText(prop, cell.getColumnIndex());
    cell.setText(text);

    if (mChangedProperties != null && mChangedProperties.contains(prop)) {
        cell.setForeground(mHighlightForegroundColor);
    } else {
        cell.setForeground(mNormalForegroundColor);
    }
}

From source file:com.android.sdkuilib.internal.widgets.AvdCreationDialog.java

License:Apache License

/**
 * Creates the UI for the hardware properties table.
 * This creates the {@link Table}, and several viewers ({@link TableViewer},
 * {@link TableViewerColumn}) and adds edit support for the 2nd column
 *///from  www  .java2 s  .c o  m
private void createHardwareTable(Composite parent) {
    final Table hardwareTable = new Table(parent, SWT.SINGLE | SWT.FULL_SELECTION);
    GridData gd = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
    gd.widthHint = 200;
    gd.heightHint = 100;
    hardwareTable.setLayoutData(gd);
    hardwareTable.setHeaderVisible(true);
    hardwareTable.setLinesVisible(true);

    // -- Table viewer
    mHardwareViewer = new TableViewer(hardwareTable);
    mHardwareViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            // it's a single selection mode, we can just access the selection index
            // from the table directly.
            mDeleteHardwareProp.setEnabled(hardwareTable.getSelectionIndex() != -1);
        }
    });

    // only a content provider. Use viewers per column below (for editing support)
    mHardwareViewer.setContentProvider(new IStructuredContentProvider() {
        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
            // we can just ignore this. we just use mProperties directly.
        }

        public Object[] getElements(Object arg0) {
            return mProperties.keySet().toArray();
        }

        public void dispose() {
            // pass
        }
    });

    // -- column 1: prop abstract name
    TableColumn col1 = new TableColumn(hardwareTable, SWT.LEFT);
    col1.setText("Property");
    col1.setWidth(150);
    TableViewerColumn tvc1 = new TableViewerColumn(mHardwareViewer, col1);
    tvc1.setLabelProvider(new CellLabelProvider() {
        @Override
        public void update(ViewerCell cell) {
            String name = cell.getElement().toString();
            HardwareProperty prop = mHardwareMap.get(name);
            if (prop != null) {
                cell.setText(prop.getAbstract());
            } else {
                cell.setText(String.format("%1$s (Unknown)", name));
            }
        }
    });

    // -- column 2: prop value
    TableColumn col2 = new TableColumn(hardwareTable, SWT.LEFT);
    col2.setText("Value");
    col2.setWidth(50);
    TableViewerColumn tvc2 = new TableViewerColumn(mHardwareViewer, col2);
    tvc2.setLabelProvider(new CellLabelProvider() {
        @Override
        public void update(ViewerCell cell) {
            String value = mProperties.get(cell.getElement());
            cell.setText(value != null ? value : "");
        }
    });

    // add editing support to the 2nd column
    tvc2.setEditingSupport(new EditingSupport(mHardwareViewer) {
        @Override
        protected void setValue(Object element, Object value) {
            String hardwareName = (String) element;
            HardwareProperty property = mHardwareMap.get(hardwareName);
            switch (property.getType()) {
            case INTEGER:
                mProperties.put((String) element, (String) value);
                break;
            case DISKSIZE:
                if (HardwareProperties.DISKSIZE_PATTERN.matcher((String) value).matches()) {
                    mProperties.put((String) element, (String) value);
                }
                break;
            case BOOLEAN:
                int index = (Integer) value;
                mProperties.put((String) element, HardwareProperties.BOOLEAN_VALUES[index]);
                break;
            }
            mHardwareViewer.refresh(element);
        }

        @Override
        protected Object getValue(Object element) {
            String hardwareName = (String) element;
            HardwareProperty property = mHardwareMap.get(hardwareName);
            String value = mProperties.get(hardwareName);
            switch (property.getType()) {
            case INTEGER:
                // intended fall-through.
            case DISKSIZE:
                return value;
            case BOOLEAN:
                return HardwareProperties.getBooleanValueIndex(value);
            }

            return null;
        }

        @Override
        protected CellEditor getCellEditor(Object element) {
            String hardwareName = (String) element;
            HardwareProperty property = mHardwareMap.get(hardwareName);
            switch (property.getType()) {
            // TODO: custom TextCellEditor that restrict input.
            case INTEGER:
                // intended fall-through.
            case DISKSIZE:
                return new TextCellEditor(hardwareTable);
            case BOOLEAN:
                return new ComboBoxCellEditor(hardwareTable, HardwareProperties.BOOLEAN_VALUES,
                        SWT.READ_ONLY | SWT.DROP_DOWN);
            }
            return null;
        }

        @Override
        protected boolean canEdit(Object element) {
            String hardwareName = (String) element;
            HardwareProperty property = mHardwareMap.get(hardwareName);
            return property != null;
        }
    });

    mHardwareViewer.setInput(mProperties);
}

From source file:com.android.sdkuilib.internal.widgets.LegacyAvdEditDialog.java

License:Apache License

/**
 * Creates the UI for the hardware properties table.
 * This creates the {@link Table}, and several viewers ({@link TableViewer},
 * {@link TableViewerColumn}) and adds edit support for the 2nd column
 *///from w  w  w . jav  a  2s .  co  m
private void createHardwareTable(Composite parent) {
    final Table hardwareTable = new Table(parent, SWT.SINGLE | SWT.FULL_SELECTION);
    GridData gd = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
    gd.widthHint = 200;
    gd.heightHint = 100;
    hardwareTable.setLayoutData(gd);
    hardwareTable.setHeaderVisible(true);
    hardwareTable.setLinesVisible(true);

    // -- Table viewer
    mHardwareViewer = new TableViewer(hardwareTable);
    mHardwareViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            // it's a single selection mode, we can just access the selection index
            // from the table directly.
            mDeleteHardwareProp.setEnabled(hardwareTable.getSelectionIndex() != -1);
        }
    });

    // only a content provider. Use viewers per column below (for editing support)
    mHardwareViewer.setContentProvider(new IStructuredContentProvider() {
        @Override
        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
            // we can just ignore this. we just use mProperties directly.
        }

        @Override
        public Object[] getElements(Object arg0) {
            return mProperties.keySet().toArray();
        }

        @Override
        public void dispose() {
            // pass
        }
    });

    // -- column 1: prop abstract name
    TableColumn col1 = new TableColumn(hardwareTable, SWT.LEFT);
    col1.setText("Property");
    col1.setWidth(150);
    TableViewerColumn tvc1 = new TableViewerColumn(mHardwareViewer, col1);
    tvc1.setLabelProvider(new CellLabelProvider() {
        @Override
        public void update(ViewerCell cell) {
            String name = cell.getElement().toString();
            HardwareProperty prop = mHardwareMap.get(name);
            if (prop != null) {
                cell.setText(prop.getAbstract());
            } else {
                cell.setText(String.format("%1$s (Unknown)", name));
            }
        }
    });

    // -- column 2: prop value
    TableColumn col2 = new TableColumn(hardwareTable, SWT.LEFT);
    col2.setText("Value");
    col2.setWidth(50);
    TableViewerColumn tvc2 = new TableViewerColumn(mHardwareViewer, col2);
    tvc2.setLabelProvider(new CellLabelProvider() {
        @Override
        public void update(ViewerCell cell) {
            String value = mProperties.get(cell.getElement());
            cell.setText(value != null ? value : "");
        }
    });

    // add editing support to the 2nd column
    tvc2.setEditingSupport(new EditingSupport(mHardwareViewer) {
        @Override
        protected void setValue(Object element, Object value) {
            String hardwareName = (String) element;
            HardwareProperty property = mHardwareMap.get(hardwareName);
            int index;
            switch (property.getType()) {
            case INTEGER:
                mProperties.put((String) element, (String) value);
                break;
            case DISKSIZE:
                if (HardwareProperties.DISKSIZE_PATTERN.matcher((String) value).matches()) {
                    mProperties.put((String) element, (String) value);
                }
                break;
            case BOOLEAN:
                index = (Integer) value;
                mProperties.put((String) element, HardwareProperties.getBooleanValue(index));
                break;
            case STRING_ENUM:
            case INTEGER_ENUM:
                // For a combo, value is the index of the enum to use.
                index = (Integer) value;
                String[] values = property.getEnum();
                if (values != null && values.length > index) {
                    mProperties.put((String) element, values[index]);
                }
                break;
            }
            mHardwareViewer.refresh(element);
        }

        @Override
        protected Object getValue(Object element) {
            String hardwareName = (String) element;
            HardwareProperty property = mHardwareMap.get(hardwareName);
            String value = mProperties.get(hardwareName);
            switch (property.getType()) {
            case INTEGER:
                // intended fall-through.
            case DISKSIZE:
                return value;
            case BOOLEAN:
                return HardwareProperties.getBooleanValueIndex(value);
            case STRING_ENUM:
            case INTEGER_ENUM:
                // For a combo, we need to return the index of the value in the enum
                String[] values = property.getEnum();
                if (values != null) {
                    for (int i = 0; i < values.length; i++) {
                        if (values[i].equals(value)) {
                            return i;
                        }
                    }
                }
            }

            return null;
        }

        @Override
        protected CellEditor getCellEditor(Object element) {
            String hardwareName = (String) element;
            HardwareProperty property = mHardwareMap.get(hardwareName);
            switch (property.getType()) {
            // TODO: custom TextCellEditor that restrict input.
            case INTEGER:
                // intended fall-through.
            case DISKSIZE:
                return new TextCellEditor(hardwareTable);
            case BOOLEAN:
                return new ComboBoxCellEditor(hardwareTable, new String[] {
                        HardwareProperties.getBooleanValue(0), HardwareProperties.getBooleanValue(1), },
                        SWT.READ_ONLY | SWT.DROP_DOWN);
            case STRING_ENUM:
            case INTEGER_ENUM:
                String[] values = property.getEnum();
                if (values != null && values.length > 0) {
                    return new ComboBoxCellEditor(hardwareTable, values, SWT.READ_ONLY | SWT.DROP_DOWN);
                }
            }
            return null;
        }

        @Override
        protected boolean canEdit(Object element) {
            String hardwareName = (String) element;
            HardwareProperty property = mHardwareMap.get(hardwareName);
            return property != null;
        }
    });

    mHardwareViewer.setInput(mProperties);
}

From source file:com.archimatetool.editor.ui.dialog.RelationshipsMatrixDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {
    // Help// w  w w  . j a v a 2  s.  c o m
    PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, HELP_ID);

    setTitle(Messages.RelationshipsMatrixDialog_0);
    setMessage(Messages.RelationshipsMatrixDialog_1);
    Composite composite = (Composite) super.createDialogArea(parent);

    Composite client = new Composite(composite, SWT.NULL);
    GridLayout layout = new GridLayout(2, false);
    client.setLayout(layout);
    client.setLayoutData(new GridData(GridData.FILL_BOTH));

    GridData gd;

    GridTableViewer viewer = new GridTableViewer(client);
    gd = new GridData(GridData.FILL_BOTH);
    gd.widthHint = 800;
    gd.heightHint = 500;
    viewer.getControl().setLayoutData(gd);

    viewer.getGrid().setHeaderVisible(true);
    viewer.getGrid().setRowHeaderVisible(true);
    viewer.getGrid().setRowsResizeable(true);
    viewer.getGrid().setCellSelectionEnabled(true);

    //viewer.setColumnProperties(new String[] {"1", "2", "3"});

    viewer.setRowHeaderLabelProvider(new CellLabelProvider() {
        @Override
        public void update(ViewerCell cell) {
            cell.setText(ArchimateLabelProvider.INSTANCE.getDefaultName((EClass) cell.getElement()));
            cell.setImage(ArchimateLabelProvider.INSTANCE.getImage(cell.getElement()));
        }
    });

    for (EClass eClass : getData()) {
        GridColumn column = new GridColumn(viewer.getGrid(), SWT.NONE);
        column.setWidth(70);
        column.setImage(ArchimateLabelProvider.INSTANCE.getImage(eClass));
        column.setHeaderTooltip(ArchimateLabelProvider.INSTANCE.getDefaultName(eClass));
    }

    viewer.setContentProvider(new IStructuredContentProvider() {
        @Override
        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }

        @Override
        public void dispose() {
        }

        @Override
        public Object[] getElements(Object inputElement) {
            return getData().toArray();
        }
    });

    viewer.setLabelProvider(new MyLabelProvider());

    //hookContextMenu(viewer);

    viewer.setInput(getData());

    String text = ""; //$NON-NLS-1$
    for (Entry<EClass, Character> entry : RelationshipsMatrix.INSTANCE.getRelationshipsValueMap().entrySet()) {
        text += entry.getValue() + ": " + ArchimateLabelProvider.INSTANCE.getDefaultShortName(entry.getKey()) //$NON-NLS-1$
                + "\n"; //$NON-NLS-1$
    }
    Label label = new Label(client, SWT.NULL);
    label.setText(text);
    label.setLayoutData(new GridData(SWT.TOP, SWT.TOP, false, true));

    return composite;
}

From source file:com.arm.cmsis.pack.tree.AdvisedCellLabelProvider.java

License:Apache License

@Override
public void update(ViewerCell cell) {
    Object element = cell.getElement();
    int index = cell.getColumnIndex();
    Color clr = columnAdvisor.getBgColor(element, index);
    if (clr != null)
        cell.setBackground(clr);/* www .  j av a 2s  .  c  o  m*/
    else
        cell.setBackground(null);

    switch (columnAdvisor.getCellControlType(element, index)) {
    case TEXT:
        cell.setText(columnAdvisor.getString(element, index));
        cell.setImage(columnAdvisor.getImage(element, index));
        break;
    case COMBO:
        cell.setText(columnAdvisor.getString(element, index));
        break;
    case URL:
        cell.setText(columnAdvisor.getString(element, index));
        cell.setForeground(getDisplay().getSystemColor(SWT.COLOR_LINK_FOREGROUND));
        break;
    default:
        break;
    }
    super.update(cell);

    //Log.writeCurrentMethod(cell);

}