Search in sources :

Example 1 with TextHoverDescriptor

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;
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) ModifyListener(org.eclipse.swt.events.ModifyListener) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) Label(org.eclipse.swt.widgets.Label) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) KeyEvent(org.eclipse.swt.events.KeyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) FontMetrics(org.eclipse.swt.graphics.FontMetrics) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GC(org.eclipse.swt.graphics.GC) TableLayout(org.eclipse.jface.viewers.TableLayout) Composite(org.eclipse.swt.widgets.Composite) TextHoverDescriptor(org.eclipse.wst.sse.ui.internal.taginfo.TextHoverManager.TextHoverDescriptor) Text(org.eclipse.swt.widgets.Text) Point(org.eclipse.swt.graphics.Point) TableColumn(org.eclipse.swt.widgets.TableColumn) Point(org.eclipse.swt.graphics.Point) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) TextHoverManager(org.eclipse.wst.sse.ui.internal.taginfo.TextHoverManager) KeyListener(org.eclipse.swt.events.KeyListener) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)1 CheckStateChangedEvent (org.eclipse.jface.viewers.CheckStateChangedEvent)1 CheckboxTableViewer (org.eclipse.jface.viewers.CheckboxTableViewer)1 ColumnWeightData (org.eclipse.jface.viewers.ColumnWeightData)1 ICheckStateListener (org.eclipse.jface.viewers.ICheckStateListener)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 TableLayout (org.eclipse.jface.viewers.TableLayout)1 KeyEvent (org.eclipse.swt.events.KeyEvent)1 KeyListener (org.eclipse.swt.events.KeyListener)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 SelectionListener (org.eclipse.swt.events.SelectionListener)1 FontMetrics (org.eclipse.swt.graphics.FontMetrics)1 GC (org.eclipse.swt.graphics.GC)1 Point (org.eclipse.swt.graphics.Point)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1