Search in sources :

Example 11 with CheckStateChangedEvent

use of org.eclipse.jface.viewers.CheckStateChangedEvent in project hale by halestudio.

the class EditMappableTypesPage method createControl.

/**
 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
 */
@Override
public void createControl(Composite parent) {
    parent.setLayout(new GridLayout());
    // create filtered tree
    PatternFilter patternFilter = new PatternFilter();
    patternFilter.setIncludeLeadingWildcard(true);
    FilteredTree tree = new FilteredTree(parent, SWT.BORDER | SWT.CHECK | SWT.H_SCROLL | SWT.V_SCROLL, patternFilter, true) {

        @Override
        protected TreeViewer doCreateTreeViewer(Composite parent, int style) {
            return new CheckboxTreeViewer(parent, style);
        }
    };
    // configure viewer
    viewer = (CheckboxTreeViewer) tree.getViewer();
    contentProvider = new NSTypeTreeContentProvider();
    viewer.setContentProvider(contentProvider);
    viewer.setComparator(new DefinitionComparator());
    viewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            Object doubleClicked = selection.getFirstElement();
            if (doubleClicked instanceof String)
                viewer.setExpandedState(doubleClicked, !viewer.getExpandedState(doubleClicked));
            else {
                boolean newState = !checkStateProvider.isChecked(doubleClicked);
                viewer.setChecked(doubleClicked, newState);
                checkStateOfTypeChanged((TypeDefinition) doubleClicked, newState);
            }
        }
    });
    viewer.setLabelProvider(definitionLabels);
    // because elements filtered by FilteredTree lose their checked state:
    checkStateProvider = new ICheckStateProvider() {

        @Override
        public boolean isGrayed(Object element) {
            if (element instanceof String) {
                Object[] children = contentProvider.getChildren(element);
                boolean containsChecked = false;
                boolean containsUnchecked = false;
                for (Object child : children) {
                    if (isChecked(child))
                        containsChecked = true;
                    else
                        containsUnchecked = true;
                    if (containsChecked && containsUnchecked)
                        return true;
                }
            }
            return false;
        }

        @Override
        public boolean isChecked(Object element) {
            if (element instanceof String) {
                for (Object child : contentProvider.getChildren(element)) if (isChecked(child))
                    return true;
                return false;
            }
            return ((TypeDefinition) element).getConstraint(MappingRelevantFlag.class).isEnabled() != changedTypes.contains(element);
        }
    };
    viewer.setCheckStateProvider(checkStateProvider);
    viewer.addCheckStateListener(new ICheckStateListener() {

        @Override
        public void checkStateChanged(CheckStateChangedEvent event) {
            if (event.getElement() instanceof String) {
                // update children
                viewer.setGrayed(event.getElement(), false);
                for (Object child : contentProvider.getChildren(event.getElement())) {
                    // if (mappedTypeFilter.select(viewer, event.getElement(), child)) {
                    if (checkStateProvider.isChecked(child) != event.getChecked()) {
                        viewer.setChecked(child, event.getChecked());
                        checkStateOfTypeChanged((TypeDefinition) child, event.getChecked());
                    }
                // }
                }
                viewer.setGrayed(event.getElement(), checkStateProvider.isGrayed(event.getElement()));
            // only two levels, no need to update any parents or
            // children's children
            } else {
                // if (mappedTypeFilter.select(viewer, null, event.getElement()))
                checkStateOfTypeChanged((TypeDefinition) event.getElement(), event.getChecked());
            // else if (!event.getChecked())
            // viewer.setChecked(event.getElement(), true);
            }
        }
    });
    // // filter types which are used in the current alignment
    // viewer.addFilter(mappedTypeFilter);
    // set input to all types in the given index
    viewer.setInput(typeIndex.getTypes());
    // expand all except XMLSchema
    viewer.expandAll();
    viewer.setExpandedState("http://www.w3.org/2001/XMLSchema", false);
    // set control
    setControl(viewer.getControl());
}
Also used : PatternFilter(org.eclipse.ui.dialogs.PatternFilter) Composite(org.eclipse.swt.widgets.Composite) ICheckStateProvider(org.eclipse.jface.viewers.ICheckStateProvider) DefinitionComparator(eu.esdihumboldt.hale.ui.common.definition.viewer.DefinitionComparator) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) FilteredTree(org.eclipse.ui.dialogs.FilteredTree) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) GridLayout(org.eclipse.swt.layout.GridLayout) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) NSTypeTreeContentProvider(eu.esdihumboldt.hale.ui.service.schema.util.NSTypeTreeContentProvider) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) MappingRelevantFlag(eu.esdihumboldt.hale.common.schema.model.constraint.type.MappingRelevantFlag)

Example 12 with CheckStateChangedEvent

use of org.eclipse.jface.viewers.CheckStateChangedEvent in project eclipse.platform.text by eclipse.

the class MatchFilterSelectionDialog method createMatchFilterControls.

