Example usage for org.eclipse.jface.viewers CheckboxTableViewer newCheckList

List of usage examples for org.eclipse.jface.viewers CheckboxTableViewer newCheckList

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers CheckboxTableViewer newCheckList.

Prototype

public static CheckboxTableViewer newCheckList(Composite parent, int style) 

Source Link

Document

Creates a table viewer on a newly-created table control under the given parent.

Usage

From source file:org.eclipse.vtp.desktop.export.internal.pages.ProjectSelectionPage.java

License:Open Source License

public void createControl(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(2, false));
    viewer = CheckboxTableViewer.newCheckList(composite, SWT.BORDER);
    viewer.addCheckStateListener(this);
    viewer.setContentProvider(this);
    viewer.setSorter(new ViewerSorter());
    viewer.setInput(projects);/*  ww w .  j  av  a  2 s  .co  m*/
    viewer.setCheckedElements(initialSelection.toArray());
    viewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 3));
    selectAll = new Button(composite, SWT.PUSH);
    selectAll.setText("Select All");
    selectAll.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
    selectAll.addSelectionListener(this);
    deselectAll = new Button(composite, SWT.PUSH);
    deselectAll.setText("Deselect All");
    deselectAll.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
    deselectAll.addSelectionListener(this);
    Label extra = new Label(composite, SWT.NONE);
    extra.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true));
    setControl(composite);
    projectSelectionChanged(false);
}

From source file:org.eclipse.wb.internal.core.databinding.ui.editor.contentproviders.ChooseClassAndPropertiesUiContentProvider.java

License:Open Source License

protected ICheckboxViewerWrapper createPropertiesViewer(Composite parent) {
    CheckboxTableViewer tableViewer = CheckboxTableViewer.newCheckList(parent,
            SWT.BORDER | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL);
    tableViewer.setContentProvider(new ArrayContentProvider());
    tableViewer.setLabelProvider(m_configuration.getPropertiesLabelProvider());
    return new CheckboxTableViewerWrapper(tableViewer);
}

From source file:org.eclipse.wb.internal.core.databinding.wizards.autobindings.DefaultAutomaticDatabindingProvider.java

License:Open Source License

public void fillWidgetComposite(Composite widgetComposite) {
    // configure widget composite
    m_widgetComposite = widgetComposite;
    GridLayoutFactory.create(widgetComposite).columns(m_strategyContainer == null ? 1 : 2).noMargins();
    // editor title
    m_editorLabel = new Label(widgetComposite, SWT.NONE);
    m_editorLabel.setText(Messages.DefaultAutomaticDatabindingProvider_editorLabel);
    // strategy title
    if (m_strategyContainer != null) {
        m_strategyLabel = new Label(widgetComposite, SWT.NONE);
        m_strategyLabel.setText(Messages.DefaultAutomaticDatabindingProvider_strategyLabel);
    }/* w w w.j a va2 s .  c  om*/
    // editor viewer
    m_editorsViewer = CheckboxTableViewer.newCheckList(widgetComposite,
            SWT.BORDER | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL);
    // create columns
    GridDataFactory.create(m_editorsViewer.getControl()).hintVC(20).fill().grabH();
    TableFactory.modify(m_editorsViewer).standard().newColumn().width(170)
            .text(Messages.DefaultAutomaticDatabindingProvider_widgetColumn);
    TableFactory.modify(m_editorsViewer).standard().newColumn().width(150)
            .text(Messages.DefaultAutomaticDatabindingProvider_propertyColumn);
    // configure viewer
    m_editorsViewer.setContentProvider(new ArrayContentProvider());
    m_editorsViewer.setLabelProvider(new DescriptorTableLabelProvider());
    m_editorsViewer.setInput(m_widgetContainer.getDescriptors());
    new SingleCheckSelectionListener(m_editorsViewer, 0);
    // strategy viewer
    if (m_strategyContainer != null) {
        m_strategiesViewer = CheckboxTableViewer.newCheckList(widgetComposite,
                SWT.BORDER | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL);
        GridDataFactory.create(m_strategiesViewer.getControl()).fill().grab();
        m_strategiesViewer.setContentProvider(new ArrayContentProvider());
        m_strategiesViewer.setLabelProvider(new DescriptorLabelProvider());
        m_strategiesViewer.setInput(m_strategyContainer.getDescriptors());
        new SingleCheckSelectionListener(m_strategiesViewer, 1);
    }
    //
    setWidgetCompositeEnabled(false);
}

