Skip to content

Commit

Permalink
Update #32 Using only one instance of image for the preferences tables
Browse files Browse the repository at this point in the history
Old use of ImageFactory for enabled and disabled buttons was causing
optimisation problem because exceeding SWT's threads handlers numbers.
  • Loading branch information
Omar WALDMANN committed Jul 5, 2017
1 parent 0043a1d commit 190298c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,19 @@ public class CheckerMetricTableViewer {

private LanguagePreferencesContainer language;
private List<CheckerPreferencesContainer> inputs;
private Image infoImage;
private Image warningImage;
private Image enabledImage;
private Image errorImage;
private Image disabledImage;

public CheckerMetricTableViewer(Composite parent, List<CheckerPreferencesContainer> checkers) {
this.inputs = checkers;
infoImage = ImageFactory.getImage(ImageFactory.INFO_SMALL);
warningImage = ImageFactory.getImage(ImageFactory.WARNING_SMALL);
errorImage = ImageFactory.getImage(ImageFactory.ERROR_SMALL);
enabledImage = ImageFactory.getImage(ImageFactory.ENABLED);
disabledImage = ImageFactory.getImage(ImageFactory.DISABLED);
GridLayout layout = new GridLayout(2, false);
parent.setLayout(layout);
Label searchLabel = new Label(parent, SWT.NONE);
Expand Down Expand Up @@ -96,9 +106,9 @@ public Image getImage(Object element) {
Image image;
CheckerPreferencesContainer checker = (CheckerPreferencesContainer) element;
if (checker.isChecked()) {
image = ImageFactory.getImage(ImageFactory.ENABLED);
image = enabledImage;
} else {
image = ImageFactory.getImage(ImageFactory.DISABLED);
image = disabledImage;
}
return image;
}
Expand Down Expand Up @@ -181,14 +191,14 @@ public Image getImage(Object element) {
Image severityImage;
switch (checker.getSeverity()) {
case UserPreferencesService.PREF_SEVERITY_ERROR_VALUE:
severityImage = ImageFactory.getImage(ImageFactory.ERROR_SMALL);
severityImage = errorImage;
break;
case UserPreferencesService.PREF_SEVERITY_WARNING_VALUE:
severityImage = ImageFactory.getImage(ImageFactory.WARNING_SMALL);
severityImage = warningImage;
break;
case UserPreferencesService.PREF_SEVERITY_INFO_VALUE:
default:
severityImage = ImageFactory.getImage(ImageFactory.INFO_SMALL);
severityImage = infoImage;
break;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public class CheckerTableViewer {
private Image infoImage;
private Image warningImage;
private Image errorImage;
private Image enabledImage;
private Image disabledImage;

private LanguagePreferencesContainer language;
private List<CheckerPreferencesContainer> inputs;

Expand All @@ -43,6 +46,8 @@ public CheckerTableViewer(Composite parent, List<CheckerPreferencesContainer> ch
infoImage = ImageFactory.getImage(ImageFactory.INFO_SMALL);
warningImage = ImageFactory.getImage(ImageFactory.WARNING_SMALL);
errorImage = ImageFactory.getImage(ImageFactory.ERROR_SMALL);
enabledImage = ImageFactory.getImage(ImageFactory.ENABLED);
disabledImage = ImageFactory.getImage(ImageFactory.DISABLED);
GridLayout layout = new GridLayout(2, false);
parent.setLayout(layout);
Label searchLabel = new Label(parent, SWT.NONE);
Expand Down Expand Up @@ -95,6 +100,7 @@ private void createColumns(Composite parent, TableViewer pCheckersTableViewer) {
TableViewerColumn col = createEnabledViewerColumn(bounds[0], 0);
col.setEditingSupport(new EnabledEditingSupport(pCheckersTableViewer));
col.setLabelProvider(new ColumnLabelProvider() {

@Override
public String getText(Object element) {
return null;
Expand All @@ -105,9 +111,9 @@ public Image getImage(Object element) {
Image image;
CheckerPreferencesContainer checker = (CheckerPreferencesContainer) element;
if (checker.isChecked()) {
image = ImageFactory.getImage(ImageFactory.ENABLED);
image = enabledImage;
} else {
image = ImageFactory.getImage(ImageFactory.DISABLED);
image = disabledImage;
}
return image;
}
Expand Down

0 comments on commit 190298c

Please sign in to comment.