Search in sources :

Example 1 with BasicTableLabelProvider

use of net.sourceforge.pmd.eclipse.ui.BasicTableLabelProvider in project pmd-eclipse-plugin by pmd.

the class BasicTableManager method setupColumns.

/**
 * @param columnDescs
 *            RuleColumnDescriptor[]
 * @param groupingField
 *            RuleFieldAccessor
 */
public void setupColumns(ItemColumnDescriptor[] columnDescs) {
    Table table = tableViewer.getTable();
    for (int i = 0; i < columnDescs.length; i++) {
        columnDescs[i].buildTableColumn(table, this);
    }
    tableViewer.setLabelProvider(new BasicTableLabelProvider(columnDescs));
    TableColumn[] columns = table.getColumns();
    for (TableColumn column : columns) {
        column.pack();
    }
}
Also used : Table(org.eclipse.swt.widgets.Table) BasicTableLabelProvider(net.sourceforge.pmd.eclipse.ui.BasicTableLabelProvider) TableColumn(org.eclipse.swt.widgets.TableColumn) Point(org.eclipse.swt.graphics.Point)

Example 2 with BasicTableLabelProvider

use of net.sourceforge.pmd.eclipse.ui.BasicTableLabelProvider in project pmd-eclipse-plugin by pmd.

the class FilterPreferencesPage method buildFilterGroup.

/**
 * Build the group of priority preferences
 *
 * @param parent
 *            the parent composite
 *
 * @return the group widget
 */
private Composite buildFilterGroup(Composite parent) {
    IStructuredContentProvider contentProvider = new IStructuredContentProvider() {

        public void dispose() {
        }

        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }

        public Object[] getElements(Object inputElement) {
            return (FilterHolder[]) inputElement;
        }
    };
    BasicTableLabelProvider labelProvider = new BasicTableLabelProvider(FilterColumnUI.VISIBLE_COLUMNS);
    reportTableMgr = new BasicTableManager<FilterHolder>("renderers", null, FilterColumnUI.VISIBLE_COLUMNS);
    tableViewer = reportTableMgr.buildTableViewer(parent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION | SWT.CHECK);
    reportTableMgr.setupColumns(FilterColumnUI.VISIBLE_COLUMNS);
    Table table = tableViewer.getTable();
    table.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true, 1, 1));
    tableViewer.setLabelProvider(labelProvider);
    tableViewer.setContentProvider(contentProvider);
    table.setHeaderVisible(true);
    tableViewer.setInput(currentFilters());
    selectCheckedFilters();
    TableColumn[] columns = table.getColumns();
    for (TableColumn column : columns) {
        column.pack();
    }
    tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            patternsSelected();
        }
    });
    tableViewer.getTable().addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event event) {
            if (event.detail == SWT.CHECK) {
                checked(event.item);
            }
        }
    });
    return parent;
}
Also used : Table(org.eclipse.swt.widgets.Table) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) ValueChangeListener(net.sourceforge.pmd.eclipse.ui.preferences.br.ValueChangeListener) Listener(org.eclipse.swt.widgets.Listener) SizeChangeListener(net.sourceforge.pmd.eclipse.ui.preferences.br.SizeChangeListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) BasicTableLabelProvider(net.sourceforge.pmd.eclipse.ui.BasicTableLabelProvider) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) TableColumn(org.eclipse.swt.widgets.TableColumn) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) GridData(org.eclipse.swt.layout.GridData) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) FocusEvent(org.eclipse.swt.events.FocusEvent) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Example 3 with BasicTableLabelProvider

use of net.sourceforge.pmd.eclipse.ui.BasicTableLabelProvider in project pmd-eclipse-plugin by pmd.

the class ASTViewPage method createControl.

/**
 * TODO use an adjustable Sash to separate the two sections TODO add an
 * XPath version combo widget
 */
