Skip to content

Commit

Permalink
Create directory dialog option for loading the custom rules
Browse files Browse the repository at this point in the history
Signed-off-by: Enri Ozuni <enriozuni@hotmail.com>
  • Loading branch information
enriozuni committed Jan 17, 2021
1 parent e6c37fe commit ec3142e
Showing 1 changed file with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,18 @@
import org.eclipse.swt.custom.TableEditor;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
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.DirectoryDialog;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.osgi.service.prefs.BackingStoreException;
Expand All @@ -52,6 +55,7 @@ public class StaticAnalyzerPreferences extends PreferenceListener {
private Button analyseDependenciesCheckBox;
private Button addNewRulesetButton, selectCustomRulesCheckBox;
private CheckboxTableViewer table;
private Button customRulesButton;

private Combo CGSelection;
private Combo forbidden;
Expand Down Expand Up @@ -253,6 +257,44 @@ public void handleEvent(Event e) {
addNewRuleset();
}
});

final Text text = new Text(staticAnalysisGroup, SWT.BORDER);
GridData data = new GridData(GridData.FILL_HORIZONTAL);
data.horizontalSpan = 4;
text.setLayoutData(data);
customRulesButton = new Button(staticAnalysisGroup, SWT.PUSH);
customRulesButton.setText("Browse custom rules directory");
customRulesButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
DirectoryDialog dlg = new DirectoryDialog(staticAnalysisGroup.getShell());

// Set the initial filter path according
// to anything they've selected or typed in
dlg.setFilterPath(text.getText());

// Change the title bar text
dlg.setText("SWT's DirectoryDialog");

// Customizable message displayed in the dialog
dlg.setMessage("Select a directory");

// Calling open() will open and run the dialog.
// It will return the selected directory, or
// null if user cancels
String dir = dlg.open();
if (dir != null) {
// Set the text box to the new selection
text.setText(dir);
if (ArtifactUtils.downloadRulesets(dir)) {
Activator.getDefault().logInfo("Rulesets updated.");
}
Ruleset newRuleset = new Ruleset(dir);
modifyRulesTable(newRuleset);
listOfRulesets.add(newRuleset);
}
}
});

selectCustomRulesCheckBox = new Button(staticAnalysisGroup, SWT.CHECK);
selectCustomRulesCheckBox.setText("Select Custom Rules");
selectCustomRulesCheckBox.addListener(SWT.Selection, new Listener() {
Expand Down

0 comments on commit ec3142e

Please sign in to comment.