From source file:org.eclipse.wb.internal.core.editor.palette.dialogs.ImportArchiveDialog.java

License:Open Source License

@Override
protected void createControls(Composite container) {
    GridLayoutFactory.create(container).columns(3);
    // title//w w w  .  j  a v  a 2 s. c o  m
    new Label(container, SWT.NONE).setText(Messages.ImportArchiveDialog_archiveLabel);
    // jar combo
    m_fileArchiveCombo = new Combo(container, SWT.READ_ONLY);
    GridDataFactory.create(m_fileArchiveCombo).fillH().grabH();
    UiUtils.setVisibleItemCount(m_fileArchiveCombo, JAR_COMBO_SIZE);
    // load history
    IDialogSettings settings = getDialogSettings();
    String[] jarHistory = settings.getArray(JAR_LIST_ID);
    if (jarHistory != null) {
        m_fileArchiveCombo.setItems(jarHistory);
    }
    //
    m_fileArchiveCombo.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            chooseFromText(m_fileArchiveCombo.getText());
        }
    });
    // choose buttons
    ToolBar browseToolBar = new ToolBar(container, SWT.FLAT | SWT.RIGHT);
    // choose menu
    m_browseItem = new ToolItem(browseToolBar, SWT.DROP_DOWN);
    m_browseItem.setToolTipText(Messages.ImportArchiveDialog_browseToolTip);
    m_browseItem.setImage(DesignerPlugin.getImage("palette/category.gif"));
    //
    m_browseMenu = new Menu(browseToolBar);
    // Classpath
    MenuItem classpathItem = new MenuItem(m_browseMenu, SWT.NONE);
    classpathItem.setText(Messages.ImportArchiveDialog_classpathItem);
    classpathItem.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            chooseFromClasspath();
        }
    });
    // Workspace
    MenuItem workspaceItem = new MenuItem(m_browseMenu, SWT.NONE);
    workspaceItem.setText(Messages.ImportArchiveDialog_workspaceItem);
    workspaceItem.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            chooseFromWorkspace();
        }
    });
    // FileSystem
    MenuItem filesystemItem = new MenuItem(m_browseMenu, SWT.NONE);
    filesystemItem.setText(Messages.ImportArchiveDialog_fileSystemItem);
    filesystemItem.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            chooseFromFilesystem();
        }
    });
    //
    m_browseItem.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            // prepare menu bounds
            Rectangle bounds = m_browseItem.getBounds();
            Point location = m_browseItem.getParent().toDisplay(new Point(bounds.x, bounds.y + bounds.height));
            m_browseMenu.setLocation(location.x, location.y);
            // show context menu
            m_browseMenu.setVisible(true);
        }
    });
    // manifest button
    m_ignoreManifestButton = new Button(container, SWT.CHECK);
    GridDataFactory.create(m_ignoreManifestButton).spanH(3);
    m_ignoreManifestButton.setText(Messages.ImportArchiveDialog_ignoreManifestFlag);
    // classes viewer
    m_classesViewer = CheckboxTableViewer.newCheckList(container, SWT.BORDER | SWT.FULL_SELECTION);
    GridDataFactory.create(m_classesViewer.getControl()).fill().grab().spanH(3).hint(300, 150);
    TableFactory.modify(m_classesViewer).headerVisible(true).linesVisible(true);
    TableFactory.modify(m_classesViewer).newColumn().text(Messages.ImportArchiveDialog_classesColumn)
            .width(getInitialSize().x - 30);
    m_classesViewer.setContentProvider(new ArrayContentProvider());
    m_classesViewer.setLabelProvider(new LabelProvider());
    m_classesViewer.addCheckStateListener(new ICheckStateListener() {
        public void checkStateChanged(CheckStateChangedEvent event) {
            calculateFinish();
        }
    });
    // category title
    m_categoryLabel = new Label(container, SWT.NONE);
    m_categoryLabel.setText(Messages.ImportArchiveDialog_categoryLabel);
    // category combo
    m_categoryCombo = new Combo(container, SWT.READ_ONLY);
    GridDataFactory.create(m_categoryCombo).fillH().grabH().spanH(2);
    UiUtils.setVisibleItemCount(m_categoryCombo, 15);
    // load categories
    m_categoryCombo.add(Messages.ImportArchiveDialog_categoryNew);
    for (CategoryInfo category : m_palette.getCategories()) {
        m_categoryCombo.add(category.getName());
    }
    if (m_initialCategory == null) {
        m_categoryCombo.select(0);
    } else {
        m_categoryCombo.select(m_palette.getCategories().indexOf(m_initialCategory) + 1);
    }
    //
    m_categoryCombo.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            calculateFinish();
        }
    });
    //
    new Label(container, SWT.NONE);
    // category name text
    m_categoryText = new Text(container, SWT.BORDER);
    GridDataFactory.create(m_categoryText).fillH().grabH().spanH(2);
    m_categoryText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            calculateFinish();
        }
    });
}

