use of org.eclipse.wst.sse.ui.internal.taginfo.TextHoverManager.TextHoverDescriptor in project webtools.sourceediting by eclipse.
the class TextHoverPreferenceTab method createContents.
/*
* (non-Javadoc)
*
* @see org.eclipse.wst.sse.ui.preferences.ui.IPreferenceTab#createContents(org.eclipse.swt.widgets.Composite)
*/
public Control createContents(Composite tabFolder) {
Composite hoverComposite = new Composite(tabFolder, SWT.NONE);
GridLayout layout = new GridLayout();
layout.numColumns = 2;
hoverComposite.setLayout(layout);
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
hoverComposite.setLayoutData(gd);
// commented out until these preferences are actually handled in some
// way
// String rollOverLabel=
// ResourceHandler.getString("TextHoverPreferenceTab.annotationRollover");
// //$NON-NLS-1$
// addCheckBox(hoverComposite, rollOverLabel,
// CommonEditorPreferenceNames.EDITOR_ANNOTATION_ROLL_OVER, 0);
//
// // Affordance checkbox
// String showAffordanceLabel =
// ResourceHandler.getString("TextHoverPreferenceTab.showAffordance");
// //$NON-NLS-1$
// addCheckBox(hoverComposite, showAffordanceLabel,
// CommonEditorPreferenceNames.EDITOR_SHOW_TEXT_HOVER_AFFORDANCE, 0);
Label label = new Label(hoverComposite, SWT.NONE);
// $NON-NLS-1$
label.setText(SSEUIMessages.TextHoverPreferenceTab_hoverPreferences);
gd = new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1);
gd.horizontalAlignment = GridData.BEGINNING;
label.setLayoutData(gd);
fHoverTableViewer = CheckboxTableViewer.newCheckList(hoverComposite, SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION);
// Hover table
fHoverTable = fHoverTableViewer.getTable();
fHoverTable.setHeaderVisible(true);
fHoverTable.setLinesVisible(true);
gd = new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1);
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=104507
GC gc = new GC(fHoverTable);
gc.setFont(fHoverTable.getFont());
FontMetrics fontMetrics = gc.getFontMetrics();
gc.dispose();
int heightHint = Dialog.convertHeightInCharsToPixels(fontMetrics, 7);
gd.heightHint = heightHint;
fHoverTable.setLayoutData(gd);
TableLayout tableLayout = new TableLayout();
tableLayout.addColumnData(new ColumnWeightData(1, 140, true));
tableLayout.addColumnData(new ColumnWeightData(1, 140, true));
fHoverTable.setLayout(tableLayout);
fHoverTable.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
}
public void widgetSelected(SelectionEvent e) {
handleHoverListSelection();
}
});
fNameColumn = new TableColumn(fHoverTable, SWT.NONE);
// $NON-NLS-1$
fNameColumn.setText(SSEUIMessages.TextHoverPreferenceTab_nameColumnTitle);
fNameColumn.setResizable(true);
fModifierColumn = new TableColumn(fHoverTable, SWT.NONE);
// $NON-NLS-1$
fModifierColumn.setText(SSEUIMessages.TextHoverPreferenceTab_modifierColumnTitle);
fModifierColumn.setResizable(true);
fHoverTableViewer.setUseHashlookup(true);
fHoverTableViewer.setContentProvider(new ArrayContentProvider());
fHoverTableViewer.setLabelProvider(new InternalTableLabelProvider());
((CheckboxTableViewer) fHoverTableViewer).addCheckStateListener(new ICheckStateListener() {
/*
* @see org.eclipse.jface.viewers.ICheckStateListener#checkStateChanged(org.eclipse.jface.viewers.CheckStateChangedEvent)
*/
public void checkStateChanged(CheckStateChangedEvent event) {
String id = ((TextHoverDescriptor) event.getElement()).getId();
if (id == null)
return;
TextHoverManager.TextHoverDescriptor[] descriptors = getTextHoverManager().getTextHovers();
TextHoverManager.TextHoverDescriptor hoverConfig = null;
int i = 0, length = fTextHovers.length;
while (i < length) {
if (id.equals(descriptors[i].getId())) {
hoverConfig = fTextHovers[i];
hoverConfig.setEnabled(event.getChecked());
fModifierEditor.setEnabled(event.getChecked());
fHoverTableViewer.setSelection(new StructuredSelection(descriptors[i]));
}
i++;
}
handleHoverListSelection();
updateStatus(hoverConfig);
}
});
// Text field for modifier string
label = new Label(hoverComposite, SWT.LEFT);
// $NON-NLS-1$
label.setText(SSEUIMessages.TextHoverPreferenceTab_keyModifier);
fModifierEditor = new Text(hoverComposite, SWT.BORDER);
gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
fModifierEditor.setLayoutData(gd);
fModifierEditor.addKeyListener(new KeyListener() {
private boolean isModifierCandidate;
public void keyPressed(KeyEvent e) {
isModifierCandidate = e.keyCode > 0 && e.character == 0 && e.stateMask == 0;
}
public void keyReleased(KeyEvent e) {
if (isModifierCandidate && e.stateMask > 0 && e.stateMask == e.stateMask && e.character == 0) {
// &&
// e.time
// -time
// <
// 1000)
// {
String text = fModifierEditor.getText();
Point selection = fModifierEditor.getSelection();
int i = selection.x - 1;
while (i > -1 && Character.isWhitespace(text.charAt(i))) {
i--;
}
boolean needsPrefixDelimiter = i > -1 && !String.valueOf(text.charAt(i)).equals(DELIMITER);
i = selection.y;
while (i < text.length() && Character.isWhitespace(text.charAt(i))) {
i++;
}
boolean needsPostfixDelimiter = i < text.length() && !String.valueOf(text.charAt(i)).equals(DELIMITER);
String insertString;
if (needsPrefixDelimiter && needsPostfixDelimiter)
insertString = NLS.bind(SSEUIMessages.TextHoverPreferenceTab_insertDelimiterAndModifierAndDelimiter, new String[] { Action.findModifierString(e.stateMask) });
else if (needsPrefixDelimiter)
insertString = NLS.bind(SSEUIMessages.TextHoverPreferenceTab_insertDelimiterAndModifier, new String[] { Action.findModifierString(e.stateMask) });
else if (needsPostfixDelimiter)
insertString = NLS.bind(SSEUIMessages.TextHoverPreferenceTab_insertModifierAndDelimiter, new String[] { Action.findModifierString(e.stateMask) });
else
insertString = Action.findModifierString(e.stateMask);
if (insertString != null)
fModifierEditor.insert(insertString);
}
}
});
fModifierEditor.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
handleModifierModified();
}
});
// Description
Label descriptionLabel = new Label(hoverComposite, SWT.LEFT);
// $NON-NLS-1$
descriptionLabel.setText(SSEUIMessages.TextHoverPreferenceTab_description);
gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING);
gd.horizontalSpan = 2;
descriptionLabel.setLayoutData(gd);
fDescription = new Text(hoverComposite, SWT.LEFT | SWT.WRAP | SWT.MULTI | SWT.READ_ONLY | SWT.BORDER);
gd = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
gd.horizontalSpan = 2;
fDescription.setLayoutData(gd);
initialize();
Dialog.applyDialogFont(hoverComposite);
PlatformUI.getWorkbench().getHelpSystem().setHelp(hoverComposite, IHelpContextIds.PREFSTE_HOVERS_HELPID);
return hoverComposite;
}
Aggregations