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:net.karlmartens.ui.viewer.CellSelectionModifier.java

License:Apache License

private String getValue(Point pt) {
    final ViewerCell cell = getViewerCell(pt);
    if (cell == null)
        return null;

    _editSupport._base = getEditingSupport(pt);
    final Object o = _editSupport.getValue(cell.getElement());
    return o.toString();
}

From source file:net.karlmartens.ui.viewer.CellSelectionModifier.java

License:Apache License

private void setValue(Point pt, String value) {
    if (!isEditable(pt))
        return;/*  w  w w.  j  a  v  a  2  s.c  o m*/

    final ViewerCell cell = getViewerCell(pt);
    if (cell == null)
        return;

    _editSupport._base = getEditingSupport(pt);
    _editSupport.setValue(cell.getElement(), value);

}

From source file:net.karlmartens.ui.viewer.TimeSeriesTableValueEditingSupport.java

License:Apache License

@Override
protected void initializeCellEditorValue(CellEditor cellEditor, ViewerCell cell) {
    cellEditor.setValue("");

    final TimeSeriesEditingSupport editingSupport = _viewer.getEditingSupport();
    if (editingSupport == null)
        return;/*from   ww w . j a va 2  s.  c o  m*/

    final TimeSeriesContentProvider cp = (TimeSeriesContentProvider) _viewer.getContentProvider();
    if (cp == null)
        return;

    final double value = cp.getValue(cell.getElement(), computePeriodIndex(cell));
    final NumberFormat format = getEditingNumberFormat(editingSupport);
    cellEditor.setValue(format.format(value));
}

From source file:net.karlmartens.ui.viewer.TimeSeriesTableValueEditingSupport.java

License:Apache License

private void update(ViewerCell cell, double value) {
    _viewer.getEditingSupport().setValue(cell.getElement(), computePeriodIndex(cell), value);
    final TableItem item = (TableItem) cell.getItem();
    item.setText(cell.getColumnIndex(), _viewer.getNumberFormat().format(value));
    _viewer.getControl().redraw();/*from  w  w w.jav  a2s .com*/
}

From source file:net.roboconf.eclipse.modeler.dialogs.ImportedVariableDialog.java

License:Apache License

@Override
protected Control createDialogArea(Composite parent) {

    // Global UI//from   w  ww.  ja v  a 2s  .c  o m
    Composite bigContainer = (Composite) super.createDialogArea(parent);
    GridLayoutFactory.swtDefaults().margins(5, 0).applyTo(bigContainer);
    bigContainer.setLayoutData(new GridData(GridData.FILL_BOTH));

    getShell().setText("Imported Variables");
    setTitle("Imported Variables");
    setMessage("Edit the variables to import.");

    // Find all the variables
    for (RoboconfFacet type : findAllFacetsAndComponents()) {

        Collection<String> varNames = findAllExportedVariables(type);
        if (!type.getExports().isEmpty())
            varNames.add(type.getName() + ".*");

        for (String varName : varNames) {
            RoboconfImportedVariable var = RoboconfEmfFactory.eINSTANCE.createRoboconfImportedVariable();
            var.setName(varName);
            if (var.getName().startsWith(this.component.getName() + "."))
                var.setOptional(true);

            this.nameToImportedVariables.put(varName, var);
        }
    }

    // Update the map that will act as our model.
    // We do this in two steps because...
    // 1. nameToImportedVariables is a tree map. Variables are sorted alphabetically.
    // 2. importedVariablesToTaken is our model for the UI. Since it is a linked hash map,
    // it preserves insertion order. So, we preserve the order from the tree map.
    //
    // And we cannot directly use a tree map with imported variables.
    // The class was generated by EMF and there is no natural ordering.
    for (RoboconfImportedVariable var : this.nameToImportedVariables.values()) {
        this.importedVariablesToTaken.put(var, Boolean.FALSE);
    }

    // Should they be marked as used?
    updateImportedVariablesStates();

    // Display them in a table viewer
    final TableViewer viewer = new TableViewer(bigContainer, SWT.BORDER | SWT.SINGLE);
    viewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
    viewer.getTable().setHeaderVisible(true);
    viewer.getTable().setLinesVisible(true);

    TableLayout tlayout = new TableLayout();
    tlayout.addColumnData(new ColumnWeightData(12, 90, true));
    tlayout.addColumnData(new ColumnWeightData(40, 200, true));
    tlayout.addColumnData(new ColumnWeightData(12, 90, true));
    viewer.getTable().setLayout(tlayout);

    String[] columnTitles = { "Import", "Variable Name", "Optional" };
    for (int i = 0; i < columnTitles.length; i++) {
        int style = i == 1 ? SWT.LEFT : SWT.CENTER;
        TableColumn column = new TableColumn(viewer.getTable(), style);
        column.setText(columnTitles[i]);
    }

    viewer.setLabelProvider(new ImportedVariableLabelProvider(this.checked, this.unchecked));
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setInput(this.importedVariablesToTaken.entrySet());
    viewer.getTable().addListener(SWT.MouseDoubleClick, new Listener() {

        @Override
        @SuppressWarnings({ "unchecked", "rawtypes" })
        public void handleEvent(Event event) {

            Point p = new Point(event.x, event.y);
            ViewerCell cell = viewer.getCell(p);

            Map.Entry<RoboconfImportedVariable, Boolean> entry = (Map.Entry) cell.getElement();
            RoboconfImportedVariable var = entry.getKey();

            if (cell.getColumnIndex() == 0) {
                entry.setValue(!entry.getValue());

            } else if (cell.getColumnIndex() == 2) {
                var.setOptional(!var.isOptional());
            }

            viewer.refresh(entry);
        }
    });

    return bigContainer;
}