public void createControl(Composite parent) {
    sashForm = new SashForm(parent, SWT.HORIZONTAL);
    Composite astPanel = new Composite(sashForm, SWT.NONE);
    GridLayout mainLayout = new GridLayout(3, false);
    astPanel.setLayout(mainLayout);
    Composite titleArea = new Composite(astPanel, SWT.NONE);
    GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalSpan = 2;
    titleArea.setLayoutData(gridData);
    titleArea.setLayout(new GridLayout(4, false));
    Label showLabel = new Label(titleArea, 0);
    showLabel.setText("Show: ");
    final Button classBtn = new Button(titleArea, SWT.RADIO);
    classBtn.setText("Class");
    classBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent se) {
            if (classBtn.getSelection()) {
                showClass();
            }
        }
    });
    final Button methodBtn = new Button(titleArea, SWT.RADIO);
    methodBtn.setText("Method");
    methodBtn.setSelection(true);
    methodBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent se) {
            enableMethodSelector(methodBtn.getSelection());
            methodPicked();
        }
    });
    buildMethodSelector(titleArea);
    astViewer = new TreeViewer(astPanel, SWT.MULTI | SWT.BORDER);
    contentProvider = new ASTContentProvider(true, true);
    astViewer.setContentProvider(contentProvider);
    astViewer.setLabelProvider(new ASTLabelProvider());
    setupListeners(astViewer.getTree());
    GridData data = new GridData(GridData.FILL_BOTH);
    data.horizontalSpan = 2;
    astViewer.getTree().setLayoutData(data);
    // ==================
    Composite xpathTestPanel = new Composite(sashForm, SWT.NONE);
    data = new GridData(GridData.FILL_BOTH);
    data.horizontalSpan = 1;
    xpathTestPanel.setLayoutData(data);
    GridLayout playLayout = new GridLayout(2, false);
    xpathTestPanel.setLayout(playLayout);
    xpathField = new StyledText(xpathTestPanel, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    gridData = new GridData(GridData.FILL_BOTH);
    gridData.grabExcessHorizontalSpace = true;
    gridData.horizontalSpan = 1;
    xpathField.setLayoutData(gridData);
    SyntaxManager.adapt(xpathField, "xpath", null);
    addXPathValidator();
    goButton = new Button(xpathTestPanel, SWT.PUSH);
    goButton.setText("GO");
    gridData = new GridData(GridData.FILL_BOTH);
    gridData.grabExcessHorizontalSpace = false;
    gridData.horizontalSpan = 1;
    goButton.setLayoutData(gridData);
    goButton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            evaluateXPath();
        }
    });
    // outputField = new StyledText(xpathTestPanel, SWT.BORDER |
    // SWT.H_SCROLL | SWT.V_SCROLL);
    gridData = new GridData(GridData.FILL_BOTH);
    gridData.grabExcessHorizontalSpace = true;
    gridData.horizontalSpan = 2;
    // outputField.setLayoutData(gridData);
    // SyntaxManager.adapt(outputField, "xpath", null);
    BasicTableManager tableMgr = new BasicTableManager("ast", null, NodeColumnUI.VISIBLE_COLUMNS);
    resultsViewer = tableMgr.buildTableViewer(xpathTestPanel);
    tableMgr.setupColumns(NodeColumnUI.VISIBLE_COLUMNS);
    IStructuredContentProvider contentProvider = new IStructuredContentProvider() {

        public void dispose() {
        }

        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }

        public Object[] getElements(Object inputElement) {
            return (Node[]) inputElement;
        }
    };
    BasicTableLabelProvider labelProvider = new BasicTableLabelProvider(NodeColumnUI.VISIBLE_COLUMNS);
    Table table = resultsViewer.getTable();
    table.setLayoutData(gridData);
    resultsViewer.setLabelProvider(labelProvider);
    resultsViewer.setContentProvider(contentProvider);
    registerListeners();
    showFirstMethod();
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) TreeViewer(org.eclipse.jface.viewers.TreeViewer) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) BasicTableManager(net.sourceforge.pmd.eclipse.ui.preferences.br.BasicTableManager) Label(org.eclipse.swt.widgets.Label) BasicTableLabelProvider(net.sourceforge.pmd.eclipse.ui.BasicTableLabelProvider) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) SashForm(org.eclipse.swt.custom.SashForm) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider)

Example 4 with BasicTableLabelProvider

use of net.sourceforge.pmd.eclipse.ui.BasicTableLabelProvider in project pmd-eclipse-plugin by pmd.

the class GeneralPreferencesPage method buildPriorityGroup.

/**
 * Build the group of priority preferences
 *
 * @param parent
 *            the parent composite
 * @return the group widget
 */
