Search in sources :

Example 1 with ExternalFileConfigurationType

use of net.sf.eclipsecs.core.config.configtypes.ExternalFileConfigurationType 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)

Aggregations

File (java.io.File)1 ICheckConfiguration (net.sf.eclipsecs.core.config.ICheckConfiguration)1 ExternalFileConfigurationType (net.sf.eclipsecs.core.config.configtypes.ExternalFileConfigurationType)1 CheckstylePluginException (net.sf.eclipsecs.core.util.CheckstylePluginException)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 SelectionListener (org.eclipse.swt.events.SelectionListener)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Button (org.eclipse.swt.widgets.Button)1 Composite (org.eclipse.swt.widgets.Composite)1 FileDialog (org.eclipse.swt.widgets.FileDialog)1 Label (org.eclipse.swt.widgets.Label)1 Text (org.eclipse.swt.widgets.Text)1