Search in sources :

Example 1 with CheckstylePluginException

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

the class CheckConfigurationPropertiesDialog method createDialogArea.

/**
 * Creates the dialogs main contents.
 *
 * @param parent
 *          the parent composite
 */
@Override
protected Control createDialogArea(Composite parent) {
    // set the logo
    this.setTitleImage(CheckstyleUIPluginImages.getImage(CheckstyleUIPluginImages.PLUGIN_LOGO));
    Composite composite = (Composite) super.createDialogArea(parent);
    Composite contents = new Composite(composite, SWT.NULL);
    contents.setLayout(new GridLayout(2, false));
    GridData fd = new GridData(GridData.FILL_BOTH);
    contents.setLayoutData(fd);
    Label lblConfigType = new Label(contents, SWT.NULL);
    lblConfigType.setText(Messages.CheckConfigurationPropertiesDialog_lblConfigType);
    fd = new GridData();
    // this is a weird hack to find the longest label
    // this is done to have a nice ordered appearance of the this label
    // and the labels below
    // this is very difficult to do, because they belong to different
    // layouts
    GC gc = new GC(lblConfigType);
    int nameSize = gc.textExtent(Messages.CheckConfigurationPropertiesDialog_lblName).x;
    int locationsSize = gc.textExtent(Messages.CheckConfigurationPropertiesDialog_lblLocation).x;
    int max = Math.max(nameSize, locationsSize);
    gc.dispose();
    fd.widthHint = max;
    lblConfigType.setLayoutData(fd);
    mConfigType = new ComboViewer(contents);
    fd = new GridData();
    mConfigType.getCombo().setLayoutData(fd);
    mConfigType.setContentProvider(new ArrayContentProvider());
    mConfigType.setLabelProvider(new LabelProvider() {

        /**
         * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
         */
        @Override
        public String getText(Object element) {
            return ((IConfigurationType) element).getName();
        }

        /**
         * @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object)
         */
        @Override
        public Image getImage(Object element) {
            return ConfigurationTypesUI.getConfigurationTypeImage((IConfigurationType) element);
        }
    });
    mConfigType.addSelectionChangedListener(new ISelectionChangedListener() {

        /**
         * @see ISelectionChangedListener#selectionChanged(
         *      org.eclipse.jface.viewers.SelectionChangedEvent)
         */
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            if (event.getSelection() instanceof IStructuredSelection) {
                IConfigurationType type = (IConfigurationType) ((IStructuredSelection) event.getSelection()).getFirstElement();
                if (mConfigType.getCombo().isEnabled()) {
                    String oldName = mCheckConfig.getName();
                    String oldDescr = mCheckConfig.getDescription();
                    mCheckConfig = mWorkingSet.newWorkingCopy(type);
                    try {
                        mCheckConfig.setName(oldName);
                    } catch (CheckstylePluginException e) {
                    // NOOP
                    }
                    mCheckConfig.setDescription(oldDescr);
                }
                createConfigurationEditor(mCheckConfig);
            }
        }
    });
    mEditorPlaceHolder = new Composite(contents, SWT.NULL);
    GridLayout layout = new GridLayout(1, true);
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    mEditorPlaceHolder.setLayout(layout);
    fd = new GridData(GridData.FILL_HORIZONTAL);
    fd.horizontalSpan = 2;
    mEditorPlaceHolder.setLayoutData(fd);
    return composite;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Image(org.eclipse.swt.graphics.Image) Point(org.eclipse.swt.graphics.Point) IConfigurationType(net.sf.eclipsecs.core.config.configtypes.IConfigurationType) GridLayout(org.eclipse.swt.layout.GridLayout) ComboViewer(org.eclipse.jface.viewers.ComboViewer) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) CheckstylePluginException(net.sf.eclipsecs.core.util.CheckstylePluginException) GC(org.eclipse.swt.graphics.GC) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 2 with CheckstylePluginException

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

the class CheckConfigurationPropertiesDialog method okPressed.

/**
 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
 */
@Override
protected void okPressed() {
    try {
        // Check if the configuration is valid
        mCheckConfig = mConfigurationEditor.getEditedWorkingCopy();
        CheckConfigurationTester tester = new CheckConfigurationTester(mCheckConfig);
        List<ResolvableProperty> unresolvedProps = tester.getUnresolvedProperties();
        if (!unresolvedProps.isEmpty()) {
            MessageDialog dialog = new MessageDialog(getShell(), Messages.CheckConfigurationPropertiesDialog_titleUnresolvedProps, null, NLS.bind(Messages.CheckConfigurationPropertiesDialog_msgUnresolvedProps, // $NON-NLS-1$
            "" + unresolvedProps.size()), MessageDialog.WARNING, new String[] { Messages.CheckConfigurationPropertiesDialog_btnEditProps, Messages.CheckConfigurationPropertiesDialog_btnContinue, Messages.CheckConfigurationPropertiesDialog_btnCancel }, 0);
            int result = dialog.open();
            if (0 == result) {
                ResolvablePropertiesDialog propsDialog = new ResolvablePropertiesDialog(getShell(), mCheckConfig);
                propsDialog.open();
                return;
            } else if (1 == result) {
                super.okPressed();
            } else if (2 == result) {
                return;
            }
        } else {
            super.okPressed();
        }
    } catch (CheckstylePluginException e) {
        CheckstyleLog.log(e);
        this.setErrorMessage(e.getLocalizedMessage());
    }
}
Also used : ResolvableProperty(net.sf.eclipsecs.core.config.ResolvableProperty) CheckstylePluginException(net.sf.eclipsecs.core.util.CheckstylePluginException) CheckConfigurationTester(net.sf.eclipsecs.core.config.CheckConfigurationTester) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) Point(org.eclipse.swt.graphics.Point)

