Skip to content

Commit

Permalink
SLE-365 Change link label + expand/collapse + perf
Browse files Browse the repository at this point in the history
  • Loading branch information
henryju committed Jul 22, 2020
1 parent 6a2ed51 commit f5d59b0
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
import org.eclipse.swtbot.swt.finder.SWTBot;
import org.eclipse.swtbot.swt.finder.waits.ICondition;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotLink;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
import org.junit.After;
import org.junit.Test;
import org.sonarlint.eclipse.its.bots.JavaPackageExplorerBot;
import org.sonarlint.eclipse.its.bots.OnTheFlyViewBot;
Expand All @@ -44,6 +46,15 @@

public class RulesConfigurationTest extends AbstractSonarLintTest {

@After
public void cleanup() {
try {
bot.shell("Preferences").close();
} catch (Exception e) {
// Ignore
}
}

@Test
public void deactivate_rule() throws Exception {
SwtBotUtils.openPerspective(bot, JavaUI.ID_PERSPECTIVE);
Expand Down Expand Up @@ -75,7 +86,7 @@ public void deactivate_rule() throws Exception {
checkIssueChanged(project);

openComplexityRule();
bot.link().click();
paramRestoreDefaultLink().click();
bot.button("Apply").click();
JobHelpers.waitForJobsToComplete(bot);
bot.activeShell().close();
Expand Down Expand Up @@ -130,11 +141,11 @@ public void ruleParametersActivationRoundTrip() {
public void defaultLinkVisibilityRoundTrip() {
bot.getFinder().setShouldFindInvisibleControls(true);
openComplexityRule();
assertThat(bot.link().isVisible()).isFalse();
assertThat(paramRestoreDefaultLink().isVisible()).isFalse();
bot.spinner().setSelection(10);
assertThat(bot.link().isVisible()).isTrue();
assertThat(paramRestoreDefaultLink().isVisible()).isTrue();
bot.spinner().setSelection(15);
assertThat(bot.link().isVisible()).isFalse();
assertThat(paramRestoreDefaultLink().isVisible()).isFalse();
bot.activeShell().close();
}

Expand All @@ -156,6 +167,10 @@ public void open_rules_configuration() {
bot.button("Cancel").click();
}

private SWTBotLink paramRestoreDefaultLink() {
return bot.link("<a>Restore defaults</a>");
}

void openRulesConfiguration() {
bot.menu("Window").menu("Preferences").click();
bot.shell("Preferences").activate();
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ public final class SonarLintImages {
public static final ImageDescriptor DEBUG = createImageDescriptor("debug.gif"); //$NON-NLS-1$
public static final ImageDescriptor SHOW_CONSOLE = createImageDescriptor("showConsole.gif"); //$NON-NLS-1$

public static final ImageDescriptor IMG_EXPAND_ALL = createImageDescriptor("full/tool16/expandall.png"); //$NON-NLS-1$
public static final ImageDescriptor IMG_COLLAPSE_ALL = createImageDescriptor("full/tool16/collapseall.png"); //$NON-NLS-1$

private SonarLintImages() {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public RuleParameterPanel(Composite parent, int style, StandaloneRuleDetails sel
this.selectedRuleMetadata = selectedRuleMetadata;
this.selectedRuleConfig = selectedRuleConfig;
this.setLayout(new GridLayout());
Group group = new Group(this, SWT.SHADOW_NONE);
Group group = new Group(this, SWT.LEFT);
group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
group.setText("Parameters");
GridLayout groupLayout = new GridLayout();
Expand All @@ -60,7 +60,7 @@ public RuleParameterPanel(Composite parent, int style, StandaloneRuleDetails sel
group.setLayout(groupLayout);

defaultLink = new Link(group, SWT.NONE);
defaultLink.setText("<a>Defaults</a>");
defaultLink.setText("<a>Restore defaults</a>");
defaultLink.setToolTipText("Restore default parameters values");
defaultLink.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false));
defaultLink.setEnabled(selectedRuleConfig.isActive());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.eclipse.jface.action.GroupMarker;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.CheckStateChangedEvent;
import org.eclipse.jface.viewers.CheckboxTreeViewer;
Expand All @@ -48,15 +49,21 @@
import org.eclipse.jface.viewers.ViewerComparator;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.dialogs.FilteredTree;
import org.eclipse.ui.dialogs.PatternFilter;
import org.sonarlint.eclipse.core.internal.preferences.RuleConfig;
import org.sonarlint.eclipse.ui.internal.SonarLintImages;
import org.sonarlint.eclipse.ui.internal.util.SonarLintRuleBrowser;
import org.sonarsource.sonarlint.core.client.api.common.RuleDetails;
import org.sonarsource.sonarlint.core.client.api.standalone.StandaloneRuleDetails;
Expand Down Expand Up @@ -111,7 +118,14 @@ protected void createControls(Composite parent) {
}

private void createFilterPart(Composite parent) {
ComboViewer combo = new ComboViewer(parent, SWT.READ_ONLY);
Composite composite = new Composite(parent, SWT.NONE);
composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
GridLayout layout = new GridLayout(2, false);
layout.marginHeight = 0;
layout.marginWidth = 0;
layout.horizontalSpacing = 40;
composite.setLayout(layout);
ComboViewer combo = new ComboViewer(composite, SWT.READ_ONLY);
combo.setContentProvider(ArrayContentProvider.getInstance());
combo.setLabelProvider(new LabelProvider() {
@Override
Expand All @@ -132,6 +146,30 @@ public String getText(Object element) {
}
};
combo.addSelectionChangedListener(selectionChangedListener);

ToolBar toolbar = new ToolBar(composite, SWT.FLAT);
toolbar.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
createExpansionItem(toolbar, true, SonarLintImages.IMG_EXPAND_ALL, "Expand all");
createExpansionItem(toolbar, false, SonarLintImages.IMG_COLLAPSE_ALL, "Collapse all");
}

private ToolItem createExpansionItem(ToolBar toolBar, final boolean expand, ImageDescriptor image, String tooltip) {
ToolItem item = new ToolItem(toolBar, SWT.PUSH);
final Image createdImage = image.createImage();
item.setImage(createdImage);
item.setToolTipText(tooltip);
item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (expand) {
tree.getViewer().expandAll();
} else {
tree.getViewer().collapseAll();
}
}
});
item.addDisposeListener(e -> createdImage.dispose());
return item;
}

private void createTreeViewer(Composite parent) {
Expand Down Expand Up @@ -262,23 +300,23 @@ public boolean isGrayed(Object element) {
if (element instanceof String) {
String language = (String) element;
boolean foundActive = false;
boolean foundInActive = false;
boolean foundInactive = false;
for (RuleDetailsWrapper wrapper : ruleDetailsWrappersByLanguage.get(language)) {
if (!filter.isRuleMatch(wrapper)) {
continue;
}
if (wrapper.ruleConfig.isActive()) {
foundActive = true;
} else {
foundInActive = true;
foundInactive = true;
}

// stop scanning after found both kinds
if (foundActive && foundInActive) {
break;
if (foundActive && foundInactive) {
return true;
}
}
return foundActive == foundInActive;
return foundActive == foundInactive;
}
return false;
}
Expand Down Expand Up @@ -436,6 +474,7 @@ private void setActiveForSelection(boolean isActive) {
while (iterator.hasNext()) {
setActiveForElement(iterator.next(), isActive);
}
tree.getViewer().refresh();
Object currentSelection = selection.getFirstElement();
refreshUiForRuleSelection(currentSelection);
}
Expand All @@ -444,11 +483,9 @@ private void setActiveForElement(Object element, boolean isActive) {
if (element instanceof RuleDetailsWrapper) {
RuleDetailsWrapper wrapper = (RuleDetailsWrapper) element;
wrapper.ruleConfig.setActive(isActive);
tree.getViewer().refresh(element);
} else if (element instanceof String) {
String language = (String) element;
ruleDetailsWrappersByLanguage.get(language).stream().forEach(w -> w.ruleConfig.setActive(isActive));
tree.getViewer().refresh();
}
}

Expand Down

0 comments on commit f5d59b0

Please sign in to comment.