Search in sources :

Example 61 with KeyAdapter

use of org.eclipse.swt.events.KeyAdapter 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 62 with KeyAdapter

use of org.eclipse.swt.events.KeyAdapter in project bndtools by bndtools.

the class PkgPatternsListPart method createSection.

protected void createSection(Section section, FormToolkit toolkit) {
    Composite composite = toolkit.createComposite(section);
    section.setClient(composite);
    ToolBar toolbar = new ToolBar(section, SWT.FLAT);
    section.setTextClient(toolbar);
    final ToolItem addItem = new ToolItem(toolbar, SWT.PUSH);
    addItem.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ADD));
    addItem.setToolTipText("Add");
    final ToolItem insertItem = new ToolItem(toolbar, SWT.PUSH);
    insertItem.setImage(imgInsert);
    insertItem.setToolTipText("Insert");
    insertItem.setEnabled(false);
    final ToolItem removeItem = new ToolItem(toolbar, SWT.PUSH);
    removeItem.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_DELETE));
    removeItem.setDisabledImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_DELETE_DISABLED));
    removeItem.setToolTipText("Remove");
    removeItem.setEnabled(false);
    Table table = toolkit.createTable(composite, SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER);
    viewer = new TableViewer(table);
    viewer.setUseHashlookup(false);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(labelProvider);
    toolbar = new ToolBar(composite, SWT.FLAT | SWT.HORIZONTAL | SWT.RIGHT);
    final ToolItem btnMoveUp = new ToolItem(toolbar, SWT.PUSH);
    btnMoveUp.setText("Up");
    btnMoveUp.setImage(imgUp);
    btnMoveUp.setEnabled(false);
    final ToolItem btnMoveDown = new ToolItem(toolbar, SWT.PUSH);
    btnMoveDown.setText("Down");
    btnMoveDown.setImage(imgDown);
    btnMoveDown.setEnabled(false);
    // Listeners
    table.addFocusListener(new FocusAdapter() {

        @Override
        public void focusGained(FocusEvent e) {
            ISelection selection = viewer.getSelection();
            if (!selection.isEmpty())
                managedForm.fireSelectionChanged(PkgPatternsListPart.this, selection);
        }
    });
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            List<C> oldSelection = selection;
            IStructuredSelection structSel = (IStructuredSelection) event.getSelection();
            @SuppressWarnings("unchecked") List<C> newSelection = structSel.toList();
            selection = newSelection;
            propChangeSupport.firePropertyChange(PROP_SELECTION, oldSelection, selection);
            managedForm.fireSelectionChanged(PkgPatternsListPart.this, event.getSelection());
            boolean enabled = !viewer.getSelection().isEmpty();
            insertItem.setEnabled(enabled);
            removeItem.setEnabled(enabled);
            btnMoveUp.setEnabled(enabled);
            btnMoveDown.setEnabled(enabled);
        }
    });
    viewer.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { LocalSelectionTransfer.getTransfer(), ResourceTransfer.getInstance(), TextTransfer.getInstance() }, new PackageDropAdapter<C>(viewer) {

        @Override
        protected C createNewEntry(String packageName) {
            return newHeaderClause(packageName);
        }

        @Override
        protected void addRows(int index, Collection<C> rows) {
            doAddClauses(rows, index, true);
        }

        @Override
        protected int indexOf(Object object) {
            return clauses.indexOf(object);
        }
    });
    table.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            if (e.character == SWT.DEL) {
                doRemoveSelectedClauses();
            } else if (e.character == '+') {
                doAddClausesAfterSelection(generateClauses());
            }
        }
    });
    addItem.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            doAddClausesAfterSelection(generateClauses());
        }
    });
    insertItem.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            doInsertClausesAtSelection(generateClauses());
        }
    });
    removeItem.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            doRemoveSelectedClauses();
        }
    });
    btnMoveUp.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            doMoveUp();
        }
    });
    btnMoveDown.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            doMoveDown();
        }
    });
    // Layout
    GridLayout layout;
    layout = new GridLayout(1, false);
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.verticalSpacing = 0;
    layout.horizontalSpacing = 0;
    composite.setLayout(layout);
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    gd.widthHint = 75;
    gd.heightHint = 75;
    table.setLayoutData(gd);
    toolbar.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
}
Also used : FocusAdapter(org.eclipse.swt.events.FocusAdapter) KeyAdapter(org.eclipse.swt.events.KeyAdapter) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) FocusEvent(org.eclipse.swt.events.FocusEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) ISelection(org.eclipse.jface.viewers.ISelection) SelectionEvent(org.eclipse.swt.events.SelectionEvent) List(java.util.List) ArrayList(java.util.ArrayList) ToolItem(org.eclipse.swt.widgets.ToolItem) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ToolBar(org.eclipse.swt.widgets.ToolBar) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) GridData(org.eclipse.swt.layout.GridData) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 63 with KeyAdapter