From source file:org.eclipse.wb.internal.core.model.property.order.ReorderDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {
    // container/* ww  w.  jav  a 2s .  c  o  m*/
    Composite container = (Composite) super.createDialogArea(parent);
    GridLayoutFactory.create(container).columns(2);
    // title
    Label title = new Label(container, SWT.NONE);
    title.setText(ModelMessages.ReorderDialog_childrenLabel);
    GridDataFactory.create(title).spanH(2);
    // reorder viewer
    m_viewer = CheckboxTableViewer.newCheckList(container, SWT.FULL_SELECTION | SWT.BORDER);
    m_viewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent e) {
            do_viewer_selectionChanged();
        }
    });
    m_viewer.setContentProvider(new ArrayContentProvider());
    m_viewer.setLabelProvider(ObjectsLabelProvider.INSTANCE);
    //
    TableFactory.modify(m_viewer).headerVisible(true).linesVisible(true);
    GridDataFactory.create(m_viewer.getControl()).fill().grab().hintC(60, 15);
    TableFactory.modify(m_viewer).newColumn().width(convertWidthInCharsToPixels(60))
            .text(ModelMessages.ReorderDialog_childColumn);
    // show all components and select first
    m_viewer.setInput(m_allInfos);
    m_viewer.getTable().select(0);
    // check all components that are already in tab order, or all, if there is not components
    m_viewer.setCheckedElements(m_orderInfo.getOrderedInfos().toArray());
    setupDragAndDrop();
    // buttons bar
    Composite buttonsComposite = new Composite(container, SWT.NONE);
    GridLayoutFactory.create(buttonsComposite).noMargins();
    GridDataFactory.create(buttonsComposite).fill().hintHC(18);
    // up
    m_upButton = new Button(buttonsComposite, SWT.NONE);
    m_upButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            do_upButton_widgetSelected(e);
        }
    });
    m_upButton.setText(ModelMessages.ReorderDialog_upButton);
    GridDataFactory.create(m_upButton).fillH().grabH();
    // down
    m_downButton = new Button(buttonsComposite, SWT.NONE);
    m_downButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            do_downButton_widgetSelected(e);
        }
    });
    m_downButton.setText(ModelMessages.ReorderDialog_downButton);
    GridDataFactory.create(m_downButton).fillH().grabH();
    // filler
    GridDataFactory.create(new Label(buttonsComposite, SWT.NONE)).fillH().grabH();
    // select all
    m_selectAllButton = new Button(buttonsComposite, SWT.NONE);
    m_selectAllButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            m_viewer.setAllChecked(true);
        }
    });
    m_selectAllButton.setText(ModelMessages.ReorderDialog_selectAllButton);
    GridDataFactory.create(m_selectAllButton).fillH().grabH();
    // unselect all
    m_unSelectAllButton = new Button(buttonsComposite, SWT.NONE);
    m_unSelectAllButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            m_viewer.setAllChecked(false);
        }
    });
    m_unSelectAllButton.setText(ModelMessages.ReorderDialog_deselectAllButton);
    GridDataFactory.create(m_unSelectAllButton).fillH().grabH();
    // calculate start state
    do_viewer_selectionChanged();
    return container;
}