private Group buildPriorityGroup(final Composite parent) {
    Group group = new Group(parent, SWT.SHADOW_IN);
    group.setText(getMessage(StringKeys.PREF_GENERAL_GROUP_PRIORITIES));
    group.setLayout(new GridLayout(2, false));
    Link link = createPreferenceLink(group, "PMD folder annotations can be enabled on the <A>label decorations</A> page", "org.eclipse.ui.preferencePages.Decorators");
    link.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false, 1, 1));
    useCustomPriorityNames = buildUseCustomPriorityNamesButton(group);
    useCustomPriorityNames.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false, 1, 1));
    IStructuredContentProvider contentProvider = new IStructuredContentProvider() {

        public void dispose() {
        }

        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }

        public Object[] getElements(Object inputElement) {
            return (RulePriority[]) inputElement;
        }
    };
    BasicTableLabelProvider labelProvider = new BasicTableLabelProvider(PriorityColumnUI.VISIBLE_COLUMNS);
    priorityTableMgr = new BasicTableManager("prio", null, PriorityColumnUI.VISIBLE_COLUMNS);
    tableViewer = priorityTableMgr.buildTableViewer(group);
    priorityTableMgr.setupColumns(PriorityColumnUI.VISIBLE_COLUMNS);
    Table table = tableViewer.getTable();
    table.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, true, 2, 1));
    tableViewer.setLabelProvider(labelProvider);
    tableViewer.setContentProvider(contentProvider);
    table.setHeaderVisible(true);
    // labelProvider.addColumnsTo(table);
    tableViewer.setInput(UISettings.currentPriorities(true));
    // TableColumn[] columns = table.getColumns();
    // for (TableColumn column : columns) column.pack();
    Composite editorPanel = new Composite(group, SWT.None);
    editorPanel.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, true));
    editorPanel.setLayout(new GridLayout(6, false));
    Label shapeLabel = new Label(editorPanel, SWT.None);
    shapeLabel.setLayoutData(new GridData());
    shapeLabel.setText("Shape:");
    final ShapePicker<Shape> ssc = new ShapePicker<Shape>(editorPanel, SWT.None, 14);
    ssc.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1));
    ssc.setSize(280, 30);
    ssc.setShapeMap(UISettings.shapeSet(SHAPE_COLOR, 10));
    ssc.setItems(UISettings.allShapes());
    Label colourLabel = new Label(editorPanel, SWT.None);
    colourLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false, 1, 1));
    colourLabel.setText("Color:");
    final ColorSelector colorPicker = new ColorSelector(editorPanel);
    Label nameLabel = new Label(editorPanel, SWT.None);
    nameLabel.setLayoutData(new GridData());
    nameLabel.setText("Name:");
    final Text priorityName = new Text(editorPanel, SWT.BORDER);
    priorityName.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, true));
    nameFields = new Control[] { nameLabel, priorityName };
    // final Label descLabel = new Label(editorPanel, SWT.None);
    // descLabel.setLayoutData( new GridData(GridData.FILL, GridData.CENTER,
    // false, true, 1, 1));
    // descLabel.setText("Description:");
    // final Text priorityDesc = new Text(editorPanel, SWT.BORDER);
    // priorityDesc.setLayoutData( new GridData(GridData.FILL,
    // GridData.CENTER, true, true, 5, 1) );
    tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            selectedPriorities(selection.toList(), ssc, colorPicker, priorityName);
        }
    });
    ssc.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            setShape((Shape) selection.getFirstElement());
        }
    });
    colorPicker.addListener(new IPropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent event) {
            setColor((RGB) event.getNewValue());
        }
    });
    priorityName.addFocusListener(new FocusAdapter() {

        public void focusLost(FocusEvent e) {
            setName(priorityName.getText());
        }
    });
    // only set this once the name fields are built
    useCustomPriorityNames.setSelection(preferences.useCustomPriorityNames());
    return group;
}
Also used : Group(org.eclipse.swt.widgets.Group) FocusAdapter(org.eclipse.swt.events.FocusAdapter) Shape(net.sourceforge.pmd.eclipse.ui.Shape) Label(org.eclipse.swt.widgets.Label) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) FocusEvent(org.eclipse.swt.events.FocusEvent) GridLayout(org.eclipse.swt.layout.GridLayout) ShapePicker(net.sourceforge.pmd.eclipse.ui.ShapePicker) IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) BasicTableManager(net.sourceforge.pmd.eclipse.ui.preferences.br.BasicTableManager) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) BasicTableLabelProvider(net.sourceforge.pmd.eclipse.ui.BasicTableLabelProvider) Text(org.eclipse.swt.widgets.Text) RGB(org.eclipse.swt.graphics.RGB) GridData(org.eclipse.swt.layout.GridData) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) ColorSelector(org.eclipse.jface.preference.ColorSelector) Link(org.eclipse.swt.widgets.Link)

Example 5 with BasicTableLabelProvider

use of net.sourceforge.pmd.eclipse.ui.BasicTableLabelProvider in project pmd-eclipse-plugin by pmd.

the class ReportPreferencesPage method buildReportGroup.

/**
 * Build the group of priority preferences
 *
 * @param parent
 *            the parent composite
 *
 * @return the group widget
 */
