Search in sources :

Example 86 with ISelectionChangedListener

use of org.eclipse.jface.viewers.ISelectionChangedListener in project archi by archimatetool.

the class ExportJasperReportsWizardPage2 method createControl.

@Override
public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NULL);
    container.setLayout(new GridLayout());
    setControl(container);
    PlatformUI.getWorkbench().getHelpSystem().setHelp(container, HELP_ID);
    Composite fieldContainer = new Composite(container, SWT.NULL);
    fieldContainer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    fieldContainer.setLayout(new GridLayout(2, false));
    // Template Combo
    Label label = new Label(fieldContainer, SWT.NONE);
    label.setText(Messages.ExportJasperReportsWizardPage2_4);
    fComboTemplateViewer = new ComboViewer(new Combo(fieldContainer, SWT.READ_ONLY | SWT.BORDER));
    fComboTemplateViewer.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    fComboTemplateViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            Template template = (Template) ((IStructuredSelection) event.getSelection()).getFirstElement();
            if (template.location == null) {
                // Custom...
                handleCustomDialog();
            } else {
                fLastSelectedTemplate = template;
            }
        }
    });
    fComboTemplateViewer.setContentProvider(new IStructuredContentProvider() {

        @Override
        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }

        @Override
        public void dispose() {
        }

        @Override
        public Object[] getElements(Object inputElement) {
            return fTemplates.toArray();
        }
    });
    fComboTemplateViewer.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            return ((Template) element).name;
        }
    });
    // $NON-NLS-1$
    fComboTemplateViewer.setInput("");
    fComboTemplateViewer.setSelection(new StructuredSelection(fTemplates.get(0)));
    // Locale Combo
    label = new Label(fieldContainer, SWT.NONE);
    label.setText(Messages.ExportJasperReportsWizardPage2_6);
    fComboLocale = new ComboViewer(new Combo(fieldContainer, SWT.READ_ONLY | SWT.BORDER));
    fComboLocale.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    fComboLocale.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            Locale locale = (Locale) ((IStructuredSelection) event.getSelection()).getFirstElement();
            fSelectedLocale = locale;
        }
    });
    fComboLocale.setContentProvider(new IStructuredContentProvider() {

        @Override
        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }

        @Override
        public void dispose() {
        }

        @Override
        public Object[] getElements(Object inputElement) {
            Locale[] locales = Locale.getAvailableLocales();
            Comparator<Locale> localeComparator = new Comparator<Locale>() {

                public int compare(Locale locale1, Locale locale2) {
                    return locale1.toString().compareTo(locale2.toString());
                }
            };
            Arrays.sort(locales, localeComparator);
            return locales;
        }
    });
    fComboLocale.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            return ((Locale) element).toLanguageTag();
        }
    });
    // $NON-NLS-1$
    fComboLocale.setInput("");
    fComboLocale.setSelection(new StructuredSelection(fSelectedLocale));
}
Also used : Locale(java.util.Locale) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Combo(org.eclipse.swt.widgets.Combo) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Viewer(org.eclipse.jface.viewers.Viewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Comparator(java.util.Comparator) GridLayout(org.eclipse.swt.layout.GridLayout) ComboViewer(org.eclipse.jface.viewers.ComboViewer) GridData(org.eclipse.swt.layout.GridData) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 87 with ISelectionChangedListener

use of org.eclipse.jface.viewers.ISelectionChangedListener in project xtext-eclipse by eclipse.

the class ProjectSelectionDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    Composite composite = (Composite) super.createDialogArea(parent);
    Font font = parent.getFont();
    composite.setFont(font);
    createMessageArea(composite);
    tableViewer = new TableViewer(composite, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            doSelectionChanged(((IStructuredSelection) event.getSelection()).toArray());
        }
    });
    tableViewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            okPressed();
        }
    });
    GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
    data.heightHint = SIZING_SELECTION_WIDGET_HEIGHT;
    data.widthHint = SIZING_SELECTION_WIDGET_WIDTH;
    tableViewer.getTable().setLayoutData(data);
    tableViewer.setContentProvider(new WorkbenchContentProvider());
    tableViewer.setLabelProvider(new WorkbenchLabelProvider());
    tableViewer.setComparator(new ResourceComparator(ResourceComparator.NAME));
    tableViewer.getControl().setFont(font);
    Button checkbox = new Button(composite, SWT.CHECK);
    checkbox.setText(Messages.ProjectSelectionDialog_filter);
    checkbox.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, true, false));
    checkbox.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            updateFilter(((Button) e.widget).getSelection());
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            updateFilter(((Button) e.widget).getSelection());
        }
    });
    boolean doFilter = !dialogSettings.getBoolean(DIALOG_SETTINGS_SHOW_ALL) && !projectsWithSpecifics.isEmpty();
    checkbox.setSelection(doFilter);
    updateFilter(doFilter);
    tableViewer.setInput(ResourcesPlugin.getWorkspace());
    doSelectionChanged(new Object[0]);
    Dialog.applyDialogFont(composite);
    return composite;
}
Also used : ResourceComparator(org.eclipse.ui.views.navigator.ResourceComparator) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) Font(org.eclipse.swt.graphics.Font) Button(org.eclipse.swt.widgets.Button) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableViewer(org.eclipse.jface.viewers.TableViewer) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 88 with ISelectionChangedListener