From source file:org.eclipse.wb.internal.swing.laf.ui.AddCustomLookAndFeelDialog.java

License:Open Source License

@Override
protected void createControls(Composite container) {
    {/*from ww w .j av a2  s .c o  m*/
        GridLayoutFactory.create(container).columns(3);
        // category
        {
            createCategoriesUI(container);
        }
        // separator label
        {
            Label label = new Label(container, SWT.NONE);
            GridDataFactory.create(label).spanH(3);
        }
        // jar
        {
            createJarUI(container);
        }
        // LAF classes
        {
            Label label = new Label(container, SWT.NONE);
            GridDataFactory.create(label).spanH(3).fillH();
            label.setText(LafMessages.AddCustomLookAndFeelDialog_classesLabel);
        }
        {
            m_classTable = CheckboxTableViewer.newCheckList(container,
                    SWT.BORDER | SWT.FULL_SELECTION | SWT.V_SCROLL);
            GridDataFactory.create(m_classTable.getControl()).spanH(2).grab().fill().hintVC(6);
        }
        // buttons composite
        {
            Composite composite = new Composite(container, SWT.NONE);
            GridDataFactory.create(composite).fill();
            GridLayoutFactory.create(composite).noMargins();
            {
                Button button = new Button(composite, SWT.NONE);
                GridDataFactory.create(button).grabH().alignHF();
                button.setText(LafMessages.AddCustomLookAndFeelDialog_selectAll);
                button.addSelectionListener(new SelectionAdapter() {
                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        if (m_classTable.getTable().isEnabled()) {
                            m_classTable.setAllChecked(true);
                        }
                    }
                });
            }
            {
                Button button = new Button(composite, SWT.NONE);
                GridDataFactory.create(button).grabH().alignHF();
                button.setText(LafMessages.AddCustomLookAndFeelDialog_deselectAll);
                button.addSelectionListener(new SelectionAdapter() {
                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        if (m_classTable.getTable().isEnabled()) {
                            m_classTable.setAllChecked(false);
                        }
                    }
                });
            }
        }
    }
    // progress
    {
        createProgressUI(container);
    }
    // configure LAF class table viewer 
    m_classTable.setContentProvider(new IStructuredContentProvider() {
        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }

        public void dispose() {
        }

        public Object[] getElements(Object inputElement) {
            return scanJarFile(m_progressMonitorPart, (String) inputElement);
        }
    });
    m_classTable.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            if (element instanceof LafEntryInfo) {
                return ((LafEntryInfo) element).getName();
            }
            return element.toString();
        }
    });
}

From source file:org.eclipse.wst.common.project.facet.ui.internal.RuntimesPanel.java

License:Open Source License