From source file:net.sf.eclipsensis.wizard.settings.NSISInstallElementLabelProvider.java

License:Open Source License

@Override
public void update(ViewerCell cell) {
    cell.setImage(getImage(cell.getElement()));
    cell.setText(getText(cell.getElement()));
}

From source file:net.sf.jmoney.importer.matcher.PatternMatchingDialog.java

License:Open Source License

private Control createSampleEntriesTableControl(Composite parent) {
    // Create the table viewer to display the sample entries
    entriesViewer = new TableViewer(parent, SWT.BORDER | SWT.FULL_SELECTION);

    // Set up the table
    final Table table = entriesViewer.getTable();

    // Turn on the header and the lines
    table.setHeaderVisible(true);// w w  w  . ja  va 2  s  . c o  m
    table.setLinesVisible(true);

    // Set the content and label providers
    entriesViewer.setContentProvider(ArrayContentProvider.getInstance());
    //      viewer.setSorter(new PatternSorter());

    ColumnViewerToolTipSupport.enableFor(entriesViewer);

    // Add the columns
    TableViewerColumn column1 = new TableViewerColumn(entriesViewer, SWT.LEFT);
    column1.getColumn().setWidth(40);
    column1.getColumn().setText("");
    column1.setLabelProvider(new CellLabelProvider() {
        @Override
        public void update(ViewerCell cell) {
            EntryData pattern = (EntryData) cell.getElement();
            cell.setText(pattern.getTextToMatch());
        }

        //         @Override
        //         public String getToolTipText(Object element) {
        //            MemoPattern pattern = (MemoPattern)element;
        //            return isMemoPatternValid(pattern);
        //         }
    });

    //      addColumn2(MemoPatternInfo.getCheckAccessor(), "The value to be put in the check field.  The values in this table may contain {0}, [1} etc. where the number matches the group number in the Java regular expression.");
    addColumn2(MemoPatternInfo.getOrderingIndexAccessor(), "The pattern index.");
    addColumn2(MemoPatternInfo.getMemoAccessor(),
            "The value to be put in the memo field.  The values in this table may contain {0}, [1} etc. where the number matches the group number in the Java regular expression.");
    addColumn2(MemoPatternInfo.getAccountAccessor(),
            "The account to be used for entries that match this pattern.");
    addColumn2(MemoPatternInfo.getDescriptionAccessor(),
            "The value to be put in the description field.  The values in this table may contain {0}, [1} etc. where the number matches the group number in the Java regular expression.");

    entriesViewer.setInput(sampleEntries);

    // Pack the columns
    for (int i = 0, n = table.getColumnCount(); i < n; i++) {
        table.getColumn(i).pack();
    }

    return table;
}

From source file:net.sf.jmoney.importer.matcher.PatternMatchingDialog.java

License:Open Source License

