<commit_before>/*******************************************************************************
 * Copyright (c) 2008 The Eclipse Foundation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *    The Eclipse Foundation - initial API and implementation
 *******************************************************************************/
package org.eclipse.epp.usagedata.internal.ui.preview;

import org.eclipse.epp.usagedata.internal.recording.filtering.PreferencesBasedFilter;
import org.eclipse.jface.dialogs.IInputValidator;
import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Shell;

public class AddFilterDialog {

	private final PreferencesBasedFilter filter;

	public AddFilterDialog(PreferencesBasedFilter filter) {
		this.filter = filter;
	}

	public void prompt(Shell shell, String suggestion) {
		InputDialog dialog = new InputDialog(shell, "New filter", "Provide a bundle name pattern. Bundles ids that match this pattern will not be uploaded.",suggestion, getValidator());
		dialog.open();
		if (dialog.getReturnCode() != SWT.OK) return;
		
		filter.addPattern(dialog.getValue().trim());
	}

	IInputValidator getValidator() {
		return new IInputValidator() {
			public String isValid(String pattern) {
				if (pattern == null) return null;
				if (pattern.trim().length() == 0) return null;
				if (alreadyHasPattern(pattern)) return "You are already filtering this pattern.";
				if (!isValidBundleIdPattern(pattern)) return "The pattern is not valid.";
				return null;
			}
		};
	}

	boolean alreadyHasPattern(String pattern) {
		return filter.includesPattern(pattern);
	}

	boolean isValidBundleIdPattern(String pattern) {
		return pattern.matches("[[a-zA-Z0-9\\*]*?\\.]*?\\.[a-zA-Z0-9\\*]+");
	}
}<commit_msg>Modified pattern used for matching bundle symbolic names; now using the right value when checking the dialog's return code.<commit_after>/*******************************************************************************
 * Copyright (c) 2008 The Eclipse Foundation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *    The Eclipse Foundation - initial API and implementation
 *******************************************************************************/
package org.eclipse.epp.usagedata.internal.ui.preview;

import org.eclipse.epp.usagedata.internal.recording.filtering.PreferencesBasedFilter;
import org.eclipse.jface.dialogs.IInputValidator;
import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Shell;

public class AddFilterDialog {

	private final PreferencesBasedFilter filter;

	public AddFilterDialog(PreferencesBasedFilter filter) {
		this.filter = filter;
	}

	public void prompt(Shell shell, String suggestion) {
		InputDialog dialog = new InputDialog(shell, "New filter", "Provide a bundle name pattern. Bundles ids that match this pattern will not be uploaded.",suggestion, getValidator());
		dialog.open();
		if (dialog.getReturnCode() != InputDialog.OK) return;
		
		filter.addPattern(dialog.getValue().trim());
	}

	IInputValidator getValidator() {
		return new IInputValidator() {
			public String isValid(String pattern) {
				if (pattern == null) return null;
				if (pattern.trim().length() == 0) return null;
				if (alreadyHasPattern(pattern)) return "You are already filtering this pattern.";
				if (!isValidBundleIdPattern(pattern)) return "The pattern is not valid.";
				return null;
			}
		};
	}

	boolean alreadyHasPattern(String pattern) {
		return filter.includesPattern(pattern);
	}

	boolean isValidBundleIdPattern(String pattern) {
		return pattern.matches("[a-zA-Z0-9\\*]*?(\\.[a-zA-Z0-9\\*]+?)*?");
	}
}
{'fraction_non_alphanumeric': 0.1802919708029197, 'fraction_numerical': 0.006326034063260341, 'mean_word_length': 5.019033674963397, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4946078', 'n_tokens_mistral': 1204, 'n_tokens_neox': 1079, 'n_words': 320}