Search in sources :

Example 21 with CheckstylePluginException

use of net.sf.eclipsecs.core.util.CheckstylePluginException in project eclipse-cs by checkstyle.

the class InternalConfigurationEditor method createEditorControl.

/**
 * {@inheritDoc}
 */
@Override
public Control createEditorControl(Composite parent, final Shell shell) {
    Composite contents = new Composite(parent, SWT.NULL);
    contents.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    GridLayout layout = new GridLayout(2, false);
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    contents.setLayout(layout);
    Label lblConfigName = new Label(contents, SWT.NULL);
    lblConfigName.setText(Messages.CheckConfigurationPropertiesDialog_lblName);
    GridData gd = new GridData();
    lblConfigName.setLayoutData(gd);
    mConfigName = new Text(contents, SWT.LEFT | SWT.SINGLE | SWT.BORDER);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    mConfigName.setLayoutData(gd);
    Label lblConfigLocation = new Label(contents, SWT.NULL);
    lblConfigLocation.setText(Messages.CheckConfigurationPropertiesDialog_lblLocation);
    gd = new GridData();
    gd.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING;
    lblConfigLocation.setLayoutData(gd);
    mLocation = new Text(contents, SWT.LEFT | SWT.SINGLE | SWT.BORDER);
    mLocation.setEditable(false);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    mLocation.setLayoutData(gd);
    Label lblDescription = new Label(contents, SWT.NULL);
    lblDescription.setText(Messages.CheckConfigurationPropertiesDialog_lblDescription);
    gd = new GridData();
    gd.horizontalSpan = 2;
    lblDescription.setLayoutData(gd);
    mDescription = new Text(contents, SWT.LEFT | SWT.WRAP | SWT.MULTI | SWT.BORDER | SWT.VERTICAL);
    gd = new GridData(GridData.FILL_BOTH);
    gd.horizontalSpan = 2;
    gd.widthHint = 300;
    gd.heightHint = 100;
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = true;
    mDescription.setLayoutData(gd);
    mBtnImport = new Button(contents, SWT.PUSH);
    mBtnImport.setText(Messages.InternalConfigurationEditor_btnImport);
    gd = new GridData();
    gd.horizontalSpan = 2;
    gd.horizontalAlignment = GridData.END;
    mBtnImport.setLayoutData(gd);
    mBtnImport.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            try {
                ICheckConfiguration targetConfig = getEditedWorkingCopy();
                FileDialog fileDialog = new FileDialog(mConfigName.getShell());
                fileDialog.setText(Messages.InternalConfigurationEditor_titleImportDialog);
                // $NON-NLS-1$ //$NON-NLS-2$
                fileDialog.setFilterExtensions(new String[] { "*.xml", "*.*" });
                String configFileString = fileDialog.open();
                if (configFileString != null && new File(configFileString).exists()) {
                    ICheckConfiguration tmpSourceConfig = new // $NON-NLS-1$
                    CheckConfiguration(// $NON-NLS-1$
                    "dummy", configFileString, null, new ExternalFileConfigurationType(), true, null, null);
                    CheckConfigurationFactory.copyConfiguration(tmpSourceConfig, targetConfig);
                }
            } catch (CheckstylePluginException ex) {
                mDialog.setErrorMessage(ex.getLocalizedMessage());
            }
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        // NOOP
        }
    });
    if (mWorkingCopy.getName() != null) {
        mConfigName.setText(mWorkingCopy.getName());
    }
    if (mWorkingCopy.getLocation() != null) {
        mLocation.setText(mWorkingCopy.getLocation());
    }
    if (mWorkingCopy.getDescription() != null) {
        mDescription.setText(mWorkingCopy.getDescription());
    }
    return contents;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ICheckConfiguration(net.sf.eclipsecs.core.config.ICheckConfiguration) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) CheckstylePluginException(net.sf.eclipsecs.core.util.CheckstylePluginException) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File) ExternalFileConfigurationType(net.sf.eclipsecs.core.config.configtypes.ExternalFileConfigurationType) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 22 with CheckstylePluginException

use of net.sf.eclipsecs.core.util.CheckstylePluginException in project eclipse-cs by checkstyle.

the class ProjectConfigurationFactory method createDefaultProjectConfiguration.

/**
 * Creates a default project configuration for the given projects, using the default globbal check
 * configuration.
 *
 * @param project
 *          the project
 * @return the default project configuration
 */
