Search in sources :

Example 1 with RuleGroupMetadata

use of net.sf.eclipsecs.core.config.meta.RuleGroupMetadata in project eclipse-cs by checkstyle.

the class CheckConfigurationConfigureDialog method createTreeViewer.

private Control createTreeViewer(Composite parent) {
    Group knownModules = new Group(parent, SWT.NULL);
    knownModules.setLayout(new GridLayout());
    knownModules.setText(Messages.CheckConfigurationConfigureDialog_lblKnownModules);
    mTxtTreeFilter = new Text(knownModules, SWT.SINGLE | SWT.BORDER);
    mTxtTreeFilter.setText(mDefaultFilterText);
    mTxtTreeFilter.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    mTxtTreeFilter.addModifyListener(mController);
    mTxtTreeFilter.addKeyListener(mController);
    // select all of the default text on focus gain
    mTxtTreeFilter.addFocusListener(new FocusListener() {

        @Override
        public void focusGained(FocusEvent e) {
            if (mDefaultFilterText.equals(mTxtTreeFilter.getText())) {
                getShell().getDisplay().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        mTxtTreeFilter.selectAll();
                    }
                });
            }
        }

        @Override
        public void focusLost(FocusEvent e) {
        }
    });
    mTreeViewer = new TreeViewer(knownModules, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    mTreeViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
    mTreeViewer.setContentProvider(new MetaDataContentProvider());
    mTreeViewer.setLabelProvider(new MetaDataLabelProvider());
    mTreeViewer.addSelectionChangedListener(mController);
    mTreeViewer.addDoubleClickListener(mController);
    mTreeViewer.getTree().addKeyListener(mController);
    // filter hidden elements
    mTreeViewer.addFilter(new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            boolean passes = true;
            if (element instanceof RuleGroupMetadata) {
                passes = !((RuleGroupMetadata) element).isHidden();
            } else if (element instanceof RuleMetadata) {
                passes = !((RuleMetadata) element).isHidden();
            }
            return passes;
        }
    });
    mAddButton = new Button(knownModules, SWT.PUSH);
    mAddButton.setText((Messages.CheckConfigurationConfigureDialog_btnAdd));
    GridData gd = new GridData();
    gd.horizontalAlignment = GridData.END;
    mAddButton.setLayoutData(gd);
    mAddButton.addSelectionListener(mController);
    return knownModules;
}
Also used : Group(org.eclipse.swt.widgets.Group) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Text(org.eclipse.swt.widgets.Text) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Viewer(org.eclipse.jface.viewers.Viewer) EnhancedCheckBoxTableViewer(net.sf.eclipsecs.ui.util.table.EnhancedCheckBoxTableViewer) FocusEvent(org.eclipse.swt.events.FocusEvent) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) RuleGroupMetadata(net.sf.eclipsecs.core.config.meta.RuleGroupMetadata) RuleMetadata(net.sf.eclipsecs.core.config.meta.RuleMetadata) FocusListener(org.eclipse.swt.events.FocusListener)

Example 2 with RuleGroupMetadata

use of net.sf.eclipsecs.core.config.meta.RuleGroupMetadata in project eclipse-cs by checkstyle.

the class CheckConfigurationConfigureDialog method initialize.

/**
 * Initialize the dialogs controls with the data.
 */
private void initialize() {
    mConfigurable = mConfiguration.isConfigurable();
    try {
        mModules = mConfiguration.getModules();
    } catch (CheckstylePluginException e) {
        mModules = new ArrayList<>();
        CheckstyleUIPlugin.errorDialog(getShell(), e, true);
    }
    mTableViewer.setInput(mModules);
    this.setTitle(NLS.bind(Messages.CheckConfigurationConfigureDialog_titleMessageArea, mConfiguration.getType().getName(), mConfiguration.getName()));
    if (mConfigurable) {
        this.setMessage(Messages.CheckConfigurationConfigureDialog_msgEditConfig);
    } else {
        this.setMessage(Messages.CheckConfigurationConfigureDialog_msgReadonlyConfig);
    }
    // set the logo
    this.setTitleImage(CheckstyleUIPluginImages.getImage(CheckstyleUIPluginImages.PLUGIN_LOGO));
    mAddButton.setEnabled(mConfigurable);
    mRemoveButton.setEnabled(mConfigurable);
    mTreeViewer.setInput(MetadataFactory.getRuleGroupMetadata());
    List<RuleGroupMetadata> checkGroups = MetadataFactory.getRuleGroupMetadata();
    if (!checkGroups.isEmpty()) {
        ISelection initialSelection = new StructuredSelection(checkGroups.get(0));
        mTreeViewer.setSelection(initialSelection);
    }
}
Also used : ArrayList(java.util.ArrayList) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) CheckstylePluginException(net.sf.eclipsecs.core.util.CheckstylePluginException) RuleGroupMetadata(net.sf.eclipsecs.core.config.meta.RuleGroupMetadata)

Aggregations

RuleGroupMetadata (net.sf.eclipsecs.core.config.meta.RuleGroupMetadata)2 ArrayList (java.util.ArrayList)1 RuleMetadata (net.sf.eclipsecs.core.config.meta.RuleMetadata)1 CheckstylePluginException (net.sf.eclipsecs.core.util.CheckstylePluginException)1 EnhancedCheckBoxTableViewer (net.sf.eclipsecs.ui.util.table.EnhancedCheckBoxTableViewer)1 ISelection (org.eclipse.jface.viewers.ISelection)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 TreeViewer (org.eclipse.jface.viewers.TreeViewer)1 Viewer (org.eclipse.jface.viewers.Viewer)1 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)1 FocusEvent (org.eclipse.swt.events.FocusEvent)1 FocusListener (org.eclipse.swt.events.FocusListener)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Button (org.eclipse.swt.widgets.Button)1 Group (org.eclipse.swt.widgets.Group)1 Text (org.eclipse.swt.widgets.Text)1