Example 3 with CheckstylePluginException

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

the class CheckConfigurationWorkingSetEditor method copyCheckConfig.

/**
 * Copy an existing config.
 */
private void copyCheckConfig() {
    IStructuredSelection selection = (IStructuredSelection) mViewer.getSelection();
    ICheckConfiguration sourceConfig = (ICheckConfiguration) selection.getFirstElement();
    if (sourceConfig == null) {
        // 
        return;
    }
    try {
        // Open the properties dialog to change default name and description
        CheckConfigurationPropertiesDialog dialog = new CheckConfigurationPropertiesDialog(getShell(), null, mWorkingSet);
        dialog.setTemplateConfiguration(sourceConfig);
        dialog.setBlockOnOpen(true);
        if (Window.OK == dialog.open()) {
            CheckConfigurationWorkingCopy newConfig = dialog.getCheckConfiguration();
            // Copy the source configuration into the new internal config
            CheckConfigurationFactory.copyConfiguration(sourceConfig, newConfig);
            mWorkingSet.addCheckConfiguration(newConfig);
            mViewer.setInput(mWorkingSet.getWorkingCopies());
            mViewer.refresh();
        }
    } catch (CheckstylePluginException e) {
        CheckstyleUIPlugin.errorDialog(getShell(), e, true);
    }
}
Also used : ICheckConfiguration(net.sf.eclipsecs.core.config.ICheckConfiguration) CheckConfigurationWorkingCopy(net.sf.eclipsecs.core.config.CheckConfigurationWorkingCopy) CheckstylePluginException(net.sf.eclipsecs.core.util.CheckstylePluginException) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 4 with CheckstylePluginException

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

the class CheckConfigurationWorkingSetEditor method configureCheckConfig.

private void configureCheckConfig() {
    CheckConfigurationWorkingCopy config = (CheckConfigurationWorkingCopy) ((IStructuredSelection) mViewer.getSelection()).getFirstElement();
    if (config != null) {
        try {
            // test if file exists
            config.getCheckstyleConfiguration();
            CheckConfigurationConfigureDialog dialog = new CheckConfigurationConfigureDialog(getShell(), config);
            dialog.setBlockOnOpen(true);
            dialog.open();
        } catch (CheckstylePluginException e) {
            CheckstyleUIPlugin.warningDialog(getShell(), NLS.bind(Messages.errorCannotResolveCheckLocation, config.getLocation(), config.getName()), e);
        }
    }
}
Also used : CheckConfigurationWorkingCopy(net.sf.eclipsecs.core.config.CheckConfigurationWorkingCopy) CheckstylePluginException(net.sf.eclipsecs.core.util.CheckstylePluginException)

Example 5 with CheckstylePluginException

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

the class ProjectConfigurationEditor method getEditedWorkingCopy.

/**
 * {@inheritDoc}
 */
@Override
public CheckConfigurationWorkingCopy getEditedWorkingCopy() throws CheckstylePluginException {
    mWorkingCopy.setName(mConfigName.getText());
    mWorkingCopy.setDescription(mDescription.getText());
    mWorkingCopy.getAdditionalData().put(ExternalFileConfigurationType.KEY_PROTECT_CONFIG, // $NON-NLS-1$
    "" + mChkProtectConfig.getSelection());
    try {
        mWorkingCopy.setLocation(mLocation.getText());
    } catch (CheckstylePluginException e) {
        String location = mLocation.getText();
        if (Strings.emptyToNull(location) == null) {
            throw e;
        }
        ICheckConfigurationWorkingSet ws = mCheckConfigDialog.getCheckConfigurationWorkingSet();
        IPath tmp = new Path(location);
        boolean isFirstPartProject = ResourcesPlugin.getWorkspace().getRoot().getProject(tmp.segment(0)).exists();
        if (ws instanceof LocalCheckConfigurationWorkingSet && !isFirstPartProject) {
            location = ((LocalCheckConfigurationWorkingSet) ws).getProject().getFullPath().append(location).toString();
            mLocation.setText(location);
        } else if (ws instanceof GlobalCheckConfigurationWorkingSet && !isFirstPartProject) {
            throw new CheckstylePluginException(NLS.bind(Messages.ProjectConfigurationEditor_msgNoProjectInWorkspace, tmp.segment(0)));
        }
        if (ensureFileExists(location)) {
            mWorkingCopy.setLocation(mLocation.getText());
        } else {
            throw e;
        }
    }
    return mWorkingCopy;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) GlobalCheckConfigurationWorkingSet(net.sf.eclipsecs.core.config.GlobalCheckConfigurationWorkingSet) IPath(org.eclipse.core.runtime.IPath) ICheckConfigurationWorkingSet(net.sf.eclipsecs.core.config.ICheckConfigurationWorkingSet) CheckstylePluginException(net.sf.eclipsecs.core.util.CheckstylePluginException) LocalCheckConfigurationWorkingSet(net.sf.eclipsecs.core.projectconfig.LocalCheckConfigurationWorkingSet)

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