private void createMatchFilterControls(Composite parent) {
    // Create list viewer
    Label l = new Label(parent, SWT.NONE);
    l.setFont(parent.getFont());
    l.setText(SearchMessages.MatchFilterSelectionDialog_filter_description);
    Table table = new Table(parent, SWT.CHECK | SWT.BORDER);
    table.setFont(parent.getFont());
    fListViewer = new CheckboxTableViewer(table);
    GridData data = new GridData(GridData.FILL_BOTH);
    data.minimumHeight = convertHeightInCharsToPixels(8);
    table.setLayoutData(data);
    class ListenerAndLabelProvider extends LabelProvider implements ISelectionChangedListener, ICheckStateListener {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            performFilterListSelectionChanged();
        }

        @Override
        public void checkStateChanged(CheckStateChangedEvent event) {
            performFilterListCheckStateChanged();
        }

        @Override
        public String getText(Object element) {
            return ((MatchFilter) element).getName();
        }
    }
    ListenerAndLabelProvider listenerAndLP = new ListenerAndLabelProvider();
    fListViewer.setLabelProvider(listenerAndLP);
    fListViewer.setContentProvider(new ArrayContentProvider());
    fListViewer.addSelectionChangedListener(listenerAndLP);
    fListViewer.addCheckStateListener(listenerAndLP);
    fListViewer.setInput(fAllFilters);
    fListViewer.setCheckedElements(fEnabledFilters);
    l = new Label(parent, SWT.NONE);
    l.setFont(parent.getFont());
    l.setText(SearchMessages.MatchFilterSelectionDialog_description_label);
    fDescription = new Text(parent, SWT.LEFT | SWT.WRAP | SWT.MULTI | SWT.READ_ONLY | SWT.BORDER | SWT.V_SCROLL);
    fDescription.setFont(parent.getFont());
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.heightHint = convertHeightInCharsToPixels(3);
    fDescription.setLayoutData(data);
}
Also used : Table(org.eclipse.swt.widgets.Table) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Text(org.eclipse.swt.widgets.Text) MatchFilter(org.eclipse.search.ui.text.MatchFilter) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 13 with CheckStateChangedEvent

use of org.eclipse.jface.viewers.CheckStateChangedEvent 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 14 with CheckStateChangedEvent

use of org.eclipse.jface.viewers.CheckStateChangedEvent in project eclipse.platform.text by eclipse.

the class SelectResourcesDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    Composite composite = (Composite) super.createDialogArea(parent);
    Label label = new Label(composite, SWT.LEFT);
    label.setText(fInstruction);
    label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    fResourceGroup = new SelectResourcesBlock(composite, ResourcesPlugin.getWorkspace().getRoot(), getResourceProvider(IResource.FOLDER | IResource.PROJECT), WorkbenchLabelProvider.getDecoratingWorkbenchLabelProvider(), getResourceProvider(IResource.FILE), WorkbenchLabelProvider.getDecoratingWorkbenchLabelProvider(), SWT.NONE, useHeightHint(parent));
    fResourceGroup.addCheckStateListener(new ICheckStateListener() {

        @Override
        public void checkStateChanged(CheckStateChangedEvent event) {
            updateSelectionCount();
        }
    });
    fCountIndication = new Label(composite, SWT.LEFT);
    fCountIndication.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    createSelectionButtonGroup(composite);
    setInitialSelection();
    return composite;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) Label(org.eclipse.swt.widgets.Label) GridData(org.eclipse.swt.layout.GridData) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent)

Example 15 with CheckStateChangedEvent

use of org.eclipse.jface.viewers.CheckStateChangedEvent in project erlide_eclipse by erlang.

the class ErlangWizardResourceImportPage method createFileSelectionGroup.

/**
 * Create the import source selection widget
 */
protected void createFileSelectionGroup(final Composite parent) {
    // Just create with a dummy root.
    selectionGroup = new ResourceTreeAndListGroup(parent, // $NON-NLS-1$
    new FileSystemElement("Dummy", null, true), getFolderProvider(), new WorkbenchLabelProvider(), getFileProvider(), new WorkbenchLabelProvider(), SWT.NONE, DialogUtil.inRegularFontMode(parent));
    final ICheckStateListener listener = new ICheckStateListener() {

        @Override
        public void checkStateChanged(final CheckStateChangedEvent event) {
            updateWidgetEnablements();
        }
    };
    final WorkbenchViewerComparator comparator = new WorkbenchViewerComparator();
    selectionGroup.setTreeComparator(comparator);
    selectionGroup.setListComparator(comparator);
    selectionGroup.addCheckStateListener(listener);
}
Also used : WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) FileSystemElement(org.eclipse.ui.dialogs.FileSystemElement) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) WorkbenchViewerComparator(org.eclipse.ui.model.WorkbenchViewerComparator) ResourceTreeAndListGroup(org.erlide.ui.util.ResourceTreeAndListGroup)

Aggregations

CheckStateChangedEvent (org.eclipse.jface.viewers.CheckStateChangedEvent)99 ICheckStateListener (org.eclipse.jface.viewers.ICheckStateListener)96 GridData (org.eclipse.swt.layout.GridData)62 Composite (org.eclipse.swt.widgets.Composite)47 GridLayout (org.eclipse.swt.layout.GridLayout)43 SelectionEvent (org.eclipse.swt.events.SelectionEvent)39 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)33 Label (org.eclipse.swt.widgets.Label)33 CheckboxTreeViewer (org.eclipse.jface.viewers.CheckboxTreeViewer)32 Button (org.eclipse.swt.widgets.Button)29 CheckboxTableViewer (org.eclipse.jface.viewers.CheckboxTableViewer)22 Viewer (org.eclipse.jface.viewers.Viewer)22 Table (org.eclipse.swt.widgets.Table)21 ArrayList (java.util.ArrayList)18 TableColumn (org.eclipse.swt.widgets.TableColumn)17 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)16 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)16 Event (org.eclipse.swt.widgets.Event)16 Listener (org.eclipse.swt.widgets.Listener)15 List (java.util.List)13