use of org.eclipse.jface.viewers.ISelectionChangedListener in project archi by archimatetool.

the class TemplateManagerDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    // Help
    PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, getHelpID());
    setTitle(Messages.TemplateManagerDialog_2);
    setMessage(Messages.TemplateManagerDialog_3);
    Composite composite = (Composite) super.createDialogArea(parent);
    Composite client = new Composite(composite, SWT.NULL);
    GridLayout layout = new GridLayout(2, false);
    client.setLayout(layout);
    client.setLayoutData(new GridData(GridData.FILL_BOTH));
    SashForm sash = new SashForm(client, SWT.HORIZONTAL);
    sash.setLayoutData(new GridData(GridData.FILL_BOTH));
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.widthHint = 580;
    gd.heightHint = 300;
    sash.setLayoutData(gd);
    // Templates Table
    Composite tableComp = new Composite(sash, SWT.BORDER);
    layout = new GridLayout();
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    tableComp.setLayout(layout);
    CLabel label = new CLabel(tableComp, SWT.NULL);
    label.setText(Messages.TemplateManagerDialog_4);
    Composite tableComp2 = new Composite(tableComp, SWT.NULL);
    tableComp2.setLayout(new TableColumnLayout());
    tableComp2.setLayoutData(new GridData(GridData.FILL_BOTH));
    fTableViewer = new TemplatesTableViewer(tableComp2, SWT.MULTI);
    fTableViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
    fTableViewer.setInput(fTemplateManager.getUserTemplates());
    fTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            Object o = ((IStructuredSelection) event.getSelection()).getFirstElement();
            fSelectedControl = fTableViewer;
            updateControls(o);
        }
    });
    // Groups Tree
    Composite treeComp = new Composite(sash, SWT.BORDER);
    layout = new GridLayout();
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    treeComp.setLayout(layout);
    label = new CLabel(treeComp, SWT.NULL);
    label.setText(Messages.TemplateManagerDialog_5);
    // label.setImage(IArchiImages.ImageFactory.getImage(ImageFactory.ECLIPSE_IMAGE_FOLDER));
    fTreeViewer = new TemplatesTreeViewer(treeComp, SWT.MULTI);
    fTreeViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
    fTreeViewer.setInput(fTemplateManager.getUserTemplateGroups());
    fTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            Object o = ((IStructuredSelection) event.getSelection()).getFirstElement();
            fSelectedControl = fTreeViewer;
            updateControls(o);
        }
    });
    new TemplateManagerDialogDragDropHandler(fTableViewer, fTreeViewer);
    // Buttons
    Composite buttonBar = new Composite(client, SWT.NULL);
    layout = new GridLayout();
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    buttonBar.setLayout(layout);
    buttonBar.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
    fButtonAddTemplate = new Button(buttonBar, SWT.NULL);
    fButtonAddTemplate.setText(Messages.TemplateManagerDialog_6);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    fButtonAddTemplate.setLayoutData(gd);
    fButtonAddTemplate.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            openTemplate();
        }
    });
    fButtonNewGroup = new Button(buttonBar, SWT.NULL);
    fButtonNewGroup.setText(Messages.TemplateManagerDialog_7);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    fButtonNewGroup.setLayoutData(gd);
    fButtonNewGroup.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            newGroup();
        }
    });
    fButtonRemove = new Button(buttonBar, SWT.NULL);
    fButtonRemove.setText(Messages.TemplateManagerDialog_8);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    fButtonRemove.setLayoutData(gd);
    fButtonRemove.setEnabled(false);
    fButtonRemove.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            deleteSelectedObjects();
        }
    });
    sash.setWeights(new int[] { 30, 70 });
    Composite fieldContainer = new Composite(composite, SWT.NULL);
    layout = new GridLayout(2, false);
    fieldContainer.setLayout(layout);
    fieldContainer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    fNameLabel = new Label(fieldContainer, SWT.NULL);
    fNameLabel.setText(Messages.TemplateManagerDialog_9);
    fNameLabel.setEnabled(false);
    fNameTextField = new Text(fieldContainer, SWT.BORDER | SWT.SINGLE);
    fNameTextField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    fNameTextField.setEnabled(false);
    // Single text control so strip CRLFs
    UIUtils.conformSingleTextControl(fNameTextField);
    fNameTextField.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            String text = fNameTextField.getText();
            if (fIsSettingFields || !StringUtils.isSet(text)) {
                return;
            }
            // Edit Template name
            if (fSelectedTemplate != null) {
                fSelectedTemplate.setName(text);
                if (!fModifiedTemplates.contains(fSelectedTemplate)) {
                    fModifiedTemplates.add(fSelectedTemplate);
                }
                fTableViewer.refresh();
                fTreeViewer.refresh();
            } else // Edit Group name
            if (fSelectedTemplateGroup != null) {
                fSelectedTemplateGroup.setName(text);
                fTreeViewer.refresh();
            }
        }
    });
    fDescriptionLabel = new Label(fieldContainer, SWT.NULL);
    fDescriptionLabel.setText(Messages.TemplateManagerDialog_10);
    fDescriptionLabel.setEnabled(false);
    fDescriptionTextField = new Text(fieldContainer, SWT.BORDER | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
    fDescriptionTextField.setEnabled(false);
    gd = new GridData(GridData.FILL_BOTH);
    gd.heightHint = 100;
    fDescriptionTextField.setLayoutData(gd);
    fDescriptionTextField.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            String text = fDescriptionTextField.getText();
            if (fIsSettingFields || !StringUtils.isSet(text)) {
                return;
            }
            if (fSelectedTemplate != null) {
                fSelectedTemplate.setDescription(fDescriptionTextField.getText());
                if (!fModifiedTemplates.contains(fSelectedTemplate)) {
                    fModifiedTemplates.add(fSelectedTemplate);
                }
            }
        }
    });
    fFileLabel = new Label(fieldContainer, SWT.NULL);
    fFileLabel.setText(Messages.TemplateManagerDialog_11);
    fFileLabel.setEnabled(false);
    fFileTextField = new Text(fieldContainer, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY);
    fFileTextField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    fFileTextField.setEnabled(false);
    return composite;
}
Also used : CLabel(org.eclipse.swt.custom.CLabel) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) CLabel(org.eclipse.swt.custom.CLabel) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Text(org.eclipse.swt.widgets.Text) SashForm(org.eclipse.swt.custom.SashForm) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Example 89 with ISelectionChangedListener