private Composite buildReportGroup(Composite parent) {
    Composite group = new Composite(parent, SWT.NONE);
    // group.setText("Formats");
    group.setLayout(new GridLayout(2, false));
    IStructuredContentProvider contentProvider = new IStructuredContentProvider() {

        public void dispose() {
        }

        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }

        public Object[] getElements(Object inputElement) {
            return (Renderer[]) inputElement;
        }
    };
    BasicTableLabelProvider labelProvider = new BasicTableLabelProvider(ReportColumnUI.VISIBLE_COLUMNS);
    reportTableMgr = new BasicTableManager("renderers", null, ReportColumnUI.VISIBLE_COLUMNS);
    tableViewer = reportTableMgr.buildTableViewer(group, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION | SWT.CHECK);
    reportTableMgr.setupColumns(ReportColumnUI.VISIBLE_COLUMNS);
    Table table = tableViewer.getTable();
    table.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, true, 2, 1));
    tableViewer.setLabelProvider(labelProvider);
    tableViewer.setContentProvider(contentProvider);
    table.setHeaderVisible(true);
    // labelProvider.addColumnsTo(table);
    tableViewer.setInput(ReportManager.INSTANCE.allRenderers());
    selectCheckedRenderers();
    TableColumn[] columns = table.getColumns();
    for (TableColumn column : columns) {
        column.pack();
    }
    Composite editorPanel = new Composite(group, SWT.None);
    editorPanel.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, true));
    editorPanel.setLayout(new GridLayout(4, false));
    Label nameLabel = new Label(editorPanel, SWT.None);
    nameLabel.setLayoutData(new GridData());
    nameLabel.setText("Name:");
    final Label rendererName = new Label(editorPanel, SWT.BORDER);
    rendererName.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, true));
    final Button suppressed = new Button(editorPanel, SWT.CHECK);
    suppressed.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 2, 1));
    suppressed.setText("Show suppressed violations");
    Label descLabel = new Label(editorPanel, SWT.None);
    descLabel.setLayoutData(new GridData());
    descLabel.setText("Description:");
    final Label descValue = new Label(editorPanel, SWT.BORDER);
    descValue.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, true, 3, 1));
    tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            List items = selection.toList();
            selectedRenderers(items, rendererName, descValue, suppressed);
            if (items.size() == 1) {
                formArranger.arrangeFor((Renderer) items.get(0));
            } else {
                formArranger.clearChildren();
            }
        }
    });
    tableViewer.getTable().addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event event) {
            if (event.detail == SWT.CHECK) {
                checked(event.item);
            }
        }
    });
    suppressed.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
        }
    });
    rendererName.addFocusListener(new FocusAdapter() {

        @Override
        public void focusLost(FocusEvent e) {
            setName(rendererName.getText());
        }
    });
    return group;
}
Also used : FocusAdapter(org.eclipse.swt.events.FocusAdapter) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) ValueChangeListener(net.sourceforge.pmd.eclipse.ui.preferences.br.ValueChangeListener) Listener(org.eclipse.swt.widgets.Listener) SizeChangeListener(net.sourceforge.pmd.eclipse.ui.preferences.br.SizeChangeListener) Label(org.eclipse.swt.widgets.Label) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) FocusEvent(org.eclipse.swt.events.FocusEvent) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) List(java.util.List) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) BasicTableManager(net.sourceforge.pmd.eclipse.ui.preferences.br.BasicTableManager) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) BasicTableLabelProvider(net.sourceforge.pmd.eclipse.ui.BasicTableLabelProvider) TableColumn(org.eclipse.swt.widgets.TableColumn) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) GridData(org.eclipse.swt.layout.GridData) Renderer(net.sourceforge.pmd.renderers.Renderer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) FocusEvent(org.eclipse.swt.events.FocusEvent) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Aggregations

BasicTableLabelProvider (net.sourceforge.pmd.eclipse.ui.BasicTableLabelProvider)5 Table (org.eclipse.swt.widgets.Table)5 IStructuredContentProvider (org.eclipse.jface.viewers.IStructuredContentProvider)4 TableViewer (org.eclipse.jface.viewers.TableViewer)4 Viewer (org.eclipse.jface.viewers.Viewer)4 GridData (org.eclipse.swt.layout.GridData)4 BasicTableManager (net.sourceforge.pmd.eclipse.ui.preferences.br.BasicTableManager)3 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)3 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)3 FocusEvent (org.eclipse.swt.events.FocusEvent)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 Composite (org.eclipse.swt.widgets.Composite)3 Label (org.eclipse.swt.widgets.Label)3 TableColumn (org.eclipse.swt.widgets.TableColumn)3 SizeChangeListener (net.sourceforge.pmd.eclipse.ui.preferences.br.SizeChangeListener)2 ValueChangeListener (net.sourceforge.pmd.eclipse.ui.preferences.br.ValueChangeListener)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 FocusAdapter (org.eclipse.swt.events.FocusAdapter)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2