public RuntimesPanel(final Composite parent, final IFacetedProjectWorkingCopy fpjwc) {
    super(parent, SWT.NONE);

    this.listeners = new ArrayList<IFacetedProjectListener>();

    addDisposeListener(new DisposeListener() {
        public void widgetDisposed(final DisposeEvent e) {
            handleWidgetDisposed();/*from  w ww.  java 2  s  .co m*/
        }
    });

    // Setup runtime validation assistant.

    this.runtimeValidationAssistant = new RuntimeValidationAssistant();

    // Bind to the data model.

    this.fpjwc = fpjwc;

    addDataModelListener(new IFacetedProjectListener() {
        public void handleEvent(final IFacetedProjectEvent event) {
            handleAvailableRuntimesChanged();
        }
    }, IFacetedProjectEvent.Type.AVAILABLE_RUNTIMES_CHANGED);

    addDataModelListener(new IFacetedProjectListener() {
        public void handleEvent(final IFacetedProjectEvent event) {
            handleTargetableRuntimesChanged();
        }
    }, IFacetedProjectEvent.Type.TARGETABLE_RUNTIMES_CHANGED);

    addDataModelListener(new IFacetedProjectListener() {
        public void handleEvent(final IFacetedProjectEvent event) {
            handleTargetedRuntimesChanged();
        }
    }, IFacetedProjectEvent.Type.TARGETED_RUNTIMES_CHANGED);

    addDataModelListener(new IFacetedProjectListener() {
        public void handleEvent(final IFacetedProjectEvent event) {
            handlePrimaryRuntimeChanged();
        }
    }, IFacetedProjectEvent.Type.PRIMARY_RUNTIME_CHANGED);

    this.showAllRuntimesSetting = false;

    // Initialize the colors.

    this.colorGray = new Color(null, 160, 160, 164);

    // Layout the panel.

    final GridLayout layout = new GridLayout(1, false);
    layout.marginHeight = 5;
    layout.marginWidth = 5;

    setLayout(layout);

    this.runtimes = CheckboxTableViewer.newCheckList(this, SWT.BORDER);
    this.runtimes.getTable().setLayoutData(gdfill());
    this.runtimes.setContentProvider(new ContentProvider());
    this.runtimes.setLabelProvider(new LabelProvider());
    this.runtimes.setSorter(new Sorter());
    this.runtimes.setInput(new Object());

    new ValidationProblemToolTip(this.runtimes.getTable());

    this.runtimes.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(final SelectionChangedEvent e) {
            handleRuntimeSelectionChanged();
        }
    });

    this.runtimes.addCheckStateListener(new ICheckStateListener() {
        public void checkStateChanged(final CheckStateChangedEvent e) {
            handleCheckStateChanged(e);
        }
    });

    this.showAllRuntimesCheckbox = new Button(this, SWT.CHECK);
    this.showAllRuntimesCheckbox.setText(Resources.showAllRuntimes);
    this.showAllRuntimesCheckbox.setSelection(this.showAllRuntimesSetting);

    this.showAllRuntimesCheckbox.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            handleShowAllRuntimesSelected();
        }
    });

    final Composite buttons = new Composite(this, SWT.NONE);
    buttons.setLayoutData(gdhalign(gd(), GridData.END));
    buttons.setLayout(glmargins(gl(2), 0, 0));

    this.makePrimaryButton = new Button(buttons, SWT.PUSH);
    this.makePrimaryButton.setText(Resources.makePrimaryLabel);
    this.makePrimaryButton.setEnabled(false);
    GridDataFactory.defaultsFor(this.makePrimaryButton).applyTo(this.makePrimaryButton);

    this.makePrimaryButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            handleMakePrimarySelected();
        }
    });

    this.newRuntimeButton = new Button(buttons, SWT.PUSH);
    this.newRuntimeButton.setText(Resources.newRuntimeButtonLabel);
    GridDataFactory.defaultsFor(this.newRuntimeButton).applyTo(this.newRuntimeButton);

    this.newRuntimeButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            handleNewRuntimeButtonSelected();
        }
    });

    this.runtimeComponentsLabel = new Label(this, SWT.NONE);
    this.runtimeComponentsLabel.setText(Resources.runtimeCompositionLabel);
    this.runtimeComponentsLabel.setLayoutData(gdhfill());

    final Color infoBackgroundColor = parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND);

    final Color infoForegroundColor = parent.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND);

    this.runtimeComponents = new TableViewer(this, SWT.BORDER);
    this.runtimeComponents.getTable().setLayoutData(gdhhint(gdhfill(), 50));
    this.runtimeComponents.getTable().setBackground(infoBackgroundColor);
    this.runtimeComponents.getTable().setForeground(infoForegroundColor);
    this.runtimeComponents.setContentProvider(new RuntimeComponentsContentProvider());
    this.runtimeComponents.setLabelProvider(new RuntimeComponentsLabelProvider());

    this.runtimeComponents.setInput(NO_RUNTIME_SELECTED_PLACEHOLDER);
    this.runtimeComponents.getTable().setEnabled(false);
    this.runtimeComponentsLabel.setEnabled(false);

    refresh();
    this.currentPrimaryRuntime = this.fpjwc.getPrimaryRuntime();

    Dialog.applyDialogFont(parent);
}

From source file:org.eclipse.wst.sse.ui.internal.filter.OutlineCustomFiltersDialog.java

