<commit_before>/*
 *  Copyright 2008 Anuradha.
 * 
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 * 
 *       http://www.apache.org/licenses/LICENSE-2.0
 * 
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */

/*
 * QueryEditor.java
 *
 * Created on Jun 19, 2008, 8:43:12 AM
 */
package org.netbeans.cubeon.local.query.ui;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import javax.swing.DefaultListModel;
import javax.swing.JComponent;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.netbeans.cubeon.local.query.LocalQuery;
import org.netbeans.cubeon.local.repository.LocalTaskPriorityProvider;
import org.netbeans.cubeon.local.repository.LocalTaskRepository;
import org.netbeans.cubeon.local.repository.LocalTaskStatusProvider;
import org.netbeans.cubeon.local.repository.LocalTaskTypeProvider;
import org.netbeans.cubeon.tasks.spi.task.TaskStatus;
import org.netbeans.cubeon.tasks.spi.task.TaskType;
import org.netbeans.cubeon.tasks.spi.task.TaskPriority;
import org.netbeans.cubeon.tasks.spi.query.TaskQuery;
import org.netbeans.cubeon.tasks.spi.query.TaskQuerySupportProvider;
import org.openide.util.NbBundle;

/**
 *
 * @author Anuradha
 */
public class QueryEditor extends javax.swing.JPanel implements TaskQuerySupportProvider.ConfigurationHandler {

    private LocalTaskRepository repository;
    private LocalQuery localQuery;
    private final String TAG_ALL = "All";

    /** Creates new form QueryEditor */
    public QueryEditor(TaskQuery query, LocalTaskRepository repository) {

        this.repository = repository;
        initComponents();
        loadAttributes(repository);
        if (query != null) {
            this.localQuery = query.getLookup().lookup(LocalQuery.class);
            txtName.setEditable(false);
        } else {
            this.localQuery = repository.getQuerySupport().createTaskQuery();
        }
        loadTaskQuery(this.localQuery);

    }

    private void loadTaskQuery(LocalQuery query) {
        txtName.setText(query.getName());
        List<TaskPriority> priorities = query.getPriorities();
        for (TaskPriority tp : priorities) {
            lstPriority.setSelectedValue(tp, false);
        }
        if (priorities.size() == 0) {
            lstPriority.setSelectedValue(TAG_ALL, false);
        }

        List<TaskType> types = query.getTypes();
        for (TaskType type : types) {
            lstType.setSelectedValue(type, false);
        }
        if (types.size() == 0) {
            lstType.setSelectedValue(TAG_ALL, false);
        }
        List<TaskStatus> status = query.getStates();
        for (TaskStatus ts : status) {
            lstStatus.setSelectedValue(ts, false);
        }
        if (status.size() == 0) {
            lstStatus.setSelectedValue(TAG_ALL, false);<commit_msg>more improvements to task query view<commit_after>/*
 *  Copyright 2008 Anuradha.
 * 
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 * 
 *       http://www.apache.org/licenses/LICENSE-2.0
 * 
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */

/*
 * QueryEditor.java
 *
 * Created on Jun 19, 2008, 8:43:12 AM
 */
package org.netbeans.cubeon.local.query.ui;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import javax.swing.DefaultListModel;
import javax.swing.DefaultListSelectionModel;
import javax.swing.JComponent;
import javax.swing.JList;
import javax.swing.ListSelectionModel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.netbeans.cubeon.local.query.LocalQuery;
import org.netbeans.cubeon.local.repository.LocalTaskPriorityProvider;
import org.netbeans.cubeon.local.repository.LocalTaskRepository;
import org.netbeans.cubeon.local.repository.LocalTaskStatusProvider;
import org.netbeans.cubeon.local.repository.LocalTaskTypeProvider;
import org.netbeans.cubeon.tasks.spi.task.TaskStatus;
import org.netbeans.cubeon.tasks.spi.task.TaskType;
import org.netbeans.cubeon.tasks.spi.task.TaskPriority;
import org.netbeans.cubeon.tasks.spi.query.TaskQuery;
import org.netbeans.cubeon.tasks.spi.query.TaskQuerySupportProvider;
import org.openide.util.NbBundle;

/**
 *
 * @author Anuradha
 */
public class QueryEditor extends javax.swing.JPanel implements TaskQuerySupportProvider.ConfigurationHandler {

    private LocalTaskRepository repository;
    private LocalQuery localQuery;
    private final String TAG_ALL = "All";

    /** Creates new form QueryEditor */
    public QueryEditor(TaskQuery query, LocalTaskRepository repository) {

        this.repository = repository;
        initComponents();
        loadAttributes(repository);
        if (query != null) {
            this.localQuery = query.getLookup().lookup(LocalQuery.class);
            txtName.setEditable(false);
        } else {
            this.localQuery = repository.getQuerySupport().createTaskQuery();
        }
        loadTaskQuery(this.localQuery);

    }

    private void selectItems(JList list, List<? extends Object> objects) {

        DefaultListSelectionModel dlsm = (DefaultListSelectionModel) list.getSelectionModel();
        dlsm.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
        dlsm.setLeadAnchorNotificationEnabled(true);
        //DefaultListModel model = (DefaultListModel) list.getModel();

        for (Object object : objects) {
           list.setSelectedValue(object, false);
        }
    }

    private void loadTaskQuery(LocalQuery query) {
        txtName.setText(query.getName());
        List<TaskPriority> priorities = query.getPriorities();

        selectItems(lstPriority, priorities);

        if (priorities.size() == 0) {
            lstPriority.setSelectedValue(TAG_ALL, false);
        }

        List<TaskType> types = query.getTypes();
        selectItems(lstType, types);
        if (types.size() == 0) {
            lstType.setSelectedValue(TAG_ALL, false);
        }
        List<TaskStatus> status = query.getStates();
        selectItems(lstStatus, status);
        if (status.size() == 0) {
            lstStatus.setSelectedValue(TAG_ALL, false);
{'fraction_non_alphanumeric': 0.10004239084357779, 'fraction_numerical': 0.0062173237247421225, 'mean_word_length': 3.420986883198001, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, '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': '3319799', 'n_tokens_mistral': 2041, 'n_tokens_neox': 1974, 'n_words': 472}