use of org.eclipse.jface.viewers.ISelectionChangedListener in project xtext-eclipse by eclipse.

the class XtextEditor method installSelectionChangedListener.

private void installSelectionChangedListener() {
    selectionChangedListener = new ISelectionChangedListener() {

        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            updateStatusLine();
        }
    };
    final ISelectionProvider selectionProvider = getSelectionProvider();
    if (selectionProvider instanceof IPostSelectionProvider) {
        final IPostSelectionProvider postSelectionProvider = (IPostSelectionProvider) selectionProvider;
        postSelectionProvider.addPostSelectionChangedListener(selectionChangedListener);
    } else {
        getSelectionProvider().addSelectionChangedListener(selectionChangedListener);
    }
}
Also used : IPostSelectionProvider(org.eclipse.jface.viewers.IPostSelectionProvider) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent)

Example 90 with ISelectionChangedListener

use of org.eclipse.jface.viewers.ISelectionChangedListener in project archi by archimatetool.

the class UserPropertiesManagerDialog method createTableControl.

private void createTableControl(Composite parent) {
    Composite tableComp = new Composite(parent, SWT.BORDER);
    TableColumnLayout tableLayout = new TableColumnLayout();
    tableComp.setLayout(tableLayout);
    tableComp.setLayoutData(new GridData(GridData.FILL_BOTH));
    fTableViewer = new TableViewer(tableComp, SWT.MULTI | SWT.FULL_SELECTION);
    fTableViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
    fTableViewer.getTable().setHeaderVisible(true);
    fTableViewer.getTable().setLinesVisible(true);
    fTableViewer.setComparator(new ViewerComparator());
    // Columns
    TableViewerColumn columnOldKey = new TableViewerColumn(fTableViewer, SWT.NONE, 0);
    columnOldKey.getColumn().setText(Messages.UserPropertiesManagerDialog_6);
    tableLayout.setColumnData(columnOldKey.getColumn(), new ColumnWeightData(40, true));
    TableViewerColumn columnNewKey = new TableViewerColumn(fTableViewer, SWT.NONE, 1);
    columnNewKey.getColumn().setText(Messages.UserPropertiesManagerDialog_7);
    tableLayout.setColumnData(columnNewKey.getColumn(), new ColumnWeightData(40, true));
    columnNewKey.setEditingSupport(new KeyEditingSupport(fTableViewer));
    TableViewerColumn columnUsedNumber = new TableViewerColumn(fTableViewer, SWT.NONE, 2);
    // $NON-NLS-1$
    columnUsedNumber.getColumn().setText("# " + Messages.UserPropertiesManagerDialog_8);
    tableLayout.setColumnData(columnUsedNumber.getColumn(), new ColumnWeightData(20, true));
    // Content Provider
    fTableViewer.setContentProvider(new IStructuredContentProvider() {

        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }

        public void dispose() {
        }

        public Object[] getElements(Object inputElement) {
            return fKeysTable.entrySet().toArray();
        }
    });
    // Label Provider
    fTableViewer.setLabelProvider(new LabelCellProvider());
    fTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            fActionDelete.setEnabled(!event.getSelection().isEmpty());
            fButtonDelete.setEnabled(!event.getSelection().isEmpty());
            fActionRename.setEnabled(!event.getSelection().isEmpty());
            fButtonRename.setEnabled(!event.getSelection().isEmpty());
        }
    });
    // anything will do //$NON-NLS-1$
    fTableViewer.setInput("");
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) Composite(org.eclipse.swt.widgets.Composite) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) TableViewer(org.eclipse.jface.viewers.TableViewer) ColumnViewer(org.eclipse.jface.viewers.ColumnViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) GridData(org.eclipse.swt.layout.GridData) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) EObject(org.eclipse.emf.ecore.EObject) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Aggregations

ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)774 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)755 GridData (org.eclipse.swt.layout.GridData)419 Composite (org.eclipse.swt.widgets.Composite)333 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)302 GridLayout (org.eclipse.swt.layout.GridLayout)247 SelectionEvent (org.eclipse.swt.events.SelectionEvent)187 Label (org.eclipse.swt.widgets.Label)157 TableViewer (org.eclipse.jface.viewers.TableViewer)151 AdapterFactoryLabelProvider (org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider)147 Button (org.eclipse.swt.widgets.Button)141 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)139 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)131 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)121 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)120 IPropertiesEditionEvent (org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)116 PropertiesEditionEvent (org.eclipse.emf.eef.runtime.impl.notify.PropertiesEditionEvent)116 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)116 Table (org.eclipse.swt.widgets.Table)93 ISelection (org.eclipse.jface.viewers.ISelection)87