Search in sources :

Example 96 with IStructuredContentProvider

use of org.eclipse.jface.viewers.IStructuredContentProvider in project azure-tools-for-java by Microsoft.

the class ApplicationInsightsPreferencePage method createApplicationInsightsResourceTable.

/**
 * createApplicationInsightsResourceTable.
 */
public void createApplicationInsightsResourceTable(Composite parent) {
    table = new Table(parent, SWT.BORDER | SWT.FULL_SELECTION);
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    GridData gridData = new GridData();
    gridData.heightHint = 360;
    gridData.verticalIndent = 15;
    gridData.horizontalAlignment = SWT.FILL;
    gridData.grabExcessHorizontalSpace = false;
    table.setLayoutData(gridData);
    TableColumn strNameCol = new TableColumn(table, SWT.FILL);
    strNameCol.setText(Messages.resrcName);
    strNameCol.setWidth(150);
    TableColumn strUrlDisCol = new TableColumn(table, SWT.FILL);
    strUrlDisCol.setText(Messages.instrKey);
    strUrlDisCol.setWidth(190);
    tableViewer = new TableViewer(table);
    tableViewer.setContentProvider(new IStructuredContentProvider() {

        @Override
        public void inputChanged(Viewer viewer, Object obj, Object obj1) {
        }

        @Override
        public void dispose() {
        }

        @Override
        public Object[] getElements(Object obj) {
            return getTableContent();
        }
    });
    tableViewer.setLabelProvider(new ITableLabelProvider() {

        @Override
        public void removeListener(ILabelProviderListener ilabelproviderlistener) {
        }

        @Override
        public boolean isLabelProperty(Object element, String s) {
            return false;
        }

        @Override
        public void dispose() {
        }

        @Override
        public void addListener(ILabelProviderListener ilabelproviderlistener) {
        }

        @Override
        public String getColumnText(Object element, int i) {
            ApplicationInsightsPageTableElement rowElement = (ApplicationInsightsPageTableElement) element;
            String result = "";
            switch(i) {
                case 0:
                    result = rowElement.getResourceName();
                    break;
                case 1:
                    result = rowElement.getInstrumentationKey();
                    break;
                default:
                    break;
            }
            return result;
        }

        @Override
        public Image getColumnImage(Object element, int i) {
            return null;
        }
    });
    tableViewer.setInput(getTableContent());
    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 1;
    gridData = new GridData();
    gridData.horizontalAlignment = SWT.END;
    gridData.verticalAlignment = GridData.BEGINNING;
    gridData.verticalIndent = 15;
    Composite containerButtons = new Composite(parent, SWT.NONE);
    containerButtons.setLayout(gridLayout);
    containerButtons.setLayoutData(gridData);
    btnNew = new Button(containerButtons, SWT.PUSH);
    btnNew.setText(Messages.btnNewLbl);
    gridData = new GridData();
    gridData.widthHint = 70;
    btnNew.setLayoutData(gridData);
    btnNew.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent arg0) {
            newButtonListener();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent arg0) {
        }
    });
    btnAdd = new Button(containerButtons, SWT.PUSH);
    btnAdd.setText(Messages.btnAddLbl);
    gridData = new GridData();
    gridData.widthHint = 70;
    btnAdd.setLayoutData(gridData);
    btnAdd.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent arg0) {
            addButtonListener();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent arg0) {
        }
    });
    btnDetails = new Button(containerButtons, SWT.PUSH);
    btnDetails.setEnabled(false);
    btnDetails.setText(Messages.btnDtlsLbl);
    gridData = new GridData();
    gridData.widthHint = 70;
    btnDetails.setLayoutData(gridData);
    btnDetails.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent arg0) {
            detailsButtonListener();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent arg0) {
        }
    });
    btnRemove = new Button(containerButtons, SWT.PUSH);
    btnRemove.setEnabled(false);
    btnRemove.setText(Messages.btnRmvLbl);
    gridData = new GridData();
    gridData.widthHint = 70;
    btnRemove.setLayoutData(gridData);
    btnRemove.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent arg0) {
            removeButtonListener();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent arg0) {
        }
    });
    table.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            selIndex = tableViewer.getTable().getSelectionIndex();
            btnDetails.setEnabled(true);
            btnRemove.setEnabled(true);
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent event) {
        }
    });
    tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent selectionchangedevent) {
            if (selectionchangedevent.getSelection().isEmpty()) {
                btnDetails.setEnabled(false);
                btnRemove.setEnabled(false);
            }
        }
    });
}
Also used : Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Image(org.eclipse.swt.graphics.Image) TableColumn(org.eclipse.swt.widgets.TableColumn) ITableLabelProvider(org.eclipse.jface.viewers.ITableLabelProvider) GridLayout(org.eclipse.swt.layout.GridLayout) ILabelProviderListener(org.eclipse.jface.viewers.ILabelProviderListener) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableViewer(org.eclipse.jface.viewers.TableViewer) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 97 with IStructuredContentProvider