License:Open Source License

private void createCheckBoxList(Composite parent) {
    // Filler/*from   ww w. ja  va  2  s.  c o  m*/
    new Label(parent, SWT.NONE);

    Label info = new Label(parent, SWT.LEFT);
    info.setText(OutlineFilterMessages.CustomFiltersDialog_filterList_label);

    fCheckBoxList = CheckboxTableViewer.newCheckList(parent, SWT.BORDER);
    GridData data = new GridData(GridData.FILL_BOTH);
    data.heightHint = fCheckBoxList.getTable().getItemHeight() * 10;
    fCheckBoxList.getTable().setLayoutData(data);

    fCheckBoxList.setLabelProvider(createLabelPrivder());
    fCheckBoxList.setContentProvider(new ArrayContentProvider());
    Arrays.sort(fBuiltInFilters);
    fCheckBoxList.setInput(fBuiltInFilters);
    setInitialSelections(getEnabledFilterDescriptors());

    List initialSelection = getInitialElementSelections();
    if (initialSelection != null && !initialSelection.isEmpty())
        checkInitialSelections();

    // Description
    info = new Label(parent, SWT.LEFT);
    info.setText(OutlineFilterMessages.CustomFiltersDialog_description_label);
    final Text description = new Text(parent,
            SWT.LEFT | SWT.WRAP | SWT.MULTI | SWT.READ_ONLY | SWT.BORDER | SWT.V_SCROLL);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.heightHint = convertHeightInCharsToPixels(3);
    description.setLayoutData(data);
    fCheckBoxList.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            ISelection selection = event.getSelection();
            if (selection instanceof IStructuredSelection) {
                Object selectedElement = ((IStructuredSelection) selection).getFirstElement();
                if (selectedElement instanceof OutlineFilterDescriptor)
                    description.setText(((OutlineFilterDescriptor) selectedElement).getDescription());
            }
        }
    });
    fCheckBoxList.addCheckStateListener(new ICheckStateListener() {
        /*
         * @see org.eclipse.jface.viewers.ICheckStateListener#checkStateChanged(org.eclipse.jface.viewers.CheckStateChangedEvent)
         */
        public void checkStateChanged(CheckStateChangedEvent event) {
            Object element = event.getElement();
            if (element instanceof OutlineFilterDescriptor) {
                // renew if already touched
                if (fFilterDescriptorChangeHistory.contains(element))
                    fFilterDescriptorChangeHistory.remove(element);
                fFilterDescriptorChangeHistory.push(element);
            }
        }
    });

    addSelectionButtons(parent);
}

From source file:org.eclipse.wst.sse.ui.internal.preferences.ui.TextHoverPreferenceTab.java

License:Open Source License