public static IProjectConfiguration createDefaultProjectConfiguration(IProject project) {
    FileSet standardFileSet = new FileSet(Messages.SimpleFileSetsEditor_nameAllFileset, CheckConfigurationFactory.getDefaultCheckConfiguration());
    try {
        standardFileSet.getFileMatchPatterns().add(new FileMatchPattern(".*"));
    } catch (CheckstylePluginException e) {
        throw new RuntimeException(e);
    }
    List<FileSet> fileSets = Arrays.asList(standardFileSet);
    IFilter[] filters = PluginFilters.getConfiguredFilters();
    List<IFilter> defaultFilters = new ArrayList<>();
    for (IFilter filter : filters) {
        if (filter.isEnabled()) {
            defaultFilters.add(filter);
        }
    }
    return new ProjectConfiguration(project, null, fileSets, defaultFilters, true, false);
}
Also used : IFilter(net.sf.eclipsecs.core.projectconfig.filters.IFilter) ArrayList(java.util.ArrayList) CheckstylePluginException(net.sf.eclipsecs.core.util.CheckstylePluginException)

Example 23 with CheckstylePluginException

use of net.sf.eclipsecs.core.util.CheckstylePluginException 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)

Example 24 with CheckstylePluginException

use of net.sf.eclipsecs.core.util.CheckstylePluginException in project eclipse-cs by checkstyle.

the class CheckConfigurationPropertiesDialog method setUniqueName.

/**
 * Creates a non conflicting name out of a name proposal.
 *
 * @param config
 *          the working copy to set the name on
 * @param checkConfigName
 *          the name proposal
 */
private void setUniqueName(CheckConfigurationWorkingCopy config, String checkConfigName) {
    String uniqueName = checkConfigName;
    int counter = 2;
    while (true) {
        try {
            config.setName(uniqueName);
            break;
        } catch (CheckstylePluginException e) {
            // $NON-NLS-1$ //$NON-NLS-2$
            uniqueName = checkConfigName + " (" + counter + ")";
            counter++;
        }
    }
}
Also used : CheckstylePluginException(net.sf.eclipsecs.core.util.CheckstylePluginException) Point(org.eclipse.swt.graphics.Point)

Example 25 with CheckstylePluginException

use of net.sf.eclipsecs.core.util.CheckstylePluginException in project eclipse-cs by checkstyle.

the class CheckConfigurationPropertiesDialog method createButtonBar.

/**
 * {@inheritDoc}
 */
@Override
protected Control createButtonBar(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout(3, false);
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    composite.setLayout(layout);
    composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    mBtnProperties = new Button(composite, SWT.PUSH);
    mBtnProperties.setText(Messages.CheckConfigurationPropertiesDialog_btnAdditionalProps);
    GridData gd = new GridData();
    gd.horizontalAlignment = GridData.BEGINNING;
    gd.horizontalIndent = 5;
    mBtnProperties.setLayoutData(gd);
    mBtnProperties.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            try {
                mConfigurationEditor.getEditedWorkingCopy();
                ResolvablePropertiesDialog dialog = new ResolvablePropertiesDialog(getShell(), mCheckConfig);
                dialog.open();
            } catch (CheckstylePluginException ex) {
                setErrorMessage(ex.getLocalizedMessage());
            }
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        // NOOP
        }
    });
    Control buttonBar = super.createButtonBar(composite);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalAlignment = GridData.END;
    buttonBar.setLayoutData(gd);
    return composite;
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) Control(org.eclipse.swt.widgets.Control) Composite(org.eclipse.swt.widgets.Composite) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) CheckstylePluginException(net.sf.eclipsecs.core.util.CheckstylePluginException) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

CheckstylePluginException (net.sf.eclipsecs.core.util.CheckstylePluginException)34 ICheckConfiguration (net.sf.eclipsecs.core.config.ICheckConfiguration)7 IProject (org.eclipse.core.resources.IProject)7 CoreException (org.eclipse.core.runtime.CoreException)7 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)6 IProjectConfiguration (net.sf.eclipsecs.core.projectconfig.IProjectConfiguration)5 GridData (org.eclipse.swt.layout.GridData)5 Composite (org.eclipse.swt.widgets.Composite)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 FileSet (net.sf.eclipsecs.core.projectconfig.FileSet)4 IFilter (net.sf.eclipsecs.core.projectconfig.filters.IFilter)4 Document (org.dom4j.Document)4 IStatus (org.eclipse.core.runtime.IStatus)4 Status (org.eclipse.core.runtime.Status)4 GridLayout (org.eclipse.swt.layout.GridLayout)4 Button (org.eclipse.swt.widgets.Button)4 File (java.io.File)3 IOException (java.io.IOException)3 CheckstyleException (com.puppycrawl.tools.checkstyle.api.CheckstyleException)2