Search in sources :

Example 81 with Listener

use of org.eclipse.swt.widgets.Listener in project eclipse.platform.text by eclipse.

the class TemplatePreferencePage method createContents.

@Override
protected Control createContents(Composite ancestor) {
    Composite parent = new Composite(ancestor, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    parent.setLayout(layout);
    Composite innerParent = new Composite(parent, SWT.NONE);
    GridLayout innerLayout = new GridLayout();
    innerLayout.numColumns = 2;
    innerLayout.marginHeight = 0;
    innerLayout.marginWidth = 0;
    innerParent.setLayout(innerLayout);
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.horizontalSpan = 2;
    innerParent.setLayoutData(gd);
    Composite tableComposite = new Composite(innerParent, SWT.NONE);
    GridData data = new GridData(GridData.FILL_BOTH);
    data.widthHint = 360;
    data.heightHint = convertHeightInCharsToPixels(10);
    tableComposite.setLayoutData(data);
    ColumnLayout columnLayout = new ColumnLayout();
    tableComposite.setLayout(columnLayout);
    Table table = new Table(tableComposite, SWT.CHECK | SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL);
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    GC gc = new GC(getShell());
    gc.setFont(JFaceResources.getDialogFont());
    TemplateViewerComparator viewerComparator = new TemplateViewerComparator();
    TableColumn column1 = new TableColumn(table, SWT.NONE);
    column1.setText(TemplatesMessages.TemplatePreferencePage_column_name);
    int minWidth = computeMinimumColumnWidth(gc, TemplatesMessages.TemplatePreferencePage_column_name);
    columnLayout.addColumnData(new ColumnWeightData(2, minWidth, true));
    column1.addSelectionListener(new TemplateColumnSelectionAdapter(column1, 0, viewerComparator));
    TableColumn column2 = new TableColumn(table, SWT.NONE);
    column2.setText(TemplatesMessages.TemplatePreferencePage_column_context);
    minWidth = computeMinimumContextColumnWidth(gc);
    columnLayout.addColumnData(new ColumnWeightData(1, minWidth, true));
    column2.addSelectionListener(new TemplateColumnSelectionAdapter(column2, 1, viewerComparator));
    TableColumn column3 = new TableColumn(table, SWT.NONE);
    column3.setText(TemplatesMessages.TemplatePreferencePage_column_description);
    minWidth = computeMinimumColumnWidth(gc, TemplatesMessages.TemplatePreferencePage_column_description);
    columnLayout.addColumnData(new ColumnWeightData(3, minWidth, true));
    column3.addSelectionListener(new TemplateColumnSelectionAdapter(column3, 2, viewerComparator));
    TableColumn column4 = new TableColumn(table, SWT.NONE);
    column4.setAlignment(SWT.CENTER);
    column4.setText(TemplatesMessages.TemplatePreferencePage_column_autoinsert);
    minWidth = computeMinimumColumnWidth(gc, TemplatesMessages.TemplatePreferencePage_column_autoinsert);
    minWidth = Math.max(minWidth, computeMinimumColumnWidth(gc, TemplatesMessages.TemplatePreferencePage_on));
    columnLayout.addColumnData(new ColumnPixelData(minWidth, false, false));
    column4.addSelectionListener(new TemplateColumnSelectionAdapter(column4, 3, viewerComparator));
    gc.dispose();
    fTableViewer = new CheckboxTableViewer(table);
    fTableViewer.setLabelProvider(new TemplateLabelProvider());
    fTableViewer.setContentProvider(new TemplateContentProvider());
    fTableViewer.setComparator(viewerComparator);
    // Specify default sorting
    table.setSortColumn(column1);
    table.setSortDirection(viewerComparator.getDirection());
    fTableViewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent e) {
            edit();
        }
    });
    fTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent e) {
            selectionChanged1();
        }
    });
    fTableViewer.addCheckStateListener(new ICheckStateListener() {

        @Override
        public void checkStateChanged(CheckStateChangedEvent event) {
            TemplatePersistenceData d = (TemplatePersistenceData) event.getElement();
            d.setEnabled(event.getChecked());
        }
    });
    BidiUtils.applyTextDirection(fTableViewer.getControl(), BidiUtils.BTD_DEFAULT);
    Composite buttons = new Composite(innerParent, SWT.NONE);
    buttons.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
    layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    buttons.setLayout(layout);
    fAddButton = new Button(buttons, SWT.PUSH);
    fAddButton.setText(TemplatesMessages.TemplatePreferencePage_new);
    fAddButton.setLayoutData(getButtonGridData(fAddButton));
    fAddButton.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event e) {
            add();
        }
    });
    fEditButton = new Button(buttons, SWT.PUSH);
    fEditButton.setText(TemplatesMessages.TemplatePreferencePage_edit);
    fEditButton.setLayoutData(getButtonGridData(fEditButton));
    fEditButton.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event e) {
            edit();
        }
    });
    fRemoveButton = new Button(buttons, SWT.PUSH);
    fRemoveButton.setText(TemplatesMessages.TemplatePreferencePage_remove);
    fRemoveButton.setLayoutData(getButtonGridData(fRemoveButton));
    fRemoveButton.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event e) {
            remove();
        }
    });
    createSeparator(buttons);
    fRestoreButton = new Button(buttons, SWT.PUSH);
    fRestoreButton.setText(TemplatesMessages.TemplatePreferencePage_restore);
    fRestoreButton.setLayoutData(getButtonGridData(fRestoreButton));
    fRestoreButton.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event e) {
            restoreDeleted();
        }
    });
    fRevertButton = new Button(buttons, SWT.PUSH);
    fRevertButton.setText(TemplatesMessages.TemplatePreferencePage_revert);
    fRevertButton.setLayoutData(getButtonGridData(fRevertButton));
    fRevertButton.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event e) {
            revert();
        }
    });
    createSeparator(buttons);
    fImportButton = new Button(buttons, SWT.PUSH);
    fImportButton.setText(TemplatesMessages.TemplatePreferencePage_import);
    fImportButton.setLayoutData(getButtonGridData(fImportButton));
    fImportButton.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event e) {
            import_();
        }
    });
    fExportButton = new Button(buttons, SWT.PUSH);
    fExportButton.setText(TemplatesMessages.TemplatePreferencePage_export);
    fExportButton.setLayoutData(getButtonGridData(fExportButton));
    fExportButton.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event e) {
            export();
        }
    });
    fPatternViewer = doCreateViewer(parent);
    if (isShowFormatterSetting()) {
        fFormatButton = new Button(parent, SWT.CHECK);
        fFormatButton.setText(TemplatesMessages.TemplatePreferencePage_use_code_formatter);
        GridData gd1 = new GridData();
        gd1.horizontalSpan = 2;
        fFormatButton.setLayoutData(gd1);
        fFormatButton.setSelection(getPreferenceStore().getBoolean(getFormatterPreferenceKey()));
    }
    fTableViewer.setInput(fTemplateStore);
    fTableViewer.setAllChecked(false);
    fTableViewer.setCheckedElements(getEnabledTemplates());
    updateButtons();
    Dialog.applyDialogFont(parent);
    innerParent.layout();
    return parent;
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) SelectionListener(org.eclipse.swt.events.SelectionListener) ITextListener(org.eclipse.jface.text.ITextListener) Listener(org.eclipse.swt.widgets.Listener) ModifyListener(org.eclipse.swt.events.ModifyListener) DisposeListener(org.eclipse.swt.events.DisposeListener) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) IMenuListener(org.eclipse.jface.action.IMenuListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) FocusListener(org.eclipse.swt.events.FocusListener) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) GC(org.eclipse.swt.graphics.GC) TemplatePersistenceData(org.eclipse.jface.text.templates.persistence.TemplatePersistenceData) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) TableColumn(org.eclipse.swt.widgets.TableColumn) GridData(org.eclipse.swt.layout.GridData) FocusEvent(org.eclipse.swt.events.FocusEvent) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) DisposeEvent(org.eclipse.swt.events.DisposeEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) Event(org.eclipse.swt.widgets.Event) TextEvent(org.eclipse.jface.text.TextEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent)