use of org.eclipse.jface.viewers.IStructuredContentProvider 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 98 with IStructuredContentProvider

use of org.eclipse.jface.viewers.IStructuredContentProvider 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)

Example 99 with IStructuredContentProvider

use of org.eclipse.jface.viewers.IStructuredContentProvider in project erlide_eclipse by erlang.

the class FoldingConfigurationBlock method createProviderViewer.

private ComboViewer createProviderViewer() {
    /* list viewer */
    final ComboViewer viewer = new ComboViewer(fProviderCombo);
    viewer.setContentProvider(new IStructuredContentProvider() {

        /*
             * @see org.eclipse.jface.viewers.IContentProvider#dispose()
             */
        @Override
        public void dispose() {
        }

        /*
             * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse
             * .jface.viewers.Viewer, java.lang.Object, java.lang.Object)
             */
        @Override
        public void inputChanged(final Viewer v, final Object oldInput, final Object newInput) {
        }

        /*
             * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements
             * (java.lang.Object)
             */
        @Override
        public Object[] getElements(final Object inputElement) {
            return fProviderDescriptors.values().toArray();
        }
    });
    viewer.setLabelProvider(new LabelProvider() {

        /*
             * @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object )
             */
        @Override
        public Image getImage(final Object element) {
            return null;
        }

        /*
             * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
             */
        @Override
        public String getText(final Object element) {
            return ((ErlangFoldingStructureProviderDescriptor) element).getName();
        }
    });
    viewer.addSelectionChangedListener(event -> {
        final IStructuredSelection sel = (IStructuredSelection) event.getSelection();
        if (!sel.isEmpty()) {
            fStore.setValue(PreferenceConstants.EDITOR_FOLDING_PROVIDER, ((ErlangFoldingStructureProviderDescriptor) sel.getFirstElement()).getId());
            updateListDependencies();
        }
    });
    viewer.setInput(fProviderDescriptors);
    viewer.refresh();
    return viewer;
}
Also used : ComboViewer(org.eclipse.jface.viewers.ComboViewer) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Viewer(org.eclipse.jface.viewers.Viewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Image(org.eclipse.swt.graphics.Image) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Aggregations

IStructuredContentProvider (org.eclipse.jface.viewers.IStructuredContentProvider)99 Viewer (org.eclipse.jface.viewers.Viewer)77 Composite (org.eclipse.swt.widgets.Composite)58 GridData (org.eclipse.swt.layout.GridData)54 TableViewer (org.eclipse.jface.viewers.TableViewer)45 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)43 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)42 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)40 GridLayout (org.eclipse.swt.layout.GridLayout)40 LabelProvider (org.eclipse.jface.viewers.LabelProvider)32 Image (org.eclipse.swt.graphics.Image)29 Button (org.eclipse.swt.widgets.Button)28 Label (org.eclipse.swt.widgets.Label)28 SelectionEvent (org.eclipse.swt.events.SelectionEvent)26 Table (org.eclipse.swt.widgets.Table)24 ArrayList (java.util.ArrayList)23 ComboViewer (org.eclipse.jface.viewers.ComboViewer)19 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)19 ILabelProviderListener (org.eclipse.jface.viewers.ILabelProviderListener)18 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)18