diff --git a/config/checkstyle-checks.xml b/config/checkstyle-checks.xml
index d1f28eef8..c3506b2e5 100644
--- a/config/checkstyle-checks.xml
+++ b/config/checkstyle-checks.xml
@@ -660,6 +660,7 @@
+
diff --git a/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/config/CheckConfigurationWorkingSetEditor.java b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/config/CheckConfigurationWorkingSetEditor.java
index 4efbae967..879a8ef4e 100644
--- a/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/config/CheckConfigurationWorkingSetEditor.java
+++ b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/config/CheckConfigurationWorkingSetEditor.java
@@ -110,30 +110,36 @@ public Composite createContents(Composite parent) {
boolean useDefaultColumn = mWorkingSet instanceof GlobalCheckConfigurationWorkingSet;
- ButtonBarActions buttonBarActions = new ButtonBarActions(this::addCheckConfig,
- this::editCheckConfig, this::configureCheckConfig, this::copyCheckConfig,
- this::removeCheckConfig, this::setDefaultCheckConfig,
- this::exportCheckstyleCheckConfig);
- this.buttonBar = new ButtonBar(configComposite, SWT.NULL, useDefaultColumn, buttonBarActions);
+ this.buttonBar = new ButtonBar(configComposite, SWT.NULL, useDefaultColumn,
+ new ButtonBarActions(this::addCheckConfig, this::editCheckConfig,
+ this::configureCheckConfig, this::copyCheckConfig, this::removeCheckConfig,
+ this::setDefaultCheckConfig, this::exportCheckstyleCheckConfig));
FormData formData = new FormData();
formData.top = new FormAttachment(0);
formData.right = new FormAttachment(100);
formData.bottom = new FormAttachment(100);
buttonBar.setLayoutData(formData);
- Composite tableAndDesc = new Composite(configComposite, SWT.NULL);
+ createTableAndDesc(configComposite, useDefaultColumn);
+ // enforce update of button enabled state
+ handleSelectionChanged(null);
+
+ return configComposite;
+ }
+
+ private void createTableAndDesc(Composite parent, boolean useDefaultColumn) {
+ Composite tableAndDesc = new Composite(parent, SWT.NULL);
tableAndDesc.setLayout(new FormLayout());
- formData = new FormData();
+ FormData formData = new FormData();
formData.left = new FormAttachment(0);
formData.top = new FormAttachment(0);
formData.right = new FormAttachment(buttonBar, -3, SWT.LEFT);
formData.bottom = new FormAttachment(100, 0);
tableAndDesc.setLayoutData(formData);
- final ConfigurationLabelProvider multiProvider = new ConfigurationLabelProvider(mWorkingSet);
this.configTable = new ConfigTable(tableAndDesc, SWT.NULL, useDefaultColumn,
- mWorkingSet.getWorkingCopies(), multiProvider, this::configureCheckConfig,
- this::handleSelectionChanged);
+ mWorkingSet.getWorkingCopies(), new ConfigurationLabelProvider(mWorkingSet),
+ this::configureCheckConfig, this::handleSelectionChanged);
formData = new FormData();
formData.left = new FormAttachment(0);
formData.top = new FormAttachment(0);
@@ -168,39 +174,38 @@ public Composite createContents(Composite parent) {
mConfigurationDescription.setLayoutData(formData);
if (mIsShowUsage) {
- Composite usageArea = new Composite(tableAndDesc, SWT.NULL);
- usageArea.setLayout(new FormLayout());
- formData = new FormData();
- formData.left = new FormAttachment(60, 0);
- formData.top = new FormAttachment(this.configTable, 3);
- formData.right = new FormAttachment(100);
- formData.bottom = new FormAttachment(100);
- usageArea.setLayoutData(formData);
-
- Label lblUsage = new Label(usageArea, SWT.NULL);
- lblUsage.setText(Messages.CheckstylePreferencePage_lblProjectUsage);
- formData = new FormData();
- formData.left = new FormAttachment(0);
- formData.top = new FormAttachment(0);
- formData.right = new FormAttachment(100);
- lblUsage.setLayoutData(formData);
-
- mUsageView = new TableViewer(usageArea);
- mUsageView.getControl().setBackground(usageArea.getBackground());
- mUsageView.setContentProvider(new ArrayContentProvider());
- mUsageView.setLabelProvider(new WorkbenchLabelProvider());
- formData = new FormData();
- formData.left = new FormAttachment(0);
- formData.top = new FormAttachment(lblUsage);
- formData.right = new FormAttachment(100);
- formData.bottom = new FormAttachment(100);
- mUsageView.getControl().setLayoutData(formData);
+ createUsageArea(tableAndDesc);
}
+ }
- // enforce update of button enabled state
- handleSelectionChanged(null);
+ private void createUsageArea(Composite parent) {
+ Composite usageArea = new Composite(parent, SWT.NULL);
+ usageArea.setLayout(new FormLayout());
+ FormData formData = new FormData();
+ formData.left = new FormAttachment(60, 0);
+ formData.top = new FormAttachment(this.configTable, 3);
+ formData.right = new FormAttachment(100);
+ formData.bottom = new FormAttachment(100);
+ usageArea.setLayoutData(formData);
- return configComposite;
+ Label lblUsage = new Label(usageArea, SWT.NULL);
+ lblUsage.setText(Messages.CheckstylePreferencePage_lblProjectUsage);
+ formData = new FormData();
+ formData.left = new FormAttachment(0);
+ formData.top = new FormAttachment(0);
+ formData.right = new FormAttachment(100);
+ lblUsage.setLayoutData(formData);
+
+ mUsageView = new TableViewer(usageArea);
+ mUsageView.getControl().setBackground(usageArea.getBackground());
+ mUsageView.setContentProvider(new ArrayContentProvider());
+ mUsageView.setLabelProvider(new WorkbenchLabelProvider());
+ formData = new FormData();
+ formData.left = new FormAttachment(0);
+ formData.top = new FormAttachment(lblUsage);
+ formData.right = new FormAttachment(100);
+ formData.bottom = new FormAttachment(100);
+ mUsageView.getControl().setLayoutData(formData);
}
/**
@@ -490,50 +495,40 @@ private ButtonBar(Composite parent, int style, boolean useDefaultButton, ButtonB
setLayout(new FormLayout());
- Button mAddButton = new Button(this, SWT.PUSH);
- mAddButton.setText(Messages.CheckstylePreferencePage_btnNew);
- mAddButton.addSelectionListener(SelectionListener
- .widgetSelectedAdapter(event -> actions.addCheckConfig.accept(getShell())));
FormData formData = new FormData();
formData.left = new FormAttachment(0);
formData.top = new FormAttachment(0);
formData.right = new FormAttachment(100);
+ Button mAddButton = createButton(this, Messages.CheckstylePreferencePage_btnNew,
+ actions.addCheckConfig);
mAddButton.setLayoutData(formData);
- mEditButton = new Button(this, SWT.PUSH);
- mEditButton.setText(Messages.CheckstylePreferencePage_btnProperties);
- mEditButton.addSelectionListener(SelectionListener
- .widgetSelectedAdapter(event -> actions.editCheckConfig.accept(getShell())));
+ mEditButton = createButton(this, Messages.CheckstylePreferencePage_btnProperties,
+ actions.editCheckConfig);
formData = new FormData();
formData.left = new FormAttachment(0);
formData.top = new FormAttachment(mAddButton, 3, SWT.BOTTOM);
formData.right = new FormAttachment(100);
mEditButton.setLayoutData(formData);
- mConfigureButton = new Button(this, SWT.PUSH);
- mConfigureButton.setText(Messages.CheckstylePreferencePage_btnConfigure);
- mConfigureButton.addSelectionListener(SelectionListener
- .widgetSelectedAdapter(event -> actions.configureCheckConfig.accept(getShell())));
+ mConfigureButton = createButton(this, Messages.CheckstylePreferencePage_btnConfigure,
+ actions.configureCheckConfig);
formData = new FormData();
formData.left = new FormAttachment(0);
formData.top = new FormAttachment(mEditButton, 3, SWT.BOTTOM);
formData.right = new FormAttachment(100);
mConfigureButton.setLayoutData(formData);
- mCopyButton = new Button(this, SWT.PUSH);
- mCopyButton.setText(Messages.CheckstylePreferencePage_btnCopy);
- mCopyButton.addSelectionListener(SelectionListener
- .widgetSelectedAdapter(event -> actions.copyCheckConfig.accept(getShell())));
+ mCopyButton = createButton(this, Messages.CheckstylePreferencePage_btnCopy,
+ actions.copyCheckConfig);
formData = new FormData();
formData.left = new FormAttachment(0);
formData.top = new FormAttachment(mConfigureButton, 3, SWT.BOTTOM);
formData.right = new FormAttachment(100);
mCopyButton.setLayoutData(formData);
- mRemoveButton = new Button(this, SWT.PUSH);
- mRemoveButton.setText(Messages.CheckstylePreferencePage_btnRemove);
- mRemoveButton.addSelectionListener(SelectionListener
- .widgetSelectedAdapter(event -> actions.removeCheckConfig.accept(getShell())));
+ mRemoveButton = createButton(this, Messages.CheckstylePreferencePage_btnRemove,
+ actions.removeCheckConfig);
formData = new FormData();
formData.left = new FormAttachment(0);
formData.top = new FormAttachment(mCopyButton, 3, SWT.BOTTOM);
@@ -541,12 +536,9 @@ private ButtonBar(Composite parent, int style, boolean useDefaultButton, ButtonB
mRemoveButton.setLayoutData(formData);
if (useDefaultButton) {
- mDefaultButton = new Button(this, SWT.PUSH);
- mDefaultButton.setText(Messages.CheckstylePreferencePage_btnDefault);
- mDefaultButton.addSelectionListener(SelectionListener
- .widgetSelectedAdapter(event -> actions.setDefaultCheckConfig.run()));
+ mDefaultButton = createButton(this, Messages.CheckstylePreferencePage_btnDefault,
+ event -> actions.setDefaultCheckConfig.run());
mDefaultButton.setToolTipText(Messages.CheckstylePreferencePage_txtDefault);
-
formData = new FormData();
formData.left = new FormAttachment(0);
formData.top = new FormAttachment(mRemoveButton, 3, SWT.BOTTOM);
@@ -556,10 +548,8 @@ private ButtonBar(Composite parent, int style, boolean useDefaultButton, ButtonB
mDefaultButton = null;
}
- mExportButton = new Button(this, SWT.PUSH);
- mExportButton.setText(Messages.CheckstylePreferencePage_btnExport);
- mExportButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(
- event -> actions.exportCheckstyleCheckConfig.accept(getShell())));
+ mExportButton = createButton(this, Messages.CheckstylePreferencePage_btnExport,
+ actions.exportCheckstyleCheckConfig);
formData = new FormData();
formData.left = new FormAttachment(0);
formData.right = new FormAttachment(100);
@@ -567,6 +557,14 @@ private ButtonBar(Composite parent, int style, boolean useDefaultButton, ButtonB
mExportButton.setLayoutData(formData);
}
+ private Button createButton(Composite parent, String text, Consumer action) {
+ Button button = new Button(parent, SWT.PUSH);
+ button.setText(text);
+ button.addSelectionListener(SelectionListener.widgetSelectedAdapter(
+ event -> action.accept(getShell())));
+ return button;
+ }
+
private void setSelectionState(boolean configSelected, boolean configEditable,
boolean configDefault) {
mEditButton.setEnabled(configSelected);
diff --git a/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/config/ConfiguredModulesTable.java b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/config/ConfiguredModulesTable.java
index eafd8ae7d..5c872fe55 100644
--- a/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/config/ConfiguredModulesTable.java
+++ b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/config/ConfiguredModulesTable.java
@@ -24,6 +24,7 @@
import java.util.function.Consumer;
import org.eclipse.jface.dialogs.IDialogSettings;
+import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.CheckboxTableViewer;
import org.eclipse.jface.viewers.ColumnWeightData;
@@ -75,36 +76,7 @@ public ConfiguredModulesTable(Composite parent, int style, boolean configurable,
configuredModulesGroup.setLayout(new GridLayout());
configuredModulesGroup.setText("\0");
- Table table = new Table(configuredModulesGroup,
- SWT.CHECK | SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
- table.setLayoutData(new GridData(GridData.FILL_BOTH));
- table.setHeaderVisible(true);
- table.setLinesVisible(true);
-
- TableLayout tableLayout = new TableLayout();
- table.setLayout(tableLayout);
-
- TableColumn column1 = new TableColumn(table, SWT.NONE);
- column1.setAlignment(SWT.CENTER);
- column1.setText(Messages.CheckConfigurationConfigureDialog_colEnabled);
- tableLayout.addColumnData(new ColumnWeightData(15));
-
- TableColumn column2 = new TableColumn(table, SWT.NONE);
- column2.setText(Messages.CheckConfigurationConfigureDialog_colModule);
- tableLayout.addColumnData(new ColumnWeightData(30));
-
- TableColumn column3 = new TableColumn(table, SWT.NONE);
- column3.setText(Messages.CheckConfigurationConfigureDialog_colSeverity);
- tableLayout.addColumnData(new ColumnWeightData(20));
-
- TableColumn column4 = new TableColumn(table, SWT.NONE);
- column4.setText(Messages.CheckConfigurationConfigureDialog_colComment);
- tableLayout.addColumnData(new ColumnWeightData(35));
-
- // by default the table viewer sorts on column 0, but we want to sort by the module label
- table.setSortColumn(column2);
-
- this.tableViewer = new CheckboxTableViewer(table);
+ this.tableViewer = new CheckboxTableViewer(createTable(configuredModulesGroup));
ModuleLabelProvider multiProvider = new ModuleLabelProvider();
tableViewer.setLabelProvider(multiProvider);
tableViewer.setContentProvider(ArrayContentProvider.getInstance());
@@ -133,29 +105,14 @@ public ConfiguredModulesTable(Composite parent, int style, boolean configurable,
}));
}
- tableViewer.setCheckStateProvider(new ICheckStateProvider() {
-
- @Override
- public boolean isGrayed(Object element) {
- return !configurable;
- }
-
- @Override
- public boolean isChecked(Object element) {
- Module module = (Module) element;
- return !Severity.IGNORE.equals(module.getSeverity()) || !module.getMetaData().hasSeverity();
- }
- });
+ tableViewer.setCheckStateProvider(new TableCheckStateProvider(configurable));
tableViewer.setInput(modules);
TableViewerEnhancer.enhance(tableViewer, multiProvider);
Composite buttons = new Composite(configuredModulesGroup, SWT.NONE);
- GridLayout layout = new GridLayout(2, true);
- layout.marginHeight = 0;
- layout.marginWidth = 0;
- buttons.setLayout(layout);
+ GridLayoutFactory.swtDefaults().numColumns(2).equalWidth(true).margins(0, 0).applyTo(buttons);
buttons.setLayoutData(new GridData());
Button mRemoveButton = new Button(buttons, SWT.PUSH);
@@ -178,6 +135,38 @@ public boolean isChecked(Object element) {
.accept((Module) tableViewer.getStructuredSelection().getFirstElement())));
}
+ private static Table createTable(Composite parent) {
+ Table table = new Table(parent, SWT.CHECK | SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
+ table.setLayoutData(new GridData(GridData.FILL_BOTH));
+ table.setHeaderVisible(true);
+ table.setLinesVisible(true);
+
+ TableLayout tableLayout = new TableLayout();
+ table.setLayout(tableLayout);
+
+ TableColumn column1 = new TableColumn(table, SWT.NONE);
+ column1.setAlignment(SWT.CENTER);
+ column1.setText(Messages.CheckConfigurationConfigureDialog_colEnabled);
+ tableLayout.addColumnData(new ColumnWeightData(15));
+
+ TableColumn column2 = new TableColumn(table, SWT.NONE);
+ column2.setText(Messages.CheckConfigurationConfigureDialog_colModule);
+ tableLayout.addColumnData(new ColumnWeightData(30));
+
+ TableColumn column3 = new TableColumn(table, SWT.NONE);
+ column3.setText(Messages.CheckConfigurationConfigureDialog_colSeverity);
+ tableLayout.addColumnData(new ColumnWeightData(20));
+
+ TableColumn column4 = new TableColumn(table, SWT.NONE);
+ column4.setText(Messages.CheckConfigurationConfigureDialog_colComment);
+ tableLayout.addColumnData(new ColumnWeightData(35));
+
+ // by default the table viewer sorts on column 0, but we want to sort by the module label
+ table.setSortColumn(column2);
+
+ return table;
+ }
+
public void refresh() {
tableViewer.refresh();
}
@@ -267,4 +256,24 @@ public IDialogSettings getTableSettings() {
return settings;
}
}
+
+ private static class TableCheckStateProvider implements ICheckStateProvider {
+
+ private final boolean configurable;
+
+ private TableCheckStateProvider(boolean configurable) {
+ this.configurable = configurable;
+ }
+
+ @Override
+ public boolean isGrayed(Object element) {
+ return !configurable;
+ }
+
+ @Override
+ public boolean isChecked(Object element) {
+ Module module = (Module) element;
+ return !Severity.IGNORE.equals(module.getSeverity()) || !module.getMetaData().hasSeverity();
+ }
+ }
}
diff --git a/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/config/configtypes/ExternalFileConfigurationEditor.java b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/config/configtypes/ExternalFileConfigurationEditor.java
index d73c20a73..61add92d7 100644
--- a/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/config/configtypes/ExternalFileConfigurationEditor.java
+++ b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/config/configtypes/ExternalFileConfigurationEditor.java
@@ -28,6 +28,8 @@
import org.apache.commons.lang3.StringUtils;
import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
@@ -93,44 +95,33 @@ public void initialize(CheckConfigurationWorkingCopy checkConfiguration,
@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);
+ GridLayoutFactory gridLayoutFactory = GridLayoutFactory.swtDefaults().numColumns(2).equalWidth(false).margins(0, 0);
+ gridLayoutFactory.applyTo(contents);
Label lblConfigName = new Label(contents, SWT.NULL);
lblConfigName.setText(Messages.CheckConfigurationPropertiesDialog_lblName);
- GridData gridData = new GridData();
- lblConfigName.setLayoutData(gridData);
+ lblConfigName.setLayoutData(new GridData());
mConfigName = new Text(contents, SWT.LEFT | SWT.SINGLE | SWT.BORDER);
- gridData = new GridData(GridData.FILL_HORIZONTAL);
- mConfigName.setLayoutData(gridData);
+ mConfigName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
mConfigName.setFocus();
Label lblConfigLocation = new Label(contents, SWT.NULL);
lblConfigLocation.setText(Messages.CheckConfigurationPropertiesDialog_lblLocation);
- gridData = new GridData();
- lblConfigLocation.setLayoutData(gridData);
+ lblConfigLocation.setLayoutData(new GridData());
Composite locationComposite = new Composite(contents, SWT.NULL);
locationComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- layout = new GridLayout(2, false);
- layout.marginWidth = 0;
- layout.marginHeight = 0;
- locationComposite.setLayout(layout);
+ gridLayoutFactory.applyTo(locationComposite);
mLocation = new Text(locationComposite, SWT.LEFT | SWT.SINGLE | SWT.BORDER);
- gridData = new GridData(GridData.FILL_HORIZONTAL);
- mLocation.setLayoutData(gridData);
+ mLocation.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
mBtnBrowse = new Button(locationComposite, SWT.PUSH);
mBtnBrowse.setText(Messages.FileConfigurationLocationEditor_btnBrowse);
- gridData = new GridData();
- mBtnBrowse.setLayoutData(gridData);
+ mBtnBrowse.setLayoutData(new GridData());
mBtnBrowse.addSelectionListener(new SelectionListener() {
@@ -153,31 +144,19 @@ public void widgetDefaultSelected(SelectionEvent e) {
Label lblDescription = new Label(contents, SWT.NULL);
lblDescription.setText(Messages.CheckConfigurationPropertiesDialog_lblDescription);
- gridData = new GridData();
- gridData.horizontalSpan = 2;
- lblDescription.setLayoutData(gridData);
+ GridDataFactory.swtDefaults().span(2, 1).applyTo(lblDescription);
mDescription = new Text(contents, SWT.LEFT | SWT.WRAP | SWT.MULTI | SWT.BORDER | SWT.VERTICAL);
- gridData = new GridData(GridData.FILL_BOTH);
- gridData.horizontalSpan = 2;
- gridData.widthHint = 300;
- gridData.heightHint = 100;
- gridData.grabExcessHorizontalSpace = true;
- gridData.grabExcessVerticalSpace = true;
- mDescription.setLayoutData(gridData);
+ GridDataFactory.create(GridData.FILL_BOTH).span(2, 1).hint(300, 100).grab(true, true).applyTo(mDescription);
Group advancedGroup = new Group(contents, SWT.NULL);
advancedGroup.setText(Messages.RemoteConfigurationEditor_titleAdvancedOptions);
- gridData = new GridData(GridData.FILL_HORIZONTAL);
- gridData.horizontalSpan = 2;
- advancedGroup.setLayoutData(gridData);
+ GridDataFactory.create(GridData.FILL_HORIZONTAL).span(2, 1).applyTo(advancedGroup);
advancedGroup.setLayout(new GridLayout(2, false));
mChkProtectConfig = new Button(advancedGroup, SWT.CHECK);
mChkProtectConfig.setText(Messages.ExternalFileConfigurationEditor_btnProtectConfigFile);
- gridData = new GridData(GridData.FILL_HORIZONTAL);
- gridData.horizontalSpan = 2;
- mChkProtectConfig.setLayoutData(gridData);
+ GridDataFactory.create(GridData.FILL_HORIZONTAL).span(2, 1).applyTo(mChkProtectConfig);
if (mWorkingCopy.getName() != null) {
mConfigName.setText(mWorkingCopy.getName());
diff --git a/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/config/configtypes/InternalConfigurationEditor.java b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/config/configtypes/InternalConfigurationEditor.java
index c1e37583f..37ab3f681 100644
--- a/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/config/configtypes/InternalConfigurationEditor.java
+++ b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/config/configtypes/InternalConfigurationEditor.java
@@ -25,10 +25,11 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
+import java.util.Optional;
import org.apache.commons.lang3.StringUtils;
+import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
@@ -92,7 +93,6 @@ public void initialize(CheckConfigurationWorkingCopy checkConfiguration,
@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);
@@ -102,17 +102,15 @@ public Control createEditorControl(Composite parent, final Shell shell) {
Label lblConfigName = new Label(contents, SWT.NULL);
lblConfigName.setText(Messages.CheckConfigurationPropertiesDialog_lblName);
- GridData gridData = new GridData();
- lblConfigName.setLayoutData(gridData);
+ lblConfigName.setLayoutData(new GridData());
mConfigName = new Text(contents, SWT.LEFT | SWT.SINGLE | SWT.BORDER);
- gridData = new GridData(GridData.FILL_HORIZONTAL);
- mConfigName.setLayoutData(gridData);
+ mConfigName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
mConfigName.setFocus();
Label lblConfigLocation = new Label(contents, SWT.NULL);
lblConfigLocation.setText(Messages.CheckConfigurationPropertiesDialog_lblLocation);
- gridData = new GridData();
+ GridData gridData = new GridData();
gridData.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING;
lblConfigLocation.setLayoutData(gridData);
@@ -138,39 +136,19 @@ public Control createEditorControl(Composite parent, final Shell shell) {
mBtnImport = new Button(contents, SWT.PUSH);
mBtnImport.setText(Messages.InternalConfigurationEditor_btnImport);
- gridData = new GridData();
- gridData.horizontalSpan = 2;
- gridData.horizontalAlignment = GridData.END;
- mBtnImport.setLayoutData(gridData);
-
- 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);
- fileDialog.setFilterExtensions(new String[] { "*.xml", "*.*" }); //$NON-NLS-1$ //$NON-NLS-2$
-
- String configFileString = fileDialog.open();
- if (configFileString != null && new File(configFileString).exists()) {
- ICheckConfiguration tmpSourceConfig = new CheckConfiguration("dummy", //$NON-NLS-1$
- configFileString, null, new ExternalFileConfigurationType(), true, null, null);
-
- tmpSourceConfig.copyConfiguration(targetConfig);
- }
- } catch (CheckstylePluginException ex) {
- mDialog.setErrorMessage(ex.getLocalizedMessage());
- }
- }
-
- @Override
- public void widgetDefaultSelected(SelectionEvent e) {
- // NOOP
- }
- });
+ GridDataFactory.swtDefaults().span(2, 1).align(GridData.END, GridData.CENTER).applyTo(mBtnImport);
+
+ mBtnImport.addSelectionListener(SelectionListener.widgetSelectedAdapter(
+ event -> promptImportConfigFile(mConfigName.getShell()).ifPresent(configFileString -> {
+ ICheckConfiguration tmpSourceConfig = new CheckConfiguration("dummy",
+ configFileString, null, new ExternalFileConfigurationType(), true, null,
+ null);
+ try {
+ tmpSourceConfig.copyConfiguration(getEditedWorkingCopy());
+ } catch (CheckstylePluginException ex) {
+ mDialog.setErrorMessage(ex.getLocalizedMessage());
+ }
+ })));
if (mWorkingCopy.getName() != null) {
mConfigName.setText(mWorkingCopy.getName());
@@ -185,6 +163,17 @@ public void widgetDefaultSelected(SelectionEvent e) {
return contents;
}
+ private static Optional promptImportConfigFile(Shell shell) {
+ FileDialog fileDialog = new FileDialog(shell);
+ fileDialog.setText(Messages.InternalConfigurationEditor_titleImportDialog);
+ fileDialog.setFilterExtensions(new String[] { "*.xml", "*.*" });
+ String configFileString = fileDialog.open();
+ if (configFileString != null && new File(configFileString).exists()) {
+ return Optional.of(configFileString);
+ }
+ return Optional.empty();
+ }
+
@Override
public CheckConfigurationWorkingCopy getEditedWorkingCopy() throws CheckstylePluginException {
mWorkingCopy.setName(mConfigName.getText());
diff --git a/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/config/configtypes/ProjectConfigurationEditor.java b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/config/configtypes/ProjectConfigurationEditor.java
index 19ee82182..97c9980bb 100644
--- a/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/config/configtypes/ProjectConfigurationEditor.java
+++ b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/config/configtypes/ProjectConfigurationEditor.java
@@ -35,6 +35,7 @@
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionListener;
@@ -115,18 +116,15 @@ public Control createEditorControl(Composite parent, final Shell shell) {
Label lblConfigName = new Label(contents, SWT.NULL);
lblConfigName.setText(Messages.CheckConfigurationPropertiesDialog_lblName);
- GridData gridData = new GridData();
- lblConfigName.setLayoutData(gridData);
+ lblConfigName.setLayoutData(new GridData());
mConfigName = new Text(contents, SWT.LEFT | SWT.SINGLE | SWT.BORDER);
- gridData = new GridData(GridData.FILL_HORIZONTAL);
- mConfigName.setLayoutData(gridData);
+ mConfigName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
mConfigName.setFocus();
Label lblConfigLocation = new Label(contents, SWT.NULL);
lblConfigLocation.setText(Messages.CheckConfigurationPropertiesDialog_lblLocation);
- gridData = new GridData();
- lblConfigLocation.setLayoutData(gridData);
+ lblConfigLocation.setLayoutData(new GridData());
Composite locationComposite = new Composite(contents, SWT.NULL);
locationComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
@@ -136,8 +134,7 @@ public Control createEditorControl(Composite parent, final Shell shell) {
locationComposite.setLayout(layout);
mLocation = new Text(locationComposite, SWT.LEFT | SWT.SINGLE | SWT.BORDER);
- gridData = new GridData(GridData.FILL_HORIZONTAL);
- mLocation.setLayoutData(gridData);
+ mLocation.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
mBtnBrowse = new Button(locationComposite, SWT.PUSH);
mBtnBrowse.setText(Messages.ProjectConfigurationLocationEditor_btnBrowse);
@@ -148,29 +145,20 @@ public Control createEditorControl(Composite parent, final Shell shell) {
Label lblDescription = new Label(contents, SWT.NULL);
lblDescription.setText(Messages.CheckConfigurationPropertiesDialog_lblDescription);
- gridData = new GridData();
- gridData.horizontalSpan = 2;
- lblDescription.setLayoutData(gridData);
+ GridDataFactory.swtDefaults().span(2, 1).applyTo(lblDescription);
mDescription = new Text(contents, SWT.LEFT | SWT.WRAP | SWT.MULTI | SWT.BORDER | SWT.VERTICAL);
- gridData = new GridData(GridData.FILL_BOTH);
- gridData.horizontalSpan = 2;
- gridData.widthHint = 300;
- gridData.heightHint = 100;
- gridData.grabExcessHorizontalSpace = true;
- gridData.grabExcessVerticalSpace = true;
- mDescription.setLayoutData(gridData);
+ GridDataFactory.create(GridData.FILL_BOTH).span(2, 1).hint(300, 100).grab(true, true)
+ .applyTo(mDescription);
Group advancedGroup = new Group(contents, SWT.NULL);
advancedGroup.setText(Messages.RemoteConfigurationEditor_titleAdvancedOptions);
- gridData = new GridData(GridData.FILL_HORIZONTAL);
- gridData.horizontalSpan = 2;
- advancedGroup.setLayoutData(gridData);
+ GridDataFactory.create(GridData.FILL_HORIZONTAL).span(2, 1).applyTo(advancedGroup);
advancedGroup.setLayout(new GridLayout(2, false));
mChkProtectConfig = new Button(advancedGroup, SWT.CHECK);
mChkProtectConfig.setText(Messages.ProjectConfigurationEditor_chkProtectConfigFile);
- gridData = new GridData(GridData.FILL_HORIZONTAL);
+ GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalSpan = 2;
mChkProtectConfig.setLayoutData(gridData);
diff --git a/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/config/configtypes/RemoteConfigurationEditor.java b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/config/configtypes/RemoteConfigurationEditor.java
index b849a11a1..79fef0afd 100644
--- a/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/config/configtypes/RemoteConfigurationEditor.java
+++ b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/config/configtypes/RemoteConfigurationEditor.java
@@ -24,6 +24,8 @@
import java.net.URL;
import org.apache.commons.lang3.StringUtils;
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
@@ -85,89 +87,66 @@ public void initialize(CheckConfigurationWorkingCopy checkConfiguration,
@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);
+ GridLayoutFactory.swtDefaults().numColumns(2).margins(0, 0).applyTo(contents);
Label lblConfigName = new Label(contents, SWT.NULL);
lblConfigName.setText(Messages.CheckConfigurationPropertiesDialog_lblName);
- GridData gridData = new GridData();
- lblConfigName.setLayoutData(gridData);
+ lblConfigName.setLayoutData(new GridData());
mConfigName = new Text(contents, SWT.LEFT | SWT.SINGLE | SWT.BORDER);
- gridData = new GridData(GridData.FILL_HORIZONTAL);
- mConfigName.setLayoutData(gridData);
+ mConfigName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
mConfigName.setFocus();
Label lblConfigLocation = new Label(contents, SWT.NULL);
lblConfigLocation.setText(Messages.CheckConfigurationPropertiesDialog_lblLocation);
- gridData = new GridData();
- gridData.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING;
- lblConfigLocation.setLayoutData(gridData);
+ GridDataFactory.swtDefaults().align(SWT.DEFAULT, SWT.BEGINNING).applyTo(lblConfigLocation);
mLocation = new Text(contents, SWT.LEFT | SWT.SINGLE | SWT.BORDER);
- gridData = new GridData(GridData.FILL_HORIZONTAL);
- mLocation.setLayoutData(gridData);
+ mLocation.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Label lblDescription = new Label(contents, SWT.NULL);
lblDescription.setText(Messages.CheckConfigurationPropertiesDialog_lblDescription);
- gridData = new GridData();
- gridData.horizontalSpan = 2;
- lblDescription.setLayoutData(gridData);
+ GridDataFactory.swtDefaults().span(2, 1).applyTo(lblDescription);
mDescription = new Text(contents, SWT.LEFT | SWT.WRAP | SWT.MULTI | SWT.BORDER | SWT.VERTICAL);
- gridData = new GridData(GridData.FILL_BOTH);
- gridData.horizontalSpan = 2;
- gridData.widthHint = 300;
- gridData.heightHint = 100;
- gridData.grabExcessHorizontalSpace = true;
- gridData.grabExcessVerticalSpace = true;
- mDescription.setLayoutData(gridData);
+ GridDataFactory.create(GridData.FILL_BOTH).span(2, 1).hint(300, 100).grab(true, true).applyTo(mDescription);
Group credentialsGroup = new Group(contents, SWT.NULL);
credentialsGroup.setText(Messages.RemoteConfigurationEditor_titleCredentialsGroup);
- gridData = new GridData(GridData.FILL_HORIZONTAL);
- gridData.horizontalSpan = 2;
- credentialsGroup.setLayoutData(gridData);
+ GridDataFactory.create(GridData.FILL_HORIZONTAL).span(2, 1).applyTo(credentialsGroup);
credentialsGroup.setLayout(new GridLayout(2, false));
Label lblUserName = new Label(credentialsGroup, SWT.NULL);
lblUserName.setText(Messages.RemoteConfigurationEditor_lblUserName);
- gridData = new GridData();
- lblUserName.setLayoutData(gridData);
+ lblUserName.setLayoutData(new GridData());
mUserName = new Text(credentialsGroup, SWT.SINGLE | SWT.BORDER);
- gridData = new GridData();
- gridData.widthHint = 100;
- mUserName.setLayoutData(gridData);
+ GridDataFactory.swtDefaults().hint(100, SWT.DEFAULT).applyTo(mUserName);
Label lblPassword = new Label(credentialsGroup, SWT.NULL);
lblPassword.setText(Messages.RemoteConfigurationEditor_lblPassword);
- gridData = new GridData();
- lblPassword.setLayoutData(gridData);
+ lblPassword.setLayoutData(new GridData());
mPassword = new Text(credentialsGroup, SWT.SINGLE | SWT.BORDER | SWT.PASSWORD);
- gridData = new GridData();
- gridData.widthHint = 100;
- mPassword.setLayoutData(gridData);
+ GridDataFactory.swtDefaults().hint(100, SWT.DEFAULT).applyTo(mPassword);
Group advancedGroup = new Group(contents, SWT.NULL);
advancedGroup.setText(Messages.RemoteConfigurationEditor_titleAdvancedOptions);
- gridData = new GridData(GridData.FILL_HORIZONTAL);
- gridData.horizontalSpan = 2;
- advancedGroup.setLayoutData(gridData);
+ GridDataFactory.create(GridData.FILL_HORIZONTAL).span(2, 1).applyTo(advancedGroup);
advancedGroup.setLayout(new GridLayout(2, false));
mChkCacheConfig = new Button(advancedGroup, SWT.CHECK);
mChkCacheConfig.setText(Messages.RemoteConfigurationEditor_btnCacheRemoteConfig);
- gridData = new GridData(GridData.FILL_HORIZONTAL);
- gridData.horizontalSpan = 2;
- mChkCacheConfig.setLayoutData(gridData);
+ GridDataFactory.create(GridData.FILL_HORIZONTAL).span(2, 1).applyTo(mChkCacheConfig);
+
+ init(shell);
+ return contents;
+ }
+
+ private void init(Shell shell) {
if (mWorkingCopy.getName() != null) {
mConfigName.setText(mWorkingCopy.getName());
}
@@ -178,7 +157,8 @@ public Control createEditorControl(Composite parent, final Shell shell) {
mDescription.setText(mWorkingCopy.getDescription());
}
- mChkCacheConfig.setSelection(Boolean.parseBoolean(mWorkingCopy.getAdditionalData().get(RemoteConfigurationType.KEY_CACHE_CONFIG)));
+ mChkCacheConfig.setSelection(Boolean.parseBoolean(
+ mWorkingCopy.getAdditionalData().get(RemoteConfigurationType.KEY_CACHE_CONFIG)));
if (mWorkingCopy.getLocation() != null) {
try {
@@ -194,8 +174,6 @@ public Control createEditorControl(Composite parent, final Shell shell) {
CheckstyleUIPlugin.errorDialog(shell, ex, true);
}
}
-
- return contents;
}
@Override
diff --git a/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/preferences/CheckstylePreferencePage.java b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/preferences/CheckstylePreferencePage.java
index 8cdc87f68..cb3414407 100644
--- a/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/preferences/CheckstylePreferencePage.java
+++ b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/preferences/CheckstylePreferencePage.java
@@ -20,13 +20,7 @@
package net.sf.eclipsecs.ui.preferences;
-import java.util.Arrays;
import java.util.Collection;
-import java.util.List;
-import java.util.Locale;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
import org.eclipse.core.resources.IProject;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialogWithToggle;
@@ -34,22 +28,14 @@
import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Group;
-import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Link;
-import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
import org.osgi.service.prefs.BackingStoreException;
@@ -57,18 +43,15 @@
import com.puppycrawl.tools.checkstyle.Main;
import net.sf.eclipsecs.core.CheckstylePluginPrefs;
-import net.sf.eclipsecs.core.builder.CheckerFactory;
import net.sf.eclipsecs.core.builder.CheckstyleBuilder;
import net.sf.eclipsecs.core.config.CheckConfigurationFactory;
import net.sf.eclipsecs.core.config.ICheckConfigurationWorkingSet;
import net.sf.eclipsecs.core.util.CheckstylePluginException;
import net.sf.eclipsecs.ui.CheckstyleUIPlugin;
-import net.sf.eclipsecs.ui.CheckstyleUIPluginImages;
import net.sf.eclipsecs.ui.CheckstyleUIPluginPrefs;
import net.sf.eclipsecs.ui.Messages;
import net.sf.eclipsecs.ui.config.CheckConfigurationWorkingSetEditor;
import net.sf.eclipsecs.ui.util.InternalBrowser;
-import net.sf.eclipsecs.ui.util.SWTUtil;
/**
* This class represents a preference page that is contributed to the Preferences dialog.
@@ -80,39 +63,8 @@
*/
public class CheckstylePreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
- private static final String DEFAULT_LANGUAGE = "default";
-
- private static final List SUPPORTED_LANGUAGES = Stream.concat(
- Stream.of(DEFAULT_LANGUAGE),
- Arrays.stream("de,en,es,fi,fr,ja,pt,tr,zh"
- .split(","))
- .sorted())
- .collect(Collectors.toList());
-
- private final PageController mController = new PageController();
-
private final ICheckConfigurationWorkingSet mWorkingSet;
-
- private Combo mRebuildIfNeeded;
-
- private Button mPurgeCacheButton;
-
- private Button mWarnBeforeLosingFilesets;
-
- private Button mIncludeRuleNamesButton;
-
- private Button mIncludeModuleIdButton;
-
- private Button mLimitCheckstyleMarkers;
-
- private Combo mLanguageIf;
-
- private Text mTxtMarkerLimit;
-
- private Button mBackgroundFullBuild;
-
- private CheckConfigurationWorkingSetEditor mWorkingSetEditor;
-
+ private CheckstylePreferencePageGeneralSettings generalSettings;
private boolean mRebuildAll;
/**
@@ -147,12 +99,12 @@ public Control createContents(Composite ancestor) {
//
// Create the general section of the screen.
//
- final Composite generalComposite = createGeneralContents(parentComposite);
+ this.generalSettings = new CheckstylePreferencePageGeneralSettings(parentComposite, SWT.NONE, () -> mRebuildAll = true);
FormData formData = new FormData();
formData.left = new FormAttachment(0);
formData.top = new FormAttachment(0);
formData.right = new FormAttachment(100);
- generalComposite.setLayoutData(formData);
+ generalSettings.setLayoutData(formData);
//
// Create the check configuration section of the screen.
@@ -160,7 +112,7 @@ public Control createContents(Composite ancestor) {
final Composite configComposite = createCheckConfigContents(parentComposite);
formData = new FormData();
formData.left = new FormAttachment(0);
- formData.top = new FormAttachment(generalComposite, 3, SWT.BOTTOM);
+ formData.top = new FormAttachment(generalSettings, 3, SWT.BOTTOM);
formData.right = new FormAttachment(100);
formData.bottom = new FormAttachment(100);
configComposite.setLayoutData(formData);
@@ -184,170 +136,6 @@ private void linkClicked(Event event) {
InternalBrowser.openLinkInExternalBrowser(url);
}
- /**
- * Create the area with the general preference settings.
- *
- * @param parent
- * the parent composite
- * @return the general area
- */
- private Composite createGeneralContents(Composite parent) {
- //
- // Build the composite for the general settings.
- //
- Group generalComposite = new Group(parent, SWT.NULL);
- generalComposite.setText(Messages.CheckstylePreferencePage_lblGeneralSettings);
- GridLayout gridLayout = new GridLayout();
- gridLayout.numColumns = 1;
- generalComposite.setLayout(gridLayout);
-
- final Composite langComposite = new Composite(generalComposite, SWT.NULL);
- gridLayout = new GridLayout(3, false);
- gridLayout.marginHeight = 0;
- gridLayout.marginWidth = 0;
- langComposite.setLayout(gridLayout);
- langComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
-
- final Label lblLanguage = new Label(langComposite, SWT.NULL);
- lblLanguage.setText(Messages.CheckstylePreferencePage_lblLocaleLanguage);
- mLanguageIf = new Combo(langComposite, SWT.READ_ONLY);
- mLanguageIf.setItems(SUPPORTED_LANGUAGES.stream().map(code -> {
- if (code == DEFAULT_LANGUAGE) {
- return code;
- }
- var loc = Locale.forLanguageTag(code);
- return code + " - " + loc.getDisplayLanguage(loc);
- }).toArray(String[]::new));
- final String lang = CheckstylePluginPrefs.getString(CheckstylePluginPrefs.PREF_LOCALE_LANGUAGE);
- final int selectedLang = SUPPORTED_LANGUAGES.indexOf(lang == null || lang.isEmpty() ? DEFAULT_LANGUAGE : lang);
- if (selectedLang != -1) {
- mLanguageIf.select(selectedLang);
- }
-
- //
- // Create a combo with the rebuild options
- //
- final Composite rebuildComposite = new Composite(generalComposite, SWT.NULL);
- gridLayout = new GridLayout(3, false);
- gridLayout.marginHeight = 0;
- gridLayout.marginWidth = 0;
- rebuildComposite.setLayout(gridLayout);
- rebuildComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
-
- Label lblRebuild = new Label(rebuildComposite, SWT.NULL);
- lblRebuild.setText(Messages.CheckstylePreferencePage_lblRebuild);
-
- mRebuildIfNeeded = new Combo(rebuildComposite, SWT.READ_ONLY);
- mRebuildIfNeeded.setItems(new String[] { MessageDialogWithToggle.PROMPT,
- MessageDialogWithToggle.ALWAYS, MessageDialogWithToggle.NEVER });
- mRebuildIfNeeded.select(mRebuildIfNeeded.indexOf(
- CheckstyleUIPluginPrefs.getString(CheckstyleUIPluginPrefs.PREF_ASK_BEFORE_REBUILD)));
-
- //
- // Create button to purge the checker cache
- //
-
- mPurgeCacheButton = new Button(rebuildComposite, SWT.FLAT);
- mPurgeCacheButton
- .setImage(CheckstyleUIPluginImages.REFRESH_ICON.getImage());
- mPurgeCacheButton.setToolTipText(Messages.CheckstylePreferencePage_btnRefreshCheckerCache);
- mPurgeCacheButton.addSelectionListener(mController);
- GridData gridData = new GridData();
- gridData.horizontalAlignment = GridData.END;
- gridData.grabExcessHorizontalSpace = true;
- gridData.heightHint = 20;
- gridData.widthHint = 20;
- mPurgeCacheButton.setLayoutData(gridData);
-
- //
- // Create the "Fileset warning" check box.
- //
- mWarnBeforeLosingFilesets = new Button(generalComposite, SWT.CHECK);
- mWarnBeforeLosingFilesets.setText(Messages.CheckstylePreferencePage_lblWarnFilesets);
- mWarnBeforeLosingFilesets.setSelection(
- CheckstyleUIPluginPrefs.getBoolean(CheckstyleUIPluginPrefs.PREF_FILESET_WARNING));
-
- //
- // Create the "Include rule name" check box.
- //
- final Composite includeRuleNamesComposite = new Composite(generalComposite, SWT.NULL);
- gridLayout = new GridLayout(2, false);
- gridLayout.marginHeight = 0;
- gridLayout.marginWidth = 0;
- includeRuleNamesComposite.setLayout(gridLayout);
-
- mIncludeRuleNamesButton = new Button(includeRuleNamesComposite, SWT.CHECK);
- mIncludeRuleNamesButton.setText(Messages.CheckstylePreferencePage_lblIncludeRulenames);
- mIncludeRuleNamesButton.setSelection(
- CheckstylePluginPrefs.getBoolean(CheckstylePluginPrefs.PREF_INCLUDE_RULE_NAMES));
-
- addRebuildNoteLabel(includeRuleNamesComposite);
-
- //
- // Create the "Include rule name" check box.
- //
- final Composite includeModuleIdComposite = new Composite(generalComposite, SWT.NULL);
- gridLayout = new GridLayout(2, false);
- gridLayout.marginHeight = 0;
- gridLayout.marginWidth = 0;
- includeModuleIdComposite.setLayout(gridLayout);
-
- mIncludeModuleIdButton = new Button(includeModuleIdComposite, SWT.CHECK);
- mIncludeModuleIdButton.setText(Messages.CheckstylePreferencePage_lblIncludeModuleIds);
- mIncludeModuleIdButton.setSelection(
- CheckstylePluginPrefs.getBoolean(CheckstylePluginPrefs.PREF_INCLUDE_MODULE_IDS));
-
- addRebuildNoteLabel(includeModuleIdComposite);
-
- //
- // Create the "limit markers" check box and text field combination
- //
- final Composite limitMarkersComposite = new Composite(generalComposite, SWT.NULL);
- gridLayout = new GridLayout(3, false);
- gridLayout.marginHeight = 0;
- gridLayout.marginWidth = 0;
- limitMarkersComposite.setLayout(gridLayout);
-
- mLimitCheckstyleMarkers = new Button(limitMarkersComposite, SWT.CHECK);
- mLimitCheckstyleMarkers.setText(Messages.CheckstylePreferencePage_lblLimitMarker);
- mLimitCheckstyleMarkers.setSelection(CheckstylePluginPrefs
- .getBoolean(CheckstylePluginPrefs.PREF_LIMIT_MARKERS_PER_RESOURCE));
-
- mTxtMarkerLimit = new Text(limitMarkersComposite, SWT.SINGLE | SWT.BORDER);
- mTxtMarkerLimit.setTextLimit(5);
- SWTUtil.addOnlyDigitInputSupport(mTxtMarkerLimit);
-
- mTxtMarkerLimit.setText(Integer.toString(
- CheckstylePluginPrefs.getInt(CheckstylePluginPrefs.PREF_MARKER_AMOUNT_LIMIT)));
- gridData = new GridData();
- gridData.widthHint = 30;
- mTxtMarkerLimit.setLayoutData(gridData);
-
- addRebuildNoteLabel(limitMarkersComposite);
-
- //
- // Create the "Run Checkstyle in background on full builds" check box.
- //
- final Composite backgroundFullBuildComposite = new Composite(generalComposite, SWT.NULL);
- gridLayout = new GridLayout(2, false);
- gridLayout.marginHeight = 0;
- gridLayout.marginWidth = 0;
- backgroundFullBuildComposite.setLayout(gridLayout);
-
- mBackgroundFullBuild = new Button(backgroundFullBuildComposite, SWT.CHECK);
- mBackgroundFullBuild.setText(Messages.CheckstylePreferencePage_txtBackgroundFullBuild0);
- mBackgroundFullBuild.setSelection(
- CheckstylePluginPrefs.getBoolean(CheckstylePluginPrefs.PREF_BACKGROUND_FULL_BUILD));
- return generalComposite;
- }
-
- private void addRebuildNoteLabel(Composite parent) {
- Label lblRebuildNote = new Label(parent, SWT.NULL);
- lblRebuildNote.setImage(CheckstyleUIPluginImages.HELP_ICON.getImage());
- lblRebuildNote.setToolTipText(Messages.CheckstylePreferencePage_txtSuggestRebuild);
- SWTUtil.addTooltipOnPressSupport(lblRebuildNote);
- }
-
/**
* Creates the content regarding the management of check configurations.
*
@@ -363,7 +151,8 @@ private Composite createCheckConfigContents(Composite parent) {
configComposite.setText(Messages.CheckstylePreferencePage_titleCheckConfigs);
configComposite.setLayout(new FormLayout());
- mWorkingSetEditor = new CheckConfigurationWorkingSetEditor(mWorkingSet, true);
+ CheckConfigurationWorkingSetEditor mWorkingSetEditor = new CheckConfigurationWorkingSetEditor(
+ mWorkingSet, true);
final Control editorControl = mWorkingSetEditor.createContents(configComposite);
FormData formData = new FormData();
formData.left = new FormAttachment(0, 3);
@@ -388,41 +177,43 @@ public boolean performOk() {
mWorkingSet.store();
CheckstylePluginPrefs.setString(CheckstylePluginPrefs.PREF_LOCALE_LANGUAGE,
- SUPPORTED_LANGUAGES.get(mLanguageIf.getSelectionIndex()));
+ generalSettings.getLanguageIf());
//
// Save the general preferences.
//
CheckstyleUIPluginPrefs.setString(CheckstyleUIPluginPrefs.PREF_ASK_BEFORE_REBUILD,
- mRebuildIfNeeded.getItem(mRebuildIfNeeded.getSelectionIndex()));
+ generalSettings.getRebuildIfNeeded());
//
// fileset warning preference
//
- boolean warnFileSetsNow = mWarnBeforeLosingFilesets.getSelection();
+ boolean warnFileSetsNow = generalSettings.getWarnBeforeLosingFilesets();
CheckstyleUIPluginPrefs.setBoolean(CheckstyleUIPluginPrefs.PREF_FILESET_WARNING,
warnFileSetsNow);
//
// Include rule names preference.
//
- boolean includeRuleNamesHasChanged = updateBooleanPreference(mIncludeRuleNamesButton,
- CheckstylePluginPrefs.PREF_INCLUDE_RULE_NAMES);
+ boolean includeRuleNamesHasChanged = updateBooleanPreference(
+ generalSettings.getIncludeRuleNames(), CheckstylePluginPrefs.PREF_INCLUDE_RULE_NAMES);
//
// Include module id preference.
//
- boolean includeModuleIdHasChanged = updateBooleanPreference(mIncludeModuleIdButton,
+ boolean includeModuleIdHasChanged = updateBooleanPreference(
+ generalSettings.getIncludeModuleIdButton(),
CheckstylePluginPrefs.PREF_INCLUDE_MODULE_IDS);
//
// Limit markers preference
//
- boolean limitMarkersHasChanged = updateBooleanPreference(mLimitCheckstyleMarkers,
+ boolean limitMarkersHasChanged = updateBooleanPreference(
+ generalSettings.getLimitCheckstyleMarkers(),
CheckstylePluginPrefs.PREF_LIMIT_MARKERS_PER_RESOURCE);
- int markerLimitNow = Integer.parseInt(mTxtMarkerLimit.getText());
+ int markerLimitNow = Integer.parseInt(generalSettings.getTxtMarkerLimit());
int markerLimitOriginal = CheckstylePluginPrefs
.getInt(CheckstylePluginPrefs.PREF_MARKER_AMOUNT_LIMIT);
CheckstylePluginPrefs.setInt(CheckstylePluginPrefs.PREF_MARKER_AMOUNT_LIMIT, markerLimitNow);
@@ -431,7 +222,7 @@ public boolean performOk() {
//
// Include background build preference.
//
- boolean runInBackgroundNow = mBackgroundFullBuild.getSelection();
+ boolean runInBackgroundNow = generalSettings.getBackgroundFullBuild();
CheckstylePluginPrefs.setBoolean(CheckstylePluginPrefs.PREF_BACKGROUND_FULL_BUILD,
runInBackgroundNow);
@@ -485,12 +276,11 @@ public boolean performOk() {
return true;
}
- private static final boolean updateBooleanPreference(Button button, String preference)
+ private static final boolean updateBooleanPreference(boolean selection, String preference)
throws BackingStoreException {
- boolean now = button.getSelection();
boolean original = CheckstylePluginPrefs.getBoolean(preference);
- CheckstylePluginPrefs.setBoolean(preference, now);
- return now != original;
+ CheckstylePluginPrefs.setBoolean(preference, selection);
+ return selection != original;
}
private boolean needRebuildAllProjects(boolean includeRuleNamesHasChanged,
@@ -499,19 +289,4 @@ private boolean needRebuildAllProjects(boolean includeRuleNamesHasChanged,
return includeRuleNamesHasChanged || includeModuleIdHasChanged || limitMarkersHasChanged
|| markerLimitHasChanged || mRebuildAll;
}
-
- /**
- * Controller for this page.
- *
- */
- private class PageController extends SelectionAdapter {
-
- @Override
- public void widgetSelected(SelectionEvent e) {
- if (mPurgeCacheButton == e.widget) {
- CheckerFactory.cleanup();
- mRebuildAll = true;
- }
- }
- }
}
diff --git a/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/preferences/CheckstylePreferencePageGeneralSettings.java b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/preferences/CheckstylePreferencePageGeneralSettings.java
new file mode 100644
index 000000000..bfabfba6d
--- /dev/null
+++ b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/preferences/CheckstylePreferencePageGeneralSettings.java
@@ -0,0 +1,236 @@
+//============================================================================
+//
+// Copyright (C) 2003-2023 the original author or authors.
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+//============================================================================
+
+package net.sf.eclipsecs.ui.preferences;
+
+import java.util.List;
+import java.util.Locale;
+import org.eclipse.jface.dialogs.MessageDialogWithToggle;
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.layout.GridLayoutFactory;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+
+import net.sf.eclipsecs.core.CheckstylePluginPrefs;
+import net.sf.eclipsecs.core.builder.CheckerFactory;
+import net.sf.eclipsecs.ui.CheckstyleUIPluginImages;
+import net.sf.eclipsecs.ui.CheckstyleUIPluginPrefs;
+import net.sf.eclipsecs.ui.Messages;
+import net.sf.eclipsecs.ui.util.SWTUtil;
+
+public final class CheckstylePreferencePageGeneralSettings extends Composite {
+
+ private static final String DEFAULT_LANGUAGE = "default";
+
+ private static final List SUPPORTED_LANGUAGES = List.of(DEFAULT_LANGUAGE, "de", "en", "es",
+ "fi", "fr", "ja", "pt", "tr", "zh");
+ private static final String[] LANGUAGE_ITEMS = SUPPORTED_LANGUAGES.stream().map(code -> {
+ if (code == DEFAULT_LANGUAGE) {
+ return code;
+ }
+ var loc = Locale.forLanguageTag(code);
+ return code + " - " + loc.getDisplayLanguage(loc);
+ }).toArray(String[]::new);
+
+ private final Combo languageIf;
+ private final Combo mRebuildIfNeeded;
+ private final Button mWarnBeforeLosingFilesets;
+ private final Button mIncludeRuleNamesButton;
+ private final Button mIncludeModuleIdButton;
+ private final Button mLimitCheckstyleMarkers;
+ private final Text mTxtMarkerLimit;
+ private final Button mBackgroundFullBuild;
+
+ public CheckstylePreferencePageGeneralSettings(Composite parent, int style, Runnable setRebuildAll) {
+ super(parent, style);
+ setLayout(new FillLayout());
+
+ Group group = new Group(this, style);
+
+ group.setText(Messages.CheckstylePreferencePage_lblGeneralSettings);
+ group.setLayout(new GridLayout());
+
+ languageIf = createLanguageSetting(group);
+
+ //
+ // Create a combo with the rebuild options
+ //
+ final Composite rebuildComposite = new Composite(group, SWT.NULL);
+ GridLayoutFactory.swtDefaults().numColumns(3).margins(0, 0).applyTo(rebuildComposite);
+ rebuildComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+ Label lblRebuild = new Label(rebuildComposite, SWT.NULL);
+ lblRebuild.setText(Messages.CheckstylePreferencePage_lblRebuild);
+
+ mRebuildIfNeeded = new Combo(rebuildComposite, SWT.READ_ONLY);
+ mRebuildIfNeeded.setItems(new String[] { MessageDialogWithToggle.PROMPT,
+ MessageDialogWithToggle.ALWAYS, MessageDialogWithToggle.NEVER });
+ mRebuildIfNeeded.select(mRebuildIfNeeded.indexOf(
+ CheckstyleUIPluginPrefs.getString(CheckstyleUIPluginPrefs.PREF_ASK_BEFORE_REBUILD)));
+
+ //
+ // Create button to purge the checker cache
+ //
+
+ Button mPurgeCacheButton = new Button(rebuildComposite, SWT.FLAT);
+ mPurgeCacheButton
+ .setImage(CheckstyleUIPluginImages.REFRESH_ICON.getImage());
+ mPurgeCacheButton.setToolTipText(Messages.CheckstylePreferencePage_btnRefreshCheckerCache);
+ mPurgeCacheButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(event -> {
+ CheckerFactory.cleanup();
+ setRebuildAll.run();
+ }));
+ GridDataFactory.swtDefaults().align(GridData.END, GridData.CENTER).grab(true, false)
+ .hint(20, 20).applyTo(mPurgeCacheButton);
+
+ //
+ // Create the "Fileset warning" check box.
+ //
+ mWarnBeforeLosingFilesets = makeButton(group, SWT.CHECK,
+ Messages.CheckstylePreferencePage_lblWarnFilesets,
+ CheckstyleUIPluginPrefs.getBoolean(CheckstyleUIPluginPrefs.PREF_FILESET_WARNING));
+
+ //
+ // Create the "Include rule name" check box.
+ //
+ final Composite includeRuleNamesComposite = new Composite(group, SWT.NULL);
+ GridLayoutFactory.swtDefaults().numColumns(2).margins(0, 0).applyTo(includeRuleNamesComposite);
+
+ mIncludeRuleNamesButton = makeButton(includeRuleNamesComposite, SWT.CHECK,
+ Messages.CheckstylePreferencePage_lblIncludeRulenames,
+ CheckstylePluginPrefs.getBoolean(CheckstylePluginPrefs.PREF_INCLUDE_RULE_NAMES));
+
+ addRebuildNoteLabel(includeRuleNamesComposite);
+
+ //
+ // Create the "Include rule name" check box.
+ //
+ final Composite includeModuleIdComposite = new Composite(group, SWT.NULL);
+ GridLayoutFactory.swtDefaults().numColumns(2).margins(0, 0).applyTo(includeModuleIdComposite);
+
+ mIncludeModuleIdButton = makeButton(includeModuleIdComposite, SWT.CHECK,
+ Messages.CheckstylePreferencePage_lblIncludeModuleIds,
+ CheckstylePluginPrefs.getBoolean(CheckstylePluginPrefs.PREF_INCLUDE_MODULE_IDS));
+
+ addRebuildNoteLabel(includeModuleIdComposite);
+
+ //
+ // Create the "limit markers" check box and text field combination
+ //
+ final Composite limitMarkersComposite = new Composite(group, SWT.NULL);
+ GridLayoutFactory.swtDefaults().numColumns(3).margins(0, 0).applyTo(limitMarkersComposite);
+
+ mLimitCheckstyleMarkers = makeButton(limitMarkersComposite, SWT.CHECK,
+ Messages.CheckstylePreferencePage_lblLimitMarker, CheckstylePluginPrefs
+ .getBoolean(CheckstylePluginPrefs.PREF_LIMIT_MARKERS_PER_RESOURCE));
+
+ mTxtMarkerLimit = new Text(limitMarkersComposite, SWT.SINGLE | SWT.BORDER);
+ mTxtMarkerLimit.setTextLimit(5);
+ SWTUtil.addOnlyDigitInputSupport(mTxtMarkerLimit);
+
+ mTxtMarkerLimit.setText(Integer.toString(
+ CheckstylePluginPrefs.getInt(CheckstylePluginPrefs.PREF_MARKER_AMOUNT_LIMIT)));
+ GridDataFactory.swtDefaults().hint(30, SWT.DEFAULT).applyTo(mTxtMarkerLimit);
+
+ addRebuildNoteLabel(limitMarkersComposite);
+
+ //
+ // Create the "Run Checkstyle in background on full builds" check box.
+ //
+ final Composite backgroundFullBuildComposite = new Composite(group, SWT.NULL);
+ GridLayoutFactory.swtDefaults().numColumns(2).margins(0, 0).applyTo(backgroundFullBuildComposite);
+
+ mBackgroundFullBuild = makeButton(backgroundFullBuildComposite, SWT.CHECK,
+ Messages.CheckstylePreferencePage_txtBackgroundFullBuild0,
+ CheckstylePluginPrefs.getBoolean(CheckstylePluginPrefs.PREF_BACKGROUND_FULL_BUILD));
+ }
+
+ private static Combo createLanguageSetting(Group group) {
+ Composite langComposite = new Composite(group, SWT.NULL);
+ GridLayoutFactory.swtDefaults().numColumns(3).margins(0, 0).applyTo(langComposite);
+ langComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+ final Label lblLanguage = new Label(langComposite, SWT.NULL);
+ lblLanguage.setText(Messages.CheckstylePreferencePage_lblLocaleLanguage);
+ Combo languageIf = new Combo(langComposite, SWT.READ_ONLY);
+ languageIf.setItems(LANGUAGE_ITEMS);
+ final String lang = CheckstylePluginPrefs.getString(CheckstylePluginPrefs.PREF_LOCALE_LANGUAGE);
+ final int selectedLang = SUPPORTED_LANGUAGES.indexOf(lang == null || lang.isEmpty() ? DEFAULT_LANGUAGE : lang);
+ if (selectedLang != -1) {
+ languageIf.select(selectedLang);
+ }
+ return languageIf;
+ }
+
+ private static Button makeButton(Composite parent, int style, String text, boolean selection) {
+ Button button = new Button(parent, style);
+ button.setText(text);
+ button.setSelection(selection);
+ return button;
+ }
+
+ private static void addRebuildNoteLabel(Composite parent) {
+ Label lblRebuildNote = new Label(parent, SWT.NULL);
+ lblRebuildNote.setImage(CheckstyleUIPluginImages.HELP_ICON.getImage());
+ lblRebuildNote.setToolTipText(Messages.CheckstylePreferencePage_txtSuggestRebuild);
+ SWTUtil.addTooltipOnPressSupport(lblRebuildNote);
+ }
+
+ public String getLanguageIf() {
+ return SUPPORTED_LANGUAGES.get(languageIf.getSelectionIndex());
+ }
+
+ public String getRebuildIfNeeded() {
+ return mRebuildIfNeeded.getItem(mRebuildIfNeeded.getSelectionIndex());
+ }
+
+ public boolean getWarnBeforeLosingFilesets() {
+ return mWarnBeforeLosingFilesets.getSelection();
+ }
+
+ public boolean getIncludeRuleNames() {
+ return mIncludeRuleNamesButton.getSelection();
+ }
+
+ public boolean getIncludeModuleIdButton() {
+ return mIncludeModuleIdButton.getSelection();
+ }
+
+ public boolean getLimitCheckstyleMarkers() {
+ return mLimitCheckstyleMarkers.getSelection();
+ }
+
+ public String getTxtMarkerLimit() {
+ return mTxtMarkerLimit.getText();
+ }
+
+ public boolean getBackgroundFullBuild() {
+ return mBackgroundFullBuild.getSelection();
+ }
+}
diff --git a/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/properties/CheckstylePropertyPage.java b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/properties/CheckstylePropertyPage.java
index e33c173f5..8a8b0c5f9 100644
--- a/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/properties/CheckstylePropertyPage.java
+++ b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/properties/CheckstylePropertyPage.java
@@ -26,21 +26,12 @@
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.jface.dialogs.IDialogConstants;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.dialogs.MessageDialogWithToggle;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.layout.FormAttachment;
-import org.eclipse.swt.layout.FormData;
-import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
@@ -58,7 +49,6 @@
import net.sf.eclipsecs.core.util.CheckstyleLog;
import net.sf.eclipsecs.core.util.CheckstylePluginException;
import net.sf.eclipsecs.ui.CheckstyleUIPlugin;
-import net.sf.eclipsecs.ui.CheckstyleUIPluginPrefs;
import net.sf.eclipsecs.ui.Messages;
import net.sf.eclipsecs.ui.config.CheckConfigurationWorkingSetEditor;
@@ -68,21 +58,7 @@
*/
public class CheckstylePropertyPage extends PropertyPage {
- //
- // controls
- //
-
- /** button to enable checkstyle for the project. */
- private Button mChkEnable;
-
- /** button to enable/disable the simple configuration. */
- private Button mChkSimpleConfig;
-
- /** the container holding the file sets editor. */
- private Composite mFileSetsContainer;
-
- /** the editor for the file sets. */
- private IFileSetsEditor mFileSetsEditor;
+ private CheckstylePropertyPageMainTab mainTab;
//
// other members
@@ -97,32 +73,21 @@ public class CheckstylePropertyPage extends PropertyPage {
// methods
//
- /**
- * Returns the project configuration.
- *
- * @return the project configuration
- */
- public ProjectConfigurationWorkingCopy getProjectConfigurationWorkingCopy() {
- return mProjectConfig;
- }
-
@Override
public void setElement(IAdaptable element) {
super.setElement(element);
+ //
+ // Get the project.
+ //
IProject project = null;
- try {
-
- //
- // Get the project.
- //
-
- IResource resource = (IResource) element;
- if (resource.getType() == IResource.PROJECT) {
- project = (IProject) resource;
- }
+ IResource resource = (IResource) element;
+ if (resource.getType() == IResource.PROJECT) {
+ project = (IProject) resource;
+ }
+ try {
IProjectConfiguration projectConfig = ProjectConfigurationFactory.getConfiguration(project);
mProjectConfig = new ProjectConfigurationWorkingCopy(projectConfig);
@@ -149,131 +114,33 @@ private void handleConfigFileError(Exception error, IProject project) {
@Override
public Control createContents(Composite parent) {
-
- Composite container = null;
-
- try {
- // suppress default- & apply-buttons
- noDefaultAndApplyButton();
-
- TabFolder mainTab = new TabFolder(parent, SWT.TOP);
- mainTab.setLayoutData(new GridData(GridData.FILL_BOTH));
- mainTab.addSelectionListener(SelectionListener.widgetSelectedAdapter(event -> {
- mFileSetsEditor.refresh();
- getContainer().updateButtons();
- }));
-
- // create the main container
- container = new Composite(mainTab, SWT.NULL);
- container.setLayout(new FormLayout());
- container.setLayoutData(new GridData(GridData.FILL_BOTH));
-
- // create the checkbox to enable/disable the simple configuration
- this.mChkSimpleConfig = new Button(container, SWT.CHECK);
- this.mChkSimpleConfig.setText(Messages.CheckstylePropertyPage_btnUseSimpleConfig);
- this.mChkSimpleConfig.addSelectionListener(new ChkSimpleConfigController());
- this.mChkSimpleConfig.setSelection(mProjectConfig.isUseSimpleConfig());
-
- FormData formData = new FormData();
- // fd.left = new FormAttachment(this.mChkEnable, 0, SWT.RIGHT);
- formData.top = new FormAttachment(0, 3);
- formData.right = new FormAttachment(100, -3);
- this.mChkSimpleConfig.setLayoutData(formData);
-
- // create the checkbox to enable/disable checkstyle
- this.mChkEnable = new Button(container, SWT.CHECK);
- this.mChkEnable.setText(Messages.CheckstylePropertyPage_btnActivateCheckstyle);
- this.mChkEnable.setSelection(mCheckstyleInitiallyActivated);
-
- formData = new FormData();
- formData.left = new FormAttachment(0, 3);
- formData.top = new FormAttachment(0, 3);
- formData.right = new FormAttachment(this.mChkSimpleConfig, 3, SWT.LEFT);
- this.mChkEnable.setLayoutData(formData);
-
- // create the checkbox for formatter syncing
- Button mChkSyncFormatter = new Button(container, SWT.CHECK);
- mChkSyncFormatter.setText(Messages.CheckstylePropertyPage_btnSyncFormatter);
- mChkSyncFormatter.addSelectionListener(SelectionListener.widgetSelectedAdapter(event -> {
- mProjectConfig.setSyncFormatter(mChkSyncFormatter.getSelection());
- }));
- mChkSyncFormatter.setSelection(mProjectConfig.isSyncFormatter());
-
- formData = new FormData();
- formData.left = new FormAttachment(0, 3);
- formData.top = new FormAttachment(this.mChkEnable, 3, SWT.BOTTOM);
- mChkSyncFormatter.setLayoutData(formData);
-
- // create the configuration area
- mFileSetsContainer = new Composite(container, SWT.NULL);
- final Control configArea = createFileSetsArea(mFileSetsContainer);
- formData = new FormData();
- formData.left = new FormAttachment(0, 3);
- formData.top = new FormAttachment(mChkSyncFormatter, 6, SWT.BOTTOM);
- formData.right = new FormAttachment(100, -3);
- formData.bottom = new FormAttachment(45);
- configArea.setLayoutData(formData);
-
- // create the filter area
- final Control filterArea = new FilterSettings(container, SWT.NONE,
- mProjectConfig.getProject(), mProjectConfig.getFilters(), getContainer()::updateButtons);
- formData = new FormData();
- formData.left = new FormAttachment(0, 3);
- formData.top = new FormAttachment(configArea, 3, SWT.BOTTOM);
- formData.right = new FormAttachment(100, -3);
- formData.bottom = new FormAttachment(100, -3);
- formData.width = 500;
- filterArea.setLayoutData(formData);
-
- // create the local configurations area
- Control localConfigArea = new LocalConfig(mainTab, SWT.NONE,
- mProjectConfig.getLocalCheckConfigWorkingSet());
-
- TabItem mainItem = new TabItem(mainTab, SWT.NULL);
- mainItem.setControl(container);
- mainItem.setText(Messages.CheckstylePropertyPage_tabMain);
-
- TabItem localItem = new TabItem(mainTab, SWT.NULL);
- localItem.setControl(localConfigArea);
- localItem.setText(Messages.CheckstylePropertyPage_tabCheckConfigs);
-
- } catch (CheckstylePluginException ex) {
- CheckstyleUIPlugin.errorDialog(getShell(), Messages.errorOpeningPropertiesPage, ex, true);
- }
-
- return container;
- }
-
- /**
- * Creates the file sets area.
- *
- * @param fileSetsContainer
- * the container to add the file sets area to
- */
- private Control createFileSetsArea(Composite fileSetsContainer) throws CheckstylePluginException {
-
- Control[] controls = fileSetsContainer.getChildren();
- for (int i = 0; i < controls.length; i++) {
- controls[i].dispose();
- }
-
- PropertyPageContext propertyPageContext = new PropertyPageContext((IProject) getElement(),
- getProjectConfigurationWorkingCopy(), getContainer()::updateButtons);
- mFileSetsEditor = FileSetsEditorFactory.createEditor(getShell(), propertyPageContext,
- mProjectConfig.isUseSimpleConfig());
- mFileSetsEditor.setFileSets(mProjectConfig.getFileSets());
-
- final Control editor = mFileSetsEditor.createContents(mFileSetsContainer);
-
- fileSetsContainer.setLayout(new FormLayout());
- FormData formData = new FormData();
- formData.left = new FormAttachment(0);
- formData.top = new FormAttachment(0);
- formData.right = new FormAttachment(100);
- formData.bottom = new FormAttachment(100);
- editor.setLayoutData(formData);
-
- return fileSetsContainer;
+ // suppress default- & apply-buttons
+ noDefaultAndApplyButton();
+
+ TabFolder tabFolder = new TabFolder(parent, SWT.TOP);
+ tabFolder.setLayoutData(new GridData(GridData.FILL_BOTH));
+ tabFolder.addSelectionListener(SelectionListener.widgetSelectedAdapter(event -> {
+ mainTab.refreshFileSetEditor();
+ getContainer().updateButtons();
+ }));
+ this.mainTab = new CheckstylePropertyPageMainTab(tabFolder, SWT.NONE,
+ new PropertyPageContext((IProject) getElement(), mProjectConfig,
+ getContainer()::updateButtons),
+ mCheckstyleInitiallyActivated);
+
+ // create the local configurations area
+ Control localConfigArea = new LocalConfig(tabFolder, SWT.NONE,
+ mProjectConfig.getLocalCheckConfigWorkingSet());
+
+ TabItem mainItem = new TabItem(tabFolder, SWT.NULL);
+ mainItem.setControl(mainTab);
+ mainItem.setText(Messages.CheckstylePropertyPage_tabMain);
+
+ TabItem localItem = new TabItem(tabFolder, SWT.NULL);
+ localItem.setControl(localConfigArea);
+ localItem.setText(Messages.CheckstylePropertyPage_tabCheckConfigs);
+
+ return mainTab;
}
@Override
@@ -303,7 +170,7 @@ public boolean isValid() {
@Override
public boolean performOk() {
return CheckstylePropertyApplyOperation.apply(getShell(), mProjectConfig,
- mChkEnable.getSelection(), mCheckstyleInitiallyActivated);
+ mainTab.isCheckstyleEnabled(), mCheckstyleInitiallyActivated);
}
private static class LocalConfig extends Composite {
@@ -329,47 +196,4 @@ private LocalConfig(Composite parent, int style, ICheckConfigurationWorkingSet w
}
}
-
- private class ChkSimpleConfigController extends SelectionAdapter {
-
- @Override
- public void widgetSelected(SelectionEvent e) {
- try {
- mProjectConfig.setUseSimpleConfig(mChkSimpleConfig.getSelection());
-
- boolean showWarning = CheckstyleUIPluginPrefs
- .getBoolean(CheckstyleUIPluginPrefs.PREF_FILESET_WARNING);
- if (showWarning && mProjectConfig.isUseSimpleConfig()) {
- MessageDialogWithToggle dialog = new MessageDialogWithToggle(getShell(),
- Messages.CheckstylePropertyPage_titleWarnFilesets, null,
- Messages.CheckstylePropertyPage_msgWarnFilesets, MessageDialog.WARNING,
- new String[] { IDialogConstants.OK_LABEL }, 0,
- Messages.CheckstylePropertyPage_mgsWarnFileSetNagOption, showWarning) {
- /**
- * Overwritten because we don't want to store which button the user pressed but the
- * state of the toggle.
- */
- @Override
- protected void buttonPressed(int buttonId) {
- getPrefStore().setValue(getPrefKey(), getToggleState());
- setReturnCode(buttonId);
- close();
- }
-
- };
- dialog.setPrefStore(CheckstyleUIPlugin.getDefault().getPreferenceStore());
- dialog.setPrefKey(CheckstyleUIPluginPrefs.PREF_FILESET_WARNING);
- dialog.open();
-
- }
-
- createFileSetsArea(mFileSetsContainer);
- mFileSetsContainer.redraw();
- mFileSetsContainer.update();
- mFileSetsContainer.layout();
- } catch (CheckstylePluginException ex) {
- CheckstyleUIPlugin.errorDialog(getShell(), Messages.errorChangingFilesetEditor, ex, true);
- }
- }
- }
}
diff --git a/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/properties/CheckstylePropertyPageMainTab.java b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/properties/CheckstylePropertyPageMainTab.java
new file mode 100644
index 000000000..b3844af35
--- /dev/null
+++ b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/properties/CheckstylePropertyPageMainTab.java
@@ -0,0 +1,193 @@
+//============================================================================
+//
+// Copyright (C) 2003-2023 the original author or authors.
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+//============================================================================
+
+package net.sf.eclipsecs.ui.properties;
+
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.dialogs.MessageDialogWithToggle;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+
+import net.sf.eclipsecs.ui.CheckstyleUIPlugin;
+import net.sf.eclipsecs.ui.CheckstyleUIPluginPrefs;
+import net.sf.eclipsecs.ui.Messages;
+
+public final class CheckstylePropertyPageMainTab extends Composite {
+
+ private final PropertyPageContext propertyPageContext;
+ private final Button mChkSimpleConfig;
+ private final Button mChkEnable;
+ private final Composite mFileSetsContainer;
+
+ private IFileSetsEditor mFileSetsEditor;
+
+ public CheckstylePropertyPageMainTab(Composite parent, int style,
+ PropertyPageContext propertyPageContext, boolean mCheckstyleInitiallyActivated) {
+ super(parent, style);
+ this.propertyPageContext = propertyPageContext;
+
+ setLayout(new FormLayout());
+ setLayoutData(new GridData(GridData.FILL_BOTH));
+
+ // create the checkbox to enable/disable the simple configuration
+ this.mChkSimpleConfig = new Button(this, SWT.CHECK);
+ this.mChkSimpleConfig.setText(Messages.CheckstylePropertyPage_btnUseSimpleConfig);
+ this.mChkSimpleConfig.addSelectionListener(new ChkSimpleConfigController());
+ this.mChkSimpleConfig.setSelection(propertyPageContext.configuration().isUseSimpleConfig());
+
+ FormData formData = new FormData();
+ // fd.left = new FormAttachment(this.mChkEnable, 0, SWT.RIGHT);
+ formData.top = new FormAttachment(0, 3);
+ formData.right = new FormAttachment(100, -3);
+ this.mChkSimpleConfig.setLayoutData(formData);
+
+ // create the checkbox to enable/disable checkstyle
+ this.mChkEnable = new Button(this, SWT.CHECK);
+ this.mChkEnable.setText(Messages.CheckstylePropertyPage_btnActivateCheckstyle);
+ this.mChkEnable.setSelection(mCheckstyleInitiallyActivated);
+
+ formData = new FormData();
+ formData.left = new FormAttachment(0, 3);
+ formData.top = new FormAttachment(0, 3);
+ formData.right = new FormAttachment(this.mChkSimpleConfig, 3, SWT.LEFT);
+ this.mChkEnable.setLayoutData(formData);
+
+ // create the checkbox for formatter syncing
+ Button mChkSyncFormatter = new Button(this, SWT.CHECK);
+ mChkSyncFormatter.setText(Messages.CheckstylePropertyPage_btnSyncFormatter);
+ mChkSyncFormatter.addSelectionListener(SelectionListener.widgetSelectedAdapter(event -> {
+ propertyPageContext.configuration().setSyncFormatter(mChkSyncFormatter.getSelection());
+ }));
+ mChkSyncFormatter.setSelection(propertyPageContext.configuration().isSyncFormatter());
+
+ formData = new FormData();
+ formData.left = new FormAttachment(0, 3);
+ formData.top = new FormAttachment(this.mChkEnable, 3, SWT.BOTTOM);
+ mChkSyncFormatter.setLayoutData(formData);
+
+ // create the configuration area
+ mFileSetsContainer = new Composite(this, SWT.NULL);
+ final Control configArea = createFileSetsArea(mFileSetsContainer);
+ formData = new FormData();
+ formData.left = new FormAttachment(0, 3);
+ formData.top = new FormAttachment(mChkSyncFormatter, 6, SWT.BOTTOM);
+ formData.right = new FormAttachment(100, -3);
+ formData.bottom = new FormAttachment(45);
+ configArea.setLayoutData(formData);
+
+ // create the filter area
+ final Control filterArea = new FilterSettings(this, SWT.NONE,
+ propertyPageContext.configuration().getProject(),
+ propertyPageContext.configuration().getFilters(), propertyPageContext.updateButtons());
+ formData = new FormData();
+ formData.left = new FormAttachment(0, 3);
+ formData.top = new FormAttachment(configArea, 3, SWT.BOTTOM);
+ formData.right = new FormAttachment(100, -3);
+ formData.bottom = new FormAttachment(100, -3);
+ formData.width = 500;
+ filterArea.setLayoutData(formData);
+ }
+
+ public boolean isCheckstyleEnabled() {
+ return mChkEnable.getSelection();
+ }
+
+ public void refreshFileSetEditor() {
+ mFileSetsEditor.refresh();
+ }
+
+ /**
+ * Creates the file sets area.
+ *
+ * @param fileSetsContainer
+ * the container to add the file sets area to
+ */
+ private Control createFileSetsArea(Composite fileSetsContainer) {
+ Control[] controls = fileSetsContainer.getChildren();
+ for (int i = 0; i < controls.length; i++) {
+ controls[i].dispose();
+ }
+
+ this.mFileSetsEditor = FileSetsEditorFactory.createEditor(getShell(), propertyPageContext,
+ propertyPageContext.configuration().isUseSimpleConfig());
+ mFileSetsEditor.setFileSets(propertyPageContext.configuration().getFileSets());
+
+ final Control editor = mFileSetsEditor.createContents(mFileSetsContainer);
+
+ fileSetsContainer.setLayout(new FormLayout());
+ FormData formData = new FormData();
+ formData.left = new FormAttachment(0);
+ formData.top = new FormAttachment(0);
+ formData.right = new FormAttachment(100);
+ formData.bottom = new FormAttachment(100);
+ editor.setLayoutData(formData);
+
+ return fileSetsContainer;
+ }
+
+ private class ChkSimpleConfigController extends SelectionAdapter {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ propertyPageContext.configuration().setUseSimpleConfig(mChkSimpleConfig.getSelection());
+
+ boolean showWarning = CheckstyleUIPluginPrefs
+ .getBoolean(CheckstyleUIPluginPrefs.PREF_FILESET_WARNING);
+ if (showWarning && propertyPageContext.configuration().isUseSimpleConfig()) {
+ MessageDialogWithToggle dialog = new MessageDialogWithToggle(getShell(),
+ Messages.CheckstylePropertyPage_titleWarnFilesets, null,
+ Messages.CheckstylePropertyPage_msgWarnFilesets, MessageDialog.WARNING,
+ new String[] { IDialogConstants.OK_LABEL }, 0,
+ Messages.CheckstylePropertyPage_mgsWarnFileSetNagOption, showWarning) {
+ /**
+ * Overwritten because we don't want to store which button the user pressed but the
+ * state of the toggle.
+ */
+ @Override
+ protected void buttonPressed(int buttonId) {
+ getPrefStore().setValue(getPrefKey(), getToggleState());
+ setReturnCode(buttonId);
+ close();
+ }
+
+ };
+ dialog.setPrefStore(CheckstyleUIPlugin.getDefault().getPreferenceStore());
+ dialog.setPrefKey(CheckstyleUIPluginPrefs.PREF_FILESET_WARNING);
+ dialog.open();
+
+ }
+
+ createFileSetsArea(mFileSetsContainer);
+ mFileSetsContainer.redraw();
+ mFileSetsContainer.update();
+ mFileSetsContainer.layout();
+ }
+ }
+}
diff --git a/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/properties/ComplexFileSetsEditor.java b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/properties/ComplexFileSetsEditor.java
index b5d336e3b..446b1a89d 100644
--- a/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/properties/ComplexFileSetsEditor.java
+++ b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/properties/ComplexFileSetsEditor.java
@@ -95,7 +95,7 @@ public List getFileSets() {
}
@Override
- public Control createContents(Composite parent) throws CheckstylePluginException {
+ public Control createContents(Composite parent) {
mComposite = parent;
diff --git a/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/properties/FileMatchPatternTable.java b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/properties/FileMatchPatternTable.java
index 5ffc734e9..51b91ceab 100644
--- a/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/properties/FileMatchPatternTable.java
+++ b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/properties/FileMatchPatternTable.java
@@ -23,6 +23,7 @@
import java.util.List;
import java.util.function.Consumer;
+import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.CheckboxTableViewer;
import org.eclipse.jface.viewers.ColumnWeightData;
@@ -38,7 +39,6 @@
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
@@ -67,10 +67,7 @@ public FileMatchPatternTable(Composite parent, int style, FileMatchPatternTableC
formData.bottom = new FormAttachment(100, -3);
buttons.setLayoutData(formData);
- GridLayout layout = new GridLayout();
- layout.marginHeight = 0;
- layout.marginWidth = 0;
- buttons.setLayout(layout);
+ GridLayoutFactory.swtDefaults().margins(0, 0).applyTo(buttons);
final Table table = new Table(composite, SWT.CHECK | SWT.BORDER | SWT.FULL_SELECTION);
formData = new FormData();
@@ -105,8 +102,7 @@ public FileMatchPatternTable(Composite parent, int style, FileMatchPatternTableC
callbacks.updateMatchView.run();
});
mPatternViewer.addCheckStateListener(event -> {
- if (event.getElement() instanceof FileMatchPattern) {
- FileMatchPattern pattern = (FileMatchPattern) event.getElement();
+ if (event.getElement() instanceof FileMatchPattern pattern) {
pattern.setIsIncludePattern(event.getChecked());
mPatternViewer.refresh();
callbacks.updateMatchView.run();
@@ -117,43 +113,24 @@ public FileMatchPatternTable(Composite parent, int style, FileMatchPatternTableC
// Build the buttons.
//
- Button mAddButton = createPushButton(buttons, Messages.FileSetEditDialog_btnAdd);
- mAddButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(event -> {
- callbacks.addFileMatchPattern.run();
- callbacks.updateMatchView.run();
- }));
-
- Button mEditButton = createPushButton(buttons, Messages.FileSetEditDialog_btnEdit);
- mEditButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(event -> {
- FileMatchPattern pattern = (FileMatchPattern) mPatternViewer.getStructuredSelection()
- .getFirstElement();
- callbacks.editFileMatchPattern.accept(pattern);
- callbacks.updateMatchView.run();
- }));
-
- Button mRemoveButton = createPushButton(buttons, Messages.FileSetEditDialog_btnRemove);
- mRemoveButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(event -> {
- FileMatchPattern pattern = (FileMatchPattern) mPatternViewer.getStructuredSelection()
- .getFirstElement();
- callbacks.removeFileMatchPattern.accept(pattern);
- callbacks.updateMatchView.run();
- }));
-
- Button mUpButton = createPushButton(buttons, Messages.FileSetEditDialog_btnUp);
- mUpButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(event -> {
- FileMatchPattern pattern = (FileMatchPattern) mPatternViewer.getStructuredSelection()
- .getFirstElement();
- callbacks.upFileMatchPattern.accept(pattern);
- callbacks.updateMatchView.run();
- }));
+ createPushButton(buttons, Messages.FileSetEditDialog_btnAdd,
+ callbacks.addFileMatchPattern);
+ createPushButton(buttons, Messages.FileSetEditDialog_btnEdit,
+ toRunnable(callbacks.editFileMatchPattern));
+ createPushButton(buttons, Messages.FileSetEditDialog_btnRemove,
+ toRunnable(callbacks.removeFileMatchPattern));
+ createPushButton(buttons, Messages.FileSetEditDialog_btnUp,
+ toRunnable(callbacks.upFileMatchPattern));
+ createPushButton(buttons, Messages.FileSetEditDialog_btnDown,
+ toRunnable(callbacks.downFileMatchPattern));
+ }
- Button mDownButton = createPushButton(buttons, Messages.FileSetEditDialog_btnDown);
- mDownButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(event -> {
+ private Runnable toRunnable(Consumer callback) {
+ return () -> {
FileMatchPattern pattern = (FileMatchPattern) mPatternViewer.getStructuredSelection()
.getFirstElement();
- callbacks.downFileMatchPattern.accept(pattern);
- callbacks.updateMatchView.run();
- }));
+ callback.accept(pattern);
+ };
}
public void refresh() {
@@ -177,12 +154,14 @@ public void setInput(List fileMatchPatterns) {
* the label for the new button
* @return the newly-created button
*/
- private static Button createPushButton(Composite parent, String label) {
+ private static Button createPushButton(Composite parent, String label, Runnable selectionListener) {
Button button = new Button(parent, SWT.PUSH);
button.setText(label);
GridData data = new GridData();
data.horizontalAlignment = GridData.FILL;
button.setLayoutData(data);
+ button.addSelectionListener(
+ SelectionListener.widgetSelectedAdapter(event -> selectionListener.run()));
return button;
}
diff --git a/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/properties/FileSetEditDialog.java b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/properties/FileSetEditDialog.java
index 6725bf2fa..7db780f8a 100644
--- a/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/properties/FileSetEditDialog.java
+++ b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/properties/FileSetEditDialog.java
@@ -230,6 +230,7 @@ private void addFileMatchPattern() {
fileMatchPatternTable.refresh();
fileMatchPatternTable.setChecked(pattern, pattern.isIncludePattern());
}
+ updateMatchView();
}
private void editFileMatchPattern(FileMatchPattern pattern) {
@@ -250,6 +251,7 @@ private void editFileMatchPattern(FileMatchPattern pattern) {
fileMatchPatternTable.refresh();
fileMatchPatternTable.setChecked(editedPattern, editedPattern.isIncludePattern());
}
+ updateMatchView();
}
private void removeFileMatchPattern(FileMatchPattern pattern) {
@@ -262,6 +264,7 @@ private void removeFileMatchPattern(FileMatchPattern pattern) {
mFileSet.getFileMatchPatterns().remove(pattern);
fileMatchPatternTable.refresh();
+ updateMatchView();
}
private void upFileMatchPattern(FileMatchPattern pattern) {
@@ -278,6 +281,7 @@ private void upFileMatchPattern(FileMatchPattern pattern) {
mFileSet.getFileMatchPatterns().add(index - 1, pattern);
fileMatchPatternTable.refresh();
}
+ updateMatchView();
}
private void downFileMatchPattern(FileMatchPattern pattern) {
@@ -299,6 +303,7 @@ private void downFileMatchPattern(FileMatchPattern pattern) {
fileMatchPatternTable.refresh();
}
+ updateMatchView();
}
private void configureFileSetConfig() {
diff --git a/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/properties/FilterSettings.java b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/properties/FilterSettings.java
index 688cba327..8a067233f 100644
--- a/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/properties/FilterSettings.java
+++ b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/properties/FilterSettings.java
@@ -25,6 +25,7 @@
import org.eclipse.core.resources.IProject;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.CheckboxTableViewer;
+import org.eclipse.jface.viewers.ICheckStateProvider;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.LabelProvider;
@@ -50,29 +51,24 @@
public class FilterSettings extends Composite {
- private final IProject project;
-
public FilterSettings(Composite parent, int style, IProject project, List filters,
Runnable markDirty) {
super(parent, style);
- this.project = project;
-
setLayout(new FillLayout());
- // group composite containing the filter settings
- Group filterArea = new Group(this, SWT.NULL);
- filterArea.setText(Messages.CheckstylePropertyPage_titleFilterGroup);
+ Group group = new Group(this, style);
- filterArea.setLayout(new FormLayout());
+ group.setText(Messages.CheckstylePropertyPage_titleFilterGroup);
+ group.setLayout(new FormLayout());
- Button btnEditFilter = new Button(filterArea, SWT.PUSH);
+ Button btnEditFilter = new Button(group, SWT.PUSH);
FormData formData = new FormData();
formData.left = new FormAttachment(0, 3);
formData.top = new FormAttachment(0, 3);
formData.right = new FormAttachment(btnEditFilter, -3, SWT.LEFT);
formData.bottom = new FormAttachment(60, -3);
- CheckboxTableViewer filterList = CheckboxTableViewer.newCheckList(filterArea, SWT.BORDER);
+ CheckboxTableViewer filterList = createFilterList(group, project);
filterList.getTable().setLayoutData(formData);
formData = new FormData();
@@ -81,7 +77,7 @@ public FilterSettings(Composite parent, int style, IProject project, List {
+ if (event.getStructuredSelection().getFirstElement() instanceof IFilter filterDef) {
+ txtFilterDescription.setText(filterDef.getDescription());
+ // activate edit button
+ btnEditFilter.setEnabled(PluginFilterEditors.hasEditor(filterDef));
+ }
+ });
- if (element instanceof IFilter) {
+ btnEditFilter.setText(Messages.CheckstylePropertyPage_btnChangeFilter);
+ btnEditFilter.addSelectionListener(SelectionListener.widgetSelectedAdapter(event -> {
+ openFilterEditor(filterList.getSelection(), filterList, project);
+ markDirty.run();
+ }));
- IFilter filter = (IFilter) element;
+ // intialize filter list
+ filterList.setInput(filters);
- buf.append(filter.getName());
- if (filter.getPresentableFilterData() != null) {
- buf.append(": ").append(filter.getPresentableFilterData()); //$NON-NLS-1$
- }
- } else {
- buf.append(super.getText(element));
- }
+ btnEditFilter.setEnabled(false);
+ }
- return buf.toString();
- }
- });
+ private CheckboxTableViewer createFilterList(Group group, IProject project) {
+ CheckboxTableViewer filterList = CheckboxTableViewer.newCheckList(group, SWT.BORDER);
+ filterList.setLabelProvider(new FilterListLabelProvider());
filterList.setContentProvider(new ArrayContentProvider());
- filterList.addSelectionChangedListener(event -> {
- if (event.getSelection() instanceof IStructuredSelection selection) {
- if (selection.getFirstElement() instanceof IFilter filterDef) {
- txtFilterDescription.setText(filterDef.getDescription());
- // activate edit button
- btnEditFilter.setEnabled(PluginFilterEditors.hasEditor(filterDef));
- }
- }
- });
- filterList.addDoubleClickListener(event -> openFilterEditor(event.getSelection(), filterList));
+ filterList.setCheckStateProvider(new FilterListCheckStateProvider());
+ filterList.addDoubleClickListener(event -> openFilterEditor(event.getSelection(), filterList, project));
filterList.addCheckStateListener(event -> {
if (event.getElement() instanceof IFilter filter) {
if (filter.isReadonly()) {
@@ -140,31 +129,7 @@ public String getText(Object element) {
}
}
});
-
- btnEditFilter.setText(Messages.CheckstylePropertyPage_btnChangeFilter);
- btnEditFilter.addSelectionListener(SelectionListener.widgetSelectedAdapter(event -> {
- ISelection selection = filterList.getSelection();
- openFilterEditor(selection, filterList);
- markDirty.run();
- }));
-
- // intialize filter list
- List filterDefs = filters;
- filterList.setInput(filterDefs);
-
- // set the checked state
- for (int i = 0; i < filterDefs.size(); i++) {
- IFilter filter = filterDefs.get(i);
- filterList.setChecked(filter, filter.isEnabled());
- }
-
- // set the readonly state
- for (int i = 0; i < filterDefs.size(); i++) {
- IFilter filter = filterDefs.get(i);
- filterList.setGrayed(filter, filter.isReadonly());
- }
-
- btnEditFilter.setEnabled(false);
+ return filterList;
}
/**
@@ -173,7 +138,7 @@ public String getText(Object element) {
* @param selection
* the selection
*/
- private void openFilterEditor(ISelection selection, CheckboxTableViewer filterList) {
+ private void openFilterEditor(ISelection selection, CheckboxTableViewer filterList, IProject project) {
if (selection instanceof IStructuredSelection) {
Object selectedElement = ((IStructuredSelection) selection).getFirstElement();
@@ -202,4 +167,34 @@ private void openFilterEditor(ISelection selection, CheckboxTableViewer filterLi
}
}
}
+
+ private static class FilterListLabelProvider extends LabelProvider {
+ @Override
+ public String getText(Object element) {
+ StringBuilder buf = new StringBuilder();
+ if (element instanceof IFilter filter) {
+ buf.append(filter.getName());
+ if (filter.getPresentableFilterData() != null) {
+ buf.append(": ").append(filter.getPresentableFilterData());
+ }
+ } else {
+ buf.append(super.getText(element));
+ }
+ return buf.toString();
+ }
+ }
+
+ private static class FilterListCheckStateProvider implements ICheckStateProvider {
+
+ @Override
+ public boolean isChecked(Object element) {
+ return ((IFilter) element).isEnabled();
+ }
+
+ @Override
+ public boolean isGrayed(Object element) {
+ return ((IFilter) element).isReadonly();
+ }
+
+ }
}
diff --git a/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/properties/IFileSetsEditor.java b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/properties/IFileSetsEditor.java
index cbbb62808..da8f6b7af 100644
--- a/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/properties/IFileSetsEditor.java
+++ b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/properties/IFileSetsEditor.java
@@ -26,7 +26,6 @@
import org.eclipse.swt.widgets.Control;
import net.sf.eclipsecs.core.projectconfig.FileSet;
-import net.sf.eclipsecs.core.util.CheckstylePluginException;
/**
* Interface for the part of the checkstyle plugin properties page that
@@ -40,20 +39,16 @@ public interface IFileSetsEditor {
* @param parent
* the parent component
* @return the control
- * @throws CheckstylePluginException
- * error while creating and initializing the control
*/
- Control createContents(Composite parent) throws CheckstylePluginException;
+ Control createContents(Composite parent);
/**
* Set the file sets for the editor.
*
* @param fileSets
* the list of file sets
- * @throws CheckstylePluginException
- * an unexpected exception occurred
*/
- void setFileSets(List fileSets) throws CheckstylePluginException;
+ void setFileSets(List fileSets);
/**
* Returns the file sets.
diff --git a/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/properties/SimpleFileSetsEditor.java b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/properties/SimpleFileSetsEditor.java
index 26656793c..afe562833 100644
--- a/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/properties/SimpleFileSetsEditor.java
+++ b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/properties/SimpleFileSetsEditor.java
@@ -91,7 +91,7 @@ public SimpleFileSetsEditor(Shell shell, PropertyPageContext propertyPageContext
}
@Override
- public void setFileSets(List fileSets) throws CheckstylePluginException {
+ public void setFileSets(List fileSets) {
mFileSets = fileSets;
ICheckConfiguration config = null;
@@ -108,7 +108,11 @@ public void setFileSets(List fileSets) throws CheckstylePluginException
}
mDefaultFileSet = new FileSet(Messages.SimpleFileSetsEditor_nameAllFileset, config);
- mDefaultFileSet.getFileMatchPatterns().add(new FileMatchPattern(".")); //$NON-NLS-1$
+ try {
+ mDefaultFileSet.getFileMatchPatterns().add(new FileMatchPattern("."));
+ } catch (CheckstylePluginException ex) {
+ // impossible
+ }
mFileSets.clear();
mFileSets.add(mDefaultFileSet);
}
@@ -119,7 +123,7 @@ public List getFileSets() {
}
@Override
- public Control createContents(Composite parent) throws CheckstylePluginException {
+ public Control createContents(Composite parent) {
mController = new Controller();
diff --git a/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/quickfixes/misc/ArrayTypeStyleQuickfix.java b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/quickfixes/misc/ArrayTypeStyleQuickfix.java
index f39e707dd..623f73fda 100644
--- a/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/quickfixes/misc/ArrayTypeStyleQuickfix.java
+++ b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/quickfixes/misc/ArrayTypeStyleQuickfix.java
@@ -48,152 +48,158 @@ public class ArrayTypeStyleQuickfix extends AbstractASTResolution {
@Override
protected ASTVisitor handleGetCorrectingASTVisitor(final IRegion lineInfo,
final int markerStartOffset) {
+ return new ArrayTypeStyleQuickfixAstVisitor(markerStartOffset);
+ }
- return new ASTVisitor() {
+ @Override
+ public String getDescription() {
+ return Messages.ArrayTypeStyleQuickfix_description;
+ }
- @Override
- public boolean visit(VariableDeclarationStatement node) {
+ @Override
+ public String getLabel() {
+ return Messages.ArrayTypeStyleQuickfix_label;
+ }
- if (containsPosition(node, markerStartOffset)) {
+ @Override
+ public Image getImage() {
+ return CheckstyleUIPluginImages.CORRECTION_CHANGE.getImage();
+ }
- if (isCStyle(node.fragments())) {
+ private class ArrayTypeStyleQuickfixAstVisitor extends ASTVisitor {
+ private final int markerStartOffset;
- int dimensions = 0;
+ private ArrayTypeStyleQuickfixAstVisitor(int markerStartOffset) {
+ this.markerStartOffset = markerStartOffset;
+ }
- List> fragments = node.fragments();
- for (int i = 0, size = fragments.size(); i < size; i++) {
- VariableDeclaration decl = (VariableDeclaration) fragments.get(i);
- if (decl.getExtraDimensions() > dimensions) {
- dimensions = decl.getExtraDimensions();
+ @Override
+ public boolean visit(VariableDeclarationStatement node) {
- }
- decl.setExtraDimensions(0);
- }
+ if (containsPosition(node, markerStartOffset)) {
- // wrap current type into ArrayType
- ArrayType arrayType = createArrayType(node.getType(), dimensions);
- node.setType(arrayType);
+ if (isCStyle(node.fragments())) {
- } else if (isJavaStyle(node.getType())) {
+ int dimensions = 0;
- int dimensions = ((ArrayType) node.getType()).getDimensions();
+ List> fragments = node.fragments();
+ for (int i = 0, size = fragments.size(); i < size; i++) {
+ VariableDeclaration decl = (VariableDeclaration) fragments.get(i);
+ if (decl.getExtraDimensions() > dimensions) {
+ dimensions = decl.getExtraDimensions();
- List> fragments = node.fragments();
- for (int i = 0, size = fragments.size(); i < size; i++) {
- VariableDeclaration decl = (VariableDeclaration) fragments.get(i);
- decl.setExtraDimensions(dimensions);
}
+ decl.setExtraDimensions(0);
+ }
+
+ // wrap current type into ArrayType
+ ArrayType arrayType = createArrayType(node.getType(), dimensions);
+ node.setType(arrayType);
+
+ } else if (isJavaStyle(node.getType())) {
+
+ int dimensions = ((ArrayType) node.getType()).getDimensions();
- Type elementType = (Type) ASTNode.copySubtree(node.getAST(),
- ((ArrayType) node.getType()).getElementType());
- node.setType(elementType);
+ List> fragments = node.fragments();
+ for (int i = 0, size = fragments.size(); i < size; i++) {
+ VariableDeclaration decl = (VariableDeclaration) fragments.get(i);
+ decl.setExtraDimensions(dimensions);
}
+
+ Type elementType = (Type) ASTNode.copySubtree(node.getAST(),
+ ((ArrayType) node.getType()).getElementType());
+ node.setType(elementType);
}
- return true;
}
+ return true;
+ }
- @Override
- public boolean visit(SingleVariableDeclaration node) {
+ @Override
+ public boolean visit(SingleVariableDeclaration node) {
- if (containsPosition(node, markerStartOffset)) {
- if (isCStyle(node)) {
- // wrap the existing type into an array type
- node.setType(createArrayType(node.getType(), node.getExtraDimensions()));
- node.setExtraDimensions(0);
- } else if (isJavaStyle(node.getType())) {
+ if (containsPosition(node, markerStartOffset)) {
+ if (isCStyle(node)) {
+ // wrap the existing type into an array type
+ node.setType(createArrayType(node.getType(), node.getExtraDimensions()));
+ node.setExtraDimensions(0);
+ } else if (isJavaStyle(node.getType())) {
- ArrayType arrayType = (ArrayType) node.getType();
- Type elementType = (Type) ASTNode.copySubtree(node.getAST(),
- arrayType.getElementType());
+ ArrayType arrayType = (ArrayType) node.getType();
+ Type elementType = (Type) ASTNode.copySubtree(node.getAST(),
+ arrayType.getElementType());
- node.setType(elementType);
- node.setExtraDimensions(arrayType.getDimensions());
- }
+ node.setType(elementType);
+ node.setExtraDimensions(arrayType.getDimensions());
}
-
- return true;
}
- @Override
- public boolean visit(FieldDeclaration node) {
+ return true;
+ }
- if (containsPosition(node, markerStartOffset)) {
+ @Override
+ public boolean visit(FieldDeclaration node) {
- if (isCStyle(node.fragments())) {
+ if (containsPosition(node, markerStartOffset)) {
- int dimensions = 0;
+ if (isCStyle(node.fragments())) {
- List> fragments = node.fragments();
- for (int i = 0, size = fragments.size(); i < size; i++) {
- VariableDeclaration decl = (VariableDeclaration) fragments.get(i);
- if (decl.getExtraDimensions() > dimensions) {
- dimensions = decl.getExtraDimensions();
+ int dimensions = 0;
- }
- decl.setExtraDimensions(0);
- }
+ List> fragments = node.fragments();
+ for (int i = 0, size = fragments.size(); i < size; i++) {
+ VariableDeclaration decl = (VariableDeclaration) fragments.get(i);
+ if (decl.getExtraDimensions() > dimensions) {
+ dimensions = decl.getExtraDimensions();
- // wrap current type into ArrayType
- ArrayType arrayType = createArrayType(node.getType(), dimensions);
- node.setType(arrayType);
- } else if (isJavaStyle(node.getType())) {
+ }
+ decl.setExtraDimensions(0);
+ }
- int dimensions = ((ArrayType) node.getType()).getDimensions();
+ // wrap current type into ArrayType
+ ArrayType arrayType = createArrayType(node.getType(), dimensions);
+ node.setType(arrayType);
+ } else if (isJavaStyle(node.getType())) {
- List> fragments = node.fragments();
- for (int i = 0, size = fragments.size(); i < size; i++) {
- VariableDeclaration decl = (VariableDeclaration) fragments.get(i);
- decl.setExtraDimensions(dimensions);
- }
+ int dimensions = ((ArrayType) node.getType()).getDimensions();
- Type elementType = (Type) ASTNode.copySubtree(node.getAST(),
- ((ArrayType) node.getType()).getElementType());
- node.setType(elementType);
+ List> fragments = node.fragments();
+ for (int i = 0, size = fragments.size(); i < size; i++) {
+ VariableDeclaration decl = (VariableDeclaration) fragments.get(i);
+ decl.setExtraDimensions(dimensions);
}
+
+ Type elementType = (Type) ASTNode.copySubtree(node.getAST(),
+ ((ArrayType) node.getType()).getElementType());
+ node.setType(elementType);
}
- return true;
}
+ return true;
+ }
- private boolean isJavaStyle(Type type) {
- return type instanceof ArrayType;
- }
+ private boolean isJavaStyle(Type type) {
+ return type instanceof ArrayType;
+ }
- private boolean isCStyle(VariableDeclaration decl) {
- return decl.getExtraDimensions() > 0;
- }
+ private boolean isCStyle(VariableDeclaration decl) {
+ return decl.getExtraDimensions() > 0;
+ }
- private boolean isCStyle(List> fragments) {
+ private boolean isCStyle(List> fragments) {
- Iterator> iter = fragments.iterator();
- while (iter.hasNext()) {
- VariableDeclaration decl = (VariableDeclaration) iter.next();
- if (isCStyle(decl)) {
- return true;
- }
+ Iterator> iter = fragments.iterator();
+ while (iter.hasNext()) {
+ VariableDeclaration decl = (VariableDeclaration) iter.next();
+ if (isCStyle(decl)) {
+ return true;
}
- return false;
}
+ return false;
+ }
- private ArrayType createArrayType(Type componentType, int dimensions) {
- Type type = (Type) ASTNode.copySubtree(componentType.getAST(), componentType);
- return componentType.getAST().newArrayType(type, dimensions);
- }
- };
- }
-
- @Override
- public String getDescription() {
- return Messages.ArrayTypeStyleQuickfix_description;
- }
-
- @Override
- public String getLabel() {
- return Messages.ArrayTypeStyleQuickfix_label;
- }
-
- @Override
- public Image getImage() {
- return CheckstyleUIPluginImages.CORRECTION_CHANGE.getImage();
+ private ArrayType createArrayType(Type componentType, int dimensions) {
+ Type type = (Type) ASTNode.copySubtree(componentType.getAST(), componentType);
+ return componentType.getAST().newArrayType(type, dimensions);
+ }
}
}
diff --git a/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/stats/views/internal/CheckstyleMarkerFilterDialog.java b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/stats/views/internal/CheckstyleMarkerFilterDialog.java
index 037053b5e..8dbe11cbb 100644
--- a/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/stats/views/internal/CheckstyleMarkerFilterDialog.java
+++ b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/stats/views/internal/CheckstyleMarkerFilterDialog.java
@@ -27,8 +27,9 @@
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.TitleAreaDialog;
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.viewers.ArrayContentProvider;
-import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.ListViewer;
import org.eclipse.jface.window.Window;
@@ -87,7 +88,7 @@ public class CheckstyleMarkerFilterDialog extends TitleAreaDialog {
private Button mChkSeverityInfo;
- private Composite mFilterComposite;
+ private Group mFilterComposite;
private Group mGrpRegex;
@@ -145,7 +146,6 @@ public CheckstyleMarkerFilter getFilter() {
@Override
protected Control createDialogArea(Composite parent) {
-
Composite composite = (Composite) super.createDialogArea(parent);
Composite dialog = new Composite(composite, SWT.NONE);
@@ -157,111 +157,91 @@ protected Control createDialogArea(Composite parent) {
mChkFilterEnabled.addSelectionListener(
SelectionListener.widgetSelectedAdapter(event -> updateControlState()));
- Group onResourceGroup = new Group(dialog, SWT.NULL);
- onResourceGroup.setText(Messages.CheckstyleMarkerFilterDialog_groupResourceSetting);
- onResourceGroup.setLayout(new GridLayout(3, false));
- onResourceGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- mFilterComposite = onResourceGroup;
-
- mRadioOnAnyResource = new Button(onResourceGroup, SWT.RADIO);
- mRadioOnAnyResource.setText(Messages.CheckstyleMarkerFilterDialog_btnOnAnyResource);
- GridData gridData = new GridData();
- gridData.horizontalSpan = 3;
- mRadioOnAnyResource.setLayoutData(gridData);
-
- mRadioAnyResourceInSameProject = new Button(onResourceGroup, SWT.RADIO);
- mRadioAnyResourceInSameProject
- .setText(Messages.CheckstyleMarkerFilterDialog_btnOnAnyResourceInSameProject);
- gridData = new GridData();
- gridData.horizontalSpan = 3;
- mRadioAnyResourceInSameProject.setLayoutData(gridData);
-
- mRadioSelectedResource = new Button(onResourceGroup, SWT.RADIO);
- mRadioSelectedResource.setText(Messages.CheckstyleMarkerFilterDialog_btnOnSelectedResource);
- gridData = new GridData();
- gridData.horizontalSpan = 3;
- mRadioSelectedResource.setLayoutData(gridData);
-
- mRadioSelectedResourceAndChildren = new Button(onResourceGroup, SWT.RADIO);
+ mFilterComposite = new Group(dialog, SWT.NULL);
+ mFilterComposite.setText(Messages.CheckstyleMarkerFilterDialog_groupResourceSetting);
+ mFilterComposite.setLayout(new GridLayout(3, false));
+ mFilterComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+ mRadioOnAnyResource = createButton(mFilterComposite, SWT.RADIO,
+ Messages.CheckstyleMarkerFilterDialog_btnOnAnyResource,
+ GridDataFactory.swtDefaults().span(3, 1));
+
+ mRadioAnyResourceInSameProject = createButton(mFilterComposite, SWT.RADIO,
+ Messages.CheckstyleMarkerFilterDialog_btnOnAnyResourceInSameProject,
+ GridDataFactory.swtDefaults().span(3, 1));
+
+ mRadioSelectedResource = createButton(mFilterComposite, SWT.RADIO,
+ Messages.CheckstyleMarkerFilterDialog_btnOnSelectedResource,
+ GridDataFactory.swtDefaults().span(3, 1));
+
+ mRadioSelectedResourceAndChildren = new Button(mFilterComposite, SWT.RADIO);
mRadioSelectedResourceAndChildren
.setText(Messages.CheckstyleMarkerFilterDialog_btnOnSelectedResourceAndChilds);
- gridData = new GridData();
- gridData.horizontalSpan = 3;
- mRadioSelectedResourceAndChildren.setLayoutData(gridData);
+ GridDataFactory.swtDefaults().span(3, 1).applyTo(mRadioSelectedResourceAndChildren);
- mRadioSelectedWorkingSet = new Button(onResourceGroup, SWT.RADIO);
- mRadioSelectedWorkingSet.setText(Messages.CheckstyleMarkerFilterDialog_btnOnWorkingSet);
- mRadioSelectedWorkingSet.setLayoutData(new GridData());
+ mRadioSelectedWorkingSet = createButton(mFilterComposite, SWT.RADIO,
+ Messages.CheckstyleMarkerFilterDialog_btnOnWorkingSet, GridDataFactory.swtDefaults());
- mLblSelectedWorkingSet = new Label(onResourceGroup, SWT.NULL);
+ mLblSelectedWorkingSet = new Label(mFilterComposite, SWT.NULL);
mLblSelectedWorkingSet.setLayoutData(
new GridData(GridData.FILL_HORIZONTAL | GridData.HORIZONTAL_ALIGN_BEGINNING));
- mBtnWorkingSet = new Button(onResourceGroup, SWT.PUSH);
- mBtnWorkingSet.setText(Messages.CheckstyleMarkerFilterDialog_btnSelect);
- gridData = new GridData();
- gridData.horizontalSpan = 1;
- gridData.verticalSpan = 2;
- mBtnWorkingSet.setLayoutData(gridData);
+ mBtnWorkingSet = createButton(mFilterComposite, SWT.PUSH,
+ Messages.CheckstyleMarkerFilterDialog_btnSelect,
+ GridDataFactory.swtDefaults().span(1, 2));
mBtnWorkingSet.addSelectionListener(mController);
- Composite severityGroup = new Composite(onResourceGroup, SWT.NULL);
- GridLayout layout = new GridLayout(4, false);
- layout.marginWidth = 0;
- severityGroup.setLayout(layout);
- gridData = new GridData(GridData.FILL_HORIZONTAL);
- gridData.horizontalSpan = 3;
- severityGroup.setLayoutData(gridData);
-
- mChkSeverityEnabled = new Button(severityGroup, SWT.CHECK);
- mChkSeverityEnabled.setText(Messages.CheckstyleMarkerFilterDialog_btnMarkerSeverity);
- mChkSeverityEnabled.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ Composite severityGroup = new Composite(mFilterComposite, SWT.NULL);
+ GridLayoutFactory.swtDefaults().numColumns(4).margins(0, 5).applyTo(severityGroup);
+ GridDataFactory.create(GridData.FILL_HORIZONTAL).span(3, 1).applyTo(severityGroup);
+
+ mChkSeverityEnabled = createButton(severityGroup, SWT.CHECK,
+ Messages.CheckstyleMarkerFilterDialog_btnMarkerSeverity,
+ GridDataFactory.create(GridData.FILL_HORIZONTAL));
mChkSeverityEnabled.addSelectionListener(
SelectionListener.widgetSelectedAdapter(event -> updateControlState()));
- mChkSeverityError = new Button(severityGroup, SWT.CHECK);
- mChkSeverityError.setText(Messages.CheckstyleMarkerFilterDialog_btnSeverityError);
- mChkSeverityError.setLayoutData(new GridData());
+ mChkSeverityError = createButton(severityGroup, SWT.CHECK,
+ Messages.CheckstyleMarkerFilterDialog_btnSeverityError, GridDataFactory.swtDefaults());
- mChkSeverityWarning = new Button(severityGroup, SWT.CHECK);
- mChkSeverityWarning.setText(Messages.CheckstyleMarkerFilterDialog_btnSeverityWarning);
- mChkSeverityWarning.setLayoutData(new GridData());
+ mChkSeverityWarning = createButton(severityGroup, SWT.CHECK,
+ Messages.CheckstyleMarkerFilterDialog_btnSeverityWarning, GridDataFactory.swtDefaults());
- mChkSeverityInfo = new Button(severityGroup, SWT.CHECK);
- mChkSeverityInfo.setText(Messages.CheckstyleMarkerFilterDialog_btnSeverityInfo);
- mChkSeverityInfo.setLayoutData(new GridData());
+ mChkSeverityInfo = createButton(severityGroup, SWT.CHECK,
+ Messages.CheckstyleMarkerFilterDialog_btnSeverityInfo, GridDataFactory.swtDefaults());
mGrpRegex = new Group(dialog, SWT.NULL);
mGrpRegex.setText(Messages.CheckstyleMarkerFilterDialog_lblExcludeMarkers);
- layout = new GridLayout(3, false);
- mGrpRegex.setLayout(layout);
- gridData = new GridData(GridData.FILL_HORIZONTAL);
- mGrpRegex.setLayoutData(gridData);
+ mGrpRegex.setLayout(new GridLayout(3, false));
+ mGrpRegex.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- mChkSelectByRegex = new Button(mGrpRegex, SWT.CHECK);
- mChkSelectByRegex.setText(Messages.CheckstyleMarkerFilterDialog_lblRegex);
- mChkSelectByRegex.setLayoutData(new GridData());
+ mChkSelectByRegex = createButton(mGrpRegex, SWT.CHECK,
+ Messages.CheckstyleMarkerFilterDialog_lblRegex, GridDataFactory.swtDefaults());
mLblRegexFilter = new Label(mGrpRegex, SWT.NULL);
- gridData = new GridData(GridData.FILL_HORIZONTAL);
- gridData.widthHint = 100;
- mLblRegexFilter.setLayoutData(gridData);
+ GridDataFactory.create(GridData.FILL_HORIZONTAL).hint(100, SWT.DEFAULT).applyTo(mLblRegexFilter);
- mBtnEditRegex = new Button(mGrpRegex, SWT.PUSH);
- mBtnEditRegex.setText(Messages.CheckstyleMarkerFilterDialog_btnEdit);
- mBtnEditRegex.setLayoutData(new GridData());
+ mBtnEditRegex = createButton(mGrpRegex, SWT.PUSH, Messages.CheckstyleMarkerFilterDialog_btnEdit,
+ GridDataFactory.swtDefaults());
mBtnEditRegex.addSelectionListener(mController);
// init the controls
updateUIFromFilter();
- this.setTitleImage(CheckstyleUIPluginImages.PLUGIN_LOGO.getImage());
- this.setTitle(Messages.CheckstyleMarkerFilterDialog_title);
- this.setMessage(Messages.CheckstyleMarkerFilterDialog_titleMessage);
+ setTitleImage(CheckstyleUIPluginImages.PLUGIN_LOGO.getImage());
+ setTitle(Messages.CheckstyleMarkerFilterDialog_title);
+ setMessage(Messages.CheckstyleMarkerFilterDialog_titleMessage);
return composite;
}
+ private static Button createButton(Composite parent, int style, String text, GridDataFactory gridDataFactory) {
+ Button button = new Button(parent, style);
+ button.setText(text);
+ gridDataFactory.applyTo(button);
+ return button;
+ }
+
@Override
protected void createButtonsForButtonBar(Composite parent) {
@@ -508,52 +488,13 @@ protected Control createDialogArea(Composite parent) {
controls.setLayout(layout);
controls.setLayoutData(new GridData(GridData.FILL_BOTH));
- final Composite buttons = new Composite(main, SWT.NONE);
- layout = new GridLayout(1, false);
- layout.marginHeight = 0;
- layout.marginWidth = 0;
- buttons.setLayout(layout);
- buttons.setLayoutData(new GridData(GridData.FILL_VERTICAL));
+ createButtons(main);
mRegexText = new Text(controls, SWT.LEFT | SWT.SINGLE | SWT.BORDER);
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.grabExcessHorizontalSpace = true;
mRegexText.setLayoutData(gridData);
- mAddButton = new Button(buttons, SWT.PUSH);
- mAddButton.setText(Messages.CheckstyleMarkerFilterDialog_btnAdd);
- gridData = new GridData(GridData.FILL_HORIZONTAL);
- gridData.verticalAlignment = SWT.TOP;
- mAddButton.setLayoutData(gridData);
- mAddButton.addSelectionListener(new SelectionListener() {
-
- @Override
- public void widgetSelected(SelectionEvent e) {
- String text = mRegexText.getText();
- if (text.trim().length() > 0) {
-
- try {
- // check for the patterns validity
- Pattern.compile(text);
-
- mFileTypesList.add(text);
- mListViewer.refresh();
- mRegexText.setText(""); //$NON-NLS-1$
-
- } catch (PatternSyntaxException ex) {
- RegexDialog.this.setErrorMessage(
- NLS.bind(Messages.CheckstyleMarkerFilterDialog_msgInvalidRegex,
- ex.getLocalizedMessage()));
- }
- }
- }
-
- @Override
- public void widgetDefaultSelected(SelectionEvent e) {
- // NOOP
- }
- });
-
mListViewer = new ListViewer(controls, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
mListViewer.setLabelProvider(new LabelProvider());
mListViewer.setContentProvider(new ArrayContentProvider());
@@ -564,26 +505,6 @@ public void widgetDefaultSelected(SelectionEvent e) {
gridData.grabExcessHorizontalSpace = true;
mListViewer.getControl().setLayoutData(gridData);
- mRemoveButton = new Button(buttons, SWT.PUSH);
- mRemoveButton.setText(Messages.CheckstyleMarkerFilterDialog_btnRemove);
- gridData = new GridData(GridData.FILL_HORIZONTAL);
- gridData.verticalAlignment = SWT.TOP;
- mRemoveButton.setLayoutData(gridData);
- mRemoveButton.addSelectionListener(new SelectionListener() {
-
- @Override
- public void widgetSelected(SelectionEvent e) {
- IStructuredSelection selection = (IStructuredSelection) mListViewer.getSelection();
- mFileTypesList.remove(selection.getFirstElement());
- mListViewer.refresh();
- }
-
- @Override
- public void widgetDefaultSelected(SelectionEvent e) {
- // NOOP
- }
- });
-
// integrate content assist
RegexCompletionProposalFactory.createForText(mRegexText);
@@ -593,6 +514,41 @@ public void widgetDefaultSelected(SelectionEvent e) {
return main;
}
+ private Composite createButtons(Composite parent) {
+ final Composite buttons = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout(1, false);
+ layout.marginHeight = 0;
+ layout.marginWidth = 0;
+ buttons.setLayout(layout);
+ buttons.setLayoutData(new GridData(GridData.FILL_VERTICAL));
+
+ mAddButton = new Button(buttons, SWT.PUSH);
+ mAddButton.setText(Messages.CheckstyleMarkerFilterDialog_btnAdd);
+ GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
+ gridData.verticalAlignment = SWT.TOP;
+ mAddButton.setLayoutData(gridData);
+ mAddButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(event -> {
+ String text = mRegexText.getText();
+ if (text.trim().length() > 0 && checkPatternValidity(text)) {
+ mFileTypesList.add(text);
+ mListViewer.refresh();
+ mRegexText.setText("");
+ }
+ }));
+
+ mRemoveButton = new Button(buttons, SWT.PUSH);
+ mRemoveButton.setText(Messages.CheckstyleMarkerFilterDialog_btnRemove);
+ gridData = new GridData(GridData.FILL_HORIZONTAL);
+ gridData.verticalAlignment = SWT.TOP;
+ mRemoveButton.setLayoutData(gridData);
+ mRemoveButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(event -> {
+ mFileTypesList.remove(mListViewer.getStructuredSelection().getFirstElement());
+ mListViewer.refresh();
+ }));
+
+ return buttons;
+ }
+
@Override
protected void okPressed() {
super.okPressed();
@@ -606,5 +562,16 @@ protected void configureShell(Shell shell) {
super.configureShell(shell);
shell.setText(Messages.CheckstyleMarkerFilterDialog_titleRegexEditor);
}
+
+ private boolean checkPatternValidity(String text) {
+ try {
+ Pattern.compile(text);
+ return true;
+ } catch (PatternSyntaxException ex) {
+ RegexDialog.this.setErrorMessage(NLS.bind(
+ Messages.CheckstyleMarkerFilterDialog_msgInvalidRegex, ex.getLocalizedMessage()));
+ return false;
+ }
+ }
}
}