Search in sources :

Example 1 with ShapePicker

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

the class RulePanelManager method buildPriorityControls.

private void buildPriorityControls(Composite parent) {
    Label priorityLabel = buildLabel(parent, StringKeys.PREF_RULEEDIT_LABEL_PRIORITY);
    GridData data = new GridData();
    data.horizontalSpan = 1;
    priorityLabel.setLayoutData(data);
    priorityCombo = buildPriorityCombo(parent);
    priorityDisplay = new ShapePicker(parent, SWT.NONE, 14);
    priorityDisplay.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 4, 1));
    priorityDisplay.setShapeMap(UISettings.shapesByPriority());
    priorityDisplay.tooltipProvider(new LabelProvider() {

        public String labelFor(Object item) {
            return UISettings.labelFor((RulePriority) item);
        }
    });
    priorityDisplay.setSize(120, 25);
}
Also used : ShapePicker(net.sourceforge.pmd.eclipse.ui.ShapePicker) Label(org.eclipse.swt.widgets.Label) GridData(org.eclipse.swt.layout.GridData) RulePriority(net.sourceforge.pmd.RulePriority) LabelProvider(net.sourceforge.pmd.eclipse.ui.LabelProvider)

Example 2 with ShapePicker

use of net.sourceforge.pmd.eclipse.ui.ShapePicker 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)

Aggregations

ShapePicker (net.sourceforge.pmd.eclipse.ui.ShapePicker)2 GridData (org.eclipse.swt.layout.GridData)2 Label (org.eclipse.swt.widgets.Label)2 RulePriority (net.sourceforge.pmd.RulePriority)1 BasicTableLabelProvider (net.sourceforge.pmd.eclipse.ui.BasicTableLabelProvider)1 LabelProvider (net.sourceforge.pmd.eclipse.ui.LabelProvider)1 Shape (net.sourceforge.pmd.eclipse.ui.Shape)1 BasicTableManager (net.sourceforge.pmd.eclipse.ui.preferences.br.BasicTableManager)1 ColorSelector (org.eclipse.jface.preference.ColorSelector)1 IPropertyChangeListener (org.eclipse.jface.util.IPropertyChangeListener)1 PropertyChangeEvent (org.eclipse.jface.util.PropertyChangeEvent)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 IStructuredContentProvider (org.eclipse.jface.viewers.IStructuredContentProvider)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 TableViewer (org.eclipse.jface.viewers.TableViewer)1 Viewer (org.eclipse.jface.viewers.Viewer)1 FocusAdapter (org.eclipse.swt.events.FocusAdapter)1 FocusEvent (org.eclipse.swt.events.FocusEvent)1 RGB (org.eclipse.swt.graphics.RGB)1