Example 82 with Listener

use of org.eclipse.swt.widgets.Listener in project eclipse.platform.text by eclipse.

the class TextViewer method createControl.

/**
 * Creates the viewer's SWT control. The viewer's text widget either is
 * the control or is a child of the control.
 *
 * @param parent the parent of the viewer's control
 * @param styles the SWT style bits for the viewer's control
 */
protected void createControl(Composite parent, int styles) {
    fTextWidget = createTextWidget(parent, styles);
    // Support scroll page upon MOD1+MouseWheel
    fTextWidget.addListener(SWT.MouseVerticalWheel, new Listener() {

        @Override
        public void handleEvent(Event event) {
            if (((event.stateMask & SWT.MOD1) == 0))
                return;
            int topIndex = fTextWidget.getTopIndex();
            int bottomIndex = JFaceTextUtil.getBottomIndex(fTextWidget);
            if (event.count > 0)
                fTextWidget.setTopIndex(2 * topIndex - bottomIndex);
            else
                fTextWidget.setTopIndex(bottomIndex);
            updateViewportListeners(INTERNAL);
        }
    });
    fTextWidget.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            fDisposedControl = getControl();
            handleDispose();
        }
    });
    fTextWidget.setFont(parent.getFont());
    fTextWidget.setDoubleClickEnabled(true);
    /*
		 * Disable SWT Shift+TAB traversal in this viewer
		 * 1GIYQ9K: ITPUI:WINNT - StyledText swallows Shift+TAB
		 */
    fTextWidget.addTraverseListener(new TraverseListener() {

        @Override
        public void keyTraversed(TraverseEvent e) {
            if ((SWT.SHIFT == e.stateMask) && ('\t' == e.character))
                e.doit = !fTextWidget.getEditable();
        }
    });
    // where does the first line start
    fTopInset = -fTextWidget.computeTrim(0, 0, 0, 0).y;
    fVerifyListener.forward(true);
    fTextWidget.addVerifyListener(fVerifyListener);
    fTextWidget.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent event) {
            selectionChanged(event.x, event.y - event.x);
        }

        @Override
        public void widgetSelected(SelectionEvent event) {
            selectionChanged(event.x, event.y - event.x);
        }
    });
    fCursorListener = new CursorListener();
    fCursorListener.install();
    initializeViewportUpdate();
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) VerifyKeyListener(org.eclipse.swt.custom.VerifyKeyListener) DisposeListener(org.eclipse.swt.events.DisposeListener) LineBackgroundListener(org.eclipse.swt.custom.LineBackgroundListener) VerifyListener(org.eclipse.swt.events.VerifyListener) TraverseListener(org.eclipse.swt.events.TraverseListener) MouseListener(org.eclipse.swt.events.MouseListener) SelectionListener(org.eclipse.swt.events.SelectionListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) ControlListener(org.eclipse.swt.events.ControlListener) Listener(org.eclipse.swt.widgets.Listener) MovementListener(org.eclipse.swt.custom.MovementListener) KeyListener(org.eclipse.swt.events.KeyListener) TraverseEvent(org.eclipse.swt.events.TraverseEvent) TraverseListener(org.eclipse.swt.events.TraverseListener) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DisposeEvent(org.eclipse.swt.events.DisposeEvent) MovementEvent(org.eclipse.swt.custom.MovementEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) TraverseEvent(org.eclipse.swt.events.TraverseEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) LineBackgroundEvent(org.eclipse.swt.custom.LineBackgroundEvent) Event(org.eclipse.swt.widgets.Event) ControlEvent(org.eclipse.swt.events.ControlEvent) VerifyEvent(org.eclipse.swt.events.VerifyEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DisposeEvent(org.eclipse.swt.events.DisposeEvent) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 83 with Listener

use of org.eclipse.swt.widgets.Listener in project eclipse.platform.text by eclipse.

the class ComboContentAssistSubjectAdapter method addSelectionListener.

@Override
public boolean addSelectionListener(final SelectionListener selectionListener) {
    fCombo.addSelectionListener(selectionListener);
    Listener listener = new Listener() {

        /*
			 * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
			 */
        @Override
        public void handleEvent(Event e) {
            selectionListener.widgetSelected(new SelectionEvent(e));
        }
    };
    fCombo.addListener(SWT.Modify, listener);
    fModifyListeners.put(selectionListener, listener);
    return true;
}
Also used : ModifyListener(org.eclipse.swt.events.ModifyListener) Listener(org.eclipse.swt.widgets.Listener) SelectionListener(org.eclipse.swt.events.SelectionListener) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Example 84 with Listener

use of org.eclipse.swt.widgets.Listener in project eclipse.platform.text by eclipse.

the class TextContentAssistSubjectAdapter method addSelectionListener.

@Override
public boolean addSelectionListener(final SelectionListener selectionListener) {
    fText.addSelectionListener(selectionListener);
    Listener listener = new Listener() {

        @Override
        public void handleEvent(Event e) {
            selectionListener.widgetSelected(new SelectionEvent(e));
        }
    };
    fText.addListener(SWT.Modify, listener);
    fModifyListeners.put(selectionListener, listener);
    return true;
}
Also used : ModifyListener(org.eclipse.swt.events.ModifyListener) Listener(org.eclipse.swt.widgets.Listener) SelectionListener(org.eclipse.swt.events.SelectionListener) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Example 85 with Listener

use of org.eclipse.swt.widgets.Listener in project linuxtools by eclipse.

the class OSIORestTaskEditorAttributePart method createContent.

@Override
protected Control createContent(FormToolkit toolkit, Composite parent) {
    attributesComposite = toolkit.createComposite(parent);
    attributesComposite.addListener(SWT.MouseDown, new Listener() {

        public void handleEvent(Event event) {
            Control focus = event.display.getFocusControl();
            if (focus instanceof Text && ((Text) focus).getEditable() == false) {
                getManagedForm().getForm().setFocus();
            }
        }
    });
    GridLayout attributesLayout = EditorUtil.createSectionClientLayout();
    attributesLayout.numColumns = 4;
    attributesLayout.horizontalSpacing = 9;
    attributesLayout.verticalSpacing = 6;
    attributesComposite.setLayout(attributesLayout);
    GridData attributesData = new GridData(GridData.FILL_BOTH);
    attributesData.horizontalSpan = 1;
    attributesData.grabExcessHorizontalSpace = true;
    attributesData.grabExcessVerticalSpace = false;
    attributesComposite.setLayoutData(attributesData);
    createAttributeControls(attributesComposite, toolkit, attributesLayout.numColumns);
    toolkit.paintBordersFor(attributesComposite);
    return attributesComposite;
}
Also used : Control(org.eclipse.swt.widgets.Control) GridLayout(org.eclipse.swt.layout.GridLayout) Listener(org.eclipse.swt.widgets.Listener) GridData(org.eclipse.swt.layout.GridData) Event(org.eclipse.swt.widgets.Event) Text(org.eclipse.swt.widgets.Text)

Aggregations

Listener (org.eclipse.swt.widgets.Listener)214 Event (org.eclipse.swt.widgets.Event)199 SelectionEvent (org.eclipse.swt.events.SelectionEvent)101 GridData (org.eclipse.swt.layout.GridData)95 Composite (org.eclipse.swt.widgets.Composite)82 GridLayout (org.eclipse.swt.layout.GridLayout)78 Point (org.eclipse.swt.graphics.Point)60 SelectionListener (org.eclipse.swt.events.SelectionListener)58 Button (org.eclipse.swt.widgets.Button)58 Label (org.eclipse.swt.widgets.Label)53 Text (org.eclipse.swt.widgets.Text)49 Table (org.eclipse.swt.widgets.Table)46 DisposeListener (org.eclipse.swt.events.DisposeListener)37 DisposeEvent (org.eclipse.swt.events.DisposeEvent)36 Rectangle (org.eclipse.swt.graphics.Rectangle)35 FocusEvent (org.eclipse.swt.events.FocusEvent)34 TableColumn (org.eclipse.swt.widgets.TableColumn)34 Shell (org.eclipse.swt.widgets.Shell)31 KeyEvent (org.eclipse.swt.events.KeyEvent)30 Group (org.eclipse.swt.widgets.Group)30