Search in sources :

Example 1 with TableLayoutComposite

use of org.python.pydev.ui.TableLayoutComposite in project Pydev by fabioz.

the class PyEditorHoverConfigurationBlock method createControl.

/**
 * Creates page for hover preferences.
 *
 * @param parent the parent composite
 * @return the control for the preference page
 */
@Override
public Control createControl(final Composite parent) {
    priorityHelpRange = new StyleRange(PyEditorMessages.PyEditorHoverConfigurationBlock_hoverPreferences.length(), priorityHelpStr.length(), parent.getDisplay().getSystemColor(SWT.COLOR_BLUE), null);
    fComp = new Composite(parent, SWT.NONE);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(fComp);
    GridLayoutFactory.fillDefaults().numColumns(3).applyTo(fComp);
    fButtonComp = new Composite(fComp, SWT.BORDER);
    GridLayoutFactory.fillDefaults().numColumns(2).applyTo(fButtonComp);
    fUseFirstHover = new Button(fButtonComp, SWT.RADIO | SWT.BORDER);
    fUseFirstHover.setText("Use highest priority Hover");
    GridDataFactory.fillDefaults().applyTo(fUseFirstHover);
    fCombineHovers = new Button(fButtonComp, SWT.RADIO | SWT.BORDER);
    fCombineHovers.setText("Combine Hovers");
    GridDataFactory.fillDefaults().applyTo(fCombineHovers);
    fCombineHovers.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            fCombiningHoverModifierEditor.setEnabled(fCombineHovers.getSelection());
            fCombiningHoverLabel.setEnabled(fCombineHovers.getSelection());
            showColumn(fPreemptColumn, fCombineHovers.getSelection());
            showColumn(fModifierColumn, !fCombineHovers.getSelection());
            fModifierFieldLabel.setEnabled(!fCombineHovers.getSelection());
        }
    });
    fCombiningHoverLabel = new Label(fComp, SWT.PUSH);
    fCombiningHoverLabel.setText("Combined Hovers Key Modifier:");
    fCombiningHoverModifierEditor = new Text(fComp, SWT.BORDER);
    fCombiningHoverModifierEditor.addKeyListener(new KeyModifierListener(fCombiningHoverModifierEditor));
    fCombiningHoverModifierEditor.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            handleModifierModified(fCombiningHoverModifierEditor);
        }
    });
    GridDataFactory.fillDefaults().grab(true, false).applyTo(fCombiningHoverModifierEditor);
    ScrolledPageContent scrolled = new ScrolledPageContent(parent, SWT.H_SCROLL | SWT.V_SCROLL);
    scrolled.setExpandHorizontal(true);
    scrolled.setExpandVertical(true);
    Composite hoverComposite = new Composite(scrolled, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    hoverComposite.setLayout(layout);
    addFiller(hoverComposite);
    fTableLabel = new StyledText(hoverComposite, SWT.NONE);
    fTableLabel.setEditable(false);
    fTableLabel.setEnabled(false);
    fTableLabel.setBackground(fTableLabel.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
    fTableLabel.setText(PyEditorMessages.PyEditorHoverConfigurationBlock_hoverPreferences);
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalAlignment = GridData.BEGINNING;
    gd.horizontalSpan = 2;
    fTableLabel.setLayoutData(gd);
    TableLayoutComposite layouter = new TableLayoutComposite(hoverComposite, SWT.NONE);
    addColumnLayoutData(layouter, fColWidths);
    // Hover table
    fHoverTable = new Table(layouter, SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE | SWT.FULL_SELECTION | SWT.CHECK);
    fHoverTable.setHeaderVisible(true);
    fHoverTable.setLinesVisible(true);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.heightHint = SWTUtil.getTableHeightHint(fHoverTable, 10);
    gd.horizontalSpan = 2;
    gd.widthHint = new PixelConverter(parent).convertWidthInCharsToPixels(100);
    layouter.setLayoutData(gd);
    fHoverTable.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            handleHoverListSelection();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
    TableLayout tableLayout = new TableLayout();
    fHoverTable.setLayout(tableLayout);
    fHoverTableViewer = new CheckboxTableViewer(fHoverTable);
    TableViewerColumn nameColumnViewer = new TableViewerColumn(fHoverTableViewer, SWT.NONE);
    nameColumnViewer.setLabelProvider(new PyEditorTextHoverDescriptorLabelProvider(fHoverTableViewer));
    fNameColumn = nameColumnViewer.getColumn();
    fNameColumn.setText(PyEditorMessages.PyEditorHoverConfigurationBlock_nameColumnTitle);
    fNameColumn.setResizable(true);
    TableViewerColumn priorityViewerColumn = new TableViewerColumn(fHoverTableViewer, SWT.NONE);
    priorityViewerColumn.setEditingSupport(new HoverTableEditingSupport(fHoverTableViewer, PRIORITY_PROP));
    priorityViewerColumn.setLabelProvider(new PyEditorTextHoverDescriptorLabelProvider(fHoverTableViewer));
    fPriorityColumn = priorityViewerColumn.getColumn();
    fPriorityColumn.setText(PyEditorMessages.PyEditorHoverConfigurationBlock_priorityColumnTitle);
    fPriorityColumn.setResizable(true);
    TableViewerColumn modifierColumnViewer = new TableViewerColumn(fHoverTableViewer, SWT.NONE);
    modifierColumnViewer.setLabelProvider(new PyEditorTextHoverDescriptorLabelProvider(fHoverTableViewer));
    fModifierColumn = modifierColumnViewer.getColumn();
    fModifierColumn.setText(PyEditorMessages.PyEditorHoverConfigurationBlock_modifierColumnTitle);
    fModifierColumn.setResizable(true);
    TableViewerColumn preemptViewerColumn = new TableViewerColumn(fHoverTableViewer, SWT.NONE);
    preemptViewerColumn.setEditingSupport(new HoverTableEditingSupport(fHoverTableViewer, PREEMPT_PROP));
    preemptViewerColumn.setLabelProvider(new PyEditorTextHoverDescriptorLabelProvider(fHoverTableViewer));
    fPreemptColumn = preemptViewerColumn.getColumn();
    fPreemptColumn.setText(PyEditorMessages.PyEditorHoverConfigurationBlock_preemptColumnTitle);
    fPreemptColumn.setResizable(true);
    fHoverTableViewer.setUseHashlookup(true);
    fHoverTableViewer.setContentProvider(new PyEditorTextHoverDescriptorContentProvider());
    fHoverTableViewer.addCheckStateListener(new ICheckStateListener() {

        /*
             * @see org.eclipse.jface.viewers.ICheckStateListener#checkStateChanged(org.eclipse.jface.viewers.Che((CheckboxTreeViewer) fHoverTableViewer)nt)
             */
        @Override
        public void checkStateChanged(CheckStateChangedEvent event) {
            String id = ((PyEditorTextHoverDescriptor) event.getElement()).getId();
            if (id == null) {
                return;
            }
            PyEditorTextHoverDescriptor[] descriptors = fHoverDescs;
            PyEditorTextHoverDescriptor hover = null;
            int i = 0, length = fHoverDescs.length;
            while (i < length) {
                if (id.equals(descriptors[i].getId())) {
                    hover = fHoverDescs[i];
                    hover.setIsEnabled(event.getChecked());
                    fModifierEditor.setEnabled(event.getChecked());
                    fHoverTableViewer.setSelection(new StructuredSelection(descriptors[i]));
                }
                i++;
            }
            handleHoverListSelection();
            updateStatus(hover);
        }
    });
    fHoverTableViewer.setSorter(new ViewerSorter() {

        @Override
        public int compare(Viewer viewer, Object e1, Object e2) {
            return ((PyEditorTextHoverDescriptor) e1).getPriority().compareTo(((PyEditorTextHoverDescriptor) e2).getPriority());
        }
    });
    // Text field for modifier string
    fModifierFieldLabel = new Label(hoverComposite, SWT.LEFT);
    fModifierFieldLabel.setText(PyEditorMessages.PyEditorHoverConfigurationBlock_keyModifier);
    fModifierEditor = new Text(hoverComposite, SWT.BORDER);
    gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    fModifierEditor.setLayoutData(gd);
    fModifierEditor.addKeyListener(new KeyModifierListener(fModifierEditor));
    fModifierEditor.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            handleModifierModified(fModifierEditor);
        }
    });
    // Description
    Label label = new Label(hoverComposite, SWT.LEFT);
    label.setText(PyEditorMessages.PyEditorHoverConfigurationBlock_description);
    gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING);
    gd.horizontalSpan = 2;
    label.setLayoutData(gd);
    fDescription = new Text(hoverComposite, SWT.LEFT | SWT.WRAP | SWT.MULTI | SWT.READ_ONLY | SWT.BORDER);
    SWTUtil.fixReadonlyTextBackground(fDescription);
    gd = new GridData(GridData.FILL_BOTH);
    gd.horizontalSpan = 2;
    fDescription.setLayoutData(gd);
    fDebugShowVars = new Button(parent, SWT.CHECK);
    fDebugShowVars.setText("Show variables values while debugging");
    fDebugShowVars.setSelection(PyHoverPreferencesPage.getShowValuesWhileDebuggingOnHover());
    fUseHoverDivider = new Button(parent, SWT.CHECK);
    fUseHoverDivider.setText("Add divider between contributions when combining hovers");
    fUseHoverDivider.setSelection(PyHoverPreferencesPage.getUseHoverDelimiters());
    scrolled.setContent(hoverComposite);
    final Point size = hoverComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    scrolled.setMinSize(size.x, size.y);
    Dialog.applyDialogFont(scrolled);
    return fComp;
}
Also used : ModifyListener(org.eclipse.swt.events.ModifyListener) TableLayoutComposite(org.python.pydev.ui.TableLayoutComposite) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) StyleRange(org.eclipse.swt.custom.StyleRange) Label(org.eclipse.swt.widgets.Label) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ViewerSorter(org.eclipse.jface.viewers.ViewerSorter) TableViewer(org.eclipse.jface.viewers.TableViewer) ColumnViewer(org.eclipse.jface.viewers.ColumnViewer) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) Viewer(org.eclipse.jface.viewers.Viewer) ModifyEvent(org.eclipse.swt.events.ModifyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableLayout(org.eclipse.jface.viewers.TableLayout) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) ScrolledPageContent(org.python.pydev.ui.ScrolledPageContent) StyledText(org.eclipse.swt.custom.StyledText) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) TableLayoutComposite(org.python.pydev.ui.TableLayoutComposite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) StyledText(org.eclipse.swt.custom.StyledText) Text(org.eclipse.swt.widgets.Text) Point(org.eclipse.swt.graphics.Point) GridData(org.eclipse.swt.layout.GridData) PixelConverter(org.eclipse.jface.layout.PixelConverter) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

PixelConverter (org.eclipse.jface.layout.PixelConverter)1 CheckStateChangedEvent (org.eclipse.jface.viewers.CheckStateChangedEvent)1 CheckboxTableViewer (org.eclipse.jface.viewers.CheckboxTableViewer)1 ColumnViewer (org.eclipse.jface.viewers.ColumnViewer)1 ICheckStateListener (org.eclipse.jface.viewers.ICheckStateListener)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 TableLayout (org.eclipse.jface.viewers.TableLayout)1 TableViewer (org.eclipse.jface.viewers.TableViewer)1 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)1 Viewer (org.eclipse.jface.viewers.Viewer)1 ViewerSorter (org.eclipse.jface.viewers.ViewerSorter)1 StyleRange (org.eclipse.swt.custom.StyleRange)1 StyledText (org.eclipse.swt.custom.StyledText)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 SelectionListener (org.eclipse.swt.events.SelectionListener)1 Point (org.eclipse.swt.graphics.Point)1