public Control createContents(Composite tabFolder) {
    Composite hoverComposite = new Composite(tabFolder, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;/*from  w ww .j  a v  a 2  s  . c  o m*/
    hoverComposite.setLayout(layout);
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    hoverComposite.setLayoutData(gd);

    // commented out until these preferences are actually handled in some
    // way
    //      String rollOverLabel=
    // ResourceHandler.getString("TextHoverPreferenceTab.annotationRollover");
    // //$NON-NLS-1$
    //      addCheckBox(hoverComposite, rollOverLabel,
    // CommonEditorPreferenceNames.EDITOR_ANNOTATION_ROLL_OVER, 0);
    //
    //      // Affordance checkbox
    //      String showAffordanceLabel =
    // ResourceHandler.getString("TextHoverPreferenceTab.showAffordance");
    // //$NON-NLS-1$
    //      addCheckBox(hoverComposite, showAffordanceLabel,
    // CommonEditorPreferenceNames.EDITOR_SHOW_TEXT_HOVER_AFFORDANCE, 0);

    Label label = new Label(hoverComposite, SWT.NONE);
    label.setText(SSEUIMessages.TextHoverPreferenceTab_hoverPreferences); //$NON-NLS-1$
    gd = new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1);
    gd.horizontalAlignment = GridData.BEGINNING;
    label.setLayoutData(gd);

    fHoverTableViewer = CheckboxTableViewer.newCheckList(hoverComposite,
            SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION);
    // Hover table
    fHoverTable = fHoverTableViewer.getTable();
    fHoverTable.setHeaderVisible(true);
    fHoverTable.setLinesVisible(true);

    gd = new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1);
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=104507
    GC gc = new GC(fHoverTable);
    gc.setFont(fHoverTable.getFont());
    FontMetrics fontMetrics = gc.getFontMetrics();
    gc.dispose();
    int heightHint = Dialog.convertHeightInCharsToPixels(fontMetrics, 7);
    gd.heightHint = heightHint;

    fHoverTable.setLayoutData(gd);

    TableLayout tableLayout = new TableLayout();
    tableLayout.addColumnData(new ColumnWeightData(1, 140, true));
    tableLayout.addColumnData(new ColumnWeightData(1, 140, true));
    fHoverTable.setLayout(tableLayout);

    fHoverTable.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent e) {
        }

        public void widgetSelected(SelectionEvent e) {
            handleHoverListSelection();
        }
    });

    fNameColumn = new TableColumn(fHoverTable, SWT.NONE);
    fNameColumn.setText(SSEUIMessages.TextHoverPreferenceTab_nameColumnTitle); //$NON-NLS-1$
    fNameColumn.setResizable(true);

    fModifierColumn = new TableColumn(fHoverTable, SWT.NONE);
    fModifierColumn.setText(SSEUIMessages.TextHoverPreferenceTab_modifierColumnTitle); //$NON-NLS-1$
    fModifierColumn.setResizable(true);

    fHoverTableViewer.setUseHashlookup(true);
    fHoverTableViewer.setContentProvider(new ArrayContentProvider());
    fHoverTableViewer.setLabelProvider(new InternalTableLabelProvider());
    ((CheckboxTableViewer) fHoverTableViewer).addCheckStateListener(new ICheckStateListener() {
        /*
         * @see org.eclipse.jface.viewers.ICheckStateListener#checkStateChanged(org.eclipse.jface.viewers.CheckStateChangedEvent)
         */
        public void checkStateChanged(CheckStateChangedEvent event) {
            String id = ((TextHoverDescriptor) event.getElement()).getId();
            if (id == null)
                return;

            TextHoverManager.TextHoverDescriptor[] descriptors = getTextHoverManager().getTextHovers();
            TextHoverManager.TextHoverDescriptor hoverConfig = null;
            int i = 0, length = fTextHovers.length;
            while (i < length) {
                if (id.equals(descriptors[i].getId())) {
                    hoverConfig = fTextHovers[i];
                    hoverConfig.setEnabled(event.getChecked());
                    fModifierEditor.setEnabled(event.getChecked());
                    fHoverTableViewer.setSelection(new StructuredSelection(descriptors[i]));
                }
                i++;
            }

            handleHoverListSelection();
            updateStatus(hoverConfig);
        }
    });

    // Text field for modifier string
    label = new Label(hoverComposite, SWT.LEFT);
    label.setText(SSEUIMessages.TextHoverPreferenceTab_keyModifier); //$NON-NLS-1$
    fModifierEditor = new Text(hoverComposite, SWT.BORDER);
    gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    fModifierEditor.setLayoutData(gd);

    fModifierEditor.addKeyListener(new KeyListener() {
        private boolean isModifierCandidate;

        public void keyPressed(KeyEvent e) {
            isModifierCandidate = e.keyCode > 0 && e.character == 0 && e.stateMask == 0;
        }

        public void keyReleased(KeyEvent e) {
            if (isModifierCandidate && e.stateMask > 0 && e.stateMask == e.stateMask && e.character == 0) {// &&
                // e.time
                // -time
                // <
                // 1000)
                // {
                String text = fModifierEditor.getText();
                Point selection = fModifierEditor.getSelection();
                int i = selection.x - 1;
                while (i > -1 && Character.isWhitespace(text.charAt(i))) {
                    i--;
                }
                boolean needsPrefixDelimiter = i > -1 && !String.valueOf(text.charAt(i)).equals(DELIMITER);

                i = selection.y;
                while (i < text.length() && Character.isWhitespace(text.charAt(i))) {
                    i++;
                }
                boolean needsPostfixDelimiter = i < text.length()
                        && !String.valueOf(text.charAt(i)).equals(DELIMITER);

                String insertString;

                if (needsPrefixDelimiter && needsPostfixDelimiter)
                    insertString = NLS.bind(
                            SSEUIMessages.TextHoverPreferenceTab_insertDelimiterAndModifierAndDelimiter,
                            new String[] { Action.findModifierString(e.stateMask) });
                else if (needsPrefixDelimiter)
                    insertString = NLS.bind(SSEUIMessages.TextHoverPreferenceTab_insertDelimiterAndModifier,
                            new String[] { Action.findModifierString(e.stateMask) });
                else if (needsPostfixDelimiter)
                    insertString = NLS.bind(SSEUIMessages.TextHoverPreferenceTab_insertModifierAndDelimiter,
                            new String[] { Action.findModifierString(e.stateMask) });
                else
                    insertString = Action.findModifierString(e.stateMask);

                if (insertString != null)
                    fModifierEditor.insert(insertString);
            }
        }
    });

    fModifierEditor.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            handleModifierModified();
        }
    });

    // Description
    Label descriptionLabel = new Label(hoverComposite, SWT.LEFT);
    descriptionLabel.setText(SSEUIMessages.TextHoverPreferenceTab_description); //$NON-NLS-1$
    gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING);
    gd.horizontalSpan = 2;
    descriptionLabel.setLayoutData(gd);
    fDescription = new Text(hoverComposite, SWT.LEFT | SWT.WRAP | SWT.MULTI | SWT.READ_ONLY | SWT.BORDER);
    gd = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
    gd.horizontalSpan = 2;
    fDescription.setLayoutData(gd);

    initialize();

    Dialog.applyDialogFont(hoverComposite);

    PlatformUI.getWorkbench().getHelpSystem().setHelp(hoverComposite, IHelpContextIds.PREFSTE_HOVERS_HELPID);
    return hoverComposite;
}