use of org.eclipse.swt.events.KeyAdapter in project bndtools by bndtools.

the class PrivatePackagesPart method createSection.

void createSection(Section section, FormToolkit toolkit) {
    section.setText("Private Packages");
    section.setDescription("The listed packages will be included in the bundle but not exported.");
    ToolBar toolbar = new ToolBar(section, SWT.FLAT);
    section.setTextClient(toolbar);
    final ToolItem addItem = new ToolItem(toolbar, SWT.PUSH);
    addItem.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ADD));
    addItem.setToolTipText("Add");
    final ToolItem removeItem = new ToolItem(toolbar, SWT.PUSH);
    removeItem.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_DELETE));
    removeItem.setDisabledImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_DELETE_DISABLED));
    removeItem.setToolTipText("Remove");
    removeItem.setEnabled(false);
    Composite composite = toolkit.createComposite(section);
    section.setClient(composite);
    table = toolkit.createTable(composite, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
    viewer = new TableViewer(table);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new PrivatePackageTableLabelProvider());
    // Listeners
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            managedForm.fireSelectionChanged(PrivatePackagesPart.this, event.getSelection());
            removeItem.setEnabled(!viewer.getSelection().isEmpty());
        }
    });
    viewer.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { LocalSelectionTransfer.getTransfer(), TextTransfer.getInstance(), ResourceTransfer.getInstance() }, new PackageDropAdapter<String>(viewer) {

        @Override
        protected String createNewEntry(String packageName) {
            return packageName;
        }

        @Override
        protected void addRows(int index, Collection<String> rows) {
            if (rows.isEmpty())
                // skip marking dirty
                return;
            if (index == -1) {
                packages.addAll(rows);
                viewer.add(rows.toArray());
            } else {
                packages.addAll(index, rows);
                viewer.refresh();
            }
            viewer.setSelection(new StructuredSelection(rows));
            markDirty();
        }

        @Override
        protected int indexOf(Object object) {
            return 0;
        }
    });
    table.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            if (e.character == SWT.DEL) {
                doRemovePackages();
            } else if (e.character == '+') {
                doAddPackages();
            }
        }
    });
    addItem.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            doAddPackages();
        }
    });
    removeItem.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            doRemovePackages();
        }
    });
    // Layout
    GridLayout layout = new GridLayout(1, false);
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    composite.setLayout(layout);
    GridData gd;
    gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    gd.heightHint = 75;
    gd.widthHint = 75;
    table.setLayoutData(gd);
}
Also used : PrivatePackageTableLabelProvider(bndtools.editor.common.PrivatePackageTableLabelProvider) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) KeyAdapter(org.eclipse.swt.events.KeyAdapter) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) ToolBar(org.eclipse.swt.widgets.ToolBar) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GridData(org.eclipse.swt.layout.GridData) TableViewer(org.eclipse.jface.viewers.TableViewer) ToolItem(org.eclipse.swt.widgets.ToolItem)

Aggregations

KeyAdapter (org.eclipse.swt.events.KeyAdapter)63 KeyEvent (org.eclipse.swt.events.KeyEvent)63 GridData (org.eclipse.swt.layout.GridData)41 GridLayout (org.eclipse.swt.layout.GridLayout)32 Composite (org.eclipse.swt.widgets.Composite)32 SelectionEvent (org.eclipse.swt.events.SelectionEvent)27 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)24 Text (org.eclipse.swt.widgets.Text)22 Label (org.eclipse.swt.widgets.Label)20 TableViewer (org.eclipse.jface.viewers.TableViewer)18 ModifyEvent (org.eclipse.swt.events.ModifyEvent)14 ModifyListener (org.eclipse.swt.events.ModifyListener)14 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)12 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)12 Button (org.eclipse.swt.widgets.Button)12 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)11 Table (org.eclipse.swt.widgets.Table)11 Point (org.eclipse.swt.graphics.Point)9 ToolBar (org.eclipse.swt.widgets.ToolBar)9 MouseAdapter (org.eclipse.swt.events.MouseAdapter)8