private Control createPatternMatchingTableControl(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(2, false));

    // Create the table viewer to display the pattern matching rules
    patternViewer = new TableViewer(composite, SWT.BORDER | SWT.FULL_SELECTION);

    // Set up the table
    final Table table = patternViewer.getTable();
    table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    TableViewerFocusCellManager focusCellManager = new TableViewerFocusCellManager(patternViewer,
            new FocusCellOwnerDrawHighlighter(patternViewer));
    ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(patternViewer) {
        @Override//from  w ww  .  ja v  a  2  s .  co m
        protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
            return event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL
                    || event.eventType == ColumnViewerEditorActivationEvent.MOUSE_CLICK_SELECTION
                    || (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED
                            && event.keyCode == SWT.CR)
                    || event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
        }
    };

    TableViewerEditor.create(patternViewer, focusCellManager, actSupport,
            ColumnViewerEditor.TABBING_HORIZONTAL | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR
                    | ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEYBOARD_ACTIVATION);

    // Set the content and label providers
    patternViewer.setContentProvider(new PatternContentProvider());
    patternViewer.setSorter(new PatternSorter());

    ColumnViewerToolTipSupport.enableFor(patternViewer);

    // Add the columns
    TableViewerColumn column1 = new TableViewerColumn(patternViewer, SWT.LEFT);
    column1.getColumn().setWidth(40);
    column1.getColumn().setText("");
    column1.setLabelProvider(new CellLabelProvider() {
        @Override
        public void update(ViewerCell cell) {
            MemoPattern pattern = (MemoPattern) cell.getElement();
            if (isMemoPatternValid(pattern) != null) {
                cell.setImage(errorImage);
            } else {
                cell.setImage(null);
            }
        }

        @Override
        public String getToolTipText(Object element) {
            MemoPattern pattern = (MemoPattern) element;
            return isMemoPatternValid(pattern);
        }
    });

    column1.setEditingSupport(new EditingSupport(patternViewer) {
        @Override
        protected boolean canEdit(Object element) {
            return false;
        }

        @Override
        protected CellEditor getCellEditor(Object element) {
            return null;
        }

        @Override
        protected Object getValue(Object element) {
            return null;
        }

        @Override
        protected void setValue(Object element, Object value) {
        }
    });

    addColumn(MemoPatternInfo.getPatternAccessor(),
            "<html>The pattern is a Java regular expression that is matched against the memo in the downloadable file.<br>For each record from the bank, the first row in this table with a matching pattern is used.</html>");
    addColumn(MemoPatternInfo.getCheckAccessor(),
            "The value to be put in the check field.  The values in this table may contain {0}, [1} etc. where the number matches the group number in the Java regular expression.");
    addColumn(MemoPatternInfo.getMemoAccessor(),
            "The value to be put in the memo field.  The values in this table may contain {0}, [1} etc. where the number matches the group number in the Java regular expression.");
    addColumn(MemoPatternInfo.getAccountAccessor(),
            "The account to be used for entries that match this pattern.");
    addColumn(MemoPatternInfo.getDescriptionAccessor(),
            "The value to be put in the description field.  The values in this table may contain {0}, [1} etc. where the number matches the group number in the Java regular expression.");

    /*
     * Set the account as the input object that contains the list of pattern
     * matching rules.
     */
    patternViewer.setInput(account);

    // Pack the columns
    for (int i = 0, n = table.getColumnCount(); i < n; i++) {
        table.getColumn(i).pack();
    }

    // Turn on the header and the lines
    table.setHeaderVisible(true);
    table.setLinesVisible(true);

    // Create the button area
    Control buttonAreaControl = createButtonArea(composite);
    buttonAreaControl.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, true));

    return composite;
}

From source file:net.sf.jmoney.reconciliation.reconcilePage.ImportOptionsDialog.java

License:Open Source License

