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;
}
Aggregations