From source file:org.eclipse.wst.sse.ui.preferences.CodeAssistCyclingConfigurationBlock.java

License:Open Source License

private void createDefaultPageViewer(Composite composite) {
    fDefaultPageViewer = CheckboxTableViewer.newCheckList(composite, SWT.SINGLE | SWT.BORDER);
    Table table = fDefaultPageViewer.getTable();
    table.setHeaderVisible(true);/*w  ww  .  j  a va2s. c  o m*/
    table.setLinesVisible(false);
    table.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, false, false, 1, 1));

    TableColumn nameColumn = new TableColumn(table, SWT.NONE);
    nameColumn.setText(SSEUIMessages.CodeAssistAdvancedConfigurationBlock_default_table_category_column_title);
    nameColumn.setResizable(false);

    fDefaultPageViewer.addCheckStateListener(new ICheckStateListener() {
        public void checkStateChanged(CheckStateChangedEvent event) {
            boolean checked = event.getChecked();
            ModelElement element = (ModelElement) event.getElement();
            element.setShouldDisplayOnDefaultPage(checked);
        }
    });

    fDefaultPageViewer.setContentProvider(new ArrayContentProvider());

    DefaultPageTableLabelProvider labelProvider = new DefaultPageTableLabelProvider();
    fDefaultPageViewer.setLabelProvider(labelProvider);
    fDefaultPageViewer.setInput(fModel.defaultPageElements);
    fDefaultPageViewer.setComparator(new ModelViewerComparator(fCategoryDefaultPageComparator));

    final int ICON_AND_CHECKBOX_WITH = 50;
    final int HEADER_MARGIN = 20;
    int minNameWidth = computeWidth(table, nameColumn.getText()) + HEADER_MARGIN;
    for (int i = 0; i < fModel.defaultPageElements.size(); i++) {
        minNameWidth = Math.max(minNameWidth,
                computeWidth(table, labelProvider.getColumnText(fModel.defaultPageElements.get(i), 0))
                        + ICON_AND_CHECKBOX_WITH);
    }

    nameColumn.setWidth(minNameWidth);

    table.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            handleDefaultPageTableSelection();
        }
    });
}