private Control createPatternMatchingTableControl(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(2, false));

    // Create the table viewer to display the pattern matching rules
    viewer = new TableViewer(composite, SWT.BORDER | SWT.FULL_SELECTION);

    // Set up the table
    final Table table = viewer.getTable();
    table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    TableViewerFocusCellManager focusCellManager = new TableViewerFocusCellManager(viewer,
            new FocusCellOwnerDrawHighlighter(viewer));
    ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(viewer) {
        @Override//from   w w  w .j a  v  a2s  .  c  o  m
        protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
            return event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL
                    || event.eventType == ColumnViewerEditorActivationEvent.MOUSE_CLICK_SELECTION
                    || (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED
                            && event.keyCode == SWT.CR)
                    || event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
        }
    };

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

    // Set the content and label providers
    viewer.setContentProvider(new PatternContentProvider());
    viewer.setSorter(new PatternSorter());

    ColumnViewerToolTipSupport.enableFor(viewer);

    // Add the columns
    TableViewerColumn column1 = new TableViewerColumn(viewer, SWT.LEFT);
    column1.getColumn().setWidth(40);
    column1.getColumn().setText("");
    column1.setLabelProvider(new CellLabelProvider() {
        @Override
        public void update(ViewerCell cell) {
            MemoPattern pattern = (MemoPattern) cell.getElement();
            if (isMemoPatternValid(pattern) != null) {
                cell.setImage(errorImage);
            } else {
                cell.setImage(null);
            }
        }

        @Override
        public String getToolTipText(Object element) {
            MemoPattern pattern = (MemoPattern) element;
            return isMemoPatternValid(pattern);
        }
    });

    column1.setEditingSupport(new EditingSupport(viewer) {
        @Override
        protected boolean canEdit(Object element) {
            return false;
        }

        @Override
        protected CellEditor getCellEditor(Object element) {
            return null;
        }

        @Override
        protected Object getValue(Object element) {
            return null;
        }

        @Override
        protected void setValue(Object element, Object value) {
        }
    });

    addColumn(MemoPatternInfo.getPatternAccessor(),
            "<html>The pattern is a Java regular expression that is matched against the memo in the downloadable file.<br>For each record from the bank, the first row in this table with a matching pattern is used.</html>");
    addColumn(MemoPatternInfo.getCheckAccessor(),
            "The value to be put in the check field.  The values in this table may contain {0}, [1} etc. where the number matches the group number in the Java regular expression.");
    addColumn(MemoPatternInfo.getMemoAccessor(),
            "The value to be put in the memo field.  The values in this table may contain {0}, [1} etc. where the number matches the group number in the Java regular expression.");
    addColumn(MemoPatternInfo.getAccountAccessor(),
            "The account to be used for entries that match this pattern.");
    addColumn(MemoPatternInfo.getDescriptionAccessor(),
            "The value to be put in the description field.  The values in this table may contain {0}, [1} etc. where the number matches the group number in the Java regular expression.");

    /*
     * Set the account as the input object that contains the list of pattern
     * matching rules.
     */
    viewer.setInput(account);

    // Pack the columns
    for (int i = 0, n = table.getColumnCount(); i < n; i++) {
        table.getColumn(i).pack();
    }

    // Turn on the header and the lines
    table.setHeaderVisible(true);
    table.setLinesVisible(true);

    // Create the button area
    Control buttonAreaControl = createButtonArea(composite);
    buttonAreaControl.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, true));

    return composite;
}

From source file:net.sf.jmoney.stocks.pages.StockBalancesEditor.java

License:Open Source License

private Control createTable(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout());

    balancesViewer = new TableViewer(composite, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.FULL_SELECTION);

    GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
    gridData.widthHint = 300;/*from   w w w.j  a va  2  s.c om*/
    gridData.heightHint = 100;
    balancesViewer.getTable().setLayoutData(gridData);

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

    balancesViewer.setContentProvider(ArrayContentProvider.getInstance());

    // Sort by stock name
    balancesViewer.setComparator(new ViewerComparator() {
        @Override
        public int compare(Viewer viewer, Object element1, Object element2) {
            StockWrapper stockWrapper1 = (StockWrapper) element1;
            StockWrapper stockWrapper2 = (StockWrapper) element2;
            return stockWrapper1.stock.getName().compareTo(stockWrapper2.stock.getName());
        }
    });

    TableViewerColumn stockNameColumn = new TableViewerColumn(balancesViewer, SWT.LEFT);
    stockNameColumn.getColumn().setText("Stock");
    stockNameColumn.getColumn().setWidth(300);

    stockNameColumn.setLabelProvider(new CellLabelProvider() {
        @Override
        public void update(ViewerCell cell) {
            StockWrapper stockWrapper = (StockWrapper) cell.getElement();
            cell.setText(stockWrapper.stock.getName());
        }
    });

    TableViewerColumn balanceColumn = new TableViewerColumn(balancesViewer, SWT.LEFT);
    balanceColumn.getColumn().setText("Number of Shares");
    balanceColumn.getColumn().setWidth(100);

    balanceColumn.setLabelProvider(new CellLabelProvider() {
        @Override
        public void update(ViewerCell cell) {
            StockWrapper stockWrapper = (StockWrapper) cell.getElement();
            cell.setText(stockWrapper.stock.format(stockWrapper.total));
        }
    });

    // Create the pop-up menu
    MenuManager menuMgr = new MenuManager();
    // TODO We are making assumptions about where this editor is placed when
    // we make the following cast to AccountEditor.  Can this be cleaned up?
    menuMgr.add(new ShowDetailsAction(balancesViewer));
    menuMgr.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
    getSite().registerContextMenu(menuMgr, balancesViewer);

    Control control = balancesViewer.getControl();
    Menu menu = menuMgr.createContextMenu(control);
    control.setMenu(menu);

    return composite;
}