Search in sources :

Example 1 with StubTypeContext

use of org.eclipse.jdt.internal.corext.refactoring.StubTypeContext in project bndtools by bndtools.

the class NewTypeWizardPage method createSuperInterfacesControls.

/**
     * Creates the controls for the superclass name field. Expects a <code>GridLayout</code> with at least 3 columns.
     *
     * @param composite
     *            the parent composite
     * @param nColumns
     *            number of columns to span
     */
protected void createSuperInterfacesControls(Composite composite, int nColumns) {
    //$NON-NLS-1$
    final String INTERFACE = "interface";
    fSuperInterfacesDialogField.doFillIntoGrid(composite, nColumns);
    final TableViewer tableViewer = fSuperInterfacesDialogField.getTableViewer();
    tableViewer.setColumnProperties(new String[] { INTERFACE });
    TableTextCellEditor cellEditor = new TableTextCellEditor(tableViewer, 0) {

        @Override
        protected void doSetFocus() {
            if (text != null) {
                text.setFocus();
                text.setSelection(text.getText().length());
                checkSelection();
                checkDeleteable();
                checkSelectable();
            }
        }
    };
    JavaTypeCompletionProcessor superInterfaceCompletionProcessor = new JavaTypeCompletionProcessor(false, false, true);
    superInterfaceCompletionProcessor.setCompletionContextRequestor(new CompletionContextRequestor() {

        @Override
        public StubTypeContext getStubTypeContext() {
            return getSuperInterfacesStubTypeContext();
        }
    });
    @SuppressWarnings("deprecation") org.eclipse.jface.contentassist.SubjectControlContentAssistant contentAssistant = ControlContentAssistHelper.createJavaContentAssistant(superInterfaceCompletionProcessor);
    Text cellEditorText = cellEditor.getText();
    @SuppressWarnings({ "deprecation", "unused" }) org.eclipse.ui.contentassist.ContentAssistHandler contentAssistantHandler = org.eclipse.ui.contentassist.ContentAssistHandler.createHandlerForText(cellEditorText, contentAssistant);
    TextFieldNavigationHandler.install(cellEditorText);
    cellEditor.setContentAssistant(contentAssistant);
    tableViewer.setCellEditors(new CellEditor[] { cellEditor });
    tableViewer.setCellModifier(new ICellModifier() {

        @Override
        public void modify(Object element, String property, Object value) {
            Object el = element;
            if (el instanceof Item)
                el = ((Item) el).getData();
            ((InterfaceWrapper) el).interfaceName = (String) value;
            fSuperInterfacesDialogField.elementChanged((InterfaceWrapper) el);
        }

        @Override
        public Object getValue(Object element, String property) {
            return ((InterfaceWrapper) element).interfaceName;
        }

        @Override
        public boolean canModify(Object element, String property) {
            return true;
        }
    });
    tableViewer.getTable().addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent event) {
            if (event.keyCode == SWT.F2 && event.stateMask == 0) {
                ISelection selection = tableViewer.getSelection();
                if (!(selection instanceof IStructuredSelection))
                    return;
                IStructuredSelection structuredSelection = (IStructuredSelection) selection;
                tableViewer.editElement(structuredSelection.getFirstElement(), 0);
            }
        }
    });
    GridData gd = (GridData) fSuperInterfacesDialogField.getListControl(null).getLayoutData();
    if (fTypeKind == CLASS_TYPE) {
        gd.heightHint = convertHeightInCharsToPixels(3);
    } else {
        gd.heightHint = convertHeightInCharsToPixels(6);
    }
    gd.grabExcessVerticalSpace = false;
    gd.widthHint = getMaxFieldWidth();
}
Also used : KeyAdapter(org.eclipse.swt.events.KeyAdapter) Text(org.eclipse.swt.widgets.Text) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) JavaTypeCompletionProcessor(org.eclipse.jdt.internal.ui.refactoring.contentassist.JavaTypeCompletionProcessor) KeyEvent(org.eclipse.swt.events.KeyEvent) Item(org.eclipse.swt.widgets.Item) ICellModifier(org.eclipse.jface.viewers.ICellModifier) ISelection(org.eclipse.jface.viewers.ISelection) GridData(org.eclipse.swt.layout.GridData) StubTypeContext(org.eclipse.jdt.internal.corext.refactoring.StubTypeContext) CompletionContextRequestor(org.eclipse.jdt.internal.ui.refactoring.contentassist.CompletionContextRequestor) TableViewer(org.eclipse.jface.viewers.TableViewer) TableTextCellEditor(org.eclipse.jdt.internal.ui.dialogs.TableTextCellEditor)

Example 2 with StubTypeContext

use of org.eclipse.jdt.internal.corext.refactoring.StubTypeContext in project bndtools by bndtools.

the class NewTypeWizardPage method createSuperClassControls.

/**
     * Creates the controls for the superclass name field. Expects a <code>GridLayout</code> with at least 3 columns.
     *
     * @param composite
     *            the parent composite
     * @param nColumns
     *            number of columns to span
     */
protected void createSuperClassControls(Composite composite, int nColumns) {
    fSuperClassDialogField.doFillIntoGrid(composite, nColumns);
    Text text = fSuperClassDialogField.getTextControl(null);
    LayoutUtil.setWidthHint(text, getMaxFieldWidth());
    JavaTypeCompletionProcessor superClassCompletionProcessor = new JavaTypeCompletionProcessor(false, false, true);
    superClassCompletionProcessor.setCompletionContextRequestor(new CompletionContextRequestor() {

        @Override
        public StubTypeContext getStubTypeContext() {
            return getSuperClassStubTypeContext();
        }
    });
    ControlContentAssistHelper.createTextContentAssistant(text, superClassCompletionProcessor);
    TextFieldNavigationHandler.install(text);
}
Also used : StubTypeContext(org.eclipse.jdt.internal.corext.refactoring.StubTypeContext) Text(org.eclipse.swt.widgets.Text) CompletionContextRequestor(org.eclipse.jdt.internal.ui.refactoring.contentassist.CompletionContextRequestor) JavaTypeCompletionProcessor(org.eclipse.jdt.internal.ui.refactoring.contentassist.JavaTypeCompletionProcessor)

Aggregations

StubTypeContext (org.eclipse.jdt.internal.corext.refactoring.StubTypeContext)2 CompletionContextRequestor (org.eclipse.jdt.internal.ui.refactoring.contentassist.CompletionContextRequestor)2 JavaTypeCompletionProcessor (org.eclipse.jdt.internal.ui.refactoring.contentassist.JavaTypeCompletionProcessor)2 Text (org.eclipse.swt.widgets.Text)2 TableTextCellEditor (org.eclipse.jdt.internal.ui.dialogs.TableTextCellEditor)1 ICellModifier (org.eclipse.jface.viewers.ICellModifier)1 ISelection (org.eclipse.jface.viewers.ISelection)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 TableViewer (org.eclipse.jface.viewers.TableViewer)1 KeyAdapter (org.eclipse.swt.events.KeyAdapter)1 KeyEvent (org.eclipse.swt.events.KeyEvent)1 GridData (org.eclipse.swt.layout.GridData)1 Item (org.eclipse.swt.widgets.Item)1